1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AppControllerGen.cxx,v $
10 * $Revision: 1.32.6.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "AppController.hxx"
35 #include "AppDetailView.hxx"
36 #include "AppView.hxx"
37 #include "dbaccess_slotid.hrc"
38 #include "dbu_app.hrc"
39 #include "dbustrings.hrc"
40 #include "defaultobjectnamecheck.hxx"
41 #include "dlgsave.hxx"
42 #include "UITools.hxx"
43 #include "subcomponentmanager.hxx"
45 /** === begin UNO includes === **/
46 #include <com/sun/star/container/XChild.hpp>
47 #include <com/sun/star/container/XContainer.hpp>
48 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
49 #include <com/sun/star/container/XNameAccess.hpp>
50 #include <com/sun/star/container/XNameContainer.hpp>
51 #include <com/sun/star/lang/XEventListener.hpp>
52 #include <com/sun/star/sdb/CommandType.hpp>
53 #include <com/sun/star/sdb/SQLContext.hpp>
54 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
55 #include <com/sun/star/sdbcx/XRename.hpp>
56 #include <com/sun/star/sdb/ErrorCondition.hpp>
57 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
58 #include <com/sun/star/sdb/SQLContext.hpp>
59 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
60 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
61 #include <com/sun/star/ucb/Command.hpp>
62 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
63 #include <com/sun/star/ucb/XCommandProcessor.hpp>
64 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
65 #include <com/sun/star/uno/XNamingService.hpp>
66 #include <com/sun/star/util/XCloseable.hpp>
67 #include <com/sun/star/util/XRefreshable.hpp>
68 #include <com/sun/star/lang/XEventListener.hpp>
69 /** === end UNO includes === **/
71 #include <cppuhelper/exc_hlp.hxx>
72 #include <connectivity/dbexception.hxx>
73 #include <connectivity/dbtools.hxx>
74 #include <connectivity/sqlerror.hxx>
75 #include <connectivity/dbexception.hxx>
76 #include <sfx2/mailmodelapi.hxx>
77 #include <svx/dbaexchange.hxx>
78 #include <toolkit/unohlp.hxx>
79 #include <tools/diagnose_ex.h>
80 #include <tools/urlobj.hxx>
81 #include <unotools/bootstrap.hxx>
82 #include <vcl/mnemonic.hxx>
83 #include <vcl/svapp.hxx>
84 #include <vcl/waitobj.hxx>
85 #include <vos/mutex.hxx>
87 //........................................................................
90 using namespace ::dbtools
;
91 using namespace ::connectivity
;
92 using namespace ::svx
;
93 using namespace ::com::sun::star::uno
;
94 using namespace ::com::sun::star::awt
;
95 using namespace ::com::sun::star::util
;
96 using namespace ::com::sun::star::frame
;
97 using namespace ::com::sun::star::lang
;
98 using namespace ::com::sun::star::ui::dialogs
;
99 using namespace ::com::sun::star::sdb
;
100 using namespace ::com::sun::star::sdbc
;
101 using namespace ::com::sun::star::sdbcx
;
102 using namespace ::com::sun::star::beans
;
103 using namespace ::com::sun::star::container
;
104 using namespace ::com::sun::star::ucb
;
106 /** === begin UNO using === **/
107 using ::com::sun::star::util::XCloseable
;
108 using ::com::sun::star::ui::XContextMenuInterceptor
;
109 /** === end UNO using === **/
110 namespace DatabaseObject
= ::com::sun::star::sdb::application::DatabaseObject
;
111 namespace ErrorCondition
= ::com::sun::star::sdb::ErrorCondition
;
113 //........................................................................
114 // -----------------------------------------------------------------------------
116 class CloseChecker
: public ::cppu::WeakImplHelper1
< com::sun::star::lang::XEventListener
>
126 virtual ~CloseChecker()
135 // interface XEventListener
136 virtual void SAL_CALL
disposing( const EventObject
& /*Source*/ ) throw( RuntimeException
)
142 // -----------------------------------------------------------------------------
143 void OApplicationController::convertToView(const ::rtl::OUString
& _sName
)
147 SharedConnection
xConnection( getConnection() );
148 Reference
< XQueriesSupplier
> xSup( xConnection
, UNO_QUERY_THROW
);
149 Reference
< XNameAccess
> xQueries( xSup
->getQueries(), UNO_QUERY_THROW
);
150 Reference
< XPropertySet
> xSourceObject( xQueries
->getByName( _sName
), UNO_QUERY_THROW
);
152 Reference
< XTablesSupplier
> xTablesSup( xConnection
, UNO_QUERY_THROW
);
153 Reference
< XNameAccess
> xTables( xTablesSup
->getTables(), UNO_QUERY_THROW
);
155 Reference
< XDatabaseMetaData
> xMeta
= xConnection
->getMetaData();
157 String aName
= String(ModuleRes(STR_TBL_TITLE
));
158 aName
= aName
.GetToken(0,' ');
159 String aDefaultName
= ::dbaui::createDefaultName(xMeta
,xTables
,aName
);
161 DynamicTableOrQueryNameCheck
aNameChecker( xConnection
, CommandType::TABLE
);
162 OSaveAsDlg
aDlg( getView(), CommandType::TABLE
, getORB(), xConnection
, aDefaultName
, aNameChecker
);
163 if ( aDlg
.Execute() == RET_OK
)
165 ::rtl::OUString sName
= aDlg
.getName();
166 ::rtl::OUString sCatalog
= aDlg
.getCatalog();
167 ::rtl::OUString sSchema
= aDlg
.getSchema();
168 ::rtl::OUString
sNewName(
169 ::dbtools::composeTableName( xMeta
, sCatalog
, sSchema
, sName
, sal_False
, ::dbtools::eInTableDefinitions
) );
170 Reference
<XPropertySet
> xView
= ::dbaui::createView(sNewName
,xConnection
,xSourceObject
);
172 throw SQLException(String(ModuleRes(STR_NO_TABLE_FORMAT_INSIDE
)),*this,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")) ,0,Any());
173 getContainer()->elementAdded(E_TABLE
,sNewName
,makeAny(xView
));
176 catch(const SQLException
& )
178 showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
180 catch( const Exception
& )
182 DBG_UNHANDLED_EXCEPTION();
185 // -----------------------------------------------------------------------------
186 void OApplicationController::pasteFormat(sal_uInt32 _nFormatId
)
192 const TransferableDataHelper
& rClipboard
= getViewClipboard();
193 ElementType eType
= getContainer()->getElementType();
194 if ( eType
== E_TABLE
)
196 m_aTableCopyHelper
.pasteTable( _nFormatId
, rClipboard
, getDatabaseName(), ensureConnection() );
199 paste( eType
, ODataAccessObjectTransferable::extractObjectDescriptor( rClipboard
) );
202 catch( const Exception
& )
204 DBG_UNHANDLED_EXCEPTION();
208 // -----------------------------------------------------------------------------
209 void OApplicationController::openDataSourceAdminDialog()
211 openDialog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.DatasourceAdministrationDialog" ) ) );
214 // -----------------------------------------------------------------------------
215 void OApplicationController::openDialog( const ::rtl::OUString
& _sServiceName
)
219 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
220 ::osl::MutexGuard
aGuard( getMutex() );
221 WaitObject
aWO(getView());
223 Sequence
< Any
> aArgs(3);
224 sal_Int32 nArgPos
= 0;
226 Reference
< ::com::sun::star::awt::XWindow
> xWindow
= getTopMostContainerWindow();
229 DBG_ASSERT( getContainer(), "OApplicationController::Construct: have no view!" );
230 if ( getContainer() )
231 xWindow
= VCLUnoHelper::GetInterface(getView()->Window::GetParent());
234 aArgs
[nArgPos
++] <<= PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentWindow")),
237 PropertyState_DIRECT_VALUE
);
239 // the initial selection
240 ::rtl::OUString sInitialSelection
;
241 if ( getContainer() )
242 sInitialSelection
= getDatabaseName();
243 if ( sInitialSelection
.getLength() )
245 aArgs
[ nArgPos
++ ] <<= PropertyValue(
246 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InitialSelection" ) ), 0,
247 makeAny( sInitialSelection
), PropertyState_DIRECT_VALUE
);
250 SharedConnection
xConnection( getConnection() );
251 if ( xConnection
.is() )
253 aArgs
[ nArgPos
++ ] <<= PropertyValue(
254 PROPERTY_ACTIVE_CONNECTION
, 0,
255 makeAny( xConnection
), PropertyState_DIRECT_VALUE
);
257 aArgs
.realloc( nArgPos
);
260 Reference
< XExecutableDialog
> xAdminDialog
;
261 xAdminDialog
= Reference
< XExecutableDialog
>(
262 getORB()->createInstanceWithArguments(_sServiceName
,aArgs
), UNO_QUERY
);
265 if (xAdminDialog
.is())
266 xAdminDialog
->execute();
268 catch( const Exception
& )
270 DBG_UNHANDLED_EXCEPTION();
273 // -----------------------------------------------------------------------------
274 void OApplicationController::openTableFilterDialog()
276 openDialog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.TableFilterDialog" ) ) );
279 // -----------------------------------------------------------------------------
280 void OApplicationController::refreshTables()
282 if ( getContainer() && getContainer()->getDetailView() )
284 WaitObject
aWO(getView());
285 OSL_ENSURE(getContainer()->getElementType() == E_TABLE
,"Only allowed when the tables container is selected!");
288 Reference
<XRefreshable
> xRefresh(getElements(E_TABLE
),UNO_QUERY
);
292 catch(const Exception
&)
294 OSL_ENSURE(0,"Could not refresh tables!");
297 getContainer()->getDetailView()->clearPages(sal_False
);
298 getContainer()->getDetailView()->createTablesPage( ensureConnection() );
301 // -----------------------------------------------------------------------------
302 void OApplicationController::openDirectSQLDialog()
304 openDialog( SERVICE_SDB_DIRECTSQLDIALOG
);
306 // -----------------------------------------------------------------------------
307 void SAL_CALL
OApplicationController::propertyChange( const PropertyChangeEvent
& evt
) throw (RuntimeException
)
309 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
310 ::osl::MutexGuard
aGuard( getMutex() );
311 if ( evt
.PropertyName
== PROPERTY_USER
)
313 m_bNeedToReconnect
= sal_True
;
314 InvalidateFeature(SID_DB_APP_STATUS_USERNAME
);
316 else if ( evt
.PropertyName
== PROPERTY_URL
)
318 m_bNeedToReconnect
= sal_True
;
319 InvalidateFeature(SID_DB_APP_STATUS_DBNAME
);
320 InvalidateFeature(SID_DB_APP_STATUS_TYPE
);
321 InvalidateFeature(SID_DB_APP_STATUS_HOSTNAME
);
323 else if ( PROPERTY_NAME
== evt
.PropertyName
)
325 const ElementType eType
= getContainer()->getElementType();
326 if ( eType
== E_FORM
|| eType
== E_REPORT
)
328 ::rtl::OUString sOldName
,sNewName
;
329 evt
.OldValue
>>= sOldName
;
330 evt
.NewValue
>>= sNewName
;
331 Reference
<XChild
> xChild(evt
.Source
,UNO_QUERY
);
334 Reference
<XContent
> xContent(xChild
->getParent(),UNO_QUERY
);
336 sOldName
= xContent
->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sOldName
;
339 getContainer()->elementReplaced( eType
, sOldName
, sNewName
);
344 aEvt
.Source
= m_xModel
;
348 // -----------------------------------------------------------------------------
349 Reference
< XDataSource
> SAL_CALL
OApplicationController::getDataSource() throw (RuntimeException
)
351 ::osl::MutexGuard
aGuard( getMutex() );
352 Reference
< XDataSource
> xDataSource( m_xDataSource
, UNO_QUERY
);
356 // -----------------------------------------------------------------------------
357 Reference
< XWindow
> SAL_CALL
OApplicationController::getApplicationMainWindow() throw (RuntimeException
)
359 ::osl::MutexGuard
aGuard( getMutex() );
360 Reference
< XFrame
> xFrame( getFrame(), UNO_QUERY_THROW
);
361 Reference
< XWindow
> xWindow( xFrame
->getContainerWindow(), UNO_QUERY_THROW
);
365 // -----------------------------------------------------------------------------
366 Sequence
< Reference
< XComponent
> > SAL_CALL
OApplicationController::getSubComponents() throw (RuntimeException
)
368 return m_pSubComponentManager
->getSubComponents();
371 // -----------------------------------------------------------------------------
372 Reference
< XConnection
> SAL_CALL
OApplicationController::getActiveConnection() throw (RuntimeException
)
374 ::osl::MutexGuard
aGuard( getMutex() );
375 return m_xDataSourceConnection
.getTyped();
378 // -----------------------------------------------------------------------------
379 ::sal_Bool SAL_CALL
OApplicationController::isConnected( ) throw (RuntimeException
)
381 ::osl::MutexGuard
aGuard( getMutex() );
382 return m_xDataSourceConnection
.is();
385 // -----------------------------------------------------------------------------
386 void SAL_CALL
OApplicationController::connect( ) throw (SQLException
, RuntimeException
)
388 SQLExceptionInfo aError
;
389 SharedConnection xConnection
= ensureConnection( &aError
);
390 if ( !xConnection
.is() )
392 if ( aError
.isValid() )
395 // no particular error, but nonetheless could not connect -> throw a generic exception
396 String
sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE
) );
397 sConnectingContext
.SearchAndReplaceAscii( "$name$", getStrippedDatabaseName() );
398 ::dbtools::throwGenericSQLException( sConnectingContext
, *this );
402 // -----------------------------------------------------------------------------
403 ::sal_Bool SAL_CALL
OApplicationController::closeSubComponents( ) throw (RuntimeException
)
405 return m_pSubComponentManager
->closeSubComponents();
409 // -----------------------------------------------------------------------------
412 ElementType
lcl_objectType2ElementType( const sal_Int32 _nObjectType
)
414 ElementType
eType( E_NONE
);
415 switch ( _nObjectType
)
417 case DatabaseObject::TABLE
: eType
= E_TABLE
; break;
418 case DatabaseObject::QUERY
: eType
= E_QUERY
; break;
419 case DatabaseObject::FORM
: eType
= E_FORM
; break;
420 case DatabaseObject::REPORT
: eType
= E_REPORT
; break;
422 OSL_ENSURE( false, "lcl_objectType2ElementType: unsupported object type!" );
423 // this should have been caught earlier
429 // -----------------------------------------------------------------------------
430 void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType
, const ::rtl::OUString
& _rObjectName
)
432 // ensure we're connected
433 if ( !isConnected() )
435 SQLError
aError( getORB() );
436 aError
.raiseException( ErrorCondition::DB_NOT_CONNECTED
, *this );
439 // ensure a proper object type
440 if ( ( _nObjectType
!= DatabaseObject::TABLE
)
441 && ( _nObjectType
!= DatabaseObject::QUERY
)
442 && ( _nObjectType
!= DatabaseObject::FORM
)
443 && ( _nObjectType
!= DatabaseObject::REPORT
)
445 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
447 // ensure an existing object
448 Reference
< XNameAccess
> xContainer( getElements( lcl_objectType2ElementType( _nObjectType
) ) );
449 if ( !xContainer
.is() )
450 // all possible reasons for this (e.g. not being connected currently) should
451 // have been handled before
452 throw RuntimeException( ::rtl::OUString(), *this );
454 bool bExistentObject
= false;
455 switch ( _nObjectType
)
457 case DatabaseObject::TABLE
:
458 case DatabaseObject::QUERY
:
459 bExistentObject
= xContainer
->hasByName( _rObjectName
);
461 case DatabaseObject::FORM
:
462 case DatabaseObject::REPORT
:
464 Reference
< XHierarchicalNameAccess
> xHierarchy( xContainer
, UNO_QUERY_THROW
);
465 bExistentObject
= xHierarchy
->hasByHierarchicalName( _rObjectName
);
470 if ( !bExistentObject
)
471 throw NoSuchElementException( _rObjectName
, *this );
474 // -----------------------------------------------------------------------------
475 Reference
< XComponent
> SAL_CALL
OApplicationController::loadComponent( ::sal_Int32 _ObjectType
,
476 const ::rtl::OUString
& _ObjectName
, ::sal_Bool _ForEditing
) throw (IllegalArgumentException
, NoSuchElementException
, SQLException
, RuntimeException
)
478 return loadComponentWithArguments( _ObjectType
, _ObjectName
, _ForEditing
, Sequence
< PropertyValue
>() );
481 // -----------------------------------------------------------------------------
482 Reference
< XComponent
> SAL_CALL
OApplicationController::loadComponentWithArguments( ::sal_Int32 _ObjectType
,
483 const ::rtl::OUString
& _ObjectName
, ::sal_Bool _ForEditing
, const Sequence
< PropertyValue
>& _Arguments
) throw (IllegalArgumentException
, NoSuchElementException
, SQLException
, RuntimeException
)
485 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
486 ::osl::MutexGuard
aGuard( getMutex() );
488 impl_validateObjectTypeAndName_throw( _ObjectType
, _ObjectName
);
490 Reference
< XComponent
> xComponent( openElementWithArguments(
492 lcl_objectType2ElementType( _ObjectType
),
493 _ForEditing
? E_OPEN_DESIGN
: E_OPEN_NORMAL
,
494 _ForEditing
? SID_DB_APP_EDIT
: SID_DB_APP_OPEN
,
495 ::comphelper::NamedValueCollection( _Arguments
)
501 // -----------------------------------------------------------------------------
502 void SAL_CALL
OApplicationController::registerContextMenuInterceptor( const Reference
< XContextMenuInterceptor
>& _Interceptor
) throw (RuntimeException
)
504 if ( _Interceptor
.is() )
505 m_aContextMenuInterceptors
.addInterface( _Interceptor
);
508 // -----------------------------------------------------------------------------
509 void SAL_CALL
OApplicationController::releaseContextMenuInterceptor( const Reference
< XContextMenuInterceptor
>& _Interceptor
) throw (RuntimeException
)
511 m_aContextMenuInterceptors
.removeInterface( _Interceptor
);
514 // -----------------------------------------------------------------------------
515 void OApplicationController::previewChanged( sal_Int32 _nMode
)
517 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
518 ::osl::MutexGuard
aGuard( getMutex() );
520 if ( m_xDataSource
.is() && !isDataSourceReadOnly() )
524 ::comphelper::NamedValueCollection
aLayoutInfo( m_xDataSource
->getPropertyValue( PROPERTY_LAYOUTINFORMATION
) );
525 sal_Int32 nOldMode
= aLayoutInfo
.getOrDefault( "Preview", _nMode
);
526 if ( nOldMode
!= _nMode
)
528 aLayoutInfo
.put( "Preview", _nMode
);
529 m_xDataSource
->setPropertyValue( PROPERTY_LAYOUTINFORMATION
, makeAny( aLayoutInfo
.getPropertyValues() ) );
532 catch ( const Exception
& )
534 DBG_UNHANDLED_EXCEPTION();
537 InvalidateFeature(SID_DB_APP_DISABLE_PREVIEW
);
538 InvalidateFeature(SID_DB_APP_VIEW_DOCINFO_PREVIEW
);
539 InvalidateFeature(SID_DB_APP_VIEW_DOC_PREVIEW
);
541 // -----------------------------------------------------------------------------
542 //void OApplicationController::updateTitle()
544 // ::rtl::OUString sName = getStrippedDatabaseName();
546 // String sTitle = String(ModuleRes(STR_APP_TITLE));
547 // sName = sName + sTitle;
549 // ::rtl::OUString aDefault;
550 // sName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ["));
551 // sName += utl::Bootstrap::getBuildIdData( aDefault );
552 // sName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("]"));
555 // -----------------------------------------------------------------------------
556 void OApplicationController::askToReconnect()
558 if ( m_bNeedToReconnect
)
560 m_bNeedToReconnect
= sal_False
;
561 sal_Bool bClear
= sal_True
;
562 if ( !m_pSubComponentManager
->empty() )
564 QueryBox
aQry(getView(), ModuleRes(APP_CLOSEDOCUMENTS
));
565 switch (aQry
.Execute())
568 closeSubComponents();
577 ElementType eType
= getContainer()->getElementType();
579 getContainer()->getDetailView()->clearPages(sal_False
);
580 getContainer()->selectContainer(E_NONE
); // invalidate the old selection
581 m_eCurrentType
= E_NONE
;
582 getContainer()->selectContainer(eType
); // reselect the current one again
587 // -----------------------------------------------------------------------------
588 ::rtl::OUString
OApplicationController::getDatabaseName() const
590 ::rtl::OUString sDatabaseName
;
593 if ( m_xDataSource
.is() )
595 OSL_VERIFY( m_xDataSource
->getPropertyValue( PROPERTY_NAME
) >>= sDatabaseName
);
598 catch ( const Exception
& )
600 DBG_UNHANDLED_EXCEPTION();
602 return sDatabaseName
;
605 // -----------------------------------------------------------------------------
606 ::rtl::OUString
OApplicationController::getStrippedDatabaseName() const
608 ::rtl::OUString sDatabaseName
;
609 return ::dbaui::getStrippedDatabaseName( m_xDataSource
, sDatabaseName
);
612 // -----------------------------------------------------------------------------
613 void OApplicationController::onDocumentOpened( const ::rtl::OUString
& _rName
, const sal_Int32 _nType
,
614 const ElementOpenMode _eMode
, const Reference
< XComponent
>& _xDocument
, const Reference
< XComponent
>& _rxDefinition
)
616 OSL_PRECOND( _xDocument
.is(), "OApplicationController::onDocumentOpened: illegal document!" );
617 if ( !_xDocument
.is() )
622 m_pSubComponentManager
->onSubComponentOpened( _rName
, _nType
, _eMode
, _rxDefinition
.is() ? _rxDefinition
: _xDocument
);
624 if ( _rxDefinition
.is() )
626 Reference
< XPropertySet
> xProp( _rxDefinition
, UNO_QUERY_THROW
);
627 Reference
< XPropertySetInfo
> xPSI( xProp
->getPropertySetInfo(), UNO_SET_THROW
);
628 xProp
->addPropertyChangeListener( PROPERTY_NAME
, static_cast< XPropertyChangeListener
* >( this ) );
631 catch( const Exception
& )
633 DBG_UNHANDLED_EXCEPTION();
636 // -----------------------------------------------------------------------------
637 sal_Bool
OApplicationController::insertHierachyElement(ElementType _eType
,const String
& _sParentFolder
,sal_Bool _bCollection
,const Reference
<XContent
>& _xContent
,sal_Bool _bMove
)
639 Reference
<XHierarchicalNameContainer
> xNames(getElements(_eType
), UNO_QUERY
);
640 return dbaui::insertHierachyElement(getView()
649 // -----------------------------------------------------------------------------
650 sal_Bool
OApplicationController::isRenameDeleteAllowed(ElementType _eType
,sal_Bool _bDelete
) const
652 ElementType eType
= getContainer()->getElementType();
653 sal_Bool bEnabled
= !isDataSourceReadOnly() && eType
== _eType
;
657 if ( E_TABLE
== eType
)
658 bEnabled
= !isConnectionReadOnly() && getContainer()->isALeafSelected();
660 sal_Bool bCompareRes
= sal_False
;
662 bCompareRes
= getContainer()->getSelectionCount() > 0;
665 bCompareRes
= getContainer()->getSelectionCount() == 1;
666 if ( bEnabled
&& bCompareRes
&& E_TABLE
== eType
)
668 ::std::vector
< ::rtl::OUString
> aList
;
669 getSelectionElementNames(aList
);
673 Reference
< XNameAccess
> xContainer
= const_cast<OApplicationController
*>(this)->getElements(eType
);
674 bEnabled
= (xContainer
.is() && xContainer
->hasByName(*aList
.begin()));
676 bEnabled
= Reference
<XRename
>(xContainer
->getByName(*aList
.begin()),UNO_QUERY
).is();
680 bEnabled
= sal_False
;
685 bEnabled
= bEnabled
&& bCompareRes
;
689 // -----------------------------------------------------------------------------
690 void OApplicationController::onLoadedMenu(const Reference
< ::com::sun::star::frame::XLayoutManager
>& _xLayoutManager
)
693 if ( _xLayoutManager
.is() )
695 static ::rtl::OUString
s_sStatusbar(RTL_CONSTASCII_USTRINGPARAM("private:resource/statusbar/statusbar"));
696 _xLayoutManager
->createElement( s_sStatusbar
);
697 _xLayoutManager
->requestElement( s_sStatusbar
);
699 if ( getContainer() )
701 // we need to share the "mnemonic space":
702 MnemonicGenerator aMnemonicGenerator
;
703 // - the menu already has mnemonics
704 SystemWindow
* pSystemWindow
= getContainer()->GetSystemWindow();
705 MenuBar
* pMenu
= pSystemWindow
? pSystemWindow
->GetMenuBar() : NULL
;
708 USHORT nMenuItems
= pMenu
->GetItemCount();
709 for ( USHORT i
= 0; i
< nMenuItems
; ++i
)
710 aMnemonicGenerator
.RegisterMnemonic( pMenu
->GetItemText( pMenu
->GetItemId( i
) ) );
712 // - the icons should use automatic ones
713 getContainer()->createIconAutoMnemonics( aMnemonicGenerator
);
714 // - as well as the entries in the task pane
715 getContainer()->setTaskExternalMnemonics( aMnemonicGenerator
);
718 Execute( SID_DB_APP_VIEW_FORMS
, Sequence
< PropertyValue
>() );
722 // -----------------------------------------------------------------------------
723 void OApplicationController::doAction(sal_uInt16 _nId
,ElementOpenMode _eOpenMode
)
725 ::std::vector
< ::rtl::OUString
> aList
;
726 getSelectionElementNames(aList
);
727 ElementType eType
= getContainer()->getElementType();
728 ::comphelper::NamedValueCollection aArguments
;
729 ElementOpenMode eOpenMode
= _eOpenMode
;
730 if ( eType
== E_REPORT
&& E_OPEN_FOR_MAIL
== _eOpenMode
)
732 aArguments
.put("Hidden",true);
733 eOpenMode
= E_OPEN_NORMAL
;
736 ::std::vector
< ::std::pair
< ::rtl::OUString
,Reference
< XModel
> > > aCompoments
;
737 ::std::vector
< ::rtl::OUString
>::iterator aEnd
= aList
.end();
738 for (::std::vector
< ::rtl::OUString
>::iterator aIter
= aList
.begin(); aIter
!= aEnd
; ++aIter
)
740 if ( SID_DB_APP_CONVERTTOVIEW
== _nId
)
741 convertToView(*aIter
);
744 Reference
< XModel
> xModel( openElementWithArguments( *aIter
, eType
, eOpenMode
, _nId
,aArguments
), UNO_QUERY
);
745 aCompoments
.push_back( ::std::pair
< ::rtl::OUString
, Reference
< XModel
> >( *aIter
, xModel
) );
749 // special handling for mail, if more than one document is selected attach them all
750 if ( _eOpenMode
== E_OPEN_FOR_MAIL
)
753 ::std::vector
< ::std::pair
< ::rtl::OUString
,Reference
< XModel
> > >::iterator componentIter
= aCompoments
.begin();
754 ::std::vector
< ::std::pair
< ::rtl::OUString
,Reference
< XModel
> > >::iterator componentEnd
= aCompoments
.end();
755 ::rtl::OUString aDocTypeString
;
756 SfxMailModel aSendMail
;
757 SfxMailModel::SendMailResult eResult
= SfxMailModel::SEND_MAIL_OK
;
758 for (; componentIter
!= componentEnd
&& SfxMailModel::SEND_MAIL_OK
== eResult
; ++componentIter
)
762 Reference
< XModel
> xModel(componentIter
->second
,UNO_QUERY
);
764 // Send document as e-Mail using stored/default type
765 eResult
= aSendMail
.AttachDocument(aDocTypeString
,xModel
,componentIter
->first
);
766 ::comphelper::disposeComponent(xModel
);
768 catch(const Exception
&)
770 DBG_UNHANDLED_EXCEPTION();
773 if ( !aSendMail
.IsEmpty() )
774 aSendMail
.Send( getFrame() );
777 // -----------------------------------------------------------------------------
778 ElementType
OApplicationController::getElementType(const Reference
< XContainer
>& _xContainer
) const
780 ElementType eRet
= E_NONE
;
781 Reference
<XServiceInfo
> xServiceInfo(_xContainer
,UNO_QUERY
);
782 if ( xServiceInfo
.is() )
784 if ( xServiceInfo
->supportsService(SERVICE_SDBCX_TABLES
) )
786 else if ( xServiceInfo
->supportsService(SERVICE_NAME_FORM_COLLECTION
) )
788 else if ( xServiceInfo
->supportsService(SERVICE_NAME_REPORT_COLLECTION
) )
796 //........................................................................
798 //........................................................................