LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/browser - unodatbr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 1787 0.0 %
Date: 2012-12-27 Functions: 0 112 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "browserids.hxx"
      22             : #include "dbaccess_helpid.hrc"
      23             : #include "dbexchange.hxx"
      24             : #include "dbtreelistbox.hxx"
      25             : #include "dbtreemodel.hxx"
      26             : #include "dbtreeview.hxx"
      27             : #include "dbu_brw.hrc"
      28             : #include "dbu_reghelper.hxx"
      29             : #include "dbustrings.hrc"
      30             : #include "dlgsave.hxx"
      31             : #include "HtmlReader.hxx"
      32             : #include "imageprovider.hxx"
      33             : #include "listviewitems.hxx"
      34             : #include "QEnumTypes.hxx"
      35             : #include "RtfReader.hxx"
      36             : #include "sbagrid.hrc"
      37             : #include "sbagrid.hxx"
      38             : #include "sqlmessage.hxx"
      39             : #include "TokenWriter.hxx"
      40             : #include "UITools.hxx"
      41             : #include "unodatbr.hxx"
      42             : #include "WColumnSelect.hxx"
      43             : #include "WCopyTable.hxx"
      44             : #include "WCPage.hxx"
      45             : #include "WExtendPages.hxx"
      46             : #include "WNameMatch.hxx"
      47             : 
      48             : #include <com/sun/star/awt/LineEndFormat.hpp>
      49             : #include <com/sun/star/awt/MouseWheelBehavior.hpp>
      50             : #include <com/sun/star/awt/TextAlign.hpp>
      51             : #include <com/sun/star/awt/VisualEffect.hpp>
      52             : #include <com/sun/star/beans/NamedValue.hpp>
      53             : #include <com/sun/star/beans/PropertyValue.hpp>
      54             : #include <com/sun/star/container/XNameContainer.hpp>
      55             : #include <com/sun/star/form/XForm.hpp>
      56             : #include <com/sun/star/form/XGridColumnFactory.hpp>
      57             : #include <com/sun/star/form/XLoadable.hpp>
      58             : #include <com/sun/star/form/XReset.hpp>
      59             : #include <com/sun/star/frame/Desktop.hpp>
      60             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      61             : #include <com/sun/star/frame/XLayoutManager.hpp>
      62             : #include <com/sun/star/lang/DisposedException.hpp>
      63             : #include <com/sun/star/i18n/Collator.hpp>
      64             : #include <com/sun/star/sdb/CommandType.hpp>
      65             : #include <com/sun/star/sdb/SQLContext.hpp>
      66             : #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
      67             : #include <com/sun/star/sdb/XCompletedConnection.hpp>
      68             : #include <com/sun/star/sdb/XDatabaseRegistrations.hpp>
      69             : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
      70             : #include <com/sun/star/sdb/XParametersSupplier.hpp>
      71             : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      72             : #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
      73             : #include <com/sun/star/sdb/XResultSetAccess.hpp>
      74             : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
      75             : #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp>
      76             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      77             : #include <com/sun/star/sdbc/DataType.hpp>
      78             : #include <com/sun/star/sdbc/FetchDirection.hpp>
      79             : #include <com/sun/star/sdbc/SQLWarning.hpp>
      80             : #include <com/sun/star/sdbc/XDataSource.hpp>
      81             : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      82             : #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
      83             : #include <com/sun/star/sdbcx/Privilege.hpp>
      84             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      85             : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
      86             : #include <com/sun/star/sdbcx/XDrop.hpp>
      87             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      88             : #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
      89             : #include <com/sun/star/task/InteractionHandler.hpp>
      90             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      91             : #include <com/sun/star/util/XFlushable.hpp>
      92             : #include <com/sun/star/document/MacroExecMode.hpp>
      93             : #include <com/sun/star/frame/XComponentLoader.hpp>
      94             : #include <com/sun/star/ui/XContextMenuInterceptor.hpp>
      95             : 
      96             : #include <comphelper/processfactory.hxx>
      97             : #include <comphelper/extract.hxx>
      98             : #include <comphelper/sequence.hxx>
      99             : #include <comphelper/types.hxx>
     100             : #include <connectivity/dbexception.hxx>
     101             : #include <cppuhelper/exc_hlp.hxx>
     102             : #include <cppuhelper/implbase2.hxx>
     103             : #include <cppuhelper/typeprovider.hxx>
     104             : #include <sfx2/app.hxx>
     105             : #include <sfx2/dispatch.hxx>
     106             : #include <sot/storage.hxx>
     107             : #include <svl/filenotation.hxx>
     108             : #include <svl/intitem.hxx>
     109             : #include <unotools/moduleoptions.hxx>
     110             : #include <svtools/svlbitm.hxx>
     111             : #include <svtools/treelistbox.hxx>
     112             : #include "svtools/treelistentry.hxx"
     113             : #include <svx/algitem.hxx>
     114             : #include <svx/dataaccessdescriptor.hxx>
     115             : #include <svx/databaseregistrationui.hxx>
     116             : #include <toolkit/unohlp.hxx>
     117             : #include <tools/diagnose_ex.h>
     118             : #include <osl/diagnose.h>
     119             : #include <tools/multisel.hxx>
     120             : #include <tools/urlobj.hxx>
     121             : #include <unotools/confignode.hxx>
     122             : #include <vcl/msgbox.hxx>
     123             : #include <vcl/split.hxx>
     124             : #include <vcl/stdtext.hxx>
     125             : #include <vcl/svapp.hxx>
     126             : #include <vcl/toolbox.hxx>
     127             : #include <vcl/waitobj.hxx>
     128             : #include <vcl/wrkwin.hxx>
     129             : #include <rtl/logfile.hxx>
     130             : 
     131             : #include <memory>
     132             : 
     133             : using namespace ::com::sun::star::uno;
     134             : using namespace ::com::sun::star::awt;
     135             : using namespace ::com::sun::star::sdb;
     136             : using namespace ::com::sun::star::sdb::application;
     137             : using namespace ::com::sun::star::sdbc;
     138             : using namespace ::com::sun::star::sdbcx;
     139             : using namespace ::com::sun::star::beans;
     140             : using namespace ::com::sun::star::util;
     141             : using namespace ::com::sun::star::frame;
     142             : using namespace ::com::sun::star::container;
     143             : using namespace ::com::sun::star::lang;
     144             : using namespace ::com::sun::star::ui::dialogs;
     145             : using namespace ::com::sun::star::task;
     146             : using namespace ::com::sun::star::form;
     147             : using namespace ::com::sun::star::io;
     148             : using namespace ::com::sun::star::i18n;
     149             : using namespace ::com::sun::star::view;
     150             : using namespace ::com::sun::star::datatransfer;
     151             : using namespace ::com::sun::star::document;
     152             : using namespace ::com::sun::star::ui;
     153             : using namespace ::dbtools;
     154             : using namespace ::comphelper;
     155             : using namespace ::svx;
     156             : 
     157             : // .........................................................................
     158             : namespace dbaui
     159             : {
     160             : // .........................................................................
     161             : 
     162             : namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
     163             : namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
     164             : 
     165             : //==================================================================
     166             : //= SbaTableQueryBrowser
     167             : //==================================================================
     168             : // -------------------------------------------------------------------------
     169           0 : extern "C" void SAL_CALL createRegistryInfo_OBrowser()
     170             : {
     171           0 :     static OMultiInstanceAutoRegistration< SbaTableQueryBrowser > aAutoRegistration;
     172           0 : }
     173             : // -------------------------------------------------------------------------
     174           0 : void SafeAddPropertyListener(const Reference< XPropertySet > & xSet, const ::rtl::OUString& rPropName, XPropertyChangeListener* pListener)
     175             : {
     176           0 :     Reference< XPropertySetInfo >  xInfo = xSet->getPropertySetInfo();
     177           0 :     if (xInfo->hasPropertyByName(rPropName))
     178           0 :         xSet->addPropertyChangeListener(rPropName, pListener);
     179           0 : }
     180             : 
     181             : // -------------------------------------------------------------------------
     182           0 : void SafeRemovePropertyListener(const Reference< XPropertySet > & xSet, const ::rtl::OUString& rPropName, XPropertyChangeListener* pListener)
     183             : {
     184           0 :     Reference< XPropertySetInfo >  xInfo = xSet->getPropertySetInfo();
     185           0 :     if (xInfo->hasPropertyByName(rPropName))
     186           0 :         xSet->removePropertyChangeListener(rPropName, pListener);
     187           0 : }
     188             : //-------------------------------------------------------------------------
     189           0 : ::rtl::OUString SAL_CALL SbaTableQueryBrowser::getImplementationName() throw(RuntimeException)
     190             : {
     191           0 :     return getImplementationName_Static();
     192             : }
     193             : //-------------------------------------------------------------------------
     194           0 : ::comphelper::StringSequence SAL_CALL SbaTableQueryBrowser::getSupportedServiceNames() throw(RuntimeException)
     195             : {
     196           0 :     return getSupportedServiceNames_Static();
     197             : }
     198             : // -------------------------------------------------------------------------
     199           0 : ::rtl::OUString SbaTableQueryBrowser::getImplementationName_Static() throw(RuntimeException)
     200             : {
     201           0 :     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbu.ODatasourceBrowser"));
     202             : }
     203             : //-------------------------------------------------------------------------
     204           0 : ::comphelper::StringSequence SbaTableQueryBrowser::getSupportedServiceNames_Static() throw(RuntimeException)
     205             : {
     206           0 :     ::comphelper::StringSequence aSupported(1);
     207           0 :     aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DataSourceBrowser"));
     208           0 :     return aSupported;
     209             : }
     210             : //-------------------------------------------------------------------------
     211           0 : Reference< XInterface > SAL_CALL SbaTableQueryBrowser::Create(const Reference<XMultiServiceFactory >& _rxFactory)
     212             : {
     213           0 :     SolarMutexGuard aGuard;
     214           0 :     return *(new SbaTableQueryBrowser(_rxFactory));
     215             : }
     216             : 
     217             : DBG_NAME(SbaTableQueryBrowser);
     218             : //------------------------------------------------------------------------------
     219           0 : SbaTableQueryBrowser::SbaTableQueryBrowser(const Reference< XMultiServiceFactory >& _rM)
     220             :     :SbaXDataBrowserController(_rM)
     221           0 :     ,m_aSelectionListeners( getMutex() )
     222           0 :     ,m_aContextMenuInterceptors( getMutex() )
     223             :     ,m_aTableCopyHelper(this)
     224             :     ,m_pTreeView(NULL)
     225             :     ,m_pSplitter(NULL)
     226             :     ,m_pTreeModel(NULL)
     227             :     ,m_pCurrentlyDisplayed(NULL)
     228             :     ,m_nAsyncDrop(0)
     229             :     ,m_nBorder(1)
     230             :     ,m_bQueryEscapeProcessing( sal_False )
     231             :     ,m_bShowMenu(sal_False)
     232             :     ,m_bInSuspend(sal_False)
     233           0 :     ,m_bEnableBrowser(sal_True)
     234             : {
     235             :     DBG_CTOR(SbaTableQueryBrowser,NULL);
     236           0 : }
     237             : 
     238             : //------------------------------------------------------------------------------
     239           0 : SbaTableQueryBrowser::~SbaTableQueryBrowser()
     240             : {
     241             :     DBG_DTOR(SbaTableQueryBrowser,NULL);
     242           0 :     if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
     243             :     {
     244             :         OSL_FAIL("Please check who doesn't dispose this component!");
     245             :         // increment ref count to prevent double call of Dtor
     246           0 :         osl_atomic_increment( &m_refCount );
     247           0 :         dispose();
     248             :     }
     249           0 : }
     250             : 
     251             : //------------------------------------------------------------------------------
     252           0 : Any SAL_CALL SbaTableQueryBrowser::queryInterface(const Type& _rType) throw (RuntimeException)
     253             : {
     254           0 :     if ( _rType.equals( XScriptInvocationContext::static_type() ) )
     255             :     {
     256             :         OSL_PRECOND( !!m_aDocScriptSupport, "SbaTableQueryBrowser::queryInterface: did not initialize this, yet!" );
     257           0 :         if ( !!m_aDocScriptSupport && *m_aDocScriptSupport )
     258           0 :             return makeAny( Reference< XScriptInvocationContext >( this ) );
     259           0 :         return Any();
     260             :     }
     261             : 
     262           0 :     Any aReturn = SbaXDataBrowserController::queryInterface(_rType);
     263           0 :     if (!aReturn.hasValue())
     264           0 :         aReturn = SbaTableQueryBrowser_Base::queryInterface(_rType);
     265           0 :     return aReturn;
     266             : }
     267             : 
     268             : //------------------------------------------------------------------------------
     269           0 : Sequence< Type > SAL_CALL SbaTableQueryBrowser::getTypes(  ) throw (RuntimeException)
     270             : {
     271             :     Sequence< Type > aTypes( ::comphelper::concatSequences(
     272             :         SbaXDataBrowserController::getTypes(),
     273             :         SbaTableQueryBrowser_Base::getTypes()
     274           0 :     ) );
     275             : 
     276             :     OSL_PRECOND( !!m_aDocScriptSupport, "SbaTableQueryBrowser::getTypes: did not initialize this, yet!" );
     277           0 :     if ( !m_aDocScriptSupport || !*m_aDocScriptSupport )
     278             :     {
     279           0 :         Sequence< Type > aStrippedTypes( aTypes.getLength() - 1 );
     280             :         ::std::remove_copy_if(
     281             :             aTypes.getConstArray(),
     282           0 :             aTypes.getConstArray() + aTypes.getLength(),
     283             :             aStrippedTypes.getArray(),
     284           0 :             ::std::bind2nd( ::std::equal_to< Type >(), XScriptInvocationContext::static_type() )
     285           0 :         );
     286           0 :         aTypes = aStrippedTypes;
     287             :     }
     288           0 :     return aTypes;
     289             : }
     290             : 
     291             : //------------------------------------------------------------------------------
     292           0 : Sequence< sal_Int8 > SAL_CALL SbaTableQueryBrowser::getImplementationId(  ) throw (RuntimeException)
     293             : {
     294             :     static ::cppu::OImplementationId * pId = 0;
     295           0 :     if (! pId)
     296             :     {
     297           0 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     298           0 :         if (! pId)
     299             :         {
     300           0 :             static ::cppu::OImplementationId aId;
     301           0 :             pId = &aId;
     302           0 :         }
     303             :     }
     304           0 :     return pId->getImplementationId();
     305             : }
     306             : 
     307             : //------------------------------------------------------------------------------
     308           0 : void SAL_CALL SbaTableQueryBrowser::disposing()
     309             : {
     310           0 :     SolarMutexGuard aGuard;
     311             :         // doin' a lot of VCL stuff here -> lock the SolarMutex
     312             : 
     313             :     // kiss our listeners goodbye
     314           0 :     EventObject aEvt(*this);
     315           0 :     m_aSelectionListeners.disposeAndClear(aEvt);
     316           0 :     m_aContextMenuInterceptors.disposeAndClear(aEvt);
     317             : 
     318             :     // reset the content's tree view: it holds a reference to our model which is to be deleted immediately,
     319             :     // and it will live longer than we do.
     320           0 :     if (getBrowserView())
     321           0 :         getBrowserView()->setTreeView(NULL);
     322             : 
     323           0 :     clearTreeModel();
     324             :     // clear the tree model
     325             :     {
     326             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     327           0 :         ::std::auto_ptr<SvTreeList> aTemp(m_pTreeModel);
     328             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     329           0 :         m_pTreeModel = NULL;
     330             :     }
     331             : 
     332             :     // remove ourself as status listener
     333           0 :     implRemoveStatusListeners();
     334             : 
     335             :     // remove the container listener from the database context
     336             :     try
     337             :     {
     338           0 :         Reference< XDatabaseRegistrations > xDatabaseRegistrations( m_xDatabaseContext, UNO_QUERY_THROW );
     339           0 :         xDatabaseRegistrations->removeDatabaseRegistrationsListener( this );
     340             :     }
     341           0 :     catch( const Exception& )
     342             :     {
     343             :         DBG_UNHANDLED_EXCEPTION();
     344             :     }
     345             : 
     346             :     // check out from all the objects we are listening
     347             :     // the frame
     348           0 :     if (m_xCurrentFrameParent.is())
     349           0 :         m_xCurrentFrameParent->removeFrameActionListener((::com::sun::star::frame::XFrameActionListener*)this);
     350           0 :     SbaXDataBrowserController::disposing();
     351           0 : }
     352             : 
     353             : //------------------------------------------------------------------------------
     354           0 : sal_Bool SbaTableQueryBrowser::Construct(Window* pParent)
     355             : {
     356           0 :     if ( !SbaXDataBrowserController::Construct( pParent ) )
     357           0 :         return sal_False;
     358             : 
     359             :     try
     360             :     {
     361           0 :         Reference< XDatabaseRegistrations > xDatabaseRegistrations( m_xDatabaseContext, UNO_QUERY_THROW );
     362           0 :         xDatabaseRegistrations->addDatabaseRegistrationsListener( this );
     363             : 
     364             :         // the collator for the string compares
     365           0 :         m_xCollator = Collator::create( comphelper::getComponentContext( getORB() ) );
     366           0 :         m_xCollator->loadDefaultCollator( Application::GetSettings().GetLanguageTag().getLocale(), 0 );
     367             :     }
     368           0 :     catch(const Exception&)
     369             :     {
     370             :         OSL_FAIL("SbaTableQueryBrowser::Construct: could not create (or start listening at) the database context!");
     371             :     }
     372             :     // some help ids
     373           0 :     if (getBrowserView() && getBrowserView()->getVclControl())
     374             :     {
     375             : 
     376             :         // create controls and set sizes
     377           0 :         const long  nFrameWidth = getBrowserView()->LogicToPixel( ::Size( 3, 0 ), MAP_APPFONT ).Width();
     378             : 
     379           0 :         m_pSplitter = new Splitter(getBrowserView(),WB_HSCROLL);
     380           0 :         m_pSplitter->SetPosSizePixel( ::Point(0,0), ::Size(nFrameWidth,0) );
     381           0 :         m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) );
     382             : 
     383           0 :         m_pTreeView = new DBTreeView(getBrowserView(),getORB(), WB_TABSTOP | WB_BORDER);
     384           0 :         m_pTreeView->SetPreExpandHandler(LINK(this, SbaTableQueryBrowser, OnExpandEntry));
     385             : 
     386           0 :         m_pTreeView->setCopyHandler(LINK(this, SbaTableQueryBrowser, OnCopyEntry));
     387             : 
     388           0 :         m_pTreeView->getListBox().setContextMenuProvider( this );
     389           0 :         m_pTreeView->getListBox().setControlActionListener( this );
     390           0 :         m_pTreeView->SetHelpId(HID_CTL_TREEVIEW);
     391             : 
     392             :         // a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide
     393           0 :         m_pSplitter->SetSplitPosPixel( getBrowserView()->LogicToPixel( ::Size( 80, 0 ), MAP_APPFONT ).Width() );
     394             : 
     395           0 :         getBrowserView()->setSplitter(m_pSplitter);
     396           0 :         getBrowserView()->setTreeView(m_pTreeView);
     397             : 
     398             :         // fill view with data
     399           0 :         m_pTreeModel = new SvTreeList;
     400           0 :         m_pTreeModel->SetSortMode(SortAscending);
     401           0 :         m_pTreeModel->SetCompareHdl(LINK(this, SbaTableQueryBrowser, OnTreeEntryCompare));
     402           0 :         m_pTreeView->setModel(m_pTreeModel);
     403           0 :         m_pTreeView->setSelChangeHdl( LINK( this, SbaTableQueryBrowser, OnSelectionChange ) );
     404             : 
     405             :         // TODO
     406           0 :         getBrowserView()->getVclControl()->GetDataWindow().SetUniqueId(UID_DATABROWSE_DATAWINDOW);
     407           0 :         getBrowserView()->getVclControl()->SetHelpId(HID_CTL_TABBROWSER);
     408           0 :         getBrowserView()->SetUniqueId(UID_CTL_CONTENT);
     409           0 :         if (getBrowserView()->getVclControl()->GetHeaderBar())
     410           0 :             getBrowserView()->getVclControl()->GetHeaderBar()->SetHelpId(HID_DATABROWSE_HEADER);
     411           0 :         InvalidateFeature(ID_BROWSER_EXPLORER);
     412             :     }
     413             : 
     414           0 :     return sal_True;
     415             : }
     416             : // ---------------------------------------------------------------------------------------------------------------------
     417             : namespace
     418             : {
     419             :     // -----------------------------------------------------------------------------------------------------------------
     420             :     struct SelectValueByName : public ::std::unary_function< ::rtl::OUString, Any >
     421             :     {
     422           0 :         const Any& operator()( ::rtl::OUString const& i_name ) const
     423             :         {
     424           0 :             return m_rCollection.get( i_name );
     425             :         }
     426             : 
     427           0 :         SelectValueByName( ::comphelper::NamedValueCollection const& i_collection )
     428           0 :             :m_rCollection( i_collection )
     429             :         {
     430           0 :         }
     431             : 
     432             :         ::comphelper::NamedValueCollection const&   m_rCollection;
     433             :     };
     434             : }
     435             : 
     436             : // ---------------------------------------------------------------------------------------------------------------------
     437           0 : void SbaTableQueryBrowser::impl_sanitizeRowSetClauses_nothrow()
     438             : {
     439             :     try
     440             :     {
     441           0 :         Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
     442           0 :         sal_Bool bEscapeProcessing = sal_False;
     443           0 :         OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
     444           0 :         if ( !bEscapeProcessing )
     445             :             // don't touch or interpret anything if escape processing is disabled
     446             :             return;
     447             : 
     448           0 :         Reference< XSingleSelectQueryComposer > xComposer( createParser_nothrow() );
     449           0 :         if ( !xComposer.is() )
     450             :             // can't do anything. Already reported via assertion in createParser_nothrow.
     451             :             return;
     452             : 
     453             :         // the tables participating in the statement
     454           0 :         const Reference< XTablesSupplier > xSuppTables( xComposer, UNO_QUERY_THROW );
     455           0 :         const Reference< XNameAccess > xTableNames( xSuppTables->getTables(), UNO_QUERY_THROW );
     456             : 
     457             :         // the columns participating in the statement
     458           0 :         const Reference< XColumnsSupplier > xSuppColumns( xComposer, UNO_QUERY_THROW );
     459           0 :         const Reference< XNameAccess > xColumnNames( xSuppColumns->getColumns(), UNO_QUERY_THROW );
     460             : 
     461             :         // .............................................................................................................
     462             :         // check if the order columns apply to tables which really exist in the statement
     463           0 :         const Reference< XIndexAccess > xOrderColumns( xComposer->getOrderColumns(), UNO_SET_THROW );
     464           0 :         const sal_Int32 nOrderColumns( xOrderColumns->getCount() );
     465           0 :         bool invalidColumn = nOrderColumns == 0;
     466           0 :         for ( sal_Int32 c=0; ( c < nOrderColumns ) && !invalidColumn; ++c )
     467             :         {
     468           0 :             const Reference< XPropertySet > xOrderColumn( xOrderColumns->getByIndex(c), UNO_QUERY_THROW );
     469           0 :             ::rtl::OUString sTableName;
     470           0 :             OSL_VERIFY( xOrderColumn->getPropertyValue( PROPERTY_TABLENAME ) >>= sTableName );
     471           0 :             ::rtl::OUString sColumnName;
     472           0 :             OSL_VERIFY( xOrderColumn->getPropertyValue( PROPERTY_NAME ) >>= sColumnName );
     473             : 
     474           0 :             if ( sTableName.isEmpty() )
     475             :             {
     476           0 :                 if ( !xColumnNames->hasByName( sColumnName ) )
     477             :                 {
     478           0 :                     invalidColumn = true;
     479             :                     break;
     480             :                 }
     481             :             }
     482             :             else
     483             :             {
     484           0 :                 if ( !xTableNames->hasByName( sTableName ) )
     485             :                 {
     486           0 :                     invalidColumn = true;
     487             :                     break;
     488             :                 }
     489             : 
     490           0 :                 const Reference< XColumnsSupplier > xSuppTableColumns( xTableNames->getByName( sTableName ), UNO_QUERY_THROW );
     491           0 :                 const Reference< XNameAccess > xTableColumnNames( xSuppTableColumns->getColumns(), UNO_QUERY_THROW );
     492           0 :                 if ( !xTableColumnNames->hasByName( sColumnName ) )
     493             :                 {
     494           0 :                     invalidColumn = true;
     495             :                     break;
     496           0 :                 }
     497             :             }
     498           0 :         }
     499             : 
     500           0 :         if ( invalidColumn )
     501             :         {
     502             :             // reset the complete order statement at both the row set and the parser
     503           0 :             const ::rtl::OUString sEmptyOrder;
     504           0 :             xRowSetProps->setPropertyValue( PROPERTY_ORDER, makeAny( sEmptyOrder ) );
     505           0 :             xComposer->setOrder( sEmptyOrder );
     506           0 :         }
     507             : 
     508             :         // .............................................................................................................
     509             :         // check if the columns participating in the filter refer to existing tables
     510             :         // TODO: there's no API at all for this. The method which comes nearest to what we need is
     511             :         // "getStructuredFilter", but it returns pure column names only. That is, for a statement like
     512             :         // "SELECT * FROM <table> WHERE <other_table>.<column> = <value>", it will return "<column>". But
     513             :         // there's no API at all to retrieve the information about  "<other_table>" - which is what would
     514             :         // be needed here.
     515             :         // That'd be a chance to replace getStructuredFilter with something more reasonable. This method
     516             :         // has at least one other problem: For a clause like "<column> != <value>", it will return "<column>"
     517             :         // as column name, "NOT_EQUAL" as operator, and "!= <value>" as value, effectively duplicating the
     518             :         // information about the operator, and beding all clients to manually remove the "!=" from the value
     519             :         // string.
     520             :         // So, what really would be handy, is some
     521             :         //   XNormalizedFilter getNormalizedFilter();
     522             :         // with
     523             :         //   interface XDisjunctiveFilterExpression
     524             :         //   {
     525             :         //     XConjunctiveFilterTerm getTerm( int index );
     526             :         //   }
     527             :         //   interface XConjunctiveFilterTerm
     528             :         //   {
     529             :         //     ComparisonPredicate getPredicate( int index );
     530             :         //   }
     531             :         //   struct ComparisonPredicate
     532             :         //   {
     533             :         //     XComparisonOperand   Lhs;
     534             :         //     SQLFilterOperator    Operator;
     535             :         //     XComparisonOperand   Rhs;
     536             :         //   }
     537             :         //   interface XComparisonOperand
     538             :         //   {
     539             :         //     SQLFilterOperand Type;
     540             :         //     XPropertySet     getColumn();
     541             :         //     string           getLiteral();
     542             :         //     ...
     543             :         //   }
     544             :         //   enum SQLFilterOperand { Column, Literal, ... }
     545             :         //
     546             :         // ... or something like this ....
     547             :     }
     548           0 :     catch( const Exception& )
     549             :     {
     550             :         DBG_UNHANDLED_EXCEPTION();
     551             :     }
     552             : }
     553             : 
     554             : // ---------------------------------------------------------------------------------------------------------------------
     555           0 : sal_Bool SbaTableQueryBrowser::InitializeForm( const Reference< XPropertySet > & i_formProperties )
     556             : {
     557           0 :     if(!m_pCurrentlyDisplayed)
     558           0 :         return sal_True;
     559             : 
     560             :     // this method set all format settings from the orignal table or query
     561             :     try
     562             :     {
     563           0 :         DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
     564           0 :         ENSURE_OR_RETURN_FALSE( pData, "SbaTableQueryBrowser::InitializeForm: No user data set at the currently displayed entry!" );
     565           0 :         ENSURE_OR_RETURN_FALSE( pData->xObjectProperties.is(), "SbaTableQueryBrowser::InitializeForm: No table available!" );
     566             : 
     567           0 :         Reference< XPropertySetInfo > xPSI( pData->xObjectProperties->getPropertySetInfo(), UNO_SET_THROW );
     568             : 
     569           0 :         ::comphelper::NamedValueCollection aPropertyValues;
     570             : 
     571             :         const ::rtl::OUString aTransferProperties[] =
     572             :         {
     573             :             PROPERTY_APPLYFILTER,
     574             :             PROPERTY_FILTER,
     575             :             PROPERTY_HAVING_CLAUSE,
     576             :             PROPERTY_ORDER
     577           0 :         };
     578           0 :         for (size_t i = 0; i < SAL_N_ELEMENTS(aTransferProperties); ++i)
     579             :         {
     580           0 :             if ( !xPSI->hasPropertyByName( aTransferProperties[i] ) )
     581           0 :                 continue;
     582           0 :             aPropertyValues.put( aTransferProperties[i], pData->xObjectProperties->getPropertyValue( aTransferProperties[i] ) );
     583             :         }
     584             : 
     585           0 :         ::std::vector< ::rtl::OUString > aNames( aPropertyValues.getNames() );
     586           0 :         ::std::sort(aNames.begin(), aNames.end());
     587           0 :         Sequence< ::rtl::OUString > aPropNames( aNames.size() );
     588           0 :         ::std::copy( aNames.begin(), aNames.end(), aPropNames.getArray() );
     589             : 
     590           0 :         Sequence< Any > aPropValues( aNames.size() );
     591           0 :         ::std::transform( aNames.begin(), aNames.end(), aPropValues.getArray(), SelectValueByName( aPropertyValues ) );
     592             : 
     593           0 :         Reference< XMultiPropertySet > xFormMultiSet( i_formProperties, UNO_QUERY_THROW );
     594           0 :         xFormMultiSet->setPropertyValues( aPropNames, aPropValues );
     595             : 
     596           0 :         impl_sanitizeRowSetClauses_nothrow();
     597             :     }
     598           0 :     catch ( const Exception& )
     599             :     {
     600             :         DBG_UNHANDLED_EXCEPTION();
     601           0 :         return sal_False;
     602             :     }
     603             : 
     604           0 :     return sal_True;
     605             : }
     606             : 
     607             : //------------------------------------------------------------------------------
     608           0 : void SbaTableQueryBrowser::initializePreviewMode()
     609             : {
     610           0 :     if ( getBrowserView() && getBrowserView()->getVclControl() )
     611             :     {
     612           0 :         getBrowserView()->getVclControl()->AlwaysEnableInput( sal_False );
     613           0 :         getBrowserView()->getVclControl()->EnableInput( sal_False );
     614           0 :         getBrowserView()->getVclControl()->ForceHideScrollbars( sal_True );
     615             :     }
     616           0 :     Reference< XPropertySet >  xDataSourceSet(getRowSet(), UNO_QUERY);
     617           0 :     if ( xDataSourceSet.is() )
     618             :     {
     619           0 :         xDataSourceSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowInserts")),makeAny(sal_False));
     620           0 :         xDataSourceSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowUpdates")),makeAny(sal_False));
     621           0 :         xDataSourceSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowDeletes")),makeAny(sal_False));
     622           0 :     }
     623           0 : }
     624             : 
     625             : //------------------------------------------------------------------------------
     626           0 : sal_Bool SbaTableQueryBrowser::InitializeGridModel(const Reference< ::com::sun::star::form::XFormComponent > & xGrid)
     627             : {
     628             :     try
     629             :     {
     630           0 :         Reference< ::com::sun::star::form::XGridColumnFactory >  xColFactory(xGrid, UNO_QUERY);
     631           0 :         Reference< XNameContainer >  xColContainer(xGrid, UNO_QUERY);
     632           0 :         clearGridColumns( xColContainer );
     633             : 
     634           0 :         Reference< XChild > xGridAsChild(xGrid, UNO_QUERY);
     635           0 :         Reference< XLoadable > xFormAsLoadable;
     636           0 :         if (xGridAsChild.is())
     637           0 :             xFormAsLoadable = xFormAsLoadable.query(xGridAsChild->getParent());
     638           0 :         if (xFormAsLoadable.is() && xFormAsLoadable->isLoaded())
     639             :         {
     640             :             // set the formats from the table
     641           0 :             if(m_pCurrentlyDisplayed)
     642             :             {
     643           0 :                 Sequence< ::rtl::OUString> aProperties(6 + ( m_bPreview ? 5 : 0 ));
     644           0 :                 Sequence< Any> aValues(7 + ( m_bPreview ? 5 : 0 ));
     645             : 
     646           0 :                 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
     647             :                 OSL_ENSURE( pData->xObjectProperties.is(), "SbaTableQueryBrowser::InitializeGridModel: No table available!" );
     648           0 :                 if ( !pData->xObjectProperties.is() )
     649           0 :                     return sal_False;
     650             : 
     651           0 :                 ::rtl::OUString* pStringIter = aProperties.getArray();
     652           0 :                 Any* pValueIter = aValues.getArray();
     653           0 :                 if ( m_bPreview )
     654             :                 {
     655           0 :                     *pStringIter++  = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AlwaysShowCursor"));
     656           0 :                     *pValueIter++   <<= sal_False;
     657           0 :                     *pStringIter++  = PROPERTY_BORDER;
     658           0 :                     *pValueIter++   <<= sal_Int16(0);
     659             :                 }
     660             : 
     661           0 :                 *pStringIter++  = PROPERTY_FONT;
     662           0 :                 *pValueIter++   = pData->xObjectProperties->getPropertyValue(PROPERTY_FONT);
     663           0 :                 *pStringIter++  = PROPERTY_TEXTEMPHASIS;
     664           0 :                 *pValueIter++   = pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTEMPHASIS);
     665           0 :                 *pStringIter++  = PROPERTY_TEXTRELIEF;
     666           0 :                 *pValueIter++   = pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTRELIEF);
     667           0 :                 if ( m_bPreview )
     668             :                 {
     669           0 :                     *pStringIter++  = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasNavigationBar"));
     670           0 :                     *pValueIter++       <<= sal_False;
     671           0 :                     *pStringIter++  = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasRecordMarker"));
     672           0 :                     *pValueIter++       <<= sal_False;
     673             :                 }
     674           0 :                 *pStringIter++  = PROPERTY_ROW_HEIGHT;
     675           0 :                 *pValueIter++   = pData->xObjectProperties->getPropertyValue(PROPERTY_ROW_HEIGHT);
     676           0 :                 if ( m_bPreview )
     677             :                 {
     678           0 :                     *pStringIter++  = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tabstop"));
     679           0 :                     *pValueIter++       <<= sal_False;
     680             :                 }
     681           0 :                 *pStringIter++  = PROPERTY_TEXTCOLOR;
     682           0 :                 *pValueIter++   = pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTCOLOR);
     683           0 :                 *pStringIter++  = PROPERTY_TEXTLINECOLOR;
     684           0 :                 *pValueIter++   = pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTLINECOLOR);
     685             : 
     686           0 :                 Reference< XMultiPropertySet >  xFormMultiSet(xGrid, UNO_QUERY);
     687           0 :                 xFormMultiSet->setPropertyValues(aProperties, aValues);
     688             :             }
     689             : 
     690             : 
     691             :             // get the formats supplier of the database we're working with
     692           0 :             Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xSupplier = getNumberFormatter()->getNumberFormatsSupplier();
     693             : 
     694           0 :             Reference<XConnection> xConnection;
     695           0 :             Reference<XPropertySet> xRowSetProps(getRowSet(),UNO_QUERY);
     696           0 :             xRowSetProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xConnection;
     697             :             OSL_ENSURE(xConnection.is(),"A ActiveConnection should normaly exists!");
     698             : 
     699           0 :             Reference<XChild> xChild(xConnection,UNO_QUERY);
     700           0 :             Reference<XPropertySet> xDataSourceProp(xChild->getParent(),UNO_QUERY);
     701           0 :             sal_Bool bSuppressVersionCol = sal_False;
     702           0 :             OSL_VERIFY( xDataSourceProp->getPropertyValue( PROPERTY_SUPPRESSVERSIONCL ) >>= bSuppressVersionCol );
     703             : 
     704             :             // insert the column into the gridcontrol so that we see something :-)
     705           0 :             ::rtl::OUString aCurrentModelType;
     706           0 :             Reference<XColumnsSupplier> xSupCols(getRowSet(),UNO_QUERY);
     707           0 :             Reference<XNameAccess> xColumns     = xSupCols->getColumns();
     708           0 :             Sequence< ::rtl::OUString> aNames   = xColumns->getElementNames();
     709           0 :             const ::rtl::OUString* pIter        = aNames.getConstArray();
     710           0 :             const ::rtl::OUString* pEnd         = pIter + aNames.getLength();
     711             : 
     712           0 :             ::rtl::OUString sDefaultProperty;
     713           0 :             Reference< XPropertySet > xColumn;
     714           0 :             Reference< XPropertySetInfo > xColPSI;
     715           0 :             for (sal_uInt16 i=0; pIter != pEnd; ++i,++pIter)
     716             :             {
     717           0 :                 xColumn.set( xColumns->getByName( *pIter ), UNO_QUERY_THROW );
     718           0 :                 xColPSI.set( xColumn->getPropertySetInfo(), UNO_SET_THROW );
     719             : 
     720             :                 // ignore the column when it is a rowversion one
     721           0 :                 if  (   bSuppressVersionCol
     722           0 :                     &&  xColPSI->hasPropertyByName( PROPERTY_ISROWVERSION )
     723           0 :                     &&  ::cppu::any2bool( xColumn->getPropertyValue( PROPERTY_ISROWVERSION ) )
     724             :                     )
     725           0 :                     continue;
     726             : 
     727             :                 // use the result set column's type to determine the type of grid column to create
     728           0 :                 sal_Bool bFormattedIsNumeric    = sal_True;
     729           0 :                 sal_Int32 nType = ::comphelper::getINT32( xColumn->getPropertyValue( PROPERTY_TYPE ) );
     730             : 
     731           0 :                 ::std::vector< NamedValue > aInitialValues;
     732           0 :                 ::std::vector< ::rtl::OUString > aCopyProperties;
     733           0 :                 Any aDefault;
     734             : 
     735           0 :                 switch(nType)
     736             :                 {
     737             :                     case DataType::BIT:
     738             :                     case DataType::BOOLEAN:
     739             :                     {
     740           0 :                         aCurrentModelType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CheckBox"));
     741           0 :                         aInitialValues.push_back( NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VisualEffect" ) ), makeAny( VisualEffect::FLAT ) ) );
     742           0 :                         sDefaultProperty = PROPERTY_DEFAULTSTATE;
     743             : 
     744           0 :                         sal_Int32 nNullable = ColumnValue::NULLABLE_UNKNOWN;
     745           0 :                         OSL_VERIFY( xColumn->getPropertyValue( PROPERTY_ISNULLABLE ) >>= nNullable );
     746             :                         aInitialValues.push_back( NamedValue(
     747             :                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TriState" ) ),
     748             :                             makeAny( sal_Bool( ColumnValue::NO_NULLS != nNullable ) )
     749           0 :                         ) );
     750           0 :                         if ( ColumnValue::NO_NULLS == nNullable )
     751           0 :                             aDefault <<= (sal_Int16)STATE_NOCHECK;
     752             :                     }
     753           0 :                     break;
     754             : 
     755             :                     case DataType::LONGVARCHAR:
     756             :                     case DataType::CLOB:
     757           0 :                         aInitialValues.push_back( NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ), makeAny( (sal_Bool)sal_True ) ) );
     758             :                         // NO break!
     759             :                     case DataType::BINARY:
     760             :                     case DataType::VARBINARY:
     761             :                     case DataType::LONGVARBINARY:
     762           0 :                         aCurrentModelType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TextField"));
     763           0 :                         sDefaultProperty = PROPERTY_DEFAULTTEXT;
     764           0 :                         break;
     765             : 
     766             :                     case DataType::VARCHAR:
     767             :                     case DataType::CHAR:
     768           0 :                         bFormattedIsNumeric = sal_False;
     769             :                         // NO break!
     770             :                     default:
     771           0 :                         aCurrentModelType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FormattedField"));
     772           0 :                         sDefaultProperty = PROPERTY_EFFECTIVEDEFAULT;
     773             : 
     774           0 :                         if ( xSupplier.is() )
     775           0 :                             aInitialValues.push_back( NamedValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FormatsSupplier")), makeAny( xSupplier ) ) );
     776           0 :                         aInitialValues.push_back( NamedValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TreatAsNumber")), makeAny( (sal_Bool)bFormattedIsNumeric ) ) );
     777           0 :                         aCopyProperties.push_back( static_cast<const rtl::OUString&>(PROPERTY_FORMATKEY) );
     778           0 :                         break;
     779             :                 }
     780             : 
     781           0 :                 aInitialValues.push_back( NamedValue( PROPERTY_CONTROLSOURCE, makeAny( *pIter ) ) );
     782           0 :                 ::rtl::OUString sLabel;
     783           0 :                 xColumn->getPropertyValue(PROPERTY_LABEL) >>= sLabel;
     784           0 :                 if ( !sLabel.isEmpty() )
     785           0 :                     aInitialValues.push_back( NamedValue( PROPERTY_LABEL, makeAny( sLabel ) ) );
     786             :                 else
     787           0 :                     aInitialValues.push_back( NamedValue( PROPERTY_LABEL, makeAny( *pIter ) ) );
     788             : 
     789           0 :                 Reference< XPropertySet > xGridCol( xColFactory->createColumn( aCurrentModelType ), UNO_SET_THROW );
     790           0 :                 Reference< XPropertySetInfo > xGridColPSI( xGridCol->getPropertySetInfo(), UNO_SET_THROW );
     791             : 
     792             :                 // calculate the default
     793           0 :                 if ( xGridColPSI->hasPropertyByName( PROPERTY_CONTROLDEFAULT ) )
     794             :                 {
     795           0 :                     aDefault = xColumn->getPropertyValue( PROPERTY_CONTROLDEFAULT );
     796             :                     // default value
     797           0 :                     if ( nType == DataType::BIT || nType == DataType::BOOLEAN )
     798             :                     {
     799           0 :                         if ( aDefault.hasValue() )
     800           0 :                             aDefault <<= (comphelper::getString(aDefault).toInt32() == 0) ? (sal_Int16)STATE_NOCHECK : (sal_Int16)STATE_CHECK;
     801             :                         else
     802           0 :                             aDefault <<= ((sal_Int16)STATE_DONTKNOW);
     803             :                     }
     804             :                 }
     805             : 
     806           0 :                 if ( aDefault.hasValue() )
     807           0 :                     aInitialValues.push_back( NamedValue( sDefaultProperty, aDefault ) );
     808             : 
     809             :                 // transfer properties from the definition to the UNO-model :
     810           0 :                 aCopyProperties.push_back( static_cast<const rtl::OUString&>(PROPERTY_HIDDEN) );
     811           0 :                 aCopyProperties.push_back( static_cast<const rtl::OUString&>(PROPERTY_WIDTH) );
     812             : 
     813             :                 // help text to display for the column
     814           0 :                 Any aDescription;
     815           0 :                 if ( xColPSI->hasPropertyByName( PROPERTY_HELPTEXT ) )
     816           0 :                     aDescription = xColumn->getPropertyValue( PROPERTY_HELPTEXT );
     817           0 :                 ::rtl::OUString sTemp;
     818           0 :                 aDescription >>= sTemp;
     819           0 :                 if ( sTemp.isEmpty() )
     820           0 :                     xColumn->getPropertyValue( PROPERTY_DESCRIPTION ) >>= sTemp;
     821             : 
     822           0 :                 aDescription <<= sTemp;
     823           0 :                 aInitialValues.push_back( NamedValue( PROPERTY_HELPTEXT, aDescription ) );
     824             : 
     825             :                 // ... horizontal justify
     826           0 :                 Any aAlign; aAlign <<= sal_Int16( 0 );
     827           0 :                 Any aColAlign( xColumn->getPropertyValue( PROPERTY_ALIGN ) );
     828           0 :                 if ( aColAlign.hasValue() )
     829           0 :                     aAlign <<= sal_Int16( ::comphelper::getINT32( aColAlign ) );
     830           0 :                 aInitialValues.push_back( NamedValue( PROPERTY_ALIGN, aAlign ) );
     831             : 
     832             :                 // don't allow the mouse to scroll in the cells
     833           0 :                 if ( xGridColPSI->hasPropertyByName( PROPERTY_MOUSE_WHEEL_BEHAVIOR ) )
     834           0 :                     aInitialValues.push_back( NamedValue( PROPERTY_MOUSE_WHEEL_BEHAVIOR, makeAny( MouseWheelBehavior::SCROLL_DISABLED ) ) );
     835             : 
     836             :                 // now set all those values
     837           0 :                 for ( ::std::vector< NamedValue >::const_iterator property = aInitialValues.begin();
     838           0 :                       property != aInitialValues.end();
     839             :                       ++property
     840             :                     )
     841             :                 {
     842           0 :                     xGridCol->setPropertyValue( property->Name, property->Value );
     843             :                 }
     844           0 :                 for ( ::std::vector< ::rtl::OUString >::const_iterator copyPropertyName = aCopyProperties.begin();
     845           0 :                       copyPropertyName != aCopyProperties.end();
     846             :                       ++copyPropertyName
     847             :                     )
     848           0 :                     xGridCol->setPropertyValue( *copyPropertyName, xColumn->getPropertyValue( *copyPropertyName ) );
     849             : 
     850           0 :                 xColContainer->insertByName(*pIter, makeAny(xGridCol));
     851           0 :             }
     852           0 :         }
     853             :     }
     854           0 :     catch(const Exception&)
     855             :     {
     856             :         DBG_UNHANDLED_EXCEPTION();
     857           0 :         return sal_False;
     858             :     }
     859             : 
     860           0 :     return sal_True;
     861             : }
     862             : // -----------------------------------------------------------------------------
     863           0 : Reference<XPropertySet> getColumnHelper(SvTreeListEntry* _pCurrentlyDisplayed,const Reference<XPropertySet>& _rxSource)
     864             : {
     865           0 :     Reference<XPropertySet> xRet;
     866           0 :     if(_pCurrentlyDisplayed)
     867             :     {
     868           0 :         DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pCurrentlyDisplayed->GetUserData());
     869           0 :         Reference<XColumnsSupplier> xColumnsSup(pData->xObjectProperties,UNO_QUERY);
     870           0 :         Reference<XNameAccess> xNames = xColumnsSup->getColumns();
     871           0 :         ::rtl::OUString aName;
     872           0 :         _rxSource->getPropertyValue(PROPERTY_NAME) >>= aName;
     873           0 :         if(xNames.is() && xNames->hasByName(aName))
     874           0 :             xRet.set(xNames->getByName(aName),UNO_QUERY);
     875             :     }
     876           0 :     return xRet;
     877             : }
     878             : 
     879             : // -----------------------------------------------------------------------
     880           0 : void SbaTableQueryBrowser::transferChangedControlProperty(const ::rtl::OUString& _rProperty, const Any& _rNewValue)
     881             : {
     882           0 :     if(m_pCurrentlyDisplayed)
     883             :     {
     884           0 :         DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
     885           0 :         Reference< XPropertySet > xObjectProps(pData->xObjectProperties, UNO_QUERY);
     886             :         OSL_ENSURE(xObjectProps.is(),"SbaTableQueryBrowser::transferChangedControlProperty: no table/query object!");
     887           0 :         if (xObjectProps.is())
     888           0 :             xObjectProps->setPropertyValue(_rProperty, _rNewValue);
     889             :     }
     890           0 : }
     891             : 
     892             : // -----------------------------------------------------------------------
     893           0 : void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException)
     894             : {
     895           0 :     SbaXDataBrowserController::propertyChange(evt);
     896             : 
     897             :     try
     898             :     {
     899           0 :         Reference< XPropertySet >  xSource(evt.Source, UNO_QUERY);
     900           0 :         if (!xSource.is())
     901           0 :             return;
     902             : 
     903             :         // one of the many properties which require us to update the definition ?
     904             :         // a column's width ?
     905           0 :         else if (evt.PropertyName.equals(PROPERTY_WIDTH))
     906             :         {   // a column width has changed -> update the model
     907             :             // (the update of the view is done elsewhere)
     908           0 :             Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
     909           0 :             if(xProp.is())
     910             :             {
     911           0 :                 if(!evt.NewValue.hasValue())
     912           0 :                     xProp->setPropertyValue(PROPERTY_WIDTH,makeAny((sal_Int32)227));
     913             :                 else
     914           0 :                     xProp->setPropertyValue(PROPERTY_WIDTH,evt.NewValue);
     915           0 :             }
     916             :         }
     917             : 
     918             :         // a column's 'visible' state ?
     919           0 :         else if (evt.PropertyName.equals(PROPERTY_HIDDEN))
     920             :         {
     921           0 :             Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
     922           0 :             if(xProp.is())
     923           0 :                 xProp->setPropertyValue(PROPERTY_HIDDEN,evt.NewValue);
     924             :         }
     925             : 
     926             :         // a columns alignment ?
     927           0 :         else if (evt.PropertyName.equals(PROPERTY_ALIGN))
     928             :         {
     929           0 :             Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
     930             :             try
     931             :             {
     932           0 :                 if(xProp.is())
     933             :                 {
     934           0 :                     if(evt.NewValue.hasValue())
     935             :                     {
     936           0 :                         sal_Int16 nAlign = 0;
     937           0 :                         if(evt.NewValue >>= nAlign)
     938           0 :                             xProp->setPropertyValue(PROPERTY_ALIGN,makeAny(sal_Int32(nAlign)));
     939             :                         else
     940           0 :                             xProp->setPropertyValue(PROPERTY_ALIGN,evt.NewValue);
     941             :                     }
     942             :                     else
     943           0 :                         xProp->setPropertyValue(PROPERTY_ALIGN,makeAny(::com::sun::star::awt::TextAlign::LEFT));
     944             :                 }
     945             :             }
     946           0 :             catch( const Exception& )
     947             :             {
     948             :                 DBG_UNHANDLED_EXCEPTION();
     949           0 :             }
     950             :         }
     951             : 
     952             :         // a column's format ?
     953           0 :         else if (   (evt.PropertyName.equals(PROPERTY_FORMATKEY))
     954           0 :             &&  (TypeClass_LONG == evt.NewValue.getValueTypeClass())
     955             :             )
     956             :         {
     957             :             // update the model (means the definition object)
     958           0 :             Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
     959           0 :             if(xProp.is())
     960           0 :                 xProp->setPropertyValue(PROPERTY_FORMATKEY,evt.NewValue);
     961             :         }
     962             : 
     963             :         // some table definition properties ?
     964             :         // the height of the rows in the grid ?
     965           0 :         else if (evt.PropertyName.equals(PROPERTY_ROW_HEIGHT))
     966             :         {
     967           0 :             if(m_pCurrentlyDisplayed)
     968             :             {
     969           0 :                 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
     970             :                 OSL_ENSURE( pData->xObjectProperties.is(), "No table available!" );
     971             : 
     972           0 :                 sal_Bool bDefault = !evt.NewValue.hasValue();
     973           0 :                 if (bDefault)
     974           0 :                     pData->xObjectProperties->setPropertyValue(PROPERTY_ROW_HEIGHT,makeAny((sal_Int32)45));
     975             :                 else
     976           0 :                     pData->xObjectProperties->setPropertyValue(PROPERTY_ROW_HEIGHT,evt.NewValue);
     977             :             }
     978             :         }
     979             : 
     980           0 :         else if (   evt.PropertyName.equals(PROPERTY_FONT)          // the font ?
     981           0 :                 ||  evt.PropertyName.equals(PROPERTY_TEXTCOLOR)     // the text color ?
     982           0 :                 ||  evt.PropertyName.equals(PROPERTY_FILTER)        // the filter ?
     983           0 :                 ||  evt.PropertyName.equals(PROPERTY_HAVING_CLAUSE) // the having clause ?
     984           0 :                 ||  evt.PropertyName.equals(PROPERTY_ORDER)         // the sort ?
     985           0 :                 ||  evt.PropertyName.equals(PROPERTY_APPLYFILTER)   // the appliance of the filter ?
     986           0 :                 ||  evt.PropertyName.equals(PROPERTY_TEXTLINECOLOR) // the text line color ?
     987           0 :                 ||  evt.PropertyName.equals(PROPERTY_TEXTEMPHASIS)  // the text emphasis ?
     988           0 :                 ||  evt.PropertyName.equals(PROPERTY_TEXTRELIEF)    // the text relief ?
     989             :                 )
     990             :         {
     991           0 :             transferChangedControlProperty(evt.PropertyName, evt.NewValue);
     992           0 :         }
     993             :     }
     994           0 :     catch( const Exception& )
     995             :     {
     996             :         DBG_UNHANDLED_EXCEPTION();
     997             :     }
     998             : }
     999             : 
    1000             : // -----------------------------------------------------------------------
    1001           0 : sal_Bool SbaTableQueryBrowser::suspend(sal_Bool bSuspend) throw( RuntimeException )
    1002             : {
    1003           0 :     SolarMutexGuard aSolarGuard;
    1004           0 :     ::osl::MutexGuard aGuard( getMutex() );
    1005           0 :     if ( getView() && getView()->IsInModalMode() )
    1006           0 :         return sal_False;
    1007           0 :     sal_Bool bRet = sal_False;
    1008           0 :     if ( !m_bInSuspend )
    1009             :     {
    1010           0 :         m_bInSuspend = sal_True;
    1011           0 :         if ( rBHelper.bDisposed )
    1012           0 :             throw DisposedException( ::rtl::OUString(), *this );
    1013             : 
    1014           0 :         bRet = SbaXDataBrowserController::suspend(bSuspend);
    1015           0 :         if ( bRet && getView() )
    1016           0 :             getView()->Hide();
    1017             : 
    1018           0 :         m_bInSuspend = sal_False;
    1019             :     }
    1020             : 
    1021           0 :     return bRet;
    1022             : }
    1023             : 
    1024             : // -------------------------------------------------------------------------
    1025           0 : void SAL_CALL SbaTableQueryBrowser::statusChanged( const FeatureStateEvent& _rEvent ) throw(RuntimeException)
    1026             : {
    1027             :     // search the external dispatcher causing this call
    1028           0 :     Reference< XDispatch > xSource(_rEvent.Source, UNO_QUERY);
    1029           0 :     ExternalFeaturesMap::iterator aLoop;
    1030           0 :     for ( aLoop = m_aExternalFeatures.begin();
    1031           0 :           aLoop != m_aExternalFeatures.end();
    1032             :           ++aLoop
    1033             :         )
    1034             :     {
    1035           0 :         if ( _rEvent.FeatureURL.Complete == aLoop->second.aURL.Complete)
    1036             :         {
    1037             :             OSL_ENSURE( xSource.get() == aLoop->second.xDispatcher.get(), "SbaTableQueryBrowser::statusChanged: inconsistent!" );
    1038             :             // update the enabled state
    1039           0 :             aLoop->second.bEnabled = _rEvent.IsEnabled;
    1040             : 
    1041           0 :             switch ( aLoop->first )
    1042             :             {
    1043             :                 case ID_BROWSER_DOCUMENT_DATASOURCE:
    1044             :                 {
    1045             :                     // if it's the slot for the document data source, remember the state
    1046           0 :                     Sequence< PropertyValue > aDescriptor;
    1047             :     #if OSL_DEBUG_LEVEL > 0
    1048             :                     sal_Bool bProperFormat =
    1049             :     #endif
    1050           0 :                     _rEvent.State >>= aDescriptor;
    1051             :                     OSL_ENSURE(bProperFormat, "SbaTableQueryBrowser::statusChanged: need a data access descriptor here!");
    1052           0 :                     m_aDocumentDataSource.initializeFrom(aDescriptor);
    1053             : 
    1054             :                     OSL_ENSURE( (   m_aDocumentDataSource.has(daDataSource)
    1055             :                                 ||  m_aDocumentDataSource.has(daDatabaseLocation)
    1056             :                                 )
    1057             :                                 &&  m_aDocumentDataSource.has(daCommand)
    1058             :                                 &&  m_aDocumentDataSource.has(daCommandType),
    1059             :                         "SbaTableQueryBrowser::statusChanged: incomplete descriptor!");
    1060             : 
    1061             :                     // check if we know the object which is set as document data source
    1062           0 :                     checkDocumentDataSource();
    1063             :                 }
    1064           0 :                 break;
    1065             : 
    1066             :                 default:
    1067             :                     // update the toolbox
    1068           0 :                     implCheckExternalSlot( aLoop->first );
    1069           0 :                     break;
    1070             :             }
    1071           0 :             break;
    1072             :         }
    1073             :     }
    1074             : 
    1075           0 :     OSL_ENSURE(aLoop != m_aExternalFeatures.end(), "SbaTableQueryBrowser::statusChanged: don't know who sent this!");
    1076           0 : }
    1077             : 
    1078             : // -------------------------------------------------------------------------
    1079           0 : void SbaTableQueryBrowser::checkDocumentDataSource()
    1080             : {
    1081           0 :     SvTreeListEntry* pDataSourceEntry = NULL;
    1082           0 :     SvTreeListEntry* pContainerEntry = NULL;
    1083           0 :     SvTreeListEntry* pObjectEntry = getObjectEntry( m_aDocumentDataSource, &pDataSourceEntry, &pContainerEntry, sal_False );
    1084           0 :     sal_Bool bKnownDocDataSource = (NULL != pObjectEntry);
    1085           0 :     if (!bKnownDocDataSource)
    1086             :     {
    1087           0 :         if (NULL != pDataSourceEntry)
    1088             :         {   // at least the data source is known
    1089           0 :             if (NULL != pContainerEntry)
    1090           0 :                 bKnownDocDataSource = sal_True; // assume we know it.
    1091             :                 // TODO: should we expand the object container? This may be too expensive just for checking ....
    1092             :             else
    1093             :             {
    1094           0 :                 if ((NULL == pObjectEntry) && m_aDocumentDataSource.has(daCommandType) && m_aDocumentDataSource.has(daCommand))
    1095             :                 {   // maybe we have a command to be displayed ?
    1096           0 :                     sal_Int32 nCommandType = CommandType::TABLE;
    1097           0 :                     m_aDocumentDataSource[daCommandType] >>= nCommandType;
    1098             : 
    1099           0 :                     ::rtl::OUString sCommand;
    1100           0 :                     m_aDocumentDataSource[daCommand] >>= sCommand;
    1101             : 
    1102           0 :                     bKnownDocDataSource = (CommandType::COMMAND == nCommandType) && (!sCommand.isEmpty());
    1103             :                 }
    1104             :             }
    1105             :         }
    1106             :     }
    1107             : 
    1108           0 :     if ( !bKnownDocDataSource )
    1109           0 :         m_aExternalFeatures[ ID_BROWSER_DOCUMENT_DATASOURCE ].bEnabled = sal_False;
    1110             : 
    1111             :     // update the toolbox
    1112           0 :     implCheckExternalSlot(ID_BROWSER_DOCUMENT_DATASOURCE);
    1113           0 : }
    1114             : 
    1115             : // -------------------------------------------------------------------------
    1116           0 : void SbaTableQueryBrowser::extractDescriptorProps(const ::svx::ODataAccessDescriptor& _rDescriptor, ::rtl::OUString& _rDataSource, ::rtl::OUString& _rCommand, sal_Int32& _rCommandType, sal_Bool& _rEscapeProcessing)
    1117             : {
    1118           0 :     _rDataSource = _rDescriptor.getDataSource();
    1119           0 :     if ( _rDescriptor.has(daCommand) )
    1120           0 :         _rDescriptor[daCommand] >>= _rCommand;
    1121           0 :     if ( _rDescriptor.has(daCommandType) )
    1122           0 :         _rDescriptor[daCommandType] >>= _rCommandType;
    1123             : 
    1124             :     // escape processing is the only one allowed not to be present
    1125           0 :     _rEscapeProcessing = sal_True;
    1126           0 :     if (_rDescriptor.has(daEscapeProcessing))
    1127           0 :         _rEscapeProcessing = ::cppu::any2bool(_rDescriptor[daEscapeProcessing]);
    1128           0 : }
    1129             : 
    1130             : // -------------------------------------------------------------------------
    1131             : namespace
    1132             : {
    1133           0 :     bool getDataSourceDisplayName_isURL( const String& _rDS, String& _rDisplayName, String& _rUniqueId )
    1134             :     {
    1135           0 :         INetURLObject aURL( _rDS );
    1136           0 :         if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
    1137             :         {
    1138           0 :             _rDisplayName = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_WITH_CHARSET);
    1139           0 :             _rUniqueId = aURL.GetMainURL( INetURLObject::NO_DECODE );
    1140           0 :             return true;
    1141             :         }
    1142           0 :         _rDisplayName = _rDS;
    1143           0 :         _rUniqueId = String();
    1144           0 :         return false;
    1145             :     }
    1146             : 
    1147             :     // .....................................................................
    1148             :     struct FilterByEntryDataId : public IEntryFilter
    1149             :     {
    1150             :         String sId;
    1151           0 :         FilterByEntryDataId( const String& _rId ) : sId( _rId ) { }
    1152             : 
    1153           0 :         virtual ~FilterByEntryDataId() {}
    1154             : 
    1155             :         virtual bool    includeEntry( SvTreeListEntry* _pEntry ) const;
    1156             :     };
    1157             : 
    1158           0 :     bool FilterByEntryDataId::includeEntry( SvTreeListEntry* _pEntry ) const
    1159             :     {
    1160           0 :         DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( _pEntry->GetUserData() );
    1161           0 :         return ( !pData || ( pData->sAccessor == sId ) );
    1162             :     }
    1163             : }
    1164             : 
    1165             : // -------------------------------------------------------------------------
    1166           0 : String SbaTableQueryBrowser::getDataSourceAcessor( SvTreeListEntry* _pDataSourceEntry ) const
    1167             : {
    1168             :     OSL_ENSURE( _pDataSourceEntry, "SbaTableQueryBrowser::getDataSourceAcessor: invalid entry!" );
    1169             : 
    1170           0 :     DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( _pDataSourceEntry->GetUserData() );
    1171             :     OSL_ENSURE( pData, "SbaTableQueryBrowser::getDataSourceAcessor: invalid entry data!" );
    1172             :     OSL_ENSURE( pData->eType == etDatasource, "SbaTableQueryBrowser::getDataSourceAcessor: entry does not denote a data source!" );
    1173           0 :     return pData->sAccessor.Len() ? pData->sAccessor : GetEntryText( _pDataSourceEntry );
    1174             : }
    1175             : 
    1176             : // -------------------------------------------------------------------------
    1177           0 : SvTreeListEntry* SbaTableQueryBrowser::getObjectEntry(const ::rtl::OUString& _rDataSource, const ::rtl::OUString& _rCommand, sal_Int32 _nCommandType,
    1178             :         SvTreeListEntry** _ppDataSourceEntry, SvTreeListEntry** _ppContainerEntry, sal_Bool _bExpandAncestors,
    1179             :         const SharedConnection& _rxConnection )
    1180             : {
    1181           0 :     if (_ppDataSourceEntry)
    1182           0 :         *_ppDataSourceEntry = NULL;
    1183           0 :     if (_ppContainerEntry)
    1184           0 :         *_ppContainerEntry = NULL;
    1185             : 
    1186           0 :     SvTreeListEntry* pObject = NULL;
    1187           0 :     if ( m_pTreeView )
    1188             :     {
    1189             :         // look for the data source entry
    1190           0 :         String sDisplayName, sDataSourceId;
    1191           0 :         bool bIsDataSourceURL = getDataSourceDisplayName_isURL( _rDataSource, sDisplayName, sDataSourceId );
    1192             :             // the display name may differ from the URL for readability reasons
    1193             :             // #i33699#
    1194             : 
    1195           0 :         FilterByEntryDataId aFilter( sDataSourceId );
    1196           0 :         SvTreeListEntry* pDataSource = m_pTreeView->getListBox().GetEntryPosByName( sDisplayName, NULL, &aFilter );
    1197           0 :         if ( !pDataSource ) // check if the data source name is a file location
    1198             :         {
    1199           0 :             if ( bIsDataSourceURL )
    1200             :             {
    1201             :                 // special case, the data source is a URL
    1202             :                 // add new entries to the list box model
    1203           0 :                 implAddDatasource( _rDataSource, _rxConnection );
    1204           0 :                 pDataSource = m_pTreeView->getListBox().GetEntryPosByName( sDisplayName, NULL, &aFilter );
    1205             :                 OSL_ENSURE( pDataSource, "SbaTableQueryBrowser::getObjectEntry: hmm - did not find it again!" );
    1206             :             }
    1207             :         }
    1208           0 :         if (_ppDataSourceEntry)
    1209             :             // (caller wants to have it ...)
    1210           0 :             *_ppDataSourceEntry = pDataSource;
    1211             : 
    1212           0 :         if (pDataSource)
    1213             :         {
    1214             :             // expand if required so
    1215           0 :             if (_bExpandAncestors)
    1216           0 :                 m_pTreeView->getListBox().Expand(pDataSource);
    1217             : 
    1218             :             // look for the object container
    1219           0 :             SvTreeListEntry* pCommandType = NULL;
    1220           0 :             switch (_nCommandType)
    1221             :             {
    1222             :                 case CommandType::TABLE:
    1223           0 :                     pCommandType = m_pTreeView->getListBox().GetModel()->GetEntry(pDataSource, CONTAINER_TABLES);
    1224           0 :                     break;
    1225             : 
    1226             :                 case CommandType::QUERY:
    1227           0 :                     pCommandType = m_pTreeView->getListBox().GetModel()->GetEntry(pDataSource, CONTAINER_QUERIES);
    1228           0 :                     break;
    1229             :             }
    1230             : 
    1231           0 :             if (_ppContainerEntry)
    1232           0 :                 *_ppContainerEntry = pCommandType;
    1233             : 
    1234           0 :             if (pCommandType)
    1235             :             {
    1236             :                 // expand if required so
    1237           0 :                 if (_bExpandAncestors)
    1238             :                 {
    1239           0 :                     m_pTreeView->getListBox().Expand(pCommandType);
    1240             :                 }
    1241             : 
    1242             :                 // look for the object
    1243           0 :                 ::rtl::OUString sCommand = _rCommand;
    1244           0 :                 sal_Int32 nIndex = 0;
    1245           0 :                 do
    1246             :                 {
    1247           0 :                     ::rtl::OUString sPath = sCommand.getToken( 0, '/', nIndex );
    1248           0 :                     pObject = m_pTreeView->getListBox().GetEntryPosByName(sPath, pCommandType);
    1249           0 :                     pCommandType = pObject;
    1250           0 :                     if ( nIndex >= 0 )
    1251             :                     {
    1252           0 :                         if (ensureEntryObject(pObject))
    1253             :                         {
    1254           0 :                             DBTreeListUserData* pParentData = static_cast< DBTreeListUserData* >( pObject->GetUserData() );
    1255           0 :                             Reference< XNameAccess > xCollection( pParentData->xContainer, UNO_QUERY );
    1256           0 :                             sal_Int32 nIndex2 = nIndex;
    1257           0 :                             sPath = sCommand.getToken( 0, '/', nIndex2 );
    1258             :                             try
    1259             :                             {
    1260           0 :                                 if ( xCollection->hasByName(sPath) )
    1261             :                                 {
    1262           0 :                                     if(!m_pTreeView->getListBox().GetEntryPosByName(sPath,pObject))
    1263             :                                     {
    1264           0 :                                         Reference<XNameAccess> xChild(xCollection->getByName(sPath),UNO_QUERY);
    1265           0 :                                         DBTreeListUserData* pEntryData = new DBTreeListUserData;
    1266           0 :                                         pEntryData->eType = etQuery;
    1267           0 :                                         if ( xChild.is() )
    1268             :                                         {
    1269           0 :                                             pEntryData->eType = etQueryContainer;
    1270             :                                         }
    1271           0 :                                         implAppendEntry( pObject, sPath, pEntryData, pEntryData->eType );
    1272             :                                     }
    1273             :                                 }
    1274             :                             }
    1275           0 :                             catch(const Exception&)
    1276             :                             {
    1277             :                                 OSL_FAIL("SbaTableQueryBrowser::populateTree: could not fill the tree");
    1278           0 :                             }
    1279             :                         }
    1280           0 :                     }
    1281             :                 }
    1282           0 :                 while ( nIndex >= 0 );
    1283             :             }
    1284           0 :         }
    1285             :     }
    1286           0 :     return pObject;
    1287             : }
    1288             : 
    1289             : // -------------------------------------------------------------------------
    1290           0 : SvTreeListEntry* SbaTableQueryBrowser::getObjectEntry(const ::svx::ODataAccessDescriptor& _rDescriptor,
    1291             :         SvTreeListEntry** _ppDataSourceEntry, SvTreeListEntry** _ppContainerEntry,
    1292             :         sal_Bool _bExpandAncestors)
    1293             : {
    1294             :     // extract the props from the descriptor
    1295           0 :     ::rtl::OUString sDataSource;
    1296           0 :     ::rtl::OUString sCommand;
    1297           0 :     sal_Int32 nCommandType = CommandType::COMMAND;
    1298           0 :     sal_Bool bEscapeProcessing = sal_True;
    1299           0 :     extractDescriptorProps(_rDescriptor, sDataSource, sCommand, nCommandType, bEscapeProcessing);
    1300             : 
    1301           0 :     return getObjectEntry( sDataSource, sCommand, nCommandType, _ppDataSourceEntry, _ppContainerEntry, _bExpandAncestors, SharedConnection() );
    1302             : }
    1303             : 
    1304             : // -------------------------------------------------------------------------
    1305           0 : void SbaTableQueryBrowser::connectExternalDispatches()
    1306             : {
    1307           0 :     Reference< XDispatchProvider >  xProvider( getFrame(), UNO_QUERY );
    1308             :     OSL_ENSURE(xProvider.is(), "SbaTableQueryBrowser::connectExternalDispatches: no DispatchProvider !");
    1309           0 :     if (xProvider.is())
    1310             :     {
    1311           0 :         if ( m_aExternalFeatures.empty() )
    1312             :         {
    1313             :             const sal_Char* pURLs[] = {
    1314             :                 ".uno:DataSourceBrowser/DocumentDataSource",
    1315             :                 ".uno:DataSourceBrowser/FormLetter",
    1316             :                 ".uno:DataSourceBrowser/InsertColumns",
    1317             :                 ".uno:DataSourceBrowser/InsertContent",
    1318           0 :             };
    1319             :             const sal_uInt16 nIds[] = {
    1320             :                 ID_BROWSER_DOCUMENT_DATASOURCE,
    1321             :                 ID_BROWSER_FORMLETTER,
    1322             :                 ID_BROWSER_INSERTCOLUMNS,
    1323             :                 ID_BROWSER_INSERTCONTENT
    1324           0 :             };
    1325             : 
    1326           0 :             for ( size_t i=0; i < sizeof( pURLs ) / sizeof( pURLs[0] ); ++i )
    1327             :             {
    1328           0 :                 URL aURL;
    1329           0 :                 aURL.Complete = ::rtl::OUString::createFromAscii( pURLs[i] );
    1330           0 :                 if ( m_xUrlTransformer.is() )
    1331           0 :                     m_xUrlTransformer->parseStrict( aURL );
    1332           0 :                 m_aExternalFeatures[ nIds[ i ] ] = ExternalFeature( aURL );
    1333           0 :             }
    1334             :         }
    1335             : 
    1336           0 :         for ( ExternalFeaturesMap::iterator feature = m_aExternalFeatures.begin();
    1337           0 :               feature != m_aExternalFeatures.end();
    1338             :               ++feature
    1339             :             )
    1340             :         {
    1341           0 :             feature->second.xDispatcher = xProvider->queryDispatch(
    1342           0 :                 feature->second.aURL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_parent")), FrameSearchFlag::PARENT
    1343           0 :             );
    1344             : 
    1345           0 :             if ( feature->second.xDispatcher.get() == static_cast< XDispatch* >( this ) )
    1346             :             {
    1347             :                 OSL_FAIL( "SbaTableQueryBrowser::connectExternalDispatches: this should not happen anymore!" );
    1348             :                     // (nowadays, the URLs aren't in our SupportedFeatures list anymore, so we should
    1349             :                     // not supply a dispatcher for this)
    1350           0 :                 feature->second.xDispatcher.clear();
    1351             :             }
    1352             : 
    1353           0 :             if ( feature->second.xDispatcher.is() )
    1354             :             {
    1355             :                 try
    1356             :                 {
    1357           0 :                     feature->second.xDispatcher->addStatusListener( this, feature->second.aURL );
    1358             :                 }
    1359           0 :                 catch( const Exception& )
    1360             :                 {
    1361             :                     DBG_UNHANDLED_EXCEPTION();
    1362             :                 }
    1363             :             }
    1364             : 
    1365           0 :             implCheckExternalSlot( feature->first );
    1366             :         }
    1367           0 :     }
    1368           0 : }
    1369             : 
    1370             : // -------------------------------------------------------------------------
    1371           0 : void SbaTableQueryBrowser::implCheckExternalSlot( sal_uInt16 _nId )
    1372             : {
    1373           0 :     if ( !m_xMainToolbar.is() )
    1374           0 :         return;
    1375             : 
    1376           0 :     Window* pToolboxWindow = VCLUnoHelper::GetWindow( m_xMainToolbar );
    1377           0 :     ToolBox* pToolbox = dynamic_cast< ToolBox* >( pToolboxWindow );
    1378             :     OSL_ENSURE( pToolbox, "SbaTableQueryBrowser::implCheckExternalSlot: cannot obtain the toolbox window!" );
    1379             : 
    1380             :     // check if we have to hide this item from the toolbox
    1381           0 :     if ( pToolbox )
    1382             :     {
    1383           0 :         sal_Bool bHaveDispatcher = m_aExternalFeatures[ _nId ].xDispatcher.is();
    1384           0 :         if ( bHaveDispatcher != pToolbox->IsItemVisible( _nId ) )
    1385           0 :             bHaveDispatcher ? pToolbox->ShowItem( _nId ) : pToolbox->HideItem( _nId );
    1386             :     }
    1387             : 
    1388             :     // and invalidate this feature in general
    1389           0 :     InvalidateFeature( _nId );
    1390             : }
    1391             : 
    1392             : // -------------------------------------------------------------------------
    1393           0 : void SAL_CALL SbaTableQueryBrowser::disposing( const EventObject& _rSource ) throw(RuntimeException)
    1394             : {
    1395             :     // our frame ?
    1396           0 :     Reference< ::com::sun::star::frame::XFrame >  xSourceFrame(_rSource.Source, UNO_QUERY);
    1397           0 :     if (m_xCurrentFrameParent.is() && (xSourceFrame == m_xCurrentFrameParent))
    1398           0 :         m_xCurrentFrameParent->removeFrameActionListener((::com::sun::star::frame::XFrameActionListener*)this);
    1399             :     else
    1400             :     {
    1401             :         // search the external dispatcher causing this call in our map
    1402           0 :         Reference< XDispatch > xSource(_rSource.Source, UNO_QUERY);
    1403           0 :         if(xSource.is())
    1404             :         {
    1405           0 :             ExternalFeaturesMap::iterator aLoop = m_aExternalFeatures.begin();
    1406           0 :             ExternalFeaturesMap::iterator aEnd = m_aExternalFeatures.end();
    1407           0 :             while (aLoop != aEnd)
    1408             :             {
    1409           0 :                 ExternalFeaturesMap::iterator aI = aLoop++;
    1410           0 :                 if ( aI->second.xDispatcher.get() == xSource.get() )
    1411             :                 {
    1412           0 :                     sal_uInt16 nSlot = aI->first;
    1413             : 
    1414             :                     // remove it
    1415           0 :                     m_aExternalFeatures.erase(aI);
    1416             : 
    1417             :                     // maybe update the UI
    1418           0 :                     implCheckExternalSlot(nSlot);
    1419             : 
    1420             :                     // continue, the same XDispatch may be resposible for more than one URL
    1421             :                 }
    1422             :             }
    1423             :         }
    1424             :         else
    1425             :         {
    1426           0 :             Reference<XConnection> xCon(_rSource.Source, UNO_QUERY);
    1427           0 :             if ( xCon.is() && m_pTreeView )
    1428             :             {   // our connection is in dispose so we have to find the entry equal with this connection
    1429             :                 // and close it what means to collapse the entry
    1430             :                 // get the top-level representing the removed data source
    1431           0 :                 SvTreeListEntry* pDSLoop = m_pTreeView->getListBox().FirstChild(NULL);
    1432           0 :                 while (pDSLoop)
    1433             :                 {
    1434           0 :                     DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pDSLoop->GetUserData());
    1435           0 :                     if ( pData && pData->xConnection == xCon )
    1436             :                     {
    1437             :                         // we set the connection to null to avoid a second disposing of the connection
    1438           0 :                         pData->xConnection.clear();
    1439           0 :                         closeConnection(pDSLoop,sal_False);
    1440           0 :                         break;
    1441             :                     }
    1442             : 
    1443           0 :                     pDSLoop = m_pTreeView->getListBox().NextSibling(pDSLoop);
    1444             :                 }
    1445             :             }
    1446             :             else
    1447           0 :                 SbaXDataBrowserController::disposing(_rSource);
    1448           0 :         }
    1449           0 :     }
    1450           0 : }
    1451             : 
    1452             : // -------------------------------------------------------------------------
    1453           0 : void SbaTableQueryBrowser::implRemoveStatusListeners()
    1454             : {
    1455             :     // clear all old dispatches
    1456           0 :     for ( ExternalFeaturesMap::const_iterator aLoop = m_aExternalFeatures.begin();
    1457           0 :           aLoop != m_aExternalFeatures.end();
    1458             :           ++aLoop
    1459             :         )
    1460             :     {
    1461           0 :         if ( aLoop->second.xDispatcher.is() )
    1462             :         {
    1463             :             try
    1464             :             {
    1465           0 :                 aLoop->second.xDispatcher->removeStatusListener( this, aLoop->second.aURL );
    1466             :             }
    1467           0 :             catch (Exception&)
    1468             :             {
    1469             :                 OSL_FAIL("SbaTableQueryBrowser::implRemoveStatusListeners: could not remove a status listener!");
    1470             :             }
    1471             :         }
    1472             :     }
    1473           0 :     m_aExternalFeatures.clear();
    1474           0 : }
    1475             : 
    1476             : // -------------------------------------------------------------------------
    1477           0 : sal_Bool SAL_CALL SbaTableQueryBrowser::select( const Any& _rSelection ) throw (IllegalArgumentException, RuntimeException)
    1478             : {
    1479           0 :     SolarMutexGuard aGuard;
    1480             :         // doin' a lot of VCL stuff here -> lock the SolarMutex
    1481             : 
    1482           0 :     Sequence< PropertyValue > aDescriptorSequence;
    1483           0 :     if (!(_rSelection >>= aDescriptorSequence))
    1484           0 :         throw IllegalArgumentException(::rtl::OUString(), *this, 1);
    1485             :         // TODO: error message
    1486             : 
    1487           0 :     ODataAccessDescriptor aDescriptor;
    1488             :     try
    1489             :     {
    1490           0 :         aDescriptor = ODataAccessDescriptor(aDescriptorSequence);
    1491             :     }
    1492           0 :     catch(const Exception&)
    1493             :     {
    1494             :         OSL_FAIL("SbaTableQueryBrowser::select: could not extract the descriptor!");
    1495             :     }
    1496             : 
    1497             :     // check the precense of the props we need
    1498           0 :     if ( !(aDescriptor.has(daDataSource) || aDescriptor.has(daDatabaseLocation)) || !aDescriptor.has(daCommand) || !aDescriptor.has(daCommandType))
    1499           0 :         throw IllegalArgumentException(::rtl::OUString(), *this, 1);
    1500             :         // TODO: error message
    1501             : 
    1502           0 :     return implSelect(aDescriptor,sal_True);
    1503             : }
    1504             : 
    1505             : // -------------------------------------------------------------------------
    1506           0 : Any SAL_CALL SbaTableQueryBrowser::getSelection(  ) throw (RuntimeException)
    1507             : {
    1508           0 :     Any aReturn;
    1509             : 
    1510             :     try
    1511             :     {
    1512           0 :         Reference< XLoadable > xLoadable(getRowSet(), UNO_QUERY);
    1513           0 :         if (xLoadable.is() && xLoadable->isLoaded())
    1514             :         {
    1515           0 :             Reference< XPropertySet > aFormProps(getRowSet(), UNO_QUERY);
    1516           0 :             ODataAccessDescriptor aDescriptor(aFormProps);
    1517             :             // remove properties which are not part of our "selection"
    1518           0 :             aDescriptor.erase(daConnection);
    1519           0 :             aDescriptor.erase(daCursor);
    1520             : 
    1521           0 :             aReturn <<= aDescriptor.createPropertyValueSequence();
    1522           0 :         }
    1523             :     }
    1524           0 :     catch( const Exception& )
    1525             :     {
    1526             :         DBG_UNHANDLED_EXCEPTION();
    1527             :     }
    1528             : 
    1529           0 :     return aReturn;
    1530             : }
    1531             : 
    1532             : // -------------------------------------------------------------------------
    1533           0 : void SAL_CALL SbaTableQueryBrowser::addSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException)
    1534             : {
    1535           0 :     m_aSelectionListeners.addInterface(_rxListener);
    1536           0 : }
    1537             : 
    1538             : // -------------------------------------------------------------------------
    1539           0 : void SAL_CALL SbaTableQueryBrowser::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException)
    1540             : {
    1541           0 :     m_aSelectionListeners.removeInterface(_rxListener);
    1542           0 : }
    1543             : 
    1544             : // -------------------------------------------------------------------------
    1545           0 : void SbaTableQueryBrowser::attachFrame(const Reference< ::com::sun::star::frame::XFrame > & _xFrame) throw( RuntimeException )
    1546             : {
    1547           0 :     implRemoveStatusListeners();
    1548             : 
    1549           0 :     if (m_xCurrentFrameParent.is())
    1550           0 :         m_xCurrentFrameParent->removeFrameActionListener((::com::sun::star::frame::XFrameActionListener*)this);
    1551             : 
    1552           0 :     SbaXDataBrowserController::attachFrame(_xFrame);
    1553             : 
    1554           0 :     Reference< XFrame > xCurrentFrame( getFrame() );
    1555           0 :     if ( xCurrentFrame.is() )
    1556             :     {
    1557           0 :         m_xCurrentFrameParent = xCurrentFrame->findFrame(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_parent")),FrameSearchFlag::PARENT);
    1558           0 :         if ( m_xCurrentFrameParent.is() )
    1559           0 :             m_xCurrentFrameParent->addFrameActionListener((::com::sun::star::frame::XFrameActionListener*)this);
    1560             : 
    1561             :         // obtain our toolbox
    1562             :         try
    1563             :         {
    1564           0 :             Reference< XPropertySet > xFrameProps( m_aCurrentFrame.getFrame(), UNO_QUERY_THROW );
    1565             :             Reference< XLayoutManager > xLayouter(
    1566           0 :                 xFrameProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ) ),
    1567           0 :                 UNO_QUERY );
    1568             : 
    1569           0 :             if ( xLayouter.is() )
    1570             :             {
    1571             :                 Reference< XUIElement > xUI(
    1572           0 :                     xLayouter->getElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/toolbar" ) ) ),
    1573           0 :                     UNO_SET_THROW );
    1574           0 :                 m_xMainToolbar = m_xMainToolbar.query( xUI->getRealInterface() );
    1575           0 :                 OSL_ENSURE( m_xMainToolbar.is(), "SbaTableQueryBrowser::attachFrame: where's my toolbox?" );
    1576           0 :             }
    1577             :         }
    1578           0 :         catch( const Exception& )
    1579             :         {
    1580             :             DBG_UNHANDLED_EXCEPTION();
    1581             :         }
    1582             :     }
    1583             : 
    1584             :     // get the dispatchers for the external slots
    1585           0 :     connectExternalDispatches();
    1586           0 : }
    1587             : 
    1588             : // -------------------------------------------------------------------------
    1589           0 : void SbaTableQueryBrowser::addModelListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
    1590             : {
    1591           0 :     SbaXDataBrowserController::addModelListeners(_xGridControlModel);
    1592           0 :     Reference< XPropertySet >  xSourceSet(_xGridControlModel, UNO_QUERY);
    1593           0 :     if (xSourceSet.is())
    1594             :     {
    1595           0 :         xSourceSet->addPropertyChangeListener(PROPERTY_ROW_HEIGHT, static_cast<XPropertyChangeListener*>(this));
    1596           0 :         xSourceSet->addPropertyChangeListener(PROPERTY_FONT, static_cast<XPropertyChangeListener*>(this));
    1597           0 :         xSourceSet->addPropertyChangeListener(PROPERTY_TEXTCOLOR, static_cast<XPropertyChangeListener*>(this));
    1598           0 :         xSourceSet->addPropertyChangeListener(PROPERTY_TEXTLINECOLOR, static_cast<XPropertyChangeListener*>(this));
    1599           0 :         xSourceSet->addPropertyChangeListener(PROPERTY_TEXTEMPHASIS, static_cast<XPropertyChangeListener*>(this));
    1600           0 :         xSourceSet->addPropertyChangeListener(PROPERTY_TEXTRELIEF, static_cast<XPropertyChangeListener*>(this));
    1601           0 :     }
    1602             : 
    1603           0 : }
    1604             : 
    1605             : // -------------------------------------------------------------------------
    1606           0 : void SbaTableQueryBrowser::removeModelListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
    1607             : {
    1608           0 :     SbaXDataBrowserController::removeModelListeners(_xGridControlModel);
    1609           0 :     Reference< XPropertySet >  xSourceSet(_xGridControlModel, UNO_QUERY);
    1610           0 :     if (xSourceSet.is())
    1611             :     {
    1612           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_ROW_HEIGHT, static_cast<XPropertyChangeListener*>(this));
    1613           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_FONT, static_cast<XPropertyChangeListener*>(this));
    1614           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_TEXTCOLOR, static_cast<XPropertyChangeListener*>(this));
    1615           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_TEXTLINECOLOR, static_cast<XPropertyChangeListener*>(this));
    1616           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_TEXTEMPHASIS, static_cast<XPropertyChangeListener*>(this));
    1617           0 :         xSourceSet->removePropertyChangeListener(PROPERTY_TEXTRELIEF, static_cast<XPropertyChangeListener*>(this));
    1618           0 :     }
    1619           0 : }
    1620             : // -------------------------------------------------------------------------
    1621           0 : void SbaTableQueryBrowser::RowChanged()
    1622             : {
    1623           0 :     if(getBrowserView())
    1624             :     {
    1625           0 :         SbaGridControl* pControl = getBrowserView()->getVclControl();
    1626           0 :         if (!pControl->IsEditing())
    1627           0 :             InvalidateFeature(ID_BROWSER_COPY);
    1628             :     }
    1629           0 :     SbaXDataBrowserController::RowChanged();
    1630           0 : }
    1631             : 
    1632             : // -------------------------------------------------------------------------
    1633           0 : void SbaTableQueryBrowser::ColumnChanged()
    1634             : {
    1635           0 :     if(getBrowserView())
    1636             :     {
    1637           0 :         SbaGridControl* pControl = getBrowserView()->getVclControl();
    1638           0 :         if (!pControl->IsEditing())
    1639           0 :             InvalidateFeature(ID_BROWSER_COPY);
    1640             :     }
    1641           0 :     SbaXDataBrowserController::ColumnChanged();
    1642           0 : }
    1643             : //------------------------------------------------------------------------------
    1644           0 : void SbaTableQueryBrowser::AddColumnListener(const Reference< XPropertySet > & xCol)
    1645             : {
    1646           0 :     SbaXDataBrowserController::AddColumnListener(xCol);
    1647           0 :     SafeAddPropertyListener(xCol, PROPERTY_WIDTH, static_cast<XPropertyChangeListener*>(this));
    1648           0 :     SafeAddPropertyListener(xCol, PROPERTY_HIDDEN, static_cast<XPropertyChangeListener*>(this));
    1649           0 :     SafeAddPropertyListener(xCol, PROPERTY_ALIGN, static_cast<XPropertyChangeListener*>(this));
    1650           0 :     SafeAddPropertyListener(xCol, PROPERTY_FORMATKEY, static_cast<XPropertyChangeListener*>(this));
    1651           0 : }
    1652             : 
    1653             : //------------------------------------------------------------------------------
    1654           0 : void SbaTableQueryBrowser::RemoveColumnListener(const Reference< XPropertySet > & xCol)
    1655             : {
    1656           0 :     SbaXDataBrowserController::RemoveColumnListener(xCol);
    1657           0 :     SafeRemovePropertyListener(xCol, PROPERTY_WIDTH, static_cast<XPropertyChangeListener*>(this));
    1658           0 :     SafeRemovePropertyListener(xCol, PROPERTY_HIDDEN, static_cast<XPropertyChangeListener*>(this));
    1659           0 :     SafeRemovePropertyListener(xCol, PROPERTY_ALIGN, static_cast<XPropertyChangeListener*>(this));
    1660           0 :     SafeRemovePropertyListener(xCol, PROPERTY_FORMATKEY, static_cast<XPropertyChangeListener*>(this));
    1661           0 : }
    1662             : 
    1663             : //------------------------------------------------------------------------------
    1664           0 : void SbaTableQueryBrowser::criticalFail()
    1665             : {
    1666           0 :     SbaXDataBrowserController::criticalFail();
    1667           0 :     unloadAndCleanup( sal_False );
    1668           0 : }
    1669             : 
    1670             : //------------------------------------------------------------------------------
    1671           0 : void SbaTableQueryBrowser::LoadFinished(sal_Bool _bWasSynch)
    1672             : {
    1673           0 :     SbaXDataBrowserController::LoadFinished(_bWasSynch);
    1674             : 
    1675           0 :     m_sQueryCommand = ::rtl::OUString();
    1676           0 :     m_bQueryEscapeProcessing = sal_False;
    1677             : 
    1678           0 :     if (isValid() && !loadingCancelled())
    1679             :     {
    1680             :         // did we load a query?
    1681             :         sal_Bool bTemporary;    // needed because we m_bQueryEscapeProcessing is only one bit wide (and we want to pass it by reference)
    1682           0 :         if ( implGetQuerySignature( m_sQueryCommand, bTemporary ) )
    1683           0 :             m_bQueryEscapeProcessing = bTemporary;
    1684             :     }
    1685             : 
    1686             :     // if the form has been loaded, this means that our "selection" has changed
    1687           0 :     EventObject aEvent( *this );
    1688           0 :     m_aSelectionListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aEvent );
    1689           0 : }
    1690             : 
    1691             : //------------------------------------------------------------------------------
    1692           0 : sal_Bool SbaTableQueryBrowser::getExternalSlotState( sal_uInt16 _nId ) const
    1693             : {
    1694           0 :     sal_Bool bEnabled = sal_False;
    1695           0 :     ExternalFeaturesMap::const_iterator aPos = m_aExternalFeatures.find( _nId );
    1696           0 :     if ( ( m_aExternalFeatures.end() != aPos ) && aPos->second.xDispatcher.is() )
    1697           0 :         bEnabled = aPos->second.bEnabled;
    1698           0 :     return bEnabled;
    1699             : }
    1700             : 
    1701             : //------------------------------------------------------------------------------
    1702           0 : FeatureState SbaTableQueryBrowser::GetState(sal_uInt16 nId) const
    1703             : {
    1704           0 :     FeatureState aReturn;
    1705             :         // (disabled automatically)
    1706             : 
    1707             :     // no chance without a view
    1708           0 :     if (!getBrowserView() || !getBrowserView()->getVclControl())
    1709           0 :         return aReturn;
    1710             : 
    1711           0 :     switch ( nId )
    1712             :     {
    1713             :         case ID_TREE_ADMINISTRATE:
    1714           0 :             aReturn.bEnabled = true;
    1715           0 :             return aReturn;
    1716             : 
    1717             :         case ID_BROWSER_CLOSE:
    1718             :             // the close button should always be enabled
    1719           0 :             aReturn.bEnabled = !m_bEnableBrowser;
    1720           0 :             return aReturn;
    1721             : 
    1722             :             // "toggle explorer" is always enabled (if we have a explorer)
    1723             :         case ID_BROWSER_EXPLORER:
    1724           0 :             aReturn.bEnabled = m_bEnableBrowser;
    1725           0 :             aReturn.bChecked = haveExplorer();
    1726           0 :             return aReturn;
    1727             : 
    1728             :         case ID_BROWSER_REMOVEFILTER:
    1729           0 :             return SbaXDataBrowserController::GetState( nId );
    1730             : 
    1731             :         case ID_BROWSER_COPY:
    1732           0 :             if ( !m_pTreeView->HasChildPathFocus() )
    1733             :                 // handled below
    1734           0 :                 break;
    1735             :             // NO break!
    1736             :         case ID_TREE_CLOSE_CONN:
    1737             :         case ID_TREE_EDIT_DATABASE:
    1738             :         {
    1739           0 :             SvTreeListEntry* pCurrentEntry( m_pTreeView->getListBox().GetCurEntry() );
    1740           0 :             EntryType eType = getEntryType( pCurrentEntry );
    1741           0 :             if ( eType == etUnknown )
    1742           0 :                 return aReturn;
    1743             : 
    1744           0 :             SvTreeListEntry* pDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent( pCurrentEntry );
    1745             :             DBTreeListUserData* pDSData
    1746             :                 =   pDataSourceEntry
    1747             :                 ?   static_cast< DBTreeListUserData* >( pDataSourceEntry->GetUserData() )
    1748           0 :                 :   NULL;
    1749             : 
    1750           0 :             if ( nId == ID_TREE_CLOSE_CONN )
    1751             :             {
    1752           0 :                 aReturn.bEnabled = ( pDSData != NULL ) && pDSData->xConnection.is();
    1753             :             }
    1754           0 :             else if ( nId == ID_TREE_EDIT_DATABASE )
    1755             :             {
    1756             :                 ::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithServiceFactory( getORB(),
    1757           0 :                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.DataAccess/Policies/Features/Common" ) ) ) );
    1758           0 :                 sal_Bool bHaveEditDatabase( sal_True );
    1759           0 :                 OSL_VERIFY( aConfig.getNodeValue( "EditDatabaseFromDataSourceView" ) >>= bHaveEditDatabase );
    1760           0 :                 aReturn.bEnabled = getORB().is() && ( pDataSourceEntry != NULL ) && bHaveEditDatabase;
    1761             :             }
    1762           0 :             else if ( nId == ID_BROWSER_COPY )
    1763             :             {
    1764           0 :                 aReturn.bEnabled = isEntryCopyAllowed( pCurrentEntry );
    1765             :             }
    1766             : 
    1767           0 :             return aReturn;
    1768             :         }
    1769             :     }
    1770             : 
    1771             :     // all slots not handled above are not available if no form is loaded
    1772           0 :     if (!isLoaded())
    1773           0 :         return aReturn;
    1774             : 
    1775             :     try
    1776             :     {
    1777           0 :         sal_Bool bHandled = sal_False;
    1778           0 :         switch (nId)
    1779             :         {
    1780             :             case ID_BROWSER_DOCUMENT_DATASOURCE:
    1781             :                 // the slot is enabled if we have an external dispatcher able to handle it,
    1782             :                 // and the dispatcher must have enabled the slot in general
    1783           0 :                 aReturn.bEnabled = getExternalSlotState( ID_BROWSER_DOCUMENT_DATASOURCE );
    1784           0 :                 bHandled = sal_True;
    1785           0 :                 break;
    1786             :             case ID_BROWSER_REFRESH:
    1787           0 :                 aReturn.bEnabled = sal_True;
    1788           0 :                 bHandled = sal_True;
    1789           0 :                 break;
    1790             :         }
    1791             : 
    1792           0 :         if (bHandled)
    1793           0 :             return aReturn;
    1794             : 
    1795             :         // no chance without valid models
    1796           0 :         if (isValid() && !isValidCursor() && nId != ID_BROWSER_CLOSE)
    1797           0 :             return aReturn;
    1798             : 
    1799           0 :         switch (nId)
    1800             :         {
    1801             :             case ID_BROWSER_INSERTCOLUMNS:
    1802             :             case ID_BROWSER_INSERTCONTENT:
    1803             :             case ID_BROWSER_FORMLETTER:
    1804             :             {
    1805             :                 // the slot is enabled if we have an external dispatcher able to handle it,
    1806             :                 // and the dispatcher must have enabled the slot in general
    1807           0 :                 aReturn.bEnabled = getExternalSlotState( nId );
    1808             : 
    1809             :                 // for the Insert* slots, we need at least one selected row
    1810           0 :                 if (ID_BROWSER_FORMLETTER != nId)
    1811           0 :                     aReturn.bEnabled = aReturn.bEnabled && getBrowserView()->getVclControl()->GetSelectRowCount();
    1812             : 
    1813             :                 // disabled for native queries which are not saved within the database
    1814           0 :                 Reference< XPropertySet >  xDataSource(getRowSet(), UNO_QUERY);
    1815             :                 try
    1816             :                 {
    1817           0 :                     aReturn.bEnabled = aReturn.bEnabled && xDataSource.is();
    1818             : 
    1819           0 :                     if (xDataSource.is())
    1820             :                     {
    1821           0 :                         sal_Int32 nType = ::comphelper::getINT32(xDataSource->getPropertyValue(PROPERTY_COMMAND_TYPE));
    1822           0 :                         aReturn.bEnabled = aReturn.bEnabled && ((::comphelper::getBOOL(xDataSource->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || (nType == ::com::sun::star::sdb::CommandType::QUERY)));
    1823             :                     }
    1824             :                 }
    1825           0 :                 catch(DisposedException&)
    1826             :                 {
    1827             :                     OSL_FAIL("SbaTableQueryBrowser::GetState: object already disposed!");
    1828             :                 }
    1829           0 :                 catch( const Exception& )
    1830             :                 {
    1831             :                     DBG_UNHANDLED_EXCEPTION();
    1832           0 :                 }
    1833             :             }
    1834           0 :             break;
    1835             : 
    1836             :             case ID_BROWSER_TITLE:
    1837             :                 {
    1838           0 :                     Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
    1839           0 :                     sal_Int32 nCommandType = CommandType::TABLE;
    1840           0 :                     xProp->getPropertyValue(PROPERTY_COMMAND_TYPE) >>= nCommandType;
    1841           0 :                     String sTitle;
    1842           0 :                     switch (nCommandType)
    1843             :                     {
    1844             :                         case CommandType::TABLE:
    1845           0 :                             sTitle = String(ModuleRes(STR_TBL_TITLE)); break;
    1846             :                         case CommandType::QUERY:
    1847             :                         case CommandType::COMMAND:
    1848           0 :                             sTitle = String(ModuleRes(STR_QRY_TITLE)); break;
    1849             :                         default:
    1850             :                             OSL_FAIL("SbaTableQueryBrowser::GetState: unknown command type!");
    1851             :                     }
    1852           0 :                     ::rtl::OUString aName;
    1853           0 :                     xProp->getPropertyValue(PROPERTY_COMMAND) >>= aName;
    1854           0 :                     String sObject(aName);
    1855             : 
    1856           0 :                     sTitle.SearchAndReplace(rtl::OUString('#'), sObject);
    1857           0 :                     aReturn.sTitle = sTitle;
    1858           0 :                     aReturn.bEnabled = sal_True;
    1859             :                 }
    1860           0 :                 break;
    1861             :             case ID_BROWSER_TABLEATTR:
    1862             :             case ID_BROWSER_ROWHEIGHT:
    1863             :             case ID_BROWSER_COLATTRSET:
    1864             :             case ID_BROWSER_COLWIDTH:
    1865           0 :                 aReturn.bEnabled = getBrowserView() && getBrowserView()->getVclControl() && isValid() && isValidCursor();
    1866             :                 //  aReturn.bEnabled &= getDefinition() && !getDefinition()->GetDatabase()->IsReadOnly();
    1867           0 :                 break;
    1868             : 
    1869             :             case ID_BROWSER_COPY:
    1870             :                 OSL_ENSURE( !m_pTreeView->HasChildPathFocus(), "SbaTableQueryBrowser::GetState( ID_BROWSER_COPY ): this should have been handled above!" );
    1871           0 :                 if (getBrowserView() && getBrowserView()->getVclControl() && !getBrowserView()->getVclControl()->IsEditing())
    1872             :                 {
    1873           0 :                     SbaGridControl* pControl = getBrowserView()->getVclControl();
    1874           0 :                     if ( pControl->GetSelectRowCount() )
    1875             :                     {
    1876           0 :                         aReturn.bEnabled = m_aCurrentFrame.isActive();
    1877           0 :                         break;
    1878             :                     }
    1879             :                     else
    1880           0 :                         aReturn.bEnabled = pControl->canCopyCellText(pControl->GetCurRow(), pControl->GetCurColumnId());
    1881           0 :                     break;
    1882             :                 }
    1883             :                 // NO break here
    1884             :             default:
    1885           0 :                 return SbaXDataBrowserController::GetState(nId);
    1886             :         }
    1887             :     }
    1888           0 :     catch(const Exception&)
    1889             :     {
    1890             :         DBG_UNHANDLED_EXCEPTION();
    1891             :     }
    1892             : 
    1893           0 :     return aReturn;
    1894             : 
    1895             : }
    1896             : 
    1897             : //------------------------------------------------------------------------------
    1898           0 : void SbaTableQueryBrowser::Execute(sal_uInt16 nId, const Sequence< PropertyValue >& aArgs)
    1899             : {
    1900           0 :     switch (nId)
    1901             :     {
    1902             :         default:
    1903           0 :             SbaXDataBrowserController::Execute(nId,aArgs);
    1904           0 :             break;
    1905             : 
    1906             :         case ID_TREE_EDIT_DATABASE:
    1907           0 :             implAdministrate( m_pTreeView->getListBox().GetCurEntry() );
    1908           0 :             break;
    1909             : 
    1910             :         case ID_TREE_CLOSE_CONN:
    1911           0 :             openHelpAgent( rtl::OString( HID_DSBROWSER_DISCONNECTING ));
    1912           0 :             closeConnection( m_pTreeView->getListBox().GetRootLevelParent( m_pTreeView->getListBox().GetCurEntry() ) );
    1913           0 :             break;
    1914             : 
    1915             :         case ID_TREE_ADMINISTRATE:
    1916           0 :             ::svx::administrateDatabaseRegistration( getView() );
    1917           0 :             break;
    1918             : 
    1919             :         case ID_BROWSER_REFRESH:
    1920             :         {
    1921           0 :             if ( !SaveModified( ) )
    1922             :                 // nothing to do
    1923           0 :                 break;
    1924             : 
    1925           0 :             sal_Bool bFullReinit = sal_False;
    1926             :             // check if the query signature (if the form is based on a query) has changed
    1927           0 :             if ( !m_sQueryCommand.isEmpty() )
    1928             :             {
    1929           0 :                 ::rtl::OUString sNewQueryCommand;
    1930             :                 sal_Bool bNewQueryEP;
    1931             : 
    1932             : #if OSL_DEBUG_LEVEL > 0
    1933             :                 sal_Bool bIsQuery =
    1934             : #endif
    1935           0 :                 implGetQuerySignature( sNewQueryCommand, bNewQueryEP );
    1936             :                 OSL_ENSURE( bIsQuery, "SbaTableQueryBrowser::Execute: was a query before, but is not anymore?" );
    1937             : 
    1938           0 :                 bFullReinit = ( sNewQueryCommand != m_sQueryCommand ) || ( m_bQueryEscapeProcessing != bNewQueryEP );
    1939             :             }
    1940           0 :             if ( !bFullReinit )
    1941             :             {
    1942             :                 // let the base class do a simple reload
    1943           0 :                 SbaXDataBrowserController::Execute(nId,aArgs);
    1944           0 :                 break;
    1945             :             }
    1946             :             // NO break here!
    1947             :         }
    1948             : 
    1949             :         case ID_BROWSER_REFRESH_REBUILD:
    1950             :         {
    1951           0 :             if ( !SaveModified() )
    1952             :                 // nothing to do
    1953           0 :                 break;
    1954             : 
    1955           0 :             SvTreeListEntry* pSelected = m_pCurrentlyDisplayed;
    1956             :             // unload
    1957           0 :             unloadAndCleanup( sal_False );
    1958             : 
    1959             :             // reselect the entry
    1960           0 :             if ( pSelected )
    1961             :             {
    1962           0 :                 implSelect( pSelected );
    1963             :             }
    1964             :             else
    1965             :             {
    1966           0 :                 Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
    1967           0 :                 implSelect(::svx::ODataAccessDescriptor(xProp));
    1968             :             }
    1969             :         }
    1970           0 :         break;
    1971             : 
    1972             :         case ID_BROWSER_EXPLORER:
    1973           0 :             toggleExplorer();
    1974           0 :             break;
    1975             : 
    1976             :         case ID_BROWSER_DOCUMENT_DATASOURCE:
    1977           0 :             implSelect(m_aDocumentDataSource);
    1978           0 :             break;
    1979             : 
    1980             :         case ID_BROWSER_INSERTCOLUMNS:
    1981             :         case ID_BROWSER_INSERTCONTENT:
    1982             :         case ID_BROWSER_FORMLETTER:
    1983           0 :             if (getBrowserView() && isValidCursor())
    1984             :             {
    1985             :                 // the URL the slot id is assigned to
    1986             :                 OSL_ENSURE( m_aExternalFeatures.find( nId ) != m_aExternalFeatures.end(),
    1987             :                     "SbaTableQueryBrowser::Execute( ID_BROWSER_?): how could this ever be enabled?" );
    1988           0 :                 URL aParentUrl = m_aExternalFeatures[ nId ].aURL;
    1989             : 
    1990             :                 // let the dispatcher execute the slot
    1991           0 :                 Reference< XDispatch > xDispatch( m_aExternalFeatures[ nId ].xDispatcher );
    1992           0 :                 if (xDispatch.is())
    1993             :                 {
    1994             :                     // set the properties for the dispatch
    1995             : 
    1996             :                     // first fill the selection
    1997           0 :                     SbaGridControl* pGrid = getBrowserView()->getVclControl();
    1998           0 :                     MultiSelection* pSelection = (MultiSelection*)pGrid->GetSelection();
    1999           0 :                     Sequence< Any > aSelection;
    2000           0 :                     if ( !pGrid->IsAllSelected() )
    2001             :                     {   // transfer the selected rows only if not all rows are selected
    2002             :                         // (all rows means the whole table)
    2003             :                         // #i3832#
    2004           0 :                         if (pSelection != NULL)
    2005             :                         {
    2006           0 :                             aSelection.realloc(pSelection->GetSelectCount());
    2007           0 :                             long nIdx = pSelection->FirstSelected();
    2008           0 :                             Any* pSelectionNos = aSelection.getArray();
    2009           0 :                             while (nIdx >= 0)
    2010             :                             {
    2011           0 :                                 *pSelectionNos++ <<= (sal_Int32)(nIdx + 1);
    2012           0 :                                 nIdx = pSelection->NextSelected();
    2013             :                             }
    2014             :                         }
    2015             :                     }
    2016             : 
    2017           0 :                     Reference< XResultSet > xCursorClone;
    2018             :                     try
    2019             :                     {
    2020           0 :                         Reference< XResultSetAccess > xResultSetAccess(getRowSet(),UNO_QUERY);
    2021           0 :                         if (xResultSetAccess.is())
    2022           0 :                             xCursorClone = xResultSetAccess->createResultSet();
    2023             :                     }
    2024           0 :                     catch(DisposedException&)
    2025             :                     {
    2026             :                         OSL_FAIL("Object already disposed!");
    2027             :                     }
    2028           0 :                     catch(const Exception&)
    2029             :                     {
    2030             :                         OSL_FAIL("SbaTableQueryBrowser::Execute(ID_BROWSER_?): could not clone the cursor!");
    2031             :                     }
    2032             : 
    2033           0 :                     Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
    2034             : 
    2035             :                     try
    2036             :                     {
    2037           0 :                         ODataAccessDescriptor aDescriptor;
    2038           0 :                         ::rtl::OUString sDataSourceName;
    2039           0 :                         xProp->getPropertyValue(PROPERTY_DATASOURCENAME) >>= sDataSourceName;
    2040             : 
    2041           0 :                         aDescriptor.setDataSource(sDataSourceName);
    2042           0 :                         aDescriptor[daCommand]      =   xProp->getPropertyValue(PROPERTY_COMMAND);
    2043           0 :                         aDescriptor[daCommandType]  =   xProp->getPropertyValue(PROPERTY_COMMAND_TYPE);
    2044           0 :                         aDescriptor[daConnection]   =   xProp->getPropertyValue(PROPERTY_ACTIVE_CONNECTION);
    2045           0 :                         aDescriptor[daCursor]       <<= xCursorClone;
    2046           0 :                         if ( aSelection.getLength() )
    2047             :                         {
    2048           0 :                             aDescriptor[daSelection]            <<= aSelection;
    2049           0 :                             aDescriptor[daBookmarkSelection]    <<= sal_False;
    2050             :                                 // these are selection indicies
    2051             :                                 // before we change this, all clients have to be adjusted
    2052             :                                 // so that they recognize the new BookmarkSelection property!
    2053             :                         }
    2054             : 
    2055           0 :                         xDispatch->dispatch(aParentUrl, aDescriptor.createPropertyValueSequence());
    2056             :                     }
    2057           0 :                     catch( const Exception& )
    2058             :                     {
    2059             :                         DBG_UNHANDLED_EXCEPTION();
    2060           0 :                     }
    2061           0 :                 }
    2062             :             }
    2063           0 :             break;
    2064             : 
    2065             :         case ID_BROWSER_CLOSE:
    2066           0 :             closeTask();
    2067             :             // if it's not 0, such a async close is already pending
    2068           0 :             break;
    2069             : 
    2070             :         case ID_BROWSER_COPY:
    2071           0 :             if(m_pTreeView->HasChildPathFocus())
    2072             :             {
    2073           0 :                 copyEntry(m_pTreeView->getListBox().GetCurEntry());
    2074             :             }
    2075           0 :             else if (getBrowserView() && getBrowserView()->getVclControl() && !getBrowserView()->getVclControl()->IsEditing() && getBrowserView()->getVclControl()->GetSelectRowCount() < 1)
    2076             :             {
    2077           0 :                 SbaGridControl* pControl = getBrowserView()->getVclControl();
    2078           0 :                 pControl->copyCellText(pControl->GetCurRow(), pControl->GetCurColumnId());
    2079             :             }
    2080             :             else
    2081           0 :                 SbaXDataBrowserController::Execute(nId,aArgs);
    2082           0 :             break;
    2083             :     }
    2084           0 : }
    2085             : 
    2086             : // -------------------------------------------------------------------------
    2087           0 : void SbaTableQueryBrowser::implAddDatasource( const String& _rDataSourceName, const SharedConnection& _rxConnection )
    2088             : {
    2089           0 :     Image a, b, c;
    2090           0 :     String d, e;
    2091           0 :     implAddDatasource( _rDataSourceName, a, d, b, e, c, _rxConnection );
    2092           0 : }
    2093             : 
    2094             : // -------------------------------------------------------------------------
    2095           0 : void SbaTableQueryBrowser::implAddDatasource(const String& _rDbName, Image& _rDbImage,
    2096             :         String& _rQueryName, Image& _rQueryImage, String& _rTableName, Image& _rTableImage,
    2097             :         const SharedConnection& _rxConnection)
    2098             : {
    2099           0 :     SolarMutexGuard aGuard;
    2100             :     // initialize the names/images if necessary
    2101           0 :     if (!_rQueryName.Len())
    2102           0 :         _rQueryName = String(ModuleRes(RID_STR_QUERIES_CONTAINER));
    2103           0 :     if (!_rTableName.Len())
    2104           0 :         _rTableName = String(ModuleRes(RID_STR_TABLES_CONTAINER));
    2105             : 
    2106           0 :     ImageProvider aImageProvider;
    2107           0 :     if (!_rQueryImage)
    2108           0 :         _rQueryImage = aImageProvider.getFolderImage( DatabaseObject::QUERY );
    2109           0 :     if (!_rTableImage)
    2110           0 :         _rTableImage = aImageProvider.getFolderImage( DatabaseObject::TABLE );
    2111             : 
    2112           0 :     if (!_rDbImage)
    2113           0 :         _rDbImage = aImageProvider.getDatabaseImage();
    2114             : 
    2115             :     // add the entry for the data source
    2116             :     // special handling for data sources denoted by URLs - we do not want to display this ugly URL, do we?
    2117             :     // #i33699#
    2118           0 :     String sDSDisplayName, sDataSourceId;
    2119           0 :     getDataSourceDisplayName_isURL( _rDbName, sDSDisplayName, sDataSourceId );
    2120             : 
    2121           0 :     SvTreeListEntry* pDatasourceEntry = m_pTreeView->getListBox().InsertEntry( sDSDisplayName, _rDbImage, _rDbImage, NULL, sal_False );
    2122           0 :     DBTreeListUserData* pDSData = new DBTreeListUserData;
    2123           0 :     pDSData->eType = etDatasource;
    2124           0 :     pDSData->sAccessor = sDataSourceId;
    2125           0 :     pDSData->xConnection = _rxConnection;
    2126           0 :     pDatasourceEntry->SetUserData(pDSData);
    2127             : 
    2128             :     // the child for the queries container
    2129             :     {
    2130           0 :         DBTreeListUserData* pQueriesData = new DBTreeListUserData;
    2131           0 :         pQueriesData->eType = etQueryContainer;
    2132             : 
    2133           0 :         m_pTreeView->getListBox().InsertEntry(
    2134             :             _rQueryName, _rQueryImage, _rQueryImage, pDatasourceEntry,
    2135           0 :             sal_True /*ChildrenOnDemand*/, LIST_APPEND, pQueriesData );
    2136             :     }
    2137             : 
    2138             :     // the child for the tables container
    2139             :     {
    2140           0 :         DBTreeListUserData* pTablesData = new DBTreeListUserData;
    2141           0 :         pTablesData->eType = etTableContainer;
    2142             : 
    2143           0 :         m_pTreeView->getListBox().InsertEntry(
    2144             :             _rTableName, _rTableImage, _rTableImage, pDatasourceEntry,
    2145           0 :             sal_True /*ChildrenOnDemand*/, LIST_APPEND, pTablesData );
    2146           0 :     }
    2147             : 
    2148           0 : }
    2149             : // -------------------------------------------------------------------------
    2150           0 : void SbaTableQueryBrowser::initializeTreeModel()
    2151             : {
    2152           0 :     if (m_xDatabaseContext.is())
    2153             :     {
    2154           0 :         Image aDBImage, aQueriesImage, aTablesImage;
    2155           0 :         String sQueriesName, sTablesName;
    2156             : 
    2157             :         // fill the model with the names of the registered datasources
    2158           0 :         Sequence< ::rtl::OUString > aDatasources = m_xDatabaseContext->getElementNames();
    2159           0 :         const ::rtl::OUString* pIter    = aDatasources.getConstArray();
    2160           0 :         const ::rtl::OUString* pEnd     = pIter + aDatasources.getLength();
    2161           0 :         for (; pIter != pEnd; ++pIter)
    2162           0 :             implAddDatasource( *pIter, aDBImage, sQueriesName, aQueriesImage, sTablesName, aTablesImage, SharedConnection() );
    2163             :     }
    2164           0 : }
    2165             : // -------------------------------------------------------------------------
    2166           0 : void SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAccess,
    2167             :                                             SvTreeListEntry* _pParent,
    2168             :                                             EntryType _eEntryType)
    2169             : {
    2170           0 :     DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pParent->GetUserData());
    2171           0 :     if(pData) // don't ask if the nameaccess is already set see OnExpandEntry views and tables
    2172           0 :         pData->xContainer = _xNameAccess;
    2173             : 
    2174             :     try
    2175             :     {
    2176           0 :         Sequence< ::rtl::OUString > aNames = _xNameAccess->getElementNames();
    2177           0 :         const ::rtl::OUString* pIter    = aNames.getConstArray();
    2178           0 :         const ::rtl::OUString* pEnd     = pIter + aNames.getLength();
    2179           0 :         for (; pIter != pEnd; ++pIter)
    2180             :         {
    2181           0 :             if( !m_pTreeView->getListBox().GetEntryPosByName(*pIter,_pParent))
    2182             :             {
    2183           0 :                 DBTreeListUserData* pEntryData = new DBTreeListUserData;
    2184           0 :                 pEntryData->eType = _eEntryType;
    2185           0 :                 if ( _eEntryType == etQuery )
    2186             :                 {
    2187           0 :                     Reference<XNameAccess> xChild(_xNameAccess->getByName(*pIter),UNO_QUERY);
    2188           0 :                     if ( xChild.is() )
    2189           0 :                         pEntryData->eType = etQueryContainer;
    2190             :                 }
    2191           0 :                 implAppendEntry( _pParent, *pIter, pEntryData, pEntryData->eType );
    2192             :             }
    2193           0 :         }
    2194             :     }
    2195           0 :     catch(const Exception&)
    2196             :     {
    2197             :         OSL_FAIL("SbaTableQueryBrowser::populateTree: could not fill the tree");
    2198             :     }
    2199           0 : }
    2200             : 
    2201             : //------------------------------------------------------------------------------
    2202           0 : SvTreeListEntry* SbaTableQueryBrowser::implAppendEntry( SvTreeListEntry* _pParent, const String& _rName, void* _pUserData, EntryType _eEntryType )
    2203             : {
    2204             :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
    2205           0 :     ::std::auto_ptr< ImageProvider > pImageProvider( getImageProviderFor( _pParent ) );
    2206             :     SAL_WNODEPRECATED_DECLARATIONS_POP
    2207             : 
    2208           0 :     Image aImage;
    2209           0 :     pImageProvider->getImages( _rName, getDatabaseObjectType( _eEntryType ), aImage );
    2210             : 
    2211           0 :     SvTreeListEntry* pNewEntry = m_pTreeView->getListBox().InsertEntry( _rName, _pParent, _eEntryType == etQueryContainer , LIST_APPEND, _pUserData );
    2212             : 
    2213           0 :     m_pTreeView->getListBox().SetExpandedEntryBmp(  pNewEntry, aImage );
    2214           0 :     m_pTreeView->getListBox().SetCollapsedEntryBmp( pNewEntry, aImage );
    2215             : 
    2216           0 :     return pNewEntry;
    2217             : }
    2218             : 
    2219             : //------------------------------------------------------------------------------
    2220           0 : IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, SvTreeListEntry*, _pParent)
    2221             : {
    2222           0 :     if (_pParent->HasChildren())
    2223             :         // nothing to to ...
    2224           0 :         return 1L;
    2225             : 
    2226           0 :     SvTreeListEntry* pFirstParent = m_pTreeView->getListBox().GetRootLevelParent(_pParent);
    2227             :     OSL_ENSURE(pFirstParent,"SbaTableQueryBrowser::OnExpandEntry: No rootlevelparent!");
    2228             : 
    2229           0 :     DBTreeListUserData* pData = static_cast< DBTreeListUserData* >(_pParent->GetUserData());
    2230             :     OSL_ENSURE(pData,"SbaTableQueryBrowser::OnExpandEntry: No user data!");
    2231             : #if OSL_DEBUG_LEVEL > 0
    2232             :     SvLBoxString* pString = static_cast<SvLBoxString*>(pFirstParent->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING));
    2233             :     OSL_ENSURE(pString,"SbaTableQueryBrowser::OnExpandEntry: No string item!");
    2234             : #endif
    2235             : 
    2236           0 :     if (etTableContainer == pData->eType)
    2237             :     {
    2238           0 :         WaitObject aWaitCursor(getBrowserView());
    2239             : 
    2240             :         // it could be that we already have a connection
    2241           0 :         SharedConnection xConnection;
    2242           0 :         ensureConnection( pFirstParent, xConnection );
    2243             : 
    2244           0 :         if ( xConnection.is() )
    2245             :         {
    2246           0 :             SQLExceptionInfo aInfo;
    2247             :             try
    2248             :             {
    2249           0 :                 Reference< XWarningsSupplier > xWarnings(xConnection, UNO_QUERY);
    2250           0 :                 if (xWarnings.is())
    2251           0 :                     xWarnings->clearWarnings();
    2252             : 
    2253             :                 // first insert the views because the tables can also include
    2254             :                 // views but that time the bitmap is the wrong one
    2255             :                 // the nameaccess will be overwriten in populateTree
    2256           0 :                 Reference<XViewsSupplier> xViewSup(xConnection,UNO_QUERY);
    2257           0 :                 if(xViewSup.is())
    2258           0 :                     populateTree( xViewSup->getViews(), _pParent, etTableOrView );
    2259             : 
    2260           0 :                 Reference<XTablesSupplier> xTabSup(xConnection,UNO_QUERY);
    2261           0 :                 if(xTabSup.is())
    2262             :                 {
    2263           0 :                     populateTree( xTabSup->getTables(), _pParent, etTableOrView );
    2264           0 :                     Reference<XContainer> xCont(xTabSup->getTables(),UNO_QUERY);
    2265           0 :                     if(xCont.is())
    2266             :                         // add as listener to know when elements are inserted or removed
    2267           0 :                         xCont->addContainerListener(this);
    2268             :                 }
    2269             : 
    2270           0 :                 if (xWarnings.is())
    2271             :                 {
    2272           0 :                     SQLExceptionInfo aWarnings(xWarnings->getWarnings());
    2273             : #if 0
    2274             : // Obviously this if test is always false. So to avoid a Clang warning
    2275             : // "use of logical '&&' with constant operand" I put this in #if
    2276             : // 0. Yeah, I know it is fairly likely nobody will ever read this
    2277             : // comment and make a decision what to do here, so I could as well
    2278             : // have just binned this...
    2279             :                     if (aWarnings.isValid() && sal_False)
    2280             :                     {
    2281             :                         SQLContext aContext;
    2282             :                         aContext.Message = String(ModuleRes(STR_OPENTABLES_WARNINGS));
    2283             :                         aContext.Details = String(ModuleRes(STR_OPENTABLES_WARNINGS_DETAILS));
    2284             :                         aContext.NextException = aWarnings.get();
    2285             :                         aWarnings = aContext;
    2286             :                         showError(aWarnings);
    2287             :                     }
    2288             : #endif
    2289             :                     // TODO: we need a better concept for these warnings:
    2290             :                     // something like "don't show any warnings for this datasource, again" would be nice
    2291             :                     // But this requires an extension of the InteractionHandler and an additional property on the data source
    2292           0 :                 }
    2293             :             }
    2294           0 :             catch(const SQLContext& e) { aInfo = e; }
    2295           0 :             catch(const SQLWarning& e) { aInfo = e; }
    2296           0 :             catch(const SQLException& e) { aInfo = e; }
    2297           0 :             catch(const WrappedTargetException& e)
    2298             :             {
    2299           0 :                 SQLException aSql;
    2300           0 :                 if(e.TargetException >>= aSql)
    2301           0 :                     aInfo = aSql;
    2302             :                 else
    2303           0 :                     OSL_FAIL("SbaTableQueryBrowser::OnExpandEntry: something strange happended!");
    2304             :             }
    2305           0 :             catch( const Exception& )
    2306             :             {
    2307             :                 DBG_UNHANDLED_EXCEPTION();
    2308             :             }
    2309           0 :             if (aInfo.isValid())
    2310           0 :                 showError(aInfo);
    2311             :         }
    2312             :         else
    2313           0 :             return 0L;
    2314             :                 // 0 indicates that an error occurred
    2315             :     }
    2316             :     else
    2317             :     {   // we have to expand the queries or bookmarks
    2318           0 :         if (ensureEntryObject(_pParent))
    2319             :         {
    2320           0 :             DBTreeListUserData* pParentData = static_cast< DBTreeListUserData* >( _pParent->GetUserData() );
    2321           0 :             Reference< XNameAccess > xCollection( pParentData->xContainer, UNO_QUERY );
    2322           0 :             populateTree( xCollection, _pParent, etQuery );
    2323             :         }
    2324             :     }
    2325           0 :     return 1L;
    2326             : }
    2327             : 
    2328             : //------------------------------------------------------------------------------
    2329           0 : sal_Bool SbaTableQueryBrowser::ensureEntryObject( SvTreeListEntry* _pEntry )
    2330             : {
    2331             :     OSL_ENSURE(_pEntry, "SbaTableQueryBrowser::ensureEntryObject: invalid argument!");
    2332           0 :     if (!_pEntry)
    2333           0 :         return sal_False;
    2334             : 
    2335           0 :     EntryType eType = getEntryType( _pEntry );
    2336             : 
    2337             :     // the user data of the entry
    2338           0 :     DBTreeListUserData* pEntryData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData());
    2339             :     OSL_ENSURE(pEntryData,"ensureEntryObject: user data should already be set!");
    2340             : 
    2341           0 :     SvTreeListEntry* pDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent(_pEntry);
    2342             : 
    2343           0 :     sal_Bool bSuccess = sal_False;
    2344           0 :     switch (eType)
    2345             :     {
    2346             :         case etQueryContainer:
    2347           0 :             if ( pEntryData->xContainer.is() )
    2348             :             {
    2349             :                 // nothing to do
    2350           0 :                 bSuccess = sal_True;
    2351           0 :                 break;
    2352             :             }
    2353             : 
    2354             :             {
    2355           0 :                 SvTreeListEntry* pParent = m_pTreeView->getListBox().GetParent(_pEntry);
    2356           0 :                 if ( pParent != pDataSourceEntry )
    2357             :                 {
    2358           0 :                     SvLBoxString* pString = (SvLBoxString*)_pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
    2359             :                     OSL_ENSURE(pString,"There must be a string item!");
    2360           0 :                     ::rtl::OUString aName(pString->GetText());
    2361           0 :                     DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pParent->GetUserData());
    2362             :                     try
    2363             :                     {
    2364           0 :                         Reference< XNameAccess > xNameAccess(pData->xContainer,UNO_QUERY);
    2365           0 :                         if ( xNameAccess.is() )
    2366           0 :                             pEntryData->xContainer.set(xNameAccess->getByName(aName),UNO_QUERY);
    2367             :                     }
    2368           0 :                     catch(const Exception& )
    2369             :                     {
    2370             :                         DBG_UNHANDLED_EXCEPTION();
    2371             :                     }
    2372             : 
    2373           0 :                     bSuccess = pEntryData->xContainer.is();
    2374             :                 }
    2375             :                 else
    2376             :                 {
    2377             :                     try
    2378             :                     {
    2379           0 :                         Reference< XQueryDefinitionsSupplier > xQuerySup;
    2380           0 :                         m_xDatabaseContext->getByName( getDataSourceAcessor( pDataSourceEntry ) ) >>= xQuerySup;
    2381           0 :                         if (xQuerySup.is())
    2382             :                         {
    2383           0 :                             Reference< XNameAccess > xQueryDefs = xQuerySup->getQueryDefinitions();
    2384           0 :                             Reference< XContainer > xCont(xQueryDefs, UNO_QUERY);
    2385           0 :                             if (xCont.is())
    2386             :                                 // add as listener to get notified if elements are inserted or removed
    2387           0 :                                 xCont->addContainerListener(this);
    2388             : 
    2389           0 :                             pEntryData->xContainer = xQueryDefs;
    2390           0 :                             bSuccess = pEntryData->xContainer.is();
    2391             :                         }
    2392             :                         else {
    2393             :                             OSL_FAIL("SbaTableQueryBrowser::ensureEntryObject: no XQueryDefinitionsSupplier interface!");
    2394           0 :                         }
    2395             :                     }
    2396           0 :                     catch( const Exception& )
    2397             :                     {
    2398             :                         DBG_UNHANDLED_EXCEPTION();
    2399             :                     }
    2400             :                 }
    2401             :             }
    2402           0 :             break;
    2403             : 
    2404             :         default:
    2405             :             OSL_FAIL("SbaTableQueryBrowser::ensureEntryObject: ooops ... missing some implementation here!");
    2406             :             // TODO ...
    2407           0 :             break;
    2408             :     }
    2409             : 
    2410           0 :     return bSuccess;
    2411             : }
    2412             : //------------------------------------------------------------------------------
    2413           0 : sal_Bool SbaTableQueryBrowser::implSelect(const ::svx::ODataAccessDescriptor& _rDescriptor,sal_Bool _bSelectDirect)
    2414             : {
    2415             :     // extract the props
    2416           0 :     ::rtl::OUString sDataSource;
    2417           0 :     ::rtl::OUString sCommand;
    2418           0 :     sal_Int32 nCommandType = CommandType::COMMAND;
    2419           0 :     sal_Bool bEscapeProcessing = sal_True;
    2420           0 :     extractDescriptorProps(_rDescriptor, sDataSource, sCommand, nCommandType, bEscapeProcessing);
    2421             : 
    2422             :     // select it
    2423           0 :     return implSelect( sDataSource, sCommand, nCommandType, bEscapeProcessing, SharedConnection(), _bSelectDirect );
    2424             : }
    2425             : 
    2426             : //------------------------------------------------------------------------------
    2427           0 : sal_Bool SbaTableQueryBrowser::implLoadAnything(const ::rtl::OUString& _rDataSourceName, const ::rtl::OUString& _rCommand,
    2428             :     const sal_Int32 _nCommandType, const sal_Bool _bEscapeProcessing, const SharedConnection& _rxConnection)
    2429             : {
    2430             :     try
    2431             :     {
    2432           0 :         Reference<XPropertySet> xProp( getRowSet(), UNO_QUERY_THROW );
    2433           0 :         Reference< XLoadable >  xLoadable( xProp, UNO_QUERY_THROW );
    2434             :         // the values allowing the RowSet to re-execute
    2435           0 :         xProp->setPropertyValue(PROPERTY_DATASOURCENAME, makeAny(_rDataSourceName));
    2436           0 :         if(_rxConnection.is())
    2437           0 :             xProp->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( _rxConnection.getTyped() ) );
    2438             : 
    2439             :             // set this _before_ setting the connection, else the rowset would rebuild it ...
    2440           0 :         xProp->setPropertyValue(PROPERTY_COMMAND_TYPE, makeAny(_nCommandType));
    2441           0 :         xProp->setPropertyValue(PROPERTY_COMMAND, makeAny(_rCommand));
    2442           0 :         xProp->setPropertyValue(PROPERTY_ESCAPE_PROCESSING, ::cppu::bool2any(_bEscapeProcessing));
    2443           0 :         if ( m_bPreview )
    2444             :         {
    2445           0 :             xProp->setPropertyValue(PROPERTY_FETCHDIRECTION, makeAny(FetchDirection::FORWARD));
    2446             :         }
    2447             : 
    2448             :         // the formatter depends on the data source we're working on, so rebuild it here ...
    2449           0 :         initFormatter();
    2450             : 
    2451             :         // switch the grid to design mode while loading
    2452           0 :         getBrowserView()->getGridControl()->setDesignMode(sal_True);
    2453           0 :         InitializeForm( xProp );
    2454             : 
    2455           0 :         sal_Bool bSuccess = sal_True;
    2456             : 
    2457             :         {
    2458             :             {
    2459           0 :                 Reference< XNameContainer >  xColContainer(getFormComponent(), UNO_QUERY);
    2460             :                 // first we have to clear the grid
    2461           0 :                 clearGridColumns(xColContainer);
    2462             :             }
    2463           0 :             FormErrorHelper aHelper(this);
    2464             :             // load the form
    2465           0 :             bSuccess = reloadForm(xLoadable);
    2466             : 
    2467             :             // initialize the model
    2468           0 :             InitializeGridModel(getFormComponent());
    2469             : 
    2470           0 :             Any aVal = xProp->getPropertyValue(PROPERTY_ISNEW);
    2471           0 :             if (aVal.hasValue() && ::comphelper::getBOOL(aVal))
    2472             :             {
    2473             :                 // then set the default values and the parameters given from the parent
    2474           0 :                 Reference< XReset> xReset(xProp, UNO_QUERY);
    2475           0 :                 xReset->reset();
    2476             :             }
    2477             : 
    2478           0 :             if ( m_bPreview )
    2479           0 :                 initializePreviewMode();
    2480             : 
    2481           0 :             LoadFinished(sal_True);
    2482             :         }
    2483             : 
    2484           0 :         InvalidateAll();
    2485           0 :         return bSuccess;
    2486             :     }
    2487           0 :     catch( const SQLException& )
    2488             :     {
    2489           0 :         Any aException( ::cppu::getCaughtException() );
    2490           0 :         showError( SQLExceptionInfo( aException ) );
    2491             :     }
    2492           0 :     catch( const WrappedTargetException& e )
    2493             :     {
    2494           0 :         SQLException aSql;
    2495           0 :         if  ( e.TargetException.isExtractableTo( ::cppu::UnoType< SQLException >::get() ) )
    2496           0 :             showError( SQLExceptionInfo( e.TargetException ) );
    2497             :         else
    2498             :         {
    2499             :             DBG_UNHANDLED_EXCEPTION();
    2500           0 :         }
    2501             :     }
    2502           0 :     catch(const Exception&)
    2503             :     {
    2504             :         DBG_UNHANDLED_EXCEPTION();
    2505             :     }
    2506             : 
    2507           0 :     InvalidateAll();
    2508           0 :     return sal_False;
    2509             : }
    2510             : 
    2511             : //------------------------------------------------------------------------------
    2512           0 : sal_Bool SbaTableQueryBrowser::implSelect(const ::rtl::OUString& _rDataSourceName, const ::rtl::OUString& _rCommand,
    2513             :                                       const sal_Int32 _nCommandType, const sal_Bool _bEscapeProcessing,
    2514             :                                       const SharedConnection& _rxConnection
    2515             :                                       ,sal_Bool _bSelectDirect)
    2516             : {
    2517           0 :     if (_rDataSourceName.getLength() && _rCommand.getLength() && (-1 != _nCommandType))
    2518             :     {
    2519           0 :         SvTreeListEntry* pDataSource = NULL;
    2520           0 :         SvTreeListEntry* pCommandType = NULL;
    2521           0 :         SvTreeListEntry* pCommand = getObjectEntry( _rDataSourceName, _rCommand, _nCommandType, &pDataSource, &pCommandType, sal_True, _rxConnection );
    2522             : 
    2523           0 :         if (pCommand)
    2524             :         {
    2525           0 :             bool bSuccess = true;
    2526           0 :             if ( _bSelectDirect )
    2527             :             {
    2528           0 :                 bSuccess = implSelect( pCommand );
    2529             :             }
    2530             :             else
    2531             :             {
    2532           0 :                 m_pTreeView->getListBox().Select( pCommand );
    2533             :             }
    2534             : 
    2535           0 :             if ( bSuccess )
    2536             :             {
    2537           0 :                 m_pTreeView->getListBox().MakeVisible(pCommand);
    2538           0 :                 m_pTreeView->getListBox().SetCursor(pCommand);
    2539             :             }
    2540             :         }
    2541           0 :         else if (!pCommandType)
    2542             :         {
    2543           0 :             if ( m_pCurrentlyDisplayed )
    2544             :             {   // tell the old entry (if any) it has been deselected
    2545           0 :                 selectPath(m_pCurrentlyDisplayed, sal_False);
    2546           0 :                 m_pCurrentlyDisplayed = NULL;
    2547             :             }
    2548             : 
    2549             :             // we have a command and need to display this in the rowset
    2550           0 :             return implLoadAnything(_rDataSourceName, _rCommand, _nCommandType, _bEscapeProcessing, _rxConnection);
    2551             :         }
    2552             :     }
    2553           0 :     return sal_False;
    2554             : }
    2555             : 
    2556             : //------------------------------------------------------------------------------
    2557           0 : IMPL_LINK(SbaTableQueryBrowser, OnSelectionChange, void*, /*NOINTERESTEDIN*/)
    2558             : {
    2559           0 :     return implSelect( m_pTreeView->getListBox().FirstSelected() ) ? 1L : 0L;
    2560             : }
    2561             : //------------------------------------------------------------------------------
    2562           0 : SvTreeListEntry* SbaTableQueryBrowser::implGetConnectionEntry(SvTreeListEntry* _pEntry) const
    2563             : {
    2564           0 :     SvTreeListEntry* pCurrentEntry = _pEntry;
    2565           0 :     DBTreeListUserData* pEntryData = static_cast< DBTreeListUserData* >( pCurrentEntry->GetUserData() );
    2566           0 :     while(pEntryData->eType != etDatasource )
    2567             :     {
    2568           0 :         pCurrentEntry = m_pTreeModel->GetParent(pCurrentEntry);
    2569           0 :         pEntryData = static_cast< DBTreeListUserData* >( pCurrentEntry->GetUserData() );
    2570             :     }
    2571           0 :     return pCurrentEntry;
    2572             : }
    2573             : //------------------------------------------------------------------------------
    2574           0 : bool SbaTableQueryBrowser::implSelect( SvTreeListEntry* _pEntry )
    2575             : {
    2576           0 :     if ( !_pEntry )
    2577           0 :         return false;
    2578             : 
    2579           0 :     DBTreeListUserData* pEntryData = static_cast< DBTreeListUserData* >( _pEntry->GetUserData() );
    2580           0 :     switch (pEntryData->eType)
    2581             :     {
    2582             :         case etTableOrView:
    2583             :         case etQuery:
    2584           0 :             break;
    2585             :         default:
    2586             :             // nothing to do
    2587           0 :             return false;
    2588             :     }
    2589             : 
    2590             :     OSL_ENSURE(m_pTreeModel->HasParent(_pEntry), "SbaTableQueryBrowser::implSelect: invalid entry (1)!");
    2591             :     OSL_ENSURE(m_pTreeModel->HasParent(m_pTreeModel->GetParent(_pEntry)), "SbaTableQueryBrowser::implSelect: invalid entry (2)!");
    2592             : 
    2593             :     // get the entry for the tables or queries
    2594           0 :     SvTreeListEntry* pContainer = m_pTreeModel->GetParent(_pEntry);
    2595           0 :     DBTreeListUserData* pContainerData = static_cast<DBTreeListUserData*>(pContainer->GetUserData());
    2596             : 
    2597             :     // get the entry for the datasource
    2598           0 :     SvTreeListEntry* pConnection = implGetConnectionEntry(pContainer);
    2599           0 :     DBTreeListUserData* pConData = static_cast<DBTreeListUserData*>(pConnection->GetUserData());
    2600             : 
    2601             :     // reinitialize the rowset
    2602             :     // but first check if it is necessary
    2603             :     // get all old properties
    2604           0 :     Reference<XPropertySet> xRowSetProps(getRowSet(),UNO_QUERY);
    2605           0 :     ::rtl::OUString aOldName;
    2606           0 :     xRowSetProps->getPropertyValue(PROPERTY_COMMAND) >>= aOldName;
    2607           0 :     sal_Int32 nOldType = 0;
    2608           0 :     xRowSetProps->getPropertyValue(PROPERTY_COMMAND_TYPE) >>= nOldType;
    2609           0 :     Reference<XConnection> xOldConnection(xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION),UNO_QUERY);
    2610             : 
    2611             :     // the name of the table or query
    2612           0 :     SvLBoxString* pString = (SvLBoxString*)_pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
    2613             :     OSL_ENSURE(pString,"There must be a string item!");
    2614           0 :     const ::rtl::OUString sSimpleName = pString->GetText();
    2615           0 :     ::rtl::OUStringBuffer sNameBuffer(sSimpleName);
    2616           0 :     if ( etQueryContainer == pContainerData->eType )
    2617             :     {
    2618           0 :         SvTreeListEntry* pTemp = pContainer;
    2619           0 :         while( m_pTreeModel->GetParent(pTemp) != pConnection )
    2620             :         {
    2621           0 :             sNameBuffer.insert(0,sal_Unicode('/'));
    2622           0 :             pString = (SvLBoxString*)pTemp->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
    2623             :             OSL_ENSURE(pString,"There must be a string item!");
    2624           0 :             sNameBuffer.insert(0,pString->GetText());
    2625           0 :             pTemp = m_pTreeModel->GetParent(pTemp);
    2626             :         }
    2627             :     }
    2628           0 :     ::rtl::OUString aName = sNameBuffer.makeStringAndClear();
    2629             : 
    2630             :     sal_Int32 nCommandType =    ( etTableContainer == pContainerData->eType)
    2631             :                             ?   CommandType::TABLE
    2632           0 :                             :   CommandType::QUERY;
    2633             : 
    2634             :     // check if need to rebuild the rowset
    2635           0 :     sal_Bool bRebuild = ( xOldConnection != pConData->xConnection )
    2636             :                      || ( nOldType != nCommandType )
    2637           0 :                      || ( aName != aOldName );
    2638             : 
    2639           0 :     Reference< ::com::sun::star::form::XLoadable >  xLoadable = getLoadable();
    2640           0 :     bRebuild |= !xLoadable->isLoaded();
    2641           0 :     bool bSuccess = true;
    2642           0 :     if ( bRebuild )
    2643             :     {
    2644             :         try
    2645             :         {
    2646           0 :             WaitObject aWaitCursor(getBrowserView());
    2647             : 
    2648             :             // tell the old entry it has been deselected
    2649           0 :             selectPath(m_pCurrentlyDisplayed, sal_False);
    2650           0 :             m_pCurrentlyDisplayed = NULL;
    2651             : 
    2652             :             // not really loaded
    2653           0 :             m_pCurrentlyDisplayed = _pEntry;
    2654             :             // tell the new entry it has been selected
    2655           0 :             selectPath(m_pCurrentlyDisplayed, sal_True);
    2656             : 
    2657             :             // get the name of the data source currently selected
    2658           0 :             ensureConnection( m_pCurrentlyDisplayed, pConData->xConnection );
    2659             : 
    2660           0 :             if ( !pConData->xConnection.is() )
    2661             :             {
    2662           0 :                 unloadAndCleanup( sal_False );
    2663           0 :                 return false;
    2664             :             }
    2665             : 
    2666           0 :             Reference<XNameAccess> xNameAccess;
    2667           0 :             switch(nCommandType)
    2668             :             {
    2669             :                 case CommandType::TABLE:
    2670             :                     {
    2671             :                         // only for tables
    2672           0 :                         if ( !pContainerData->xContainer.is() )
    2673             :                         {
    2674           0 :                             Reference<XTablesSupplier> xSup( pConData->xConnection, UNO_QUERY );
    2675           0 :                             if(xSup.is())
    2676           0 :                                 xNameAccess = xSup->getTables();
    2677             : 
    2678           0 :                             pContainerData->xContainer = xNameAccess;
    2679             :                         }
    2680             :                         else
    2681           0 :                             xNameAccess.set( pContainerData->xContainer, UNO_QUERY );
    2682             :                     }
    2683           0 :                     break;
    2684             :                 case CommandType::QUERY:
    2685             :                     {
    2686           0 :                         if ( pContainerData->xContainer.is() )
    2687           0 :                             xNameAccess.set( pContainerData->xContainer, UNO_QUERY );
    2688             :                         else
    2689             :                         {
    2690           0 :                             Reference<XQueriesSupplier> xSup( pConData->xConnection, UNO_QUERY );
    2691           0 :                             if(xSup.is())
    2692           0 :                                 xNameAccess = xSup->getQueries();
    2693             :                         }
    2694             :                     }
    2695           0 :                     break;
    2696             :             }
    2697           0 :             String sStatus(ModuleRes( CommandType::TABLE == nCommandType ? STR_LOADING_TABLE : STR_LOADING_QUERY ));
    2698           0 :             sStatus.SearchAndReplaceAscii("$name$", aName);
    2699           0 :             BrowserViewStatusDisplay aShowStatus(static_cast<UnoDataBrowserView*>(getView()), sStatus);
    2700             : 
    2701             : 
    2702           0 :             sal_Bool bEscapeProcessing = sal_True;
    2703           0 :             if(xNameAccess.is() && xNameAccess->hasByName(sSimpleName))
    2704             :             {
    2705           0 :                 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData());
    2706           0 :                 if ( !pData->xObjectProperties.is() )
    2707             :                 {
    2708           0 :                     Reference<XInterface> xObject;
    2709           0 :                     if(xNameAccess->getByName(sSimpleName) >>= xObject) // remember the table or query object
    2710             :                     {
    2711           0 :                         pData->xObjectProperties = pData->xObjectProperties.query( xObject );
    2712             :                         // if the query contains a parameterized statement and preview is enabled we won't get any data.
    2713           0 :                         if ( nCommandType == CommandType::QUERY && xObject.is() )
    2714             :                         {
    2715           0 :                             Reference<XPropertySet> xObjectProps(xObject,UNO_QUERY);
    2716           0 :                             xObjectProps->getPropertyValue(PROPERTY_ESCAPE_PROCESSING) >>= bEscapeProcessing;
    2717           0 :                             if ( m_bPreview )
    2718             :                             {
    2719           0 :                                 ::rtl::OUString sSql;
    2720           0 :                                 xObjectProps->getPropertyValue(PROPERTY_COMMAND) >>= sSql;
    2721           0 :                                 Reference< XMultiServiceFactory >  xFactory( pConData->xConnection, UNO_QUERY );
    2722           0 :                                 if (xFactory.is())
    2723             :                                 {
    2724             :                                     try
    2725             :                                     {
    2726           0 :                                         Reference<XSingleSelectQueryAnalyzer> xAnalyzer(xFactory->createInstance(SERVICE_NAME_SINGLESELECTQUERYCOMPOSER),UNO_QUERY);
    2727           0 :                                         if ( xAnalyzer.is() )
    2728             :                                         {
    2729           0 :                                             xAnalyzer->setQuery(sSql);
    2730           0 :                                             Reference<XParametersSupplier> xParSup(xAnalyzer,UNO_QUERY);
    2731           0 :                                             if ( xParSup->getParameters()->getCount() > 0 )
    2732             :                                             {
    2733           0 :                                                 String sFilter = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" WHERE "));
    2734           0 :                                                 sFilter = sFilter + xAnalyzer->getFilter();
    2735           0 :                                                 String sReplace(sSql);
    2736           0 :                                                 sReplace.SearchAndReplace(sFilter,String());
    2737           0 :                                                 xAnalyzer->setQuery(sReplace);
    2738           0 :                                                 Reference<XSingleSelectQueryComposer> xComposer(xAnalyzer,UNO_QUERY);
    2739           0 :                                                 xComposer->setFilter(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0=1")));
    2740           0 :                                                 aName = xAnalyzer->getQuery();
    2741           0 :                                                 nCommandType = CommandType::COMMAND;
    2742           0 :                                             }
    2743           0 :                                         }
    2744             :                                     }
    2745           0 :                                     catch (Exception&)
    2746             :                                     {
    2747             :                                         DBG_UNHANDLED_EXCEPTION();
    2748             :                                     }
    2749           0 :                                 }
    2750           0 :                             }
    2751             :                         }
    2752           0 :                     }
    2753             :                 }
    2754             :             }
    2755             : 
    2756           0 :             String sDataSourceName( getDataSourceAcessor( pConnection ) );
    2757           0 :             bSuccess = implLoadAnything( sDataSourceName, aName, nCommandType, bEscapeProcessing, pConData->xConnection );
    2758           0 :             if ( !bSuccess )
    2759             :             {   // clean up
    2760           0 :                 criticalFail();
    2761           0 :             }
    2762             :         }
    2763           0 :         catch(const SQLException& e)
    2764             :         {
    2765           0 :             showError(SQLExceptionInfo(e));
    2766             :             // reset the values
    2767           0 :             xRowSetProps->setPropertyValue(PROPERTY_DATASOURCENAME,Any());
    2768           0 :             xRowSetProps->setPropertyValue(PROPERTY_ACTIVE_CONNECTION,Any());
    2769             :         }
    2770           0 :         catch(WrappedTargetException& e)
    2771             :         {
    2772           0 :             SQLException aSql;
    2773           0 :             if(e.TargetException >>= aSql)
    2774           0 :                 showError(SQLExceptionInfo(aSql));
    2775             :             else
    2776             :                 OSL_FAIL("SbaTableQueryBrowser::implSelect: something strange happended!");
    2777             :             // reset the values
    2778           0 :             xRowSetProps->setPropertyValue(PROPERTY_DATASOURCENAME,Any());
    2779           0 :             xRowSetProps->setPropertyValue(PROPERTY_ACTIVE_CONNECTION,Any());
    2780             :         }
    2781           0 :         catch(const Exception&)
    2782             :         {
    2783             :             // reset the values
    2784           0 :             xRowSetProps->setPropertyValue(PROPERTY_DATASOURCENAME,Any());
    2785           0 :             xRowSetProps->setPropertyValue(PROPERTY_ACTIVE_CONNECTION,Any());
    2786             :         }
    2787             :     }
    2788           0 :     return bSuccess;
    2789             : }
    2790             : 
    2791             : // -----------------------------------------------------------------------------
    2792           0 : SvTreeListEntry* SbaTableQueryBrowser::getEntryFromContainer(const Reference<XNameAccess>& _rxNameAccess)
    2793             : {
    2794           0 :     DBTreeListBox& rListBox = m_pTreeView->getListBox();
    2795           0 :     SvTreeListEntry* pContainer = NULL;
    2796           0 :     SvTreeListEntry* pDSLoop = rListBox.FirstChild(NULL);
    2797           0 :     while (pDSLoop)
    2798             :     {
    2799           0 :         pContainer  = rListBox.GetEntry(pDSLoop, CONTAINER_QUERIES);
    2800           0 :         DBTreeListUserData* pQueriesData = static_cast<DBTreeListUserData*>(pContainer->GetUserData());
    2801           0 :         if ( pQueriesData && pQueriesData->xContainer == _rxNameAccess )
    2802           0 :             break;
    2803             : 
    2804           0 :         pContainer  = rListBox.GetEntry(pDSLoop, CONTAINER_TABLES);
    2805           0 :         DBTreeListUserData* pTablesData = static_cast<DBTreeListUserData*>(pContainer->GetUserData());
    2806           0 :         if ( pTablesData && pTablesData->xContainer == _rxNameAccess )
    2807           0 :             break;
    2808             : 
    2809           0 :         pDSLoop     = rListBox.NextSibling(pDSLoop);
    2810           0 :         pContainer  = NULL;
    2811             :     }
    2812           0 :     return pContainer;
    2813             : }
    2814             : 
    2815             : // -------------------------------------------------------------------------
    2816           0 : void SAL_CALL SbaTableQueryBrowser::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
    2817             : {
    2818           0 :     SolarMutexGuard aSolarGuard;
    2819             : 
    2820           0 :     Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
    2821             :     // first search for a definition container where we can insert this element
    2822             : 
    2823           0 :     SvTreeListEntry* pEntry = getEntryFromContainer(xNames);
    2824           0 :     if(pEntry)  // found one
    2825             :     {
    2826             :         // insert the new entry into the tree
    2827           0 :         DBTreeListUserData* pContainerData = static_cast<DBTreeListUserData*>(pEntry->GetUserData());
    2828             :         OSL_ENSURE(pContainerData, "elementInserted: There must be user data for this type!");
    2829             : 
    2830           0 :         DBTreeListUserData* pNewData = new DBTreeListUserData;
    2831           0 :         sal_Bool bIsTable = etTableContainer == pContainerData->eType;
    2832           0 :         if ( bIsTable )
    2833             :         {
    2834           0 :             _rEvent.Element >>= pNewData->xObjectProperties;// remember the new element
    2835           0 :             pNewData->eType = etTableOrView;
    2836             :         }
    2837             :         else
    2838             :         {
    2839           0 :             if ((sal_Int32)m_pTreeView->getListBox().GetChildCount(pEntry) < ( xNames->getElementNames().getLength() - 1 ) )
    2840             :             {
    2841             :                 // the item inserts its children on demand, but it has not been expanded yet. So ensure here and
    2842             :                 // now that it has all items
    2843           0 :                 populateTree(xNames, pEntry, etQuery );
    2844             :             }
    2845           0 :             pNewData->eType = etQuery;
    2846             :         }
    2847           0 :         implAppendEntry( pEntry, ::comphelper::getString( _rEvent.Accessor ), pNewData, pNewData->eType );
    2848             :     }
    2849             :     else
    2850           0 :         SbaXDataBrowserController::elementInserted(_rEvent);
    2851           0 : }
    2852             : // -------------------------------------------------------------------------
    2853           0 : sal_Bool SbaTableQueryBrowser::isCurrentlyDisplayedChanged(const String& _sName,SvTreeListEntry* _pContainer)
    2854             : {
    2855             :     return m_pCurrentlyDisplayed
    2856           0 :             &&  getEntryType(m_pCurrentlyDisplayed) == getChildType(_pContainer)
    2857           0 :             &&  m_pTreeView->getListBox().GetParent(m_pCurrentlyDisplayed) == _pContainer
    2858           0 :             &&  m_pTreeView->getListBox().GetEntryText(m_pCurrentlyDisplayed) == _sName;
    2859             : }
    2860             : // -------------------------------------------------------------------------
    2861           0 : void SAL_CALL SbaTableQueryBrowser::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
    2862             : {
    2863           0 :     SolarMutexGuard aSolarGuard;
    2864             : 
    2865           0 :     Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
    2866             :     // get the top-level representing the removed data source
    2867             :     // and search for the queries and tables
    2868           0 :     SvTreeListEntry* pContainer = getEntryFromContainer(xNames);
    2869           0 :     if ( pContainer )
    2870             :     { // a query or table has been removed
    2871           0 :         String aName = ::comphelper::getString(_rEvent.Accessor);
    2872             : 
    2873           0 :         if ( isCurrentlyDisplayedChanged( aName, pContainer) )
    2874             :         {   // the element displayed currently has been replaced
    2875             : 
    2876             :             // we need to remember the old value
    2877           0 :             SvTreeListEntry* pTemp = m_pCurrentlyDisplayed;
    2878             : 
    2879             :             // unload
    2880           0 :             unloadAndCleanup( sal_False ); // don't dispose the connection
    2881             : 
    2882           0 :             DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pTemp->GetUserData());
    2883           0 :             pTemp->SetUserData(NULL);
    2884           0 :             delete pData;
    2885             :                 // the data could be null because we have a table which isn't correct
    2886           0 :             m_pTreeModel->Remove(pTemp);
    2887             :         }
    2888             :         else
    2889             :         {
    2890             :             // remove the entry from the model
    2891           0 :             SvTreeListEntry* pChild = m_pTreeModel->FirstChild(pContainer);
    2892           0 :             while(pChild)
    2893             :             {
    2894           0 :                 if (m_pTreeView->getListBox().GetEntryText(pChild) == aName)
    2895             :                 {
    2896           0 :                     DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pChild->GetUserData());
    2897           0 :                     pChild->SetUserData(NULL);
    2898           0 :                     delete pData;
    2899           0 :                     m_pTreeModel->Remove(pChild);
    2900           0 :                     break;
    2901             :                 }
    2902           0 :                 pChild = m_pTreeModel->NextSibling(pChild);
    2903             :             }
    2904             :         }
    2905             : 
    2906             :         // maybe the object which is part of the document data source has been removed
    2907           0 :         checkDocumentDataSource();
    2908             :     }
    2909             :     else
    2910           0 :         SbaXDataBrowserController::elementRemoved(_rEvent);
    2911           0 : }
    2912             : 
    2913             : // -------------------------------------------------------------------------
    2914           0 : void SAL_CALL SbaTableQueryBrowser::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
    2915             : {
    2916           0 :     SolarMutexGuard aSolarGuard;
    2917             : 
    2918           0 :     Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
    2919           0 :     SvTreeListEntry* pContainer = getEntryFromContainer(xNames);
    2920           0 :     if ( pContainer )
    2921             :     {    // a table or query as been replaced
    2922           0 :         String aName = ::comphelper::getString(_rEvent.Accessor);
    2923             : 
    2924           0 :         if ( isCurrentlyDisplayedChanged( aName, pContainer) )
    2925             :         {   // the element displayed currently has been replaced
    2926             : 
    2927             :             // we need to remember the old value
    2928           0 :             SvTreeListEntry* pTemp = m_pCurrentlyDisplayed;
    2929           0 :             unloadAndCleanup( sal_False ); // don't dispose the connection
    2930             : 
    2931           0 :             DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pTemp->GetUserData());
    2932           0 :             if (pData)
    2933             :             {
    2934           0 :                 if ( etTableOrView == pData->eType )
    2935             :                 { // only insert userdata when we have a table because the query is only a commanddefinition object and not a query
    2936           0 :                      _rEvent.Element >>= pData->xObjectProperties;  // remember the new element
    2937             :                 }
    2938             :                 else
    2939             :                 {
    2940           0 :                     pTemp->SetUserData(NULL);
    2941           0 :                     delete pData;
    2942             :                 }
    2943             :             }
    2944             :         }
    2945             :         else
    2946             :         {
    2947             :             // find the entry for this name
    2948           0 :             SvTreeListEntry* pChild = m_pTreeModel->FirstChild(pContainer);
    2949           0 :             while(pChild)
    2950             :             {
    2951           0 :                 if (m_pTreeView->getListBox().GetEntryText(pChild) == aName)
    2952             :                 {
    2953           0 :                     DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pChild->GetUserData());
    2954           0 :                     if (pData)
    2955             :                     {
    2956           0 :                         if ( etTableOrView == pData->eType )
    2957             :                         { // only insert userdata when we have a table because the query is only a commanddefinition object and not a query
    2958           0 :                             _rEvent.Element >>= pData->xObjectProperties;   // remember the new element
    2959             :                         }
    2960             :                         else
    2961             :                         {
    2962           0 :                             pChild->SetUserData(NULL);
    2963           0 :                             delete pData;
    2964             :                         }
    2965             :                     }
    2966           0 :                     break;
    2967             :                 }
    2968           0 :                 pChild = m_pTreeModel->NextSibling(pChild);
    2969             :             }
    2970             :         }
    2971             : 
    2972             :         // maybe the object which is part of the document data source has been removed
    2973           0 :         checkDocumentDataSource();
    2974             :     }
    2975           0 :     else if (xNames.get() == m_xDatabaseContext.get())
    2976             :     {   // a datasource has been replaced in the context
    2977             :         OSL_FAIL("SbaTableQueryBrowser::elementReplaced: no support for replaced data sources!");
    2978             :             // very suspicious: the database context should not allow to replace data source, only to register
    2979             :             // and revoke them
    2980             :     }
    2981             :     else
    2982           0 :         SbaXDataBrowserController::elementReplaced(_rEvent);
    2983           0 : }
    2984             : 
    2985             : // -------------------------------------------------------------------------
    2986           0 : void SbaTableQueryBrowser::impl_releaseConnection( SharedConnection& _rxConnection )
    2987             : {
    2988             :     // remove as event listener
    2989           0 :     Reference< XComponent > xComponent( _rxConnection, UNO_QUERY );
    2990           0 :     if ( xComponent.is() )
    2991             :     {
    2992           0 :         Reference< XEventListener > xListener( static_cast< ::cppu::OWeakObject* >( this ), UNO_QUERY );
    2993           0 :         xComponent->removeEventListener( xListener );
    2994             :     }
    2995             : 
    2996             :     try
    2997             :     {
    2998             :         // temporary (hopefully!) hack for #i55274#
    2999           0 :         Reference< XFlushable > xFlush( _rxConnection, UNO_QUERY );
    3000           0 :         if ( xFlush.is() )
    3001           0 :             xFlush->flush();
    3002             :     }
    3003           0 :     catch( const Exception& )
    3004             :     {
    3005             :         DBG_UNHANDLED_EXCEPTION();
    3006             :     }
    3007             : 
    3008             :     // clear
    3009           0 :     _rxConnection.clear();
    3010             :         // will implicitly dispose if we have the ownership, since xConnection is a SharedConnection
    3011           0 : }
    3012             : 
    3013             : // -------------------------------------------------------------------------
    3014           0 : void SbaTableQueryBrowser::disposeConnection( SvTreeListEntry* _pDSEntry )
    3015             : {
    3016             :     OSL_ENSURE( _pDSEntry, "SbaTableQueryBrowser::disposeConnection: invalid entry (NULL)!" );
    3017             :     OSL_ENSURE( impl_isDataSourceEntry( _pDSEntry ), "SbaTableQueryBrowser::disposeConnection: invalid entry (not top-level)!" );
    3018             : 
    3019           0 :     if ( _pDSEntry )
    3020             :     {
    3021           0 :         DBTreeListUserData* pTreeListData = static_cast< DBTreeListUserData* >( _pDSEntry->GetUserData() );
    3022           0 :         if ( pTreeListData )
    3023           0 :             impl_releaseConnection( pTreeListData->xConnection );
    3024             :     }
    3025           0 : }
    3026             : 
    3027             : // -------------------------------------------------------------------------
    3028           0 : void SbaTableQueryBrowser::closeConnection(SvTreeListEntry* _pDSEntry,sal_Bool _bDisposeConnection)
    3029             : {
    3030             :     OSL_ENSURE(_pDSEntry, "SbaTableQueryBrowser::closeConnection: invalid entry (NULL)!");
    3031             :     OSL_ENSURE( impl_isDataSourceEntry( _pDSEntry ), "SbaTableQueryBrowser::closeConnection: invalid entry (not top-level)!");
    3032             : 
    3033             :     // if one of the entries of the given DS is displayed currently, unload the form
    3034           0 :     if (m_pCurrentlyDisplayed && (m_pTreeView->getListBox().GetRootLevelParent(m_pCurrentlyDisplayed) == _pDSEntry))
    3035           0 :         unloadAndCleanup(_bDisposeConnection);
    3036             : 
    3037             :     // collapse the query/table container
    3038           0 :     for (SvTreeListEntry* pContainers = m_pTreeModel->FirstChild(_pDSEntry); pContainers; pContainers= m_pTreeModel->NextSibling(pContainers))
    3039             :     {
    3040           0 :         SvTreeListEntry* pElements = m_pTreeModel->FirstChild(pContainers);
    3041           0 :         if ( pElements )
    3042           0 :             m_pTreeView->getListBox().Collapse(pContainers);
    3043           0 :         m_pTreeView->getListBox().EnableExpandHandler(pContainers);
    3044             :         // and delete their children (they are connection-relative)
    3045           0 :         for (; pElements; )
    3046             :         {
    3047           0 :             SvTreeListEntry* pRemove = pElements;
    3048           0 :             pElements= m_pTreeModel->NextSibling(pElements);
    3049           0 :             DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pRemove->GetUserData());
    3050           0 :             pRemove->SetUserData(NULL);
    3051           0 :             delete pData;
    3052           0 :             m_pTreeModel->Remove(pRemove);
    3053             :         }
    3054             :     }
    3055             :     // collapse the entry itself
    3056           0 :     m_pTreeView->getListBox().Collapse(_pDSEntry);
    3057             : 
    3058             :     // dispose/reset the connection
    3059           0 :     if ( _bDisposeConnection )
    3060           0 :         disposeConnection( _pDSEntry );
    3061           0 : }
    3062             : 
    3063             : // -------------------------------------------------------------------------
    3064           0 : void SbaTableQueryBrowser::unloadAndCleanup( sal_Bool _bDisposeConnection )
    3065             : {
    3066           0 :     if (!m_pCurrentlyDisplayed)
    3067             :         // nothing to do
    3068           0 :         return;
    3069             : 
    3070           0 :     SvTreeListEntry* pDSEntry = m_pTreeView->getListBox().GetRootLevelParent(m_pCurrentlyDisplayed);
    3071             : 
    3072             :     // de-select the path for the currently displayed table/query
    3073           0 :     if (m_pCurrentlyDisplayed)
    3074             :     {
    3075           0 :         selectPath(m_pCurrentlyDisplayed, sal_False);
    3076             :     }
    3077           0 :     m_pCurrentlyDisplayed = NULL;
    3078             : 
    3079             :     try
    3080             :     {
    3081             :         // get the active connection. We need to dispose it.
    3082           0 :         Reference< XPropertySet > xRowSetProps(getRowSet(),UNO_QUERY);
    3083           0 :         Reference< XConnection > xConn;
    3084           0 :         xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION) >>= xConn;
    3085             : #if OSL_DEBUG_LEVEL > 1
    3086             :         {
    3087             :             Reference< XComponent > xComp;
    3088             :             ::cppu::extractInterface(xComp, xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION));
    3089             :         }
    3090             : #endif
    3091             : 
    3092             :         // unload the form
    3093           0 :         Reference< XLoadable > xLoadable = getLoadable();
    3094           0 :         if (xLoadable->isLoaded())
    3095           0 :             xLoadable->unload();
    3096             : 
    3097             :         // clear the grid control
    3098           0 :         Reference< XNameContainer > xConta(getControlModel(),UNO_QUERY);
    3099           0 :         clearGridColumns(xConta);
    3100             : 
    3101             :         // dispose the connection
    3102           0 :         if(_bDisposeConnection)
    3103           0 :             disposeConnection( pDSEntry );
    3104             :     }
    3105           0 :     catch(SQLException& e)
    3106             :     {
    3107           0 :         showError(SQLExceptionInfo(e));
    3108             :     }
    3109           0 :     catch(WrappedTargetException& e)
    3110             :     {
    3111           0 :         SQLException aSql;
    3112           0 :         if(e.TargetException >>= aSql)
    3113           0 :             showError(SQLExceptionInfo(aSql));
    3114             :         else
    3115           0 :             OSL_FAIL("SbaTableQueryBrowser::unloadAndCleanup: something strange happended!");
    3116             :     }
    3117           0 :     catch(const Exception&)
    3118             :     {
    3119             :         OSL_FAIL("SbaTableQueryBrowser::unloadAndCleanup: could not reset the form");
    3120             :     }
    3121             : }
    3122             : 
    3123             : // -------------------------------------------------------------------------
    3124             : namespace
    3125             : {
    3126           0 :     Reference< XInterface > lcl_getDataSource( const Reference< XDatabaseContext >& _rxDatabaseContext,
    3127             :         const ::rtl::OUString& _rDataSourceName, const Reference< XConnection >& _rxConnection )
    3128             :     {
    3129           0 :         Reference< XDataSource > xDataSource;
    3130             :         try
    3131             :         {
    3132           0 :             if ( !_rDataSourceName.isEmpty() && _rxDatabaseContext->hasByName( _rDataSourceName ) )
    3133           0 :                 xDataSource.set( _rxDatabaseContext->getByName( _rDataSourceName ), UNO_QUERY_THROW );
    3134             : 
    3135           0 :             if ( !xDataSource.is() )
    3136             :             {
    3137           0 :                 Reference< XChild > xConnAsChild( _rxConnection, UNO_QUERY );
    3138           0 :                 if ( xConnAsChild.is() )
    3139           0 :                     xDataSource.set( xConnAsChild->getParent(), UNO_QUERY_THROW );
    3140             :             }
    3141             :         }
    3142           0 :         catch( const Exception& )
    3143             :         {
    3144             :             DBG_UNHANDLED_EXCEPTION();
    3145             :         }
    3146           0 :         return xDataSource.get();
    3147             :     }
    3148             : }
    3149             : 
    3150             : // -------------------------------------------------------------------------
    3151           0 : void SbaTableQueryBrowser::impl_initialize()
    3152             : {
    3153           0 :     SolarMutexGuard aGuard;
    3154             :         // doin' a lot of VCL stuff here -> lock the SolarMutex
    3155             : 
    3156             :     // first initialize the parent
    3157           0 :     SbaXDataBrowserController::impl_initialize();
    3158             : 
    3159           0 :     Reference<XConnection> xForeignConnection;
    3160           0 :     Reference< XFrame > xFrame;
    3161             : 
    3162           0 :     ::rtl::OUString aTableName, aCatalogName, aSchemaName;
    3163             : 
    3164           0 :     sal_Bool bEsacpeProcessing = sal_True;
    3165           0 :     sal_Int32 nInitialDisplayCommandType = CommandType::COMMAND;
    3166           0 :     ::rtl::OUString sInitialDataSourceName;
    3167           0 :     ::rtl::OUString sInitialCommand;
    3168             : 
    3169           0 :     const NamedValueCollection& rArguments( getInitParams() );
    3170             : 
    3171           0 :     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_DATASOURCENAME, sInitialDataSourceName );
    3172           0 :     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_COMMAND_TYPE, nInitialDisplayCommandType );
    3173           0 :     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_COMMAND, sInitialCommand );
    3174           0 :     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, xForeignConnection );
    3175           0 :     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_UPDATE_CATALOGNAME, aCatalogName );
    3176           0 :     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_UPDATE_SCHEMANAME, aSchemaName );
    3177           0 :     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_UPDATE_TABLENAME, aTableName );
    3178           0 :     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, bEsacpeProcessing );
    3179           0 :     rArguments.get_ensureType( "Frame", xFrame );
    3180           0 :     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_SHOWMENU, m_bShowMenu );
    3181             : 
    3182             :     // disable the browser if either of ShowTreeViewButton (compatibility name) or EnableBrowser
    3183             :     // is present and set to FALSE
    3184           0 :     sal_Bool bDisableBrowser =  ( sal_False == rArguments.getOrDefault( "ShowTreeViewButton", sal_True ) )   // compatibility name
    3185           0 :                             ||  ( sal_False == rArguments.getOrDefault( (::rtl::OUString)PROPERTY_ENABLE_BROWSER, sal_True ) );
    3186             :     OSL_ENSURE( !rArguments.has( "ShowTreeViewButton" ),
    3187             :         "SbaTableQueryBrowser::impl_initialize: ShowTreeViewButton is superseded by EnableBrowser!" );
    3188           0 :     m_bEnableBrowser = !bDisableBrowser;
    3189             : 
    3190             :     // hide the tree view it is disabled in general, or if the settings tell to hide it initially
    3191           0 :     sal_Bool bHideTreeView =    ( !m_bEnableBrowser )
    3192           0 :                             ||  ( sal_False == rArguments.getOrDefault( "ShowTreeView", sal_True ) )  // compatibility name
    3193           0 :                             ||  ( sal_False == rArguments.getOrDefault( (::rtl::OUString)PROPERTY_SHOW_BROWSER, sal_True ) );
    3194             :     OSL_ENSURE( !rArguments.has( "ShowTreeView" ),
    3195             :         "SbaTableQueryBrowser::impl_initialize: ShowTreeView is superseded by ShowBrowser!" );
    3196             : 
    3197           0 :     if ( bHideTreeView )
    3198           0 :         hideExplorer();
    3199             :     else
    3200           0 :         showExplorer();
    3201             : 
    3202           0 :     if ( m_bPreview )
    3203             :     {
    3204             :         try
    3205             :         {
    3206           0 :             Sequence< ::rtl::OUString> aProperties(5);
    3207           0 :             Sequence< Any> aValues(5);
    3208             : 
    3209           0 :             ::rtl::OUString* pStringIter = aProperties.getArray();
    3210           0 :             Any* pValueIter = aValues.getArray();
    3211           0 :             *pStringIter++  = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AlwaysShowCursor"));
    3212           0 :             *pValueIter++   <<= sal_False;
    3213           0 :             *pStringIter++  = PROPERTY_BORDER;
    3214           0 :             *pValueIter++   <<= sal_Int16(0);
    3215             : 
    3216           0 :             *pStringIter++  = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasNavigationBar"));
    3217           0 :             *pValueIter++       <<= sal_False;
    3218           0 :             *pStringIter++  = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasRecordMarker"));
    3219           0 :             *pValueIter++       <<= sal_False;
    3220             : 
    3221           0 :             *pStringIter++  = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tabstop"));
    3222           0 :             *pValueIter++       <<= sal_False;
    3223             : 
    3224           0 :             Reference< XMultiPropertySet >  xFormMultiSet(getFormComponent(), UNO_QUERY);
    3225           0 :             if ( xFormMultiSet.is() )
    3226           0 :                 xFormMultiSet->setPropertyValues(aProperties, aValues);
    3227             :         }
    3228           0 :         catch(const Exception&)
    3229             :         {
    3230             :             DBG_UNHANDLED_EXCEPTION();
    3231             :         }
    3232             :     }
    3233             : 
    3234             :     // are we loaded into a (sub)frame of an embedded document (i.e. a form belonging to a database
    3235             :     // document)?
    3236           0 :     sal_Bool bSubFrameOfEmbeddedDocument = sal_False;
    3237           0 :     if ( xFrame.is() )
    3238             :     {
    3239           0 :         Reference<XFramesSupplier> xSup = xFrame->getCreator();
    3240           0 :         Reference<XController> xCont = xSup.is() ? xSup->getController() : Reference<XController>();
    3241             : 
    3242           0 :         bSubFrameOfEmbeddedDocument = xCont.is() && ::dbtools::isEmbeddedInDatabase( xCont->getModel(), xForeignConnection );
    3243             :     }
    3244             : 
    3245             :     // if we have a connection at this point, it was either passed from outside, our
    3246             :     // determined from a outer DB document. In both cases, do not dispose it later on.
    3247           0 :     SharedConnection xConnection( xForeignConnection, SharedConnection::NoTakeOwnership );
    3248             : 
    3249             :     // should we display all registered databases in the left hand side tree?
    3250             :     // or only *one* special?
    3251           0 :     sal_Bool bLimitedTreeEntries = sal_False;
    3252             :     // if we're part of a frame which is a secondary frame of a database document, then only
    3253             :     // display the database for this document, not all registered ones
    3254           0 :     bLimitedTreeEntries |= bSubFrameOfEmbeddedDocument;
    3255             :     // if the tree view is not to be displayed at all, then only display the data source
    3256             :     // which was given as initial selection
    3257           0 :     bLimitedTreeEntries |= ( m_bEnableBrowser != sal_True );
    3258             : 
    3259           0 :     if ( bLimitedTreeEntries )
    3260             :     {
    3261           0 :         if ( xConnection.is() )
    3262             :         {
    3263           0 :             startConnectionListening( xConnection );
    3264             : 
    3265             :             // if no initial name was given, try to obtain one from the data source
    3266           0 :             if ( sInitialDataSourceName.isEmpty() )
    3267             :             {
    3268           0 :                 Reference< XChild > xChild( xConnection, UNO_QUERY );
    3269           0 :                 Reference< XPropertySet > xDataSourceProperties;
    3270           0 :                 if ( xChild.is() )
    3271           0 :                     xDataSourceProperties = xDataSourceProperties.query( xChild->getParent() );
    3272           0 :                 if ( xDataSourceProperties.is() )
    3273             :                 {
    3274             :                     try
    3275             :                     {
    3276           0 :                         OSL_VERIFY( xDataSourceProperties->getPropertyValue( PROPERTY_NAME ) >>= sInitialDataSourceName );
    3277             :                     }
    3278           0 :                     catch( const Exception& )
    3279             :                     {
    3280             :                         OSL_FAIL( "SbaTableQueryBrowser::impl_initialize: a connection parent which does not have a 'Name'!??" );
    3281             :                     }
    3282           0 :                 }
    3283             :             }
    3284             :         }
    3285             : 
    3286           0 :         implAddDatasource( sInitialDataSourceName, xConnection );
    3287           0 :         m_pTreeView->getListBox().Expand( m_pTreeView->getListBox().First() );
    3288             :     }
    3289             :     else
    3290           0 :         initializeTreeModel();
    3291             : 
    3292           0 :     if ( m_bEnableBrowser )
    3293             :     {
    3294           0 :         m_aDocScriptSupport = ::boost::optional< bool >( false );
    3295             :     }
    3296             :     else
    3297             :     {
    3298             :         // we are not used as "browser", but as mere view for a single table/query/command. In particular,
    3299             :         // there is a specific database document which we belong to.
    3300             :         Reference< XOfficeDatabaseDocument > xDocument( getDataSourceOrModel(
    3301           0 :             lcl_getDataSource( m_xDatabaseContext, sInitialDataSourceName, xConnection ) ), UNO_QUERY );
    3302           0 :         m_aDocScriptSupport = ::boost::optional< bool >( Reference< XEmbeddedScripts >( xDocument, UNO_QUERY ).is() );
    3303             :     }
    3304             : 
    3305           0 :     if ( implSelect( sInitialDataSourceName, sInitialCommand, nInitialDisplayCommandType, bEsacpeProcessing, xConnection, sal_True ) )
    3306             :     {
    3307             :         try
    3308             :         {
    3309           0 :             Reference< XPropertySet > xRowSetProps(getRowSet(), UNO_QUERY);
    3310           0 :             xRowSetProps->setPropertyValue(PROPERTY_UPDATE_CATALOGNAME,makeAny(aCatalogName));
    3311           0 :             xRowSetProps->setPropertyValue(PROPERTY_UPDATE_SCHEMANAME,makeAny(aSchemaName));
    3312           0 :             xRowSetProps->setPropertyValue(PROPERTY_UPDATE_TABLENAME,makeAny(aTableName));
    3313             : 
    3314             :         }
    3315           0 :         catch(const Exception&)
    3316             :         {
    3317             :             OSL_FAIL("SbaTableQueryBrowser::impl_initialize: could not set the update related names!");
    3318             :         }
    3319             :     }
    3320             : 
    3321           0 :     InvalidateAll();
    3322           0 : }
    3323             : 
    3324             : // -------------------------------------------------------------------------
    3325           0 : sal_Bool SbaTableQueryBrowser::haveExplorer() const
    3326             : {
    3327           0 :     return m_pTreeView && m_pTreeView->IsVisible();
    3328             : }
    3329             : 
    3330             : // -------------------------------------------------------------------------
    3331           0 : void SbaTableQueryBrowser::hideExplorer()
    3332             : {
    3333           0 :     if (!haveExplorer())
    3334           0 :         return;
    3335           0 :     if (!getBrowserView())
    3336           0 :         return;
    3337             : 
    3338           0 :     m_pTreeView->Hide();
    3339           0 :     m_pSplitter->Hide();
    3340           0 :     getBrowserView()->Resize();
    3341             : 
    3342           0 :     InvalidateFeature(ID_BROWSER_EXPLORER);
    3343             : }
    3344             : 
    3345             : // -------------------------------------------------------------------------
    3346           0 : void SbaTableQueryBrowser::showExplorer()
    3347             : {
    3348           0 :     if (haveExplorer())
    3349           0 :         return;
    3350             : 
    3351           0 :     if (!getBrowserView())
    3352           0 :         return;
    3353             : 
    3354           0 :     m_pTreeView->Show();
    3355           0 :     m_pSplitter->Show();
    3356           0 :     getBrowserView()->Resize();
    3357             : 
    3358           0 :     InvalidateFeature(ID_BROWSER_EXPLORER);
    3359             : }
    3360             : 
    3361             : // -----------------------------------------------------------------------------
    3362           0 : sal_Bool SbaTableQueryBrowser::ensureConnection(SvTreeListEntry* _pAnyEntry, SharedConnection& _rConnection)
    3363             : {
    3364           0 :     SvTreeListEntry* pDSEntry = m_pTreeView->getListBox().GetRootLevelParent(_pAnyEntry);
    3365             :     DBTreeListUserData* pDSData =
    3366             :                 pDSEntry
    3367             :             ?   static_cast<DBTreeListUserData*>(pDSEntry->GetUserData())
    3368           0 :             :   NULL;
    3369             : 
    3370           0 :     return ensureConnection( pDSEntry, pDSData, _rConnection );
    3371             : }
    3372             : 
    3373             : // -----------------------------------------------------------------------------
    3374             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
    3375           0 : ::std::auto_ptr< ImageProvider > SbaTableQueryBrowser::getImageProviderFor( SvTreeListEntry* _pAnyEntry )
    3376             : {
    3377           0 :     ::std::auto_ptr< ImageProvider > pImageProvider( new ImageProvider );
    3378           0 :     SharedConnection xConnection;
    3379           0 :     if ( getExistentConnectionFor( _pAnyEntry, xConnection ) )
    3380           0 :         pImageProvider.reset( new ImageProvider( xConnection ) );
    3381           0 :     return pImageProvider;
    3382             : }
    3383             : SAL_WNODEPRECATED_DECLARATIONS_POP
    3384             : 
    3385             : // -----------------------------------------------------------------------------
    3386           0 : sal_Bool SbaTableQueryBrowser::getExistentConnectionFor( SvTreeListEntry* _pAnyEntry, SharedConnection& _rConnection )
    3387             : {
    3388           0 :     SvTreeListEntry* pDSEntry = m_pTreeView->getListBox().GetRootLevelParent( _pAnyEntry );
    3389             :     DBTreeListUserData* pDSData =
    3390             :                 pDSEntry
    3391             :             ?   static_cast< DBTreeListUserData* >( pDSEntry->GetUserData() )
    3392           0 :             :   NULL;
    3393           0 :     if ( pDSData )
    3394           0 :         _rConnection = pDSData->xConnection;
    3395           0 :     return _rConnection.is();
    3396             : }
    3397             : 
    3398             : #if OSL_DEBUG_LEVEL > 0
    3399             : // -----------------------------------------------------------------------------
    3400             : bool SbaTableQueryBrowser::impl_isDataSourceEntry( SvTreeListEntry* _pEntry ) const
    3401             : {
    3402             :     return m_pTreeModel->GetRootLevelParent( _pEntry ) == _pEntry;
    3403             : }
    3404             : #endif
    3405             : 
    3406             : // -----------------------------------------------------------------------------
    3407           0 : sal_Bool SbaTableQueryBrowser::ensureConnection( SvTreeListEntry* _pDSEntry, void* pDSData, SharedConnection& _rConnection )
    3408             : {
    3409             :     OSL_ENSURE( impl_isDataSourceEntry( _pDSEntry ), "SbaTableQueryBrowser::ensureConnection: this entry does not denote a data source!" );
    3410           0 :     if(_pDSEntry)
    3411             :     {
    3412           0 :         DBTreeListUserData* pTreeListData = static_cast<DBTreeListUserData*>(pDSData);
    3413           0 :         ::rtl::OUString aDSName = GetEntryText(_pDSEntry);
    3414             : 
    3415           0 :         if ( pTreeListData )
    3416           0 :             _rConnection = pTreeListData->xConnection;
    3417             : 
    3418           0 :         if ( !_rConnection.is() && pTreeListData )
    3419             :         {
    3420             :             // show the "connecting to ..." status
    3421           0 :             String sConnecting(ModuleRes(STR_CONNECTING_DATASOURCE));
    3422           0 :             sConnecting.SearchAndReplaceAscii("$name$", aDSName);
    3423           0 :             BrowserViewStatusDisplay aShowStatus(static_cast<UnoDataBrowserView*>(getView()), sConnecting);
    3424             : 
    3425             :             // build a string showing context information in case of error
    3426           0 :             String sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE ) );
    3427           0 :             sConnectingContext.SearchAndReplaceAscii("$name$", aDSName);
    3428             : 
    3429             :             // connect
    3430             :             _rConnection.reset(
    3431             :                 connect( getDataSourceAcessor( _pDSEntry ), sConnectingContext, NULL ),
    3432             :                 SharedConnection::TakeOwnership
    3433           0 :             );
    3434             : 
    3435             :             // remember the connection
    3436           0 :             pTreeListData->xConnection = _rConnection;
    3437           0 :         }
    3438             :     }
    3439             : 
    3440           0 :     return _rConnection.is();
    3441             : }
    3442             : 
    3443             : // -----------------------------------------------------------------------------
    3444           0 : IMPL_LINK( SbaTableQueryBrowser, OnTreeEntryCompare, const SvSortData*, _pSortData )
    3445             : {
    3446           0 :     const SvTreeListEntry* pLHS = static_cast<const SvTreeListEntry*>(_pSortData->pLeft);
    3447           0 :     const SvTreeListEntry* pRHS = static_cast<const SvTreeListEntry*>(_pSortData->pRight);
    3448             :     OSL_ENSURE(pLHS && pRHS, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid tree entries!");
    3449             :     // we want the table entry and the end so we have to do a check
    3450             : 
    3451           0 :     if (isContainer(pRHS))
    3452             :     {
    3453             :         // don't use getEntryType (directly or indirecly) for the LHS:
    3454             :         // LHS is currently beeing inserted, so it is not "completely valid" at the moment
    3455             : 
    3456           0 :         const EntryType eRight = getEntryType(pRHS);
    3457           0 :         if (etTableContainer == eRight)
    3458             :             // every other container should be placed _before_ the bookmark container
    3459           0 :             return -1;
    3460             : 
    3461           0 :         const String sLeft = m_pTreeView->getListBox().GetEntryText(const_cast<SvTreeListEntry*>(pLHS));
    3462             : 
    3463           0 :         EntryType eLeft = etTableContainer;
    3464           0 :         if (String(ModuleRes(RID_STR_TABLES_CONTAINER)) == sLeft)
    3465           0 :             eLeft = etTableContainer;
    3466           0 :         else if (String(ModuleRes(RID_STR_QUERIES_CONTAINER)) == sLeft)
    3467           0 :             eLeft = etQueryContainer;
    3468             : 
    3469           0 :         if ( eLeft == eRight )
    3470           0 :             return COMPARE_EQUAL;
    3471             : 
    3472           0 :         if ( ( eLeft == etTableContainer ) && ( eRight == etQueryContainer ) )
    3473           0 :             return COMPARE_GREATER;
    3474             : 
    3475           0 :         if ( ( eLeft == etQueryContainer ) && ( eRight == etTableContainer ) )
    3476           0 :             return COMPARE_LESS;
    3477             : 
    3478             :         OSL_FAIL( "SbaTableQueryBrowser::OnTreeEntryCompare: unexpected case!" );
    3479           0 :         return COMPARE_EQUAL;
    3480             :     }
    3481             : 
    3482           0 :     const SvLBoxString* pLeftTextItem = static_cast<const SvLBoxString*>(pLHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
    3483           0 :     const SvLBoxString* pRightTextItem = static_cast<const SvLBoxString*>(pRHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
    3484             :     OSL_ENSURE(pLeftTextItem && pRightTextItem, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid text items!");
    3485             : 
    3486           0 :     String sLeftText = pLeftTextItem->GetText();
    3487           0 :     String sRightText = pRightTextItem->GetText();
    3488             : 
    3489           0 :     sal_Int32 nCompareResult = 0;   // equal by default
    3490             : 
    3491           0 :     if (m_xCollator.is())
    3492             :     {
    3493             :         try
    3494             :         {
    3495           0 :             nCompareResult = m_xCollator->compareString(sLeftText, sRightText);
    3496             :         }
    3497           0 :         catch(const Exception&)
    3498             :         {
    3499             :         }
    3500             :     }
    3501             :     else
    3502             :         // default behaviour if we do not have a collator -> do the simple string compare
    3503           0 :         nCompareResult = sLeftText.CompareTo(sRightText);
    3504             : 
    3505           0 :     return nCompareResult;
    3506             : }
    3507             : 
    3508             : // -----------------------------------------------------------------------------
    3509           0 : void SbaTableQueryBrowser::implAdministrate( SvTreeListEntry* _pApplyTo )
    3510             : {
    3511             :     OSL_PRECOND( _pApplyTo, "SbaTableQueryBrowser::implAdministrate: illegal entry!" );
    3512           0 :     if ( !_pApplyTo )
    3513           0 :         return;
    3514             : 
    3515             :     try
    3516             :     {
    3517             :         // get the desktop object
    3518           0 :         sal_Int32 nFrameSearchFlag = FrameSearchFlag::ALL | FrameSearchFlag::GLOBAL ;
    3519           0 :         Reference< XDesktop2 > xFrameLoader = Desktop::create( comphelper::getComponentContext(getORB()) );
    3520             : 
    3521             :         // the initial selection
    3522           0 :         SvTreeListEntry* pTopLevelSelected = _pApplyTo;
    3523           0 :         while (pTopLevelSelected && m_pTreeView->getListBox().GetParent(pTopLevelSelected))
    3524           0 :             pTopLevelSelected = m_pTreeView->getListBox().GetParent(pTopLevelSelected);
    3525           0 :         ::rtl::OUString sInitialSelection;
    3526           0 :         if (pTopLevelSelected)
    3527           0 :             sInitialSelection = getDataSourceAcessor( pTopLevelSelected );
    3528             : 
    3529           0 :         Reference< XDataSource > xDataSource( getDataSourceByName( sInitialSelection, getView(), comphelper::getComponentContext(getORB()), NULL ) );
    3530           0 :         Reference< XModel > xDocumentModel( getDataSourceOrModel( xDataSource ), UNO_QUERY );
    3531             : 
    3532           0 :         if ( xDocumentModel.is() )
    3533             :         {
    3534             :             Reference< XInteractionHandler2 > xInteractionHandler(
    3535           0 :                 InteractionHandler::createWithParent(comphelper::getComponentContext(getORB()), 0) );
    3536             : 
    3537           0 :             ::comphelper::NamedValueCollection aLoadArgs;
    3538           0 :             aLoadArgs.put( "Model", xDocumentModel );
    3539           0 :             aLoadArgs.put( "InteractionHandler", xInteractionHandler );
    3540           0 :             aLoadArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
    3541             : 
    3542           0 :             Sequence< PropertyValue > aLoadArgPV;
    3543           0 :             aLoadArgs >>= aLoadArgPV;
    3544             : 
    3545           0 :             xFrameLoader->loadComponentFromURL(
    3546           0 :                 xDocumentModel->getURL(),
    3547             :                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_default")),
    3548             :                 nFrameSearchFlag,
    3549             :                 aLoadArgPV
    3550           0 :             );
    3551           0 :         }
    3552             :     }
    3553           0 :     catch( const Exception& )
    3554             :     {
    3555             :         DBG_UNHANDLED_EXCEPTION();
    3556             :     }
    3557             : }
    3558             : 
    3559             : // -----------------------------------------------------------------------------
    3560           0 : sal_Bool SbaTableQueryBrowser::requestQuickHelp( const SvTreeListEntry* _pEntry, String& _rText ) const
    3561             : {
    3562           0 :     const DBTreeListUserData* pData = static_cast< const DBTreeListUserData* >( _pEntry->GetUserData() );
    3563           0 :     if ( ( pData->eType == etDatasource ) && pData->sAccessor.Len() )
    3564             :     {
    3565           0 :         _rText = ::svt::OFileNotation( pData->sAccessor ).get( ::svt::OFileNotation::N_SYSTEM );
    3566           0 :         return sal_True;
    3567             :     }
    3568           0 :     return sal_False;
    3569             : }
    3570             : 
    3571             : // -----------------------------------------------------------------------------
    3572           0 : PopupMenu* SbaTableQueryBrowser::getContextMenu( Control& _rControl ) const
    3573             : {
    3574             :     OSL_PRECOND( &m_pTreeView->getListBox() == &_rControl,
    3575             :         "SbaTableQueryBrowser::getContextMenu: where does this come from?" );
    3576           0 :     if ( &m_pTreeView->getListBox() != &_rControl )
    3577           0 :         return NULL;
    3578             : 
    3579           0 :     return new PopupMenu( ModuleRes( MENU_BROWSER_DEFAULTCONTEXT ) );
    3580             : }
    3581             : 
    3582             : // -----------------------------------------------------------------------------
    3583           0 : IController& SbaTableQueryBrowser::getCommandController()
    3584             : {
    3585           0 :     return *this;
    3586             : }
    3587             : 
    3588             : // -----------------------------------------------------------------------------
    3589           0 : ::cppu::OInterfaceContainerHelper* SbaTableQueryBrowser::getContextMenuInterceptors()
    3590             : {
    3591           0 :     return &m_aContextMenuInterceptors;
    3592             : }
    3593             : 
    3594             : // -----------------------------------------------------------------------------
    3595           0 : Any SbaTableQueryBrowser::getCurrentSelection( Control& _rControl ) const
    3596             : {
    3597             :     OSL_PRECOND( &m_pTreeView->getListBox() == &_rControl,
    3598             :         "SbaTableQueryBrowser::getCurrentSelection: where does this come from?" );
    3599             : 
    3600           0 :     if ( &m_pTreeView->getListBox() != &_rControl )
    3601           0 :         return Any();
    3602             : 
    3603           0 :     SvTreeListEntry* pSelected = m_pTreeView->getListBox().FirstSelected();
    3604           0 :     if ( !pSelected )
    3605           0 :         return Any();
    3606             : 
    3607             :     OSL_ENSURE( m_pTreeView->getListBox().NextSelected( pSelected ) == NULL,
    3608             :         "SbaTableQueryBrowser::getCurrentSelection: single-selection is expected here!" );
    3609             : 
    3610           0 :     NamedDatabaseObject aSelectedObject;
    3611           0 :     DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( pSelected->GetUserData() );
    3612           0 :     aSelectedObject.Type = static_cast< sal_Int32 >( pData->eType );
    3613             : 
    3614           0 :     switch ( aSelectedObject.Type )
    3615             :     {
    3616             :     case DatabaseObject::QUERY:
    3617             :     case DatabaseObject::TABLE:
    3618           0 :         aSelectedObject.Name = m_pTreeView->getListBox().GetEntryText( pSelected );
    3619           0 :         break;
    3620             : 
    3621             :     case DatabaseObjectContainer::DATA_SOURCE:
    3622             :     case DatabaseObjectContainer::QUERIES:
    3623             :     case DatabaseObjectContainer::TABLES:
    3624           0 :         aSelectedObject.Name = getDataSourceAcessor( pSelected );
    3625           0 :         break;
    3626             : 
    3627             :     default:
    3628             :         OSL_FAIL( "SbaTableQueryBrowser::getCurrentSelection: invalid (unexpected) object type!" );
    3629           0 :         break;
    3630             :     }
    3631             : 
    3632           0 :     return makeAny( aSelectedObject );
    3633             : }
    3634             : 
    3635             : // -----------------------------------------------------------------------------
    3636           0 : sal_Bool SbaTableQueryBrowser::implGetQuerySignature( ::rtl::OUString& _rCommand, sal_Bool& _bEscapeProcessing )
    3637             : {
    3638           0 :     _rCommand = ::rtl::OUString();
    3639           0 :     _bEscapeProcessing = sal_False;
    3640             : 
    3641             :     try
    3642             :     {
    3643             :         // contain the dss (data source signature) of the form
    3644           0 :         ::rtl::OUString sDataSourceName;
    3645           0 :         ::rtl::OUString sCommand;
    3646           0 :         sal_Int32       nCommandType = CommandType::COMMAND;
    3647           0 :         Reference< XPropertySet > xRowsetProps( getRowSet(), UNO_QUERY );
    3648           0 :         ODataAccessDescriptor aDesc( xRowsetProps );
    3649           0 :         sDataSourceName = aDesc.getDataSource();
    3650           0 :         aDesc[ daCommand ]      >>= sCommand;
    3651           0 :         aDesc[ daCommandType ]  >>= nCommandType;
    3652             : 
    3653             :         // do we need to do anything?
    3654           0 :         if ( CommandType::QUERY != nCommandType )
    3655           0 :             return sal_False;
    3656             : 
    3657             :         // get the query object
    3658           0 :         Reference< XQueryDefinitionsSupplier > xSuppQueries;
    3659           0 :         Reference< XNameAccess > xQueries;
    3660           0 :         Reference< XPropertySet > xQuery;
    3661           0 :         m_xDatabaseContext->getByName( sDataSourceName ) >>= xSuppQueries;
    3662           0 :         if ( xSuppQueries.is() )
    3663           0 :             xQueries = xSuppQueries->getQueryDefinitions();
    3664           0 :         if ( xQueries.is() )
    3665           0 :             xQueries->getByName( sCommand ) >>= xQuery;
    3666             :         OSL_ENSURE( xQuery.is(), "SbaTableQueryBrowser::implGetQuerySignature: could not retrieve the query object!" );
    3667             : 
    3668             :         // get the two properties we need
    3669           0 :         if ( xQuery.is() )
    3670             :         {
    3671           0 :             xQuery->getPropertyValue( PROPERTY_COMMAND ) >>= _rCommand;
    3672           0 :             _bEscapeProcessing = ::cppu::any2bool( xQuery->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) );
    3673           0 :             return sal_True;
    3674           0 :         }
    3675             :     }
    3676           0 :     catch( const Exception& )
    3677             :     {
    3678             :         DBG_UNHANDLED_EXCEPTION();
    3679             :     }
    3680             : 
    3681           0 :     return sal_False;
    3682             : }
    3683             : //------------------------------------------------------------------------------
    3684           0 : void SbaTableQueryBrowser::frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( RuntimeException )
    3685             : {
    3686           0 :     if (aEvent.Frame == m_xCurrentFrameParent)
    3687             :     {
    3688           0 :         if(aEvent.Action == FrameAction_COMPONENT_DETACHING)
    3689           0 :             implRemoveStatusListeners();
    3690           0 :         else if (aEvent.Action == FrameAction_COMPONENT_REATTACHED)
    3691           0 :             connectExternalDispatches();
    3692             :     }
    3693             :     else
    3694           0 :         SbaXDataBrowserController::frameAction(aEvent);
    3695             : 
    3696           0 : }
    3697             : // -----------------------------------------------------------------------------
    3698           0 : void SbaTableQueryBrowser::clearGridColumns(const Reference< XNameContainer >& _xColContainer)
    3699             : {
    3700             :     // first we have to clear the grid
    3701           0 :     Sequence< ::rtl::OUString > aNames = _xColContainer->getElementNames();
    3702           0 :     const ::rtl::OUString* pIter    = aNames.getConstArray();
    3703           0 :     const ::rtl::OUString* pEnd     = pIter + aNames.getLength();
    3704           0 :     Reference< XInterface > xColumn;
    3705           0 :     for (; pIter != pEnd;++pIter)
    3706             :     {
    3707           0 :         _xColContainer->getByName(*pIter) >>= xColumn;
    3708           0 :         _xColContainer->removeByName(*pIter);
    3709           0 :         ::comphelper::disposeComponent(xColumn);
    3710           0 :     }
    3711           0 : }
    3712             : // -----------------------------------------------------------------------------
    3713           0 : void SbaTableQueryBrowser::loadMenu(const Reference< XFrame >& _xFrame)
    3714             : {
    3715           0 :     if ( m_bShowMenu )
    3716             :     {
    3717           0 :         OGenericUnoController::loadMenu(_xFrame);
    3718             :     }
    3719           0 :     else if ( !m_bPreview )
    3720             :     {
    3721           0 :         Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager = getLayoutManager(_xFrame);
    3722             : 
    3723           0 :         if ( xLayoutManager.is() )
    3724             :         {
    3725           0 :             xLayoutManager->lock();
    3726           0 :             xLayoutManager->createElement( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/toolbar" )));
    3727           0 :             xLayoutManager->unlock();
    3728           0 :             xLayoutManager->doLayout();
    3729             :         }
    3730           0 :         onLoadedMenu( xLayoutManager );
    3731             :     }
    3732           0 : }
    3733             : // -----------------------------------------------------------------------------
    3734           0 : ::rtl::OUString SbaTableQueryBrowser::getPrivateTitle() const
    3735             : {
    3736           0 :     ::rtl::OUString sTitle;
    3737           0 :     if ( m_pCurrentlyDisplayed )
    3738             :     {
    3739           0 :         SvTreeListEntry* pContainer = m_pTreeModel->GetParent(m_pCurrentlyDisplayed);
    3740             :         // get the entry for the datasource
    3741           0 :         SvTreeListEntry* pConnection = implGetConnectionEntry(pContainer);
    3742           0 :         ::rtl::OUString sName = m_pTreeView->getListBox().GetEntryText(m_pCurrentlyDisplayed);
    3743           0 :         sTitle = GetEntryText( pConnection );
    3744           0 :         INetURLObject aURL(sTitle);
    3745           0 :         if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
    3746           0 :             sTitle = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_WITH_CHARSET);
    3747           0 :         if ( !sName.isEmpty() )
    3748             :         {
    3749           0 :             sName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - "));
    3750           0 :             sName += sTitle;
    3751           0 :             sTitle = sName;
    3752           0 :         }
    3753             :     }
    3754             : 
    3755           0 :     return sTitle;
    3756             : }
    3757             : // -----------------------------------------------------------------------------
    3758           0 : sal_Bool SbaTableQueryBrowser::preReloadForm()
    3759             : {
    3760           0 :     sal_Bool bIni = sal_False;
    3761           0 :     if ( !m_pCurrentlyDisplayed )
    3762             :     {
    3763             :         // switch the grid to design mode while loading
    3764           0 :         getBrowserView()->getGridControl()->setDesignMode(sal_True);
    3765             :         // we had an invalid statement so we need to connect the column models
    3766           0 :         Reference<XPropertySet> xRowSetProps(getRowSet(),UNO_QUERY);
    3767           0 :         ::svx::ODataAccessDescriptor aDesc(xRowSetProps);
    3768             :         // extract the props
    3769           0 :         ::rtl::OUString sDataSource;
    3770           0 :         ::rtl::OUString sCommand;
    3771           0 :         sal_Int32 nCommandType = CommandType::COMMAND;
    3772           0 :         sal_Bool bEscapeProcessing = sal_True;
    3773           0 :         extractDescriptorProps(aDesc, sDataSource, sCommand, nCommandType, bEscapeProcessing);
    3774           0 :         if ( !sDataSource.isEmpty() && !sCommand.isEmpty() && (-1 != nCommandType) )
    3775             :         {
    3776           0 :             SvTreeListEntry* pDataSource = NULL;
    3777           0 :             SvTreeListEntry* pCommandType = NULL;
    3778           0 :             m_pCurrentlyDisplayed = getObjectEntry( sDataSource, sCommand, nCommandType, &pDataSource, &pCommandType, sal_True, SharedConnection() );
    3779           0 :             bIni = sal_True;
    3780           0 :         }
    3781             :     }
    3782           0 :     return bIni;
    3783             : }
    3784             : 
    3785             : // -----------------------------------------------------------------------------
    3786           0 : void SbaTableQueryBrowser::postReloadForm()
    3787             : {
    3788           0 :     InitializeGridModel(getFormComponent());
    3789           0 :     LoadFinished(sal_True);
    3790           0 : }
    3791             : 
    3792             : //------------------------------------------------------------------------------
    3793           0 : Reference< XEmbeddedScripts > SAL_CALL SbaTableQueryBrowser::getScriptContainer() throw (RuntimeException)
    3794             : {
    3795             :     // update our database document
    3796           0 :     Reference< XModel > xDocument;
    3797             :     try
    3798             :     {
    3799           0 :         Reference< XPropertySet > xCursorProps( getRowSet(), UNO_QUERY_THROW );
    3800           0 :         Reference< XConnection > xConnection( xCursorProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ), UNO_QUERY );
    3801           0 :         if ( xConnection.is() )
    3802             :         {
    3803           0 :             Reference< XChild > xChild( xConnection, UNO_QUERY_THROW );
    3804           0 :             Reference< XDocumentDataSource > xDataSource( xChild->getParent(), UNO_QUERY_THROW );
    3805           0 :             xDocument.set( xDataSource->getDatabaseDocument(), UNO_QUERY_THROW );
    3806           0 :         }
    3807             :     }
    3808           0 :     catch( const Exception& )
    3809             :     {
    3810             :         DBG_UNHANDLED_EXCEPTION();
    3811             :     }
    3812           0 :     Reference< XEmbeddedScripts > xScripts( xDocument, UNO_QUERY );
    3813             :     OSL_ENSURE( xScripts.is() || !xDocument.is(),
    3814             :         "SbaTableQueryBrowser::getScriptContainer: invalid database document!" );
    3815           0 :     return xScripts;
    3816             : }
    3817             : 
    3818             : //------------------------------------------------------------------------------
    3819           0 : void SAL_CALL SbaTableQueryBrowser::registerContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException)
    3820             : {
    3821           0 :     if ( _Interceptor.is() )
    3822           0 :         m_aContextMenuInterceptors.addInterface( _Interceptor );
    3823           0 : }
    3824             : 
    3825             : //------------------------------------------------------------------------------
    3826           0 : void SAL_CALL SbaTableQueryBrowser::releaseContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException)
    3827             : {
    3828           0 :     if ( _Interceptor.is() )
    3829           0 :         m_aContextMenuInterceptors.removeInterface( _Interceptor );
    3830           0 : }
    3831             : 
    3832             : //------------------------------------------------------------------------------
    3833           0 : void SAL_CALL SbaTableQueryBrowser::registeredDatabaseLocation( const DatabaseRegistrationEvent& _Event ) throw (RuntimeException)
    3834             : {
    3835           0 :     SolarMutexGuard aGuard;
    3836           0 :     implAddDatasource( _Event.Name, SharedConnection() );
    3837           0 : }
    3838             : 
    3839             : //------------------------------------------------------------------------------
    3840           0 : void SbaTableQueryBrowser::impl_cleanupDataSourceEntry( const String& _rDataSourceName )
    3841             : {
    3842             :     // get the top-level representing the removed data source
    3843           0 :     SvTreeListEntry* pDataSourceEntry = m_pTreeView->getListBox().FirstChild( NULL );
    3844           0 :     while ( pDataSourceEntry )
    3845             :     {
    3846           0 :         if ( m_pTreeView->getListBox().GetEntryText( pDataSourceEntry ) == _rDataSourceName )
    3847           0 :             break;
    3848             : 
    3849           0 :         pDataSourceEntry = m_pTreeView->getListBox().NextSibling( pDataSourceEntry );
    3850             :     }
    3851             : 
    3852             :     OSL_ENSURE( pDataSourceEntry, "SbaTableQueryBrowser::impl_cleanupDataSourceEntry: do not know this data source!" );
    3853           0 :     if ( !pDataSourceEntry )
    3854           0 :         return;
    3855             : 
    3856           0 :     if ( isSelected( pDataSourceEntry ) )
    3857             :     {   // a table or query belonging to the deleted data source is currently beeing displayed.
    3858             :         OSL_ENSURE( m_pTreeView->getListBox().GetRootLevelParent( m_pCurrentlyDisplayed ) == pDataSourceEntry,
    3859             :             "SbaTableQueryBrowser::impl_cleanupDataSourceEntry: inconsistence (1)!" );
    3860           0 :         unloadAndCleanup( sal_True );
    3861             :     }
    3862             :     else
    3863             :         OSL_ENSURE(
    3864             :                 ( NULL == m_pCurrentlyDisplayed )
    3865             :             ||  ( m_pTreeView->getListBox().GetRootLevelParent( m_pCurrentlyDisplayed ) != pDataSourceEntry ),
    3866             :             "SbaTableQueryBrowser::impl_cleanupDataSourceEntry: inconsistence (2)!");
    3867             : 
    3868             :     // delete any user data of the child entries of the to-be-removed entry
    3869             :     std::pair<SvTreeListEntries::iterator, SvTreeListEntries::iterator> aIters =
    3870           0 :         m_pTreeModel->GetChildIterators(pDataSourceEntry);
    3871             : 
    3872           0 :     SvTreeListEntries::iterator it = aIters.first, itEnd = aIters.second;
    3873             : 
    3874           0 :     for (; it != itEnd; ++it)
    3875             :     {
    3876           0 :         SvTreeListEntry* pEntry = &(*it);
    3877           0 :         const DBTreeListUserData* pData = static_cast<const DBTreeListUserData*>(pEntry->GetUserData());
    3878           0 :         pEntry->SetUserData(NULL);
    3879           0 :         delete pData;
    3880             :     }
    3881             : 
    3882             :     // remove the entry
    3883           0 :     DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( pDataSourceEntry->GetUserData() );
    3884           0 :     pDataSourceEntry->SetUserData( NULL );
    3885           0 :     delete pData;
    3886           0 :     m_pTreeModel->Remove( pDataSourceEntry );
    3887             : }
    3888             : 
    3889             : //------------------------------------------------------------------------------
    3890           0 : void SAL_CALL SbaTableQueryBrowser::revokedDatabaseLocation( const DatabaseRegistrationEvent& _Event ) throw (RuntimeException)
    3891             : {
    3892           0 :     SolarMutexGuard aGuard;
    3893             : 
    3894           0 :     impl_cleanupDataSourceEntry( _Event.Name );
    3895             : 
    3896             :     // maybe the object which is part of the document data source has been removed
    3897           0 :     checkDocumentDataSource();
    3898           0 : }
    3899             : 
    3900             : //------------------------------------------------------------------------------
    3901           0 : void SAL_CALL SbaTableQueryBrowser::changedDatabaseLocation( const DatabaseRegistrationEvent& _Event ) throw (RuntimeException)
    3902             : {
    3903           0 :     SolarMutexGuard aGuard;
    3904             : 
    3905             :     // in case the data source was expanded, and connected, we need to clean it up
    3906             :     // for simplicity, just do as if the data source were completely removed and re-added
    3907           0 :     impl_cleanupDataSourceEntry( _Event.Name );
    3908           0 :     implAddDatasource( _Event.Name, SharedConnection() );
    3909           0 : }
    3910             : 
    3911             : 
    3912             : // .........................................................................
    3913             : }   // namespace dbaui
    3914             : // .........................................................................
    3915             : 
    3916             : 
    3917             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10