LCOV - code coverage report
Current view: top level - dbaccess/source/ui/app - AppController.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 1449 0.0 %
Date: 2014-04-14 Functions: 0 96 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             : #include "AppController.hxx"
      21             : #include "dbustrings.hrc"
      22             : #include "advancedsettingsdlg.hxx"
      23             : #include "subcomponentmanager.hxx"
      24             : 
      25             : #include <com/sun/star/beans/NamedValue.hpp>
      26             : #include <com/sun/star/container/XChild.hpp>
      27             : #include <com/sun/star/container/XContainer.hpp>
      28             : #include <com/sun/star/container/XContentEnumerationAccess.hpp>
      29             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      30             : #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
      31             : #include <com/sun/star/container/XNameContainer.hpp>
      32             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      33             : #include <com/sun/star/frame/XStorable.hpp>
      34             : #include <com/sun/star/sdb/CommandType.hpp>
      35             : #include <com/sun/star/sdb/ErrorMessageDialog.hpp>
      36             : #include <com/sun/star/sdb/SQLContext.hpp>
      37             : #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
      38             : #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
      39             : #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
      40             : #include <com/sun/star/sdbc/XDataSource.hpp>
      41             : #include <com/sun/star/sdbcx/XAlterView.hpp>
      42             : #include <com/sun/star/sdbcx/XAppend.hpp>
      43             : #include <com/sun/star/sdbcx/XRename.hpp>
      44             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      45             : #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
      46             : #include <com/sun/star/sdb/application/MacroMigrationWizard.hpp>
      47             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      48             : #include <com/sun/star/uno/XNamingService.hpp>
      49             : #include <com/sun/star/util/XFlushable.hpp>
      50             : #include <com/sun/star/util/XModifiable.hpp>
      51             : #include <com/sun/star/util/XModifyBroadcaster.hpp>
      52             : #include <com/sun/star/util/XNumberFormatter.hpp>
      53             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      54             : #include <com/sun/star/document/XEmbeddedScripts.hpp>
      55             : #include <com/sun/star/frame/XModel2.hpp>
      56             : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
      57             : #include "com/sun/star/beans/NamedValue.hpp"
      58             : #include <com/sun/star/awt/XTopWindow.hpp>
      59             : #include <com/sun/star/task/XInteractionHandler.hpp>
      60             : #include <com/sun/star/sdb/application/DatabaseObject.hpp>
      61             : #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
      62             : #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
      63             : #include <com/sun/star/container/XHierarchicalName.hpp>
      64             : #include <tools/diagnose_ex.h>
      65             : #include <osl/diagnose.h>
      66             : 
      67             : #include <svl/urihelper.hxx>
      68             : #include <svl/filenotation.hxx>
      69             : #include <svtools/treelistbox.hxx>
      70             : #include <svtools/transfer.hxx>
      71             : #include <svtools/cliplistener.hxx>
      72             : #include <svtools/svlbitm.hxx>
      73             : #include <svtools/insdlg.hxx>
      74             : 
      75             : #include <comphelper/sequence.hxx>
      76             : #include <comphelper/uno3.hxx>
      77             : #include <comphelper/types.hxx>
      78             : #include <comphelper/interaction.hxx>
      79             : #include <comphelper/processfactory.hxx>
      80             : 
      81             : #include <vcl/msgbox.hxx>
      82             : #include <vcl/stdtext.hxx>
      83             : #include <vcl/svapp.hxx>
      84             : #include <vcl/menu.hxx>
      85             : #include <vcl/lstbox.hxx>
      86             : 
      87             : #include <unotools/closeveto.hxx>
      88             : #include <unotools/pathoptions.hxx>
      89             : #include <unotools/tempfile.hxx>
      90             : #include <unotools/moduleoptions.hxx>
      91             : #include <unotools/historyoptions.hxx>
      92             : 
      93             : #include <sfx2/mailmodelapi.hxx>
      94             : #include <sfx2/filedlghelper.hxx>
      95             : #include <sfx2/docfilt.hxx>
      96             : #include <sfx2/QuerySaveDocument.hxx>
      97             : 
      98             : #include <cppuhelper/typeprovider.hxx>
      99             : #include <cppuhelper/exc_hlp.hxx>
     100             : 
     101             : #include <connectivity/dbtools.hxx>
     102             : #include <connectivity/dbexception.hxx>
     103             : 
     104             : #include <svx/dbaexchange.hxx>
     105             : #include <svx/dbaobjectex.hxx>
     106             : #include <svx/svxdlg.hxx>
     107             : 
     108             : #include <osl/mutex.hxx>
     109             : #include "AppView.hxx"
     110             : #include "browserids.hxx"
     111             : #include "dbu_reghelper.hxx"
     112             : #include "dbu_app.hrc"
     113             : #include "defaultobjectnamecheck.hxx"
     114             : #include "databaseobjectview.hxx"
     115             : #include "listviewitems.hxx"
     116             : #include "AppDetailView.hxx"
     117             : #include "linkeddocuments.hxx"
     118             : #include "sqlmessage.hxx"
     119             : #include "UITools.hxx"
     120             : #include "dsntypes.hxx"
     121             : #include "dbaccess_helpid.hrc"
     122             : #include "dlgsave.hxx"
     123             : #include "dbaccess_slotid.hrc"
     124             : 
     125             : #include <algorithm>
     126             : #include <functional>
     127             : 
     128             : #include <boost/noncopyable.hpp>
     129             : 
     130           0 : extern "C" void SAL_CALL createRegistryInfo_ODBApplication()
     131             : {
     132           0 :     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OApplicationController > aAutoRegistration;
     133           0 : }
     134             : 
     135             : namespace dbaui
     136             : {
     137             : using namespace ::dbtools;
     138             : using namespace ::svx;
     139             : using namespace ::com::sun::star;
     140             : using namespace ::com::sun::star::uno;
     141             : using namespace ::com::sun::star::ucb;
     142             : using namespace ::com::sun::star::view;
     143             : using namespace ::com::sun::star::util;
     144             : using namespace ::com::sun::star::beans;
     145             : using namespace ::com::sun::star::lang;
     146             : using namespace ::com::sun::star::frame;
     147             : using namespace ::com::sun::star::container;
     148             : using namespace ::com::sun::star::sdb;
     149             : using namespace ::com::sun::star::sdbc;
     150             : using namespace ::com::sun::star::sdbcx;
     151             : using namespace ::com::sun::star::datatransfer;
     152             : using namespace ::com::sun::star::ui::dialogs;
     153             : using namespace ::com::sun::star::task;
     154             : using ::com::sun::star::document::XEmbeddedScripts;
     155             : using ::com::sun::star::document::XDocumentEventBroadcaster;
     156             : using ::com::sun::star::document::DocumentEvent;
     157             : using ::com::sun::star::sdb::application::NamedDatabaseObject;
     158             : 
     159             : namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
     160             : namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
     161             : 
     162           0 : OUString SAL_CALL OApplicationController::getImplementationName() throw( RuntimeException, std::exception )
     163             : {
     164           0 :     return getImplementationName_Static();
     165             : }
     166             : 
     167           0 : OUString OApplicationController::getImplementationName_Static() throw( RuntimeException )
     168             : {
     169           0 :     return OUString(SERVICE_SDB_APPLICATIONCONTROLLER);
     170             : }
     171             : 
     172           0 : Sequence< OUString> OApplicationController::getSupportedServiceNames_Static(void) throw( RuntimeException )
     173             : {
     174           0 :     Sequence< OUString> aSupported(1);
     175           0 :     aSupported[0] = "com.sun.star.sdb.application.DefaultViewController";
     176           0 :     return aSupported;
     177             : }
     178             : 
     179           0 : Sequence< OUString> SAL_CALL OApplicationController::getSupportedServiceNames() throw(RuntimeException, std::exception)
     180             : {
     181           0 :     return getSupportedServiceNames_Static();
     182             : }
     183             : 
     184           0 : Reference< XInterface > SAL_CALL OApplicationController::Create(const Reference<XMultiServiceFactory >& _rxFactory)
     185             : {
     186           0 :     return *(new OApplicationController( comphelper::getComponentContext(_rxFactory)));
     187             : }
     188             : 
     189           0 : struct XContainerFunctor : public ::std::unary_function< OApplicationController::TContainerVector::value_type , bool>
     190             : {
     191             :     Reference<XContainerListener> m_xContainerListener;
     192           0 :     XContainerFunctor( const Reference<XContainerListener>& _xContainerListener)
     193           0 :         : m_xContainerListener(_xContainerListener){}
     194             : 
     195           0 :     bool operator() (const OApplicationController::TContainerVector::value_type& lhs) const
     196             :     {
     197           0 :         if ( lhs.is() )
     198           0 :             lhs->removeContainerListener(m_xContainerListener);
     199           0 :         return true;
     200             :     }
     201             : };
     202             : 
     203             : // OApplicationController
     204             : class SelectionNotifier : public ::boost::noncopyable
     205             : {
     206             : private:
     207             :     ::cppu::OInterfaceContainerHelper   m_aSelectionListeners;
     208             :     ::cppu::OWeakObject&                m_rContext;
     209             :     sal_Int32                           m_nSelectionNestingLevel;
     210             : 
     211             : public:
     212           0 :     SelectionNotifier( ::osl::Mutex& _rMutex, ::cppu::OWeakObject& _rContext )
     213             :         :m_aSelectionListeners( _rMutex )
     214             :         ,m_rContext( _rContext )
     215           0 :         ,m_nSelectionNestingLevel( 0 )
     216             :     {
     217           0 :     }
     218             : 
     219           0 :     void addListener( const Reference< XSelectionChangeListener >& _Listener )
     220             :     {
     221           0 :         m_aSelectionListeners.addInterface( _Listener );
     222           0 :     }
     223             : 
     224           0 :     void removeListener( const Reference< XSelectionChangeListener >& _Listener )
     225             :     {
     226           0 :         m_aSelectionListeners.removeInterface( _Listener );
     227           0 :     }
     228             : 
     229           0 :     void disposing()
     230             :     {
     231           0 :         EventObject aEvent( m_rContext );
     232           0 :         m_aSelectionListeners.disposeAndClear( aEvent );
     233           0 :     }
     234             : 
     235           0 :     ~SelectionNotifier()
     236           0 :     {
     237           0 :     }
     238             : 
     239           0 :     struct SelectionGuardAccess { friend class SelectionGuard; private: SelectionGuardAccess() { }  };
     240             : 
     241             :     /** enters a block which modifies the selection of our owner.
     242             : 
     243             :         Can be called multiple times, the only important thing is to call leaveSelection
     244             :         equally often.
     245             :     */
     246           0 :     void    enterSelection( SelectionGuardAccess )
     247             :     {
     248           0 :         ++m_nSelectionNestingLevel;
     249           0 :     }
     250             : 
     251             :     /** leaves a block which modifies the selection of our owner
     252             : 
     253             :         Must be paired with enterSelection calls.
     254             : 
     255             :         When the last block is left, i.e. the last leaveSelection call is made on the current stack,
     256             :         then our SelectionChangeListeners are notified
     257             :     */
     258           0 :     void    leaveSelection( SelectionGuardAccess )
     259             :     {
     260           0 :         if ( --m_nSelectionNestingLevel == 0 )
     261             :         {
     262           0 :             EventObject aEvent( m_rContext );
     263           0 :             m_aSelectionListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aEvent );
     264             :         }
     265           0 :     }
     266             : };
     267             : 
     268             : class SelectionGuard : public ::boost::noncopyable
     269             : {
     270             : public:
     271           0 :     SelectionGuard( SelectionNotifier& _rNotifier )
     272           0 :         :m_rNotifier( _rNotifier )
     273             :     {
     274           0 :         m_rNotifier.enterSelection( SelectionNotifier::SelectionGuardAccess() );
     275           0 :     }
     276             : 
     277           0 :     ~SelectionGuard()
     278             :     {
     279           0 :         m_rNotifier.leaveSelection( SelectionNotifier::SelectionGuardAccess() );
     280           0 :     }
     281             : 
     282             : private:
     283             :     SelectionNotifier&  m_rNotifier;
     284             : };
     285             : 
     286             : // OApplicationController
     287           0 : OApplicationController::OApplicationController(const Reference< XComponentContext >& _rxORB)
     288             :     :OApplicationController_CBASE( _rxORB )
     289           0 :     ,m_aContextMenuInterceptors( getMutex() )
     290           0 :     ,m_pSubComponentManager( new SubComponentManager( *this, getSharedMutex() ) )
     291             :     ,m_aTypeCollection( _rxORB )
     292             :     ,m_aTableCopyHelper(this)
     293             :     ,m_pClipbordNotifier(NULL)
     294             :     ,m_nAsyncDrop(0)
     295             :     ,m_aSelectContainerEvent( LINK( this, OApplicationController, OnSelectContainer ) )
     296             :     ,m_ePreviewMode(E_PREVIEWNONE)
     297             :     ,m_eCurrentType(E_NONE)
     298             :     ,m_bNeedToReconnect(sal_False)
     299             :     ,m_bSuspended( sal_False )
     300           0 :     ,m_pSelectionNotifier( new SelectionNotifier( getMutex(), *this ) )
     301             : {
     302           0 : }
     303             : 
     304           0 : OApplicationController::~OApplicationController()
     305             : {
     306           0 :     if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
     307             :     {
     308             :         OSL_FAIL("Please check who doesn't dispose this component!");
     309             :         // increment ref count to prevent double call of Dtor
     310           0 :         osl_atomic_increment( &m_refCount );
     311           0 :         dispose();
     312             :     }
     313             :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
     314           0 :     ::std::auto_ptr< Window> aTemp( getView() );
     315             :     SAL_WNODEPRECATED_DECLARATIONS_POP
     316           0 :     clearView();
     317             : 
     318           0 : }
     319             : 
     320           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
     321           0 : IMPLEMENT_FORWARD_XINTERFACE2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
     322           0 : void OApplicationController::disconnect()
     323             : {
     324           0 :     if ( m_xDataSourceConnection.is() )
     325           0 :         stopConnectionListening( m_xDataSourceConnection );
     326             : 
     327             :     try
     328             :     {
     329             :         // temporary (hopefully!) hack for #i55274#
     330           0 :         Reference< XFlushable > xFlush( m_xDataSourceConnection, UNO_QUERY );
     331           0 :         if ( xFlush.is() && m_xMetaData.is() && !m_xMetaData->isReadOnly() )
     332           0 :             xFlush->flush();
     333             :     }
     334           0 :     catch( const Exception& )
     335             :     {
     336             :         DBG_UNHANDLED_EXCEPTION();
     337             :     }
     338             : 
     339           0 :     m_xDataSourceConnection.clear();
     340           0 :     m_xMetaData.clear();
     341             : 
     342           0 :     InvalidateAll();
     343           0 : }
     344             : 
     345           0 : void SAL_CALL OApplicationController::disposing()
     346             : {
     347           0 :     ::std::for_each(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),XContainerFunctor(this));
     348           0 :     m_aCurrentContainers.clear();
     349           0 :     m_pSubComponentManager->disposing();
     350           0 :     m_pSelectionNotifier->disposing();
     351             : 
     352           0 :     if ( getView() )
     353             :     {
     354           0 :         getContainer()->showPreview(NULL);
     355           0 :         m_pClipbordNotifier->ClearCallbackLink();
     356           0 :         m_pClipbordNotifier->AddRemoveListener( getView(), false );
     357           0 :         m_pClipbordNotifier->release();
     358           0 :         m_pClipbordNotifier = NULL;
     359             :     }
     360             : 
     361           0 :     disconnect();
     362             :     try
     363             :     {
     364           0 :         Reference < XFrame > xFrame;
     365           0 :         attachFrame( xFrame );
     366             : 
     367           0 :         if ( m_xDataSource.is() )
     368             :         {
     369           0 :             m_xDataSource->removePropertyChangeListener(OUString(), this);
     370           0 :             m_xDataSource->removePropertyChangeListener(PROPERTY_INFO, this);
     371           0 :             m_xDataSource->removePropertyChangeListener(PROPERTY_URL, this);
     372           0 :             m_xDataSource->removePropertyChangeListener(PROPERTY_ISPASSWORDREQUIRED, this);
     373           0 :             m_xDataSource->removePropertyChangeListener(PROPERTY_LAYOUTINFORMATION, this);
     374           0 :             m_xDataSource->removePropertyChangeListener(PROPERTY_SUPPRESSVERSIONCL, this);
     375           0 :             m_xDataSource->removePropertyChangeListener(PROPERTY_TABLEFILTER, this);
     376           0 :             m_xDataSource->removePropertyChangeListener(PROPERTY_TABLETYPEFILTER, this);
     377           0 :             m_xDataSource->removePropertyChangeListener(PROPERTY_USER, this);
     378             :             // otherwise we may delete our datasource twice
     379           0 :             Reference<XPropertySet> xProp = m_xDataSource;
     380           0 :             m_xDataSource = NULL;
     381             :         }
     382             : 
     383           0 :         Reference< XModifyBroadcaster > xBroadcaster( m_xModel, UNO_QUERY );
     384           0 :         if ( xBroadcaster.is() )
     385           0 :             xBroadcaster->removeModifyListener(static_cast<XModifyListener*>(this));
     386             : 
     387           0 :         if ( m_xModel.is() )
     388             :         {
     389           0 :             OUString sUrl = m_xModel->getURL();
     390           0 :             if ( !sUrl.isEmpty() )
     391             :             {
     392           0 :                 ::comphelper::NamedValueCollection aArgs( m_xModel->getArgs() );
     393           0 :                 if ( true == aArgs.getOrDefault( "PickListEntry", true ) )
     394             :                 {
     395           0 :                     OUString     aFilter;
     396           0 :                     INetURLObject       aURL( m_xModel->getURL() );
     397           0 :                     const SfxFilter* pFilter = getStandardDatabaseFilter();
     398           0 :                     if ( pFilter )
     399           0 :                         aFilter = pFilter->GetFilterName();
     400             : 
     401             :                     // add to svtool history options
     402             :                     SvtHistoryOptions().AppendItem( ePICKLIST,
     403             :                             aURL.GetURLNoPass( INetURLObject::NO_DECODE ),
     404             :                             aFilter,
     405             :                             getStrippedDatabaseName(),
     406             :                             OUString(),
     407           0 :                             OUString());
     408             : 
     409             :                     // add to recent document list
     410           0 :                     if ( aURL.GetProtocol() == INET_PROT_FILE )
     411             :                         Application::AddToRecentDocumentList( aURL.GetURLNoPass( INetURLObject::NO_DECODE ),
     412           0 :                                                               (pFilter) ? pFilter->GetMimeType() : OUString(),
     413           0 :                                                               (pFilter) ? pFilter->GetServiceName() : OUString() );
     414           0 :                 }
     415             :             }
     416             : 
     417           0 :             m_xModel->disconnectController( this );
     418             : 
     419           0 :             m_xModel.clear();
     420           0 :         }
     421             :     }
     422           0 :     catch(const Exception&)
     423             :     {
     424             :         DBG_UNHANDLED_EXCEPTION();
     425             :     }
     426             : 
     427           0 :     clearView();
     428           0 :     OApplicationController_CBASE::disposing(); // here the m_refCount must be equal 5
     429           0 : }
     430             : 
     431           0 : bool OApplicationController::Construct(Window* _pParent)
     432             : {
     433           0 :     setView( * new OApplicationView( _pParent, getORB(), *this, m_ePreviewMode ) );
     434           0 :     getView()->SetUniqueId(UID_APP_VIEW);
     435             : 
     436             :     // late construction
     437           0 :     bool bSuccess = false;
     438             :     try
     439             :     {
     440           0 :         getContainer()->Construct();
     441           0 :         bSuccess = true;
     442             :     }
     443           0 :     catch(const SQLException&)
     444             :     {
     445             :     }
     446           0 :     catch(const Exception&)
     447             :     {
     448             :         OSL_FAIL("OApplicationController::Construct : the construction of UnoDataBrowserView failed !");
     449             :     }
     450             : 
     451           0 :     if ( !bSuccess )
     452             :     {
     453             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     454           0 :         ::std::auto_ptr< Window> aTemp( getView() );
     455             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     456           0 :         clearView();
     457           0 :         return false;
     458             :     }
     459             : 
     460             :     // now that we have a view we can create the clipboard listener
     461           0 :     m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( getView() );
     462           0 :     m_aSystemClipboard.StartClipboardListening( );
     463             : 
     464           0 :     m_pClipbordNotifier = new TransferableClipboardListener( LINK( this, OApplicationController, OnClipboardChanged ) );
     465           0 :     m_pClipbordNotifier->acquire();
     466           0 :     m_pClipbordNotifier->AddRemoveListener( getView(), true );
     467             : 
     468           0 :     OApplicationController_CBASE::Construct( _pParent );
     469           0 :     getView()->Show();
     470             : 
     471           0 :     return true;
     472             : }
     473             : 
     474           0 : void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) throw( RuntimeException, std::exception )
     475             : {
     476           0 :     ::osl::MutexGuard aGuard( getMutex() );
     477           0 :     Reference<XConnection> xCon(_rSource.Source, UNO_QUERY);
     478           0 :     if ( xCon.is() )
     479             :     {
     480             :         OSL_ENSURE( m_xDataSourceConnection == xCon,
     481             :             "OApplicationController::disposing: which connection does this come from?" );
     482             : 
     483           0 :         if ( getContainer() && getContainer()->getElementType() == E_TABLE )
     484           0 :             getContainer()->clearPages();
     485           0 :         if ( m_xDataSourceConnection == xCon )
     486             :         {
     487           0 :             m_xMetaData.clear();
     488           0 :             m_xDataSourceConnection.clear();
     489             :         }
     490             :     }
     491           0 :     else if ( _rSource.Source == m_xModel )
     492             :     {
     493           0 :         m_xModel.clear();
     494             :     }
     495           0 :     else if ( _rSource.Source == m_xDataSource )
     496             :     {
     497           0 :         m_xDataSource = NULL;
     498             :     }
     499             :     else
     500             :     {
     501           0 :         Reference<XContainer> xContainer( _rSource.Source, UNO_QUERY );
     502           0 :         if ( xContainer.is() )
     503             :         {
     504           0 :             TContainerVector::iterator aFind = ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer);
     505           0 :             if ( aFind != m_aCurrentContainers.end() )
     506           0 :                 m_aCurrentContainers.erase(aFind);
     507             :         }
     508           0 :         OApplicationController_CBASE::disposing( _rSource );
     509           0 :     }
     510           0 : }
     511             : 
     512           0 : sal_Bool SAL_CALL OApplicationController::suspend(sal_Bool bSuspend) throw( RuntimeException, std::exception )
     513             : {
     514             :     // notify the OnPrepareViewClosing event (before locking any mutex)
     515           0 :     Reference< XDocumentEventBroadcaster > xBroadcaster( m_xModel, UNO_QUERY );
     516           0 :     if ( xBroadcaster.is() )
     517             :     {
     518           0 :         xBroadcaster->notifyDocumentEvent(
     519             :             OUString("OnPrepareViewClosing"),
     520             :             this,
     521             :             Any()
     522           0 :         );
     523             :     }
     524             : 
     525           0 :     SolarMutexGuard aSolarGuard;
     526           0 :     ::osl::MutexGuard aGuard( getMutex() );
     527             : 
     528           0 :     if ( getView() && getView()->IsInModalMode() )
     529           0 :         return sal_False;
     530             : 
     531           0 :     sal_Bool bCanSuspend = sal_True;
     532             : 
     533           0 :     if ( m_bSuspended != bSuspend )
     534             :     {
     535           0 :         if ( bSuspend && !closeSubComponents() )
     536           0 :             return sal_False;
     537             : 
     538           0 :         Reference<XModifiable> xModi(m_xModel,UNO_QUERY);
     539           0 :         Reference<XStorable> xStor(getModel(),UNO_QUERY);
     540             : 
     541           0 :         if  (   bSuspend
     542           0 :             &&  xStor.is()
     543           0 :             &&  !xStor->isReadonly()
     544           0 :             &&  (   xModi.is()
     545           0 :                 &&  xModi->isModified()
     546             :                 )
     547             :             )
     548             :         {
     549           0 :             switch (ExecuteQuerySaveDocument(getView(),getStrippedDatabaseName()))
     550             :             {
     551             :                 case RET_YES:
     552           0 :                     Execute(ID_BROWSER_SAVEDOC,Sequence<PropertyValue>());
     553           0 :                     bCanSuspend = !xModi->isModified();
     554             :                     // when we save the document this must be false else some press cancel
     555           0 :                     break;
     556             :                 case RET_CANCEL:
     557           0 :                     bCanSuspend = sal_False;
     558             :                 default:
     559           0 :                     break;
     560             :             }
     561           0 :         }
     562             :     }
     563             : 
     564           0 :     if ( bCanSuspend )
     565           0 :         m_bSuspended = bSuspend;
     566             : 
     567           0 :     return bCanSuspend;
     568             : }
     569             : 
     570           0 : FeatureState OApplicationController::GetState(sal_uInt16 _nId) const
     571             : {
     572           0 :     FeatureState aReturn;
     573           0 :     aReturn.bEnabled = false;
     574             :     // check this first
     575           0 :     if ( !getContainer() || m_bReadOnly )
     576           0 :         return aReturn;
     577             : 
     578             :     try
     579             :     {
     580           0 :         switch (_nId)
     581             :         {
     582             :             case SID_OPENURL:
     583           0 :                 aReturn.bEnabled = true;
     584           0 :                 if ( m_xModel.is() )
     585           0 :                     aReturn.sTitle = m_xModel->getURL();
     586           0 :                 break;
     587             :             case ID_BROWSER_COPY:
     588             :                 {
     589           0 :                     sal_Int32 nCount = getContainer()->getSelectionCount();
     590           0 :                     aReturn.bEnabled = nCount >= 1;
     591           0 :                     if ( aReturn.bEnabled && nCount == 1 && getContainer()->getElementType() == E_TABLE )
     592           0 :                         aReturn.bEnabled = getContainer()->isALeafSelected();
     593             :                 }
     594           0 :                 break;
     595             :             case ID_BROWSER_CUT:
     596           0 :                 aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() >= 1;
     597           0 :                 aReturn.bEnabled = aReturn.bEnabled && ( (ID_BROWSER_CUT == _nId && getContainer()->getElementType() == E_TABLE) ? getContainer()->isCutAllowed() : sal_True);
     598           0 :                 break;
     599             :             case ID_BROWSER_PASTE:
     600           0 :                 switch( getContainer()->getElementType() )
     601             :                 {
     602             :                     case E_TABLE:
     603           0 :                         aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly() && isTableFormat();
     604           0 :                         break;
     605             :                     case E_QUERY:
     606           0 :                         aReturn.bEnabled = !isDataSourceReadOnly() && getViewClipboard().HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY);
     607           0 :                         break;
     608             :                     default:
     609           0 :                         aReturn.bEnabled = !isDataSourceReadOnly() && OComponentTransferable::canExtractComponentDescriptor(getViewClipboard().GetDataFlavorExVector(),getContainer()->getElementType() == E_FORM);
     610             :                 }
     611           0 :                 break;
     612             :             case SID_DB_APP_PASTE_SPECIAL:
     613           0 :                 aReturn.bEnabled = getContainer()->getElementType() == E_TABLE && !isDataSourceReadOnly() && !isConnectionReadOnly() && isTableFormat();
     614           0 :                 break;
     615             :             case SID_OPENDOC:
     616             :             case SID_HELP_INDEX:
     617           0 :                 aReturn.bEnabled = true;
     618           0 :                 break;
     619             :             case ID_BROWSER_SAVEDOC:
     620           0 :                 aReturn.bEnabled = !isDataSourceReadOnly() && m_xDocumentModify.is() && m_xDocumentModify->isModified();
     621           0 :                 break;
     622             :             case ID_BROWSER_SAVEASDOC:
     623           0 :                 aReturn.bEnabled = true;
     624           0 :                 break;
     625             :             case ID_BROWSER_SORTUP:
     626           0 :                 aReturn.bEnabled = getContainer()->isFilled() && getContainer()->getElementCount();
     627           0 :                 aReturn.bChecked = aReturn.bEnabled && getContainer()->isSortUp();
     628           0 :                 break;
     629             :             case ID_BROWSER_SORTDOWN:
     630           0 :                 aReturn.bEnabled = getContainer()->isFilled() && getContainer()->getElementCount();
     631           0 :                 aReturn.bChecked = aReturn.bEnabled && !getContainer()->isSortUp();
     632           0 :                 break;
     633             : 
     634             :             case SID_NEWDOC:
     635             :             case SID_APP_NEW_FORM:
     636             :             case ID_DOCUMENT_CREATE_REPWIZ:
     637           0 :                 aReturn.bEnabled = !isDataSourceReadOnly() && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER);
     638           0 :                 break;
     639             :             case SID_APP_NEW_REPORT:
     640           0 :                 aReturn.bEnabled = !isDataSourceReadOnly()
     641           0 :                                     && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER);
     642           0 :                 if ( aReturn.bEnabled )
     643             :                 {
     644           0 :                     Reference< XContentEnumerationAccess > xEnumAccess(m_xContext->getServiceManager(), UNO_QUERY);
     645           0 :                     aReturn.bEnabled = xEnumAccess.is();
     646           0 :                     if ( aReturn.bEnabled )
     647             :                     {
     648           0 :                         const OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_xContext);
     649           0 :                         aReturn.bEnabled = !sReportEngineServiceName.isEmpty();
     650           0 :                         if ( aReturn.bEnabled )
     651             :                         {
     652           0 :                             const Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(sReportEngineServiceName);
     653           0 :                             aReturn.bEnabled = xEnumDrivers.is() && xEnumDrivers->hasMoreElements();
     654           0 :                         }
     655           0 :                     }
     656             :                 }
     657           0 :                 break;
     658             :             case SID_DB_APP_VIEW_TABLES:
     659           0 :                 aReturn.bEnabled = true;
     660           0 :                 aReturn.bChecked = getContainer()->getElementType() == E_TABLE;
     661           0 :                 break;
     662             :             case SID_DB_APP_VIEW_QUERIES:
     663           0 :                 aReturn.bEnabled = true;
     664           0 :                 aReturn.bChecked = getContainer()->getElementType() == E_QUERY;
     665           0 :                 break;
     666             :             case SID_DB_APP_VIEW_FORMS:
     667           0 :                 aReturn.bEnabled = true;
     668           0 :                 aReturn.bChecked = getContainer()->getElementType() == E_FORM;
     669           0 :                 break;
     670             :             case SID_DB_APP_VIEW_REPORTS:
     671           0 :                 aReturn.bEnabled = true;
     672           0 :                 aReturn.bChecked = getContainer()->getElementType() == E_REPORT;
     673           0 :                 break;
     674             :             case ID_NEW_QUERY_DESIGN:
     675             :             case ID_NEW_QUERY_SQL:
     676             :             case ID_APP_NEW_QUERY_AUTO_PILOT:
     677             :             case SID_DB_FORM_NEW_PILOT:
     678           0 :                 aReturn.bEnabled = !isDataSourceReadOnly();
     679           0 :                 break;
     680             :             case ID_NEW_VIEW_DESIGN:
     681             :             case SID_DB_NEW_VIEW_SQL:
     682             :             case ID_NEW_VIEW_DESIGN_AUTO_PILOT:
     683           0 :                 aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly();
     684           0 :                 if ( aReturn.bEnabled )
     685             :                 {
     686           0 :                     Reference<XViewsSupplier> xViewsSup( getConnection(), UNO_QUERY );
     687           0 :                     aReturn.bEnabled = xViewsSup.is();
     688             :                 }
     689           0 :                 break;
     690             :             case ID_NEW_TABLE_DESIGN:
     691             :             case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
     692           0 :                 aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly();
     693           0 :                 break;
     694             :             case ID_DIRECT_SQL:
     695           0 :                 aReturn.bEnabled = true;
     696           0 :                 break;
     697             :             case ID_MIGRATE_SCRIPTS:
     698             :             {
     699             :                 // Our document supports embedding scripts into it, if and only if there are no
     700             :                 // forms/reports with macros/scripts into them. So, we need to enable migration
     701             :                 // if and only if the database document does *not* support embedding scripts.
     702             :                 bool bAvailable =
     703           0 :                         !Reference< XEmbeddedScripts >( m_xModel, UNO_QUERY ).is()
     704           0 :                     &&  !Reference< XStorable >( m_xModel, UNO_QUERY_THROW )->isReadonly();
     705           0 :                 aReturn.bEnabled = bAvailable;
     706           0 :                 if ( !bAvailable )
     707           0 :                     aReturn.bInvisible = true;
     708             :             }
     709           0 :             break;
     710             :             case SID_APP_NEW_FOLDER:
     711           0 :                 aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() <= 1;
     712           0 :                 if ( aReturn.bEnabled )
     713             :                 {
     714           0 :                     const ElementType eType = getContainer()->getElementType();
     715           0 :                     aReturn.bEnabled = eType == E_REPORT || eType == E_FORM;
     716             :                 }
     717           0 :                 break;
     718             :             case SID_FORM_CREATE_REPWIZ_PRE_SEL:
     719             :             case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
     720             :             case SID_APP_NEW_REPORT_PRE_SEL:
     721           0 :                 aReturn.bEnabled = !isDataSourceReadOnly()
     722           0 :                                     && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER)
     723           0 :                                     && getContainer()->isALeafSelected();
     724           0 :                 if ( aReturn.bEnabled )
     725             :                 {
     726           0 :                     ElementType eType = getContainer()->getElementType();
     727           0 :                     aReturn.bEnabled = eType == E_QUERY || eType == E_TABLE;
     728           0 :                     if ( aReturn.bEnabled && SID_APP_NEW_REPORT_PRE_SEL == _nId )
     729             :                     {
     730           0 :                         Reference< XContentEnumerationAccess > xEnumAccess(m_xContext->getServiceManager(), UNO_QUERY);
     731           0 :                         aReturn.bEnabled = xEnumAccess.is();
     732           0 :                         if ( aReturn.bEnabled )
     733             :                         {
     734           0 :                             static OUString s_sReportDesign("org.libreoffice.report.pentaho.SOReportJobFactory");
     735           0 :                             Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(s_sReportDesign);
     736           0 :                             aReturn.bEnabled = xEnumDrivers.is() && xEnumDrivers->hasMoreElements();
     737           0 :                         }
     738             :                     }
     739             :                 }
     740           0 :                 break;
     741             :             case SID_DB_APP_DELETE:
     742             :             case SID_DB_APP_RENAME:
     743           0 :                 aReturn.bEnabled = isRenameDeleteAllowed(getContainer()->getElementType(), _nId == SID_DB_APP_DELETE);
     744           0 :                 break;
     745             :             case SID_DB_APP_TABLE_DELETE:
     746             :             case SID_DB_APP_TABLE_RENAME:
     747           0 :                 aReturn.bEnabled = isRenameDeleteAllowed(E_TABLE, _nId == SID_DB_APP_TABLE_DELETE);
     748           0 :                 break;
     749             :             case SID_DB_APP_QUERY_DELETE:
     750             :             case SID_DB_APP_QUERY_RENAME:
     751           0 :                 aReturn.bEnabled = isRenameDeleteAllowed(E_QUERY, _nId == SID_DB_APP_QUERY_DELETE);
     752           0 :                 break;
     753             :             case SID_DB_APP_FORM_DELETE:
     754             :             case SID_DB_APP_FORM_RENAME:
     755           0 :                 aReturn.bEnabled = isRenameDeleteAllowed(E_FORM, _nId == SID_DB_APP_FORM_DELETE);
     756           0 :                 break;
     757             :             case SID_DB_APP_REPORT_DELETE:
     758             :             case SID_DB_APP_REPORT_RENAME:
     759           0 :                 aReturn.bEnabled = isRenameDeleteAllowed(E_REPORT, _nId == SID_DB_APP_REPORT_DELETE);
     760           0 :                 break;
     761             : 
     762             :             case SID_SELECTALL:
     763           0 :                 aReturn.bEnabled = getContainer()->getElementCount() > 0 && getContainer()->getSelectionCount() != getContainer()->getElementCount();
     764           0 :                 break;
     765             :             case SID_DB_APP_EDIT:
     766             :             case SID_DB_APP_TABLE_EDIT:
     767             :             case SID_DB_APP_QUERY_EDIT:
     768             :             case SID_DB_APP_FORM_EDIT:
     769             :             case SID_DB_APP_REPORT_EDIT:
     770           0 :                 aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() > 0
     771           0 :                                     && getContainer()->isALeafSelected();
     772           0 :                 break;
     773             :             case SID_DB_APP_EDIT_SQL_VIEW:
     774           0 :                 if ( isDataSourceReadOnly() )
     775           0 :                     aReturn.bEnabled = false;
     776             :                 else
     777             :                 {
     778           0 :                     switch ( getContainer()->getElementType() )
     779             :                     {
     780             :                     case E_QUERY:
     781           0 :                         aReturn.bEnabled =  ( getContainer()->getSelectionCount() > 0 )
     782           0 :                                         &&  ( getContainer()->isALeafSelected() );
     783           0 :                         break;
     784             :                     case E_TABLE:
     785           0 :                         aReturn.bEnabled = false;
     786             :                         // there's one exception: views which support altering their underlying
     787             :                         // command can be edited in SQL view, too
     788           0 :                         if  (   ( getContainer()->getSelectionCount() > 0 )
     789           0 :                             &&  ( getContainer()->isALeafSelected() )
     790             :                             )
     791             :                         {
     792           0 :                             ::std::vector< OUString > aSelected;
     793           0 :                             getSelectionElementNames( aSelected );
     794           0 :                             bool bAlterableViews = true;
     795           0 :                             for (   ::std::vector< OUString >::const_iterator selectedName = aSelected.begin();
     796           0 :                                     bAlterableViews && ( selectedName != aSelected.end() ) ;
     797             :                                     ++selectedName
     798             :                                 )
     799             :                             {
     800           0 :                                 bAlterableViews &= impl_isAlterableView_nothrow( *selectedName );
     801             :                             }
     802           0 :                             aReturn.bEnabled = bAlterableViews;
     803             :                         }
     804           0 :                         break;
     805             :                     default:
     806           0 :                         break;
     807             :                     }
     808             :                 }
     809           0 :                 break;
     810             :             case SID_DB_APP_OPEN:
     811             :             case SID_DB_APP_TABLE_OPEN:
     812             :             case SID_DB_APP_QUERY_OPEN:
     813             :             case SID_DB_APP_FORM_OPEN:
     814             :             case SID_DB_APP_REPORT_OPEN:
     815           0 :                 aReturn.bEnabled = getContainer()->getSelectionCount() > 0 && getContainer()->isALeafSelected();
     816           0 :                 break;
     817             :             case SID_DB_APP_DSUSERADMIN:
     818           0 :                 aReturn.bEnabled = !m_aTypeCollection.isEmbeddedDatabase(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
     819           0 :                 break;
     820             :             case SID_DB_APP_DSRELDESIGN:
     821           0 :                 aReturn.bEnabled = true;
     822           0 :                 break;
     823             :             case SID_DB_APP_TABLEFILTER:
     824           0 :                 aReturn.bEnabled = !isDataSourceReadOnly();
     825           0 :                 break;
     826             :             case SID_DB_APP_REFRESH_TABLES:
     827           0 :                 aReturn.bEnabled = getContainer()->getElementType() == E_TABLE && isConnected();
     828           0 :                 break;
     829             :             case SID_DB_APP_DSPROPS:
     830           0 :                 aReturn.bEnabled = m_xDataSource.is() && m_aTypeCollection.isShowPropertiesEnabled(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
     831           0 :                 break;
     832             :             case SID_DB_APP_DSCONNECTION_TYPE:
     833           0 :                 aReturn.bEnabled = !isDataSourceReadOnly() && m_xDataSource.is() && !m_aTypeCollection.isEmbeddedDatabase(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
     834           0 :                 break;
     835             :             case SID_DB_APP_DSADVANCED_SETTINGS:
     836           0 :                 aReturn.bEnabled = m_xDataSource.is() && AdvancedSettingsDialog::doesHaveAnyAdvancedSettings( m_aTypeCollection.getType(::comphelper::getString( m_xDataSource->getPropertyValue( PROPERTY_URL ) )) );
     837           0 :                 break;
     838             :             case SID_DB_APP_CONVERTTOVIEW:
     839           0 :                 aReturn.bEnabled = !isDataSourceReadOnly();
     840           0 :                 if ( aReturn.bEnabled )
     841             :                 {
     842           0 :                     ElementType eType = getContainer()->getElementType();
     843           0 :                     aReturn.bEnabled = eType == E_QUERY && getContainer()->getSelectionCount() > 0;
     844           0 :                     if ( aReturn.bEnabled )
     845             :                     {
     846           0 :                         Reference<XViewsSupplier> xViewSup( getConnection(), UNO_QUERY );
     847           0 :                         aReturn.bEnabled = xViewSup.is() && Reference<XAppend>(xViewSup->getViews(),UNO_QUERY).is();
     848             :                     }
     849             :                 }
     850           0 :                 break;
     851             :             case SID_DB_APP_DISABLE_PREVIEW:
     852           0 :                 aReturn.bEnabled = true;
     853           0 :                 aReturn.bChecked = getContainer()->getPreviewMode() == E_PREVIEWNONE;
     854           0 :                 break;
     855             :             case SID_DB_APP_VIEW_DOCINFO_PREVIEW:
     856             :                 {
     857           0 :                     ElementType eType = getContainer()->getElementType();
     858           0 :                     aReturn.bEnabled = (E_REPORT == eType || E_FORM == eType);
     859           0 :                     aReturn.bChecked = getContainer()->getPreviewMode() == E_DOCUMENTINFO;
     860             :                 }
     861           0 :                 break;
     862             :             case SID_DB_APP_VIEW_DOC_PREVIEW:
     863           0 :                 aReturn.bEnabled = true;
     864           0 :                 aReturn.bChecked = getContainer()->getPreviewMode() == E_DOCUMENT;
     865           0 :                 break;
     866             :             case ID_BROWSER_UNDO:
     867           0 :                 aReturn.bEnabled = false;
     868           0 :                 break;
     869             :             case SID_MAIL_SENDDOC:
     870           0 :                 aReturn.bEnabled = true;
     871           0 :                 break;
     872             :             case SID_DB_APP_SENDREPORTASMAIL:
     873             :                 {
     874           0 :                     ElementType eType = getContainer()->getElementType();
     875           0 :                     aReturn.bEnabled = E_REPORT == eType && getContainer()->getSelectionCount() > 0 && getContainer()->isALeafSelected();
     876             :                 }
     877           0 :                 break;
     878             :             case SID_DB_APP_SENDREPORTTOWRITER:
     879             :             case SID_DB_APP_DBADMIN:
     880           0 :                 aReturn.bEnabled = false;
     881           0 :                 break;
     882             :             case SID_DB_APP_STATUS_TYPE:
     883           0 :                 aReturn.bEnabled = m_xDataSource.is();
     884           0 :                 if ( aReturn.bEnabled )
     885             :                 {
     886           0 :                     OUString sURL;
     887           0 :                     m_xDataSource->getPropertyValue(PROPERTY_URL) >>= sURL;
     888           0 :                     OUString sDSTypeName;
     889           0 :                     if ( m_aTypeCollection.isEmbeddedDatabase( sURL ) )
     890             :                     {
     891           0 :                         sDSTypeName = OUString( ModuleRes( RID_STR_EMBEDDED_DATABASE ) );
     892             :                     }
     893             :                     else
     894             :                     {
     895           0 :                         sDSTypeName = m_aTypeCollection.getTypeDisplayName(sURL);
     896             :                     }
     897           0 :                     aReturn.sTitle = sDSTypeName;
     898             :                 }
     899           0 :                 break;
     900             :             case SID_DB_APP_STATUS_DBNAME:
     901           0 :                 aReturn.bEnabled = m_xDataSource.is();
     902           0 :                 if ( aReturn.bEnabled )
     903             :                 {
     904           0 :                     OUString sURL;
     905           0 :                     m_xDataSource->getPropertyValue(PROPERTY_URL) >>= sURL;
     906           0 :                     OUString sDatabaseName;
     907           0 :                     OUString sHostName;
     908           0 :                     sal_Int32 nPortNumber( -1 );
     909             : 
     910           0 :                     m_aTypeCollection.extractHostNamePort( sURL, sDatabaseName, sHostName, nPortNumber );
     911             : 
     912           0 :                     if ( sDatabaseName.isEmpty() )
     913           0 :                         sDatabaseName = m_aTypeCollection.cutPrefix( sURL );
     914           0 :                     if ( m_aTypeCollection.isFileSystemBased(sURL) )
     915             :                     {
     916           0 :                         sDatabaseName = SvtPathOptions().SubstituteVariable( sDatabaseName );
     917           0 :                         if ( !sDatabaseName.isEmpty() )
     918             :                         {
     919           0 :                             ::svt::OFileNotation aFileNotation(sDatabaseName);
     920             :                             // set this decoded URL as text
     921           0 :                             sDatabaseName = aFileNotation.get(::svt::OFileNotation::N_SYSTEM);
     922             :                         }
     923             :                     }
     924             : 
     925           0 :                     if ( sDatabaseName.isEmpty() )
     926           0 :                         sDatabaseName = m_aTypeCollection.getTypeDisplayName( sURL );
     927             : 
     928           0 :                     aReturn.sTitle = sDatabaseName;
     929             :                 }
     930           0 :                 break;
     931             :             case SID_DB_APP_STATUS_USERNAME:
     932           0 :                 aReturn.bEnabled = m_xDataSource.is();
     933           0 :                 if ( aReturn.bEnabled )
     934           0 :                     m_xDataSource->getPropertyValue( PROPERTY_USER ) >>= aReturn.sTitle;
     935           0 :                 break;
     936             :             case SID_DB_APP_STATUS_HOSTNAME:
     937           0 :                 aReturn.bEnabled = m_xDataSource.is();
     938           0 :                 if ( aReturn.bEnabled )
     939             :                 {
     940           0 :                     OUString sURL;
     941           0 :                     m_xDataSource->getPropertyValue( PROPERTY_URL ) >>= sURL;
     942             : 
     943           0 :                     OUString sHostName, sDatabaseName;
     944           0 :                     sal_Int32 nPortNumber = -1;
     945           0 :                     m_aTypeCollection.extractHostNamePort( sURL, sDatabaseName, sHostName, nPortNumber );
     946           0 :                     aReturn.sTitle = sHostName;
     947             :                 }
     948           0 :                 break;
     949             :             default:
     950           0 :                 aReturn = OApplicationController_CBASE::GetState(_nId);
     951             :         }
     952             :     }
     953           0 :     catch(const Exception& )
     954             :     {
     955             :         DBG_UNHANDLED_EXCEPTION();
     956             :     }
     957           0 :     return aReturn;
     958             : }
     959             : 
     960             : namespace
     961             : {
     962           0 :     bool lcl_handleException_nothrow( const Reference< XModel >& _rxDocument, const Any& _rException )
     963             :     {
     964           0 :         bool bHandled = false;
     965             : 
     966             :         // try handling the error with an interaction handler
     967           0 :         ::comphelper::NamedValueCollection aArgs( _rxDocument->getArgs() );
     968           0 :         Reference< XInteractionHandler > xHandler( aArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) );
     969           0 :         if ( xHandler.is() )
     970             :         {
     971           0 :             Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( _rException ) );
     972           0 :             Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
     973           0 :             pRequest->addContinuation( pApprove.get() );
     974             : 
     975             :             try
     976             :             {
     977           0 :                 xHandler->handle( pRequest.get() );
     978             :             }
     979           0 :             catch( const Exception& )
     980             :             {
     981             :                 DBG_UNHANDLED_EXCEPTION();
     982             :             }
     983             : 
     984           0 :             bHandled = pApprove->wasSelected();
     985             :         }
     986           0 :         return bHandled;
     987             :     }
     988             : }
     989             : 
     990           0 : void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
     991             : {
     992           0 :     SolarMutexGuard aSolarGuard;
     993           0 :     ::osl::MutexGuard aGuard( getMutex() );
     994             : 
     995           0 :     if ( isUserDefinedFeature( _nId ) )
     996             :     {
     997           0 :         OApplicationController_CBASE::Execute( _nId, aArgs );
     998           0 :         return;
     999             :     }
    1000             : 
    1001           0 :     if ( !getContainer() || m_bReadOnly )
    1002           0 :         return; // return without execution
    1003             : 
    1004             :     try
    1005             :     {
    1006           0 :         switch(_nId)
    1007             :         {
    1008             :             case ID_BROWSER_CUT:
    1009           0 :                 getContainer()->cut();
    1010           0 :                 break;
    1011             :             case ID_BROWSER_COPY:
    1012             :                 {
    1013           0 :                     TransferableHelper* pTransfer = copyObject( );
    1014           0 :                     Reference< XTransferable> aEnsureDelete = pTransfer;
    1015             : 
    1016           0 :                     if ( pTransfer )
    1017           0 :                         pTransfer->CopyToClipboard(getView());
    1018             :                 }
    1019           0 :                 break;
    1020             :             case ID_BROWSER_PASTE:
    1021             :                 {
    1022           0 :                     const TransferableDataHelper& rTransferData( getViewClipboard() );
    1023           0 :                     ElementType eType = getContainer()->getElementType();
    1024             : 
    1025           0 :                     switch( eType )
    1026             :                     {
    1027             :                         case E_TABLE:
    1028             :                             {
    1029             :                                 // get the selected tablename
    1030           0 :                                 ::std::vector< OUString > aList;
    1031           0 :                                 getSelectionElementNames( aList );
    1032           0 :                                 if ( !aList.empty() )
    1033           0 :                                     m_aTableCopyHelper.SetTableNameForAppend( *aList.begin() );
    1034             :                                 else
    1035           0 :                                     m_aTableCopyHelper.ResetTableNameForAppend();
    1036             : 
    1037           0 :                                 m_aTableCopyHelper.pasteTable( rTransferData , getDatabaseName(), ensureConnection() );
    1038             :                             }
    1039           0 :                             break;
    1040             : 
    1041             :                         case E_QUERY:
    1042           0 :                             if ( rTransferData.HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY) )
    1043           0 :                                 paste( E_QUERY, ODataAccessObjectTransferable::extractObjectDescriptor( rTransferData ) );
    1044           0 :                             break;
    1045             :                         default:
    1046             :                             {
    1047           0 :                                 ::std::vector< OUString> aList;
    1048           0 :                                 getSelectionElementNames(aList);
    1049           0 :                                 OUString sFolderNameToInsertInto;
    1050           0 :                                 if ( !aList.empty() )
    1051             :                                 {
    1052           0 :                                     Reference< XHierarchicalNameAccess > xContainer(getElements(eType),UNO_QUERY);
    1053           0 :                                     if ( xContainer.is()
    1054           0 :                                         && xContainer->hasByHierarchicalName(*aList.begin())
    1055           0 :                                         && (xContainer->getByHierarchicalName(*aList.begin()) >>= xContainer)
    1056           0 :                                         && xContainer.is()
    1057             :                                         )
    1058           0 :                                         sFolderNameToInsertInto = *aList.begin();
    1059             :                                 }
    1060             :                                 paste( eType, OComponentTransferable::extractComponentDescriptor( rTransferData ),
    1061           0 :                                     sFolderNameToInsertInto );
    1062             :                             }
    1063           0 :                             break;
    1064             :                     }
    1065             :                 }
    1066           0 :                 break;
    1067             :             case SID_DB_APP_PASTE_SPECIAL:
    1068             :                 {
    1069           0 :                     if ( !aArgs.getLength() )
    1070             :                     {
    1071           0 :                         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    1072             :                         SAL_WNODEPRECATED_DECLARATIONS_PUSH
    1073           0 :                         ::std::auto_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( getView() ));
    1074             :                         SAL_WNODEPRECATED_DECLARATIONS_POP
    1075           0 :                         ::std::vector<SotFormatStringId> aFormatIds;
    1076           0 :                         getSupportedFormats(getContainer()->getElementType(),aFormatIds);
    1077           0 :                         const ::std::vector<SotFormatStringId>::iterator aEnd = aFormatIds.end();
    1078           0 :                         OUString sEmpty;
    1079           0 :                         for (::std::vector<SotFormatStringId>::iterator aIter = aFormatIds.begin();aIter != aEnd; ++aIter)
    1080           0 :                             pDlg->Insert(*aIter,sEmpty);
    1081             : 
    1082           0 :                         const TransferableDataHelper& rClipboard = getViewClipboard();
    1083           0 :                         pasteFormat(pDlg->GetFormat(rClipboard.GetTransferable()));
    1084             :                     }
    1085             :                     else
    1086             :                     {
    1087           0 :                         const PropertyValue* pIter = aArgs.getConstArray();
    1088           0 :                         const PropertyValue* pEnd  = pIter + aArgs.getLength();
    1089           0 :                         for( ; pIter != pEnd ; ++pIter)
    1090             :                         {
    1091           0 :                             if ( pIter->Name == "FormatStringId" )
    1092             :                             {
    1093           0 :                                 SotFormatStringId nFormatId = 0;
    1094           0 :                                 if ( pIter->Value >>= nFormatId )
    1095           0 :                                     pasteFormat(nFormatId);
    1096           0 :                                 break;
    1097             :                             }
    1098             :                         }
    1099             :                     }
    1100             :                 }
    1101           0 :                 break;
    1102             :             case SID_OPENDOC:
    1103             :             case SID_HELP_INDEX:
    1104             :                 {
    1105           0 :                     Reference < XDispatchProvider > xProv( getFrame(), UNO_QUERY );
    1106           0 :                     if ( xProv.is() )
    1107             :                     {
    1108           0 :                         URL aURL;
    1109           0 :                         switch(_nId)
    1110             :                         {
    1111             :                             case SID_HELP_INDEX:
    1112           0 :                                 aURL.Complete = ".uno:HelpIndex";
    1113           0 :                                 break;
    1114             :                             case SID_OPENDOC:
    1115           0 :                                 aURL.Complete = ".uno:Open";
    1116           0 :                                 break;
    1117             :                         }
    1118             : 
    1119           0 :                         if ( m_xUrlTransformer.is() )
    1120           0 :                             m_xUrlTransformer->parseStrict( aURL );
    1121           0 :                         Reference < XDispatch > xDisp = xProv->queryDispatch( aURL, OUString(), 0 );
    1122           0 :                         if ( xDisp.is() )
    1123           0 :                             xDisp->dispatch( aURL, Sequence < PropertyValue >() );
    1124           0 :                     }
    1125             :                 }
    1126           0 :                 break;
    1127             :             case ID_BROWSER_SAVEDOC:
    1128             :                 {
    1129           0 :                     Reference< XStorable > xStore( m_xModel, UNO_QUERY_THROW );
    1130             :                     try
    1131             :                     {
    1132           0 :                         xStore->store();
    1133             :                     }
    1134           0 :                     catch( const Exception& )
    1135             :                     {
    1136           0 :                         lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() );
    1137           0 :                     }
    1138             :                 }
    1139           0 :                 break;
    1140             : 
    1141             :             case ID_BROWSER_SAVEASDOC:
    1142             :                 {
    1143           0 :                     OUString sUrl;
    1144           0 :                     if ( m_xModel.is() )
    1145           0 :                         sUrl = m_xModel->getURL();
    1146           0 :                     if ( sUrl.isEmpty() )
    1147           0 :                         sUrl = SvtPathOptions().GetWorkPath();
    1148             : 
    1149             :                     ::sfx2::FileDialogHelper aFileDlg(
    1150             :                         ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
    1151           0 :                         0, getView());
    1152           0 :                     aFileDlg.SetDisplayDirectory( sUrl );
    1153             : 
    1154           0 :                     const SfxFilter* pFilter = getStandardDatabaseFilter();
    1155           0 :                     if ( pFilter )
    1156             :                     {
    1157           0 :                         aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
    1158           0 :                         aFileDlg.SetCurrentFilter(pFilter->GetUIName());
    1159             :                     }
    1160             : 
    1161           0 :                     if ( aFileDlg.Execute() != ERRCODE_NONE )
    1162           0 :                         break;
    1163             : 
    1164           0 :                     Reference<XStorable> xStore( m_xModel, UNO_QUERY_THROW );
    1165           0 :                     INetURLObject aURL( aFileDlg.GetPath() );
    1166             :                     try
    1167             :                     {
    1168           0 :                         xStore->storeAsURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), Sequence< PropertyValue >() );
    1169             :                     }
    1170           0 :                     catch( const Exception& )
    1171             :                     {
    1172           0 :                         lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() );
    1173             :                     }
    1174             : 
    1175             :                     /*updateTitle();*/
    1176           0 :                     m_bCurrentlyModified = false;
    1177           0 :                     InvalidateFeature(ID_BROWSER_SAVEDOC);
    1178           0 :                     if ( getContainer()->getElementType() == E_NONE )
    1179             :                     {
    1180           0 :                         getContainer()->selectContainer(E_NONE);
    1181           0 :                         getContainer()->selectContainer(E_TABLE);
    1182             :                         // #i95524#
    1183           0 :                         getContainer()->Invalidate();
    1184           0 :                         refreshTables();
    1185           0 :                     }
    1186             : 
    1187             :                 }
    1188           0 :                 break;
    1189             :             case ID_BROWSER_SORTUP:
    1190           0 :                 getContainer()->sortUp();
    1191           0 :                 InvalidateFeature(ID_BROWSER_SORTDOWN);
    1192           0 :                 break;
    1193             :             case ID_BROWSER_SORTDOWN:
    1194           0 :                 getContainer()->sortDown();
    1195           0 :                 InvalidateFeature(ID_BROWSER_SORTUP);
    1196           0 :                 break;
    1197             : 
    1198             :             case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
    1199             :             case ID_NEW_VIEW_DESIGN_AUTO_PILOT:
    1200             :             case ID_APP_NEW_QUERY_AUTO_PILOT:
    1201             :             case SID_DB_FORM_NEW_PILOT:
    1202             :             case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
    1203             :             case SID_APP_NEW_REPORT_PRE_SEL:
    1204             :             case SID_FORM_CREATE_REPWIZ_PRE_SEL:
    1205             :             case ID_DOCUMENT_CREATE_REPWIZ:
    1206             :             case SID_APP_NEW_FORM:
    1207             :             case SID_APP_NEW_REPORT:
    1208             :             case ID_NEW_QUERY_SQL:
    1209             :             case ID_NEW_QUERY_DESIGN:
    1210             :             case ID_NEW_TABLE_DESIGN:
    1211             :                 {
    1212           0 :                     ElementType eType = E_TABLE;
    1213           0 :                     sal_Bool bAutoPilot = sal_False;
    1214           0 :                     ::comphelper::NamedValueCollection aCreationArgs;
    1215             : 
    1216           0 :                     switch( _nId )
    1217             :                     {
    1218             :                         case SID_DB_FORM_NEW_PILOT:
    1219             :                         case SID_FORM_CREATE_REPWIZ_PRE_SEL:
    1220           0 :                             bAutoPilot = sal_True;
    1221             :                             // run through
    1222             :                         case SID_APP_NEW_FORM:
    1223           0 :                             eType = E_FORM;
    1224           0 :                             break;
    1225             :                         case ID_DOCUMENT_CREATE_REPWIZ:
    1226             :                         case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
    1227           0 :                             bAutoPilot = sal_True;
    1228             :                             // run through
    1229             :                         case SID_APP_NEW_REPORT:
    1230             :                         case SID_APP_NEW_REPORT_PRE_SEL:
    1231           0 :                             eType = E_REPORT;
    1232           0 :                             break;
    1233             :                         case ID_APP_NEW_QUERY_AUTO_PILOT:
    1234           0 :                             bAutoPilot = sal_True;
    1235           0 :                             eType = E_QUERY;
    1236           0 :                             break;
    1237             :                         case ID_NEW_QUERY_DESIGN:
    1238           0 :                             aCreationArgs.put( (OUString)PROPERTY_GRAPHICAL_DESIGN, sal_True );
    1239             :                             // run through
    1240             :                         case ID_NEW_QUERY_SQL:
    1241           0 :                             eType = E_QUERY;
    1242           0 :                             break;
    1243             :                          case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
    1244           0 :                              bAutoPilot = sal_True;
    1245             :                              // run through
    1246             :                         case ID_NEW_TABLE_DESIGN:
    1247           0 :                             break;
    1248             :                         default:
    1249             :                             OSL_FAIL("illegal switch call!");
    1250             :                     }
    1251           0 :                     if ( bAutoPilot )
    1252           0 :                         getContainer()->PostUserEvent( LINK( this, OApplicationController, OnCreateWithPilot ), reinterpret_cast< void* >( eType ) );
    1253             :                     else
    1254             :                     {
    1255           0 :                         Reference< XComponent > xDocDefinition;
    1256           0 :                         newElement( eType, aCreationArgs, xDocDefinition );
    1257           0 :                     }
    1258             :                 }
    1259           0 :                 break;
    1260             :             case SID_APP_NEW_FOLDER:
    1261             :                 {
    1262           0 :                     ElementType eType = getContainer()->getElementType();
    1263           0 :                     OUString sName = getContainer()->getQualifiedName( NULL );
    1264           0 :                     insertHierachyElement(eType,sName);
    1265             :                 }
    1266           0 :                 break;
    1267             :             case ID_NEW_VIEW_DESIGN:
    1268             :             case SID_DB_NEW_VIEW_SQL:
    1269             :                 {
    1270           0 :                     SharedConnection xConnection( ensureConnection() );
    1271           0 :                     if ( xConnection.is() )
    1272             :                     {
    1273           0 :                         QueryDesigner aDesigner( getORB(), this, getFrame(), true );
    1274             : 
    1275           0 :                         ::comphelper::NamedValueCollection aCreationArgs;
    1276           0 :                         aCreationArgs.put( (OUString)PROPERTY_GRAPHICAL_DESIGN, ID_NEW_VIEW_DESIGN == _nId );
    1277             : 
    1278           0 :                         const Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
    1279           0 :                         const Reference< XComponent > xComponent( aDesigner.createNew( xDataSource, aCreationArgs ), UNO_QUERY );
    1280           0 :                         onDocumentOpened( OUString(), E_QUERY, E_OPEN_DESIGN, xComponent, NULL );
    1281           0 :                     }
    1282             :                 }
    1283           0 :                 break;
    1284             :             case SID_DB_APP_DELETE:
    1285             :             case SID_DB_APP_TABLE_DELETE:
    1286             :             case SID_DB_APP_QUERY_DELETE:
    1287             :             case SID_DB_APP_FORM_DELETE:
    1288             :             case SID_DB_APP_REPORT_DELETE:
    1289           0 :                 deleteEntries();
    1290           0 :                 break;
    1291             :             case SID_DB_APP_RENAME:
    1292             :             case SID_DB_APP_TABLE_RENAME:
    1293             :             case SID_DB_APP_QUERY_RENAME:
    1294             :             case SID_DB_APP_FORM_RENAME:
    1295             :             case SID_DB_APP_REPORT_RENAME:
    1296           0 :                 renameEntry();
    1297           0 :                 break;
    1298             :             case SID_DB_APP_EDIT:
    1299             :             case SID_DB_APP_EDIT_SQL_VIEW:
    1300             :             case SID_DB_APP_TABLE_EDIT:
    1301             :             case SID_DB_APP_QUERY_EDIT:
    1302             :             case SID_DB_APP_FORM_EDIT:
    1303             :             case SID_DB_APP_REPORT_EDIT:
    1304           0 :                 doAction( _nId, E_OPEN_DESIGN );
    1305           0 :                 break;
    1306             :             case SID_DB_APP_OPEN:
    1307             :             case SID_DB_APP_TABLE_OPEN:
    1308             :             case SID_DB_APP_QUERY_OPEN:
    1309             :             case SID_DB_APP_FORM_OPEN:
    1310             :             case SID_DB_APP_REPORT_OPEN:
    1311           0 :                 doAction( _nId, E_OPEN_NORMAL );
    1312           0 :                 break;
    1313             :             case SID_DB_APP_CONVERTTOVIEW:
    1314           0 :                 doAction( _nId, E_OPEN_NORMAL );
    1315           0 :                 break;
    1316             :             case SID_SELECTALL:
    1317           0 :                 getContainer()->selectAll();
    1318           0 :                 InvalidateAll();
    1319           0 :                 break;
    1320             :             case SID_DB_APP_DSRELDESIGN:
    1321             :             {
    1322           0 :                 Reference< XComponent > xRelationDesigner;
    1323           0 :                 if ( !m_pSubComponentManager->activateSubFrame( OUString(), SID_DB_APP_DSRELDESIGN, E_OPEN_DESIGN, xRelationDesigner ) )
    1324             :                 {
    1325           0 :                     SharedConnection xConnection( ensureConnection() );
    1326           0 :                     if ( xConnection.is() )
    1327             :                     {
    1328           0 :                         RelationDesigner aDesigner( getORB(), this, m_aCurrentFrame.getFrame() );
    1329             : 
    1330           0 :                         const Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
    1331           0 :                         const Reference< XComponent > xComponent( aDesigner.createNew( xDataSource ), UNO_QUERY );
    1332           0 :                         onDocumentOpened( OUString(), SID_DB_APP_DSRELDESIGN, E_OPEN_DESIGN, xComponent, NULL );
    1333           0 :                     }
    1334           0 :                 }
    1335             :             }
    1336           0 :             break;
    1337             :             case SID_DB_APP_DSUSERADMIN:
    1338             :                 {
    1339           0 :                     SharedConnection xConnection( ensureConnection() );
    1340           0 :                     if ( xConnection.is() )
    1341           0 :                         openDialog(OUString("com.sun.star.sdb.UserAdministrationDialog"));
    1342             :                 }
    1343           0 :                 break;
    1344             :             case SID_DB_APP_TABLEFILTER:
    1345           0 :                 openTableFilterDialog();
    1346           0 :                 askToReconnect();
    1347           0 :                 break;
    1348             :             case SID_DB_APP_REFRESH_TABLES:
    1349           0 :                 refreshTables();
    1350           0 :                 break;
    1351             :             case SID_DB_APP_DSPROPS:
    1352           0 :                 openDataSourceAdminDialog();
    1353           0 :                 askToReconnect();
    1354           0 :                 break;
    1355             :             case SID_DB_APP_DSADVANCED_SETTINGS:
    1356           0 :                 openDialog(OUString("com.sun.star.sdb.AdvancedDatabaseSettingsDialog"));
    1357           0 :                 askToReconnect();
    1358           0 :                 break;
    1359             :             case SID_DB_APP_DSCONNECTION_TYPE:
    1360           0 :                 openDialog(OUString("com.sun.star.sdb.DataSourceTypeChangeDialog"));
    1361           0 :                 askToReconnect();
    1362           0 :                 break;
    1363             :             case ID_DIRECT_SQL:
    1364             :                 {
    1365           0 :                     SharedConnection xConnection( ensureConnection() );
    1366           0 :                     if ( xConnection.is() )
    1367           0 :                         openDirectSQLDialog();
    1368             :                 }
    1369           0 :                 break;
    1370             :             case ID_MIGRATE_SCRIPTS:
    1371           0 :                 impl_migrateScripts_nothrow();
    1372           0 :                 break;
    1373             :             case SID_DB_APP_VIEW_TABLES:
    1374           0 :                 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_TABLE ) );
    1375           0 :                 break;
    1376             :             case SID_DB_APP_VIEW_QUERIES:
    1377           0 :                 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_QUERY ) );
    1378           0 :                 break;
    1379             :             case SID_DB_APP_VIEW_FORMS:
    1380           0 :                 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_FORM ) );
    1381           0 :                 break;
    1382             :             case SID_DB_APP_VIEW_REPORTS:
    1383           0 :                 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_REPORT ) );
    1384           0 :                 break;
    1385             :             case SID_DB_APP_DISABLE_PREVIEW:
    1386           0 :                 m_ePreviewMode = E_PREVIEWNONE;
    1387           0 :                 getContainer()->switchPreview(m_ePreviewMode);
    1388           0 :                 break;
    1389             :             case SID_DB_APP_VIEW_DOCINFO_PREVIEW:
    1390           0 :                 m_ePreviewMode = E_DOCUMENTINFO;
    1391           0 :                 getContainer()->switchPreview(m_ePreviewMode);
    1392           0 :                 break;
    1393             :             case SID_DB_APP_VIEW_DOC_PREVIEW:
    1394           0 :                 m_ePreviewMode = E_DOCUMENT;
    1395           0 :                 getContainer()->switchPreview(m_ePreviewMode);
    1396           0 :                 break;
    1397             :             case SID_MAIL_SENDDOC:
    1398             :                 {
    1399           0 :                     SfxMailModel aSendMail;
    1400           0 :                     if ( aSendMail.AttachDocument(OUString(),getModel(), OUString()) == SfxMailModel::SEND_MAIL_OK )
    1401           0 :                         aSendMail.Send( getFrame() );
    1402             :                 }
    1403           0 :                 break;
    1404             :             case SID_DB_APP_SENDREPORTASMAIL:
    1405           0 :                 doAction( _nId, E_OPEN_FOR_MAIL );
    1406           0 :                 break;
    1407             :         }
    1408             :     }
    1409           0 :     catch( const Exception& )
    1410             :     {
    1411             :         DBG_UNHANDLED_EXCEPTION();
    1412             :     }
    1413           0 :     InvalidateFeature(_nId);
    1414             : }
    1415             : 
    1416           0 : void OApplicationController::describeSupportedFeatures()
    1417             : {
    1418           0 :     OApplicationController_CBASE::describeSupportedFeatures();
    1419             : 
    1420           0 :     implDescribeSupportedFeature( ".uno:Save",               ID_BROWSER_SAVEDOC,        CommandGroup::DOCUMENT );
    1421           0 :     implDescribeSupportedFeature( ".uno:SaveAs",             ID_BROWSER_SAVEASDOC,      CommandGroup::DOCUMENT );
    1422           0 :     implDescribeSupportedFeature( ".uno:SendMail",           SID_MAIL_SENDDOC,          CommandGroup::DOCUMENT );
    1423             :     implDescribeSupportedFeature( ".uno:DBSendReportAsMail",SID_DB_APP_SENDREPORTASMAIL,
    1424           0 :                                                                                         CommandGroup::DOCUMENT );
    1425             :     implDescribeSupportedFeature( ".uno:DBSendReportToWriter",SID_DB_APP_SENDREPORTTOWRITER,
    1426           0 :                                                                                         CommandGroup::DOCUMENT );
    1427           0 :     implDescribeSupportedFeature( ".uno:DBNewForm",          SID_APP_NEW_FORM,          CommandGroup::INSERT );
    1428           0 :     implDescribeSupportedFeature( ".uno:DBNewFolder",        SID_APP_NEW_FOLDER,        CommandGroup::INSERT );
    1429           0 :     implDescribeSupportedFeature( ".uno:DBNewFormAutoPilot", SID_DB_FORM_NEW_PILOT,     CommandGroup::INSERT );
    1430             :     implDescribeSupportedFeature( ".uno:DBNewFormAutoPilotWithPreSelection",
    1431             :                                                              SID_FORM_CREATE_REPWIZ_PRE_SEL,
    1432           0 :                                                                                         CommandGroup::APPLICATION );
    1433             : 
    1434           0 :     implDescribeSupportedFeature( ".uno:DBNewReport",        SID_APP_NEW_REPORT,        CommandGroup::INSERT );
    1435             :     implDescribeSupportedFeature( ".uno:DBNewReportAutoPilot",
    1436           0 :                                                              ID_DOCUMENT_CREATE_REPWIZ, CommandGroup::INSERT );
    1437             :     implDescribeSupportedFeature( ".uno:DBNewReportAutoPilotWithPreSelection",
    1438             :                                                              SID_REPORT_CREATE_REPWIZ_PRE_SEL,
    1439           0 :                                                                                         CommandGroup::APPLICATION );
    1440           0 :     implDescribeSupportedFeature( ".uno:DBNewQuery",         ID_NEW_QUERY_DESIGN,       CommandGroup::INSERT );
    1441           0 :     implDescribeSupportedFeature( ".uno:DBNewQuerySql",      ID_NEW_QUERY_SQL,          CommandGroup::INSERT );
    1442             :     implDescribeSupportedFeature( ".uno:DBNewQueryAutoPilot",ID_APP_NEW_QUERY_AUTO_PILOT,
    1443           0 :                                                                                         CommandGroup::INSERT );
    1444           0 :     implDescribeSupportedFeature( ".uno:DBNewTable",         ID_NEW_TABLE_DESIGN,       CommandGroup::INSERT );
    1445             :     implDescribeSupportedFeature( ".uno:DBNewTableAutoPilot",ID_NEW_TABLE_DESIGN_AUTO_PILOT,
    1446           0 :                                                                                         CommandGroup::INSERT );
    1447           0 :     implDescribeSupportedFeature( ".uno:DBNewView",          ID_NEW_VIEW_DESIGN,        CommandGroup::INSERT );
    1448           0 :     implDescribeSupportedFeature( ".uno:DBNewViewSQL",       SID_DB_NEW_VIEW_SQL,       CommandGroup::INSERT );
    1449             : 
    1450           0 :     implDescribeSupportedFeature( ".uno:DBDelete",           SID_DB_APP_DELETE,         CommandGroup::EDIT );
    1451           0 :     implDescribeSupportedFeature( ".uno:Delete",             SID_DB_APP_DELETE,         CommandGroup::EDIT );
    1452           0 :     implDescribeSupportedFeature( ".uno:DBRename",           SID_DB_APP_RENAME,         CommandGroup::EDIT );
    1453           0 :     implDescribeSupportedFeature( ".uno:DBEdit",             SID_DB_APP_EDIT,           CommandGroup::EDIT );
    1454           0 :     implDescribeSupportedFeature( ".uno:DBEditSqlView",      SID_DB_APP_EDIT_SQL_VIEW,  CommandGroup::EDIT );
    1455           0 :     implDescribeSupportedFeature( ".uno:DBOpen",             SID_DB_APP_OPEN,           CommandGroup::EDIT );
    1456             : 
    1457           0 :     implDescribeSupportedFeature( ".uno:DBTableDelete",      SID_DB_APP_TABLE_DELETE,   CommandGroup::EDIT );
    1458           0 :     implDescribeSupportedFeature( ".uno:DBTableRename",      SID_DB_APP_TABLE_RENAME,   CommandGroup::EDIT );
    1459           0 :     implDescribeSupportedFeature( ".uno:DBTableEdit",        SID_DB_APP_TABLE_EDIT,     CommandGroup::EDIT );
    1460           0 :     implDescribeSupportedFeature( ".uno:DBTableOpen",        SID_DB_APP_TABLE_OPEN,     CommandGroup::EDIT );
    1461             : 
    1462           0 :     implDescribeSupportedFeature( ".uno:DBQueryDelete",      SID_DB_APP_QUERY_DELETE,   CommandGroup::EDIT );
    1463           0 :     implDescribeSupportedFeature( ".uno:DBQueryRename",      SID_DB_APP_QUERY_RENAME,   CommandGroup::EDIT );
    1464           0 :     implDescribeSupportedFeature( ".uno:DBQueryEdit",        SID_DB_APP_QUERY_EDIT,     CommandGroup::EDIT );
    1465           0 :     implDescribeSupportedFeature( ".uno:DBQueryOpen",        SID_DB_APP_QUERY_OPEN,     CommandGroup::EDIT );
    1466             : 
    1467           0 :     implDescribeSupportedFeature( ".uno:DBFormDelete",       SID_DB_APP_FORM_DELETE,    CommandGroup::EDIT );
    1468           0 :     implDescribeSupportedFeature( ".uno:DBFormRename",       SID_DB_APP_FORM_RENAME,    CommandGroup::EDIT );
    1469           0 :     implDescribeSupportedFeature( ".uno:DBFormEdit",         SID_DB_APP_FORM_EDIT,      CommandGroup::EDIT );
    1470           0 :     implDescribeSupportedFeature( ".uno:DBFormOpen",         SID_DB_APP_FORM_OPEN,      CommandGroup::EDIT );
    1471             : 
    1472           0 :     implDescribeSupportedFeature( ".uno:DBReportDelete",     SID_DB_APP_REPORT_DELETE,  CommandGroup::EDIT );
    1473           0 :     implDescribeSupportedFeature( ".uno:DBReportRename",     SID_DB_APP_REPORT_RENAME,  CommandGroup::EDIT );
    1474           0 :     implDescribeSupportedFeature( ".uno:DBReportEdit",       SID_DB_APP_REPORT_EDIT,    CommandGroup::EDIT );
    1475           0 :     implDescribeSupportedFeature( ".uno:DBReportOpen",       SID_DB_APP_REPORT_OPEN,    CommandGroup::EDIT );
    1476             : 
    1477           0 :     implDescribeSupportedFeature( ".uno:SelectAll",          SID_SELECTALL,             CommandGroup::EDIT );
    1478           0 :     implDescribeSupportedFeature( ".uno:Undo",               ID_BROWSER_UNDO,           CommandGroup::EDIT );
    1479             : 
    1480           0 :     implDescribeSupportedFeature( ".uno:Sortup",             ID_BROWSER_SORTUP,         CommandGroup::VIEW );
    1481           0 :     implDescribeSupportedFeature( ".uno:SortDown",           ID_BROWSER_SORTDOWN,       CommandGroup::VIEW );
    1482           0 :     implDescribeSupportedFeature( ".uno:DBRelationDesign",   SID_DB_APP_DSRELDESIGN,    CommandGroup::APPLICATION );
    1483           0 :     implDescribeSupportedFeature( ".uno:DBUserAdmin",        SID_DB_APP_DSUSERADMIN,    CommandGroup::APPLICATION );
    1484           0 :     implDescribeSupportedFeature( ".uno:DBTableFilter",      SID_DB_APP_TABLEFILTER,    CommandGroup::APPLICATION );
    1485           0 :     implDescribeSupportedFeature( ".uno:DBDSProperties",     SID_DB_APP_DSPROPS,        CommandGroup::EDIT );
    1486             :     implDescribeSupportedFeature( ".uno:DBDSConnectionType", SID_DB_APP_DSCONNECTION_TYPE,
    1487           0 :                                                                                         CommandGroup::EDIT );
    1488             :     implDescribeSupportedFeature( ".uno:DBDSAdvancedSettings",
    1489             :                                                              SID_DB_APP_DSADVANCED_SETTINGS,
    1490           0 :                                                                                         CommandGroup::EDIT );
    1491           0 :     implDescribeSupportedFeature( ".uno:PasteSpecial",       SID_DB_APP_PASTE_SPECIAL,  CommandGroup::EDIT );
    1492           0 :     implDescribeSupportedFeature( ".uno:DBConvertToView",    SID_DB_APP_CONVERTTOVIEW,  CommandGroup::EDIT );
    1493           0 :     implDescribeSupportedFeature( ".uno:DBRefreshTables",    SID_DB_APP_REFRESH_TABLES, CommandGroup::APPLICATION );
    1494           0 :     implDescribeSupportedFeature( ".uno:DBDirectSQL",        ID_DIRECT_SQL,             CommandGroup::APPLICATION );
    1495           0 :     implDescribeSupportedFeature( ".uno:DBMigrateScripts",   ID_MIGRATE_SCRIPTS,        CommandGroup::APPLICATION );
    1496           0 :     implDescribeSupportedFeature( ".uno:DBViewTables",       SID_DB_APP_VIEW_TABLES,    CommandGroup::VIEW );
    1497           0 :     implDescribeSupportedFeature( ".uno:DBViewQueries",      SID_DB_APP_VIEW_QUERIES,   CommandGroup::VIEW );
    1498           0 :     implDescribeSupportedFeature( ".uno:DBViewForms",        SID_DB_APP_VIEW_FORMS,     CommandGroup::VIEW );
    1499           0 :     implDescribeSupportedFeature( ".uno:DBViewReports",      SID_DB_APP_VIEW_REPORTS,   CommandGroup::VIEW );
    1500           0 :     implDescribeSupportedFeature( ".uno:DBDisablePreview",   SID_DB_APP_DISABLE_PREVIEW,CommandGroup::VIEW );
    1501             :     implDescribeSupportedFeature( ".uno:DBShowDocInfoPreview",
    1502             :                                                              SID_DB_APP_VIEW_DOCINFO_PREVIEW,
    1503           0 :                                                                                         CommandGroup::VIEW );
    1504             :     implDescribeSupportedFeature( ".uno:DBShowDocPreview",   SID_DB_APP_VIEW_DOC_PREVIEW,
    1505           0 :                                                                                         CommandGroup::VIEW );
    1506             : 
    1507           0 :     implDescribeSupportedFeature( ".uno:OpenUrl",            SID_OPENURL,               CommandGroup::APPLICATION );
    1508             : 
    1509             :     // this one should not appear under Tools->Customize->Keyboard
    1510             :     implDescribeSupportedFeature( ".uno:DBNewReportWithPreSelection",
    1511           0 :                                                              SID_APP_NEW_REPORT_PRE_SEL,CommandGroup::INTERNAL );
    1512           0 :     implDescribeSupportedFeature( ".uno:DBDSImport",        SID_DB_APP_DSIMPORT, CommandGroup::INTERNAL);
    1513           0 :     implDescribeSupportedFeature( ".uno:DBDSExport",        SID_DB_APP_DSEXPORT, CommandGroup::INTERNAL);
    1514           0 :     implDescribeSupportedFeature( ".uno:DBDBAdmin",         SID_DB_APP_DBADMIN, CommandGroup::INTERNAL);
    1515             : 
    1516             :     // status info
    1517           0 :     implDescribeSupportedFeature( ".uno:DBStatusType",      SID_DB_APP_STATUS_TYPE, CommandGroup::INTERNAL);
    1518           0 :     implDescribeSupportedFeature( ".uno:DBStatusDBName",    SID_DB_APP_STATUS_DBNAME, CommandGroup::INTERNAL);
    1519           0 :     implDescribeSupportedFeature( ".uno:DBStatusUserName",  SID_DB_APP_STATUS_USERNAME, CommandGroup::INTERNAL);
    1520           0 :     implDescribeSupportedFeature( ".uno:DBStatusHostName",  SID_DB_APP_STATUS_HOSTNAME, CommandGroup::INTERNAL);
    1521           0 : }
    1522             : 
    1523           0 : OApplicationView*   OApplicationController::getContainer() const
    1524             : {
    1525           0 :     return static_cast< OApplicationView* >( getView() );
    1526             : }
    1527             : 
    1528             : // ::com::sun::star::container::XContainerListener
    1529           0 : void SAL_CALL OApplicationController::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
    1530             : {
    1531           0 :     SolarMutexGuard aSolarGuard;
    1532           0 :     ::osl::MutexGuard aGuard( getMutex() );
    1533             : 
    1534           0 :     Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
    1535           0 :     if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
    1536             :     {
    1537             :         OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
    1538           0 :         if ( getContainer() )
    1539             :         {
    1540           0 :             OUString sName;
    1541           0 :             _rEvent.Accessor >>= sName;
    1542           0 :             ElementType eType = getElementType(xContainer);
    1543             : 
    1544           0 :             switch( eType )
    1545             :             {
    1546             :                 case E_TABLE:
    1547           0 :                     ensureConnection();
    1548           0 :                     break;
    1549             :                 case E_FORM:
    1550             :                 case E_REPORT:
    1551             :                     {
    1552           0 :                         Reference< XContainer > xSubContainer(_rEvent.Element,UNO_QUERY);
    1553           0 :                         if ( xSubContainer.is() )
    1554           0 :                             containerFound(xSubContainer);
    1555             :                     }
    1556           0 :                     break;
    1557             :                 default:
    1558           0 :                     break;
    1559             :             }
    1560           0 :             getContainer()->elementAdded(eType,sName,_rEvent.Element);
    1561             :         }
    1562           0 :     }
    1563           0 : }
    1564             : 
    1565           0 : void SAL_CALL OApplicationController::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
    1566             : {
    1567           0 :     SolarMutexGuard aSolarGuard;
    1568           0 :     ::osl::MutexGuard aGuard( getMutex() );
    1569             : 
    1570           0 :     Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
    1571           0 :     if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
    1572             :     {
    1573             :         OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
    1574           0 :         OUString sName;
    1575           0 :         _rEvent.Accessor >>= sName;
    1576           0 :         ElementType eType = getElementType(xContainer);
    1577           0 :         switch( eType )
    1578             :         {
    1579             :             case E_TABLE:
    1580           0 :                 ensureConnection();
    1581           0 :                 break;
    1582             :             case E_FORM:
    1583             :             case E_REPORT:
    1584             :                 {
    1585           0 :                     Reference<XContent> xContent(xContainer,UNO_QUERY);
    1586           0 :                     if ( xContent.is() )
    1587             :                     {
    1588           0 :                         sName = xContent->getIdentifier()->getContentIdentifier() + "/" + sName;
    1589           0 :                     }
    1590             :                 }
    1591           0 :                 break;
    1592             :             default:
    1593           0 :                 break;
    1594             :         }
    1595           0 :         getContainer()->elementRemoved(eType,sName);
    1596           0 :     }
    1597           0 : }
    1598             : 
    1599           0 : void SAL_CALL OApplicationController::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
    1600             : {
    1601           0 :     SolarMutexGuard aSolarGuard;
    1602           0 :     ::osl::MutexGuard aGuard( getMutex() );
    1603             : 
    1604           0 :     Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
    1605           0 :     if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
    1606             :     {
    1607             :         OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
    1608           0 :         OUString sName;
    1609             :         try
    1610             :         {
    1611           0 :             _rEvent.Accessor >>= sName;
    1612           0 :             Reference<XConnection> xConnection;
    1613           0 :             Reference<XPropertySet> xProp(_rEvent.Element,UNO_QUERY);
    1614           0 :             OUString sNewName;
    1615             : 
    1616           0 :             ElementType eType = getElementType(xContainer);
    1617           0 :             switch( eType )
    1618             :             {
    1619             :                 case E_TABLE:
    1620             :                 {
    1621           0 :                     ensureConnection();
    1622           0 :                     if ( xProp.is() && m_xMetaData.is() )
    1623           0 :                         sNewName = ::dbaui::composeTableName( m_xMetaData, xProp, ::dbtools::eInDataManipulation, false, false, false );
    1624             :                 }
    1625           0 :                 break;
    1626             :                 case E_FORM:
    1627             :                 case E_REPORT:
    1628             :                     {
    1629           0 :                         Reference<XContent> xContent(xContainer,UNO_QUERY);
    1630           0 :                         if ( xContent.is() )
    1631             :                         {
    1632           0 :                             sName = xContent->getIdentifier()->getContentIdentifier() + "/" + sName;
    1633           0 :                         }
    1634             :                     }
    1635           0 :                     break;
    1636             :                 default:
    1637           0 :                     break;
    1638           0 :             }
    1639             :             //  getContainer()->elementReplaced(getContainer()->getElementType(),sName,sNewName);
    1640             :         }
    1641           0 :         catch( Exception& )
    1642             :         {
    1643             :             DBG_UNHANDLED_EXCEPTION();
    1644           0 :         }
    1645           0 :     }
    1646           0 : }
    1647             : 
    1648             : namespace
    1649             : {
    1650           0 :     OUString lcl_getToolBarResource(ElementType _eType)
    1651             :     {
    1652           0 :         OUString sToolbar;
    1653           0 :         switch(_eType)
    1654             :         {
    1655             :             case E_TABLE:
    1656           0 :                 sToolbar = "private:resource/toolbar/tableobjectbar";
    1657           0 :                 break;
    1658             :             case E_QUERY:
    1659           0 :                 sToolbar = "private:resource/toolbar/queryobjectbar";
    1660           0 :                 break;
    1661             :             case E_FORM:
    1662           0 :                 sToolbar = "private:resource/toolbar/formobjectbar";
    1663           0 :                 break;
    1664             :             case E_REPORT:
    1665           0 :                 sToolbar = "private:resource/toolbar/reportobjectbar";
    1666           0 :                 break;
    1667             :             case E_NONE:
    1668           0 :                 break;
    1669             :             default:
    1670             :                 OSL_FAIL("Invalid ElementType!");
    1671           0 :                 break;
    1672             :         }
    1673           0 :         return sToolbar;
    1674             :     }
    1675             : }
    1676             : 
    1677           0 : sal_Bool OApplicationController::onContainerSelect(ElementType _eType)
    1678             : {
    1679             :     OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
    1680             : 
    1681           0 :     if ( m_eCurrentType != _eType && _eType != E_NONE )
    1682             :     {
    1683           0 :         SelectionGuard aSelGuard( *m_pSelectionNotifier );
    1684             : 
    1685           0 :         if ( _eType == E_TABLE )
    1686             :         {
    1687             :             try
    1688             :             {
    1689           0 :                 SharedConnection xConnection( ensureConnection() );
    1690           0 :                 if ( xConnection.is() && getContainer()->getDetailView() )
    1691             :                 {
    1692           0 :                     getContainer()->getDetailView()->createTablesPage(xConnection);
    1693           0 :                     Reference<XTablesSupplier> xTabSup(xConnection,UNO_QUERY);
    1694           0 :                     if ( xTabSup.is() )
    1695           0 :                         addContainerListener(xTabSup->getTables());
    1696             :                 }
    1697             :                 else
    1698             :                 {
    1699           0 :                     return sal_False;
    1700           0 :                 }
    1701             :             }
    1702           0 :             catch( const Exception& )
    1703             :             {
    1704           0 :                 return sal_False;
    1705             :             }
    1706             :         }
    1707           0 :         Reference< XLayoutManager > xLayoutManager = getLayoutManager( getFrame() );
    1708           0 :         if ( xLayoutManager.is() )
    1709             :         {
    1710           0 :             OUString sToolbar = lcl_getToolBarResource(_eType);
    1711           0 :             OUString sDestroyToolbar = lcl_getToolBarResource(m_eCurrentType);
    1712             : 
    1713           0 :             xLayoutManager->lock();
    1714           0 :             xLayoutManager->destroyElement( sDestroyToolbar );
    1715           0 :             if ( !sToolbar.isEmpty() )
    1716             :             {
    1717           0 :                 xLayoutManager->createElement( sToolbar );
    1718           0 :                 xLayoutManager->requestElement( sToolbar );
    1719             :             }
    1720           0 :             xLayoutManager->unlock();
    1721           0 :             xLayoutManager->doLayout();
    1722             :         }
    1723             : 
    1724           0 :         if ( _eType != E_TABLE && getContainer()->getDetailView() )
    1725             :         {
    1726           0 :             Reference< XNameAccess > xContainer = getElements(_eType);
    1727           0 :             addContainerListener(xContainer);
    1728           0 :             getContainer()->getDetailView()->createPage(_eType,xContainer);
    1729             :         }
    1730             : 
    1731           0 :         SelectionByElementType::iterator pendingSelection = m_aPendingSelection.find( _eType );
    1732           0 :         if ( pendingSelection != m_aPendingSelection.end() )
    1733             :         {
    1734           0 :             Sequence< OUString > aSelected( pendingSelection->second.size() );
    1735           0 :             ::std::copy( pendingSelection->second.begin(), pendingSelection->second.end(), aSelected.getArray() );
    1736           0 :             getContainer()->selectElements( aSelected );
    1737             : 
    1738           0 :             m_aPendingSelection.erase( pendingSelection );
    1739             :         }
    1740             : 
    1741           0 :         InvalidateAll();
    1742             :     }
    1743           0 :     m_eCurrentType = _eType;
    1744             : 
    1745           0 :     return sal_True;
    1746             : }
    1747             : 
    1748           0 : bool OApplicationController::onEntryDoubleClick( SvTreeListBox& _rTree )
    1749             : {
    1750           0 :     if ( getContainer() && getContainer()->isLeaf( _rTree.GetHdlEntry() ) )
    1751             :     {
    1752             :         try
    1753             :         {
    1754             :             openElement(
    1755             :                 getContainer()->getQualifiedName( _rTree.GetHdlEntry() ),
    1756             :                 getContainer()->getElementType(),
    1757             :                 E_OPEN_NORMAL
    1758           0 :             );
    1759           0 :             return true;    // handled
    1760             :         }
    1761           0 :         catch(const Exception&)
    1762             :         {
    1763             :             DBG_UNHANDLED_EXCEPTION();
    1764             :         }
    1765             :     }
    1766           0 :     return false;   // not handled
    1767             : }
    1768             : 
    1769           0 : bool OApplicationController::impl_isAlterableView_nothrow( const OUString& _rTableOrViewName ) const
    1770             : {
    1771             :     OSL_PRECOND( m_xDataSourceConnection.is(), "OApplicationController::impl_isAlterableView_nothrow: no connection!" );
    1772             : 
    1773           0 :     bool bIsAlterableView( false );
    1774             :     try
    1775             :     {
    1776           0 :         Reference< XViewsSupplier > xViewsSupp( m_xDataSourceConnection, UNO_QUERY );
    1777           0 :         Reference< XNameAccess > xViews;
    1778           0 :         if ( xViewsSupp.is() )
    1779           0 :             xViews = xViewsSupp->getViews();
    1780             : 
    1781           0 :         Reference< XAlterView > xAsAlterableView;
    1782           0 :         if ( xViews.is() && xViews->hasByName( _rTableOrViewName ) )
    1783           0 :             xAsAlterableView.set( xViews->getByName( _rTableOrViewName ), UNO_QUERY );
    1784             : 
    1785           0 :         bIsAlterableView = xAsAlterableView.is();
    1786             :     }
    1787           0 :     catch( const Exception& )
    1788             :     {
    1789             :         DBG_UNHANDLED_EXCEPTION();
    1790             :     }
    1791           0 :     return bIsAlterableView;
    1792             : }
    1793             : 
    1794           0 : Reference< XComponent > OApplicationController::openElement(const OUString& _sName, ElementType _eType,
    1795             :     ElementOpenMode _eOpenMode, sal_uInt16 _nInstigatorCommand )
    1796             : {
    1797           0 :     return openElementWithArguments( _sName, _eType, _eOpenMode, _nInstigatorCommand, ::comphelper::NamedValueCollection() );
    1798             : }
    1799             : 
    1800           0 : Reference< XComponent > OApplicationController::openElementWithArguments( const OUString& _sName, ElementType _eType,
    1801             :     ElementOpenMode _eOpenMode, sal_uInt16 _nInstigatorCommand, const ::comphelper::NamedValueCollection& _rAdditionalArguments )
    1802             : {
    1803             :     OSL_PRECOND( getContainer(), "OApplicationController::openElementWithArguments: no view!" );
    1804           0 :     if ( !getContainer() )
    1805           0 :         return NULL;
    1806             : 
    1807           0 :     Reference< XComponent > xRet;
    1808           0 :     if ( _eOpenMode == E_OPEN_DESIGN )
    1809             :     {
    1810             :         // OJ: http://www.openoffice.org/issues/show_bug.cgi?id=30382
    1811           0 :         getContainer()->showPreview(NULL);
    1812             :     }
    1813             : 
    1814           0 :     bool isStandaloneDocument = false;
    1815           0 :     switch ( _eType )
    1816             :     {
    1817             :     case E_REPORT:
    1818           0 :         if ( _eOpenMode != E_OPEN_DESIGN )
    1819             :         {
    1820             :             // reports which are opened in a mode other than design are no sub components of our application
    1821             :             // component, but standalone documents.
    1822           0 :             isStandaloneDocument = true;
    1823             :         }
    1824             :         // NO break!
    1825             :     case E_FORM:
    1826             :     {
    1827           0 :         if ( isStandaloneDocument || !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode, xRet ) )
    1828             :         {
    1829             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
    1830           0 :             ::std::auto_ptr< OLinkedDocumentsAccess > aHelper = getDocumentsAccess( _eType );
    1831             :             SAL_WNODEPRECATED_DECLARATIONS_POP
    1832           0 :             if ( !aHelper->isConnected() )
    1833           0 :                 break;
    1834             : 
    1835           0 :             Reference< XComponent > xDefinition;
    1836           0 :             xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments );
    1837             : 
    1838           0 :             if ( !isStandaloneDocument )
    1839           0 :                 onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition );
    1840             :         }
    1841             :     }
    1842           0 :     break;
    1843             : 
    1844             :     case E_QUERY:
    1845             :     case E_TABLE:
    1846             :     {
    1847           0 :         if ( !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode, xRet ) )
    1848             :         {
    1849           0 :             SharedConnection xConnection( ensureConnection() );
    1850           0 :             if ( !xConnection.is() )
    1851           0 :                 break;
    1852             : 
    1853             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
    1854           0 :             ::std::auto_ptr< DatabaseObjectView > pDesigner;
    1855             :             SAL_WNODEPRECATED_DECLARATIONS_POP
    1856           0 :             ::comphelper::NamedValueCollection aArguments( _rAdditionalArguments );
    1857             : 
    1858           0 :             Any aDataSource;
    1859           0 :             if ( _eOpenMode == E_OPEN_DESIGN )
    1860             :             {
    1861           0 :                 bool bAddViewTypeArg = false;
    1862             : 
    1863           0 :                 if ( _eType == E_TABLE )
    1864             :                 {
    1865           0 :                     if ( impl_isAlterableView_nothrow( _sName ) )
    1866             :                     {
    1867           0 :                         pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), true ) );
    1868           0 :                         bAddViewTypeArg = true;
    1869             :                     }
    1870             :                     else
    1871             :                     {
    1872           0 :                         pDesigner.reset( new TableDesigner( getORB(), this, m_aCurrentFrame.getFrame() ) );
    1873             :                     }
    1874             :                 }
    1875           0 :                 else if ( _eType == E_QUERY )
    1876             :                 {
    1877           0 :                     pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), false ) );
    1878           0 :                     bAddViewTypeArg = true;
    1879             :                 }
    1880           0 :                 aDataSource <<= m_xDataSource;
    1881             : 
    1882           0 :                 if ( bAddViewTypeArg )
    1883             :                 {
    1884           0 :                     const bool bQueryGraphicalMode =( _nInstigatorCommand != SID_DB_APP_EDIT_SQL_VIEW );
    1885           0 :                     aArguments.put( (OUString)PROPERTY_GRAPHICAL_DESIGN, bQueryGraphicalMode );
    1886             :                 }
    1887             : 
    1888             :             }
    1889             :             else
    1890             :             {
    1891           0 :                 pDesigner.reset( new ResultSetBrowser( getORB(), this, m_aCurrentFrame.getFrame(), _eType == E_TABLE ) );
    1892             : 
    1893           0 :                 if ( !aArguments.has( (OUString)PROPERTY_SHOWMENU ) )
    1894           0 :                     aArguments.put( (OUString)PROPERTY_SHOWMENU, makeAny( (sal_Bool)sal_True ) );
    1895             : 
    1896           0 :                 aDataSource <<= getDatabaseName();
    1897             :             }
    1898             : 
    1899           0 :             xRet.set( pDesigner->openExisting( aDataSource, _sName, aArguments ) );
    1900           0 :             onDocumentOpened( _sName, _eType, _eOpenMode, xRet, NULL );
    1901             :         }
    1902             :     }
    1903           0 :     break;
    1904             : 
    1905             :     default:
    1906             :         OSL_FAIL( "OApplicationController::openElement: illegal object type!" );
    1907           0 :         break;
    1908             :     }
    1909           0 :     return xRet;
    1910             : }
    1911             : 
    1912           0 : IMPL_LINK( OApplicationController, OnSelectContainer, void*, _pType )
    1913             : {
    1914           0 :     ElementType eType = (ElementType)reinterpret_cast< sal_IntPtr >( _pType );
    1915           0 :     if (getContainer())
    1916           0 :         getContainer()->selectContainer(eType);
    1917           0 :     return 0L;
    1918             : }
    1919             : 
    1920           0 : IMPL_LINK( OApplicationController, OnCreateWithPilot, void*, _pType )
    1921             : {
    1922           0 :     ElementType eType = (ElementType)reinterpret_cast< sal_IntPtr >( _pType );
    1923           0 :     newElementWithPilot( eType );
    1924           0 :     return 0L;
    1925             : }
    1926             : 
    1927           0 : void OApplicationController::newElementWithPilot( ElementType _eType )
    1928             : {
    1929           0 :     utl::CloseVeto aKeepDoc( getFrame() );
    1930             :         // prevent the document being closed while the wizard is open
    1931             : 
    1932             :     OSL_ENSURE( getContainer(), "OApplicationController::newElementWithPilot: without a view?" );
    1933             : 
    1934           0 :     switch ( _eType )
    1935             :     {
    1936             :         case E_REPORT:
    1937             :         case E_FORM:
    1938             :         {
    1939             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
    1940           0 :             ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType);
    1941             :             SAL_WNODEPRECATED_DECLARATIONS_POP
    1942           0 :             if ( aHelper->isConnected() )
    1943             :             {
    1944           0 :                 sal_Int32 nCommandType = -1;
    1945           0 :                 const OUString sCurrentSelected( getCurrentlySelectedName( nCommandType ) );
    1946           0 :                 if ( E_REPORT == _eType )
    1947           0 :                     aHelper->newReportWithPilot( nCommandType, sCurrentSelected );
    1948             :                 else
    1949           0 :                     aHelper->newFormWithPilot( nCommandType, sCurrentSelected );
    1950           0 :             }
    1951             :         }
    1952           0 :         break;
    1953             :         case E_QUERY:
    1954             :         case E_TABLE:
    1955             :          {
    1956             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
    1957           0 :             ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType);
    1958             :             SAL_WNODEPRECATED_DECLARATIONS_POP
    1959           0 :             if ( aHelper->isConnected() )
    1960             :             {
    1961           0 :                 if ( E_QUERY == _eType )
    1962           0 :                     aHelper->newQueryWithPilot();
    1963             :                 else
    1964           0 :                     aHelper->newTableWithPilot();
    1965           0 :             }
    1966             :          }
    1967           0 :          break;
    1968             :         case E_NONE:
    1969           0 :             break;
    1970           0 :     }
    1971             : 
    1972             :     // no need for onDocumentOpened, the table wizard opens the created table by using
    1973             :     // XDatabaseDocumentUI::loadComponent method.
    1974           0 : }
    1975             : 
    1976           0 : Reference< XComponent > OApplicationController::newElement( ElementType _eType, const ::comphelper::NamedValueCollection& i_rAdditionalArguments,
    1977             :                                                            Reference< XComponent >& o_rDocumentDefinition )
    1978             : {
    1979             :     OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
    1980             : 
    1981           0 :     Reference< XComponent > xComponent;
    1982           0 :     o_rDocumentDefinition.clear();
    1983             : 
    1984           0 :     switch ( _eType )
    1985             :     {
    1986             :         case E_FORM:
    1987             :         case E_REPORT:
    1988             :         {
    1989             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
    1990           0 :             ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess( _eType );
    1991             :             SAL_WNODEPRECATED_DECLARATIONS_POP
    1992           0 :             if ( !aHelper->isConnected() )
    1993           0 :                 break;
    1994             : 
    1995           0 :             xComponent = aHelper->newDocument( _eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT, i_rAdditionalArguments, o_rDocumentDefinition );
    1996             :         }
    1997           0 :         break;
    1998             : 
    1999             :         case E_QUERY:
    2000             :         case E_TABLE:
    2001             :         {
    2002             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
    2003           0 :             ::std::auto_ptr< DatabaseObjectView > pDesigner;
    2004             :             SAL_WNODEPRECATED_DECLARATIONS_POP
    2005           0 :             SharedConnection xConnection( ensureConnection() );
    2006           0 :             if ( !xConnection.is() )
    2007           0 :                 break;
    2008             : 
    2009           0 :             if ( _eType == E_TABLE )
    2010             :             {
    2011           0 :                 pDesigner.reset( new TableDesigner( getORB(), this, getFrame() ) );
    2012             :             }
    2013           0 :             else if ( _eType == E_QUERY )
    2014             :             {
    2015           0 :                 pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false ) );
    2016             :             }
    2017             : 
    2018           0 :             Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
    2019           0 :             xComponent.set( pDesigner->createNew( xDataSource, i_rAdditionalArguments ), UNO_QUERY );
    2020             :         }
    2021           0 :         break;
    2022             : 
    2023             :         default:
    2024             :             OSL_FAIL( "OApplicationController::newElement: illegal type!" );
    2025           0 :             break;
    2026             :     }
    2027             : 
    2028           0 :     if ( xComponent.is() )
    2029           0 :         onDocumentOpened( OUString(), _eType, E_OPEN_DESIGN, xComponent, o_rDocumentDefinition );
    2030             : 
    2031           0 :     return xComponent;
    2032             : }
    2033             : 
    2034           0 : void OApplicationController::addContainerListener(const Reference<XNameAccess>& _xCollection)
    2035             : {
    2036             :     try
    2037             :     {
    2038           0 :         Reference< XContainer > xCont(_xCollection, UNO_QUERY);
    2039           0 :         if ( xCont.is() )
    2040             :         {
    2041             :             // add as listener to get notified if elements are inserted or removed
    2042           0 :             TContainerVector::iterator aFind = ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xCont);
    2043           0 :             if ( aFind == m_aCurrentContainers.end() )
    2044             :             {
    2045           0 :                 xCont->addContainerListener(this);
    2046           0 :                 m_aCurrentContainers.push_back(xCont);
    2047             :             }
    2048           0 :         }
    2049             :     }
    2050           0 :     catch( const Exception& )
    2051             :     {
    2052             :         DBG_UNHANDLED_EXCEPTION();
    2053             :     }
    2054           0 : }
    2055             : 
    2056           0 : void OApplicationController::renameEntry()
    2057             : {
    2058           0 :     SolarMutexGuard aSolarGuard;
    2059           0 :     ::osl::MutexGuard aGuard( getMutex() );
    2060             : 
    2061             :     OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
    2062           0 :     ::std::vector< OUString> aList;
    2063           0 :     getSelectionElementNames(aList);
    2064             : 
    2065           0 :     Reference< XNameAccess > xContainer = getElements(getContainer()->getElementType());
    2066             :     OSL_ENSURE(aList.size() == 1,"Invalid rename call here. More than one element!");
    2067           0 :     if ( aList.empty() )
    2068           0 :         return;
    2069             : 
    2070             :     try
    2071             :     {
    2072           0 :         if ( xContainer.is() )
    2073             :         {
    2074             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
    2075           0 :             ::std::auto_ptr< IObjectNameCheck > pNameChecker;
    2076           0 :             ::std::auto_ptr< OSaveAsDlg > aDialog;
    2077             :             SAL_WNODEPRECATED_DECLARATIONS_POP
    2078             : 
    2079           0 :             Reference<XRename> xRename;
    2080           0 :             const ElementType eType = getContainer()->getElementType();
    2081           0 :             switch( eType )
    2082             :             {
    2083             :                 case E_FORM:
    2084             :                 case E_REPORT:
    2085             :                     {
    2086           0 :                         Reference<XHierarchicalNameContainer> xHNames(xContainer, UNO_QUERY);
    2087           0 :                         if ( xHNames.is() )
    2088             :                         {
    2089           0 :                             OUString sLabel;
    2090           0 :                             if ( eType == E_FORM )
    2091           0 :                                 sLabel = OUString(ModuleRes( STR_FRM_LABEL ));
    2092             :                             else
    2093           0 :                                 sLabel = OUString(ModuleRes( STR_RPT_LABEL ));
    2094             : 
    2095           0 :                             OUString sName = *aList.begin();
    2096           0 :                             if ( xHNames->hasByHierarchicalName(sName) )
    2097             :                             {
    2098           0 :                                 xRename.set(xHNames->getByHierarchicalName(sName),UNO_QUERY);
    2099           0 :                                 Reference<XChild> xChild(xRename,UNO_QUERY);
    2100           0 :                                 if ( xChild.is() )
    2101             :                                 {
    2102           0 :                                     Reference<XHierarchicalNameContainer> xParent(xChild->getParent(),UNO_QUERY);
    2103           0 :                                     if ( xParent.is() )
    2104             :                                     {
    2105           0 :                                         xHNames = xParent;
    2106           0 :                                         Reference<XPropertySet>(xRename,UNO_QUERY)->getPropertyValue(PROPERTY_NAME) >>= sName;
    2107           0 :                                     }
    2108             :                                 }
    2109           0 :                                 pNameChecker.reset( new HierarchicalNameCheck( xHNames.get(), OUString() ) );
    2110             :                                 aDialog.reset( new OSaveAsDlg(
    2111           0 :                                     getView(), getORB(), sName, sLabel, *pNameChecker, SAD_TITLE_RENAME ) );
    2112           0 :                             }
    2113           0 :                         }
    2114             :                     }
    2115           0 :                     break;
    2116             :                 case E_TABLE:
    2117           0 :                     ensureConnection();
    2118           0 :                     if ( !getConnection().is() )
    2119           0 :                         break;
    2120             :                     // NO break
    2121             :                 case E_QUERY:
    2122           0 :                     if ( xContainer->hasByName(*aList.begin()) )
    2123             :                     {
    2124           0 :                         xRename.set(xContainer->getByName(*aList.begin()),UNO_QUERY);
    2125           0 :                         sal_Int32 nCommandType = eType == E_QUERY ? CommandType::QUERY : CommandType::TABLE;
    2126             : 
    2127           0 :                         ensureConnection();
    2128           0 :                         pNameChecker.reset( new DynamicTableOrQueryNameCheck( getConnection(), nCommandType ) );
    2129             :                         aDialog.reset( new OSaveAsDlg(
    2130           0 :                             getView(), nCommandType, getORB(), getConnection(),
    2131           0 :                                 *aList.begin(), *pNameChecker, SAD_TITLE_RENAME ) );
    2132             :                     }
    2133           0 :                     break;
    2134             :                 default:
    2135           0 :                     break;
    2136             :             }
    2137             : 
    2138           0 :             if ( xRename.is() && aDialog.get() )
    2139             :             {
    2140             : 
    2141           0 :                 sal_Bool bTryAgain = sal_True;
    2142           0 :                 while( bTryAgain )
    2143             :                 {
    2144           0 :                     if ( aDialog->Execute() == RET_OK )
    2145             :                     {
    2146             :                         try
    2147             :                         {
    2148           0 :                             OUString sNewName;
    2149           0 :                             if ( eType == E_TABLE )
    2150             :                             {
    2151           0 :                                 OUString sName = aDialog->getName();
    2152           0 :                                 OUString sCatalog = aDialog->getCatalog();
    2153           0 :                                 OUString sSchema  = aDialog->getSchema();
    2154             : 
    2155           0 :                                 sNewName = ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sName, false, ::dbtools::eInDataManipulation );
    2156             :                             }
    2157             :                             else
    2158           0 :                                 sNewName = aDialog->getName();
    2159             : 
    2160           0 :                             OUString sOldName = *aList.begin();
    2161           0 :                             if ( eType == E_FORM || eType == E_REPORT )
    2162             :                             {
    2163           0 :                                 Reference<XContent> xContent(xRename,UNO_QUERY);
    2164           0 :                                 if ( xContent.is() )
    2165             :                                 {
    2166           0 :                                     sOldName = xContent->getIdentifier()->getContentIdentifier();
    2167           0 :                                 }
    2168             :                             }
    2169             : 
    2170           0 :                             xRename->rename(sNewName);
    2171             : 
    2172           0 :                             if ( eType == E_TABLE )
    2173             :                             {
    2174           0 :                                 Reference<XPropertySet> xProp(xRename,UNO_QUERY);
    2175           0 :                                 sNewName = ::dbaui::composeTableName( m_xMetaData, xProp, ::dbtools::eInDataManipulation, false, false, false );
    2176             :                             }
    2177           0 :                             getContainer()->elementReplaced( eType , sOldName, sNewName );
    2178             : 
    2179           0 :                             bTryAgain = sal_False;
    2180             :                         }
    2181           0 :                         catch(const SQLException& )
    2182             :                         {
    2183           0 :                             showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
    2184             : 
    2185             :                         }
    2186           0 :                         catch(const ElementExistException& e)
    2187             :                         {
    2188           0 :                             OUString sStatus("S1000");
    2189           0 :                             OUString sMsg = OUString( ModuleRes( STR_NAME_ALREADY_EXISTS ) );
    2190           0 :                             showError(SQLExceptionInfo(SQLException(sMsg.replaceAll(OUString('#'), e.Message), e.Context, sStatus, 0, Any())));
    2191             :                         }
    2192           0 :                         catch(const Exception& )
    2193             :                         {
    2194             :                             DBG_UNHANDLED_EXCEPTION();
    2195             :                         }
    2196             :                     }
    2197             :                     else
    2198           0 :                         bTryAgain = sal_False;
    2199             :                 }
    2200           0 :             }
    2201             :         }
    2202             :     }
    2203           0 :     catch(const Exception& )
    2204             :     {
    2205             :         DBG_UNHANDLED_EXCEPTION();
    2206           0 :     }
    2207             : }
    2208             : 
    2209           0 : void OApplicationController::onSelectionChanged()
    2210             : {
    2211           0 :     InvalidateAll();
    2212             : 
    2213           0 :     SelectionGuard aSelGuard( *m_pSelectionNotifier );
    2214             : 
    2215           0 :     OApplicationView* pView = getContainer();
    2216           0 :     if ( !pView )
    2217           0 :         return;
    2218             : 
    2219           0 :     if ( pView->getSelectionCount() == 1 )
    2220             :     {
    2221           0 :         const ElementType eType = pView->getElementType();
    2222           0 :           if ( pView->isALeafSelected() )
    2223             :         {
    2224           0 :             const OUString sName = pView->getQualifiedName( NULL /* means 'first selected' */ );
    2225           0 :             showPreviewFor( eType, sName );
    2226             :         }
    2227           0 :     }
    2228             : }
    2229             : 
    2230           0 : void OApplicationController::showPreviewFor(const ElementType _eType,const OUString& _sName)
    2231             : {
    2232           0 :     if ( m_ePreviewMode == E_PREVIEWNONE )
    2233           0 :         return;
    2234             : 
    2235           0 :     OApplicationView* pView = getContainer();
    2236           0 :     if ( !pView )
    2237           0 :         return;
    2238             : 
    2239             :     try
    2240             :     {
    2241           0 :         switch( _eType )
    2242             :         {
    2243             :             case E_FORM:
    2244             :             case E_REPORT:
    2245             :             {
    2246           0 :                 Reference< XHierarchicalNameAccess > xContainer( getElements( _eType ), UNO_QUERY_THROW );
    2247           0 :                 Reference< XContent> xContent( xContainer->getByHierarchicalName( _sName ), UNO_QUERY_THROW );
    2248           0 :                 pView->showPreview( xContent );
    2249             :             }
    2250           0 :             break;
    2251             : 
    2252             :             case E_TABLE:
    2253             :             case E_QUERY:
    2254             :                 {
    2255           0 :                     SharedConnection xConnection( ensureConnection() );
    2256           0 :                     if ( xConnection.is() )
    2257           0 :                         pView->showPreview( getDatabaseName(), xConnection, _sName, _eType == E_TABLE );
    2258             :                 }
    2259           0 :                 return;
    2260             : 
    2261             :             default:
    2262             :                 OSL_FAIL( "OApplicationController::showPreviewFor: unexpected element type!" );
    2263           0 :                 break;
    2264             :         }
    2265             :     }
    2266           0 :     catch( const SQLException& )
    2267             :     {
    2268           0 :         showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
    2269             :     }
    2270           0 :     catch(const Exception& )
    2271             :     {
    2272             :         DBG_UNHANDLED_EXCEPTION();
    2273             :     }
    2274             : }
    2275             : 
    2276           0 : IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged)
    2277             : {
    2278           0 :     OnInvalidateClipboard();
    2279           0 :     return 0L;
    2280             : }
    2281             : 
    2282           0 : void OApplicationController::OnInvalidateClipboard()
    2283             : {
    2284           0 :     InvalidateFeature(ID_BROWSER_CUT);
    2285           0 :     InvalidateFeature(ID_BROWSER_COPY);
    2286           0 :     InvalidateFeature(ID_BROWSER_PASTE);
    2287           0 :     InvalidateFeature(SID_DB_APP_PASTE_SPECIAL);
    2288           0 : }
    2289             : 
    2290           0 : void OApplicationController::onCutEntry()
    2291             : {
    2292           0 : }
    2293             : 
    2294           0 : void OApplicationController::onCopyEntry()
    2295             : {
    2296           0 :     Execute(ID_BROWSER_COPY,Sequence<PropertyValue>());
    2297           0 : }
    2298             : 
    2299           0 : void OApplicationController::onPasteEntry()
    2300             : {
    2301           0 :     Execute(ID_BROWSER_PASTE,Sequence<PropertyValue>());
    2302           0 : }
    2303             : 
    2304           0 : void OApplicationController::onDeleteEntry()
    2305             : {
    2306           0 :     ElementType eType = getContainer()->getElementType();
    2307           0 :     sal_uInt16 nId = 0;
    2308           0 :     switch(eType)
    2309             :     {
    2310             :         case E_TABLE:
    2311           0 :             nId = SID_DB_APP_TABLE_DELETE;
    2312           0 :             break;
    2313             :         case E_QUERY:
    2314           0 :             nId = SID_DB_APP_QUERY_DELETE;
    2315           0 :             break;
    2316             :         case E_FORM:
    2317           0 :             nId = SID_DB_APP_FORM_DELETE;
    2318           0 :             break;
    2319             :         case E_REPORT:
    2320           0 :             nId = SID_DB_APP_REPORT_DELETE;
    2321           0 :             break;
    2322             :         default:
    2323             :             OSL_FAIL("Invalid ElementType!");
    2324           0 :             break;
    2325             :     }
    2326           0 :     executeChecked(nId,Sequence<PropertyValue>());
    2327           0 : }
    2328             : 
    2329           0 : void OApplicationController::executeUnChecked(const URL& _rCommand, const Sequence< PropertyValue>& aArgs)
    2330             : {
    2331           0 :     OApplicationController_CBASE::executeUnChecked( _rCommand, aArgs );
    2332           0 : }
    2333             : 
    2334           0 : void OApplicationController::executeChecked(const URL& _rCommand, const Sequence< PropertyValue>& aArgs)
    2335             : {
    2336           0 :     OApplicationController_CBASE::executeChecked( _rCommand, aArgs );
    2337           0 : }
    2338             : 
    2339           0 : void OApplicationController::executeUnChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue>& aArgs)
    2340             : {
    2341           0 :     OApplicationController_CBASE::executeUnChecked( _nCommandId, aArgs );
    2342           0 : }
    2343             : 
    2344           0 : void OApplicationController::executeChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue>& aArgs)
    2345             : {
    2346           0 :     OApplicationController_CBASE::executeChecked( _nCommandId, aArgs );
    2347           0 : }
    2348             : 
    2349           0 : bool OApplicationController::isCommandEnabled(sal_uInt16 _nCommandId) const
    2350             : {
    2351           0 :     return OApplicationController_CBASE::isCommandEnabled( _nCommandId );
    2352             : }
    2353             : 
    2354           0 : bool OApplicationController::isCommandEnabled( const OUString& _rCompleteCommandURL ) const
    2355             : {
    2356           0 :     return OApplicationController_CBASE::isCommandEnabled( _rCompleteCommandURL );
    2357             : }
    2358             : 
    2359           0 : sal_uInt16 OApplicationController::registerCommandURL( const OUString& _rCompleteCommandURL )
    2360             : {
    2361           0 :     return OApplicationController_CBASE::registerCommandURL( _rCompleteCommandURL );
    2362             : }
    2363             : 
    2364           0 : void OApplicationController::notifyHiContrastChanged()
    2365             : {
    2366           0 :     OApplicationController_CBASE::notifyHiContrastChanged();
    2367           0 : }
    2368             : 
    2369           0 : Reference< XController > OApplicationController::getXController() throw( RuntimeException )
    2370             : {
    2371           0 :     return OApplicationController_CBASE::getXController();
    2372             : }
    2373             : 
    2374           0 : bool OApplicationController::interceptUserInput( const NotifyEvent& _rEvent )
    2375             : {
    2376           0 :     return OApplicationController_CBASE::interceptUserInput( _rEvent );
    2377             : }
    2378             : 
    2379           0 : PopupMenu* OApplicationController::getContextMenu( Control& /*_rControl*/ ) const
    2380             : {
    2381           0 :     return new PopupMenu( ModuleRes( RID_MENU_APP_EDIT ) );
    2382             : }
    2383             : 
    2384           0 : IController& OApplicationController::getCommandController()
    2385             : {
    2386           0 :     return *static_cast< IApplicationController* >( this );
    2387             : }
    2388             : 
    2389           0 : ::cppu::OInterfaceContainerHelper* OApplicationController::getContextMenuInterceptors()
    2390             : {
    2391           0 :     return &m_aContextMenuInterceptors;
    2392             : }
    2393             : 
    2394           0 : Any OApplicationController::getCurrentSelection( Control& _rControl ) const
    2395             : {
    2396           0 :     Sequence< NamedDatabaseObject > aSelection;
    2397           0 :     getContainer()->describeCurrentSelectionForControl( _rControl, aSelection );
    2398           0 :     return makeAny( aSelection );
    2399             : }
    2400             : 
    2401           0 : sal_Bool OApplicationController::requestQuickHelp( const SvTreeListEntry* /*_pEntry*/, OUString& /*_rText*/ ) const
    2402             : {
    2403           0 :     return sal_False;
    2404             : }
    2405             : 
    2406           0 : sal_Bool OApplicationController::requestDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
    2407             : {
    2408           0 :     TransferableHelper* pTransfer = NULL;
    2409           0 :     if ( getContainer() && getContainer()->getSelectionCount() )
    2410             :     {
    2411             :         try
    2412             :         {
    2413           0 :             pTransfer = copyObject( );
    2414           0 :             Reference< XTransferable> xEnsureDelete = pTransfer;
    2415             : 
    2416           0 :             if ( pTransfer && getContainer()->getDetailView() )
    2417             :             {
    2418           0 :                 ElementType eType = getContainer()->getElementType();
    2419           0 :                 pTransfer->StartDrag( getContainer()->getDetailView()->getTreeWindow(), ((eType == E_FORM || eType == E_REPORT) ? DND_ACTION_COPYMOVE : DND_ACTION_COPY) );
    2420           0 :             }
    2421             :         }
    2422           0 :         catch(const Exception& )
    2423             :         {
    2424             :             DBG_UNHANDLED_EXCEPTION();
    2425             :         }
    2426             :     }
    2427             : 
    2428           0 :     return NULL != pTransfer;
    2429             : }
    2430             : 
    2431           0 : sal_Int8 OApplicationController::queryDrop( const AcceptDropEvent& _rEvt, const DataFlavorExVector& _rFlavors )
    2432             : {
    2433           0 :     sal_Int8 nActionAskedFor = _rEvt.mnAction;
    2434             :     // check if we're a table or query container
    2435           0 :     OApplicationView* pView = getContainer();
    2436           0 :     if ( pView && !isDataSourceReadOnly() )
    2437             :     {
    2438           0 :         ElementType eType = pView->getElementType();
    2439           0 :         if ( eType != E_NONE && (eType != E_TABLE || !isConnectionReadOnly()) )
    2440             :         {
    2441             :             // check for the concrete type
    2442           0 :             if(::std::find_if(_rFlavors.begin(),_rFlavors.end(),TAppSupportedSotFunctor(eType,sal_True)) != _rFlavors.end())
    2443           0 :                 return DND_ACTION_COPY;
    2444           0 :             if ( eType == E_FORM || eType == E_REPORT )
    2445             :             {
    2446           0 :                 sal_Int8 nAction = OComponentTransferable::canExtractComponentDescriptor(_rFlavors,eType == E_FORM) ? DND_ACTION_COPY : DND_ACTION_NONE;
    2447           0 :                 if ( nAction != DND_ACTION_NONE )
    2448             :                 {
    2449           0 :                     SvTreeListEntry* pHitEntry = pView->getEntry(_rEvt.maPosPixel);
    2450           0 :                     OUString sName;
    2451           0 :                     if ( pHitEntry )
    2452             :                     {
    2453           0 :                         sName = pView->getQualifiedName( pHitEntry );
    2454           0 :                         if ( !sName.isEmpty() )
    2455             :                         {
    2456           0 :                             Reference< XHierarchicalNameAccess > xContainer(getElements(pView->getElementType()),UNO_QUERY);
    2457           0 :                             if ( xContainer.is() && xContainer->hasByHierarchicalName(sName) )
    2458             :                             {
    2459           0 :                                 Reference< XHierarchicalNameAccess > xHitObject(xContainer->getByHierarchicalName(sName),UNO_QUERY);
    2460           0 :                                 if ( xHitObject.is() )
    2461           0 :                                     nAction = nActionAskedFor & DND_ACTION_COPYMOVE;
    2462             :                             }
    2463             :                             else
    2464           0 :                                 nAction = DND_ACTION_NONE;
    2465             :                         }
    2466           0 :                     }
    2467             :                 }
    2468           0 :                 return nAction;
    2469             :             }
    2470             :         }
    2471             :     }
    2472             : 
    2473           0 :     return DND_ACTION_NONE;
    2474             : }
    2475             : 
    2476           0 : sal_Int8 OApplicationController::executeDrop( const ExecuteDropEvent& _rEvt )
    2477             : {
    2478           0 :     OApplicationView* pView = getContainer();
    2479           0 :     if ( !pView || pView->getElementType() == E_NONE )
    2480             :     {
    2481             :         OSL_FAIL("OApplicationController::executeDrop: what the hell did queryDrop do?");
    2482             :             // queryDrop shoud not have allowed us to reach this situation ....
    2483           0 :         return DND_ACTION_NONE;
    2484             :     }
    2485             : 
    2486             :     // a TransferableDataHelper for accessing the dropped data
    2487           0 :     TransferableDataHelper aDroppedData(_rEvt.maDropEvent.Transferable);
    2488             : 
    2489             :     // reset the data of the previous async drop (if any)
    2490           0 :     if ( m_nAsyncDrop )
    2491           0 :         Application::RemoveUserEvent(m_nAsyncDrop);
    2492             : 
    2493           0 :     m_nAsyncDrop = 0;
    2494           0 :     m_aAsyncDrop.aDroppedData.clear();
    2495           0 :     m_aAsyncDrop.nType          = pView->getElementType();
    2496           0 :     m_aAsyncDrop.nAction        = _rEvt.mnAction;
    2497           0 :     m_aAsyncDrop.bError         = sal_False;
    2498           0 :     m_aAsyncDrop.bHtml          = sal_False;
    2499           0 :     m_aAsyncDrop.aUrl           = "";
    2500             : 
    2501             :     // loop through the available formats and see what we can do ...
    2502             :     // first we have to check if it is our own format, if not we have to copy the stream :-(
    2503           0 :     if ( ODataAccessObjectTransferable::canExtractObjectDescriptor(aDroppedData.GetDataFlavorExVector()) )
    2504             :     {
    2505           0 :         m_aAsyncDrop.aDroppedData   = ODataAccessObjectTransferable::extractObjectDescriptor(aDroppedData);
    2506             : 
    2507             :         // asyncron because we some dialogs and we aren't allowed to show them while in D&D
    2508           0 :         m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
    2509           0 :         return DND_ACTION_COPY;
    2510             :     }
    2511           0 :     else if ( OComponentTransferable::canExtractComponentDescriptor(aDroppedData.GetDataFlavorExVector(),m_aAsyncDrop.nType == E_FORM) )
    2512             :     {
    2513           0 :         m_aAsyncDrop.aDroppedData = OComponentTransferable::extractComponentDescriptor(aDroppedData);
    2514           0 :         SvTreeListEntry* pHitEntry = pView->getEntry(_rEvt.maPosPixel);
    2515           0 :         if ( pHitEntry )
    2516           0 :             m_aAsyncDrop.aUrl = pView->getQualifiedName( pHitEntry );
    2517             : 
    2518           0 :         sal_Int8 nAction = _rEvt.mnAction;
    2519           0 :         Reference<XContent> xContent;
    2520           0 :         m_aAsyncDrop.aDroppedData[daComponent] >>= xContent;
    2521           0 :         if ( xContent.is() )
    2522             :         {
    2523           0 :             OUString sName = xContent->getIdentifier()->getContentIdentifier();
    2524           0 :             sal_Int32 nIndex = 0;
    2525           0 :             sName = sName.copy(sName.getToken(0,'/',nIndex).getLength() + 1);
    2526           0 :             if ( m_aAsyncDrop.aUrl.getLength() >= sName.getLength() && m_aAsyncDrop.aUrl.startsWith(sName) )
    2527             :             {
    2528           0 :                 m_aAsyncDrop.aDroppedData.clear();
    2529           0 :                 return DND_ACTION_NONE;
    2530             :             }
    2531             : 
    2532             :             // check if move is allowed, if another object with the same name exists only copy is allowed
    2533           0 :             Reference< XHierarchicalNameAccess > xContainer(getElements(m_aAsyncDrop.nType),UNO_QUERY);
    2534           0 :             Reference<XNameAccess> xNameAccess(xContainer,UNO_QUERY);
    2535             : 
    2536           0 :             if ( !m_aAsyncDrop.aUrl.isEmpty() && xContainer.is() && xContainer->hasByHierarchicalName(m_aAsyncDrop.aUrl) )
    2537           0 :                 xNameAccess.set(xContainer->getByHierarchicalName(m_aAsyncDrop.aUrl),UNO_QUERY);
    2538             : 
    2539           0 :             if ( xNameAccess.is() )
    2540             :             {
    2541           0 :                 Reference<XPropertySet> xProp(xContent,UNO_QUERY);
    2542           0 :                 if ( xProp.is() )
    2543             :                 {
    2544           0 :                     xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
    2545           0 :                     if ( xNameAccess.is() && xNameAccess->hasByName(sName) )
    2546           0 :                         nAction &= ~DND_ACTION_MOVE;
    2547             :                 }
    2548             :                 else
    2549           0 :                     nAction &= ~DND_ACTION_MOVE;
    2550           0 :             }
    2551             :         }
    2552           0 :         if ( nAction != DND_ACTION_NONE )
    2553             :         {
    2554           0 :             m_aAsyncDrop.nAction = nAction;
    2555             :             // asyncron because we some dialogs and we aren't allowed to show them while in D&D
    2556           0 :             m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
    2557             :         }
    2558             :         else
    2559           0 :             m_aAsyncDrop.aDroppedData.clear();
    2560           0 :         return nAction;
    2561             :     }
    2562             :     else
    2563             :     {
    2564           0 :         SharedConnection xConnection( ensureConnection() );
    2565           0 :         if ( xConnection.is() && m_aTableCopyHelper.copyTagTable( aDroppedData, m_aAsyncDrop, xConnection ) )
    2566             :         {
    2567             :             // asyncron because we some dialogs and we aren't allowed to show them while in D&D
    2568           0 :             m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
    2569           0 :             return DND_ACTION_COPY;
    2570           0 :         }
    2571             :     }
    2572             : 
    2573           0 :     return DND_ACTION_NONE;
    2574             : }
    2575             : 
    2576           0 : Reference< XModel >  SAL_CALL OApplicationController::getModel(void) throw( RuntimeException, std::exception )
    2577             : {
    2578           0 :     return m_xModel;
    2579             : }
    2580             : 
    2581           0 : void OApplicationController::onAttachedFrame()
    2582             : {
    2583           0 :     sal_Int32 nConnectedControllers( 0 );
    2584             :     try
    2585             :     {
    2586           0 :         Reference< XModel2 > xModel( m_xModel, UNO_QUERY_THROW );
    2587           0 :         Reference< XEnumeration > xEnumControllers( xModel->getControllers(), UNO_SET_THROW );
    2588           0 :         while ( xEnumControllers->hasMoreElements() )
    2589             :         {
    2590           0 :             Reference< XController > xController( xEnumControllers->nextElement(), UNO_QUERY_THROW );
    2591           0 :             ++nConnectedControllers;
    2592           0 :         }
    2593             :     }
    2594           0 :     catch( const Exception& )
    2595             :     {
    2596             :         DBG_UNHANDLED_EXCEPTION();
    2597             :     }
    2598             : 
    2599           0 :     if ( nConnectedControllers > 1 )
    2600             :     {   // we are not the first connected controller, there were already others
    2601           0 :         return;
    2602             :     }
    2603             : 
    2604           0 :     OnFirstControllerConnected();
    2605             : }
    2606             : 
    2607           0 : void OApplicationController::OnFirstControllerConnected()
    2608             : {
    2609           0 :     if ( !m_xModel.is() )
    2610             :     {
    2611             :         OSL_FAIL( "OApplicationController::OnFirstControllerConnected: too late!" );
    2612             :     }
    2613             : 
    2614             :     // if we have forms or reports which contain macros/scripts, then show a warning
    2615             :     // which suggests the user to migrate them to the database document
    2616           0 :     Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
    2617           0 :     if ( xDocumentScripts.is() )
    2618             :     {
    2619             :         // no need to show this warning, obviously the document supports embedding scripts
    2620             :         // into itself, so there are no "old-style" forms/reports which have macros/scripts
    2621             :         // themselves
    2622           0 :         return;
    2623             :     }
    2624             : 
    2625             :     try
    2626             :     {
    2627             :         // If the migration just happened, but was not successful, the document is reloaded.
    2628             :         // In this case, we should not show the warning, again.
    2629           0 :         ::comphelper::NamedValueCollection aModelArgs( m_xModel->getArgs() );
    2630           0 :         if ( aModelArgs.getOrDefault( "SuppressMigrationWarning", sal_False ) )
    2631           0 :             return;
    2632             : 
    2633             :         // also, if the document is read-only, then no migration is possible, and the
    2634             :         // respective menu entry is hidden. So, don't show the warning in this case, too.
    2635           0 :         if ( Reference< XStorable >( m_xModel, UNO_QUERY_THROW )->isReadonly() )
    2636           0 :             return;
    2637             : 
    2638           0 :         SQLWarning aWarning;
    2639           0 :         aWarning.Message = OUString( ModuleRes( STR_SUB_DOCS_WITH_SCRIPTS ) );
    2640           0 :         SQLException aDetail;
    2641           0 :         aDetail.Message = OUString( ModuleRes( STR_SUB_DOCS_WITH_SCRIPTS_DETAIL ) );
    2642           0 :         aWarning.NextException <<= aDetail;
    2643             : 
    2644           0 :         Reference< XExecutableDialog > xDialog = ErrorMessageDialog::create( getORB(), "", NULL, makeAny( aWarning ) );
    2645           0 :         xDialog->execute();
    2646             :     }
    2647           0 :     catch( const Exception& )
    2648             :     {
    2649             :         DBG_UNHANDLED_EXCEPTION();
    2650             :     }
    2651             : 
    2652           0 :     return;
    2653             : }
    2654             : 
    2655           0 : void SAL_CALL OApplicationController::attachFrame( const Reference< XFrame > & i_rxFrame ) throw( RuntimeException, std::exception )
    2656             : {
    2657           0 :     ::osl::MutexGuard aGuard( getMutex() );
    2658             : 
    2659           0 :     OApplicationController_CBASE::attachFrame( i_rxFrame );
    2660           0 :     if ( getFrame().is() )
    2661           0 :         onAttachedFrame();
    2662           0 : }
    2663             : 
    2664           0 : sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > & _rxModel) throw( RuntimeException, std::exception )
    2665             : {
    2666           0 :     ::osl::MutexGuard aGuard( getMutex() );
    2667           0 :     const Reference< XOfficeDatabaseDocument > xOfficeDoc( _rxModel, UNO_QUERY );
    2668           0 :     const Reference< XModifiable > xDocModify( _rxModel, UNO_QUERY );
    2669           0 :     if ( ( !xOfficeDoc.is() || !xDocModify.is() ) && _rxModel.is() )
    2670             :     {
    2671             :         OSL_FAIL( "OApplicationController::attachModel: invalid model!" );
    2672           0 :         return sal_False;
    2673             :     }
    2674             : 
    2675           0 :     if ( m_xModel.is() && ( m_xModel != _rxModel ) && ( _rxModel.is() ) )
    2676             :     {
    2677             :         OSL_ENSURE( false, "OApplicationController::attachModel: missing implementation: setting a new model while we have another one!" );
    2678             :         // we'd need to completely update our view here, close sub components, and the like
    2679           0 :         return sal_False;
    2680             :     }
    2681             : 
    2682             :     const OUString aPropertyNames[] =
    2683             :     {
    2684             :         OUString(PROPERTY_URL), OUString(PROPERTY_USER)
    2685           0 :     };
    2686             : 
    2687             :     // disconnect from old model
    2688             :     try
    2689             :     {
    2690           0 :         if ( m_xDataSource.is() )
    2691             :         {
    2692           0 :             for ( size_t i=0; i < sizeof( aPropertyNames ) / sizeof( aPropertyNames[0] ); ++i )
    2693             :             {
    2694           0 :                 m_xDataSource->removePropertyChangeListener( aPropertyNames[i], this );
    2695             :             }
    2696             :         }
    2697             : 
    2698           0 :         Reference< XModifyBroadcaster >  xBroadcaster( m_xModel, UNO_QUERY );
    2699           0 :         if ( xBroadcaster.is() )
    2700           0 :             xBroadcaster->removeModifyListener( this );
    2701             :     }
    2702           0 :     catch( const Exception& )
    2703             :     {
    2704             :         DBG_UNHANDLED_EXCEPTION();
    2705             :     }
    2706             : 
    2707           0 :     m_xModel = _rxModel;
    2708           0 :     m_xDocumentModify = xDocModify;
    2709           0 :     m_xDataSource.set( xOfficeDoc.is() ? xOfficeDoc->getDataSource() : Reference< XDataSource >(), UNO_QUERY );
    2710             : 
    2711             :     // connect to new model
    2712             :     try
    2713             :     {
    2714           0 :         if ( m_xDataSource.is() )
    2715             :         {
    2716           0 :             for ( size_t i=0; i < sizeof( aPropertyNames ) / sizeof( aPropertyNames[0] ); ++i )
    2717             :             {
    2718           0 :                 m_xDataSource->addPropertyChangeListener( aPropertyNames[i], this );
    2719             :             }
    2720             :         }
    2721             : 
    2722           0 :         Reference< XModifyBroadcaster >  xBroadcaster( m_xModel, UNO_QUERY_THROW );
    2723           0 :         xBroadcaster->addModifyListener( this );
    2724             : 
    2725             :     }
    2726           0 :     catch( const Exception& )
    2727             :     {
    2728             :         DBG_UNHANDLED_EXCEPTION();
    2729             :     }
    2730             : 
    2731             :     // initial preview mode
    2732           0 :     if ( m_xDataSource.is() )
    2733             :     {
    2734             :         try
    2735             :         {
    2736             :             // to get the 'modified' for the data source
    2737           0 :             ::comphelper::NamedValueCollection aLayoutInfo( m_xDataSource->getPropertyValue( PROPERTY_LAYOUTINFORMATION ) );
    2738           0 :             if ( aLayoutInfo.has( (OUString)INFO_PREVIEW ) )
    2739             :             {
    2740           0 :                 const sal_Int32 nPreviewMode( aLayoutInfo.getOrDefault( (OUString)INFO_PREVIEW, (sal_Int32)0 ) );
    2741           0 :                 m_ePreviewMode = static_cast< PreviewMode >( nPreviewMode );
    2742           0 :                 if ( getView() )
    2743           0 :                     getContainer()->switchPreview( m_ePreviewMode );
    2744           0 :             }
    2745             :         }
    2746           0 :         catch( const Exception& )
    2747             :         {
    2748             :             DBG_UNHANDLED_EXCEPTION();
    2749             :         }
    2750             :     }
    2751             : 
    2752           0 :     return sal_True;
    2753             : }
    2754             : 
    2755           0 : void OApplicationController::containerFound( const Reference< XContainer >& _xContainer)
    2756             : {
    2757             :     try
    2758             :     {
    2759           0 :         if ( _xContainer.is() )
    2760             :         {
    2761           0 :             m_aCurrentContainers.push_back(_xContainer);
    2762           0 :             _xContainer->addContainerListener(this);
    2763             :         }
    2764             :     }
    2765           0 :     catch(const Exception&)
    2766             :     {
    2767             :         DBG_UNHANDLED_EXCEPTION();
    2768             :     }
    2769           0 : }
    2770             : 
    2771           0 : OUString OApplicationController::getCurrentlySelectedName(sal_Int32& _rnCommandType) const
    2772             : {
    2773           0 :     _rnCommandType = ( (getContainer()->getElementType() == E_QUERY)
    2774           0 :                                 ? CommandType::QUERY : ( (getContainer()->getElementType() == E_TABLE) ? CommandType::TABLE : -1 ));
    2775             : 
    2776           0 :     OUString sName;
    2777           0 :     if ( _rnCommandType != -1 )
    2778             :     {
    2779             :         try
    2780             :         {
    2781           0 :             sName = getContainer()->getQualifiedName( NULL );
    2782             :             OSL_ENSURE( !sName.isEmpty(), "OApplicationController::getCurrentlySelectedName: no name given!" );
    2783             :         }
    2784           0 :         catch( const Exception& )
    2785             :         {
    2786             :             DBG_UNHANDLED_EXCEPTION();
    2787             :         }
    2788             :     }
    2789           0 :     return sName;
    2790             : }
    2791             : 
    2792           0 : void SAL_CALL OApplicationController::addSelectionChangeListener( const Reference< view::XSelectionChangeListener >& _Listener ) throw (RuntimeException, std::exception)
    2793             : {
    2794           0 :     m_pSelectionNotifier->addListener( _Listener );
    2795           0 : }
    2796             : 
    2797           0 : void SAL_CALL OApplicationController::removeSelectionChangeListener( const Reference< view::XSelectionChangeListener >& _Listener ) throw (RuntimeException, std::exception)
    2798             : {
    2799           0 :     m_pSelectionNotifier->removeListener( _Listener );
    2800           0 : }
    2801             : 
    2802           0 : sal_Bool SAL_CALL OApplicationController::select( const Any& _aSelection ) throw (IllegalArgumentException, RuntimeException, std::exception)
    2803             : {
    2804           0 :     SolarMutexGuard aSolarGuard;
    2805           0 :     ::osl::MutexGuard aGuard( getMutex() );
    2806           0 :     Sequence< OUString> aSelection;
    2807           0 :     if ( !_aSelection.hasValue() || !getView() )
    2808             :     {
    2809           0 :         getContainer()->selectElements(aSelection);
    2810           0 :         return sal_True;
    2811             :     }
    2812             : 
    2813             :     // BEGIN compatibility
    2814           0 :     Sequence< NamedValue > aCurrentSelection;
    2815           0 :     if ( (_aSelection >>= aCurrentSelection) && aCurrentSelection.getLength() )
    2816             :     {
    2817           0 :         ElementType eType = E_NONE;
    2818           0 :         const NamedValue* pIter = aCurrentSelection.getConstArray();
    2819           0 :         const NamedValue* pEnd  = pIter + aCurrentSelection.getLength();
    2820           0 :         for(;pIter != pEnd;++pIter)
    2821             :         {
    2822           0 :             if ( pIter->Name == "Type" )
    2823             :             {
    2824           0 :                 sal_Int32 nType = 0;
    2825           0 :                 pIter->Value >>= nType;
    2826           0 :                 if ( nType < DatabaseObject::TABLE || nType > DatabaseObject::REPORT )
    2827           0 :                     throw IllegalArgumentException();
    2828           0 :                 eType = static_cast< ElementType >( nType );
    2829             :             }
    2830           0 :             else if ( pIter->Name == "Selection" )
    2831           0 :                 pIter->Value >>= aSelection;
    2832             :         }
    2833             : 
    2834           0 :         m_aSelectContainerEvent.CancelCall();   // just in case the async select request was running
    2835           0 :         getContainer()->selectContainer(eType);
    2836           0 :         getContainer()->selectElements(aSelection);
    2837           0 :         return sal_True;
    2838             :     }
    2839             :     // END compatibility
    2840             : 
    2841           0 :     Sequence< NamedDatabaseObject > aSelectedObjects;
    2842           0 :     if ( !( _aSelection >>= aSelectedObjects ) )
    2843             :     {
    2844           0 :         aSelectedObjects.realloc( 1 );
    2845           0 :         if ( !( _aSelection >>= aSelectedObjects[0] ) )
    2846           0 :             throw IllegalArgumentException();
    2847             :     }
    2848             : 
    2849           0 :     SelectionByElementType aSelectedElements;
    2850           0 :     ElementType eSelectedCategory = E_NONE;
    2851           0 :     for (   const NamedDatabaseObject* pObject = aSelectedObjects.getConstArray();
    2852           0 :             pObject != aSelectedObjects.getConstArray() + aSelectedObjects.getLength();
    2853             :             ++pObject
    2854             :         )
    2855             :     {
    2856           0 :         switch ( pObject->Type )
    2857             :         {
    2858             :             case DatabaseObject::TABLE:
    2859             :             case DatabaseObjectContainer::SCHEMA:
    2860             :             case DatabaseObjectContainer::CATALOG:
    2861           0 :                 aSelectedElements[ E_TABLE ].push_back( pObject->Name );
    2862           0 :                 break;
    2863             :             case DatabaseObject::QUERY:
    2864           0 :                 aSelectedElements[ E_QUERY ].push_back( pObject->Name );
    2865           0 :                 break;
    2866             :             case DatabaseObject::FORM:
    2867             :             case DatabaseObjectContainer::FORMS_FOLDER:
    2868           0 :                 aSelectedElements[ E_FORM ].push_back( pObject->Name );
    2869           0 :                 break;
    2870             :             case DatabaseObject::REPORT:
    2871             :             case DatabaseObjectContainer::REPORTS_FOLDER:
    2872           0 :                 aSelectedElements[ E_REPORT ].push_back( pObject->Name );
    2873           0 :                 break;
    2874             :             case DatabaseObjectContainer::TABLES:
    2875             :             case DatabaseObjectContainer::QUERIES:
    2876             :             case DatabaseObjectContainer::FORMS:
    2877             :             case DatabaseObjectContainer::REPORTS:
    2878           0 :                 if ( eSelectedCategory != E_NONE )
    2879             :                     throw IllegalArgumentException(
    2880             :                         OUString(ModuleRes(RID_STR_NO_DIFF_CAT)),
    2881           0 :                         *this, sal_Int16( pObject - aSelectedObjects.getConstArray() ) );
    2882             :                 eSelectedCategory =
    2883           0 :                         ( pObject->Type == DatabaseObjectContainer::TABLES )  ? E_TABLE
    2884           0 :                     :   ( pObject->Type == DatabaseObjectContainer::QUERIES ) ? E_QUERY
    2885           0 :                     :   ( pObject->Type == DatabaseObjectContainer::FORMS )   ? E_FORM
    2886           0 :                     :   ( pObject->Type == DatabaseObjectContainer::REPORTS ) ? E_REPORT
    2887           0 :                     :   E_NONE;
    2888           0 :                 break;
    2889             : 
    2890             :             default:
    2891             :             case DatabaseObjectContainer::DATA_SOURCE:
    2892             :             {
    2893             :                 OUString sMessage(
    2894             :                         OUString(ModuleRes(RID_STR_UNSUPPORTED_OBJECT_TYPE)).
    2895           0 :                     replaceFirst("$type$", OUString::number(pObject->Type)));
    2896           0 :                 throw IllegalArgumentException(sMessage, *this, sal_Int16( pObject - aSelectedObjects.getConstArray() ));
    2897             :             }
    2898             :         }
    2899             :     }
    2900             : 
    2901           0 :     for (   SelectionByElementType::const_iterator sel = aSelectedElements.begin();
    2902           0 :             sel != aSelectedElements.end();
    2903             :             ++sel
    2904             :         )
    2905             :     {
    2906           0 :         if ( sel->first == m_eCurrentType )
    2907             :         {
    2908           0 :             Sequence< OUString > aSelected( sel->second.size() );
    2909           0 :             ::std::copy( sel->second.begin(), sel->second.end(), aSelected.getArray() );
    2910           0 :             getContainer()->selectElements( aSelected );
    2911             :         }
    2912             :         else
    2913             :         {
    2914           0 :             m_aPendingSelection[ sel->first ] = sel->second;
    2915             :         }
    2916             :     }
    2917             : 
    2918           0 :     m_aSelectContainerEvent.CancelCall();   // just in case the async select request was running
    2919           0 :     getContainer()->selectContainer( eSelectedCategory );
    2920             : 
    2921           0 :     return sal_True;
    2922             : }
    2923             : 
    2924           0 : Any SAL_CALL OApplicationController::getSelection(  ) throw (RuntimeException, std::exception)
    2925             : {
    2926           0 :     SolarMutexGuard aSolarGuard;
    2927           0 :     ::osl::MutexGuard aGuard( getMutex() );
    2928             : 
    2929           0 :     Sequence< NamedDatabaseObject > aCurrentSelection;
    2930           0 :     const ElementType eType( getContainer()->getElementType() );
    2931           0 :     if ( eType != E_NONE )
    2932             :     {
    2933           0 :         getContainer()->describeCurrentSelectionForType( eType, aCurrentSelection );
    2934           0 :         if ( aCurrentSelection.getLength() == 0 )
    2935             :         {   // if no objects are selected, add an entry to the sequence which describes the overall category
    2936             :             // which is selected currently
    2937           0 :             aCurrentSelection.realloc(1);
    2938           0 :             aCurrentSelection[0].Name = getDatabaseName();
    2939           0 :             switch ( eType )
    2940             :             {
    2941           0 :             case E_TABLE:   aCurrentSelection[0].Type = DatabaseObjectContainer::TABLES;   break;
    2942           0 :             case E_QUERY:   aCurrentSelection[0].Type = DatabaseObjectContainer::QUERIES;  break;
    2943           0 :             case E_FORM:    aCurrentSelection[0].Type = DatabaseObjectContainer::FORMS;    break;
    2944           0 :             case E_REPORT:  aCurrentSelection[0].Type = DatabaseObjectContainer::REPORTS;  break;
    2945             :             default:
    2946             :                 OSL_FAIL( "OApplicationController::getSelection: unexpected current element type!" );
    2947           0 :                 break;
    2948             :             }
    2949             :         }
    2950             :     }
    2951           0 :     return makeAny( aCurrentSelection );
    2952             : }
    2953             : 
    2954           0 : void OApplicationController::impl_migrateScripts_nothrow()
    2955             : {
    2956             :     try
    2957             :     {
    2958           0 :         Reference< XExecutableDialog > xDialog = css::sdb::application::MacroMigrationWizard::createWithDocument( getORB(), Reference< XOfficeDatabaseDocument >( m_xModel, UNO_QUERY_THROW ) );
    2959           0 :         xDialog->execute();
    2960             :     }
    2961           0 :     catch( const Exception& )
    2962             :     {
    2963             :         DBG_UNHANDLED_EXCEPTION();
    2964             :     }
    2965           0 : }
    2966             : 
    2967           0 : }   // namespace dbaui
    2968             : 
    2969             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10