bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / ui / app / AppController.cxx
blob7655b70eab7b859ee721c8ba4590a21c3e18a72e
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 .
21 #include "AppController.hxx"
22 #include "dbustrings.hrc"
23 #include "advancedsettingsdlg.hxx"
24 #include "subcomponentmanager.hxx"
26 #include <com/sun/star/beans/NamedValue.hpp>
27 #include <com/sun/star/container/XChild.hpp>
28 #include <com/sun/star/container/XContainer.hpp>
29 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
30 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
31 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
32 #include <com/sun/star/container/XNameContainer.hpp>
33 #include <com/sun/star/frame/FrameSearchFlag.hpp>
34 #include <com/sun/star/frame/XStorable.hpp>
35 #include <com/sun/star/sdb/CommandType.hpp>
36 #include <com/sun/star/sdb/ErrorMessageDialog.hpp>
37 #include <com/sun/star/sdb/SQLContext.hpp>
38 #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
39 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
40 #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
41 #include <com/sun/star/sdbc/XDataSource.hpp>
42 #include <com/sun/star/sdbcx/XAlterView.hpp>
43 #include <com/sun/star/sdbcx/XAppend.hpp>
44 #include <com/sun/star/sdbcx/XRename.hpp>
45 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
46 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
47 #include <com/sun/star/sdb/application/MacroMigrationWizard.hpp>
48 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
49 #include <com/sun/star/uno/XNamingService.hpp>
50 #include <com/sun/star/util/XFlushable.hpp>
51 #include <com/sun/star/util/XModifiable.hpp>
52 #include <com/sun/star/util/XModifyBroadcaster.hpp>
53 #include <com/sun/star/util/XNumberFormatter.hpp>
54 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
55 #include <com/sun/star/document/XEmbeddedScripts.hpp>
56 #include <com/sun/star/frame/XModel2.hpp>
57 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
58 #include "com/sun/star/beans/NamedValue.hpp"
59 #include <com/sun/star/awt/XTopWindow.hpp>
60 #include <com/sun/star/task/XInteractionHandler.hpp>
61 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
62 #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
63 #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
64 #include <com/sun/star/container/XHierarchicalName.hpp>
65 #include <tools/diagnose_ex.h>
66 #include <osl/diagnose.h>
67 #include <tools/string.hxx>
69 #include <svl/urihelper.hxx>
70 #include <svl/filenotation.hxx>
71 #include <svtools/treelistbox.hxx>
72 #include <svtools/transfer.hxx>
73 #include <svtools/cliplistener.hxx>
74 #include <svtools/svlbitm.hxx>
75 #include <svtools/insdlg.hxx>
77 #include <comphelper/sequence.hxx>
78 #include <comphelper/uno3.hxx>
79 #include <comphelper/types.hxx>
80 #include <comphelper/interaction.hxx>
81 #include <comphelper/processfactory.hxx>
83 #include <vcl/msgbox.hxx>
84 #include <vcl/stdtext.hxx>
85 #include <vcl/svapp.hxx>
86 #include <vcl/menu.hxx>
87 #include <vcl/lstbox.hxx>
89 #include <unotools/closeveto.hxx>
90 #include <unotools/pathoptions.hxx>
91 #include <unotools/tempfile.hxx>
92 #include <unotools/moduleoptions.hxx>
93 #include <unotools/historyoptions.hxx>
95 #include <sfx2/mailmodelapi.hxx>
96 #include <sfx2/filedlghelper.hxx>
97 #include <sfx2/docfilt.hxx>
98 #include <sfx2/QuerySaveDocument.hxx>
100 #include <cppuhelper/typeprovider.hxx>
101 #include <cppuhelper/exc_hlp.hxx>
103 #include <connectivity/dbtools.hxx>
104 #include <connectivity/dbexception.hxx>
106 #include <svx/dbaexchange.hxx>
107 #include <svx/dbaobjectex.hxx>
108 #include <svx/svxdlg.hxx>
110 #include <osl/mutex.hxx>
111 #include "AppView.hxx"
112 #include "browserids.hxx"
113 #include "dbu_reghelper.hxx"
114 #include "dbu_app.hrc"
115 #include "defaultobjectnamecheck.hxx"
116 #include "databaseobjectview.hxx"
117 #include "listviewitems.hxx"
118 #include "AppDetailView.hxx"
119 #include "linkeddocuments.hxx"
120 #include "sqlmessage.hxx"
121 #include "UITools.hxx"
122 #include "dsntypes.hxx"
123 #include "dbaccess_helpid.hrc"
124 #include "dlgsave.hxx"
125 #include "dbaccess_slotid.hrc"
127 #include <algorithm>
128 #include <functional>
130 #include <boost/noncopyable.hpp>
132 extern "C" void SAL_CALL createRegistryInfo_ODBApplication()
134 static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OApplicationController > aAutoRegistration;
136 //........................................................................
137 namespace dbaui
139 //........................................................................
140 using namespace ::dbtools;
141 using namespace ::svx;
142 using namespace ::com::sun::star;
143 using namespace ::com::sun::star::uno;
144 using namespace ::com::sun::star::ucb;
145 using namespace ::com::sun::star::view;
146 using namespace ::com::sun::star::util;
147 using namespace ::com::sun::star::beans;
148 using namespace ::com::sun::star::lang;
149 using namespace ::com::sun::star::frame;
150 using namespace ::com::sun::star::container;
151 using namespace ::com::sun::star::sdb;
152 using namespace ::com::sun::star::sdbc;
153 using namespace ::com::sun::star::sdbcx;
154 using namespace ::com::sun::star::datatransfer;
155 using namespace ::com::sun::star::ui::dialogs;
156 using namespace ::com::sun::star::task;
157 using ::com::sun::star::document::XEmbeddedScripts;
158 using ::com::sun::star::document::XDocumentEventBroadcaster;
159 using ::com::sun::star::document::DocumentEvent;
160 using ::com::sun::star::sdb::application::NamedDatabaseObject;
162 namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
163 namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
165 //------------------------------------------------------------------------------
166 OUString SAL_CALL OApplicationController::getImplementationName() throw( RuntimeException )
168 return getImplementationName_Static();
171 //------------------------------------------------------------------------------
172 OUString OApplicationController::getImplementationName_Static() throw( RuntimeException )
174 return OUString(SERVICE_SDB_APPLICATIONCONTROLLER);
176 //------------------------------------------------------------------------------
177 Sequence< OUString> OApplicationController::getSupportedServiceNames_Static(void) throw( RuntimeException )
179 Sequence< OUString> aSupported(1);
180 aSupported.getArray()[0] = OUString("com.sun.star.sdb.application.DefaultViewController");
181 return aSupported;
183 //-------------------------------------------------------------------------
184 Sequence< OUString> SAL_CALL OApplicationController::getSupportedServiceNames() throw(RuntimeException)
186 return getSupportedServiceNames_Static();
188 // -------------------------------------------------------------------------
189 Reference< XInterface > SAL_CALL OApplicationController::Create(const Reference<XMultiServiceFactory >& _rxFactory)
191 return *(new OApplicationController( comphelper::getComponentContext(_rxFactory)));
193 // -----------------------------------------------------------------------------
195 struct XContainerFunctor : public ::std::unary_function< OApplicationController::TContainerVector::value_type , bool>
197 Reference<XContainerListener> m_xContainerListener;
198 XContainerFunctor( const Reference<XContainerListener>& _xContainerListener)
199 : m_xContainerListener(_xContainerListener){}
201 bool operator() (const OApplicationController::TContainerVector::value_type& lhs) const
203 if ( lhs.is() )
204 lhs->removeContainerListener(m_xContainerListener);
205 return true;
209 //====================================================================
210 //= OApplicationController
211 //====================================================================
212 class SelectionNotifier : public ::boost::noncopyable
214 private:
215 ::cppu::OInterfaceContainerHelper m_aSelectionListeners;
216 ::cppu::OWeakObject& m_rContext;
217 sal_Int32 m_nSelectionNestingLevel;
219 public:
220 SelectionNotifier( ::osl::Mutex& _rMutex, ::cppu::OWeakObject& _rContext )
221 :m_aSelectionListeners( _rMutex )
222 ,m_rContext( _rContext )
223 ,m_nSelectionNestingLevel( 0 )
227 void addListener( const Reference< XSelectionChangeListener >& _Listener )
229 m_aSelectionListeners.addInterface( _Listener );
232 void removeListener( const Reference< XSelectionChangeListener >& _Listener )
234 m_aSelectionListeners.removeInterface( _Listener );
237 void disposing()
239 EventObject aEvent( m_rContext );
240 m_aSelectionListeners.disposeAndClear( aEvent );
243 ~SelectionNotifier()
247 struct SelectionGuardAccess { friend class SelectionGuard; private: SelectionGuardAccess() { } };
249 /** enters a block which modifies the selection of our owner.
251 Can be called multiple times, the only important thing is to call leaveSelection
252 equally often.
254 void enterSelection( SelectionGuardAccess )
256 ++m_nSelectionNestingLevel;
259 /** leaves a block which modifies the selection of our owner
261 Must be paired with enterSelection calls.
263 When the last block is left, i.e. the last leaveSelection call is made on the current stack,
264 then our SelectionChangeListeners are notified
266 void leaveSelection( SelectionGuardAccess )
268 if ( --m_nSelectionNestingLevel == 0 )
270 EventObject aEvent( m_rContext );
271 m_aSelectionListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aEvent );
276 class SelectionGuard : public ::boost::noncopyable
278 public:
279 SelectionGuard( SelectionNotifier& _rNotifier )
280 :m_rNotifier( _rNotifier )
282 m_rNotifier.enterSelection( SelectionNotifier::SelectionGuardAccess() );
285 ~SelectionGuard()
287 m_rNotifier.leaveSelection( SelectionNotifier::SelectionGuardAccess() );
290 private:
291 SelectionNotifier& m_rNotifier;
294 //====================================================================
295 //= OApplicationController
296 //====================================================================
297 DBG_NAME(OApplicationController)
298 //--------------------------------------------------------------------
299 OApplicationController::OApplicationController(const Reference< XComponentContext >& _rxORB)
300 :OApplicationController_CBASE( _rxORB )
301 ,m_aContextMenuInterceptors( getMutex() )
302 ,m_pSubComponentManager( new SubComponentManager( *this, getSharedMutex() ) )
303 ,m_aTypeCollection( _rxORB )
304 ,m_aTableCopyHelper(this)
305 ,m_pClipbordNotifier(NULL)
306 ,m_nAsyncDrop(0)
307 ,m_aSelectContainerEvent( LINK( this, OApplicationController, OnSelectContainer ) )
308 ,m_ePreviewMode(E_PREVIEWNONE)
309 ,m_eCurrentType(E_NONE)
310 ,m_bNeedToReconnect(sal_False)
311 ,m_bSuspended( sal_False )
312 ,m_pSelectionNotifier( new SelectionNotifier( getMutex(), *this ) )
314 DBG_CTOR(OApplicationController,NULL);
316 //------------------------------------------------------------------------------
317 OApplicationController::~OApplicationController()
319 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
321 OSL_FAIL("Please check who doesn't dispose this component!");
322 // increment ref count to prevent double call of Dtor
323 osl_atomic_increment( &m_refCount );
324 dispose();
326 SAL_WNODEPRECATED_DECLARATIONS_PUSH
327 ::std::auto_ptr< Window> aTemp( getView() );
328 SAL_WNODEPRECATED_DECLARATIONS_POP
329 clearView();
331 DBG_DTOR(OApplicationController,NULL);
333 //--------------------------------------------------------------------
334 IMPLEMENT_FORWARD_XTYPEPROVIDER2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
335 IMPLEMENT_FORWARD_XINTERFACE2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
336 // -----------------------------------------------------------------------------
337 void OApplicationController::disconnect()
339 if ( m_xDataSourceConnection.is() )
340 stopConnectionListening( m_xDataSourceConnection );
344 // temporary (hopefully!) hack for #i55274#
345 Reference< XFlushable > xFlush( m_xDataSourceConnection, UNO_QUERY );
346 if ( xFlush.is() && m_xMetaData.is() && !m_xMetaData->isReadOnly() )
347 xFlush->flush();
349 catch( const Exception& )
351 DBG_UNHANDLED_EXCEPTION();
354 m_xDataSourceConnection.clear();
355 m_xMetaData.clear();
357 InvalidateAll();
360 //--------------------------------------------------------------------
361 void SAL_CALL OApplicationController::disposing()
363 ::std::for_each(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),XContainerFunctor(this));
364 m_aCurrentContainers.clear();
365 m_pSubComponentManager->disposing();
366 m_pSelectionNotifier->disposing();
368 if ( getView() )
370 getContainer()->showPreview(NULL);
371 m_pClipbordNotifier->ClearCallbackLink();
372 m_pClipbordNotifier->AddRemoveListener( getView(), sal_False );
373 m_pClipbordNotifier->release();
374 m_pClipbordNotifier = NULL;
377 disconnect();
380 Reference < XFrame > xFrame;
381 attachFrame( xFrame );
383 if ( m_xDataSource.is() )
385 m_xDataSource->removePropertyChangeListener(OUString(), this);
386 m_xDataSource->removePropertyChangeListener(PROPERTY_INFO, this);
387 m_xDataSource->removePropertyChangeListener(PROPERTY_URL, this);
388 m_xDataSource->removePropertyChangeListener(PROPERTY_ISPASSWORDREQUIRED, this);
389 m_xDataSource->removePropertyChangeListener(PROPERTY_LAYOUTINFORMATION, this);
390 m_xDataSource->removePropertyChangeListener(PROPERTY_SUPPRESSVERSIONCL, this);
391 m_xDataSource->removePropertyChangeListener(PROPERTY_TABLEFILTER, this);
392 m_xDataSource->removePropertyChangeListener(PROPERTY_TABLETYPEFILTER, this);
393 m_xDataSource->removePropertyChangeListener(PROPERTY_USER, this);
394 // otherwise we may delete our datasource twice
395 Reference<XPropertySet> xProp = m_xDataSource;
396 m_xDataSource = NULL;
399 Reference< XModifyBroadcaster > xBroadcaster( m_xModel, UNO_QUERY );
400 if ( xBroadcaster.is() )
401 xBroadcaster->removeModifyListener(static_cast<XModifyListener*>(this));
403 if ( m_xModel.is() )
405 OUString sUrl = m_xModel->getURL();
406 if ( !sUrl.isEmpty() )
408 ::comphelper::NamedValueCollection aArgs( m_xModel->getArgs() );
409 if ( true == aArgs.getOrDefault( "PickListEntry", true ) )
411 OUString aFilter;
412 INetURLObject aURL( m_xModel->getURL() );
413 const SfxFilter* pFilter = getStandardDatabaseFilter();
414 if ( pFilter )
415 aFilter = pFilter->GetFilterName();
417 // add to svtool history options
418 SvtHistoryOptions().AppendItem( ePICKLIST,
419 aURL.GetURLNoPass( INetURLObject::NO_DECODE ),
420 aFilter,
421 getStrippedDatabaseName(),
422 OUString() );
424 // add to recent document list
425 if ( aURL.GetProtocol() == INET_PROT_FILE )
426 Application::AddToRecentDocumentList( aURL.GetURLNoPass( INetURLObject::NO_DECODE ),
427 (pFilter) ? pFilter->GetMimeType() : OUString(),
428 (pFilter) ? pFilter->GetServiceName() : OUString() );
432 m_xModel->disconnectController( this );
434 m_xModel.clear();
437 catch(const Exception&)
439 DBG_UNHANDLED_EXCEPTION();
442 clearView();
443 OApplicationController_CBASE::disposing(); // here the m_refCount must be equal 5
446 //--------------------------------------------------------------------
447 sal_Bool OApplicationController::Construct(Window* _pParent)
449 setView( * new OApplicationView( _pParent, getORB(), *this, m_ePreviewMode ) );
450 getView()->SetUniqueId(UID_APP_VIEW);
452 // late construction
453 sal_Bool bSuccess = sal_False;
456 getContainer()->Construct();
457 bSuccess = sal_True;
459 catch(const SQLException&)
462 catch(const Exception&)
464 OSL_FAIL("OApplicationController::Construct : the construction of UnoDataBrowserView failed !");
467 if ( !bSuccess )
469 SAL_WNODEPRECATED_DECLARATIONS_PUSH
470 ::std::auto_ptr< Window> aTemp( getView() );
471 SAL_WNODEPRECATED_DECLARATIONS_POP
472 clearView();
473 return sal_False;
476 // now that we have a view we can create the clipboard listener
477 m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( getView() );
478 m_aSystemClipboard.StartClipboardListening( );
480 m_pClipbordNotifier = new TransferableClipboardListener( LINK( this, OApplicationController, OnClipboardChanged ) );
481 m_pClipbordNotifier->acquire();
482 m_pClipbordNotifier->AddRemoveListener( getView(), sal_True );
484 OApplicationController_CBASE::Construct( _pParent );
485 getView()->Show();
487 return sal_True;
490 //--------------------------------------------------------------------
491 void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) throw( RuntimeException )
493 ::osl::MutexGuard aGuard( getMutex() );
494 Reference<XConnection> xCon(_rSource.Source, UNO_QUERY);
495 if ( xCon.is() )
497 OSL_ENSURE( m_xDataSourceConnection == xCon,
498 "OApplicationController::disposing: which connection does this come from?" );
500 if ( getContainer() && getContainer()->getElementType() == E_TABLE )
501 getContainer()->clearPages();
502 if ( m_xDataSourceConnection == xCon )
504 m_xMetaData.clear();
505 m_xDataSourceConnection.clear();
508 else if ( _rSource.Source == m_xModel )
510 m_xModel.clear();
512 else if ( _rSource.Source == m_xDataSource )
514 m_xDataSource = NULL;
516 else
518 Reference<XContainer> xContainer( _rSource.Source, UNO_QUERY );
519 if ( xContainer.is() )
521 TContainerVector::iterator aFind = ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer);
522 if ( aFind != m_aCurrentContainers.end() )
523 m_aCurrentContainers.erase(aFind);
525 OApplicationController_CBASE::disposing( _rSource );
528 //--------------------------------------------------------------------
529 sal_Bool SAL_CALL OApplicationController::suspend(sal_Bool bSuspend) throw( RuntimeException )
531 // notify the OnPrepareViewClosing event (before locking any mutex)
532 Reference< XDocumentEventBroadcaster > xBroadcaster( m_xModel, UNO_QUERY );
533 if ( xBroadcaster.is() )
535 xBroadcaster->notifyDocumentEvent(
536 OUString("OnPrepareViewClosing"),
537 this,
538 Any()
542 SolarMutexGuard aSolarGuard;
543 ::osl::MutexGuard aGuard( getMutex() );
545 if ( getView() && getView()->IsInModalMode() )
546 return sal_False;
548 sal_Bool bCanSuspend = sal_True;
550 if ( m_bSuspended != bSuspend )
552 if ( bSuspend && !closeSubComponents() )
553 return sal_False;
555 Reference<XModifiable> xModi(m_xModel,UNO_QUERY);
556 Reference<XStorable> xStor(getModel(),UNO_QUERY);
558 if ( bSuspend
559 && xStor.is()
560 && !xStor->isReadonly()
561 && ( xModi.is()
562 && xModi->isModified()
566 switch (ExecuteQuerySaveDocument(getView(),getStrippedDatabaseName()))
568 case RET_YES:
569 Execute(ID_BROWSER_SAVEDOC,Sequence<PropertyValue>());
570 bCanSuspend = !xModi->isModified();
571 // when we save the document this must be false else some press cancel
572 break;
573 case RET_CANCEL:
574 bCanSuspend = sal_False;
575 default:
576 break;
581 if ( bCanSuspend )
582 m_bSuspended = bSuspend;
584 return bCanSuspend;
586 // -----------------------------------------------------------------------------
587 FeatureState OApplicationController::GetState(sal_uInt16 _nId) const
589 FeatureState aReturn;
590 aReturn.bEnabled = sal_False;
591 // check this first
592 if ( !getContainer() || m_bReadOnly )
593 return aReturn;
597 switch (_nId)
599 case SID_OPENURL:
600 aReturn.bEnabled = sal_True;
601 if ( m_xModel.is() )
602 aReturn.sTitle = m_xModel->getURL();
603 break;
604 case ID_BROWSER_COPY:
606 sal_Int32 nCount = getContainer()->getSelectionCount();
607 aReturn.bEnabled = nCount >= 1;
608 if ( aReturn.bEnabled && nCount == 1 && getContainer()->getElementType() == E_TABLE )
609 aReturn.bEnabled = getContainer()->isALeafSelected();
611 break;
612 case ID_BROWSER_CUT:
613 aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() >= 1;
614 aReturn.bEnabled = aReturn.bEnabled && ( (ID_BROWSER_CUT == _nId && getContainer()->getElementType() == E_TABLE) ? getContainer()->isCutAllowed() : sal_True);
615 break;
616 case ID_BROWSER_PASTE:
617 switch( getContainer()->getElementType() )
619 case E_TABLE:
620 aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly() && isTableFormat();
621 break;
622 case E_QUERY:
623 aReturn.bEnabled = !isDataSourceReadOnly() && getViewClipboard().HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY);
624 break;
625 default:
626 aReturn.bEnabled = !isDataSourceReadOnly() && OComponentTransferable::canExtractComponentDescriptor(getViewClipboard().GetDataFlavorExVector(),getContainer()->getElementType() == E_FORM);
628 break;
629 case SID_DB_APP_PASTE_SPECIAL:
630 aReturn.bEnabled = getContainer()->getElementType() == E_TABLE && !isDataSourceReadOnly() && !isConnectionReadOnly() && isTableFormat();
631 break;
632 case SID_OPENDOC:
633 case SID_HELP_INDEX:
634 aReturn.bEnabled = sal_True;
635 break;
636 case ID_BROWSER_SAVEDOC:
637 aReturn.bEnabled = !isDataSourceReadOnly() && m_xDocumentModify.is() && m_xDocumentModify->isModified();
638 break;
639 case ID_BROWSER_SAVEASDOC:
640 aReturn.bEnabled = sal_True;
641 break;
642 case ID_BROWSER_SORTUP:
643 aReturn.bEnabled = getContainer()->isFilled() && getContainer()->getElementCount();
644 aReturn.bChecked = aReturn.bEnabled && getContainer()->isSortUp();
645 break;
646 case ID_BROWSER_SORTDOWN:
647 aReturn.bEnabled = getContainer()->isFilled() && getContainer()->getElementCount();
648 aReturn.bChecked = aReturn.bEnabled && !getContainer()->isSortUp();
649 break;
651 case SID_NEWDOC:
652 case SID_APP_NEW_FORM:
653 case ID_DOCUMENT_CREATE_REPWIZ:
654 aReturn.bEnabled = !isDataSourceReadOnly() && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER);
655 break;
656 case SID_APP_NEW_REPORT:
657 aReturn.bEnabled = !isDataSourceReadOnly()
658 && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER);
659 if ( aReturn.bEnabled )
661 Reference< XContentEnumerationAccess > xEnumAccess(m_xContext->getServiceManager(), UNO_QUERY);
662 aReturn.bEnabled = xEnumAccess.is();
663 if ( aReturn.bEnabled )
665 const OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_xContext);
666 aReturn.bEnabled = !sReportEngineServiceName.isEmpty();
667 if ( aReturn.bEnabled )
669 const Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(sReportEngineServiceName);
670 aReturn.bEnabled = xEnumDrivers.is() && xEnumDrivers->hasMoreElements();
674 break;
675 case SID_DB_APP_VIEW_TABLES:
676 aReturn.bEnabled = sal_True;
677 aReturn.bChecked = getContainer()->getElementType() == E_TABLE;
678 break;
679 case SID_DB_APP_VIEW_QUERIES:
680 aReturn.bEnabled = sal_True;
681 aReturn.bChecked = getContainer()->getElementType() == E_QUERY;
682 break;
683 case SID_DB_APP_VIEW_FORMS:
684 aReturn.bEnabled = sal_True;
685 aReturn.bChecked = getContainer()->getElementType() == E_FORM;
686 break;
687 case SID_DB_APP_VIEW_REPORTS:
688 aReturn.bEnabled = sal_True;
689 aReturn.bChecked = getContainer()->getElementType() == E_REPORT;
690 break;
691 case ID_NEW_QUERY_DESIGN:
692 case ID_NEW_QUERY_SQL:
693 case ID_APP_NEW_QUERY_AUTO_PILOT:
694 case SID_DB_FORM_NEW_PILOT:
695 aReturn.bEnabled = !isDataSourceReadOnly();
696 break;
697 case ID_NEW_VIEW_DESIGN:
698 case SID_DB_NEW_VIEW_SQL:
699 case ID_NEW_VIEW_DESIGN_AUTO_PILOT:
700 aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly();
701 if ( aReturn.bEnabled )
703 Reference<XViewsSupplier> xViewsSup( getConnection(), UNO_QUERY );
704 aReturn.bEnabled = xViewsSup.is();
706 break;
707 case ID_NEW_TABLE_DESIGN:
708 case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
709 aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly();
710 break;
711 case ID_DIRECT_SQL:
712 aReturn.bEnabled = sal_True;
713 break;
714 case ID_MIGRATE_SCRIPTS:
716 // Our document supports embedding scripts into it, if and only if there are no
717 // forms/reports with macros/scripts into them. So, we need to enable migration
718 // if and only if the database document does *not* support embedding scripts.
719 bool bAvailable =
720 !Reference< XEmbeddedScripts >( m_xModel, UNO_QUERY ).is()
721 && !Reference< XStorable >( m_xModel, UNO_QUERY_THROW )->isReadonly();
722 aReturn.bEnabled = bAvailable;
723 if ( !bAvailable )
724 aReturn.bInvisible = true;
726 break;
727 case SID_APP_NEW_FOLDER:
728 aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() <= 1;
729 if ( aReturn.bEnabled )
731 const ElementType eType = getContainer()->getElementType();
732 aReturn.bEnabled = eType == E_REPORT || eType == E_FORM;
734 break;
735 case SID_FORM_CREATE_REPWIZ_PRE_SEL:
736 case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
737 case SID_APP_NEW_REPORT_PRE_SEL:
738 aReturn.bEnabled = !isDataSourceReadOnly()
739 && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER)
740 && getContainer()->isALeafSelected();
741 if ( aReturn.bEnabled )
743 ElementType eType = getContainer()->getElementType();
744 aReturn.bEnabled = eType == E_QUERY || eType == E_TABLE;
745 if ( aReturn.bEnabled && SID_APP_NEW_REPORT_PRE_SEL == _nId )
747 Reference< XContentEnumerationAccess > xEnumAccess(m_xContext->getServiceManager(), UNO_QUERY);
748 aReturn.bEnabled = xEnumAccess.is();
749 if ( aReturn.bEnabled )
751 static OUString s_sReportDesign("org.libreoffice.report.pentaho.SOReportJobFactory");
752 Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(s_sReportDesign);
753 aReturn.bEnabled = xEnumDrivers.is() && xEnumDrivers->hasMoreElements();
757 break;
758 case SID_DB_APP_DELETE:
759 case SID_DB_APP_RENAME:
760 aReturn.bEnabled = isRenameDeleteAllowed(getContainer()->getElementType(), _nId == SID_DB_APP_DELETE);
761 break;
762 case SID_DB_APP_TABLE_DELETE:
763 case SID_DB_APP_TABLE_RENAME:
764 aReturn.bEnabled = isRenameDeleteAllowed(E_TABLE, _nId == SID_DB_APP_TABLE_DELETE);
765 break;
766 case SID_DB_APP_QUERY_DELETE:
767 case SID_DB_APP_QUERY_RENAME:
768 aReturn.bEnabled = isRenameDeleteAllowed(E_QUERY, _nId == SID_DB_APP_QUERY_DELETE);
769 break;
770 case SID_DB_APP_FORM_DELETE:
771 case SID_DB_APP_FORM_RENAME:
772 aReturn.bEnabled = isRenameDeleteAllowed(E_FORM, _nId == SID_DB_APP_FORM_DELETE);
773 break;
774 case SID_DB_APP_REPORT_DELETE:
775 case SID_DB_APP_REPORT_RENAME:
776 aReturn.bEnabled = isRenameDeleteAllowed(E_REPORT, _nId == SID_DB_APP_REPORT_DELETE);
777 break;
779 case SID_SELECTALL:
780 aReturn.bEnabled = getContainer()->getElementCount() > 0 && getContainer()->getSelectionCount() != getContainer()->getElementCount();
781 break;
782 case SID_DB_APP_EDIT:
783 case SID_DB_APP_TABLE_EDIT:
784 case SID_DB_APP_QUERY_EDIT:
785 case SID_DB_APP_FORM_EDIT:
786 case SID_DB_APP_REPORT_EDIT:
787 aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() > 0
788 && getContainer()->isALeafSelected();
789 break;
790 case SID_DB_APP_EDIT_SQL_VIEW:
791 if ( isDataSourceReadOnly() )
792 aReturn.bEnabled = sal_False;
793 else
795 switch ( getContainer()->getElementType() )
797 case E_QUERY:
798 aReturn.bEnabled = ( getContainer()->getSelectionCount() > 0 )
799 && ( getContainer()->isALeafSelected() );
800 break;
801 case E_TABLE:
802 aReturn.bEnabled = sal_False;
803 // there's one exception: views which support altering their underlying
804 // command can be edited in SQL view, too
805 if ( ( getContainer()->getSelectionCount() > 0 )
806 && ( getContainer()->isALeafSelected() )
809 ::std::vector< OUString > aSelected;
810 getSelectionElementNames( aSelected );
811 bool bAlterableViews = true;
812 for ( ::std::vector< OUString >::const_iterator selectedName = aSelected.begin();
813 bAlterableViews && ( selectedName != aSelected.end() ) ;
814 ++selectedName
817 bAlterableViews &= impl_isAlterableView_nothrow( *selectedName );
819 aReturn.bEnabled = bAlterableViews;
821 break;
822 default:
823 break;
826 break;
827 case SID_DB_APP_OPEN:
828 case SID_DB_APP_TABLE_OPEN:
829 case SID_DB_APP_QUERY_OPEN:
830 case SID_DB_APP_FORM_OPEN:
831 case SID_DB_APP_REPORT_OPEN:
832 aReturn.bEnabled = getContainer()->getSelectionCount() > 0 && getContainer()->isALeafSelected();
833 break;
834 case SID_DB_APP_DSUSERADMIN:
835 aReturn.bEnabled = !m_aTypeCollection.isEmbeddedDatabase(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
836 break;
837 case SID_DB_APP_DSRELDESIGN:
838 aReturn.bEnabled = sal_True;
839 break;
840 case SID_DB_APP_TABLEFILTER:
841 aReturn.bEnabled = !isDataSourceReadOnly();
842 break;
843 case SID_DB_APP_REFRESH_TABLES:
844 aReturn.bEnabled = getContainer()->getElementType() == E_TABLE && isConnected();
845 break;
846 case SID_DB_APP_DSPROPS:
847 aReturn.bEnabled = m_xDataSource.is() && m_aTypeCollection.isShowPropertiesEnabled(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
848 break;
849 case SID_DB_APP_DSCONNECTION_TYPE:
850 aReturn.bEnabled = !isDataSourceReadOnly() && m_xDataSource.is() && !m_aTypeCollection.isEmbeddedDatabase(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
851 break;
852 case SID_DB_APP_DSADVANCED_SETTINGS:
853 aReturn.bEnabled = m_xDataSource.is() && AdvancedSettingsDialog::doesHaveAnyAdvancedSettings( m_aTypeCollection.getType(::comphelper::getString( m_xDataSource->getPropertyValue( PROPERTY_URL ) )) );
854 break;
855 case SID_DB_APP_CONVERTTOVIEW:
856 aReturn.bEnabled = !isDataSourceReadOnly();
857 if ( aReturn.bEnabled )
859 ElementType eType = getContainer()->getElementType();
860 aReturn.bEnabled = eType == E_QUERY && getContainer()->getSelectionCount() > 0;
861 if ( aReturn.bEnabled )
863 Reference<XViewsSupplier> xViewSup( getConnection(), UNO_QUERY );
864 aReturn.bEnabled = xViewSup.is() && Reference<XAppend>(xViewSup->getViews(),UNO_QUERY).is();
867 break;
868 case SID_DB_APP_DISABLE_PREVIEW:
869 aReturn.bEnabled = sal_True;
870 aReturn.bChecked = getContainer()->getPreviewMode() == E_PREVIEWNONE;
871 break;
872 case SID_DB_APP_VIEW_DOCINFO_PREVIEW:
874 ElementType eType = getContainer()->getElementType();
875 aReturn.bEnabled = (E_REPORT == eType || E_FORM == eType);
876 aReturn.bChecked = getContainer()->getPreviewMode() == E_DOCUMENTINFO;
878 break;
879 case SID_DB_APP_VIEW_DOC_PREVIEW:
880 aReturn.bEnabled = sal_True;
881 aReturn.bChecked = getContainer()->getPreviewMode() == E_DOCUMENT;
882 break;
883 case ID_BROWSER_UNDO:
884 aReturn.bEnabled = sal_False;
885 break;
886 case SID_MAIL_SENDDOC:
887 aReturn.bEnabled = sal_True;
888 break;
889 case SID_DB_APP_SENDREPORTASMAIL:
891 ElementType eType = getContainer()->getElementType();
892 aReturn.bEnabled = E_REPORT == eType && getContainer()->getSelectionCount() > 0 && getContainer()->isALeafSelected();
894 break;
895 case SID_DB_APP_SENDREPORTTOWRITER:
896 case SID_DB_APP_DBADMIN:
897 aReturn.bEnabled = sal_False;
898 break;
899 case SID_DB_APP_STATUS_TYPE:
900 aReturn.bEnabled = m_xDataSource.is();
901 if ( aReturn.bEnabled )
903 OUString sURL;
904 m_xDataSource->getPropertyValue(PROPERTY_URL) >>= sURL;
905 OUString sDSTypeName;
906 if ( m_aTypeCollection.isEmbeddedDatabase( sURL ) )
908 sDSTypeName = OUString( ModuleRes( RID_STR_EMBEDDED_DATABASE ) );
910 else
912 sDSTypeName = m_aTypeCollection.getTypeDisplayName(sURL);
914 aReturn.sTitle = sDSTypeName;
916 break;
917 case SID_DB_APP_STATUS_DBNAME:
918 aReturn.bEnabled = m_xDataSource.is();
919 if ( aReturn.bEnabled )
921 OUString sURL;
922 m_xDataSource->getPropertyValue(PROPERTY_URL) >>= sURL;
923 OUString sDatabaseName;
924 OUString sHostName;
925 sal_Int32 nPortNumber( -1 );
927 m_aTypeCollection.extractHostNamePort( sURL, sDatabaseName, sHostName, nPortNumber );
929 if ( sDatabaseName.isEmpty() )
930 sDatabaseName = m_aTypeCollection.cutPrefix( sURL );
931 if ( m_aTypeCollection.isFileSystemBased(sURL) )
933 sDatabaseName = SvtPathOptions().SubstituteVariable( sDatabaseName );
934 if ( !sDatabaseName.isEmpty() )
936 ::svt::OFileNotation aFileNotation(sDatabaseName);
937 // set this decoded URL as text
938 sDatabaseName = aFileNotation.get(::svt::OFileNotation::N_SYSTEM);
942 if ( sDatabaseName.isEmpty() )
943 sDatabaseName = m_aTypeCollection.getTypeDisplayName( sURL );
945 aReturn.sTitle = sDatabaseName;
947 break;
948 case SID_DB_APP_STATUS_USERNAME:
949 aReturn.bEnabled = m_xDataSource.is();
950 if ( aReturn.bEnabled )
951 m_xDataSource->getPropertyValue( PROPERTY_USER ) >>= aReturn.sTitle;
952 break;
953 case SID_DB_APP_STATUS_HOSTNAME:
954 aReturn.bEnabled = m_xDataSource.is();
955 if ( aReturn.bEnabled )
957 OUString sURL;
958 m_xDataSource->getPropertyValue( PROPERTY_URL ) >>= sURL;
960 OUString sHostName, sDatabaseName;
961 sal_Int32 nPortNumber = -1;
962 m_aTypeCollection.extractHostNamePort( sURL, sDatabaseName, sHostName, nPortNumber );
963 aReturn.sTitle = sHostName;
965 break;
966 default:
967 aReturn = OApplicationController_CBASE::GetState(_nId);
970 catch(const Exception& )
972 DBG_UNHANDLED_EXCEPTION();
974 return aReturn;
977 // -----------------------------------------------------------------------------
978 namespace
980 bool lcl_handleException_nothrow( const Reference< XModel >& _rxDocument, const Any& _rException )
982 bool bHandled = false;
984 // try handling the error with an interaction handler
985 ::comphelper::NamedValueCollection aArgs( _rxDocument->getArgs() );
986 Reference< XInteractionHandler > xHandler( aArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) );
987 if ( xHandler.is() )
989 Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( _rException ) );
990 Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
991 pRequest->addContinuation( pApprove.get() );
995 xHandler->handle( pRequest.get() );
997 catch( const Exception& )
999 DBG_UNHANDLED_EXCEPTION();
1002 bHandled = pApprove->wasSelected();
1004 return bHandled;
1008 // -----------------------------------------------------------------------------
1009 void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
1011 SolarMutexGuard aSolarGuard;
1012 ::osl::MutexGuard aGuard( getMutex() );
1014 if ( isUserDefinedFeature( _nId ) )
1016 OApplicationController_CBASE::Execute( _nId, aArgs );
1017 return;
1020 if ( !getContainer() || m_bReadOnly )
1021 return; // return without execution
1025 switch(_nId)
1027 case ID_BROWSER_CUT:
1028 getContainer()->cut();
1029 break;
1030 case ID_BROWSER_COPY:
1032 TransferableHelper* pTransfer = copyObject( );
1033 Reference< XTransferable> aEnsureDelete = pTransfer;
1035 if ( pTransfer )
1036 pTransfer->CopyToClipboard(getView());
1038 break;
1039 case ID_BROWSER_PASTE:
1041 const TransferableDataHelper& rTransferData( getViewClipboard() );
1042 ElementType eType = getContainer()->getElementType();
1044 switch( eType )
1046 case E_TABLE:
1048 // get the selected tablename
1049 ::std::vector< OUString > aList;
1050 getSelectionElementNames( aList );
1051 if ( !aList.empty() )
1052 m_aTableCopyHelper.SetTableNameForAppend( *aList.begin() );
1053 else
1054 m_aTableCopyHelper.ResetTableNameForAppend();
1056 m_aTableCopyHelper.pasteTable( rTransferData , getDatabaseName(), ensureConnection() );
1058 break;
1060 case E_QUERY:
1061 if ( rTransferData.HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY) )
1062 paste( E_QUERY, ODataAccessObjectTransferable::extractObjectDescriptor( rTransferData ) );
1063 break;
1064 default:
1066 ::std::vector< OUString> aList;
1067 getSelectionElementNames(aList);
1068 OUString sFolderNameToInsertInto;
1069 if ( !aList.empty() )
1071 Reference< XHierarchicalNameAccess > xContainer(getElements(eType),UNO_QUERY);
1072 if ( xContainer.is()
1073 && xContainer->hasByHierarchicalName(*aList.begin())
1074 && (xContainer->getByHierarchicalName(*aList.begin()) >>= xContainer)
1075 && xContainer.is()
1077 sFolderNameToInsertInto = *aList.begin();
1079 paste( eType, OComponentTransferable::extractComponentDescriptor( rTransferData ),
1080 sFolderNameToInsertInto );
1082 break;
1085 break;
1086 case SID_DB_APP_PASTE_SPECIAL:
1088 if ( !aArgs.getLength() )
1090 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1091 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1092 ::std::auto_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( getView() ));
1093 SAL_WNODEPRECATED_DECLARATIONS_POP
1094 ::std::vector<SotFormatStringId> aFormatIds;
1095 getSupportedFormats(getContainer()->getElementType(),aFormatIds);
1096 const ::std::vector<SotFormatStringId>::iterator aEnd = aFormatIds.end();
1097 OUString sEmpty;
1098 for (::std::vector<SotFormatStringId>::iterator aIter = aFormatIds.begin();aIter != aEnd; ++aIter)
1099 pDlg->Insert(*aIter,sEmpty);
1101 const TransferableDataHelper& rClipboard = getViewClipboard();
1102 pasteFormat(pDlg->GetFormat(rClipboard.GetTransferable()));
1104 else
1106 const PropertyValue* pIter = aArgs.getConstArray();
1107 const PropertyValue* pEnd = pIter + aArgs.getLength();
1108 for( ; pIter != pEnd ; ++pIter)
1110 if ( pIter->Name == "FormatStringId" )
1112 SotFormatStringId nFormatId = 0;
1113 if ( pIter->Value >>= nFormatId )
1114 pasteFormat(nFormatId);
1115 break;
1120 break;
1121 case SID_OPENDOC:
1122 case SID_HELP_INDEX:
1124 Reference < XDispatchProvider > xProv( getFrame(), UNO_QUERY );
1125 if ( xProv.is() )
1127 URL aURL;
1128 switch(_nId)
1130 case SID_HELP_INDEX:
1131 aURL.Complete = OUString(".uno:HelpIndex");
1132 break;
1133 case SID_OPENDOC:
1134 aURL.Complete = OUString(".uno:Open");
1135 break;
1138 if ( m_xUrlTransformer.is() )
1139 m_xUrlTransformer->parseStrict( aURL );
1140 Reference < XDispatch > xDisp = xProv->queryDispatch( aURL, OUString(), 0 );
1141 if ( xDisp.is() )
1142 xDisp->dispatch( aURL, Sequence < PropertyValue >() );
1145 break;
1146 case ID_BROWSER_SAVEDOC:
1148 Reference< XStorable > xStore( m_xModel, UNO_QUERY_THROW );
1151 xStore->store();
1153 catch( const Exception& )
1155 lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() );
1158 break;
1160 case ID_BROWSER_SAVEASDOC:
1162 OUString sUrl;
1163 if ( m_xModel.is() )
1164 sUrl = m_xModel->getURL();
1165 if ( sUrl.isEmpty() )
1166 sUrl = SvtPathOptions().GetWorkPath();
1168 ::sfx2::FileDialogHelper aFileDlg(
1169 ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
1170 0, getView());
1171 aFileDlg.SetDisplayDirectory( sUrl );
1173 const SfxFilter* pFilter = getStandardDatabaseFilter();
1174 if ( pFilter )
1176 aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
1177 aFileDlg.SetCurrentFilter(pFilter->GetUIName());
1180 if ( aFileDlg.Execute() != ERRCODE_NONE )
1181 break;
1183 Reference<XStorable> xStore( m_xModel, UNO_QUERY_THROW );
1184 INetURLObject aURL( aFileDlg.GetPath() );
1187 xStore->storeAsURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), Sequence< PropertyValue >() );
1189 catch( const Exception& )
1191 lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() );
1194 /*updateTitle();*/
1195 m_bCurrentlyModified = sal_False;
1196 InvalidateFeature(ID_BROWSER_SAVEDOC);
1197 if ( getContainer()->getElementType() == E_NONE )
1199 getContainer()->selectContainer(E_NONE);
1200 getContainer()->selectContainer(E_TABLE);
1201 // #i95524#
1202 getContainer()->Invalidate();
1203 refreshTables();
1207 break;
1208 case ID_BROWSER_SORTUP:
1209 getContainer()->sortUp();
1210 InvalidateFeature(ID_BROWSER_SORTDOWN);
1211 break;
1212 case ID_BROWSER_SORTDOWN:
1213 getContainer()->sortDown();
1214 InvalidateFeature(ID_BROWSER_SORTUP);
1215 break;
1217 case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
1218 case ID_NEW_VIEW_DESIGN_AUTO_PILOT:
1219 case ID_APP_NEW_QUERY_AUTO_PILOT:
1220 case SID_DB_FORM_NEW_PILOT:
1221 case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
1222 case SID_APP_NEW_REPORT_PRE_SEL:
1223 case SID_FORM_CREATE_REPWIZ_PRE_SEL:
1224 case ID_DOCUMENT_CREATE_REPWIZ:
1225 case SID_APP_NEW_FORM:
1226 case SID_APP_NEW_REPORT:
1227 case ID_NEW_QUERY_SQL:
1228 case ID_NEW_QUERY_DESIGN:
1229 case ID_NEW_TABLE_DESIGN:
1231 ElementType eType = E_TABLE;
1232 sal_Bool bAutoPilot = sal_False;
1233 ::comphelper::NamedValueCollection aCreationArgs;
1235 switch( _nId )
1237 case SID_DB_FORM_NEW_PILOT:
1238 case SID_FORM_CREATE_REPWIZ_PRE_SEL:
1239 bAutoPilot = sal_True;
1240 // run through
1241 case SID_APP_NEW_FORM:
1242 eType = E_FORM;
1243 break;
1244 case ID_DOCUMENT_CREATE_REPWIZ:
1245 case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
1246 bAutoPilot = sal_True;
1247 // run through
1248 case SID_APP_NEW_REPORT:
1249 case SID_APP_NEW_REPORT_PRE_SEL:
1250 eType = E_REPORT;
1251 break;
1252 case ID_APP_NEW_QUERY_AUTO_PILOT:
1253 bAutoPilot = sal_True;
1254 eType = E_QUERY;
1255 break;
1256 case ID_NEW_QUERY_DESIGN:
1257 aCreationArgs.put( (OUString)PROPERTY_GRAPHICAL_DESIGN, sal_True );
1258 // run through
1259 case ID_NEW_QUERY_SQL:
1260 eType = E_QUERY;
1261 break;
1262 case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
1263 bAutoPilot = sal_True;
1264 // run through
1265 case ID_NEW_TABLE_DESIGN:
1266 break;
1267 default:
1268 OSL_FAIL("illegal switch call!");
1270 if ( bAutoPilot )
1271 getContainer()->PostUserEvent( LINK( this, OApplicationController, OnCreateWithPilot ), reinterpret_cast< void* >( eType ) );
1272 else
1274 Reference< XComponent > xDocDefinition;
1275 newElement( eType, aCreationArgs, xDocDefinition );
1278 break;
1279 case SID_APP_NEW_FOLDER:
1281 ElementType eType = getContainer()->getElementType();
1282 OUString sName = getContainer()->getQualifiedName( NULL );
1283 insertHierachyElement(eType,sName);
1285 break;
1286 case ID_NEW_VIEW_DESIGN:
1287 case SID_DB_NEW_VIEW_SQL:
1289 SharedConnection xConnection( ensureConnection() );
1290 if ( xConnection.is() )
1292 QueryDesigner aDesigner( getORB(), this, getFrame(), true );
1294 ::comphelper::NamedValueCollection aCreationArgs;
1295 aCreationArgs.put( (OUString)PROPERTY_GRAPHICAL_DESIGN, ID_NEW_VIEW_DESIGN == _nId );
1297 const Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
1298 const Reference< XComponent > xComponent( aDesigner.createNew( xDataSource, aCreationArgs ), UNO_QUERY );
1299 onDocumentOpened( OUString(), E_QUERY, E_OPEN_DESIGN, xComponent, NULL );
1302 break;
1303 case SID_DB_APP_DELETE:
1304 case SID_DB_APP_TABLE_DELETE:
1305 case SID_DB_APP_QUERY_DELETE:
1306 case SID_DB_APP_FORM_DELETE:
1307 case SID_DB_APP_REPORT_DELETE:
1308 deleteEntries();
1309 break;
1310 case SID_DB_APP_RENAME:
1311 case SID_DB_APP_TABLE_RENAME:
1312 case SID_DB_APP_QUERY_RENAME:
1313 case SID_DB_APP_FORM_RENAME:
1314 case SID_DB_APP_REPORT_RENAME:
1315 renameEntry();
1316 break;
1317 case SID_DB_APP_EDIT:
1318 case SID_DB_APP_EDIT_SQL_VIEW:
1319 case SID_DB_APP_TABLE_EDIT:
1320 case SID_DB_APP_QUERY_EDIT:
1321 case SID_DB_APP_FORM_EDIT:
1322 case SID_DB_APP_REPORT_EDIT:
1323 doAction( _nId, E_OPEN_DESIGN );
1324 break;
1325 case SID_DB_APP_OPEN:
1326 case SID_DB_APP_TABLE_OPEN:
1327 case SID_DB_APP_QUERY_OPEN:
1328 case SID_DB_APP_FORM_OPEN:
1329 case SID_DB_APP_REPORT_OPEN:
1330 doAction( _nId, E_OPEN_NORMAL );
1331 break;
1332 case SID_DB_APP_CONVERTTOVIEW:
1333 doAction( _nId, E_OPEN_NORMAL );
1334 break;
1335 case SID_SELECTALL:
1336 getContainer()->selectAll();
1337 InvalidateAll();
1338 break;
1339 case SID_DB_APP_DSRELDESIGN:
1341 Reference< XComponent > xRelationDesigner;
1342 if ( !m_pSubComponentManager->activateSubFrame( OUString(), SID_DB_APP_DSRELDESIGN, E_OPEN_DESIGN, xRelationDesigner ) )
1344 SharedConnection xConnection( ensureConnection() );
1345 if ( xConnection.is() )
1347 RelationDesigner aDesigner( getORB(), this, m_aCurrentFrame.getFrame() );
1349 const Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
1350 const Reference< XComponent > xComponent( aDesigner.createNew( xDataSource ), UNO_QUERY );
1351 onDocumentOpened( OUString(), SID_DB_APP_DSRELDESIGN, E_OPEN_DESIGN, xComponent, NULL );
1355 break;
1356 case SID_DB_APP_DSUSERADMIN:
1358 SharedConnection xConnection( ensureConnection() );
1359 if ( xConnection.is() )
1360 openDialog(OUString("com.sun.star.sdb.UserAdministrationDialog"));
1362 break;
1363 case SID_DB_APP_TABLEFILTER:
1364 openTableFilterDialog();
1365 askToReconnect();
1366 break;
1367 case SID_DB_APP_REFRESH_TABLES:
1368 refreshTables();
1369 break;
1370 case SID_DB_APP_DSPROPS:
1371 openDataSourceAdminDialog();
1372 askToReconnect();
1373 break;
1374 case SID_DB_APP_DSADVANCED_SETTINGS:
1375 openDialog(OUString("com.sun.star.sdb.AdvancedDatabaseSettingsDialog"));
1376 askToReconnect();
1377 break;
1378 case SID_DB_APP_DSCONNECTION_TYPE:
1379 openDialog(OUString("com.sun.star.sdb.DataSourceTypeChangeDialog"));
1380 askToReconnect();
1381 break;
1382 case ID_DIRECT_SQL:
1384 SharedConnection xConnection( ensureConnection() );
1385 if ( xConnection.is() )
1386 openDirectSQLDialog();
1388 break;
1389 case ID_MIGRATE_SCRIPTS:
1390 impl_migrateScripts_nothrow();
1391 break;
1392 case SID_DB_APP_VIEW_TABLES:
1393 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_TABLE ) );
1394 break;
1395 case SID_DB_APP_VIEW_QUERIES:
1396 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_QUERY ) );
1397 break;
1398 case SID_DB_APP_VIEW_FORMS:
1399 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_FORM ) );
1400 break;
1401 case SID_DB_APP_VIEW_REPORTS:
1402 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_REPORT ) );
1403 break;
1404 case SID_DB_APP_DISABLE_PREVIEW:
1405 m_ePreviewMode = E_PREVIEWNONE;
1406 getContainer()->switchPreview(m_ePreviewMode);
1407 break;
1408 case SID_DB_APP_VIEW_DOCINFO_PREVIEW:
1409 m_ePreviewMode = E_DOCUMENTINFO;
1410 getContainer()->switchPreview(m_ePreviewMode);
1411 break;
1412 case SID_DB_APP_VIEW_DOC_PREVIEW:
1413 m_ePreviewMode = E_DOCUMENT;
1414 getContainer()->switchPreview(m_ePreviewMode);
1415 break;
1416 case SID_MAIL_SENDDOC:
1418 SfxMailModel aSendMail;
1419 if ( aSendMail.AttachDocument(OUString(),getModel(), OUString()) == SfxMailModel::SEND_MAIL_OK )
1420 aSendMail.Send( getFrame() );
1422 break;
1423 case SID_DB_APP_SENDREPORTASMAIL:
1424 doAction( _nId, E_OPEN_FOR_MAIL );
1425 break;
1428 catch( const Exception& )
1430 DBG_UNHANDLED_EXCEPTION();
1432 InvalidateFeature(_nId);
1434 // -----------------------------------------------------------------------------
1435 void OApplicationController::describeSupportedFeatures()
1437 OApplicationController_CBASE::describeSupportedFeatures();
1439 implDescribeSupportedFeature( ".uno:Save", ID_BROWSER_SAVEDOC, CommandGroup::DOCUMENT );
1440 implDescribeSupportedFeature( ".uno:SaveAs", ID_BROWSER_SAVEASDOC, CommandGroup::DOCUMENT );
1441 implDescribeSupportedFeature( ".uno:SendMail", SID_MAIL_SENDDOC, CommandGroup::DOCUMENT );
1442 implDescribeSupportedFeature( ".uno:DBSendReportAsMail",SID_DB_APP_SENDREPORTASMAIL,
1443 CommandGroup::DOCUMENT );
1444 implDescribeSupportedFeature( ".uno:DBSendReportToWriter",SID_DB_APP_SENDREPORTTOWRITER,
1445 CommandGroup::DOCUMENT );
1446 implDescribeSupportedFeature( ".uno:DBNewForm", SID_APP_NEW_FORM, CommandGroup::INSERT );
1447 implDescribeSupportedFeature( ".uno:DBNewFolder", SID_APP_NEW_FOLDER, CommandGroup::INSERT );
1448 implDescribeSupportedFeature( ".uno:DBNewFormAutoPilot", SID_DB_FORM_NEW_PILOT, CommandGroup::INSERT );
1449 implDescribeSupportedFeature( ".uno:DBNewFormAutoPilotWithPreSelection",
1450 SID_FORM_CREATE_REPWIZ_PRE_SEL,
1451 CommandGroup::APPLICATION );
1453 implDescribeSupportedFeature( ".uno:DBNewReport", SID_APP_NEW_REPORT, CommandGroup::INSERT );
1454 implDescribeSupportedFeature( ".uno:DBNewReportAutoPilot",
1455 ID_DOCUMENT_CREATE_REPWIZ, CommandGroup::INSERT );
1456 implDescribeSupportedFeature( ".uno:DBNewReportAutoPilotWithPreSelection",
1457 SID_REPORT_CREATE_REPWIZ_PRE_SEL,
1458 CommandGroup::APPLICATION );
1459 implDescribeSupportedFeature( ".uno:DBNewQuery", ID_NEW_QUERY_DESIGN, CommandGroup::INSERT );
1460 implDescribeSupportedFeature( ".uno:DBNewQuerySql", ID_NEW_QUERY_SQL, CommandGroup::INSERT );
1461 implDescribeSupportedFeature( ".uno:DBNewQueryAutoPilot",ID_APP_NEW_QUERY_AUTO_PILOT,
1462 CommandGroup::INSERT );
1463 implDescribeSupportedFeature( ".uno:DBNewTable", ID_NEW_TABLE_DESIGN, CommandGroup::INSERT );
1464 implDescribeSupportedFeature( ".uno:DBNewTableAutoPilot",ID_NEW_TABLE_DESIGN_AUTO_PILOT,
1465 CommandGroup::INSERT );
1466 implDescribeSupportedFeature( ".uno:DBNewView", ID_NEW_VIEW_DESIGN, CommandGroup::INSERT );
1467 implDescribeSupportedFeature( ".uno:DBNewViewSQL", SID_DB_NEW_VIEW_SQL, CommandGroup::INSERT );
1469 implDescribeSupportedFeature( ".uno:DBDelete", SID_DB_APP_DELETE, CommandGroup::EDIT );
1470 implDescribeSupportedFeature( ".uno:Delete", SID_DB_APP_DELETE, CommandGroup::EDIT );
1471 implDescribeSupportedFeature( ".uno:DBRename", SID_DB_APP_RENAME, CommandGroup::EDIT );
1472 implDescribeSupportedFeature( ".uno:DBEdit", SID_DB_APP_EDIT, CommandGroup::EDIT );
1473 implDescribeSupportedFeature( ".uno:DBEditSqlView", SID_DB_APP_EDIT_SQL_VIEW, CommandGroup::EDIT );
1474 implDescribeSupportedFeature( ".uno:DBOpen", SID_DB_APP_OPEN, CommandGroup::EDIT );
1476 implDescribeSupportedFeature( ".uno:DBTableDelete", SID_DB_APP_TABLE_DELETE, CommandGroup::EDIT );
1477 implDescribeSupportedFeature( ".uno:DBTableRename", SID_DB_APP_TABLE_RENAME, CommandGroup::EDIT );
1478 implDescribeSupportedFeature( ".uno:DBTableEdit", SID_DB_APP_TABLE_EDIT, CommandGroup::EDIT );
1479 implDescribeSupportedFeature( ".uno:DBTableOpen", SID_DB_APP_TABLE_OPEN, CommandGroup::EDIT );
1481 implDescribeSupportedFeature( ".uno:DBQueryDelete", SID_DB_APP_QUERY_DELETE, CommandGroup::EDIT );
1482 implDescribeSupportedFeature( ".uno:DBQueryRename", SID_DB_APP_QUERY_RENAME, CommandGroup::EDIT );
1483 implDescribeSupportedFeature( ".uno:DBQueryEdit", SID_DB_APP_QUERY_EDIT, CommandGroup::EDIT );
1484 implDescribeSupportedFeature( ".uno:DBQueryOpen", SID_DB_APP_QUERY_OPEN, CommandGroup::EDIT );
1486 implDescribeSupportedFeature( ".uno:DBFormDelete", SID_DB_APP_FORM_DELETE, CommandGroup::EDIT );
1487 implDescribeSupportedFeature( ".uno:DBFormRename", SID_DB_APP_FORM_RENAME, CommandGroup::EDIT );
1488 implDescribeSupportedFeature( ".uno:DBFormEdit", SID_DB_APP_FORM_EDIT, CommandGroup::EDIT );
1489 implDescribeSupportedFeature( ".uno:DBFormOpen", SID_DB_APP_FORM_OPEN, CommandGroup::EDIT );
1491 implDescribeSupportedFeature( ".uno:DBReportDelete", SID_DB_APP_REPORT_DELETE, CommandGroup::EDIT );
1492 implDescribeSupportedFeature( ".uno:DBReportRename", SID_DB_APP_REPORT_RENAME, CommandGroup::EDIT );
1493 implDescribeSupportedFeature( ".uno:DBReportEdit", SID_DB_APP_REPORT_EDIT, CommandGroup::EDIT );
1494 implDescribeSupportedFeature( ".uno:DBReportOpen", SID_DB_APP_REPORT_OPEN, CommandGroup::EDIT );
1496 implDescribeSupportedFeature( ".uno:SelectAll", SID_SELECTALL, CommandGroup::EDIT );
1497 implDescribeSupportedFeature( ".uno:Undo", ID_BROWSER_UNDO, CommandGroup::EDIT );
1499 implDescribeSupportedFeature( ".uno:Sortup", ID_BROWSER_SORTUP, CommandGroup::VIEW );
1500 implDescribeSupportedFeature( ".uno:SortDown", ID_BROWSER_SORTDOWN, CommandGroup::VIEW );
1501 implDescribeSupportedFeature( ".uno:DBRelationDesign", SID_DB_APP_DSRELDESIGN, CommandGroup::APPLICATION );
1502 implDescribeSupportedFeature( ".uno:DBUserAdmin", SID_DB_APP_DSUSERADMIN, CommandGroup::APPLICATION );
1503 implDescribeSupportedFeature( ".uno:DBTableFilter", SID_DB_APP_TABLEFILTER, CommandGroup::APPLICATION );
1504 implDescribeSupportedFeature( ".uno:DBDSProperties", SID_DB_APP_DSPROPS, CommandGroup::EDIT );
1505 implDescribeSupportedFeature( ".uno:DBDSConnectionType", SID_DB_APP_DSCONNECTION_TYPE,
1506 CommandGroup::EDIT );
1507 implDescribeSupportedFeature( ".uno:DBDSAdvancedSettings",
1508 SID_DB_APP_DSADVANCED_SETTINGS,
1509 CommandGroup::EDIT );
1510 implDescribeSupportedFeature( ".uno:PasteSpecial", SID_DB_APP_PASTE_SPECIAL, CommandGroup::EDIT );
1511 implDescribeSupportedFeature( ".uno:DBConvertToView", SID_DB_APP_CONVERTTOVIEW, CommandGroup::EDIT );
1512 implDescribeSupportedFeature( ".uno:DBRefreshTables", SID_DB_APP_REFRESH_TABLES, CommandGroup::APPLICATION );
1513 implDescribeSupportedFeature( ".uno:DBDirectSQL", ID_DIRECT_SQL, CommandGroup::APPLICATION );
1514 implDescribeSupportedFeature( ".uno:DBMigrateScripts", ID_MIGRATE_SCRIPTS, CommandGroup::APPLICATION );
1515 implDescribeSupportedFeature( ".uno:DBViewTables", SID_DB_APP_VIEW_TABLES, CommandGroup::VIEW );
1516 implDescribeSupportedFeature( ".uno:DBViewQueries", SID_DB_APP_VIEW_QUERIES, CommandGroup::VIEW );
1517 implDescribeSupportedFeature( ".uno:DBViewForms", SID_DB_APP_VIEW_FORMS, CommandGroup::VIEW );
1518 implDescribeSupportedFeature( ".uno:DBViewReports", SID_DB_APP_VIEW_REPORTS, CommandGroup::VIEW );
1519 implDescribeSupportedFeature( ".uno:DBDisablePreview", SID_DB_APP_DISABLE_PREVIEW,CommandGroup::VIEW );
1520 implDescribeSupportedFeature( ".uno:DBShowDocInfoPreview",
1521 SID_DB_APP_VIEW_DOCINFO_PREVIEW,
1522 CommandGroup::VIEW );
1523 implDescribeSupportedFeature( ".uno:DBShowDocPreview", SID_DB_APP_VIEW_DOC_PREVIEW,
1524 CommandGroup::VIEW );
1526 implDescribeSupportedFeature( ".uno:OpenUrl", SID_OPENURL, CommandGroup::APPLICATION );
1528 // this one should not appear under Tools->Customize->Keyboard
1529 implDescribeSupportedFeature( ".uno:DBNewReportWithPreSelection",
1530 SID_APP_NEW_REPORT_PRE_SEL,CommandGroup::INTERNAL );
1531 implDescribeSupportedFeature( ".uno:DBDSImport", SID_DB_APP_DSIMPORT, CommandGroup::INTERNAL);
1532 implDescribeSupportedFeature( ".uno:DBDSExport", SID_DB_APP_DSEXPORT, CommandGroup::INTERNAL);
1533 implDescribeSupportedFeature( ".uno:DBDBAdmin", SID_DB_APP_DBADMIN, CommandGroup::INTERNAL);
1535 // status info
1536 implDescribeSupportedFeature( ".uno:DBStatusType", SID_DB_APP_STATUS_TYPE, CommandGroup::INTERNAL);
1537 implDescribeSupportedFeature( ".uno:DBStatusDBName", SID_DB_APP_STATUS_DBNAME, CommandGroup::INTERNAL);
1538 implDescribeSupportedFeature( ".uno:DBStatusUserName", SID_DB_APP_STATUS_USERNAME, CommandGroup::INTERNAL);
1539 implDescribeSupportedFeature( ".uno:DBStatusHostName", SID_DB_APP_STATUS_HOSTNAME, CommandGroup::INTERNAL);
1541 // -----------------------------------------------------------------------------
1542 OApplicationView* OApplicationController::getContainer() const
1544 return static_cast< OApplicationView* >( getView() );
1547 // -----------------------------------------------------------------------------
1548 // ::com::sun::star::container::XContainerListener
1549 void SAL_CALL OApplicationController::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
1551 SolarMutexGuard aSolarGuard;
1552 ::osl::MutexGuard aGuard( getMutex() );
1554 Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
1555 if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
1557 OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1558 if ( getContainer() )
1560 OUString sName;
1561 _rEvent.Accessor >>= sName;
1562 ElementType eType = getElementType(xContainer);
1564 switch( eType )
1566 case E_TABLE:
1567 ensureConnection();
1568 break;
1569 case E_FORM:
1570 case E_REPORT:
1572 Reference< XContainer > xSubContainer(_rEvent.Element,UNO_QUERY);
1573 if ( xSubContainer.is() )
1574 containerFound(xSubContainer);
1576 break;
1577 default:
1578 break;
1580 getContainer()->elementAdded(eType,sName,_rEvent.Element);
1584 // -----------------------------------------------------------------------------
1585 void SAL_CALL OApplicationController::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
1587 SolarMutexGuard aSolarGuard;
1588 ::osl::MutexGuard aGuard( getMutex() );
1590 Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
1591 if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
1593 OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1594 OUString sName;
1595 _rEvent.Accessor >>= sName;
1596 ElementType eType = getElementType(xContainer);
1597 switch( eType )
1599 case E_TABLE:
1600 ensureConnection();
1601 break;
1602 case E_FORM:
1603 case E_REPORT:
1605 Reference<XContent> xContent(xContainer,UNO_QUERY);
1606 if ( xContent.is() )
1608 sName = xContent->getIdentifier()->getContentIdentifier() + OUString("/") + sName;
1611 break;
1612 default:
1613 break;
1615 getContainer()->elementRemoved(eType,sName);
1618 // -----------------------------------------------------------------------------
1619 void SAL_CALL OApplicationController::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
1621 SolarMutexGuard aSolarGuard;
1622 ::osl::MutexGuard aGuard( getMutex() );
1624 Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
1625 if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
1627 OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1628 OUString sName;
1631 _rEvent.Accessor >>= sName;
1632 Reference<XConnection> xConnection;
1633 Reference<XPropertySet> xProp(_rEvent.Element,UNO_QUERY);
1634 OUString sNewName;
1636 ElementType eType = getElementType(xContainer);
1637 switch( eType )
1639 case E_TABLE:
1641 ensureConnection();
1642 if ( xProp.is() && m_xMetaData.is() )
1643 sNewName = ::dbaui::composeTableName( m_xMetaData, xProp, ::dbtools::eInDataManipulation, false, false, false );
1645 break;
1646 case E_FORM:
1647 case E_REPORT:
1649 Reference<XContent> xContent(xContainer,UNO_QUERY);
1650 if ( xContent.is() )
1652 sName = xContent->getIdentifier()->getContentIdentifier() + OUString("/") + sName;
1655 break;
1656 default:
1657 break;
1659 // getContainer()->elementReplaced(getContainer()->getElementType(),sName,sNewName);
1661 catch( Exception& )
1663 DBG_UNHANDLED_EXCEPTION();
1667 namespace
1669 OUString lcl_getToolBarResource(ElementType _eType)
1671 OUString sToolbar;
1672 switch(_eType)
1674 case E_TABLE:
1675 sToolbar = OUString("private:resource/toolbar/tableobjectbar");
1676 break;
1677 case E_QUERY:
1678 sToolbar = OUString("private:resource/toolbar/queryobjectbar");
1679 break;
1680 case E_FORM:
1681 sToolbar = OUString("private:resource/toolbar/formobjectbar");
1682 break;
1683 case E_REPORT:
1684 sToolbar = OUString("private:resource/toolbar/reportobjectbar");
1685 break;
1686 case E_NONE:
1687 break;
1688 default:
1689 OSL_FAIL("Invalid ElementType!");
1690 break;
1692 return sToolbar;
1695 // -----------------------------------------------------------------------------
1696 sal_Bool OApplicationController::onContainerSelect(ElementType _eType)
1698 OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1700 if ( m_eCurrentType != _eType && _eType != E_NONE )
1702 SelectionGuard aSelGuard( *m_pSelectionNotifier );
1704 if ( _eType == E_TABLE )
1708 SharedConnection xConnection( ensureConnection() );
1709 if ( xConnection.is() && getContainer()->getDetailView() )
1711 getContainer()->getDetailView()->createTablesPage(xConnection);
1712 Reference<XTablesSupplier> xTabSup(xConnection,UNO_QUERY);
1713 if ( xTabSup.is() )
1714 addContainerListener(xTabSup->getTables());
1716 else
1718 return sal_False;
1721 catch( const Exception& )
1723 return sal_False;
1726 Reference< XLayoutManager > xLayoutManager = getLayoutManager( getFrame() );
1727 if ( xLayoutManager.is() )
1729 OUString sToolbar = lcl_getToolBarResource(_eType);
1730 OUString sDestroyToolbar = lcl_getToolBarResource(m_eCurrentType);
1732 xLayoutManager->lock();
1733 xLayoutManager->destroyElement( sDestroyToolbar );
1734 if ( !sToolbar.isEmpty() )
1736 xLayoutManager->createElement( sToolbar );
1737 xLayoutManager->requestElement( sToolbar );
1739 xLayoutManager->unlock();
1740 xLayoutManager->doLayout();
1743 if ( _eType != E_TABLE && getContainer()->getDetailView() )
1745 Reference< XNameAccess > xContainer = getElements(_eType);
1746 addContainerListener(xContainer);
1747 getContainer()->getDetailView()->createPage(_eType,xContainer);
1750 SelectionByElementType::iterator pendingSelection = m_aPendingSelection.find( _eType );
1751 if ( pendingSelection != m_aPendingSelection.end() )
1753 Sequence< OUString > aSelected( pendingSelection->second.size() );
1754 ::std::copy( pendingSelection->second.begin(), pendingSelection->second.end(), aSelected.getArray() );
1755 getContainer()->selectElements( aSelected );
1757 m_aPendingSelection.erase( pendingSelection );
1760 InvalidateAll();
1762 m_eCurrentType = _eType;
1764 return sal_True;
1766 // -----------------------------------------------------------------------------
1767 bool OApplicationController::onEntryDoubleClick( SvTreeListBox& _rTree )
1769 if ( getContainer() && getContainer()->isLeaf( _rTree.GetHdlEntry() ) )
1773 openElement(
1774 getContainer()->getQualifiedName( _rTree.GetHdlEntry() ),
1775 getContainer()->getElementType(),
1776 E_OPEN_NORMAL
1778 return true; // handled
1780 catch(const Exception&)
1782 DBG_UNHANDLED_EXCEPTION();
1785 return false; // not handled
1787 // -----------------------------------------------------------------------------
1788 bool OApplicationController::impl_isAlterableView_nothrow( const OUString& _rTableOrViewName ) const
1790 OSL_PRECOND( m_xDataSourceConnection.is(), "OApplicationController::impl_isAlterableView_nothrow: no connection!" );
1792 bool bIsAlterableView( false );
1795 Reference< XViewsSupplier > xViewsSupp( m_xDataSourceConnection, UNO_QUERY );
1796 Reference< XNameAccess > xViews;
1797 if ( xViewsSupp.is() )
1798 xViews = xViewsSupp->getViews();
1800 Reference< XAlterView > xAsAlterableView;
1801 if ( xViews.is() && xViews->hasByName( _rTableOrViewName ) )
1802 xAsAlterableView.set( xViews->getByName( _rTableOrViewName ), UNO_QUERY );
1804 bIsAlterableView = xAsAlterableView.is();
1806 catch( const Exception& )
1808 DBG_UNHANDLED_EXCEPTION();
1810 return bIsAlterableView;
1813 // -----------------------------------------------------------------------------
1814 Reference< XComponent > OApplicationController::openElement(const OUString& _sName, ElementType _eType,
1815 ElementOpenMode _eOpenMode, sal_uInt16 _nInstigatorCommand )
1817 return openElementWithArguments( _sName, _eType, _eOpenMode, _nInstigatorCommand, ::comphelper::NamedValueCollection() );
1820 // -----------------------------------------------------------------------------
1821 Reference< XComponent > OApplicationController::openElementWithArguments( const OUString& _sName, ElementType _eType,
1822 ElementOpenMode _eOpenMode, sal_uInt16 _nInstigatorCommand, const ::comphelper::NamedValueCollection& _rAdditionalArguments )
1824 OSL_PRECOND( getContainer(), "OApplicationController::openElementWithArguments: no view!" );
1825 if ( !getContainer() )
1826 return NULL;
1828 Reference< XComponent > xRet;
1829 if ( _eOpenMode == E_OPEN_DESIGN )
1831 // OJ: http://www.openoffice.org/issues/show_bug.cgi?id=30382
1832 getContainer()->showPreview(NULL);
1835 bool isStandaloneDocument = false;
1836 switch ( _eType )
1838 case E_REPORT:
1839 if ( _eOpenMode != E_OPEN_DESIGN )
1841 // reports which are opened in a mode other than design are no sub components of our application
1842 // component, but standalone documents.
1843 isStandaloneDocument = true;
1845 // NO break!
1846 case E_FORM:
1848 if ( isStandaloneDocument || !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode, xRet ) )
1850 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1851 ::std::auto_ptr< OLinkedDocumentsAccess > aHelper = getDocumentsAccess( _eType );
1852 SAL_WNODEPRECATED_DECLARATIONS_POP
1853 if ( !aHelper->isConnected() )
1854 break;
1856 Reference< XComponent > xDefinition;
1857 xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments );
1859 if ( !isStandaloneDocument )
1860 onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition );
1863 break;
1865 case E_QUERY:
1866 case E_TABLE:
1868 if ( !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode, xRet ) )
1870 SharedConnection xConnection( ensureConnection() );
1871 if ( !xConnection.is() )
1872 break;
1874 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1875 ::std::auto_ptr< DatabaseObjectView > pDesigner;
1876 SAL_WNODEPRECATED_DECLARATIONS_POP
1877 ::comphelper::NamedValueCollection aArguments( _rAdditionalArguments );
1879 Any aDataSource;
1880 if ( _eOpenMode == E_OPEN_DESIGN )
1882 bool bAddViewTypeArg = false;
1884 if ( _eType == E_TABLE )
1886 if ( impl_isAlterableView_nothrow( _sName ) )
1888 pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), true ) );
1889 bAddViewTypeArg = true;
1891 else
1893 pDesigner.reset( new TableDesigner( getORB(), this, m_aCurrentFrame.getFrame() ) );
1896 else if ( _eType == E_QUERY )
1898 pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), false ) );
1899 bAddViewTypeArg = true;
1901 aDataSource <<= m_xDataSource;
1903 if ( bAddViewTypeArg )
1905 const bool bQueryGraphicalMode =( _nInstigatorCommand != SID_DB_APP_EDIT_SQL_VIEW );
1906 aArguments.put( (OUString)PROPERTY_GRAPHICAL_DESIGN, bQueryGraphicalMode );
1910 else
1912 pDesigner.reset( new ResultSetBrowser( getORB(), this, m_aCurrentFrame.getFrame(), _eType == E_TABLE ) );
1914 if ( !aArguments.has( (OUString)PROPERTY_SHOWMENU ) )
1915 aArguments.put( (OUString)PROPERTY_SHOWMENU, makeAny( (sal_Bool)sal_True ) );
1917 aDataSource <<= getDatabaseName();
1920 xRet.set( pDesigner->openExisting( aDataSource, _sName, aArguments ) );
1921 onDocumentOpened( _sName, _eType, _eOpenMode, xRet, NULL );
1924 break;
1926 default:
1927 OSL_FAIL( "OApplicationController::openElement: illegal object type!" );
1928 break;
1930 return xRet;
1932 // -----------------------------------------------------------------------------
1933 IMPL_LINK( OApplicationController, OnSelectContainer, void*, _pType )
1935 ElementType eType = (ElementType)reinterpret_cast< sal_IntPtr >( _pType );
1936 if (getContainer())
1937 getContainer()->selectContainer(eType);
1938 return 0L;
1940 // -----------------------------------------------------------------------------
1941 IMPL_LINK( OApplicationController, OnCreateWithPilot, void*, _pType )
1943 ElementType eType = (ElementType)reinterpret_cast< sal_IntPtr >( _pType );
1944 newElementWithPilot( eType );
1945 return 0L;
1948 // -----------------------------------------------------------------------------
1949 void OApplicationController::newElementWithPilot( ElementType _eType )
1951 utl::CloseVeto aKeepDoc( getFrame() );
1952 // prevent the document being closed while the wizard is open
1954 OSL_ENSURE( getContainer(), "OApplicationController::newElementWithPilot: without a view?" );
1956 switch ( _eType )
1958 case E_REPORT:
1959 case E_FORM:
1961 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1962 ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType);
1963 SAL_WNODEPRECATED_DECLARATIONS_POP
1964 if ( aHelper->isConnected() )
1966 sal_Int32 nCommandType = -1;
1967 const OUString sCurrentSelected( getCurrentlySelectedName( nCommandType ) );
1968 if ( E_REPORT == _eType )
1969 aHelper->newReportWithPilot( nCommandType, sCurrentSelected );
1970 else
1971 aHelper->newFormWithPilot( nCommandType, sCurrentSelected );
1974 break;
1975 case E_QUERY:
1976 case E_TABLE:
1978 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1979 ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType);
1980 SAL_WNODEPRECATED_DECLARATIONS_POP
1981 if ( aHelper->isConnected() )
1983 if ( E_QUERY == _eType )
1984 aHelper->newQueryWithPilot();
1985 else
1986 aHelper->newTableWithPilot();
1989 break;
1990 case E_NONE:
1991 break;
1994 // no need for onDocumentOpened, the table wizard opens the created table by using
1995 // XDatabaseDocumentUI::loadComponent method.
1998 // -----------------------------------------------------------------------------
1999 Reference< XComponent > OApplicationController::newElement( ElementType _eType, const ::comphelper::NamedValueCollection& i_rAdditionalArguments,
2000 Reference< XComponent >& o_rDocumentDefinition )
2002 OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
2004 Reference< XComponent > xComponent;
2005 o_rDocumentDefinition.clear();
2007 switch ( _eType )
2009 case E_FORM:
2010 case E_REPORT:
2012 SAL_WNODEPRECATED_DECLARATIONS_PUSH
2013 ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess( _eType );
2014 SAL_WNODEPRECATED_DECLARATIONS_POP
2015 if ( !aHelper->isConnected() )
2016 break;
2018 xComponent = aHelper->newDocument( _eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT, i_rAdditionalArguments, o_rDocumentDefinition );
2020 break;
2022 case E_QUERY:
2023 case E_TABLE:
2025 SAL_WNODEPRECATED_DECLARATIONS_PUSH
2026 ::std::auto_ptr< DatabaseObjectView > pDesigner;
2027 SAL_WNODEPRECATED_DECLARATIONS_POP
2028 SharedConnection xConnection( ensureConnection() );
2029 if ( !xConnection.is() )
2030 break;
2032 if ( _eType == E_TABLE )
2034 pDesigner.reset( new TableDesigner( getORB(), this, getFrame() ) );
2036 else if ( _eType == E_QUERY )
2038 pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false ) );
2041 Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
2042 xComponent.set( pDesigner->createNew( xDataSource, i_rAdditionalArguments ), UNO_QUERY );
2044 break;
2046 default:
2047 OSL_FAIL( "OApplicationController::newElement: illegal type!" );
2048 break;
2051 if ( xComponent.is() )
2052 onDocumentOpened( OUString(), _eType, E_OPEN_DESIGN, xComponent, o_rDocumentDefinition );
2054 return xComponent;
2057 // -----------------------------------------------------------------------------
2058 void OApplicationController::addContainerListener(const Reference<XNameAccess>& _xCollection)
2062 Reference< XContainer > xCont(_xCollection, UNO_QUERY);
2063 if ( xCont.is() )
2065 // add as listener to get notified if elements are inserted or removed
2066 TContainerVector::iterator aFind = ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xCont);
2067 if ( aFind == m_aCurrentContainers.end() )
2069 xCont->addContainerListener(this);
2070 m_aCurrentContainers.push_back(xCont);
2074 catch( const Exception& )
2076 DBG_UNHANDLED_EXCEPTION();
2079 // -----------------------------------------------------------------------------
2080 void OApplicationController::renameEntry()
2082 SolarMutexGuard aSolarGuard;
2083 ::osl::MutexGuard aGuard( getMutex() );
2085 OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
2086 ::std::vector< OUString> aList;
2087 getSelectionElementNames(aList);
2089 Reference< XNameAccess > xContainer = getElements(getContainer()->getElementType());
2090 OSL_ENSURE(aList.size() == 1,"Invalid rename call here. More than one element!");
2091 if ( aList.empty() )
2092 return;
2096 if ( xContainer.is() )
2098 SAL_WNODEPRECATED_DECLARATIONS_PUSH
2099 ::std::auto_ptr< IObjectNameCheck > pNameChecker;
2100 ::std::auto_ptr< OSaveAsDlg > aDialog;
2101 SAL_WNODEPRECATED_DECLARATIONS_POP
2103 Reference<XRename> xRename;
2104 const ElementType eType = getContainer()->getElementType();
2105 switch( eType )
2107 case E_FORM:
2108 case E_REPORT:
2110 Reference<XHierarchicalNameContainer> xHNames(xContainer, UNO_QUERY);
2111 if ( xHNames.is() )
2113 OUString sLabel;
2114 if ( eType == E_FORM )
2115 sLabel = OUString(ModuleRes( STR_FRM_LABEL ));
2116 else
2117 sLabel = OUString(ModuleRes( STR_RPT_LABEL ));
2119 OUString sName = *aList.begin();
2120 if ( xHNames->hasByHierarchicalName(sName) )
2122 xRename.set(xHNames->getByHierarchicalName(sName),UNO_QUERY);
2123 Reference<XChild> xChild(xRename,UNO_QUERY);
2124 if ( xChild.is() )
2126 Reference<XHierarchicalNameContainer> xParent(xChild->getParent(),UNO_QUERY);
2127 if ( xParent.is() )
2129 xHNames = xParent;
2130 Reference<XPropertySet>(xRename,UNO_QUERY)->getPropertyValue(PROPERTY_NAME) >>= sName;
2133 pNameChecker.reset( new HierarchicalNameCheck( xHNames.get(), OUString() ) );
2134 aDialog.reset( new OSaveAsDlg(
2135 getView(), getORB(), sName, sLabel, *pNameChecker, SAD_TITLE_RENAME ) );
2139 break;
2140 case E_TABLE:
2141 ensureConnection();
2142 if ( !getConnection().is() )
2143 break;
2144 // NO break
2145 case E_QUERY:
2146 if ( xContainer->hasByName(*aList.begin()) )
2148 xRename.set(xContainer->getByName(*aList.begin()),UNO_QUERY);
2149 sal_Int32 nCommandType = eType == E_QUERY ? CommandType::QUERY : CommandType::TABLE;
2151 ensureConnection();
2152 pNameChecker.reset( new DynamicTableOrQueryNameCheck( getConnection(), nCommandType ) );
2153 aDialog.reset( new OSaveAsDlg(
2154 getView(), nCommandType, getORB(), getConnection(),
2155 *aList.begin(), *pNameChecker, SAD_TITLE_RENAME ) );
2157 break;
2158 default:
2159 break;
2162 if ( xRename.is() && aDialog.get() )
2165 sal_Bool bTryAgain = sal_True;
2166 while( bTryAgain )
2168 if ( aDialog->Execute() == RET_OK )
2172 OUString sNewName;
2173 if ( eType == E_TABLE )
2175 OUString sName = aDialog->getName();
2176 OUString sCatalog = aDialog->getCatalog();
2177 OUString sSchema = aDialog->getSchema();
2179 sNewName = ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sName, sal_False, ::dbtools::eInDataManipulation );
2181 else
2182 sNewName = aDialog->getName();
2184 OUString sOldName = *aList.begin();
2185 if ( eType == E_FORM || eType == E_REPORT )
2187 Reference<XContent> xContent(xRename,UNO_QUERY);
2188 if ( xContent.is() )
2190 sOldName = xContent->getIdentifier()->getContentIdentifier();
2194 xRename->rename(sNewName);
2196 if ( eType == E_TABLE )
2198 Reference<XPropertySet> xProp(xRename,UNO_QUERY);
2199 sNewName = ::dbaui::composeTableName( m_xMetaData, xProp, ::dbtools::eInDataManipulation, false, false, false );
2201 getContainer()->elementReplaced( eType , sOldName, sNewName );
2203 bTryAgain = sal_False;
2205 catch(const SQLException& )
2207 showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
2210 catch(const ElementExistException& e)
2212 OUString sStatus("S1000");
2213 OUString sMsg = OUString( ModuleRes( STR_NAME_ALREADY_EXISTS ) );
2214 showError(SQLExceptionInfo(SQLException(sMsg.replaceAll(OUString('#'), e.Message), e.Context, sStatus, 0, Any())));
2216 catch(const Exception& )
2218 DBG_UNHANDLED_EXCEPTION();
2221 else
2222 bTryAgain = sal_False;
2227 catch(const Exception& )
2229 DBG_UNHANDLED_EXCEPTION();
2233 // -----------------------------------------------------------------------------
2234 void OApplicationController::onSelectionChanged()
2236 InvalidateAll();
2238 SelectionGuard aSelGuard( *m_pSelectionNotifier );
2240 OApplicationView* pView = getContainer();
2241 if ( !pView )
2242 return;
2244 if ( pView->getSelectionCount() == 1 )
2246 const ElementType eType = pView->getElementType();
2247 if ( pView->isALeafSelected() )
2249 const OUString sName = pView->getQualifiedName( NULL /* means 'first selected' */ );
2250 showPreviewFor( eType, sName );
2254 // -----------------------------------------------------------------------------
2255 void OApplicationController::showPreviewFor(const ElementType _eType,const OUString& _sName)
2257 if ( m_ePreviewMode == E_PREVIEWNONE )
2258 return;
2260 OApplicationView* pView = getContainer();
2261 if ( !pView )
2262 return;
2266 switch( _eType )
2268 case E_FORM:
2269 case E_REPORT:
2271 Reference< XHierarchicalNameAccess > xContainer( getElements( _eType ), UNO_QUERY_THROW );
2272 Reference< XContent> xContent( xContainer->getByHierarchicalName( _sName ), UNO_QUERY_THROW );
2273 pView->showPreview( xContent );
2275 break;
2277 case E_TABLE:
2278 case E_QUERY:
2280 SharedConnection xConnection( ensureConnection() );
2281 if ( xConnection.is() )
2282 pView->showPreview( getDatabaseName(), xConnection, _sName, _eType == E_TABLE );
2284 return;
2286 default:
2287 OSL_FAIL( "OApplicationController::showPreviewFor: unexpected element type!" );
2288 break;
2291 catch( const SQLException& )
2293 showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
2295 catch(const Exception& )
2297 DBG_UNHANDLED_EXCEPTION();
2301 //------------------------------------------------------------------------------
2302 IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged)
2304 OnInvalidateClipboard();
2305 return 0L;
2307 //------------------------------------------------------------------------------
2308 void OApplicationController::OnInvalidateClipboard()
2310 InvalidateFeature(ID_BROWSER_CUT);
2311 InvalidateFeature(ID_BROWSER_COPY);
2312 InvalidateFeature(ID_BROWSER_PASTE);
2313 InvalidateFeature(SID_DB_APP_PASTE_SPECIAL);
2315 // -----------------------------------------------------------------------------
2316 void OApplicationController::onCutEntry()
2319 // -----------------------------------------------------------------------------
2320 void OApplicationController::onCopyEntry()
2322 Execute(ID_BROWSER_COPY,Sequence<PropertyValue>());
2324 // -----------------------------------------------------------------------------
2325 void OApplicationController::onPasteEntry()
2327 Execute(ID_BROWSER_PASTE,Sequence<PropertyValue>());
2329 // -----------------------------------------------------------------------------
2330 void OApplicationController::onDeleteEntry()
2332 ElementType eType = getContainer()->getElementType();
2333 sal_uInt16 nId = 0;
2334 switch(eType)
2336 case E_TABLE:
2337 nId = SID_DB_APP_TABLE_DELETE;
2338 break;
2339 case E_QUERY:
2340 nId = SID_DB_APP_QUERY_DELETE;
2341 break;
2342 case E_FORM:
2343 nId = SID_DB_APP_FORM_DELETE;
2344 break;
2345 case E_REPORT:
2346 nId = SID_DB_APP_REPORT_DELETE;
2347 break;
2348 default:
2349 OSL_FAIL("Invalid ElementType!");
2350 break;
2352 executeChecked(nId,Sequence<PropertyValue>());
2355 // -----------------------------------------------------------------------------
2356 void OApplicationController::executeUnChecked(const URL& _rCommand, const Sequence< PropertyValue>& aArgs)
2358 OApplicationController_CBASE::executeUnChecked( _rCommand, aArgs );
2361 // -----------------------------------------------------------------------------
2362 void OApplicationController::executeChecked(const URL& _rCommand, const Sequence< PropertyValue>& aArgs)
2364 OApplicationController_CBASE::executeChecked( _rCommand, aArgs );
2367 // -----------------------------------------------------------------------------
2368 void OApplicationController::executeUnChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue>& aArgs)
2370 OApplicationController_CBASE::executeUnChecked( _nCommandId, aArgs );
2373 // -----------------------------------------------------------------------------
2374 void OApplicationController::executeChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue>& aArgs)
2376 OApplicationController_CBASE::executeChecked( _nCommandId, aArgs );
2379 // -----------------------------------------------------------------------------
2380 sal_Bool OApplicationController::isCommandEnabled(sal_uInt16 _nCommandId) const
2382 return OApplicationController_CBASE::isCommandEnabled( _nCommandId );
2385 // -----------------------------------------------------------------------------
2386 sal_Bool OApplicationController::isCommandEnabled( const OUString& _rCompleteCommandURL ) const
2388 return OApplicationController_CBASE::isCommandEnabled( _rCompleteCommandURL );
2391 // -----------------------------------------------------------------------------
2392 sal_uInt16 OApplicationController::registerCommandURL( const OUString& _rCompleteCommandURL )
2394 return OApplicationController_CBASE::registerCommandURL( _rCompleteCommandURL );
2397 // -----------------------------------------------------------------------------
2398 void OApplicationController::notifyHiContrastChanged()
2400 OApplicationController_CBASE::notifyHiContrastChanged();
2403 // -----------------------------------------------------------------------------
2404 Reference< XController > OApplicationController::getXController() throw( RuntimeException )
2406 return OApplicationController_CBASE::getXController();
2409 // -----------------------------------------------------------------------------
2410 bool OApplicationController::interceptUserInput( const NotifyEvent& _rEvent )
2412 return OApplicationController_CBASE::interceptUserInput( _rEvent );
2415 // -----------------------------------------------------------------------------
2416 PopupMenu* OApplicationController::getContextMenu( Control& /*_rControl*/ ) const
2418 return new PopupMenu( ModuleRes( RID_MENU_APP_EDIT ) );
2421 // -----------------------------------------------------------------------------
2422 IController& OApplicationController::getCommandController()
2424 return *static_cast< IApplicationController* >( this );
2427 // -----------------------------------------------------------------------------
2428 ::cppu::OInterfaceContainerHelper* OApplicationController::getContextMenuInterceptors()
2430 return &m_aContextMenuInterceptors;
2433 // -----------------------------------------------------------------------------
2434 Any OApplicationController::getCurrentSelection( Control& _rControl ) const
2436 Sequence< NamedDatabaseObject > aSelection;
2437 getContainer()->describeCurrentSelectionForControl( _rControl, aSelection );
2438 return makeAny( aSelection );
2441 // -----------------------------------------------------------------------------
2442 sal_Bool OApplicationController::requestQuickHelp( const SvTreeListEntry* /*_pEntry*/, OUString& /*_rText*/ ) const
2444 return sal_False;
2447 // -----------------------------------------------------------------------------
2448 sal_Bool OApplicationController::requestDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
2450 TransferableHelper* pTransfer = NULL;
2451 if ( getContainer() && getContainer()->getSelectionCount() )
2455 pTransfer = copyObject( );
2456 Reference< XTransferable> xEnsureDelete = pTransfer;
2458 if ( pTransfer && getContainer()->getDetailView() )
2460 ElementType eType = getContainer()->getElementType();
2461 pTransfer->StartDrag( getContainer()->getDetailView()->getTreeWindow(), ((eType == E_FORM || eType == E_REPORT) ? DND_ACTION_COPYMOVE : DND_ACTION_COPY) );
2464 catch(const Exception& )
2466 DBG_UNHANDLED_EXCEPTION();
2470 return NULL != pTransfer;
2472 // -----------------------------------------------------------------------------
2473 sal_Int8 OApplicationController::queryDrop( const AcceptDropEvent& _rEvt, const DataFlavorExVector& _rFlavors )
2475 sal_Int8 nActionAskedFor = _rEvt.mnAction;
2476 // check if we're a table or query container
2477 OApplicationView* pView = getContainer();
2478 if ( pView && !isDataSourceReadOnly() )
2480 ElementType eType = pView->getElementType();
2481 if ( eType != E_NONE && (eType != E_TABLE || !isConnectionReadOnly()) )
2483 // check for the concrete type
2484 if(::std::find_if(_rFlavors.begin(),_rFlavors.end(),TAppSupportedSotFunctor(eType,sal_True)) != _rFlavors.end())
2485 return DND_ACTION_COPY;
2486 if ( eType == E_FORM || eType == E_REPORT )
2488 sal_Int8 nAction = OComponentTransferable::canExtractComponentDescriptor(_rFlavors,eType == E_FORM) ? DND_ACTION_COPY : DND_ACTION_NONE;
2489 if ( nAction != DND_ACTION_NONE )
2491 SvTreeListEntry* pHitEntry = pView->getEntry(_rEvt.maPosPixel);
2492 OUString sName;
2493 if ( pHitEntry )
2495 sName = pView->getQualifiedName( pHitEntry );
2496 if ( !sName.isEmpty() )
2498 Reference< XHierarchicalNameAccess > xContainer(getElements(pView->getElementType()),UNO_QUERY);
2499 if ( xContainer.is() && xContainer->hasByHierarchicalName(sName) )
2501 Reference< XHierarchicalNameAccess > xHitObject(xContainer->getByHierarchicalName(sName),UNO_QUERY);
2502 if ( xHitObject.is() )
2503 nAction = nActionAskedFor & DND_ACTION_COPYMOVE;
2505 else
2506 nAction = DND_ACTION_NONE;
2510 return nAction;
2515 return DND_ACTION_NONE;
2517 // -----------------------------------------------------------------------------
2518 sal_Int8 OApplicationController::executeDrop( const ExecuteDropEvent& _rEvt )
2520 OApplicationView* pView = getContainer();
2521 if ( !pView || pView->getElementType() == E_NONE )
2523 OSL_FAIL("OApplicationController::executeDrop: what the hell did queryDrop do?");
2524 // queryDrop shoud not have allowed us to reach this situation ....
2525 return DND_ACTION_NONE;
2528 // a TransferableDataHelper for accessing the dropped data
2529 TransferableDataHelper aDroppedData(_rEvt.maDropEvent.Transferable);
2532 // reset the data of the previous async drop (if any)
2533 if ( m_nAsyncDrop )
2534 Application::RemoveUserEvent(m_nAsyncDrop);
2537 m_nAsyncDrop = 0;
2538 m_aAsyncDrop.aDroppedData.clear();
2539 m_aAsyncDrop.nType = pView->getElementType();
2540 m_aAsyncDrop.nAction = _rEvt.mnAction;
2541 m_aAsyncDrop.bError = sal_False;
2542 m_aAsyncDrop.bHtml = sal_False;
2543 m_aAsyncDrop.aUrl = OUString();
2546 // loop through the available formats and see what we can do ...
2547 // first we have to check if it is our own format, if not we have to copy the stream :-(
2548 if ( ODataAccessObjectTransferable::canExtractObjectDescriptor(aDroppedData.GetDataFlavorExVector()) )
2550 m_aAsyncDrop.aDroppedData = ODataAccessObjectTransferable::extractObjectDescriptor(aDroppedData);
2552 // asyncron because we some dialogs and we aren't allowed to show them while in D&D
2553 m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
2554 return DND_ACTION_COPY;
2556 else if ( OComponentTransferable::canExtractComponentDescriptor(aDroppedData.GetDataFlavorExVector(),m_aAsyncDrop.nType == E_FORM) )
2558 m_aAsyncDrop.aDroppedData = OComponentTransferable::extractComponentDescriptor(aDroppedData);
2559 SvTreeListEntry* pHitEntry = pView->getEntry(_rEvt.maPosPixel);
2560 if ( pHitEntry )
2561 m_aAsyncDrop.aUrl = pView->getQualifiedName( pHitEntry );
2563 sal_Int8 nAction = _rEvt.mnAction;
2564 Reference<XContent> xContent;
2565 m_aAsyncDrop.aDroppedData[daComponent] >>= xContent;
2566 if ( xContent.is() )
2568 OUString sName = xContent->getIdentifier()->getContentIdentifier();
2569 sal_Int32 nIndex = 0;
2570 sName = sName.copy(sName.getToken(0,'/',nIndex).getLength() + 1);
2571 if ( m_aAsyncDrop.aUrl.Len() >= sName.getLength() && 0 == sName.compareTo(m_aAsyncDrop.aUrl,sName.getLength()) )
2573 m_aAsyncDrop.aDroppedData.clear();
2574 return DND_ACTION_NONE;
2577 // check if move is allowed, if another object with the same name exists only copy is allowed
2578 Reference< XHierarchicalNameAccess > xContainer(getElements(m_aAsyncDrop.nType),UNO_QUERY);
2579 Reference<XNameAccess> xNameAccess(xContainer,UNO_QUERY);
2581 if ( m_aAsyncDrop.aUrl.Len() && xContainer.is() && xContainer->hasByHierarchicalName(m_aAsyncDrop.aUrl) )
2582 xNameAccess.set(xContainer->getByHierarchicalName(m_aAsyncDrop.aUrl),UNO_QUERY);
2584 if ( xNameAccess.is() )
2586 Reference<XPropertySet> xProp(xContent,UNO_QUERY);
2587 if ( xProp.is() )
2589 xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
2590 if ( xNameAccess.is() && xNameAccess->hasByName(sName) )
2591 nAction &= ~DND_ACTION_MOVE;
2593 else
2594 nAction &= ~DND_ACTION_MOVE;
2597 if ( nAction != DND_ACTION_NONE )
2599 m_aAsyncDrop.nAction = nAction;
2600 // asyncron because we some dialogs and we aren't allowed to show them while in D&D
2601 m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
2603 else
2604 m_aAsyncDrop.aDroppedData.clear();
2605 return nAction;
2607 else
2609 SharedConnection xConnection( ensureConnection() );
2610 if ( xConnection.is() && m_aTableCopyHelper.copyTagTable( aDroppedData, m_aAsyncDrop, xConnection ) )
2612 // asyncron because we some dialogs and we aren't allowed to show them while in D&D
2613 m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
2614 return DND_ACTION_COPY;
2618 return DND_ACTION_NONE;
2620 // -----------------------------------------------------------------------------
2621 Reference< XModel > SAL_CALL OApplicationController::getModel(void) throw( RuntimeException )
2623 return m_xModel;
2626 // -----------------------------------------------------------------------------
2627 void OApplicationController::onAttachedFrame()
2629 sal_Int32 nConnectedControllers( 0 );
2632 Reference< XModel2 > xModel( m_xModel, UNO_QUERY_THROW );
2633 Reference< XEnumeration > xEnumControllers( xModel->getControllers(), UNO_SET_THROW );
2634 while ( xEnumControllers->hasMoreElements() )
2636 Reference< XController > xController( xEnumControllers->nextElement(), UNO_QUERY_THROW );
2637 ++nConnectedControllers;
2640 catch( const Exception& )
2642 DBG_UNHANDLED_EXCEPTION();
2645 if ( nConnectedControllers > 1 )
2646 { // we are not the first connected controller, there were already others
2647 return;
2650 OnFirstControllerConnected();
2653 // -----------------------------------------------------------------------------
2654 void OApplicationController::OnFirstControllerConnected()
2656 if ( !m_xModel.is() )
2658 OSL_FAIL( "OApplicationController::OnFirstControllerConnected: too late!" );
2661 // if we have forms or reports which contain macros/scripts, then show a warning
2662 // which suggests the user to migrate them to the database document
2663 Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
2664 if ( xDocumentScripts.is() )
2666 // no need to show this warning, obviously the document supports embedding scripts
2667 // into itself, so there are no "old-style" forms/reports which have macros/scripts
2668 // themselves
2669 return;
2674 // If the migration just happened, but was not successful, the document is reloaded.
2675 // In this case, we should not show the warning, again.
2676 ::comphelper::NamedValueCollection aModelArgs( m_xModel->getArgs() );
2677 if ( aModelArgs.getOrDefault( "SuppressMigrationWarning", sal_False ) )
2678 return;
2680 // also, if the document is read-only, then no migration is possible, and the
2681 // respective menu entry is hidden. So, don't show the warning in this case, too.
2682 if ( Reference< XStorable >( m_xModel, UNO_QUERY_THROW )->isReadonly() )
2683 return;
2685 SQLWarning aWarning;
2686 aWarning.Message = OUString( ModuleRes( STR_SUB_DOCS_WITH_SCRIPTS ) );
2687 SQLException aDetail;
2688 aDetail.Message = OUString( ModuleRes( STR_SUB_DOCS_WITH_SCRIPTS_DETAIL ) );
2689 aWarning.NextException <<= aDetail;
2691 Reference< XExecutableDialog > xDialog = ErrorMessageDialog::create( getORB(), "", NULL, makeAny( aWarning ) );
2692 xDialog->execute();
2694 catch( const Exception& )
2696 DBG_UNHANDLED_EXCEPTION();
2699 return;
2702 // -----------------------------------------------------------------------------
2703 void SAL_CALL OApplicationController::attachFrame( const Reference< XFrame > & i_rxFrame ) throw( RuntimeException )
2705 ::osl::MutexGuard aGuard( getMutex() );
2707 OApplicationController_CBASE::attachFrame( i_rxFrame );
2708 if ( getFrame().is() )
2709 onAttachedFrame();
2712 // -----------------------------------------------------------------------------
2713 sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > & _rxModel) throw( RuntimeException )
2715 ::osl::MutexGuard aGuard( getMutex() );
2716 const Reference< XOfficeDatabaseDocument > xOfficeDoc( _rxModel, UNO_QUERY );
2717 const Reference< XModifiable > xDocModify( _rxModel, UNO_QUERY );
2718 if ( ( !xOfficeDoc.is() || !xDocModify.is() ) && _rxModel.is() )
2720 OSL_FAIL( "OApplicationController::attachModel: invalid model!" );
2721 return sal_False;
2724 if ( m_xModel.is() && ( m_xModel != _rxModel ) && ( _rxModel.is() ) )
2726 OSL_ENSURE( false, "OApplicationController::attachModel: missing implementation: setting a new model while we have another one!" );
2727 // we'd need to completely update our view here, close sub components, and the like
2728 return sal_False;
2731 const OUString aPropertyNames[] =
2733 OUString(PROPERTY_URL), OUString(PROPERTY_USER)
2736 // disconnect from old model
2739 if ( m_xDataSource.is() )
2741 for ( size_t i=0; i < sizeof( aPropertyNames ) / sizeof( aPropertyNames[0] ); ++i )
2743 m_xDataSource->removePropertyChangeListener( aPropertyNames[i], this );
2747 Reference< XModifyBroadcaster > xBroadcaster( m_xModel, UNO_QUERY );
2748 if ( xBroadcaster.is() )
2749 xBroadcaster->removeModifyListener( this );
2751 catch( const Exception& )
2753 DBG_UNHANDLED_EXCEPTION();
2756 m_xModel = _rxModel;
2757 m_xDocumentModify = xDocModify;
2758 m_xDataSource.set( xOfficeDoc.is() ? xOfficeDoc->getDataSource() : Reference< XDataSource >(), UNO_QUERY );
2760 // connect to new model
2763 if ( m_xDataSource.is() )
2765 for ( size_t i=0; i < sizeof( aPropertyNames ) / sizeof( aPropertyNames[0] ); ++i )
2767 m_xDataSource->addPropertyChangeListener( aPropertyNames[i], this );
2771 Reference< XModifyBroadcaster > xBroadcaster( m_xModel, UNO_QUERY_THROW );
2772 xBroadcaster->addModifyListener( this );
2775 catch( const Exception& )
2777 DBG_UNHANDLED_EXCEPTION();
2780 // initial preview mode
2781 if ( m_xDataSource.is() )
2785 // to get the 'modified' for the data source
2786 ::comphelper::NamedValueCollection aLayoutInfo( m_xDataSource->getPropertyValue( PROPERTY_LAYOUTINFORMATION ) );
2787 if ( aLayoutInfo.has( (OUString)INFO_PREVIEW ) )
2789 const sal_Int32 nPreviewMode( aLayoutInfo.getOrDefault( (OUString)INFO_PREVIEW, (sal_Int32)0 ) );
2790 m_ePreviewMode = static_cast< PreviewMode >( nPreviewMode );
2791 if ( getView() )
2792 getContainer()->switchPreview( m_ePreviewMode );
2795 catch( const Exception& )
2797 DBG_UNHANDLED_EXCEPTION();
2801 return sal_True;
2803 // -----------------------------------------------------------------------------
2804 void OApplicationController::containerFound( const Reference< XContainer >& _xContainer)
2808 if ( _xContainer.is() )
2810 m_aCurrentContainers.push_back(_xContainer);
2811 _xContainer->addContainerListener(this);
2814 catch(const Exception&)
2816 DBG_UNHANDLED_EXCEPTION();
2819 // -----------------------------------------------------------------------------
2820 OUString OApplicationController::getCurrentlySelectedName(sal_Int32& _rnCommandType) const
2822 _rnCommandType = ( (getContainer()->getElementType() == E_QUERY)
2823 ? CommandType::QUERY : ( (getContainer()->getElementType() == E_TABLE) ? CommandType::TABLE : -1 ));
2826 OUString sName;
2827 if ( _rnCommandType != -1 )
2831 sName = getContainer()->getQualifiedName( NULL );
2832 OSL_ENSURE( !sName.isEmpty(), "OApplicationController::getCurrentlySelectedName: no name given!" );
2834 catch( const Exception& )
2836 DBG_UNHANDLED_EXCEPTION();
2839 return sName;
2842 // -----------------------------------------------------------------------------
2843 void SAL_CALL OApplicationController::addSelectionChangeListener( const Reference< view::XSelectionChangeListener >& _Listener ) throw (RuntimeException)
2845 m_pSelectionNotifier->addListener( _Listener );
2848 // -----------------------------------------------------------------------------
2849 void SAL_CALL OApplicationController::removeSelectionChangeListener( const Reference< view::XSelectionChangeListener >& _Listener ) throw (RuntimeException)
2851 m_pSelectionNotifier->removeListener( _Listener );
2854 // -----------------------------------------------------------------------------
2855 ::sal_Bool SAL_CALL OApplicationController::select( const Any& _aSelection ) throw (IllegalArgumentException, RuntimeException)
2857 SolarMutexGuard aSolarGuard;
2858 ::osl::MutexGuard aGuard( getMutex() );
2859 Sequence< OUString> aSelection;
2860 if ( !_aSelection.hasValue() || !getView() )
2862 getContainer()->selectElements(aSelection);
2863 return sal_True;
2866 // --------------------------------------------------------------
2867 // BEGIN compatibility
2868 Sequence< NamedValue > aCurrentSelection;
2869 if ( (_aSelection >>= aCurrentSelection) && aCurrentSelection.getLength() )
2871 ElementType eType = E_NONE;
2872 const NamedValue* pIter = aCurrentSelection.getConstArray();
2873 const NamedValue* pEnd = pIter + aCurrentSelection.getLength();
2874 for(;pIter != pEnd;++pIter)
2876 if ( pIter->Name == "Type" )
2878 sal_Int32 nType = 0;
2879 pIter->Value >>= nType;
2880 if ( nType < DatabaseObject::TABLE || nType > DatabaseObject::REPORT )
2881 throw IllegalArgumentException();
2882 eType = static_cast< ElementType >( nType );
2884 else if ( pIter->Name == "Selection" )
2885 pIter->Value >>= aSelection;
2888 m_aSelectContainerEvent.CancelCall(); // just in case the async select request was running
2889 getContainer()->selectContainer(eType);
2890 getContainer()->selectElements(aSelection);
2891 return sal_True;
2893 // END compatibility
2894 // --------------------------------------------------------------
2896 Sequence< NamedDatabaseObject > aSelectedObjects;
2897 if ( !( _aSelection >>= aSelectedObjects ) )
2899 aSelectedObjects.realloc( 1 );
2900 if ( !( _aSelection >>= aSelectedObjects[0] ) )
2901 throw IllegalArgumentException();
2904 SelectionByElementType aSelectedElements;
2905 ElementType eSelectedCategory = E_NONE;
2906 for ( const NamedDatabaseObject* pObject = aSelectedObjects.getConstArray();
2907 pObject != aSelectedObjects.getConstArray() + aSelectedObjects.getLength();
2908 ++pObject
2911 switch ( pObject->Type )
2913 case DatabaseObject::TABLE:
2914 case DatabaseObjectContainer::SCHEMA:
2915 case DatabaseObjectContainer::CATALOG:
2916 aSelectedElements[ E_TABLE ].push_back( pObject->Name );
2917 break;
2918 case DatabaseObject::QUERY:
2919 aSelectedElements[ E_QUERY ].push_back( pObject->Name );
2920 break;
2921 case DatabaseObject::FORM:
2922 case DatabaseObjectContainer::FORMS_FOLDER:
2923 aSelectedElements[ E_FORM ].push_back( pObject->Name );
2924 break;
2925 case DatabaseObject::REPORT:
2926 case DatabaseObjectContainer::REPORTS_FOLDER:
2927 aSelectedElements[ E_REPORT ].push_back( pObject->Name );
2928 break;
2929 case DatabaseObjectContainer::TABLES:
2930 case DatabaseObjectContainer::QUERIES:
2931 case DatabaseObjectContainer::FORMS:
2932 case DatabaseObjectContainer::REPORTS:
2933 if ( eSelectedCategory != E_NONE )
2934 throw IllegalArgumentException(
2935 OUString(ModuleRes(RID_STR_NO_DIFF_CAT)),
2936 *this, sal_Int16( pObject - aSelectedObjects.getConstArray() ) );
2937 eSelectedCategory =
2938 ( pObject->Type == DatabaseObjectContainer::TABLES ) ? E_TABLE
2939 : ( pObject->Type == DatabaseObjectContainer::QUERIES ) ? E_QUERY
2940 : ( pObject->Type == DatabaseObjectContainer::FORMS ) ? E_FORM
2941 : ( pObject->Type == DatabaseObjectContainer::REPORTS ) ? E_REPORT
2942 : E_NONE;
2943 break;
2945 default:
2946 case DatabaseObjectContainer::DATA_SOURCE:
2948 OUString sMessage(
2949 OUString(
2950 OUString(ModuleRes(RID_STR_UNSUPPORTED_OBJECT_TYPE))).
2951 replaceFirst("$type$", OUString::valueOf(sal_Int32(pObject->Type))));
2952 throw IllegalArgumentException(sMessage, *this, sal_Int16( pObject - aSelectedObjects.getConstArray() ));
2957 for ( SelectionByElementType::const_iterator sel = aSelectedElements.begin();
2958 sel != aSelectedElements.end();
2959 ++sel
2962 if ( sel->first == m_eCurrentType )
2964 Sequence< OUString > aSelected( sel->second.size() );
2965 ::std::copy( sel->second.begin(), sel->second.end(), aSelected.getArray() );
2966 getContainer()->selectElements( aSelected );
2968 else
2970 m_aPendingSelection[ sel->first ] = sel->second;
2974 m_aSelectContainerEvent.CancelCall(); // just in case the async select request was running
2975 getContainer()->selectContainer( eSelectedCategory );
2977 return sal_True;
2979 // -----------------------------------------------------------------------------
2980 Any SAL_CALL OApplicationController::getSelection( ) throw (RuntimeException)
2982 SolarMutexGuard aSolarGuard;
2983 ::osl::MutexGuard aGuard( getMutex() );
2985 Sequence< NamedDatabaseObject > aCurrentSelection;
2986 const ElementType eType( getContainer()->getElementType() );
2987 if ( eType != E_NONE )
2989 getContainer()->describeCurrentSelectionForType( eType, aCurrentSelection );
2990 if ( aCurrentSelection.getLength() == 0 )
2991 { // if no objects are selected, add an entry to the sequence which describes the overall category
2992 // which is selected currently
2993 aCurrentSelection.realloc(1);
2994 aCurrentSelection[0].Name = getDatabaseName();
2995 switch ( eType )
2997 case E_TABLE: aCurrentSelection[0].Type = DatabaseObjectContainer::TABLES; break;
2998 case E_QUERY: aCurrentSelection[0].Type = DatabaseObjectContainer::QUERIES; break;
2999 case E_FORM: aCurrentSelection[0].Type = DatabaseObjectContainer::FORMS; break;
3000 case E_REPORT: aCurrentSelection[0].Type = DatabaseObjectContainer::REPORTS; break;
3001 default:
3002 OSL_FAIL( "OApplicationController::getSelection: unexpected current element type!" );
3003 break;
3007 return makeAny( aCurrentSelection );
3009 // -----------------------------------------------------------------------------
3010 void OApplicationController::impl_migrateScripts_nothrow()
3014 Reference< XExecutableDialog > xDialog = css::sdb::application::MacroMigrationWizard::createWithDocument( getORB(), Reference< XOfficeDatabaseDocument >( m_xModel, UNO_QUERY_THROW ) );
3015 xDialog->execute();
3017 catch( const Exception& )
3019 DBG_UNHANDLED_EXCEPTION();
3023 //........................................................................
3024 } // namespace dbaui
3025 //........................................................................
3027 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */