LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/app - AppControllerGen.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 351 0.3 %
Date: 2013-07-09 Functions: 2 36 5.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "AppController.hxx"
      22             : #include "AppDetailView.hxx"
      23             : #include "AppView.hxx"
      24             : #include "dbaccess_slotid.hrc"
      25             : #include "dbu_app.hrc"
      26             : #include "dbustrings.hrc"
      27             : #include "defaultobjectnamecheck.hxx"
      28             : #include "dlgsave.hxx"
      29             : #include "UITools.hxx"
      30             : #include "subcomponentmanager.hxx"
      31             : 
      32             : #include <com/sun/star/container/XChild.hpp>
      33             : #include <com/sun/star/container/XContainer.hpp>
      34             : #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
      35             : #include <com/sun/star/container/XNameAccess.hpp>
      36             : #include <com/sun/star/container/XNameContainer.hpp>
      37             : #include <com/sun/star/lang/XEventListener.hpp>
      38             : #include <com/sun/star/sdb/CommandType.hpp>
      39             : #include <com/sun/star/sdb/SQLContext.hpp>
      40             : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      41             : #include <com/sun/star/sdbcx/XRename.hpp>
      42             : #include <com/sun/star/sdb/ErrorCondition.hpp>
      43             : #include <com/sun/star/sdb/application/DatabaseObject.hpp>
      44             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      45             : #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
      46             : #include <com/sun/star/ucb/Command.hpp>
      47             : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
      48             : #include <com/sun/star/ucb/XCommandProcessor.hpp>
      49             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      50             : #include <com/sun/star/uno/XNamingService.hpp>
      51             : #include <com/sun/star/util/XCloseable.hpp>
      52             : #include <com/sun/star/util/XRefreshable.hpp>
      53             : 
      54             : #include <cppuhelper/exc_hlp.hxx>
      55             : #include <comphelper/processfactory.hxx>
      56             : #include <connectivity/dbexception.hxx>
      57             : #include <connectivity/dbtools.hxx>
      58             : #include <connectivity/sqlerror.hxx>
      59             : #include <sfx2/mailmodelapi.hxx>
      60             : #include <svx/dbaexchange.hxx>
      61             : #include <toolkit/helper/vclunohelper.hxx>
      62             : #include <tools/diagnose_ex.h>
      63             : #include <osl/diagnose.h>
      64             : #include <unotools/bootstrap.hxx>
      65             : #include <vcl/mnemonic.hxx>
      66             : #include <vcl/svapp.hxx>
      67             : #include <vcl/waitobj.hxx>
      68             : #include <osl/mutex.hxx>
      69             : 
      70             : //........................................................................
      71             : namespace dbaui
      72             : {
      73             : using namespace ::dbtools;
      74             : using namespace ::connectivity;
      75             : using namespace ::svx;
      76             : using namespace ::com::sun::star;
      77             : using namespace ::com::sun::star::uno;
      78             : using namespace ::com::sun::star::awt;
      79             : using namespace ::com::sun::star::util;
      80             : using namespace ::com::sun::star::frame;
      81             : using namespace ::com::sun::star::lang;
      82             : using namespace ::com::sun::star::ui::dialogs;
      83             : using namespace ::com::sun::star::sdb;
      84             : using namespace ::com::sun::star::sdbc;
      85             : using namespace ::com::sun::star::sdbcx;
      86             : using namespace ::com::sun::star::beans;
      87             : using namespace ::com::sun::star::container;
      88             : using namespace ::com::sun::star::ucb;
      89             : 
      90             : using ::com::sun::star::util::XCloseable;
      91             : using ::com::sun::star::ui::XContextMenuInterceptor;
      92             : 
      93             : namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
      94             : namespace ErrorCondition = ::com::sun::star::sdb::ErrorCondition;
      95             : 
      96             : //........................................................................
      97             : // -----------------------------------------------------------------------------
      98             : 
      99             : class CloseChecker : public ::cppu::WeakImplHelper1< com::sun::star::lang::XEventListener >
     100             : {
     101             :     bool    m_bClosed;
     102             : 
     103             : public:
     104             :     CloseChecker()
     105             :         :m_bClosed( false )
     106             :     {
     107             :     }
     108             : 
     109             :     virtual ~CloseChecker()
     110             :     {
     111             :     }
     112             : 
     113             :     bool isClosed()
     114             :     {
     115             :         return true;
     116             :     }
     117             : 
     118             :     // interface XEventListener
     119             :     virtual void SAL_CALL disposing( const EventObject& /*Source*/ ) throw( RuntimeException )
     120             :     {
     121             :         m_bClosed = true;
     122             :     }
     123             : 
     124             : };
     125             : // -----------------------------------------------------------------------------
     126           0 : void OApplicationController::convertToView(const OUString& _sName)
     127             : {
     128             :     try
     129             :     {
     130           0 :         SharedConnection xConnection( getConnection() );
     131           0 :         Reference< XQueriesSupplier > xSup( xConnection, UNO_QUERY_THROW );
     132           0 :         Reference< XNameAccess > xQueries( xSup->getQueries(), UNO_QUERY_THROW );
     133           0 :         Reference< XPropertySet > xSourceObject( xQueries->getByName( _sName ), UNO_QUERY_THROW );
     134             : 
     135           0 :         Reference< XTablesSupplier > xTablesSup( xConnection, UNO_QUERY_THROW );
     136           0 :         Reference< XNameAccess > xTables( xTablesSup->getTables(), UNO_QUERY_THROW );
     137             : 
     138           0 :         Reference< XDatabaseMetaData  > xMeta = xConnection->getMetaData();
     139             : 
     140           0 :         OUString aName = OUString(ModuleRes(STR_TBL_TITLE));
     141           0 :         aName = aName.getToken(0,' ');
     142           0 :         OUString aDefaultName = ::dbaui::createDefaultName(xMeta,xTables,aName);
     143             : 
     144           0 :         DynamicTableOrQueryNameCheck aNameChecker( xConnection, CommandType::TABLE );
     145           0 :         OSaveAsDlg aDlg( getView(), CommandType::TABLE, getORB(), xConnection, aDefaultName, aNameChecker );
     146           0 :         if ( aDlg.Execute() == RET_OK )
     147             :         {
     148           0 :             OUString sName = aDlg.getName();
     149           0 :             OUString sCatalog = aDlg.getCatalog();
     150           0 :             OUString sSchema  = aDlg.getSchema();
     151             :             OUString sNewName(
     152           0 :                 ::dbtools::composeTableName( xMeta, sCatalog, sSchema, sName, sal_False, ::dbtools::eInTableDefinitions ) );
     153           0 :             Reference<XPropertySet> xView = ::dbaui::createView(sNewName,xConnection,xSourceObject);
     154           0 :             if ( !xView.is() )
     155           0 :                 throw SQLException(OUString(ModuleRes(STR_NO_TABLE_FORMAT_INSIDE)),*this,OUString( "S1000" ) ,0,Any());
     156           0 :             getContainer()->elementAdded(E_TABLE,sNewName,makeAny(xView));
     157           0 :         }
     158             :     }
     159           0 :     catch(const SQLException& )
     160             :     {
     161           0 :         showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
     162             :     }
     163           0 :     catch( const Exception& )
     164             :     {
     165             :         DBG_UNHANDLED_EXCEPTION();
     166             :     }
     167           0 : }
     168             : // -----------------------------------------------------------------------------
     169           0 : void OApplicationController::pasteFormat(sal_uInt32 _nFormatId)
     170             : {
     171           0 :     if ( _nFormatId )
     172             :     {
     173             :         try
     174             :         {
     175           0 :             const TransferableDataHelper& rClipboard = getViewClipboard();
     176           0 :             ElementType eType = getContainer()->getElementType();
     177           0 :             if ( eType == E_TABLE )
     178             :             {
     179           0 :                 m_aTableCopyHelper.pasteTable( _nFormatId, rClipboard, getDatabaseName(), ensureConnection() );
     180             :             }
     181             :             else
     182           0 :                 paste( eType, ODataAccessObjectTransferable::extractObjectDescriptor( rClipboard ) );
     183             : 
     184             :         }
     185           0 :         catch( const Exception& )
     186             :         {
     187             :             DBG_UNHANDLED_EXCEPTION();
     188             :         }
     189             :     }
     190           0 : }
     191             : // -----------------------------------------------------------------------------
     192           0 : void OApplicationController::openDataSourceAdminDialog()
     193             : {
     194           0 :     openDialog( OUString( "com.sun.star.sdb.DatasourceAdministrationDialog" ) );
     195           0 : }
     196             : 
     197             : // -----------------------------------------------------------------------------
     198           0 : void OApplicationController::openDialog( const OUString& _sServiceName )
     199             : {
     200             :     try
     201             :     {
     202           0 :         SolarMutexGuard aSolarGuard;
     203           0 :         ::osl::MutexGuard aGuard( getMutex() );
     204           0 :         WaitObject aWO(getView());
     205             : 
     206           0 :         Sequence< Any > aArgs(3);
     207           0 :         sal_Int32 nArgPos = 0;
     208             : 
     209           0 :         Reference< ::com::sun::star::awt::XWindow> xWindow = getTopMostContainerWindow();
     210           0 :         if ( !xWindow.is() )
     211             :         {
     212             :             OSL_ENSURE( getContainer(), "OApplicationController::Construct: have no view!" );
     213           0 :             if ( getContainer() )
     214           0 :                 xWindow = VCLUnoHelper::GetInterface(getView()->Window::GetParent());
     215             :         }
     216             :         // the parent window
     217           0 :         aArgs[nArgPos++] <<= PropertyValue( OUString("ParentWindow"),
     218             :                                     0,
     219             :                                     makeAny(xWindow),
     220           0 :                                     PropertyState_DIRECT_VALUE);
     221             : 
     222             :         // the initial selection
     223           0 :         OUString sInitialSelection;
     224           0 :         if ( getContainer() )
     225           0 :             sInitialSelection = getDatabaseName();
     226           0 :         if ( !sInitialSelection.isEmpty() )
     227             :         {
     228           0 :             aArgs[ nArgPos++ ] <<= PropertyValue(
     229             :                 OUString( "InitialSelection" ), 0,
     230           0 :                 makeAny( sInitialSelection ), PropertyState_DIRECT_VALUE );
     231             :         }
     232             : 
     233           0 :         SharedConnection xConnection( getConnection() );
     234           0 :         if ( xConnection.is() )
     235             :         {
     236           0 :             aArgs[ nArgPos++ ] <<= PropertyValue(
     237             :                 PROPERTY_ACTIVE_CONNECTION, 0,
     238           0 :                 makeAny( xConnection ), PropertyState_DIRECT_VALUE );
     239             :         }
     240           0 :         aArgs.realloc( nArgPos );
     241             : 
     242             :         // create the dialog
     243           0 :         Reference< XExecutableDialog > xAdminDialog;
     244           0 :         xAdminDialog = Reference< XExecutableDialog >(
     245           0 :             getORB()->getServiceManager()->createInstanceWithArgumentsAndContext(_sServiceName, aArgs, getORB()),
     246           0 :             UNO_QUERY);
     247             : 
     248             :         // execute it
     249           0 :         if (xAdminDialog.is())
     250           0 :             xAdminDialog->execute();
     251             :     }
     252           0 :     catch( const Exception& )
     253             :     {
     254             :         DBG_UNHANDLED_EXCEPTION();
     255             :     }
     256           0 : }
     257             : // -----------------------------------------------------------------------------
     258           0 : void OApplicationController::openTableFilterDialog()
     259             : {
     260           0 :     openDialog( OUString( "com.sun.star.sdb.TableFilterDialog" ) );
     261           0 : }
     262             : 
     263             : // -----------------------------------------------------------------------------
     264           0 : void OApplicationController::refreshTables()
     265             : {
     266           0 :     if ( getContainer() && getContainer()->getDetailView() )
     267             :     {
     268           0 :         WaitObject aWO(getView());
     269             :         OSL_ENSURE(getContainer()->getElementType() == E_TABLE,"Only allowed when the tables container is selected!");
     270             :         try
     271             :         {
     272           0 :             Reference<XRefreshable> xRefresh(getElements(E_TABLE),UNO_QUERY);
     273           0 :             if ( xRefresh.is() )
     274           0 :                 xRefresh->refresh();
     275             :         }
     276           0 :         catch(const Exception&)
     277             :         {
     278             :             OSL_FAIL("Could not refresh tables!");
     279             :         }
     280             : 
     281           0 :         getContainer()->getDetailView()->clearPages(sal_False);
     282           0 :         getContainer()->getDetailView()->createTablesPage( ensureConnection() );
     283             :     }
     284           0 : }
     285             : // -----------------------------------------------------------------------------
     286           0 : void OApplicationController::openDirectSQLDialog()
     287             : {
     288           0 :     openDialog( SERVICE_SDB_DIRECTSQLDIALOG );
     289           0 : }
     290             : // -----------------------------------------------------------------------------
     291           0 : void SAL_CALL OApplicationController::propertyChange( const PropertyChangeEvent& evt ) throw (RuntimeException)
     292             : {
     293           0 :     SolarMutexGuard aSolarGuard;
     294           0 :     ::osl::MutexGuard aGuard( getMutex() );
     295           0 :     if ( evt.PropertyName == PROPERTY_USER )
     296             :     {
     297           0 :         m_bNeedToReconnect = sal_True;
     298           0 :         InvalidateFeature(SID_DB_APP_STATUS_USERNAME);
     299             :     }
     300           0 :     else if ( evt.PropertyName == PROPERTY_URL )
     301             :     {
     302           0 :         m_bNeedToReconnect = sal_True;
     303           0 :         InvalidateFeature(SID_DB_APP_STATUS_DBNAME);
     304           0 :         InvalidateFeature(SID_DB_APP_STATUS_TYPE);
     305           0 :         InvalidateFeature(SID_DB_APP_STATUS_HOSTNAME);
     306             :     }
     307           0 :     else if ( PROPERTY_NAME == evt.PropertyName )
     308             :     {
     309           0 :         const ElementType eType = getContainer()->getElementType();
     310           0 :         if ( eType == E_FORM || eType == E_REPORT )
     311             :         {
     312           0 :             OUString sOldName,sNewName;
     313           0 :             evt.OldValue >>= sOldName;
     314           0 :             evt.NewValue >>= sNewName;
     315             : 
     316             :             // if the old name is empty, then this is a newly inserted content. We're notified of it via the
     317             :             // elementInserted method, so there's no need to handle it here.
     318             : 
     319           0 :             if ( !sOldName.isEmpty() )
     320             :             {
     321           0 :                 Reference<XChild> xChild(evt.Source,UNO_QUERY);
     322           0 :                 if ( xChild.is() )
     323             :                 {
     324           0 :                     Reference<XContent> xContent(xChild->getParent(),UNO_QUERY);
     325           0 :                     if ( xContent.is() )
     326           0 :                         sOldName = xContent->getIdentifier()->getContentIdentifier() + OUString("/") + sOldName;
     327             :                 }
     328             : 
     329           0 :                 getContainer()->elementReplaced( eType , sOldName, sNewName );
     330           0 :             }
     331             :         }
     332             :     }
     333             : 
     334           0 :     EventObject aEvt;
     335           0 :     aEvt.Source = m_xModel;
     336           0 :     modified(aEvt);
     337           0 : }
     338             : 
     339             : // -----------------------------------------------------------------------------
     340           0 : Reference< XDataSource > SAL_CALL OApplicationController::getDataSource() throw (RuntimeException)
     341             : {
     342           0 :     ::osl::MutexGuard aGuard( getMutex() );
     343           0 :     Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
     344           0 :     return xDataSource;
     345             : }
     346             : 
     347             : // -----------------------------------------------------------------------------
     348           0 : Reference< XWindow > SAL_CALL OApplicationController::getApplicationMainWindow() throw (RuntimeException)
     349             : {
     350           0 :     ::osl::MutexGuard aGuard( getMutex() );
     351           0 :     Reference< XFrame > xFrame( getFrame(), UNO_QUERY_THROW );
     352           0 :     Reference< XWindow > xWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
     353           0 :     return xWindow;
     354             : }
     355             : 
     356             : // -----------------------------------------------------------------------------
     357           0 : Sequence< Reference< XComponent > > SAL_CALL OApplicationController::getSubComponents() throw (RuntimeException)
     358             : {
     359           0 :     ::osl::MutexGuard aGuard( getMutex() );
     360           0 :     return m_pSubComponentManager->getSubComponents();
     361             : }
     362             : 
     363             : // -----------------------------------------------------------------------------
     364           0 : Reference< XConnection > SAL_CALL OApplicationController::getActiveConnection() throw (RuntimeException)
     365             : {
     366           0 :     ::osl::MutexGuard aGuard( getMutex() );
     367           0 :     return m_xDataSourceConnection.getTyped();
     368             : }
     369             : 
     370             : // -----------------------------------------------------------------------------
     371           0 : ::sal_Bool SAL_CALL OApplicationController::isConnected(  ) throw (RuntimeException)
     372             : {
     373           0 :     ::osl::MutexGuard aGuard( getMutex() );
     374           0 :     return m_xDataSourceConnection.is();
     375             : }
     376             : 
     377             : // -----------------------------------------------------------------------------
     378           0 : void SAL_CALL OApplicationController::connect(  ) throw (SQLException, RuntimeException)
     379             : {
     380           0 :     SQLExceptionInfo aError;
     381           0 :     SharedConnection xConnection = ensureConnection( &aError );
     382           0 :     if ( !xConnection.is() )
     383             :     {
     384           0 :         if ( aError.isValid() )
     385           0 :             aError.doThrow();
     386             : 
     387             :         // no particular error, but nonetheless could not connect -> throw a generic exception
     388           0 :         OUString sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE ) );
     389           0 :         ::dbtools::throwGenericSQLException( sConnectingContext.replaceFirst( "$name$", getStrippedDatabaseName() ), *this );
     390           0 :     }
     391           0 : }
     392             : 
     393             : // -----------------------------------------------------------------------------
     394           0 : beans::Pair< ::sal_Int32, OUString > SAL_CALL OApplicationController::identifySubComponent( const Reference< XComponent >& i_rSubComponent ) throw (IllegalArgumentException, RuntimeException)
     395             : {
     396           0 :     ::osl::MutexGuard aGuard( getMutex() );
     397             : 
     398           0 :     sal_Int32 nType = -1;
     399           0 :     OUString sName;
     400             : 
     401           0 :     if ( !m_pSubComponentManager->lookupSubComponent( i_rSubComponent, sName, nType ) )
     402           0 :         throw IllegalArgumentException( OUString(), *this, 1 );
     403             : 
     404           0 :     if ( nType == SID_DB_APP_DSRELDESIGN )
     405             :         // this is somewhat hacky ... we're expected to return a DatabaseObject value. However, there is no such
     406             :         // value for the relation design. /me thinks we should change the API definition here ...
     407           0 :         nType = -1;
     408             : 
     409           0 :     return beans::Pair< ::sal_Int32, OUString >( nType, sName );
     410             : }
     411             : 
     412             : // -----------------------------------------------------------------------------
     413           0 : ::sal_Bool SAL_CALL OApplicationController::closeSubComponents(  ) throw (RuntimeException)
     414             : {
     415           0 :     SolarMutexGuard aSolarGuard;
     416           0 :     ::osl::MutexGuard aGuard( getMutex() );
     417           0 :     return m_pSubComponentManager->closeSubComponents();
     418             : }
     419             : 
     420             : 
     421             : // -----------------------------------------------------------------------------
     422             : namespace
     423             : {
     424           0 :     ElementType lcl_objectType2ElementType( const sal_Int32 _nObjectType )
     425             :     {
     426           0 :         ElementType eType( E_NONE );
     427           0 :         switch ( _nObjectType )
     428             :         {
     429           0 :         case DatabaseObject::TABLE:  eType = E_TABLE;   break;
     430           0 :         case DatabaseObject::QUERY:  eType = E_QUERY;   break;
     431           0 :         case DatabaseObject::FORM:   eType = E_FORM;    break;
     432           0 :         case DatabaseObject::REPORT: eType = E_REPORT;  break;
     433             :         default:
     434             :             OSL_FAIL( "lcl_objectType2ElementType: unsupported object type!" );
     435             :                 // this should have been caught earlier
     436             :         }
     437           0 :         return eType;
     438             :     }
     439             : }
     440             : 
     441             : // -----------------------------------------------------------------------------
     442           0 : void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::boost::optional< OUString >& i_rObjectName )
     443             : {
     444             :     // ensure we're connected
     445           0 :     if ( !isConnected() )
     446             :     {
     447           0 :         SQLError aError( getORB() );
     448           0 :         aError.raiseException( ErrorCondition::DB_NOT_CONNECTED, *this );
     449             :     }
     450             : 
     451             :     // ensure a proper object type
     452           0 :     if  (   ( _nObjectType != DatabaseObject::TABLE )
     453           0 :         &&  ( _nObjectType != DatabaseObject::QUERY )
     454           0 :         &&  ( _nObjectType != DatabaseObject::FORM )
     455           0 :         &&  ( _nObjectType != DatabaseObject::REPORT )
     456             :         )
     457           0 :         throw IllegalArgumentException( OUString(), *this, 1 );
     458             : 
     459           0 :     if ( !i_rObjectName )
     460           0 :         return;
     461             : 
     462             :     // ensure an existing object
     463           0 :     Reference< XNameAccess > xContainer( getElements( lcl_objectType2ElementType( _nObjectType ) ) );
     464           0 :     if ( !xContainer.is() )
     465             :         // all possible reasons for this (e.g. not being connected currently) should
     466             :         // have been handled before
     467           0 :         throw RuntimeException( OUString(), *this );
     468             : 
     469           0 :     bool bExistentObject = false;
     470           0 :     switch ( _nObjectType )
     471             :     {
     472             :     case DatabaseObject::TABLE:
     473             :     case DatabaseObject::QUERY:
     474           0 :         bExistentObject = xContainer->hasByName( *i_rObjectName );
     475           0 :         break;
     476             :     case DatabaseObject::FORM:
     477             :     case DatabaseObject::REPORT:
     478             :     {
     479           0 :         Reference< XHierarchicalNameAccess > xHierarchy( xContainer, UNO_QUERY_THROW );
     480           0 :         bExistentObject = xHierarchy->hasByHierarchicalName( *i_rObjectName );
     481             :     }
     482           0 :     break;
     483             :     }
     484             : 
     485           0 :     if ( !bExistentObject )
     486           0 :         throw NoSuchElementException( *i_rObjectName, *this );
     487             : }
     488             : 
     489             : // -----------------------------------------------------------------------------
     490           0 : Reference< XComponent > SAL_CALL OApplicationController::loadComponent( ::sal_Int32 _ObjectType,
     491             :     const OUString& _ObjectName, ::sal_Bool _ForEditing ) throw (IllegalArgumentException, NoSuchElementException, SQLException, RuntimeException)
     492             : {
     493           0 :     return loadComponentWithArguments( _ObjectType, _ObjectName, _ForEditing, Sequence< PropertyValue >() );
     494             : }
     495             : 
     496             : // -----------------------------------------------------------------------------
     497           0 : Reference< XComponent > SAL_CALL OApplicationController::loadComponentWithArguments( ::sal_Int32 _ObjectType,
     498             :     const OUString& _ObjectName, ::sal_Bool _ForEditing, const Sequence< PropertyValue >& _Arguments ) throw (IllegalArgumentException, NoSuchElementException, SQLException, RuntimeException)
     499             : {
     500           0 :     SolarMutexGuard aSolarGuard;
     501           0 :     ::osl::MutexGuard aGuard( getMutex() );
     502             : 
     503           0 :     impl_validateObjectTypeAndName_throw( _ObjectType, _ObjectName );
     504             : 
     505             :     Reference< XComponent > xComponent( openElementWithArguments(
     506             :         _ObjectName,
     507             :         lcl_objectType2ElementType( _ObjectType ),
     508             :         _ForEditing ? E_OPEN_DESIGN : E_OPEN_NORMAL,
     509             :         _ForEditing ? SID_DB_APP_EDIT : SID_DB_APP_OPEN,
     510             :         ::comphelper::NamedValueCollection( _Arguments )
     511           0 :     ) );
     512             : 
     513           0 :     return xComponent;
     514             : }
     515             : 
     516             : // -----------------------------------------------------------------------------
     517           0 : Reference< XComponent > SAL_CALL OApplicationController::createComponent( ::sal_Int32 i_nObjectType, Reference< XComponent >& o_DocumentDefinition  ) throw (IllegalArgumentException, SQLException, RuntimeException)
     518             : {
     519           0 :     return createComponentWithArguments( i_nObjectType, Sequence< PropertyValue >(), o_DocumentDefinition );
     520             : }
     521             : 
     522             : // -----------------------------------------------------------------------------
     523           0 : Reference< XComponent > SAL_CALL OApplicationController::createComponentWithArguments( ::sal_Int32 i_nObjectType, const Sequence< PropertyValue >& i_rArguments, Reference< XComponent >& o_DocumentDefinition ) throw (IllegalArgumentException, SQLException, RuntimeException)
     524             : {
     525           0 :     SolarMutexGuard aSolarGuard;
     526           0 :     ::osl::MutexGuard aGuard( getMutex() );
     527             : 
     528           0 :     impl_validateObjectTypeAndName_throw( i_nObjectType, ::boost::optional< OUString >() );
     529             : 
     530             :     Reference< XComponent > xComponent( newElement(
     531             :         lcl_objectType2ElementType( i_nObjectType ),
     532             :         ::comphelper::NamedValueCollection( i_rArguments ),
     533             :         o_DocumentDefinition
     534           0 :     ) );
     535             : 
     536           0 :     return xComponent;
     537             : }
     538             : 
     539             : // -----------------------------------------------------------------------------
     540           0 : void SAL_CALL OApplicationController::registerContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException)
     541             : {
     542           0 :     if ( _Interceptor.is() )
     543           0 :         m_aContextMenuInterceptors.addInterface( _Interceptor );
     544           0 : }
     545             : 
     546             : // -----------------------------------------------------------------------------
     547           0 : void SAL_CALL OApplicationController::releaseContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException)
     548             : {
     549           0 :     m_aContextMenuInterceptors.removeInterface( _Interceptor );
     550           0 : }
     551             : 
     552             : // -----------------------------------------------------------------------------
     553           0 : void OApplicationController::previewChanged( sal_Int32 _nMode )
     554             : {
     555           0 :     SolarMutexGuard aSolarGuard;
     556           0 :     ::osl::MutexGuard aGuard( getMutex() );
     557             : 
     558           0 :     if ( m_xDataSource.is() && !isDataSourceReadOnly() )
     559             :     {
     560             :         try
     561             :         {
     562           0 :             ::comphelper::NamedValueCollection aLayoutInfo( m_xDataSource->getPropertyValue( PROPERTY_LAYOUTINFORMATION ) );
     563           0 :             sal_Int32 nOldMode = aLayoutInfo.getOrDefault( "Preview", _nMode );
     564           0 :             if ( nOldMode != _nMode )
     565             :             {
     566           0 :                 aLayoutInfo.put( "Preview", _nMode );
     567           0 :                 m_xDataSource->setPropertyValue( PROPERTY_LAYOUTINFORMATION, makeAny( aLayoutInfo.getPropertyValues() ) );
     568           0 :             }
     569             :         }
     570           0 :         catch ( const Exception& )
     571             :         {
     572             :             DBG_UNHANDLED_EXCEPTION();
     573             :         }
     574             :     }
     575           0 :     InvalidateFeature(SID_DB_APP_DISABLE_PREVIEW);
     576           0 :     InvalidateFeature(SID_DB_APP_VIEW_DOCINFO_PREVIEW);
     577           0 :     InvalidateFeature(SID_DB_APP_VIEW_DOC_PREVIEW);
     578           0 : }
     579             : // -----------------------------------------------------------------------------
     580           0 : void OApplicationController::askToReconnect()
     581             : {
     582           0 :     if ( m_bNeedToReconnect )
     583             :     {
     584           0 :         m_bNeedToReconnect = sal_False;
     585           0 :         sal_Bool bClear = sal_True;
     586           0 :         if ( !m_pSubComponentManager->empty() )
     587             :         {
     588           0 :             QueryBox aQry(getView(), ModuleRes(APP_CLOSEDOCUMENTS));
     589           0 :             switch (aQry.Execute())
     590             :             {
     591             :                 case RET_YES:
     592           0 :                     closeSubComponents();
     593           0 :                     break;
     594             :                 default:
     595           0 :                     bClear = sal_False;
     596           0 :                     break;
     597           0 :             }
     598             :         }
     599           0 :         if ( bClear )
     600             :         {
     601           0 :             ElementType eType = getContainer()->getElementType();
     602           0 :             disconnect();
     603           0 :             getContainer()->getDetailView()->clearPages(sal_False);
     604           0 :             getContainer()->selectContainer(E_NONE); // invalidate the old selection
     605           0 :             m_eCurrentType = E_NONE;
     606           0 :             getContainer()->selectContainer(eType); // reselect the current one again
     607             :         }
     608             :     }
     609           0 : }
     610             : 
     611             : // -----------------------------------------------------------------------------
     612           0 : OUString OApplicationController::getDatabaseName() const
     613             : {
     614           0 :     OUString sDatabaseName;
     615             :     try
     616             :     {
     617           0 :         if ( m_xDataSource.is() )
     618             :         {
     619           0 :             OSL_VERIFY( m_xDataSource->getPropertyValue( PROPERTY_NAME ) >>= sDatabaseName );
     620             :         }
     621             :     }
     622           0 :     catch ( const Exception& )
     623             :     {
     624             :         DBG_UNHANDLED_EXCEPTION();
     625             :     }
     626           0 :     return sDatabaseName;
     627             : }
     628             : 
     629             : // -----------------------------------------------------------------------------
     630           0 : OUString OApplicationController::getStrippedDatabaseName() const
     631             : {
     632           0 :     OUString sDatabaseName;
     633           0 :     return ::dbaui::getStrippedDatabaseName( m_xDataSource, sDatabaseName );
     634             : }
     635             : 
     636             : // -----------------------------------------------------------------------------
     637           0 : void OApplicationController::onDocumentOpened( const OUString& _rName, const sal_Int32 _nType,
     638             :         const ElementOpenMode _eMode, const Reference< XComponent >& _xDocument, const Reference< XComponent >& _rxDefinition )
     639             : {
     640           0 :     if ( !_xDocument.is() )
     641           0 :         return;
     642             : 
     643             :     try
     644             :     {
     645             :         OSL_ENSURE( _xDocument.is(), "OApplicationController::onDocumentOpened: is there any *valid* scenario where this fails?" );
     646           0 :         m_pSubComponentManager->onSubComponentOpened( _rName, _nType, _eMode, _xDocument.is() ? _xDocument : _rxDefinition );
     647             : 
     648           0 :         if ( _rxDefinition.is() )
     649             :         {
     650           0 :             Reference< XPropertySet > xProp( _rxDefinition, UNO_QUERY_THROW );
     651           0 :             Reference< XPropertySetInfo > xPSI( xProp->getPropertySetInfo(), UNO_SET_THROW );
     652           0 :             xProp->addPropertyChangeListener( PROPERTY_NAME, static_cast< XPropertyChangeListener* >( this ) );
     653             :         }
     654             :     }
     655           0 :     catch( const Exception& )
     656             :     {
     657             :         DBG_UNHANDLED_EXCEPTION();
     658             :     }
     659             : }
     660             : // -----------------------------------------------------------------------------
     661           0 : sal_Bool OApplicationController::insertHierachyElement(ElementType _eType,const OUString& _sParentFolder,sal_Bool _bCollection,const Reference<XContent>& _xContent,sal_Bool _bMove)
     662             : {
     663           0 :     Reference<XHierarchicalNameContainer> xNames(getElements(_eType), UNO_QUERY);
     664           0 :     return dbaui::insertHierachyElement(getView()
     665             :                            ,getORB()
     666             :                            ,xNames
     667             :                            ,_sParentFolder
     668             :                            ,_eType == E_FORM
     669             :                            ,_bCollection
     670             :                            ,_xContent
     671           0 :                            ,_bMove);
     672             : }
     673             : // -----------------------------------------------------------------------------
     674           0 : sal_Bool OApplicationController::isRenameDeleteAllowed(ElementType _eType,sal_Bool _bDelete) const
     675             : {
     676           0 :     ElementType eType = getContainer()->getElementType();
     677           0 :     sal_Bool bEnabled = !isDataSourceReadOnly() && eType == _eType;
     678           0 :     if ( bEnabled )
     679             :     {
     680             : 
     681           0 :         if ( E_TABLE == eType )
     682           0 :             bEnabled = !isConnectionReadOnly() && getContainer()->isALeafSelected();
     683             : 
     684           0 :         sal_Bool bCompareRes = sal_False;
     685           0 :         if ( _bDelete )
     686           0 :             bCompareRes = getContainer()->getSelectionCount() > 0;
     687             :         else
     688             :         {
     689           0 :             bCompareRes = getContainer()->getSelectionCount() == 1;
     690           0 :             if ( bEnabled && bCompareRes && E_TABLE == eType )
     691             :             {
     692           0 :                 ::std::vector< OUString> aList;
     693           0 :                 getSelectionElementNames(aList);
     694             : 
     695             :                 try
     696             :                 {
     697           0 :                     Reference< XNameAccess > xContainer = const_cast<OApplicationController*>(this)->getElements(eType);
     698           0 :                     bEnabled = (xContainer.is() && xContainer->hasByName(*aList.begin()));
     699           0 :                     if ( bEnabled )
     700           0 :                         bEnabled = Reference<XRename>(xContainer->getByName(*aList.begin()),UNO_QUERY).is();
     701             :                 }
     702           0 :                 catch(Exception&)
     703             :                 {
     704           0 :                     bEnabled = sal_False;
     705           0 :                 }
     706             :             }
     707             :         }
     708             : 
     709           0 :         bEnabled = bEnabled && bCompareRes;
     710             :     }
     711           0 :     return bEnabled;
     712             : }
     713             : // -----------------------------------------------------------------------------
     714           0 : void OApplicationController::onLoadedMenu(const Reference< ::com::sun::star::frame::XLayoutManager >& _xLayoutManager)
     715             : {
     716             : 
     717           0 :     if ( _xLayoutManager.is() )
     718             :     {
     719           0 :         static OUString s_sStatusbar("private:resource/statusbar/statusbar");
     720           0 :         _xLayoutManager->createElement( s_sStatusbar );
     721           0 :         _xLayoutManager->requestElement( s_sStatusbar );
     722             : 
     723           0 :         if ( getContainer() )
     724             :         {
     725             :             // we need to share the "mnemonic space":
     726           0 :             MnemonicGenerator aMnemonicGenerator;
     727             :             // - the menu already has mnemonics
     728           0 :             SystemWindow* pSystemWindow = getContainer()->GetSystemWindow();
     729           0 :             MenuBar* pMenu = pSystemWindow ? pSystemWindow->GetMenuBar() : NULL;
     730           0 :             if ( pMenu )
     731             :             {
     732           0 :                 sal_uInt16 nMenuItems = pMenu->GetItemCount();
     733           0 :                 for ( sal_uInt16 i = 0; i < nMenuItems; ++i )
     734           0 :                     aMnemonicGenerator.RegisterMnemonic( pMenu->GetItemText( pMenu->GetItemId( i ) ) );
     735             :             }
     736             :             // - the icons should use automatic ones
     737           0 :             getContainer()->createIconAutoMnemonics( aMnemonicGenerator );
     738             :             // - as well as the entries in the task pane
     739           0 :             getContainer()->setTaskExternalMnemonics( aMnemonicGenerator );
     740             :         }
     741             : 
     742           0 :         Execute( SID_DB_APP_VIEW_FORMS, Sequence< PropertyValue >() );
     743           0 :         InvalidateAll();
     744             :     }
     745           0 : }
     746             : // -----------------------------------------------------------------------------
     747           0 : void OApplicationController::doAction(sal_uInt16 _nId ,ElementOpenMode _eOpenMode)
     748             : {
     749           0 :     ::std::vector< OUString> aList;
     750           0 :     getSelectionElementNames(aList);
     751           0 :     ElementType eType = getContainer()->getElementType();
     752           0 :     ::comphelper::NamedValueCollection aArguments;
     753           0 :     ElementOpenMode eOpenMode = _eOpenMode;
     754           0 :     if ( eType == E_REPORT && E_OPEN_FOR_MAIL == _eOpenMode )
     755             :     {
     756           0 :         aArguments.put("Hidden",true);
     757           0 :         eOpenMode = E_OPEN_NORMAL;
     758             :     }
     759             : 
     760           0 :     ::std::vector< ::std::pair< OUString ,Reference< XModel > > > aCompoments;
     761           0 :     ::std::vector< OUString>::iterator aEnd = aList.end();
     762           0 :     for (::std::vector< OUString>::iterator aIter = aList.begin(); aIter != aEnd; ++aIter)
     763             :     {
     764           0 :         if ( SID_DB_APP_CONVERTTOVIEW == _nId )
     765           0 :             convertToView(*aIter);
     766             :         else
     767             :         {
     768           0 :             Reference< XModel > xModel( openElementWithArguments( *aIter, eType, eOpenMode, _nId,aArguments ), UNO_QUERY );
     769           0 :             aCompoments.push_back( ::std::pair< OUString, Reference< XModel > >( *aIter, xModel ) );
     770             :         }
     771             :     }
     772             : 
     773             :     // special handling for mail, if more than one document is selected attach them all
     774           0 :     if ( _eOpenMode == E_OPEN_FOR_MAIL )
     775             :     {
     776             : 
     777           0 :         ::std::vector< ::std::pair< OUString ,Reference< XModel > > >::iterator componentIter = aCompoments.begin();
     778           0 :         ::std::vector< ::std::pair< OUString ,Reference< XModel > > >::iterator componentEnd = aCompoments.end();
     779           0 :         OUString aDocTypeString;
     780           0 :         SfxMailModel aSendMail;
     781           0 :         SfxMailModel::SendMailResult eResult = SfxMailModel::SEND_MAIL_OK;
     782           0 :         for (; componentIter != componentEnd && SfxMailModel::SEND_MAIL_OK == eResult; ++componentIter)
     783             :         {
     784             :             try
     785             :             {
     786           0 :                 Reference< XModel > xModel(componentIter->second,UNO_QUERY);
     787             : 
     788             :                 // Send document as e-Mail using stored/default type
     789           0 :                 eResult = aSendMail.AttachDocument(aDocTypeString,xModel,componentIter->first);
     790           0 :                 ::comphelper::disposeComponent(xModel);
     791             :             }
     792           0 :             catch(const Exception&)
     793             :             {
     794             :                 DBG_UNHANDLED_EXCEPTION();
     795             :             }
     796             :         }
     797           0 :         if ( !aSendMail.IsEmpty() )
     798           0 :             aSendMail.Send( getFrame() );
     799           0 :     }
     800           0 : }
     801             : // -----------------------------------------------------------------------------
     802           0 : ElementType OApplicationController::getElementType(const Reference< XContainer >& _xContainer) const
     803             : {
     804           0 :     ElementType eRet = E_NONE;
     805           0 :     Reference<XServiceInfo> xServiceInfo(_xContainer,UNO_QUERY);
     806           0 :     if ( xServiceInfo.is() )
     807             :     {
     808           0 :         if ( xServiceInfo->supportsService(SERVICE_SDBCX_TABLES) )
     809           0 :             eRet = E_TABLE;
     810           0 :         else if ( xServiceInfo->supportsService(SERVICE_NAME_FORM_COLLECTION) )
     811           0 :             eRet = E_FORM;
     812           0 :         else if ( xServiceInfo->supportsService(SERVICE_NAME_REPORT_COLLECTION) )
     813           0 :             eRet = E_REPORT;
     814             :         else
     815           0 :             eRet = E_QUERY;
     816             :     }
     817           0 :     return eRet;
     818             : }
     819             : 
     820             : //........................................................................
     821          12 : }   // namespace dbaui
     822             : //........................................................................
     823             : 
     824             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10