fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / app / AppControllerGen.cxx
blob776c51da9be5402b64edf1c59be76f585c3b9b5d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/XCloseable.hpp>
51 #include <com/sun/star/util/XRefreshable.hpp>
53 #include <cppuhelper/exc_hlp.hxx>
54 #include <comphelper/processfactory.hxx>
55 #include <connectivity/dbexception.hxx>
56 #include <connectivity/dbtools.hxx>
57 #include <connectivity/sqlerror.hxx>
58 #include <sfx2/mailmodelapi.hxx>
59 #include <svx/dbaexchange.hxx>
60 #include <toolkit/helper/vclunohelper.hxx>
61 #include <tools/diagnose_ex.h>
62 #include <osl/diagnose.h>
63 #include <unotools/bootstrap.hxx>
64 #include <vcl/layout.hxx>
65 #include <vcl/mnemonic.hxx>
66 #include <vcl/svapp.hxx>
67 #include <vcl/waitobj.hxx>
68 #include <osl/mutex.hxx>
70 namespace dbaui
72 using namespace ::dbtools;
73 using namespace ::connectivity;
74 using namespace ::svx;
75 using namespace ::com::sun::star;
76 using namespace ::com::sun::star::uno;
77 using namespace ::com::sun::star::awt;
78 using namespace ::com::sun::star::util;
79 using namespace ::com::sun::star::frame;
80 using namespace ::com::sun::star::lang;
81 using namespace ::com::sun::star::ui::dialogs;
82 using namespace ::com::sun::star::sdb;
83 using namespace ::com::sun::star::sdbc;
84 using namespace ::com::sun::star::sdbcx;
85 using namespace ::com::sun::star::beans;
86 using namespace ::com::sun::star::container;
87 using namespace ::com::sun::star::ucb;
89 using ::com::sun::star::util::XCloseable;
90 using ::com::sun::star::ui::XContextMenuInterceptor;
92 namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
93 namespace ErrorCondition = ::com::sun::star::sdb::ErrorCondition;
95 void OApplicationController::convertToView(const OUString& _sName)
97 try
99 SharedConnection xConnection( getConnection() );
100 Reference< XQueriesSupplier > xSup( xConnection, UNO_QUERY_THROW );
101 Reference< XNameAccess > xQueries( xSup->getQueries(), UNO_QUERY_THROW );
102 Reference< XPropertySet > xSourceObject( xQueries->getByName( _sName ), UNO_QUERY_THROW );
104 Reference< XTablesSupplier > xTablesSup( xConnection, UNO_QUERY_THROW );
105 Reference< XNameAccess > xTables( xTablesSup->getTables(), UNO_QUERY_THROW );
107 Reference< XDatabaseMetaData > xMeta = xConnection->getMetaData();
109 OUString aName = OUString(ModuleRes(STR_TBL_TITLE));
110 aName = aName.getToken(0,' ');
111 OUString aDefaultName = ::dbaui::createDefaultName(xMeta,xTables,aName);
113 DynamicTableOrQueryNameCheck aNameChecker( xConnection, CommandType::TABLE );
114 ScopedVclPtrInstance< OSaveAsDlg > aDlg( getView(), CommandType::TABLE, getORB(), xConnection, aDefaultName, aNameChecker );
115 if ( aDlg->Execute() == RET_OK )
117 OUString sName = aDlg->getName();
118 OUString sCatalog = aDlg->getCatalog();
119 OUString sSchema = aDlg->getSchema();
120 OUString sNewName(
121 ::dbtools::composeTableName( xMeta, sCatalog, sSchema, sName, false, ::dbtools::eInTableDefinitions ) );
122 Reference<XPropertySet> xView = ::dbaui::createView(sNewName,xConnection,xSourceObject);
123 if ( !xView.is() )
124 throw SQLException(OUString(ModuleRes(STR_NO_TABLE_FORMAT_INSIDE)),*this,OUString( "S1000" ) ,0,Any());
125 getContainer()->elementAdded(E_TABLE,sNewName,makeAny(xView));
128 catch(const SQLException& )
130 showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
132 catch( const Exception& )
134 DBG_UNHANDLED_EXCEPTION();
138 void OApplicationController::pasteFormat(SotClipboardFormatId _nFormatId)
140 if ( _nFormatId != SotClipboardFormatId::NONE )
144 const TransferableDataHelper& rClipboard = getViewClipboard();
145 ElementType eType = getContainer()->getElementType();
146 if ( eType == E_TABLE )
148 m_aTableCopyHelper.pasteTable( _nFormatId, rClipboard, getDatabaseName(), ensureConnection() );
150 else
151 paste( eType, ODataAccessObjectTransferable::extractObjectDescriptor( rClipboard ) );
154 catch( const Exception& )
156 DBG_UNHANDLED_EXCEPTION();
161 void OApplicationController::openDataSourceAdminDialog()
163 openDialog( OUString( "com.sun.star.sdb.DatasourceAdministrationDialog" ) );
166 void OApplicationController::openDialog( const OUString& _sServiceName )
170 SolarMutexGuard aSolarGuard;
171 ::osl::MutexGuard aGuard( getMutex() );
172 WaitObject aWO(getView());
174 Sequence< Any > aArgs(3);
175 sal_Int32 nArgPos = 0;
177 Reference< ::com::sun::star::awt::XWindow> xWindow = getTopMostContainerWindow();
178 if ( !xWindow.is() )
180 OSL_ENSURE( getContainer(), "OApplicationController::Construct: have no view!" );
181 if ( getContainer() )
182 xWindow = VCLUnoHelper::GetInterface(getView()->Window::GetParent());
184 // the parent window
185 aArgs[nArgPos++] <<= PropertyValue( OUString("ParentWindow"),
187 makeAny(xWindow),
188 PropertyState_DIRECT_VALUE);
190 // the initial selection
191 OUString sInitialSelection;
192 if ( getContainer() )
193 sInitialSelection = getDatabaseName();
194 if ( !sInitialSelection.isEmpty() )
196 aArgs[ nArgPos++ ] <<= PropertyValue(
197 OUString( "InitialSelection" ), 0,
198 makeAny( sInitialSelection ), PropertyState_DIRECT_VALUE );
201 SharedConnection xConnection( getConnection() );
202 if ( xConnection.is() )
204 aArgs[ nArgPos++ ] <<= PropertyValue(
205 PROPERTY_ACTIVE_CONNECTION, 0,
206 makeAny( xConnection ), PropertyState_DIRECT_VALUE );
208 aArgs.realloc( nArgPos );
210 // create the dialog
211 Reference< XExecutableDialog > xAdminDialog;
212 xAdminDialog = Reference< XExecutableDialog >(
213 getORB()->getServiceManager()->createInstanceWithArgumentsAndContext(_sServiceName, aArgs, getORB()),
214 UNO_QUERY);
216 // execute it
217 if (xAdminDialog.is())
218 xAdminDialog->execute();
220 catch( const Exception& )
222 DBG_UNHANDLED_EXCEPTION();
226 void OApplicationController::openTableFilterDialog()
228 openDialog( OUString( "com.sun.star.sdb.TableFilterDialog" ) );
231 void OApplicationController::refreshTables()
233 if ( getContainer() && getContainer()->getDetailView() )
235 WaitObject aWO(getView());
236 OSL_ENSURE(getContainer()->getElementType() == E_TABLE,"Only allowed when the tables container is selected!");
239 Reference<XRefreshable> xRefresh(getElements(E_TABLE),UNO_QUERY);
240 if ( xRefresh.is() )
241 xRefresh->refresh();
243 catch(const Exception&)
245 OSL_FAIL("Could not refresh tables!");
248 getContainer()->getDetailView()->clearPages(false);
249 getContainer()->getDetailView()->createTablesPage( ensureConnection() );
253 void OApplicationController::openDirectSQLDialog()
255 openDialog( SERVICE_SDB_DIRECTSQLDIALOG );
258 void SAL_CALL OApplicationController::propertyChange( const PropertyChangeEvent& evt ) throw (RuntimeException, std::exception)
260 SolarMutexGuard aSolarGuard;
261 ::osl::MutexGuard aGuard( getMutex() );
262 if ( evt.PropertyName == PROPERTY_USER )
264 m_bNeedToReconnect = true;
265 InvalidateFeature(SID_DB_APP_STATUS_USERNAME);
267 else if ( evt.PropertyName == PROPERTY_URL )
269 m_bNeedToReconnect = true;
270 InvalidateFeature(SID_DB_APP_STATUS_DBNAME);
271 InvalidateFeature(SID_DB_APP_STATUS_TYPE);
272 InvalidateFeature(SID_DB_APP_STATUS_HOSTNAME);
274 else if ( PROPERTY_NAME == evt.PropertyName )
276 const ElementType eType = getContainer()->getElementType();
277 if ( eType == E_FORM || eType == E_REPORT )
279 OUString sOldName,sNewName;
280 evt.OldValue >>= sOldName;
281 evt.NewValue >>= sNewName;
283 // if the old name is empty, then this is a newly inserted content. We're notified of it via the
284 // elementInserted method, so there's no need to handle it here.
286 if ( !sOldName.isEmpty() )
288 Reference<XChild> xChild(evt.Source,UNO_QUERY);
289 if ( xChild.is() )
291 Reference<XContent> xContent(xChild->getParent(),UNO_QUERY);
292 if ( xContent.is() )
293 sOldName = xContent->getIdentifier()->getContentIdentifier() + "/" + sOldName;
296 getContainer()->elementReplaced( eType , sOldName, sNewName );
301 EventObject aEvt;
302 aEvt.Source = m_xModel;
303 modified(aEvt);
306 Reference< XDataSource > SAL_CALL OApplicationController::getDataSource() throw (RuntimeException, std::exception)
308 ::osl::MutexGuard aGuard( getMutex() );
309 Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
310 return xDataSource;
313 Reference< XWindow > SAL_CALL OApplicationController::getApplicationMainWindow() throw (RuntimeException, std::exception)
315 ::osl::MutexGuard aGuard( getMutex() );
316 Reference< XFrame > xFrame( getFrame(), UNO_QUERY_THROW );
317 Reference< XWindow > xWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
318 return xWindow;
321 Sequence< Reference< XComponent > > SAL_CALL OApplicationController::getSubComponents() throw (RuntimeException, std::exception)
323 ::osl::MutexGuard aGuard( getMutex() );
324 return m_pSubComponentManager->getSubComponents();
327 Reference< XConnection > SAL_CALL OApplicationController::getActiveConnection() throw (RuntimeException, std::exception)
329 ::osl::MutexGuard aGuard( getMutex() );
330 return m_xDataSourceConnection.getTyped();
333 sal_Bool SAL_CALL OApplicationController::isConnected( ) throw (RuntimeException, std::exception)
335 ::osl::MutexGuard aGuard( getMutex() );
336 return m_xDataSourceConnection.is();
339 void SAL_CALL OApplicationController::connect( ) throw (SQLException, RuntimeException, std::exception)
341 SQLExceptionInfo aError;
342 SharedConnection xConnection = ensureConnection( &aError );
343 if ( !xConnection.is() )
345 if ( aError.isValid() )
346 aError.doThrow();
348 // no particular error, but nonetheless could not connect -> throw a generic exception
349 OUString sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE ) );
350 ::dbtools::throwGenericSQLException( sConnectingContext.replaceFirst( "$name$", getStrippedDatabaseName() ), *this );
354 beans::Pair< ::sal_Int32, OUString > SAL_CALL OApplicationController::identifySubComponent( const Reference< XComponent >& i_rSubComponent ) throw (IllegalArgumentException, RuntimeException, std::exception)
356 ::osl::MutexGuard aGuard( getMutex() );
358 sal_Int32 nType = -1;
359 OUString sName;
361 if ( !m_pSubComponentManager->lookupSubComponent( i_rSubComponent, sName, nType ) )
362 throw IllegalArgumentException( OUString(), *this, 1 );
364 if ( nType == SID_DB_APP_DSRELDESIGN )
365 // this is somewhat hacky ... we're expected to return a DatabaseObject value. However, there is no such
366 // value for the relation design. /me thinks we should change the API definition here ...
367 nType = -1;
369 return beans::Pair< ::sal_Int32, OUString >( nType, sName );
372 sal_Bool SAL_CALL OApplicationController::closeSubComponents( ) throw (RuntimeException, std::exception)
374 SolarMutexGuard aSolarGuard;
375 ::osl::MutexGuard aGuard( getMutex() );
376 return m_pSubComponentManager->closeSubComponents();
379 namespace
381 ElementType lcl_objectType2ElementType( const sal_Int32 _nObjectType )
383 ElementType eType( E_NONE );
384 switch ( _nObjectType )
386 case DatabaseObject::TABLE: eType = E_TABLE; break;
387 case DatabaseObject::QUERY: eType = E_QUERY; break;
388 case DatabaseObject::FORM: eType = E_FORM; break;
389 case DatabaseObject::REPORT: eType = E_REPORT; break;
390 default:
391 OSL_FAIL( "lcl_objectType2ElementType: unsupported object type!" );
392 // this should have been caught earlier
394 return eType;
398 void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::boost::optional< OUString >& i_rObjectName )
400 // ensure we're connected
401 if ( !isConnected() )
403 SQLError aError( getORB() );
404 aError.raiseException( ErrorCondition::DB_NOT_CONNECTED, *this );
407 // ensure a proper object type
408 if ( ( _nObjectType != DatabaseObject::TABLE )
409 && ( _nObjectType != DatabaseObject::QUERY )
410 && ( _nObjectType != DatabaseObject::FORM )
411 && ( _nObjectType != DatabaseObject::REPORT )
413 throw IllegalArgumentException( OUString(), *this, 1 );
415 if ( !i_rObjectName )
416 return;
418 // ensure an existing object
419 Reference< XNameAccess > xContainer( getElements( lcl_objectType2ElementType( _nObjectType ) ) );
420 if ( !xContainer.is() )
421 // all possible reasons for this (e.g. not being connected currently) should
422 // have been handled before
423 throw RuntimeException( OUString(), *this );
425 bool bExistentObject = false;
426 switch ( _nObjectType )
428 case DatabaseObject::TABLE:
429 case DatabaseObject::QUERY:
430 bExistentObject = xContainer->hasByName( *i_rObjectName );
431 break;
432 case DatabaseObject::FORM:
433 case DatabaseObject::REPORT:
435 Reference< XHierarchicalNameAccess > xHierarchy( xContainer, UNO_QUERY_THROW );
436 bExistentObject = xHierarchy->hasByHierarchicalName( *i_rObjectName );
438 break;
441 if ( !bExistentObject )
442 throw NoSuchElementException( *i_rObjectName, *this );
445 Reference< XComponent > SAL_CALL OApplicationController::loadComponent( ::sal_Int32 _ObjectType,
446 const OUString& _ObjectName, sal_Bool _ForEditing ) throw (IllegalArgumentException, NoSuchElementException, SQLException, RuntimeException, std::exception)
448 return loadComponentWithArguments( _ObjectType, _ObjectName, _ForEditing, Sequence< PropertyValue >() );
451 Reference< XComponent > SAL_CALL OApplicationController::loadComponentWithArguments( ::sal_Int32 _ObjectType,
452 const OUString& _ObjectName, sal_Bool _ForEditing, const Sequence< PropertyValue >& _Arguments ) throw (IllegalArgumentException, NoSuchElementException, SQLException, RuntimeException, std::exception)
454 SolarMutexGuard aSolarGuard;
455 ::osl::MutexGuard aGuard( getMutex() );
457 impl_validateObjectTypeAndName_throw( _ObjectType, _ObjectName );
459 Reference< XComponent > xComponent( openElementWithArguments(
460 _ObjectName,
461 lcl_objectType2ElementType( _ObjectType ),
462 _ForEditing ? E_OPEN_DESIGN : E_OPEN_NORMAL,
463 _ForEditing ? SID_DB_APP_EDIT : SID_DB_APP_OPEN,
464 ::comphelper::NamedValueCollection( _Arguments )
465 ) );
467 return xComponent;
470 Reference< XComponent > SAL_CALL OApplicationController::createComponent( ::sal_Int32 i_nObjectType, Reference< XComponent >& o_DocumentDefinition ) throw (IllegalArgumentException, SQLException, RuntimeException, std::exception)
472 return createComponentWithArguments( i_nObjectType, Sequence< PropertyValue >(), o_DocumentDefinition );
475 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)
477 SolarMutexGuard aSolarGuard;
478 ::osl::MutexGuard aGuard( getMutex() );
480 impl_validateObjectTypeAndName_throw( i_nObjectType, ::boost::optional< OUString >() );
482 Reference< XComponent > xComponent( newElement(
483 lcl_objectType2ElementType( i_nObjectType ),
484 ::comphelper::NamedValueCollection( i_rArguments ),
485 o_DocumentDefinition
486 ) );
488 return xComponent;
491 void SAL_CALL OApplicationController::registerContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException, std::exception)
493 if ( _Interceptor.is() )
494 m_aContextMenuInterceptors.addInterface( _Interceptor );
497 void SAL_CALL OApplicationController::releaseContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException, std::exception)
499 m_aContextMenuInterceptors.removeInterface( _Interceptor );
502 void OApplicationController::previewChanged( sal_Int32 _nMode )
504 SolarMutexGuard aSolarGuard;
505 ::osl::MutexGuard aGuard( getMutex() );
507 if ( m_xDataSource.is() && !isDataSourceReadOnly() )
511 ::comphelper::NamedValueCollection aLayoutInfo( m_xDataSource->getPropertyValue( PROPERTY_LAYOUTINFORMATION ) );
512 sal_Int32 nOldMode = aLayoutInfo.getOrDefault( "Preview", _nMode );
513 if ( nOldMode != _nMode )
515 aLayoutInfo.put( "Preview", _nMode );
516 m_xDataSource->setPropertyValue( PROPERTY_LAYOUTINFORMATION, makeAny( aLayoutInfo.getPropertyValues() ) );
519 catch ( const Exception& )
521 DBG_UNHANDLED_EXCEPTION();
524 InvalidateFeature(SID_DB_APP_DISABLE_PREVIEW);
525 InvalidateFeature(SID_DB_APP_VIEW_DOCINFO_PREVIEW);
526 InvalidateFeature(SID_DB_APP_VIEW_DOC_PREVIEW);
529 void OApplicationController::askToReconnect()
531 if ( m_bNeedToReconnect )
533 m_bNeedToReconnect = false;
534 bool bClear = true;
535 if ( !m_pSubComponentManager->empty() )
537 ScopedVclPtrInstance< MessageDialog > aQry(getView(), ModuleRes(STR_QUERY_CLOSEDOCUMENTS), VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
538 switch (aQry->Execute())
540 case RET_YES:
541 closeSubComponents();
542 break;
543 default:
544 bClear = false;
545 break;
548 if ( bClear )
550 ElementType eType = getContainer()->getElementType();
551 disconnect();
552 getContainer()->getDetailView()->clearPages(false);
553 getContainer()->selectContainer(E_NONE); // invalidate the old selection
554 m_eCurrentType = E_NONE;
555 getContainer()->selectContainer(eType); // reselect the current one again
560 OUString OApplicationController::getDatabaseName() const
562 OUString sDatabaseName;
565 if ( m_xDataSource.is() )
567 OSL_VERIFY( m_xDataSource->getPropertyValue( PROPERTY_NAME ) >>= sDatabaseName );
570 catch ( const Exception& )
572 DBG_UNHANDLED_EXCEPTION();
574 return sDatabaseName;
577 OUString OApplicationController::getStrippedDatabaseName() const
579 OUString sDatabaseName;
580 return ::dbaui::getStrippedDatabaseName( m_xDataSource, sDatabaseName );
583 void OApplicationController::onDocumentOpened( const OUString& _rName, const sal_Int32 _nType,
584 const ElementOpenMode _eMode, const Reference< XComponent >& _xDocument, const Reference< XComponent >& _rxDefinition )
586 if ( !_xDocument.is() )
587 return;
591 OSL_ENSURE( _xDocument.is(), "OApplicationController::onDocumentOpened: is there any *valid* scenario where this fails?" );
592 m_pSubComponentManager->onSubComponentOpened( _rName, _nType, _eMode, _xDocument.is() ? _xDocument : _rxDefinition );
594 if ( _rxDefinition.is() )
596 Reference< XPropertySet > xProp( _rxDefinition, UNO_QUERY_THROW );
597 Reference< XPropertySetInfo > xPSI( xProp->getPropertySetInfo(), UNO_SET_THROW );
598 xProp->addPropertyChangeListener( PROPERTY_NAME, static_cast< XPropertyChangeListener* >( this ) );
601 catch( const Exception& )
603 DBG_UNHANDLED_EXCEPTION();
607 bool OApplicationController::insertHierachyElement(ElementType _eType, const OUString& _sParentFolder, bool _bCollection, const Reference<XContent>& _xContent, bool _bMove)
609 Reference<XHierarchicalNameContainer> xNames(getElements(_eType), UNO_QUERY);
610 return dbaui::insertHierachyElement(getView()
611 ,getORB()
612 ,xNames
613 ,_sParentFolder
614 ,_eType == E_FORM
615 ,_bCollection
616 ,_xContent
617 ,_bMove);
620 bool OApplicationController::isRenameDeleteAllowed(ElementType _eType, bool _bDelete) const
622 ElementType eType = getContainer()->getElementType();
623 bool bEnabled = !isDataSourceReadOnly() && eType == _eType;
624 if ( bEnabled )
627 if ( E_TABLE == eType )
628 bEnabled = !isConnectionReadOnly() && getContainer()->isALeafSelected();
630 bool bCompareRes = false;
631 if ( _bDelete )
632 bCompareRes = getContainer()->getSelectionCount() > 0;
633 else
635 bCompareRes = getContainer()->getSelectionCount() == 1;
636 if ( bEnabled && bCompareRes && E_TABLE == eType )
638 ::std::vector< OUString> aList;
639 getSelectionElementNames(aList);
643 Reference< XNameAccess > xContainer = const_cast<OApplicationController*>(this)->getElements(eType);
644 bEnabled = (xContainer.is() && xContainer->hasByName(*aList.begin()));
645 if ( bEnabled )
646 bEnabled = Reference<XRename>(xContainer->getByName(*aList.begin()),UNO_QUERY).is();
648 catch(Exception&)
650 bEnabled = false;
655 bEnabled = bEnabled && bCompareRes;
657 return bEnabled;
660 void OApplicationController::onLoadedMenu(const Reference< ::com::sun::star::frame::XLayoutManager >& _xLayoutManager)
663 if ( _xLayoutManager.is() )
665 static const char s_sStatusbar[] = "private:resource/statusbar/statusbar";
666 _xLayoutManager->createElement( s_sStatusbar );
667 _xLayoutManager->requestElement( s_sStatusbar );
669 if ( getContainer() )
671 // we need to share the "mnemonic space":
672 MnemonicGenerator aMnemonicGenerator;
673 // - the menu already has mnemonics
674 SystemWindow* pSystemWindow = getContainer()->GetSystemWindow();
675 MenuBar* pMenu = pSystemWindow ? pSystemWindow->GetMenuBar() : NULL;
676 if ( pMenu )
678 sal_uInt16 nMenuItems = pMenu->GetItemCount();
679 for ( sal_uInt16 i = 0; i < nMenuItems; ++i )
680 aMnemonicGenerator.RegisterMnemonic( pMenu->GetItemText( pMenu->GetItemId( i ) ) );
682 // - the icons should use automatic ones
683 getContainer()->createIconAutoMnemonics( aMnemonicGenerator );
684 // - as well as the entries in the task pane
685 getContainer()->setTaskExternalMnemonics( aMnemonicGenerator );
688 Execute( SID_DB_APP_VIEW_FORMS, Sequence< PropertyValue >() );
689 InvalidateAll();
693 void OApplicationController::doAction(sal_uInt16 _nId, const ElementOpenMode _eOpenMode)
695 ::std::vector< OUString> aList;
696 getSelectionElementNames(aList);
697 ElementType eType = getContainer()->getElementType();
698 ::comphelper::NamedValueCollection aArguments;
699 ElementOpenMode eOpenMode = _eOpenMode;
700 if ( eType == E_REPORT && E_OPEN_FOR_MAIL == _eOpenMode )
702 aArguments.put("Hidden",true);
703 eOpenMode = E_OPEN_NORMAL;
706 ::std::vector< ::std::pair< OUString ,Reference< XModel > > > aCompoments;
707 ::std::vector< OUString>::iterator aEnd = aList.end();
708 for (::std::vector< OUString>::iterator aIter = aList.begin(); aIter != aEnd; ++aIter)
710 if ( SID_DB_APP_CONVERTTOVIEW == _nId )
711 convertToView(*aIter);
712 else
714 Reference< XModel > xModel( openElementWithArguments( *aIter, eType, eOpenMode, _nId,aArguments ), UNO_QUERY );
715 aCompoments.push_back( ::std::pair< OUString, Reference< XModel > >( *aIter, xModel ) );
719 // special handling for mail, if more than one document is selected attach them all
720 if ( _eOpenMode == E_OPEN_FOR_MAIL )
723 ::std::vector< ::std::pair< OUString ,Reference< XModel > > >::iterator componentIter = aCompoments.begin();
724 ::std::vector< ::std::pair< OUString ,Reference< XModel > > >::iterator componentEnd = aCompoments.end();
725 OUString aDocTypeString;
726 SfxMailModel aSendMail;
727 SfxMailModel::SendMailResult eResult = SfxMailModel::SEND_MAIL_OK;
728 for (; componentIter != componentEnd && SfxMailModel::SEND_MAIL_OK == eResult; ++componentIter)
732 Reference< XModel > xModel(componentIter->second,UNO_QUERY);
734 // Send document as e-Mail using stored/default type
735 eResult = aSendMail.AttachDocument(aDocTypeString,xModel,componentIter->first);
736 ::comphelper::disposeComponent(xModel);
738 catch(const Exception&)
740 DBG_UNHANDLED_EXCEPTION();
743 if ( !aSendMail.IsEmpty() )
744 aSendMail.Send( getFrame() );
748 ElementType OApplicationController::getElementType(const Reference< XContainer >& _xContainer)
750 ElementType eRet = E_NONE;
751 Reference<XServiceInfo> xServiceInfo(_xContainer,UNO_QUERY);
752 if ( xServiceInfo.is() )
754 if ( xServiceInfo->supportsService(SERVICE_SDBCX_TABLES) )
755 eRet = E_TABLE;
756 else if ( xServiceInfo->supportsService(SERVICE_NAME_FORM_COLLECTION) )
757 eRet = E_FORM;
758 else if ( xServiceInfo->supportsService(SERVICE_NAME_REPORT_COLLECTION) )
759 eRet = E_REPORT;
760 else
761 eRet = E_QUERY;
763 return eRet;
766 } // namespace dbaui
768 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */