1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "AppController.hxx"
31 #include "AppDetailView.hxx"
32 #include "AppView.hxx"
33 #include "dbaccess_slotid.hrc"
34 #include "dbu_app.hrc"
35 #include "dbustrings.hrc"
36 #include "defaultobjectnamecheck.hxx"
37 #include "dlgsave.hxx"
38 #include "UITools.hxx"
39 #include "subcomponentmanager.hxx"
41 /** === begin UNO includes === **/
42 #include <com/sun/star/container/XChild.hpp>
43 #include <com/sun/star/container/XContainer.hpp>
44 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
45 #include <com/sun/star/container/XNameAccess.hpp>
46 #include <com/sun/star/container/XNameContainer.hpp>
47 #include <com/sun/star/lang/XEventListener.hpp>
48 #include <com/sun/star/sdb/CommandType.hpp>
49 #include <com/sun/star/sdb/SQLContext.hpp>
50 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
51 #include <com/sun/star/sdbcx/XRename.hpp>
52 #include <com/sun/star/sdb/ErrorCondition.hpp>
53 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
54 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
55 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
56 #include <com/sun/star/ucb/Command.hpp>
57 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
58 #include <com/sun/star/ucb/XCommandProcessor.hpp>
59 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
60 #include <com/sun/star/uno/XNamingService.hpp>
61 #include <com/sun/star/util/XCloseable.hpp>
62 #include <com/sun/star/util/XRefreshable.hpp>
63 /** === end UNO includes === **/
65 #include <cppuhelper/exc_hlp.hxx>
66 #include <connectivity/dbexception.hxx>
67 #include <connectivity/dbtools.hxx>
68 #include <connectivity/sqlerror.hxx>
69 #include <sfx2/mailmodelapi.hxx>
70 #include <svx/dbaexchange.hxx>
71 #include <toolkit/unohlp.hxx>
72 #include <tools/diagnose_ex.h>
73 #include <osl/diagnose.h>
74 #include <unotools/bootstrap.hxx>
75 #include <vcl/mnemonic.hxx>
76 #include <vcl/svapp.hxx>
77 #include <vcl/waitobj.hxx>
78 #include <osl/mutex.hxx>
80 //........................................................................
83 using namespace ::dbtools
;
84 using namespace ::connectivity
;
85 using namespace ::svx
;
86 using namespace ::com::sun::star
;
87 using namespace ::com::sun::star::uno
;
88 using namespace ::com::sun::star::awt
;
89 using namespace ::com::sun::star::util
;
90 using namespace ::com::sun::star::frame
;
91 using namespace ::com::sun::star::lang
;
92 using namespace ::com::sun::star::ui::dialogs
;
93 using namespace ::com::sun::star::sdb
;
94 using namespace ::com::sun::star::sdbc
;
95 using namespace ::com::sun::star::sdbcx
;
96 using namespace ::com::sun::star::beans
;
97 using namespace ::com::sun::star::container
;
98 using namespace ::com::sun::star::ucb
;
100 /** === begin UNO using === **/
101 using ::com::sun::star::util::XCloseable
;
102 using ::com::sun::star::ui::XContextMenuInterceptor
;
103 /** === end UNO using === **/
105 namespace DatabaseObject
= ::com::sun::star::sdb::application::DatabaseObject
;
106 namespace ErrorCondition
= ::com::sun::star::sdb::ErrorCondition
;
108 //........................................................................
109 // -----------------------------------------------------------------------------
111 class CloseChecker
: public ::cppu::WeakImplHelper1
< com::sun::star::lang::XEventListener
>
121 virtual ~CloseChecker()
130 // interface XEventListener
131 virtual void SAL_CALL
disposing( const EventObject
& /*Source*/ ) throw( RuntimeException
)
137 // -----------------------------------------------------------------------------
138 void OApplicationController::convertToView(const ::rtl::OUString
& _sName
)
142 SharedConnection
xConnection( getConnection() );
143 Reference
< XQueriesSupplier
> xSup( xConnection
, UNO_QUERY_THROW
);
144 Reference
< XNameAccess
> xQueries( xSup
->getQueries(), UNO_QUERY_THROW
);
145 Reference
< XPropertySet
> xSourceObject( xQueries
->getByName( _sName
), UNO_QUERY_THROW
);
147 Reference
< XTablesSupplier
> xTablesSup( xConnection
, UNO_QUERY_THROW
);
148 Reference
< XNameAccess
> xTables( xTablesSup
->getTables(), UNO_QUERY_THROW
);
150 Reference
< XDatabaseMetaData
> xMeta
= xConnection
->getMetaData();
152 String aName
= String(ModuleRes(STR_TBL_TITLE
));
153 aName
= aName
.GetToken(0,' ');
154 String aDefaultName
= ::dbaui::createDefaultName(xMeta
,xTables
,aName
);
156 DynamicTableOrQueryNameCheck
aNameChecker( xConnection
, CommandType::TABLE
);
157 OSaveAsDlg
aDlg( getView(), CommandType::TABLE
, getORB(), xConnection
, aDefaultName
, aNameChecker
);
158 if ( aDlg
.Execute() == RET_OK
)
160 ::rtl::OUString sName
= aDlg
.getName();
161 ::rtl::OUString sCatalog
= aDlg
.getCatalog();
162 ::rtl::OUString sSchema
= aDlg
.getSchema();
163 ::rtl::OUString
sNewName(
164 ::dbtools::composeTableName( xMeta
, sCatalog
, sSchema
, sName
, sal_False
, ::dbtools::eInTableDefinitions
) );
165 Reference
<XPropertySet
> xView
= ::dbaui::createView(sNewName
,xConnection
,xSourceObject
);
167 throw SQLException(String(ModuleRes(STR_NO_TABLE_FORMAT_INSIDE
)),*this,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")) ,0,Any());
168 getContainer()->elementAdded(E_TABLE
,sNewName
,makeAny(xView
));
171 catch(const SQLException
& )
173 showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
175 catch( const Exception
& )
177 DBG_UNHANDLED_EXCEPTION();
180 // -----------------------------------------------------------------------------
181 void OApplicationController::pasteFormat(sal_uInt32 _nFormatId
)
187 const TransferableDataHelper
& rClipboard
= getViewClipboard();
188 ElementType eType
= getContainer()->getElementType();
189 if ( eType
== E_TABLE
)
191 m_aTableCopyHelper
.pasteTable( _nFormatId
, rClipboard
, getDatabaseName(), ensureConnection() );
194 paste( eType
, ODataAccessObjectTransferable::extractObjectDescriptor( rClipboard
) );
197 catch( const Exception
& )
199 DBG_UNHANDLED_EXCEPTION();
203 // -----------------------------------------------------------------------------
204 void OApplicationController::openDataSourceAdminDialog()
206 openDialog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.DatasourceAdministrationDialog" ) ) );
209 // -----------------------------------------------------------------------------
210 void OApplicationController::openDialog( const ::rtl::OUString
& _sServiceName
)
214 SolarMutexGuard aSolarGuard
;
215 ::osl::MutexGuard
aGuard( getMutex() );
216 WaitObject
aWO(getView());
218 Sequence
< Any
> aArgs(3);
219 sal_Int32 nArgPos
= 0;
221 Reference
< ::com::sun::star::awt::XWindow
> xWindow
= getTopMostContainerWindow();
224 OSL_ENSURE( getContainer(), "OApplicationController::Construct: have no view!" );
225 if ( getContainer() )
226 xWindow
= VCLUnoHelper::GetInterface(getView()->Window::GetParent());
229 aArgs
[nArgPos
++] <<= PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentWindow")),
232 PropertyState_DIRECT_VALUE
);
234 // the initial selection
235 ::rtl::OUString sInitialSelection
;
236 if ( getContainer() )
237 sInitialSelection
= getDatabaseName();
238 if ( !sInitialSelection
.isEmpty() )
240 aArgs
[ nArgPos
++ ] <<= PropertyValue(
241 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InitialSelection" ) ), 0,
242 makeAny( sInitialSelection
), PropertyState_DIRECT_VALUE
);
245 SharedConnection
xConnection( getConnection() );
246 if ( xConnection
.is() )
248 aArgs
[ nArgPos
++ ] <<= PropertyValue(
249 PROPERTY_ACTIVE_CONNECTION
, 0,
250 makeAny( xConnection
), PropertyState_DIRECT_VALUE
);
252 aArgs
.realloc( nArgPos
);
255 Reference
< XExecutableDialog
> xAdminDialog
;
256 xAdminDialog
= Reference
< XExecutableDialog
>(
257 getORB()->createInstanceWithArguments(_sServiceName
,aArgs
), UNO_QUERY
);
260 if (xAdminDialog
.is())
261 xAdminDialog
->execute();
263 catch( const Exception
& )
265 DBG_UNHANDLED_EXCEPTION();
268 // -----------------------------------------------------------------------------
269 void OApplicationController::openTableFilterDialog()
271 openDialog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.TableFilterDialog" ) ) );
274 // -----------------------------------------------------------------------------
275 void OApplicationController::refreshTables()
277 if ( getContainer() && getContainer()->getDetailView() )
279 WaitObject
aWO(getView());
280 OSL_ENSURE(getContainer()->getElementType() == E_TABLE
,"Only allowed when the tables container is selected!");
283 Reference
<XRefreshable
> xRefresh(getElements(E_TABLE
),UNO_QUERY
);
287 catch(const Exception
&)
289 OSL_FAIL("Could not refresh tables!");
292 getContainer()->getDetailView()->clearPages(sal_False
);
293 getContainer()->getDetailView()->createTablesPage( ensureConnection() );
296 // -----------------------------------------------------------------------------
297 void OApplicationController::openDirectSQLDialog()
299 openDialog( SERVICE_SDB_DIRECTSQLDIALOG
);
301 // -----------------------------------------------------------------------------
302 void SAL_CALL
OApplicationController::propertyChange( const PropertyChangeEvent
& evt
) throw (RuntimeException
)
304 SolarMutexGuard aSolarGuard
;
305 ::osl::MutexGuard
aGuard( getMutex() );
306 if ( evt
.PropertyName
== PROPERTY_USER
)
308 m_bNeedToReconnect
= sal_True
;
309 InvalidateFeature(SID_DB_APP_STATUS_USERNAME
);
311 else if ( evt
.PropertyName
== PROPERTY_URL
)
313 m_bNeedToReconnect
= sal_True
;
314 InvalidateFeature(SID_DB_APP_STATUS_DBNAME
);
315 InvalidateFeature(SID_DB_APP_STATUS_TYPE
);
316 InvalidateFeature(SID_DB_APP_STATUS_HOSTNAME
);
318 else if ( PROPERTY_NAME
== evt
.PropertyName
)
320 const ElementType eType
= getContainer()->getElementType();
321 if ( eType
== E_FORM
|| eType
== E_REPORT
)
323 ::rtl::OUString sOldName
,sNewName
;
324 evt
.OldValue
>>= sOldName
;
325 evt
.NewValue
>>= sNewName
;
327 // if the old name is empty, then this is a newly inserted content. We're notified of it via the
328 // elementInserted method, so there's no need to handle it here.
330 if ( !sOldName
.isEmpty() )
332 Reference
<XChild
> xChild(evt
.Source
,UNO_QUERY
);
335 Reference
<XContent
> xContent(xChild
->getParent(),UNO_QUERY
);
337 sOldName
= xContent
->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sOldName
;
340 getContainer()->elementReplaced( eType
, sOldName
, sNewName
);
346 aEvt
.Source
= m_xModel
;
350 // -----------------------------------------------------------------------------
351 Reference
< XDataSource
> SAL_CALL
OApplicationController::getDataSource() throw (RuntimeException
)
353 ::osl::MutexGuard
aGuard( getMutex() );
354 Reference
< XDataSource
> xDataSource( m_xDataSource
, UNO_QUERY
);
358 // -----------------------------------------------------------------------------
359 Reference
< XWindow
> SAL_CALL
OApplicationController::getApplicationMainWindow() throw (RuntimeException
)
361 ::osl::MutexGuard
aGuard( getMutex() );
362 Reference
< XFrame
> xFrame( getFrame(), UNO_QUERY_THROW
);
363 Reference
< XWindow
> xWindow( xFrame
->getContainerWindow(), UNO_QUERY_THROW
);
367 // -----------------------------------------------------------------------------
368 Sequence
< Reference
< XComponent
> > SAL_CALL
OApplicationController::getSubComponents() throw (RuntimeException
)
370 ::osl::MutexGuard
aGuard( getMutex() );
371 return m_pSubComponentManager
->getSubComponents();
374 // -----------------------------------------------------------------------------
375 Reference
< XConnection
> SAL_CALL
OApplicationController::getActiveConnection() throw (RuntimeException
)
377 ::osl::MutexGuard
aGuard( getMutex() );
378 return m_xDataSourceConnection
.getTyped();
381 // -----------------------------------------------------------------------------
382 ::sal_Bool SAL_CALL
OApplicationController::isConnected( ) throw (RuntimeException
)
384 ::osl::MutexGuard
aGuard( getMutex() );
385 return m_xDataSourceConnection
.is();
388 // -----------------------------------------------------------------------------
389 void SAL_CALL
OApplicationController::connect( ) throw (SQLException
, RuntimeException
)
391 SolarMutexGuard aSolarGuard
;
392 ::osl::MutexGuard
aGuard( getMutex() );
394 SQLExceptionInfo aError
;
395 SharedConnection xConnection
= ensureConnection( &aError
);
396 if ( !xConnection
.is() )
398 if ( aError
.isValid() )
401 // no particular error, but nonetheless could not connect -> throw a generic exception
402 String
sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE
) );
403 sConnectingContext
.SearchAndReplaceAscii( "$name$", getStrippedDatabaseName() );
404 ::dbtools::throwGenericSQLException( sConnectingContext
, *this );
408 // -----------------------------------------------------------------------------
409 beans::Pair
< ::sal_Int32
, ::rtl::OUString
> SAL_CALL
OApplicationController::identifySubComponent( const Reference
< XComponent
>& i_rSubComponent
) throw (IllegalArgumentException
, RuntimeException
)
411 ::osl::MutexGuard
aGuard( getMutex() );
413 sal_Int32 nType
= -1;
414 ::rtl::OUString sName
;
416 if ( !m_pSubComponentManager
->lookupSubComponent( i_rSubComponent
, sName
, nType
) )
417 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
419 if ( nType
== SID_DB_APP_DSRELDESIGN
)
420 // this is somewhat hacky ... we're expected to return a DatabaseObject value. However, there is no such
421 // value for the relation design. /me thinks we should change the API definition here ...
424 return beans::Pair
< ::sal_Int32
, ::rtl::OUString
>( nType
, sName
);
427 // -----------------------------------------------------------------------------
428 ::sal_Bool SAL_CALL
OApplicationController::closeSubComponents( ) throw (RuntimeException
)
430 SolarMutexGuard aSolarGuard
;
431 ::osl::MutexGuard
aGuard( getMutex() );
432 return m_pSubComponentManager
->closeSubComponents();
436 // -----------------------------------------------------------------------------
439 ElementType
lcl_objectType2ElementType( const sal_Int32 _nObjectType
)
441 ElementType
eType( E_NONE
);
442 switch ( _nObjectType
)
444 case DatabaseObject::TABLE
: eType
= E_TABLE
; break;
445 case DatabaseObject::QUERY
: eType
= E_QUERY
; break;
446 case DatabaseObject::FORM
: eType
= E_FORM
; break;
447 case DatabaseObject::REPORT
: eType
= E_REPORT
; break;
449 OSL_FAIL( "lcl_objectType2ElementType: unsupported object type!" );
450 // this should have been caught earlier
456 // -----------------------------------------------------------------------------
457 void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType
, const ::boost::optional
< ::rtl::OUString
>& i_rObjectName
)
459 // ensure we're connected
460 if ( !isConnected() )
462 SQLError
aError( getORB() );
463 aError
.raiseException( ErrorCondition::DB_NOT_CONNECTED
, *this );
466 // ensure a proper object type
467 if ( ( _nObjectType
!= DatabaseObject::TABLE
)
468 && ( _nObjectType
!= DatabaseObject::QUERY
)
469 && ( _nObjectType
!= DatabaseObject::FORM
)
470 && ( _nObjectType
!= DatabaseObject::REPORT
)
472 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
474 if ( !i_rObjectName
)
477 // ensure an existing object
478 Reference
< XNameAccess
> xContainer( getElements( lcl_objectType2ElementType( _nObjectType
) ) );
479 if ( !xContainer
.is() )
480 // all possible reasons for this (e.g. not being connected currently) should
481 // have been handled before
482 throw RuntimeException( ::rtl::OUString(), *this );
484 bool bExistentObject
= false;
485 switch ( _nObjectType
)
487 case DatabaseObject::TABLE
:
488 case DatabaseObject::QUERY
:
489 bExistentObject
= xContainer
->hasByName( *i_rObjectName
);
491 case DatabaseObject::FORM
:
492 case DatabaseObject::REPORT
:
494 Reference
< XHierarchicalNameAccess
> xHierarchy( xContainer
, UNO_QUERY_THROW
);
495 bExistentObject
= xHierarchy
->hasByHierarchicalName( *i_rObjectName
);
500 if ( !bExistentObject
)
501 throw NoSuchElementException( *i_rObjectName
, *this );
504 // -----------------------------------------------------------------------------
505 Reference
< XComponent
> SAL_CALL
OApplicationController::loadComponent( ::sal_Int32 _ObjectType
,
506 const ::rtl::OUString
& _ObjectName
, ::sal_Bool _ForEditing
) throw (IllegalArgumentException
, NoSuchElementException
, SQLException
, RuntimeException
)
508 return loadComponentWithArguments( _ObjectType
, _ObjectName
, _ForEditing
, Sequence
< PropertyValue
>() );
511 // -----------------------------------------------------------------------------
512 Reference
< XComponent
> SAL_CALL
OApplicationController::loadComponentWithArguments( ::sal_Int32 _ObjectType
,
513 const ::rtl::OUString
& _ObjectName
, ::sal_Bool _ForEditing
, const Sequence
< PropertyValue
>& _Arguments
) throw (IllegalArgumentException
, NoSuchElementException
, SQLException
, RuntimeException
)
515 SolarMutexGuard aSolarGuard
;
516 ::osl::MutexGuard
aGuard( getMutex() );
518 impl_validateObjectTypeAndName_throw( _ObjectType
, _ObjectName
);
520 Reference
< XComponent
> xComponent( openElementWithArguments(
522 lcl_objectType2ElementType( _ObjectType
),
523 _ForEditing
? E_OPEN_DESIGN
: E_OPEN_NORMAL
,
524 _ForEditing
? SID_DB_APP_EDIT
: SID_DB_APP_OPEN
,
525 ::comphelper::NamedValueCollection( _Arguments
)
531 // -----------------------------------------------------------------------------
532 Reference
< XComponent
> SAL_CALL
OApplicationController::createComponent( ::sal_Int32 i_nObjectType
, Reference
< XComponent
>& o_DocumentDefinition
) throw (IllegalArgumentException
, SQLException
, RuntimeException
)
534 return createComponentWithArguments( i_nObjectType
, Sequence
< PropertyValue
>(), o_DocumentDefinition
);
537 // -----------------------------------------------------------------------------
538 Reference
< XComponent
> SAL_CALL
OApplicationController::createComponentWithArguments( ::sal_Int32 i_nObjectType
, const Sequence
< PropertyValue
>& i_rArguments
, Reference
< XComponent
>& o_DocumentDefinition
) throw (IllegalArgumentException
, SQLException
, RuntimeException
)
540 SolarMutexGuard aSolarGuard
;
541 ::osl::MutexGuard
aGuard( getMutex() );
543 impl_validateObjectTypeAndName_throw( i_nObjectType
, ::boost::optional
< ::rtl::OUString
>() );
545 Reference
< XComponent
> xComponent( newElement(
546 lcl_objectType2ElementType( i_nObjectType
),
547 ::comphelper::NamedValueCollection( i_rArguments
),
554 // -----------------------------------------------------------------------------
555 void SAL_CALL
OApplicationController::registerContextMenuInterceptor( const Reference
< XContextMenuInterceptor
>& _Interceptor
) throw (RuntimeException
)
557 if ( _Interceptor
.is() )
558 m_aContextMenuInterceptors
.addInterface( _Interceptor
);
561 // -----------------------------------------------------------------------------
562 void SAL_CALL
OApplicationController::releaseContextMenuInterceptor( const Reference
< XContextMenuInterceptor
>& _Interceptor
) throw (RuntimeException
)
564 m_aContextMenuInterceptors
.removeInterface( _Interceptor
);
567 // -----------------------------------------------------------------------------
568 void OApplicationController::previewChanged( sal_Int32 _nMode
)
570 SolarMutexGuard aSolarGuard
;
571 ::osl::MutexGuard
aGuard( getMutex() );
573 if ( m_xDataSource
.is() && !isDataSourceReadOnly() )
577 ::comphelper::NamedValueCollection
aLayoutInfo( m_xDataSource
->getPropertyValue( PROPERTY_LAYOUTINFORMATION
) );
578 sal_Int32 nOldMode
= aLayoutInfo
.getOrDefault( "Preview", _nMode
);
579 if ( nOldMode
!= _nMode
)
581 aLayoutInfo
.put( "Preview", _nMode
);
582 m_xDataSource
->setPropertyValue( PROPERTY_LAYOUTINFORMATION
, makeAny( aLayoutInfo
.getPropertyValues() ) );
585 catch ( const Exception
& )
587 DBG_UNHANDLED_EXCEPTION();
590 InvalidateFeature(SID_DB_APP_DISABLE_PREVIEW
);
591 InvalidateFeature(SID_DB_APP_VIEW_DOCINFO_PREVIEW
);
592 InvalidateFeature(SID_DB_APP_VIEW_DOC_PREVIEW
);
594 // -----------------------------------------------------------------------------
595 void OApplicationController::askToReconnect()
597 if ( m_bNeedToReconnect
)
599 m_bNeedToReconnect
= sal_False
;
600 sal_Bool bClear
= sal_True
;
601 if ( !m_pSubComponentManager
->empty() )
603 QueryBox
aQry(getView(), ModuleRes(APP_CLOSEDOCUMENTS
));
604 switch (aQry
.Execute())
607 closeSubComponents();
616 ElementType eType
= getContainer()->getElementType();
618 getContainer()->getDetailView()->clearPages(sal_False
);
619 getContainer()->selectContainer(E_NONE
); // invalidate the old selection
620 m_eCurrentType
= E_NONE
;
621 getContainer()->selectContainer(eType
); // reselect the current one again
626 // -----------------------------------------------------------------------------
627 ::rtl::OUString
OApplicationController::getDatabaseName() const
629 ::rtl::OUString sDatabaseName
;
632 if ( m_xDataSource
.is() )
634 OSL_VERIFY( m_xDataSource
->getPropertyValue( PROPERTY_NAME
) >>= sDatabaseName
);
637 catch ( const Exception
& )
639 DBG_UNHANDLED_EXCEPTION();
641 return sDatabaseName
;
644 // -----------------------------------------------------------------------------
645 ::rtl::OUString
OApplicationController::getStrippedDatabaseName() const
647 ::rtl::OUString sDatabaseName
;
648 return ::dbaui::getStrippedDatabaseName( m_xDataSource
, sDatabaseName
);
651 // -----------------------------------------------------------------------------
652 void OApplicationController::onDocumentOpened( const ::rtl::OUString
& _rName
, const sal_Int32 _nType
,
653 const ElementOpenMode _eMode
, const Reference
< XComponent
>& _xDocument
, const Reference
< XComponent
>& _rxDefinition
)
655 if ( !_xDocument
.is() )
660 OSL_ENSURE( _xDocument
.is(), "OApplicationController::onDocumentOpened: is there any *valid* scenario where this fails?" );
661 m_pSubComponentManager
->onSubComponentOpened( _rName
, _nType
, _eMode
, _xDocument
.is() ? _xDocument
: _rxDefinition
);
663 if ( _rxDefinition
.is() )
665 Reference
< XPropertySet
> xProp( _rxDefinition
, UNO_QUERY_THROW
);
666 Reference
< XPropertySetInfo
> xPSI( xProp
->getPropertySetInfo(), UNO_SET_THROW
);
667 xProp
->addPropertyChangeListener( PROPERTY_NAME
, static_cast< XPropertyChangeListener
* >( this ) );
670 catch( const Exception
& )
672 DBG_UNHANDLED_EXCEPTION();
675 // -----------------------------------------------------------------------------
676 sal_Bool
OApplicationController::insertHierachyElement(ElementType _eType
,const String
& _sParentFolder
,sal_Bool _bCollection
,const Reference
<XContent
>& _xContent
,sal_Bool _bMove
)
678 Reference
<XHierarchicalNameContainer
> xNames(getElements(_eType
), UNO_QUERY
);
679 return dbaui::insertHierachyElement(getView()
688 // -----------------------------------------------------------------------------
689 sal_Bool
OApplicationController::isRenameDeleteAllowed(ElementType _eType
,sal_Bool _bDelete
) const
691 ElementType eType
= getContainer()->getElementType();
692 sal_Bool bEnabled
= !isDataSourceReadOnly() && eType
== _eType
;
696 if ( E_TABLE
== eType
)
697 bEnabled
= !isConnectionReadOnly() && getContainer()->isALeafSelected();
699 sal_Bool bCompareRes
= sal_False
;
701 bCompareRes
= getContainer()->getSelectionCount() > 0;
704 bCompareRes
= getContainer()->getSelectionCount() == 1;
705 if ( bEnabled
&& bCompareRes
&& E_TABLE
== eType
)
707 ::std::vector
< ::rtl::OUString
> aList
;
708 getSelectionElementNames(aList
);
712 Reference
< XNameAccess
> xContainer
= const_cast<OApplicationController
*>(this)->getElements(eType
);
713 bEnabled
= (xContainer
.is() && xContainer
->hasByName(*aList
.begin()));
715 bEnabled
= Reference
<XRename
>(xContainer
->getByName(*aList
.begin()),UNO_QUERY
).is();
719 bEnabled
= sal_False
;
724 bEnabled
= bEnabled
&& bCompareRes
;
728 // -----------------------------------------------------------------------------
729 void OApplicationController::onLoadedMenu(const Reference
< ::com::sun::star::frame::XLayoutManager
>& _xLayoutManager
)
732 if ( _xLayoutManager
.is() )
734 static ::rtl::OUString
s_sStatusbar(RTL_CONSTASCII_USTRINGPARAM("private:resource/statusbar/statusbar"));
735 _xLayoutManager
->createElement( s_sStatusbar
);
736 _xLayoutManager
->requestElement( s_sStatusbar
);
738 if ( getContainer() )
740 // we need to share the "mnemonic space":
741 MnemonicGenerator aMnemonicGenerator
;
742 // - the menu already has mnemonics
743 SystemWindow
* pSystemWindow
= getContainer()->GetSystemWindow();
744 MenuBar
* pMenu
= pSystemWindow
? pSystemWindow
->GetMenuBar() : NULL
;
747 sal_uInt16 nMenuItems
= pMenu
->GetItemCount();
748 for ( sal_uInt16 i
= 0; i
< nMenuItems
; ++i
)
749 aMnemonicGenerator
.RegisterMnemonic( pMenu
->GetItemText( pMenu
->GetItemId( i
) ) );
751 // - the icons should use automatic ones
752 getContainer()->createIconAutoMnemonics( aMnemonicGenerator
);
753 // - as well as the entries in the task pane
754 getContainer()->setTaskExternalMnemonics( aMnemonicGenerator
);
757 Execute( SID_DB_APP_VIEW_FORMS
, Sequence
< PropertyValue
>() );
761 // -----------------------------------------------------------------------------
762 void OApplicationController::doAction(sal_uInt16 _nId
,ElementOpenMode _eOpenMode
)
764 ::std::vector
< ::rtl::OUString
> aList
;
765 getSelectionElementNames(aList
);
766 ElementType eType
= getContainer()->getElementType();
767 ::comphelper::NamedValueCollection aArguments
;
768 ElementOpenMode eOpenMode
= _eOpenMode
;
769 if ( eType
== E_REPORT
&& E_OPEN_FOR_MAIL
== _eOpenMode
)
771 aArguments
.put("Hidden",true);
772 eOpenMode
= E_OPEN_NORMAL
;
775 ::std::vector
< ::std::pair
< ::rtl::OUString
,Reference
< XModel
> > > aCompoments
;
776 ::std::vector
< ::rtl::OUString
>::iterator aEnd
= aList
.end();
777 for (::std::vector
< ::rtl::OUString
>::iterator aIter
= aList
.begin(); aIter
!= aEnd
; ++aIter
)
779 if ( SID_DB_APP_CONVERTTOVIEW
== _nId
)
780 convertToView(*aIter
);
783 Reference
< XModel
> xModel( openElementWithArguments( *aIter
, eType
, eOpenMode
, _nId
,aArguments
), UNO_QUERY
);
784 aCompoments
.push_back( ::std::pair
< ::rtl::OUString
, Reference
< XModel
> >( *aIter
, xModel
) );
788 // special handling for mail, if more than one document is selected attach them all
789 if ( _eOpenMode
== E_OPEN_FOR_MAIL
)
792 ::std::vector
< ::std::pair
< ::rtl::OUString
,Reference
< XModel
> > >::iterator componentIter
= aCompoments
.begin();
793 ::std::vector
< ::std::pair
< ::rtl::OUString
,Reference
< XModel
> > >::iterator componentEnd
= aCompoments
.end();
794 ::rtl::OUString aDocTypeString
;
795 SfxMailModel aSendMail
;
796 SfxMailModel::SendMailResult eResult
= SfxMailModel::SEND_MAIL_OK
;
797 for (; componentIter
!= componentEnd
&& SfxMailModel::SEND_MAIL_OK
== eResult
; ++componentIter
)
801 Reference
< XModel
> xModel(componentIter
->second
,UNO_QUERY
);
803 // Send document as e-Mail using stored/default type
804 eResult
= aSendMail
.AttachDocument(aDocTypeString
,xModel
,componentIter
->first
);
805 ::comphelper::disposeComponent(xModel
);
807 catch(const Exception
&)
809 DBG_UNHANDLED_EXCEPTION();
812 if ( !aSendMail
.IsEmpty() )
813 aSendMail
.Send( getFrame() );
816 // -----------------------------------------------------------------------------
817 ElementType
OApplicationController::getElementType(const Reference
< XContainer
>& _xContainer
) const
819 ElementType eRet
= E_NONE
;
820 Reference
<XServiceInfo
> xServiceInfo(_xContainer
,UNO_QUERY
);
821 if ( xServiceInfo
.is() )
823 if ( xServiceInfo
->supportsService(SERVICE_SDBCX_TABLES
) )
825 else if ( xServiceInfo
->supportsService(SERVICE_NAME_FORM_COLLECTION
) )
827 else if ( xServiceInfo
->supportsService(SERVICE_NAME_REPORT_COLLECTION
) )
835 //........................................................................
837 //........................................................................
839 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */