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

Generated by: LCOV version 1.10