1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "AppController.hxx"
21 #include "AppDetailView.hxx"
22 #include "AppView.hxx"
23 #include "dbaccess_slotid.hrc"
24 #include "dbu_app.hrc"
25 #include "dbustrings.hrc"
26 #include "defaultobjectnamecheck.hxx"
27 #include "dlgsave.hxx"
28 #include "UITools.hxx"
29 #include "subcomponentmanager.hxx"
31 #include <com/sun/star/container/XChild.hpp>
32 #include <com/sun/star/container/XContainer.hpp>
33 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
34 #include <com/sun/star/container/XNameAccess.hpp>
35 #include <com/sun/star/container/XNameContainer.hpp>
36 #include <com/sun/star/lang/XEventListener.hpp>
37 #include <com/sun/star/sdb/CommandType.hpp>
38 #include <com/sun/star/sdb/SQLContext.hpp>
39 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
40 #include <com/sun/star/sdbcx/XRename.hpp>
41 #include <com/sun/star/sdb/ErrorCondition.hpp>
42 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
43 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
44 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
45 #include <com/sun/star/ucb/Command.hpp>
46 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
47 #include <com/sun/star/ucb/XCommandProcessor.hpp>
48 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
49 #include <com/sun/star/uno/XNamingService.hpp>
50 #include <com/sun/star/util/XRefreshable.hpp>
52 #include <cppuhelper/exc_hlp.hxx>
53 #include <comphelper/processfactory.hxx>
54 #include <connectivity/dbexception.hxx>
55 #include <connectivity/dbtools.hxx>
56 #include <connectivity/sqlerror.hxx>
57 #include <sfx2/mailmodelapi.hxx>
58 #include <svx/dbaexchange.hxx>
59 #include <toolkit/helper/vclunohelper.hxx>
60 #include <tools/diagnose_ex.h>
61 #include <osl/diagnose.h>
62 #include <unotools/bootstrap.hxx>
63 #include <vcl/layout.hxx>
64 #include <vcl/mnemonic.hxx>
65 #include <vcl/svapp.hxx>
66 #include <vcl/waitobj.hxx>
67 #include <osl/mutex.hxx>
71 using namespace ::dbtools
;
72 using namespace ::connectivity
;
73 using namespace ::svx
;
74 using namespace ::com::sun::star
;
75 using namespace ::com::sun::star::uno
;
76 using namespace ::com::sun::star::awt
;
77 using namespace ::com::sun::star::util
;
78 using namespace ::com::sun::star::frame
;
79 using namespace ::com::sun::star::lang
;
80 using namespace ::com::sun::star::ui::dialogs
;
81 using namespace ::com::sun::star::sdb
;
82 using namespace ::com::sun::star::sdbc
;
83 using namespace ::com::sun::star::sdbcx
;
84 using namespace ::com::sun::star::beans
;
85 using namespace ::com::sun::star::container
;
86 using namespace ::com::sun::star::ucb
;
88 using ::com::sun::star::ui::XContextMenuInterceptor
;
90 namespace DatabaseObject
= ::com::sun::star::sdb::application::DatabaseObject
;
91 namespace ErrorCondition
= ::com::sun::star::sdb::ErrorCondition
;
93 void OApplicationController::convertToView(const OUString
& _sName
)
97 SharedConnection
xConnection( getConnection() );
98 Reference
< XQueriesSupplier
> xSup( xConnection
, UNO_QUERY_THROW
);
99 Reference
< XNameAccess
> xQueries( xSup
->getQueries(), UNO_QUERY_THROW
);
100 Reference
< XPropertySet
> xSourceObject( xQueries
->getByName( _sName
), UNO_QUERY_THROW
);
102 Reference
< XTablesSupplier
> xTablesSup( xConnection
, UNO_QUERY_THROW
);
103 Reference
< XNameAccess
> xTables( xTablesSup
->getTables(), UNO_QUERY_THROW
);
105 Reference
< XDatabaseMetaData
> xMeta
= xConnection
->getMetaData();
107 OUString aName
= OUString(ModuleRes(STR_TBL_TITLE
));
108 aName
= aName
.getToken(0,' ');
109 OUString aDefaultName
= ::dbaui::createDefaultName(xMeta
,xTables
,aName
);
111 DynamicTableOrQueryNameCheck
aNameChecker( xConnection
, CommandType::TABLE
);
112 ScopedVclPtrInstance
< OSaveAsDlg
> aDlg( getView(), CommandType::TABLE
, getORB(), xConnection
, aDefaultName
, aNameChecker
);
113 if ( aDlg
->Execute() == RET_OK
)
115 OUString sName
= aDlg
->getName();
116 OUString sCatalog
= aDlg
->getCatalog();
117 OUString sSchema
= aDlg
->getSchema();
119 ::dbtools::composeTableName( xMeta
, sCatalog
, sSchema
, sName
, false, ::dbtools::EComposeRule::InTableDefinitions
) );
120 Reference
<XPropertySet
> xView
= ::dbaui::createView(sNewName
,xConnection
,xSourceObject
);
122 throw SQLException(OUString(ModuleRes(STR_NO_TABLE_FORMAT_INSIDE
)),*this,OUString( "S1000" ) ,0,Any());
123 getContainer()->elementAdded(E_TABLE
,sNewName
,makeAny(xView
));
126 catch(const SQLException
& )
128 showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
130 catch( const Exception
& )
132 DBG_UNHANDLED_EXCEPTION();
136 void OApplicationController::pasteFormat(SotClipboardFormatId _nFormatId
)
138 if ( _nFormatId
!= SotClipboardFormatId::NONE
)
142 const TransferableDataHelper
& rClipboard
= getViewClipboard();
143 ElementType eType
= getContainer()->getElementType();
144 if ( eType
== E_TABLE
)
146 m_aTableCopyHelper
.pasteTable( _nFormatId
, rClipboard
, getDatabaseName(), ensureConnection() );
149 paste( eType
, ODataAccessObjectTransferable::extractObjectDescriptor( rClipboard
) );
152 catch( const Exception
& )
154 DBG_UNHANDLED_EXCEPTION();
159 void OApplicationController::openDialog( const OUString
& _sServiceName
)
163 SolarMutexGuard aSolarGuard
;
164 ::osl::MutexGuard
aGuard( getMutex() );
165 WaitObject
aWO(getView());
167 Sequence
< Any
> aArgs(3);
168 sal_Int32 nArgPos
= 0;
170 Reference
< css::awt::XWindow
> xWindow
= getTopMostContainerWindow();
173 OSL_ENSURE( getContainer(), "OApplicationController::Construct: have no view!" );
174 if ( getContainer() )
175 xWindow
= VCLUnoHelper::GetInterface(getView()->Window::GetParent());
178 aArgs
[nArgPos
++] <<= PropertyValue( OUString("ParentWindow"),
181 PropertyState_DIRECT_VALUE
);
183 // the initial selection
184 OUString sInitialSelection
;
185 if ( getContainer() )
186 sInitialSelection
= getDatabaseName();
187 if ( !sInitialSelection
.isEmpty() )
189 aArgs
[ nArgPos
++ ] <<= PropertyValue(
190 OUString( "InitialSelection" ), 0,
191 makeAny( sInitialSelection
), PropertyState_DIRECT_VALUE
);
194 SharedConnection
xConnection( getConnection() );
195 if ( xConnection
.is() )
197 aArgs
[ nArgPos
++ ] <<= PropertyValue(
198 PROPERTY_ACTIVE_CONNECTION
, 0,
199 makeAny( xConnection
), PropertyState_DIRECT_VALUE
);
201 aArgs
.realloc( nArgPos
);
204 Reference
< XExecutableDialog
> xAdminDialog
;
206 getORB()->getServiceManager()->createInstanceWithArgumentsAndContext(_sServiceName
, aArgs
, getORB()),
210 if (xAdminDialog
.is())
211 xAdminDialog
->execute();
213 catch( const Exception
& )
215 DBG_UNHANDLED_EXCEPTION();
219 void OApplicationController::refreshTables()
221 if ( getContainer() && getContainer()->getDetailView() )
223 WaitObject
aWO(getView());
224 OSL_ENSURE(getContainer()->getElementType() == E_TABLE
,"Only allowed when the tables container is selected!");
227 Reference
<XRefreshable
> xRefresh(getElements(E_TABLE
),UNO_QUERY
);
231 catch(const Exception
&)
233 OSL_FAIL("Could not refresh tables!");
236 getContainer()->getDetailView()->clearPages(false);
237 getContainer()->getDetailView()->createTablesPage( ensureConnection() );
241 void SAL_CALL
OApplicationController::propertyChange( const PropertyChangeEvent
& evt
) throw (RuntimeException
, std::exception
)
243 SolarMutexGuard aSolarGuard
;
244 ::osl::MutexGuard
aGuard( getMutex() );
245 if ( evt
.PropertyName
== PROPERTY_USER
)
247 m_bNeedToReconnect
= true;
248 InvalidateFeature(SID_DB_APP_STATUS_USERNAME
);
250 else if ( evt
.PropertyName
== PROPERTY_URL
)
252 m_bNeedToReconnect
= true;
253 InvalidateFeature(SID_DB_APP_STATUS_DBNAME
);
254 InvalidateFeature(SID_DB_APP_STATUS_TYPE
);
255 InvalidateFeature(SID_DB_APP_STATUS_HOSTNAME
);
257 else if ( PROPERTY_NAME
== evt
.PropertyName
)
259 const ElementType eType
= getContainer()->getElementType();
260 if ( eType
== E_FORM
|| eType
== E_REPORT
)
262 OUString sOldName
,sNewName
;
263 evt
.OldValue
>>= sOldName
;
264 evt
.NewValue
>>= sNewName
;
266 // if the old name is empty, then this is a newly inserted content. We're notified of it via the
267 // elementInserted method, so there's no need to handle it here.
269 if ( !sOldName
.isEmpty() )
271 Reference
<XChild
> xChild(evt
.Source
,UNO_QUERY
);
274 Reference
<XContent
> xContent(xChild
->getParent(),UNO_QUERY
);
276 sOldName
= xContent
->getIdentifier()->getContentIdentifier() + "/" + sOldName
;
279 getContainer()->elementReplaced( eType
, sOldName
, sNewName
);
285 aEvt
.Source
= m_xModel
;
289 Reference
< XDataSource
> SAL_CALL
OApplicationController::getDataSource() throw (RuntimeException
, std::exception
)
291 ::osl::MutexGuard
aGuard( getMutex() );
292 Reference
< XDataSource
> xDataSource( m_xDataSource
, UNO_QUERY
);
296 Reference
< XWindow
> SAL_CALL
OApplicationController::getApplicationMainWindow() throw (RuntimeException
, std::exception
)
298 ::osl::MutexGuard
aGuard( getMutex() );
299 Reference
< XFrame
> xFrame( getFrame(), UNO_QUERY_THROW
);
300 Reference
< XWindow
> xWindow( xFrame
->getContainerWindow(), UNO_QUERY_THROW
);
304 Sequence
< Reference
< XComponent
> > SAL_CALL
OApplicationController::getSubComponents() throw (RuntimeException
, std::exception
)
306 ::osl::MutexGuard
aGuard( getMutex() );
307 return m_pSubComponentManager
->getSubComponents();
310 Reference
< XConnection
> SAL_CALL
OApplicationController::getActiveConnection() throw (RuntimeException
, std::exception
)
312 ::osl::MutexGuard
aGuard( getMutex() );
313 return m_xDataSourceConnection
.getTyped();
316 sal_Bool SAL_CALL
OApplicationController::isConnected( ) throw (RuntimeException
, std::exception
)
318 ::osl::MutexGuard
aGuard( getMutex() );
319 return m_xDataSourceConnection
.is();
322 void SAL_CALL
OApplicationController::connect( ) throw (SQLException
, RuntimeException
, std::exception
)
324 SQLExceptionInfo aError
;
325 SharedConnection xConnection
= ensureConnection( &aError
);
326 if ( !xConnection
.is() )
328 if ( aError
.isValid() )
331 // no particular error, but nonetheless could not connect -> throw a generic exception
332 OUString
sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE
) );
333 ::dbtools::throwGenericSQLException( sConnectingContext
.replaceFirst( "$name$", getStrippedDatabaseName() ), *this );
337 beans::Pair
< ::sal_Int32
, OUString
> SAL_CALL
OApplicationController::identifySubComponent( const Reference
< XComponent
>& i_rSubComponent
) throw (IllegalArgumentException
, RuntimeException
, std::exception
)
339 ::osl::MutexGuard
aGuard( getMutex() );
341 sal_Int32 nType
= -1;
344 if ( !m_pSubComponentManager
->lookupSubComponent( i_rSubComponent
, sName
, nType
) )
345 throw IllegalArgumentException( OUString(), *this, 1 );
347 if ( nType
== SID_DB_APP_DSRELDESIGN
)
348 // this is somewhat hacky ... we're expected to return a DatabaseObject value. However, there is no such
349 // value for the relation design. /me thinks we should change the API definition here ...
352 return beans::Pair
< ::sal_Int32
, OUString
>( nType
, sName
);
355 sal_Bool SAL_CALL
OApplicationController::closeSubComponents( ) throw (RuntimeException
, std::exception
)
357 SolarMutexGuard aSolarGuard
;
358 ::osl::MutexGuard
aGuard( getMutex() );
359 return m_pSubComponentManager
->closeSubComponents();
364 ElementType
lcl_objectType2ElementType( const sal_Int32 _nObjectType
)
366 ElementType
eType( E_NONE
);
367 switch ( _nObjectType
)
369 case DatabaseObject::TABLE
: eType
= E_TABLE
; break;
370 case DatabaseObject::QUERY
: eType
= E_QUERY
; break;
371 case DatabaseObject::FORM
: eType
= E_FORM
; break;
372 case DatabaseObject::REPORT
: eType
= E_REPORT
; break;
374 OSL_FAIL( "lcl_objectType2ElementType: unsupported object type!" );
375 // this should have been caught earlier
381 void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType
, const ::boost::optional
< OUString
>& i_rObjectName
)
383 // ensure we're connected
384 if ( !isConnected() )
386 SQLError
aError( getORB() );
387 aError
.raiseException( ErrorCondition::DB_NOT_CONNECTED
, *this );
390 // ensure a proper object type
391 if ( ( _nObjectType
!= DatabaseObject::TABLE
)
392 && ( _nObjectType
!= DatabaseObject::QUERY
)
393 && ( _nObjectType
!= DatabaseObject::FORM
)
394 && ( _nObjectType
!= DatabaseObject::REPORT
)
396 throw IllegalArgumentException( OUString(), *this, 1 );
398 if ( !i_rObjectName
)
401 // ensure an existing object
402 Reference
< XNameAccess
> xContainer( getElements( lcl_objectType2ElementType( _nObjectType
) ) );
403 if ( !xContainer
.is() )
404 // all possible reasons for this (e.g. not being connected currently) should
405 // have been handled before
406 throw RuntimeException( OUString(), *this );
408 bool bExistentObject
= false;
409 switch ( _nObjectType
)
411 case DatabaseObject::TABLE
:
412 case DatabaseObject::QUERY
:
413 bExistentObject
= xContainer
->hasByName( *i_rObjectName
);
415 case DatabaseObject::FORM
:
416 case DatabaseObject::REPORT
:
418 Reference
< XHierarchicalNameAccess
> xHierarchy( xContainer
, UNO_QUERY_THROW
);
419 bExistentObject
= xHierarchy
->hasByHierarchicalName( *i_rObjectName
);
424 if ( !bExistentObject
)
425 throw NoSuchElementException( *i_rObjectName
, *this );
428 Reference
< XComponent
> SAL_CALL
OApplicationController::loadComponent( ::sal_Int32 ObjectType
,
429 const OUString
& ObjectName
, sal_Bool ForEditing
) throw (IllegalArgumentException
, NoSuchElementException
, SQLException
, RuntimeException
, std::exception
)
431 return loadComponentWithArguments( ObjectType
, ObjectName
, ForEditing
, Sequence
< PropertyValue
>() );
434 Reference
< XComponent
> SAL_CALL
OApplicationController::loadComponentWithArguments( ::sal_Int32 ObjectType
,
435 const OUString
& ObjectName
, sal_Bool ForEditing
, const Sequence
< PropertyValue
>& Arguments
) throw (IllegalArgumentException
, NoSuchElementException
, SQLException
, RuntimeException
, std::exception
)
437 SolarMutexGuard aSolarGuard
;
438 ::osl::MutexGuard
aGuard( getMutex() );
440 impl_validateObjectTypeAndName_throw( ObjectType
, ObjectName
);
442 Reference
< XComponent
> xComponent( openElementWithArguments(
444 lcl_objectType2ElementType( ObjectType
),
445 ForEditing
? E_OPEN_DESIGN
: E_OPEN_NORMAL
,
446 ForEditing
? SID_DB_APP_EDIT
: SID_DB_APP_OPEN
,
447 ::comphelper::NamedValueCollection( Arguments
)
453 Reference
< XComponent
> SAL_CALL
OApplicationController::createComponent( ::sal_Int32 i_nObjectType
, Reference
< XComponent
>& o_DocumentDefinition
) throw (IllegalArgumentException
, SQLException
, RuntimeException
, std::exception
)
455 return createComponentWithArguments( i_nObjectType
, Sequence
< PropertyValue
>(), o_DocumentDefinition
);
458 Reference
< XComponent
> SAL_CALL
OApplicationController::createComponentWithArguments( ::sal_Int32 i_nObjectType
, const Sequence
< PropertyValue
>& i_rArguments
, Reference
< XComponent
>& o_DocumentDefinition
) throw (IllegalArgumentException
, NoSuchElementException
, SQLException
, RuntimeException
, std::exception
)
460 SolarMutexGuard aSolarGuard
;
461 ::osl::MutexGuard
aGuard( getMutex() );
463 impl_validateObjectTypeAndName_throw( i_nObjectType
, ::boost::optional
< OUString
>() );
465 Reference
< XComponent
> xComponent( newElement(
466 lcl_objectType2ElementType( i_nObjectType
),
467 ::comphelper::NamedValueCollection( i_rArguments
),
474 void SAL_CALL
OApplicationController::registerContextMenuInterceptor( const Reference
< XContextMenuInterceptor
>& Interceptor
) throw (RuntimeException
, std::exception
)
476 if ( Interceptor
.is() )
477 m_aContextMenuInterceptors
.addInterface( Interceptor
);
480 void SAL_CALL
OApplicationController::releaseContextMenuInterceptor( const Reference
< XContextMenuInterceptor
>& Interceptor
) throw (RuntimeException
, std::exception
)
482 m_aContextMenuInterceptors
.removeInterface( Interceptor
);
485 void OApplicationController::previewChanged( sal_Int32 _nMode
)
487 SolarMutexGuard aSolarGuard
;
488 ::osl::MutexGuard
aGuard( getMutex() );
490 if ( m_xDataSource
.is() && !isDataSourceReadOnly() )
494 ::comphelper::NamedValueCollection
aLayoutInfo( m_xDataSource
->getPropertyValue( PROPERTY_LAYOUTINFORMATION
) );
495 sal_Int32 nOldMode
= aLayoutInfo
.getOrDefault( "Preview", _nMode
);
496 if ( nOldMode
!= _nMode
)
498 aLayoutInfo
.put( "Preview", _nMode
);
499 m_xDataSource
->setPropertyValue( PROPERTY_LAYOUTINFORMATION
, makeAny( aLayoutInfo
.getPropertyValues() ) );
502 catch ( const Exception
& )
504 DBG_UNHANDLED_EXCEPTION();
507 InvalidateFeature(SID_DB_APP_DISABLE_PREVIEW
);
508 InvalidateFeature(SID_DB_APP_VIEW_DOCINFO_PREVIEW
);
509 InvalidateFeature(SID_DB_APP_VIEW_DOC_PREVIEW
);
512 void OApplicationController::askToReconnect()
514 if ( m_bNeedToReconnect
)
516 m_bNeedToReconnect
= false;
518 if ( !m_pSubComponentManager
->empty() )
520 ScopedVclPtrInstance
< MessageDialog
> aQry(getView(), ModuleRes(STR_QUERY_CLOSEDOCUMENTS
), VclMessageType::Question
, VCL_BUTTONS_YES_NO
);
521 switch (aQry
->Execute())
524 closeSubComponents();
533 ElementType eType
= getContainer()->getElementType();
535 getContainer()->getDetailView()->clearPages(false);
536 getContainer()->selectContainer(E_NONE
); // invalidate the old selection
537 m_eCurrentType
= E_NONE
;
538 getContainer()->selectContainer(eType
); // reselect the current one again
543 OUString
OApplicationController::getDatabaseName() const
545 OUString sDatabaseName
;
548 if ( m_xDataSource
.is() )
550 OSL_VERIFY( m_xDataSource
->getPropertyValue( PROPERTY_NAME
) >>= sDatabaseName
);
553 catch ( const Exception
& )
555 DBG_UNHANDLED_EXCEPTION();
557 return sDatabaseName
;
560 OUString
OApplicationController::getStrippedDatabaseName() const
562 OUString sDatabaseName
;
563 return ::dbaui::getStrippedDatabaseName( m_xDataSource
, sDatabaseName
);
566 void OApplicationController::onDocumentOpened( const OUString
& _rName
, const sal_Int32 _nType
,
567 const ElementOpenMode _eMode
, const Reference
< XComponent
>& _xDocument
, const Reference
< XComponent
>& _rxDefinition
)
569 if ( !_xDocument
.is() )
574 OSL_ENSURE( _xDocument
.is(), "OApplicationController::onDocumentOpened: is there any *valid* scenario where this fails?" );
575 m_pSubComponentManager
->onSubComponentOpened( _rName
, _nType
, _eMode
, _xDocument
.is() ? _xDocument
: _rxDefinition
);
577 if ( _rxDefinition
.is() )
579 Reference
< XPropertySet
> xProp( _rxDefinition
, UNO_QUERY_THROW
);
580 Reference
< XPropertySetInfo
> xPSI( xProp
->getPropertySetInfo(), UNO_SET_THROW
);
581 xProp
->addPropertyChangeListener( PROPERTY_NAME
, static_cast< XPropertyChangeListener
* >( this ) );
584 catch( const Exception
& )
586 DBG_UNHANDLED_EXCEPTION();
590 bool OApplicationController::insertHierachyElement(ElementType _eType
, const OUString
& _sParentFolder
, bool _bCollection
, const Reference
<XContent
>& _xContent
, bool _bMove
)
592 Reference
<XHierarchicalNameContainer
> xNames(getElements(_eType
), UNO_QUERY
);
593 return dbaui::insertHierachyElement(getView()
603 bool OApplicationController::isRenameDeleteAllowed(ElementType _eType
, bool _bDelete
) const
605 ElementType eType
= getContainer()->getElementType();
606 bool bEnabled
= !isDataSourceReadOnly() && eType
== _eType
;
610 if ( E_TABLE
== eType
)
611 bEnabled
= !isConnectionReadOnly() && getContainer()->isALeafSelected();
613 bool bCompareRes
= false;
615 bCompareRes
= getContainer()->getSelectionCount() > 0;
618 bCompareRes
= getContainer()->getSelectionCount() == 1;
619 if ( bEnabled
&& bCompareRes
&& E_TABLE
== eType
)
621 ::std::vector
< OUString
> aList
;
622 getSelectionElementNames(aList
);
626 Reference
< XNameAccess
> xContainer
= const_cast<OApplicationController
*>(this)->getElements(eType
);
627 bEnabled
= (xContainer
.is() && xContainer
->hasByName(*aList
.begin()));
629 bEnabled
= Reference
<XRename
>(xContainer
->getByName(*aList
.begin()),UNO_QUERY
).is();
638 bEnabled
= bEnabled
&& bCompareRes
;
643 void OApplicationController::onLoadedMenu(const Reference
< css::frame::XLayoutManager
>& _xLayoutManager
)
646 if ( _xLayoutManager
.is() )
648 static const char s_sStatusbar
[] = "private:resource/statusbar/statusbar";
649 _xLayoutManager
->createElement( s_sStatusbar
);
650 _xLayoutManager
->requestElement( s_sStatusbar
);
652 if ( getContainer() )
654 // we need to share the "mnemonic space":
655 MnemonicGenerator aMnemonicGenerator
;
656 // - the menu already has mnemonics
657 SystemWindow
* pSystemWindow
= getContainer()->GetSystemWindow();
658 MenuBar
* pMenu
= pSystemWindow
? pSystemWindow
->GetMenuBar() : nullptr;
661 sal_uInt16 nMenuItems
= pMenu
->GetItemCount();
662 for ( sal_uInt16 i
= 0; i
< nMenuItems
; ++i
)
663 aMnemonicGenerator
.RegisterMnemonic( pMenu
->GetItemText( pMenu
->GetItemId( i
) ) );
665 // - the icons should use automatic ones
666 getContainer()->createIconAutoMnemonics( aMnemonicGenerator
);
667 // - as well as the entries in the task pane
668 getContainer()->setTaskExternalMnemonics( aMnemonicGenerator
);
671 Execute( SID_DB_APP_VIEW_FORMS
, Sequence
< PropertyValue
>() );
676 void OApplicationController::doAction(sal_uInt16 _nId
, const ElementOpenMode _eOpenMode
)
678 ::std::vector
< OUString
> aList
;
679 getSelectionElementNames(aList
);
680 ElementType eType
= getContainer()->getElementType();
681 ::comphelper::NamedValueCollection aArguments
;
682 ElementOpenMode eOpenMode
= _eOpenMode
;
683 if ( eType
== E_REPORT
&& E_OPEN_FOR_MAIL
== _eOpenMode
)
685 aArguments
.put("Hidden",true);
686 eOpenMode
= E_OPEN_NORMAL
;
689 ::std::vector
< ::std::pair
< OUString
,Reference
< XModel
> > > aComponents
;
690 ::std::vector
< OUString
>::const_iterator aEnd
= aList
.end();
691 for (::std::vector
< OUString
>::const_iterator aIter
= aList
.begin(); aIter
!= aEnd
; ++aIter
)
693 if ( SID_DB_APP_CONVERTTOVIEW
== _nId
)
694 convertToView(*aIter
);
697 Reference
< XModel
> xModel( openElementWithArguments( *aIter
, eType
, eOpenMode
, _nId
,aArguments
), UNO_QUERY
);
698 aComponents
.push_back( ::std::pair
< OUString
, Reference
< XModel
> >( *aIter
, xModel
) );
702 // special handling for mail, if more than one document is selected attach them all
703 if ( _eOpenMode
== E_OPEN_FOR_MAIL
)
706 ::std::vector
< ::std::pair
< OUString
,Reference
< XModel
> > >::const_iterator componentIter
= aComponents
.begin();
707 ::std::vector
< ::std::pair
< OUString
,Reference
< XModel
> > >::const_iterator componentEnd
= aComponents
.end();
708 OUString aDocTypeString
;
709 SfxMailModel aSendMail
;
710 SfxMailModel::SendMailResult eResult
= SfxMailModel::SEND_MAIL_OK
;
711 for (; componentIter
!= componentEnd
&& SfxMailModel::SEND_MAIL_OK
== eResult
; ++componentIter
)
715 Reference
< XModel
> xModel(componentIter
->second
,UNO_QUERY
);
717 // Send document as e-Mail using stored/default type
718 eResult
= aSendMail
.AttachDocument(aDocTypeString
,xModel
,componentIter
->first
);
719 ::comphelper::disposeComponent(xModel
);
721 catch(const Exception
&)
723 DBG_UNHANDLED_EXCEPTION();
726 if ( !aSendMail
.IsEmpty() )
727 aSendMail
.Send( getFrame() );
731 ElementType
OApplicationController::getElementType(const Reference
< XContainer
>& _xContainer
)
733 ElementType eRet
= E_NONE
;
734 Reference
<XServiceInfo
> xServiceInfo(_xContainer
,UNO_QUERY
);
735 if ( xServiceInfo
.is() )
737 if ( xServiceInfo
->supportsService(SERVICE_SDBCX_TABLES
) )
739 else if ( xServiceInfo
->supportsService(SERVICE_NAME_FORM_COLLECTION
) )
741 else if ( xServiceInfo
->supportsService(SERVICE_NAME_REPORT_COLLECTION
) )
751 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */