merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / app / AppController.cxx
blob2af08e0d0175a86099836b67e03815b3b11ccf2a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AppController.cxx,v $
10 * $Revision: 1.63.20.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "AppController.hxx"
35 #include "dbustrings.hrc"
36 #include "advancedsettingsdlg.hxx"
37 #include "subcomponentmanager.hxx"
39 /** === begin UNO includes === **/
40 #include <com/sun/star/beans/NamedValue.hpp>
41 #include <com/sun/star/container/XChild.hpp>
42 #include <com/sun/star/container/XContainer.hpp>
43 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
44 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
45 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
46 #include <com/sun/star/container/XNameContainer.hpp>
47 #include <com/sun/star/frame/FrameSearchFlag.hpp>
48 #include <com/sun/star/frame/XStorable.hpp>
49 #include <com/sun/star/sdb/CommandType.hpp>
50 #include <com/sun/star/sdb/SQLContext.hpp>
51 #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
52 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
53 #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
54 #include <com/sun/star/sdbc/XDataSource.hpp>
55 #include <com/sun/star/sdbcx/XAlterView.hpp>
56 #include <com/sun/star/sdbcx/XAppend.hpp>
57 #include <com/sun/star/sdbcx/XRename.hpp>
58 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
59 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
60 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
61 #include <com/sun/star/uno/XNamingService.hpp>
62 #include <com/sun/star/util/XFlushable.hpp>
63 #include <com/sun/star/util/XModifiable.hpp>
64 #include <com/sun/star/util/XModifyBroadcaster.hpp>
65 #include <com/sun/star/util/XNumberFormatter.hpp>
66 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
67 #include <com/sun/star/document/XEmbeddedScripts.hpp>
68 #include <com/sun/star/frame/XModel2.hpp>
69 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
70 #include <com/sun/star/util/XModifyBroadcaster.hpp>
71 #include <com/sun/star/util/XModifiable.hpp>
72 #include <com/sun/star/frame/FrameSearchFlag.hpp>
73 #include <com/sun/star/util/XFlushable.hpp>
74 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
75 #include "com/sun/star/beans/NamedValue.hpp"
76 #include <com/sun/star/awt/XTopWindow.hpp>
77 #include <com/sun/star/task/XInteractionHandler.hpp>
78 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
79 #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
80 #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
81 /** === end UNO includes === **/
83 #ifndef _TOOLS_DEBUG_HXX
84 #include <tools/debug.hxx>
85 #endif
86 #ifndef TOOLS_DIAGNOSE_EX_H
87 #include <tools/diagnose_ex.h>
88 #endif
89 #ifndef SVTOOLS_URIHELPER_HXX
90 #include <svtools/urihelper.hxx>
91 #endif
92 #ifndef _COMPHELPER_TYPES_HXX_
93 #include <comphelper/types.hxx>
94 #endif
95 #ifndef _COMPHELPER_INTERACTION_HXX_
96 #include <comphelper/interaction.hxx>
97 #endif
98 #ifndef COMPHELPER_COMPONENTCONTEXT_HXX
99 #include <comphelper/componentcontext.hxx>
100 #endif
101 #ifndef _SV_MSGBOX_HXX
102 #include <vcl/msgbox.hxx>
103 #endif
104 #ifndef _VCL_STDTEXT_HXX
105 #include <vcl/stdtext.hxx>
106 #endif
107 #ifndef _FILEDLGHELPER_HXX
108 #include <sfx2/filedlghelper.hxx>
109 #endif
110 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
111 #include <cppuhelper/typeprovider.hxx>
112 #endif
113 #ifndef _CPPUHELPER_EXC_HLP_HXX_
114 #include <cppuhelper/exc_hlp.hxx>
115 #endif
116 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
117 #include <connectivity/dbtools.hxx>
118 #endif
119 #ifndef DBAUI_APPVIEW_HXX
120 #include "AppView.hxx"
121 #endif
122 #ifndef DBACCESS_UI_BROWSER_ID_HXX
123 #include "browserids.hxx"
124 #endif
125 #ifndef _DBAU_REGHELPER_HXX_
126 #include "dbu_reghelper.hxx"
127 #endif
128 #ifndef _DBU_APP_HRC_
129 #include "dbu_app.hrc"
130 #endif
131 #ifndef DBACCESS_SOURCE_UI_MISC_DEFAULTOBJECTNAMECHECK_HXX
132 #include "defaultobjectnamecheck.hxx"
133 #endif
134 #ifndef _SV_MENU_HXX
135 #include <vcl/menu.hxx>
136 #endif
137 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
138 #include <svtools/pathoptions.hxx>
139 #endif
140 #ifndef INCLUDED_SVTOOLS_INTERNALOPTIONS_HXX
141 #include <svtools/internaloptions.hxx>
142 #endif
143 #ifndef _COMPHELPER_UNO3_HXX_
144 #include <comphelper/uno3.hxx>
145 #endif
146 #ifndef DBACCESS_DATABASE_OBJECT_VIEW_HXX
147 #include "databaseobjectview.hxx"
148 #endif
149 #ifndef _SV_SVAPP_HXX //autogen
150 #include <vcl/svapp.hxx>
151 #endif
152 #ifndef _SVLBOXITM_HXX
153 #include <svtools/svlbitm.hxx>
154 #endif
155 #ifndef _DBAUI_LISTVIEWITEMS_HXX_
156 #include "listviewitems.hxx"
157 #endif
159 #ifndef DBAUI_APPDETAILVIEW_HXX
160 #include "AppDetailView.hxx"
161 #endif
162 #ifndef _DBAUI_LINKEDDOCUMENTS_HXX_
163 #include "linkeddocuments.hxx"
164 #endif
165 #ifndef _SV_LSTBOX_HXX
166 #include <vcl/lstbox.hxx>
167 #endif
168 #ifndef _DBHELPER_DBEXCEPTION_HXX_
169 #include <connectivity/dbexception.hxx>
170 #endif
171 #ifndef _DBAUI_SQLMESSAGE_HXX_
172 #include "sqlmessage.hxx"
173 #endif
174 #ifndef _STRING_HXX
175 #include <tools/string.hxx>
176 #endif
177 #ifndef INCLUDED_SFX_MAILMODELAPI_HXX
178 #include <sfx2/mailmodelapi.hxx>
179 #endif
180 #ifndef INCLUDED_SVTOOLS_MODULEOPTIONS_HXX
181 #include <svtools/moduleoptions.hxx>
182 #endif
183 #ifndef _SVTREEBOX_HXX
184 #include <svtools/svtreebx.hxx>
185 #endif
186 #ifndef _TRANSFER_HXX
187 #include <svtools/transfer.hxx>
188 #endif
189 #ifndef _CLIPLISTENER_HXX
190 #include <svtools/cliplistener.hxx>
191 #endif
192 #ifndef _SVX_DBAEXCHANGE_HXX_
193 #include <svx/dbaexchange.hxx>
194 #endif
195 #ifndef SVX_DBAOBJECTEX_HXX
196 #include <svx/dbaobjectex.hxx>
197 #endif
198 #ifndef DBAUI_TOOLS_HXX
199 #include "UITools.hxx"
200 #endif
201 #ifndef _DBAUI_DSNTYPES_HXX_
202 #include "dsntypes.hxx"
203 #endif
204 #include <svx/svxdlg.hxx>
205 #include <svtools/insdlg.hxx>
206 #ifndef _UNOTOOLS_TEMPFILE_HXX
207 #include <unotools/tempfile.hxx>
208 #endif
209 #ifndef _DBA_DBACCESS_HELPID_HRC_
210 #include "dbaccess_helpid.hrc"
211 #endif
212 #ifndef DBAUI_DLGSAVE_HXX
213 #include "dlgsave.hxx"
214 #endif
215 #ifndef _SFX_DOCFILT_HACK_HXX
216 #include <sfx2/docfilt.hxx>
217 #endif
218 #ifndef SFX_QUERYSAVEDOCUMENT_HXX
219 #include <sfx2/QuerySaveDocument.hxx>
220 #endif
221 #ifndef INCLUDED_SVTOOLS_HISTORYOPTIONS_HXX
222 #include <svtools/historyoptions.hxx>
223 #endif
224 #ifndef SVTOOLS_FILENOTATION_HXX_
225 #include <svtools/filenotation.hxx>
226 #endif
227 #ifndef _COMPHELPER_SEQUENCE_HXX_
228 #include <comphelper/sequence.hxx>
229 #endif
230 #ifndef _VOS_MUTEX_HXX_
231 #include <vos/mutex.hxx>
232 #endif
233 #ifndef _DBACCESS_SLOTID_HRC_
234 #include "dbaccess_slotid.hrc"
235 #endif
237 #include <algorithm>
238 #include <functional>
240 #include <boost/noncopyable.hpp>
242 extern "C" void SAL_CALL createRegistryInfo_ODBApplication()
244 static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OApplicationController > aAutoRegistration;
246 //........................................................................
247 namespace dbaui
249 //........................................................................
250 using namespace ::dbtools;
251 using namespace ::svx;
252 using namespace ::com::sun::star;
253 using namespace ::com::sun::star::uno;
254 using namespace ::com::sun::star::ucb;
255 using namespace ::com::sun::star::view;
256 using namespace ::com::sun::star::util;
257 using namespace ::com::sun::star::beans;
258 using namespace ::com::sun::star::lang;
259 using namespace ::com::sun::star::frame;
260 using namespace ::com::sun::star::container;
261 using namespace ::com::sun::star::sdb;
262 using namespace ::com::sun::star::sdbc;
263 using namespace ::com::sun::star::sdbcx;
264 using namespace ::com::sun::star::datatransfer;
265 using namespace ::com::sun::star::ui::dialogs;
266 using namespace ::com::sun::star::task;
267 using ::com::sun::star::document::XEmbeddedScripts;
268 using ::com::sun::star::document::XDocumentEventBroadcaster;
269 using ::com::sun::star::document::DocumentEvent;
270 using ::com::sun::star::sdb::application::NamedDatabaseObject;
272 namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
273 namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
275 //------------------------------------------------------------------------------
276 ::rtl::OUString SAL_CALL OApplicationController::getImplementationName() throw( RuntimeException )
278 return getImplementationName_Static();
281 //------------------------------------------------------------------------------
282 ::rtl::OUString OApplicationController::getImplementationName_Static() throw( RuntimeException )
284 return ::rtl::OUString(SERVICE_SDB_APPLICATIONCONTROLLER);
286 //------------------------------------------------------------------------------
287 Sequence< ::rtl::OUString> OApplicationController::getSupportedServiceNames_Static(void) throw( RuntimeException )
289 Sequence< ::rtl::OUString> aSupported(1);
290 aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.application.DefaultViewController");
291 return aSupported;
293 //-------------------------------------------------------------------------
294 Sequence< ::rtl::OUString> SAL_CALL OApplicationController::getSupportedServiceNames() throw(RuntimeException)
296 return getSupportedServiceNames_Static();
298 // -------------------------------------------------------------------------
299 Reference< XInterface > SAL_CALL OApplicationController::Create(const Reference<XMultiServiceFactory >& _rxFactory)
301 return *(new OApplicationController(_rxFactory));
303 // -----------------------------------------------------------------------------
305 struct XContainerFunctor : public ::std::unary_function< OApplicationController::TContainerVector::value_type , bool>
307 Reference<XContainerListener> m_xContainerListener;
308 XContainerFunctor( const Reference<XContainerListener>& _xContainerListener)
309 : m_xContainerListener(_xContainerListener){}
311 bool operator() (const OApplicationController::TContainerVector::value_type& lhs) const
313 if ( lhs.is() )
314 lhs->removeContainerListener(m_xContainerListener);
315 return true;
319 //====================================================================
320 //= OApplicationController
321 //====================================================================
322 class SelectionNotifier : public ::boost::noncopyable
324 private:
325 ::cppu::OInterfaceContainerHelper m_aSelectionListeners;
326 ::cppu::OWeakObject& m_rContext;
327 sal_Int32 m_nSelectionNestingLevel;
329 public:
330 SelectionNotifier( ::osl::Mutex& _rMutex, ::cppu::OWeakObject& _rContext )
331 :m_aSelectionListeners( _rMutex )
332 ,m_rContext( _rContext )
333 ,m_nSelectionNestingLevel( 0 )
337 void addListener( const Reference< XSelectionChangeListener >& _Listener )
339 m_aSelectionListeners.addInterface( _Listener );
342 void removeListener( const Reference< XSelectionChangeListener >& _Listener )
344 m_aSelectionListeners.removeInterface( _Listener );
347 void disposing()
349 EventObject aEvent( m_rContext );
350 m_aSelectionListeners.disposeAndClear( aEvent );
353 ~SelectionNotifier()
357 struct SelectionGuardAccess { friend class SelectionGuard; private: SelectionGuardAccess() { } };
359 /** enters a block which modifies the selection of our owner.
361 Can be called multiple times, the only important thing is to call leaveSelection
362 equally often.
364 void enterSelection( SelectionGuardAccess )
366 ++m_nSelectionNestingLevel;
369 /** leaves a block which modifies the selection of our owner
371 Must be paired with enterSelection calls.
373 When the last block is left, i.e. the last leaveSelection call is made on the current stack,
374 then our SelectionChangeListeners are notified
376 void leaveSelection( SelectionGuardAccess )
378 if ( --m_nSelectionNestingLevel == 0 )
380 EventObject aEvent( m_rContext );
381 m_aSelectionListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aEvent );
386 class SelectionGuard : public ::boost::noncopyable
388 public:
389 SelectionGuard( SelectionNotifier& _rNotifier )
390 :m_rNotifier( _rNotifier )
392 m_rNotifier.enterSelection( SelectionNotifier::SelectionGuardAccess() );
395 ~SelectionGuard()
397 m_rNotifier.leaveSelection( SelectionNotifier::SelectionGuardAccess() );
400 private:
401 SelectionNotifier& m_rNotifier;
404 //====================================================================
405 //= OApplicationController
406 //====================================================================
407 DBG_NAME(OApplicationController)
408 //--------------------------------------------------------------------
409 OApplicationController::OApplicationController(const Reference< XMultiServiceFactory >& _rxORB)
410 :OApplicationController_CBASE( _rxORB )
411 ,m_aContextMenuInterceptors( getMutex() )
412 ,m_pSubComponentManager( new SubComponentManager( *this, getSharedMutex() ) )
413 ,m_aTypeCollection(_rxORB)
414 ,m_aTableCopyHelper(this)
415 ,m_pClipbordNotifier(NULL)
416 ,m_nAsyncDrop(0)
417 ,m_aControllerConnectedEvent( LINK( this, OApplicationController, OnFirstControllerConnected ) )
418 ,m_aSelectContainerEvent( LINK( this, OApplicationController, OnSelectContainer ) )
419 ,m_ePreviewMode(E_PREVIEWNONE)
420 ,m_eCurrentType(E_NONE)
421 ,m_bNeedToReconnect(sal_False)
422 ,m_bSuspended( sal_False )
423 ,m_pSelectionNotifier( new SelectionNotifier( getMutex(), *this ) )
425 DBG_CTOR(OApplicationController,NULL);
427 //------------------------------------------------------------------------------
428 OApplicationController::~OApplicationController()
430 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
432 OSL_ENSURE(0,"Please check who doesn't dispose this component!");
433 // increment ref count to prevent double call of Dtor
434 osl_incrementInterlockedCount( &m_refCount );
435 dispose();
437 ::std::auto_ptr< Window> aTemp(m_pView);
438 m_pView = NULL;
440 DBG_DTOR(OApplicationController,NULL);
442 //--------------------------------------------------------------------
443 IMPLEMENT_FORWARD_XTYPEPROVIDER2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
444 IMPLEMENT_FORWARD_XINTERFACE2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
445 // -----------------------------------------------------------------------------
446 void OApplicationController::disconnect()
448 if ( m_xDataSourceConnection.is() )
449 stopConnectionListening( m_xDataSourceConnection );
453 // temporary (hopefully!) hack for #i55274#
454 Reference< XFlushable > xFlush( m_xDataSourceConnection, UNO_QUERY );
455 if ( xFlush.is() && m_xMetaData.is() && !m_xMetaData->isReadOnly() )
456 xFlush->flush();
458 catch( const Exception& )
460 DBG_UNHANDLED_EXCEPTION();
463 m_xDataSourceConnection.clear();
464 m_xMetaData.clear();
466 InvalidateAll();
469 //--------------------------------------------------------------------
470 void SAL_CALL OApplicationController::disposing()
472 m_aControllerConnectedEvent.CancelCall();
474 ::std::for_each(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),XContainerFunctor(this));
475 m_aCurrentContainers.clear();
476 m_pSubComponentManager->disposing();
477 m_pSelectionNotifier->disposing();
479 if ( getView() )
481 getContainer()->showPreview(NULL);
482 m_pClipbordNotifier->ClearCallbackLink();
483 m_pClipbordNotifier->AddRemoveListener( getView(), sal_False );
484 m_pClipbordNotifier->release();
485 m_pClipbordNotifier = NULL;
488 disconnect();
491 Reference < XFrame > xFrame;
492 attachFrame( xFrame );
494 if ( m_xDataSource.is() )
496 m_xDataSource->removePropertyChangeListener(::rtl::OUString(), this);
497 m_xDataSource->removePropertyChangeListener(PROPERTY_INFO, this);
498 m_xDataSource->removePropertyChangeListener(PROPERTY_URL, this);
499 m_xDataSource->removePropertyChangeListener(PROPERTY_ISPASSWORDREQUIRED, this);
500 m_xDataSource->removePropertyChangeListener(PROPERTY_LAYOUTINFORMATION, this);
501 m_xDataSource->removePropertyChangeListener(PROPERTY_SUPPRESSVERSIONCL, this);
502 m_xDataSource->removePropertyChangeListener(PROPERTY_TABLEFILTER, this);
503 m_xDataSource->removePropertyChangeListener(PROPERTY_TABLETYPEFILTER, this);
504 m_xDataSource->removePropertyChangeListener(PROPERTY_USER, this);
505 // otherwise we may delete our datasource twice
506 Reference<XPropertySet> xProp = m_xDataSource;
507 m_xDataSource = NULL;
510 Reference< XModifyBroadcaster > xBroadcaster( m_xModel, UNO_QUERY );
511 if ( xBroadcaster.is() )
512 xBroadcaster->removeModifyListener(static_cast<XModifyListener*>(this));
514 if ( m_xModel.is() )
516 ::rtl::OUString sUrl = m_xModel->getURL();
517 if ( sUrl.getLength() )
519 ::comphelper::NamedValueCollection aArgs( m_xModel->getArgs() );
520 if ( true == aArgs.getOrDefault( "PickListEntry", true ) )
522 ::rtl::OUString aFilter;
523 INetURLObject aURL( m_xModel->getURL() );
524 const SfxFilter* pFilter = getStandardDatabaseFilter();
525 if ( pFilter )
526 aFilter = pFilter->GetFilterName();
528 // add to svtool history options
529 SvtHistoryOptions().AppendItem( ePICKLIST,
530 aURL.GetURLNoPass( INetURLObject::NO_DECODE ),
531 aFilter,
532 getStrippedDatabaseName(),
533 ::rtl::OUString() );
537 m_aModelConnector.clear();
538 m_xModel.clear();
541 catch(Exception)
543 DBG_UNHANDLED_EXCEPTION();
546 m_pView = NULL;
547 OApplicationController_CBASE::disposing(); // here the m_refCount must be equal 5
550 //--------------------------------------------------------------------
551 sal_Bool OApplicationController::Construct(Window* _pParent)
553 m_pView = new OApplicationView( _pParent, getORB(), *this, m_ePreviewMode );
554 m_pView->SetUniqueId(UID_APP_VIEW);
556 // late construction
557 sal_Bool bSuccess = sal_False;
560 getContainer()->Construct();
561 bSuccess = sal_True;
563 catch(SQLException&)
566 catch(Exception&)
568 DBG_ERROR("OApplicationController::Construct : the construction of UnoDataBrowserView failed !");
571 if ( !bSuccess )
573 ::std::auto_ptr< Window> aTemp(m_pView);
574 m_pView = NULL;
575 return sal_False;
578 DBG_ASSERT( getView(), "OApplicationController::Construct: have no view!" );
579 if ( getView() )
580 getView()->enableSeparator( );
582 // now that we have a view we can create the clipboard listener
583 m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( getView() );
584 m_aSystemClipboard.StartClipboardListening( );
586 m_pClipbordNotifier = new TransferableClipboardListener( LINK( this, OApplicationController, OnClipboardChanged ) );
587 m_pClipbordNotifier->acquire();
588 m_pClipbordNotifier->AddRemoveListener( getView(), sal_True );
590 OApplicationController_CBASE::Construct( _pParent );
591 getView()->Show();
593 return sal_True;
596 //--------------------------------------------------------------------
597 void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) throw( RuntimeException )
599 ::osl::MutexGuard aGuard( getMutex() );
600 Reference<XConnection> xCon(_rSource.Source, UNO_QUERY);
601 if ( xCon.is() )
603 DBG_ASSERT( ( m_xDataSourceConnection == xCon ) && getContainer() && ( getContainer()->getElementType() == E_TABLE ),
604 "OApplicationController::disposing: the below code will ignore this call - why?" );
606 if ( getContainer() && getContainer()->getElementType() == E_TABLE )
607 getContainer()->clearPages();
608 if ( m_xDataSourceConnection == xCon )
610 m_xMetaData.clear();
611 m_xDataSourceConnection.clear();
614 else if ( _rSource.Source == m_xModel )
616 m_xModel.clear();
617 m_aModelConnector.clear();
619 else if ( _rSource.Source == m_xDataSource )
621 m_xDataSource = NULL;
623 else
625 Reference<XContainer> xContainer( _rSource.Source, UNO_QUERY );
626 if ( xContainer.is() )
628 TContainerVector::iterator aFind = ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer);
629 if ( aFind != m_aCurrentContainers.end() )
630 m_aCurrentContainers.erase(aFind);
632 OApplicationController_CBASE::disposing( _rSource );
635 //--------------------------------------------------------------------
636 sal_Bool SAL_CALL OApplicationController::suspend(sal_Bool bSuspend) throw( RuntimeException )
638 // notify the OnPrepareViewClosing event (before locking any mutex)
639 Reference< XDocumentEventBroadcaster > xBroadcaster( m_xModel, UNO_QUERY );
640 if ( xBroadcaster.is() )
642 xBroadcaster->notifyDocumentEvent(
643 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnPrepareViewClosing" ) ),
644 this,
645 Any()
649 ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
650 ::osl::MutexGuard aGuard( getMutex() );
652 if ( getView() && getView()->IsInModalMode() )
653 return sal_False;
655 sal_Bool bCanSuspend = sal_True;
657 if ( m_bSuspended != bSuspend )
659 if ( bSuspend && !closeSubComponents() )
660 return sal_False;
662 Reference<XModifiable> xModi(m_xModel,UNO_QUERY);
663 Reference<XStorable> xStor(getModel(),UNO_QUERY);
665 if ( bSuspend
666 && xStor.is()
667 && !xStor->isReadonly()
668 && ( xModi.is()
669 && xModi->isModified()
673 switch (ExecuteQuerySaveDocument(getView(),getStrippedDatabaseName()))
675 case RET_YES:
676 Execute(ID_BROWSER_SAVEDOC,Sequence<PropertyValue>());
677 bCanSuspend = !xModi->isModified();
678 // when we save the document this must be false else some press cancel
679 break;
680 case RET_CANCEL:
681 bCanSuspend = sal_False;
682 default:
683 break;
688 if ( bCanSuspend )
689 m_bSuspended = bSuspend;
691 return bCanSuspend;
693 // -----------------------------------------------------------------------------
694 FeatureState OApplicationController::GetState(sal_uInt16 _nId) const
696 FeatureState aReturn;
697 aReturn.bEnabled = sal_False;
698 // check this first
699 if ( !getContainer() || m_bReadOnly )
700 return aReturn;
704 switch (_nId)
706 case SID_OPENURL:
707 aReturn.bEnabled = sal_True;
708 if ( m_xModel.is() )
709 aReturn.sTitle = m_xModel->getURL();
710 break;
711 case ID_BROWSER_COPY:
713 sal_Int32 nCount = getContainer()->getSelectionCount();
714 aReturn.bEnabled = nCount >= 1;
715 if ( aReturn.bEnabled && nCount == 1 && getContainer()->getElementType() == E_TABLE )
716 aReturn.bEnabled = getContainer()->isALeafSelected();
718 break;
719 case ID_BROWSER_CUT:
720 aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() >= 1;
721 aReturn.bEnabled = aReturn.bEnabled && ( (ID_BROWSER_CUT == _nId && getContainer()->getElementType() == E_TABLE) ? getContainer()->isCutAllowed() : sal_True);
722 break;
723 case ID_BROWSER_PASTE:
724 switch( getContainer()->getElementType() )
726 case E_TABLE:
727 aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly() && isTableFormat();
728 break;
729 case E_QUERY:
730 aReturn.bEnabled = !isDataSourceReadOnly() && getViewClipboard().HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY);
731 break;
732 default:
733 aReturn.bEnabled = !isDataSourceReadOnly() && OComponentTransferable::canExtractComponentDescriptor(getViewClipboard().GetDataFlavorExVector(),getContainer()->getElementType() == E_FORM);
735 break;
736 case SID_DB_APP_PASTE_SPECIAL:
737 aReturn.bEnabled = getContainer()->getElementType() == E_TABLE && !isDataSourceReadOnly() && !isConnectionReadOnly() && isTableFormat();
738 break;
739 case SID_OPENDOC:
740 case SID_HELP_INDEX:
741 aReturn.bEnabled = sal_True;
742 break;
743 case ID_BROWSER_SAVEDOC:
744 aReturn.bEnabled = !isDataSourceReadOnly() && m_xDocumentModify.is() && m_xDocumentModify->isModified();
745 break;
746 case ID_BROWSER_SAVEASDOC:
747 aReturn.bEnabled = sal_True;
748 break;
749 case ID_BROWSER_SORTUP:
750 aReturn.bEnabled = getContainer()->isFilled() && getContainer()->getElementCount();
751 aReturn.bChecked = aReturn.bEnabled && getContainer()->isSortUp();
752 break;
753 case ID_BROWSER_SORTDOWN:
754 aReturn.bEnabled = getContainer()->isFilled() && getContainer()->getElementCount();
755 aReturn.bChecked = aReturn.bEnabled && !getContainer()->isSortUp();
756 break;
758 case SID_NEWDOC:
759 case SID_APP_NEW_FORM:
760 case ID_DOCUMENT_CREATE_REPWIZ:
761 aReturn.bEnabled = !isDataSourceReadOnly() && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER);
762 break;
763 case SID_APP_NEW_REPORT:
764 aReturn.bEnabled = !isDataSourceReadOnly()
765 && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER);
766 if ( aReturn.bEnabled )
768 Reference< XContentEnumerationAccess > xEnumAccess(m_xServiceFactory, UNO_QUERY);
769 aReturn.bEnabled = xEnumAccess.is();
770 if ( aReturn.bEnabled )
772 const ::rtl::OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_xServiceFactory);
773 aReturn.bEnabled = sReportEngineServiceName.getLength() != 0;
774 if ( aReturn.bEnabled )
776 const Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(sReportEngineServiceName);
777 aReturn.bEnabled = xEnumDrivers.is() && xEnumDrivers->hasMoreElements();
781 break;
782 case SID_DB_APP_VIEW_TABLES:
783 aReturn.bEnabled = sal_True;
784 aReturn.bChecked = getContainer()->getElementType() == E_TABLE;
785 break;
786 case SID_DB_APP_VIEW_QUERIES:
787 aReturn.bEnabled = sal_True;
788 aReturn.bChecked = getContainer()->getElementType() == E_QUERY;
789 break;
790 case SID_DB_APP_VIEW_FORMS:
791 aReturn.bEnabled = sal_True;
792 aReturn.bChecked = getContainer()->getElementType() == E_FORM;
793 break;
794 case SID_DB_APP_VIEW_REPORTS:
795 aReturn.bEnabled = sal_True;
796 aReturn.bChecked = getContainer()->getElementType() == E_REPORT;
797 break;
798 case ID_NEW_QUERY_DESIGN:
799 case ID_NEW_QUERY_SQL:
800 case ID_APP_NEW_QUERY_AUTO_PILOT:
801 case SID_DB_FORM_NEW_PILOT:
802 aReturn.bEnabled = !isDataSourceReadOnly();
803 break;
804 case ID_NEW_VIEW_DESIGN:
805 case SID_DB_NEW_VIEW_SQL:
806 case ID_NEW_VIEW_DESIGN_AUTO_PILOT:
807 aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly();
808 if ( aReturn.bEnabled )
810 Reference<XViewsSupplier> xViewsSup( getConnection(), UNO_QUERY );
811 aReturn.bEnabled = xViewsSup.is();
813 break;
814 case ID_NEW_TABLE_DESIGN:
815 case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
816 aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly();
817 break;
818 case ID_DIRECT_SQL:
819 aReturn.bEnabled = sal_True;
820 break;
821 case ID_MIGRATE_SCRIPTS:
823 // Our document supports embedding scripts into it, if and only if there are no
824 // forms/reports with macros/scripts into them. So, we need to enable migration
825 // if and only if the database document does *not* support embedding scripts.
826 bool bAvailable =
827 !Reference< XEmbeddedScripts >( m_xModel, UNO_QUERY ).is()
828 && !Reference< XStorable >( m_xModel, UNO_QUERY_THROW )->isReadonly();
829 aReturn.bEnabled = bAvailable;
830 if ( !bAvailable )
831 aReturn.bInvisible = true;
833 break;
834 case SID_APP_NEW_FOLDER:
835 aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() <= 1;
836 if ( aReturn.bEnabled )
838 const ElementType eType = getContainer()->getElementType();
839 aReturn.bEnabled = eType == E_REPORT || eType == E_FORM;
841 break;
842 case SID_FORM_CREATE_REPWIZ_PRE_SEL:
843 case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
844 case SID_APP_NEW_REPORT_PRE_SEL:
845 aReturn.bEnabled = !isDataSourceReadOnly()
846 && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER)
847 && getContainer()->isALeafSelected();
848 if ( aReturn.bEnabled )
850 ElementType eType = getContainer()->getElementType();
851 aReturn.bEnabled = eType == E_QUERY || eType == E_TABLE;
852 if ( aReturn.bEnabled && SID_APP_NEW_REPORT_PRE_SEL == _nId )
854 Reference< XContentEnumerationAccess > xEnumAccess(m_xServiceFactory, UNO_QUERY);
855 aReturn.bEnabled = xEnumAccess.is();
856 if ( aReturn.bEnabled )
858 static ::rtl::OUString s_sReportDesign(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.pentaho.SOReportJobFactory"));
859 Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(s_sReportDesign);
860 aReturn.bEnabled = xEnumDrivers.is() && xEnumDrivers->hasMoreElements();
864 break;
865 case SID_DB_APP_DELETE:
866 case SID_DB_APP_RENAME:
867 aReturn.bEnabled = isRenameDeleteAllowed(getContainer()->getElementType(), _nId == SID_DB_APP_DELETE);
868 break;
869 case SID_DB_APP_TABLE_DELETE:
870 case SID_DB_APP_TABLE_RENAME:
871 aReturn.bEnabled = isRenameDeleteAllowed(E_TABLE, _nId == SID_DB_APP_TABLE_DELETE);
872 break;
873 case SID_DB_APP_QUERY_DELETE:
874 case SID_DB_APP_QUERY_RENAME:
875 aReturn.bEnabled = isRenameDeleteAllowed(E_QUERY, _nId == SID_DB_APP_QUERY_DELETE);
876 break;
877 case SID_DB_APP_FORM_DELETE:
878 case SID_DB_APP_FORM_RENAME:
879 aReturn.bEnabled = isRenameDeleteAllowed(E_FORM, _nId == SID_DB_APP_FORM_DELETE);
880 break;
881 case SID_DB_APP_REPORT_DELETE:
882 case SID_DB_APP_REPORT_RENAME:
883 aReturn.bEnabled = isRenameDeleteAllowed(E_REPORT, _nId == SID_DB_APP_REPORT_DELETE);
884 break;
886 case SID_SELECTALL:
887 aReturn.bEnabled = getContainer()->getElementCount() > 0 && getContainer()->getSelectionCount() != getContainer()->getElementCount();
888 break;
889 case SID_DB_APP_EDIT:
890 case SID_DB_APP_TABLE_EDIT:
891 case SID_DB_APP_QUERY_EDIT:
892 case SID_DB_APP_FORM_EDIT:
893 case SID_DB_APP_REPORT_EDIT:
894 aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() > 0
895 && getContainer()->isALeafSelected();
896 break;
897 case SID_DB_APP_EDIT_SQL_VIEW:
898 if ( isDataSourceReadOnly() )
899 aReturn.bEnabled = sal_False;
900 else
902 switch ( getContainer()->getElementType() )
904 case E_QUERY:
905 aReturn.bEnabled = ( getContainer()->getSelectionCount() > 0 )
906 && ( getContainer()->isALeafSelected() );
907 break;
908 case E_TABLE:
909 aReturn.bEnabled = sal_False;
910 // there's one exception: views which support altering their underlying
911 // command can be edited in SQL view, too
912 if ( ( getContainer()->getSelectionCount() > 0 )
913 && ( getContainer()->isALeafSelected() )
916 ::std::vector< ::rtl::OUString > aSelected;
917 getSelectionElementNames( aSelected );
918 bool bAlterableViews = true;
919 for ( ::std::vector< ::rtl::OUString >::const_iterator selectedName = aSelected.begin();
920 bAlterableViews && ( selectedName != aSelected.end() ) ;
921 ++selectedName
924 bAlterableViews &= impl_isAlterableView_nothrow( *selectedName );
926 aReturn.bEnabled = bAlterableViews;
928 break;
929 default:
930 break;
933 break;
934 case SID_DB_APP_OPEN:
935 case SID_DB_APP_TABLE_OPEN:
936 case SID_DB_APP_QUERY_OPEN:
937 case SID_DB_APP_FORM_OPEN:
938 case SID_DB_APP_REPORT_OPEN:
939 aReturn.bEnabled = getContainer()->getSelectionCount() > 0 && getContainer()->isALeafSelected();
940 break;
941 case SID_DB_APP_DSUSERADMIN:
942 aReturn.bEnabled = !m_aTypeCollection.isEmbeddedDatabase(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
943 break;
944 case SID_DB_APP_DSRELDESIGN:
945 aReturn.bEnabled = sal_True;
946 break;
947 case SID_DB_APP_TABLEFILTER:
948 aReturn.bEnabled = !isDataSourceReadOnly();
949 break;
950 case SID_DB_APP_REFRESH_TABLES:
951 aReturn.bEnabled = getContainer()->getElementType() == E_TABLE && isConnected();
952 break;
953 case SID_DB_APP_DSPROPS:
954 aReturn.bEnabled = m_xDataSource.is() && m_aTypeCollection.isShowPropertiesEnabled(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
955 break;
956 case SID_DB_APP_DSCONNECTION_TYPE:
957 aReturn.bEnabled = !isDataSourceReadOnly() && m_xDataSource.is() && !m_aTypeCollection.isEmbeddedDatabase(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
958 break;
959 case SID_DB_APP_DSADVANCED_SETTINGS:
960 aReturn.bEnabled = m_xDataSource.is() && AdvancedSettingsDialog::doesHaveAnyAdvancedSettings( m_aTypeCollection.getType(::comphelper::getString( m_xDataSource->getPropertyValue( PROPERTY_URL ) )) );
961 break;
962 case SID_DB_APP_CONVERTTOVIEW:
963 aReturn.bEnabled = !isDataSourceReadOnly();
964 if ( aReturn.bEnabled )
966 ElementType eType = getContainer()->getElementType();
967 aReturn.bEnabled = eType == E_QUERY && getContainer()->getSelectionCount() > 0;
968 if ( aReturn.bEnabled )
970 Reference<XViewsSupplier> xViewSup( getConnection(), UNO_QUERY );
971 aReturn.bEnabled = xViewSup.is() && Reference<XAppend>(xViewSup->getViews(),UNO_QUERY).is();
974 break;
975 case SID_DB_APP_DISABLE_PREVIEW:
976 aReturn.bEnabled = sal_True;
977 aReturn.bChecked = getContainer()->getPreviewMode() == E_PREVIEWNONE;
978 break;
979 case SID_DB_APP_VIEW_DOCINFO_PREVIEW:
981 ElementType eType = getContainer()->getElementType();
982 aReturn.bEnabled = (E_REPORT == eType || E_FORM == eType);
983 aReturn.bChecked = getContainer()->getPreviewMode() == E_DOCUMENTINFO;
985 break;
986 case SID_DB_APP_VIEW_DOC_PREVIEW:
987 aReturn.bEnabled = sal_True;
988 aReturn.bChecked = getContainer()->getPreviewMode() == E_DOCUMENT;
989 break;
990 case ID_BROWSER_UNDO:
991 aReturn.bEnabled = sal_False;
992 break;
993 case SID_MAIL_SENDDOC:
994 aReturn.bEnabled = sal_True;
995 break;
996 case SID_DB_APP_SENDREPORTASMAIL:
998 ElementType eType = getContainer()->getElementType();
999 aReturn.bEnabled = E_REPORT == eType && getContainer()->getSelectionCount() > 0 && getContainer()->isALeafSelected();
1001 break;
1002 case SID_DB_APP_SENDREPORTTOWRITER:
1003 case SID_DB_APP_DBADMIN:
1004 aReturn.bEnabled = sal_False;
1005 break;
1006 case SID_DB_APP_STATUS_TYPE:
1007 aReturn.bEnabled = m_xDataSource.is();
1008 if ( aReturn.bEnabled )
1010 ::rtl::OUString sURL;
1011 m_xDataSource->getPropertyValue(PROPERTY_URL) >>= sURL;
1012 ::rtl::OUString sDSTypeName;
1013 if ( m_aTypeCollection.isEmbeddedDatabase( sURL ) )
1015 sDSTypeName = String( ModuleRes( RID_STR_EMBEDDED_DATABASE ) );
1017 else
1019 sDSTypeName = m_aTypeCollection.getTypeDisplayName(sURL);
1021 aReturn.sTitle = sDSTypeName;
1023 break;
1024 case SID_DB_APP_STATUS_DBNAME:
1025 aReturn.bEnabled = m_xDataSource.is();
1026 if ( aReturn.bEnabled )
1028 ::rtl::OUString sURL;
1029 m_xDataSource->getPropertyValue(PROPERTY_URL) >>= sURL;
1030 String sDatabaseName;
1031 String sHostName;
1032 sal_Int32 nPortNumber( -1 );
1034 m_aTypeCollection.extractHostNamePort( sURL, sDatabaseName, sHostName, nPortNumber );
1036 if ( !sDatabaseName.Len() )
1037 sDatabaseName = m_aTypeCollection.cutPrefix( sURL );
1038 if ( m_aTypeCollection.isFileSystemBased(sURL) )
1040 sDatabaseName = SvtPathOptions().SubstituteVariable( sDatabaseName );
1041 if ( sDatabaseName.Len() )
1043 ::svt::OFileNotation aFileNotation(sDatabaseName);
1044 // set this decoded URL as text
1045 sDatabaseName = aFileNotation.get(::svt::OFileNotation::N_SYSTEM);
1049 if ( sDatabaseName.Len() == 0 )
1050 sDatabaseName = m_aTypeCollection.getTypeDisplayName( sURL );
1052 aReturn.sTitle = sDatabaseName;
1054 break;
1055 case SID_DB_APP_STATUS_USERNAME:
1056 aReturn.bEnabled = m_xDataSource.is();
1057 if ( aReturn.bEnabled )
1058 m_xDataSource->getPropertyValue( PROPERTY_USER ) >>= aReturn.sTitle;
1059 break;
1060 case SID_DB_APP_STATUS_HOSTNAME:
1061 aReturn.bEnabled = m_xDataSource.is();
1062 if ( aReturn.bEnabled )
1064 ::rtl::OUString sURL;
1065 m_xDataSource->getPropertyValue( PROPERTY_URL ) >>= sURL;
1067 String sHostName, sDatabaseName;
1068 sal_Int32 nPortNumber = -1;
1069 m_aTypeCollection.extractHostNamePort( sURL, sDatabaseName, sHostName, nPortNumber );
1070 aReturn.sTitle = sHostName;
1072 break;
1073 default:
1074 aReturn = OApplicationController_CBASE::GetState(_nId);
1077 catch(const Exception& )
1079 DBG_UNHANDLED_EXCEPTION();
1081 return aReturn;
1084 // -----------------------------------------------------------------------------
1085 namespace
1087 bool lcl_handleException_nothrow( const Reference< XModel >& _rxDocument, const Any& _rException )
1089 bool bHandled = false;
1091 // try handling the error with an interaction handler
1092 ::comphelper::NamedValueCollection aArgs( _rxDocument->getArgs() );
1093 Reference< XInteractionHandler > xHandler( aArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) );
1094 if ( xHandler.is() )
1096 ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( _rException ) );
1097 ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
1098 pRequest->addContinuation( pApprove.get() );
1102 xHandler->handle( pRequest.get() );
1104 catch( const Exception& )
1106 DBG_UNHANDLED_EXCEPTION();
1109 bHandled = pApprove->wasSelected();
1111 return bHandled;
1115 // -----------------------------------------------------------------------------
1116 void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
1118 ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1119 ::osl::MutexGuard aGuard( getMutex() );
1121 if ( isUserDefinedFeature( _nId ) )
1123 OApplicationController_CBASE::Execute( _nId, aArgs );
1124 return;
1127 if ( !getContainer() || m_bReadOnly )
1128 return; // return without execution
1132 switch(_nId)
1134 case ID_BROWSER_CUT:
1135 getContainer()->cut();
1136 break;
1137 case ID_BROWSER_COPY:
1139 TransferableHelper* pTransfer = copyObject( );
1140 Reference< XTransferable> aEnsureDelete = pTransfer;
1142 if ( pTransfer )
1143 pTransfer->CopyToClipboard(getView());
1145 break;
1146 case ID_BROWSER_PASTE:
1148 const TransferableDataHelper& rTransferData( getViewClipboard() );
1149 ElementType eType = getContainer()->getElementType();
1151 switch( eType )
1153 case E_TABLE:
1155 // get the selected tablename
1156 ::std::vector< ::rtl::OUString > aList;
1157 getSelectionElementNames( aList );
1158 if ( !aList.empty() )
1159 m_aTableCopyHelper.SetTableNameForAppend( *aList.begin() );
1160 else
1161 m_aTableCopyHelper.ResetTableNameForAppend();
1163 m_aTableCopyHelper.pasteTable( rTransferData , getDatabaseName(), ensureConnection() );
1165 break;
1167 case E_QUERY:
1168 if ( rTransferData.HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY) )
1169 paste( E_QUERY, ODataAccessObjectTransferable::extractObjectDescriptor( rTransferData ) );
1170 break;
1171 default:
1173 ::std::vector< ::rtl::OUString> aList;
1174 getSelectionElementNames(aList);
1175 ::rtl::OUString sFolderNameToInsertInto;
1176 if ( !aList.empty() )
1178 Reference< XHierarchicalNameAccess > xContainer(getElements(eType),UNO_QUERY);
1179 if ( xContainer.is()
1180 && xContainer->hasByHierarchicalName(*aList.begin())
1181 && (xContainer->getByHierarchicalName(*aList.begin()) >>= xContainer)
1182 && xContainer.is()
1184 sFolderNameToInsertInto = *aList.begin();
1186 paste( eType, OComponentTransferable::extractComponentDescriptor( rTransferData ),
1187 sFolderNameToInsertInto );
1189 break;
1192 break;
1193 case SID_DB_APP_PASTE_SPECIAL:
1195 if ( !aArgs.getLength() )
1197 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1198 ::std::auto_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( getView() ));
1199 ::std::vector<SotFormatStringId> aFormatIds;
1200 getSupportedFormats(getContainer()->getElementType(),aFormatIds);
1201 const ::std::vector<SotFormatStringId>::iterator aEnd = aFormatIds.end();
1202 ::rtl::OUString sEmpty;
1203 for (::std::vector<SotFormatStringId>::iterator aIter = aFormatIds.begin();aIter != aEnd; ++aIter)
1204 pDlg->Insert(*aIter,sEmpty);
1206 const TransferableDataHelper& rClipboard = getViewClipboard();
1207 pasteFormat(pDlg->GetFormat(rClipboard.GetTransferable()));
1209 else
1211 const PropertyValue* pIter = aArgs.getConstArray();
1212 const PropertyValue* pEnd = pIter + aArgs.getLength();
1213 for( ; pIter != pEnd ; ++pIter)
1215 if ( pIter->Name.equalsAscii("FormatStringId") )
1217 SotFormatStringId nFormatId = 0;
1218 if ( pIter->Value >>= nFormatId )
1219 pasteFormat(nFormatId);
1220 break;
1225 break;
1226 case SID_OPENDOC:
1227 case SID_HELP_INDEX:
1229 Reference < XDispatchProvider > xProv( getFrame(), UNO_QUERY );
1230 if ( xProv.is() )
1232 URL aURL;
1233 switch(_nId)
1235 case SID_HELP_INDEX:
1236 aURL.Complete = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:HelpIndex"));
1237 break;
1238 case SID_OPENDOC:
1239 aURL.Complete = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Open"));
1240 break;
1243 if ( m_xUrlTransformer.is() )
1244 m_xUrlTransformer->parseStrict( aURL );
1245 Reference < XDispatch > xDisp = xProv->queryDispatch( aURL, String(), 0 );
1246 if ( xDisp.is() )
1247 xDisp->dispatch( aURL, Sequence < PropertyValue >() );
1250 break;
1251 case ID_BROWSER_SAVEDOC:
1253 Reference< XStorable > xStore( m_xModel, UNO_QUERY_THROW );
1256 xStore->store();
1258 catch( const Exception& )
1260 lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() );
1263 break;
1265 case ID_BROWSER_SAVEASDOC:
1267 WinBits nBits(WB_STDMODAL|WB_SAVEAS);
1268 ::rtl::OUString sUrl;
1269 if ( m_xModel.is() )
1270 sUrl = m_xModel->getURL();
1271 if ( !sUrl.getLength() )
1272 sUrl = SvtPathOptions().GetWorkPath();
1274 ::sfx2::FileDialogHelper aFileDlg( com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,static_cast<sal_uInt32>(nBits) ,getView());
1275 aFileDlg.SetDisplayDirectory( sUrl );
1277 const SfxFilter* pFilter = getStandardDatabaseFilter();
1278 if ( pFilter )
1280 aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
1281 aFileDlg.SetCurrentFilter(pFilter->GetUIName());
1284 if ( aFileDlg.Execute() != ERRCODE_NONE )
1285 break;
1287 Reference<XStorable> xStore( m_xModel, UNO_QUERY_THROW );
1288 INetURLObject aURL( aFileDlg.GetPath() );
1291 xStore->storeAsURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), Sequence< PropertyValue >() );
1293 catch( const Exception& )
1295 lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() );
1298 /*updateTitle();*/
1299 m_bCurrentlyModified = sal_False;
1300 InvalidateFeature(ID_BROWSER_SAVEDOC);
1301 if ( getContainer()->getElementType() == E_NONE )
1303 getContainer()->selectContainer(E_NONE);
1304 getContainer()->selectContainer(E_TABLE);
1305 // #i95524#
1306 getContainer()->Invalidate();
1307 refreshTables();
1311 break;
1312 case ID_BROWSER_SORTUP:
1313 getContainer()->sortUp();
1314 InvalidateFeature(ID_BROWSER_SORTDOWN);
1315 break;
1316 case ID_BROWSER_SORTDOWN:
1317 getContainer()->sortDown();
1318 InvalidateFeature(ID_BROWSER_SORTUP);
1319 break;
1321 case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
1322 case ID_NEW_VIEW_DESIGN_AUTO_PILOT:
1323 case ID_APP_NEW_QUERY_AUTO_PILOT:
1324 case SID_DB_FORM_NEW_PILOT:
1325 case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
1326 case SID_APP_NEW_REPORT_PRE_SEL:
1327 case SID_FORM_CREATE_REPWIZ_PRE_SEL:
1328 case ID_DOCUMENT_CREATE_REPWIZ:
1329 case SID_APP_NEW_FORM:
1330 case SID_APP_NEW_REPORT:
1331 case ID_NEW_QUERY_SQL:
1332 case ID_NEW_QUERY_DESIGN:
1333 case ID_NEW_TABLE_DESIGN:
1335 ElementType eType = E_TABLE;
1336 sal_Bool bAutoPilot = sal_False;
1337 sal_Bool bSQLView = sal_False;
1339 switch( _nId )
1341 case SID_DB_FORM_NEW_PILOT:
1342 case SID_FORM_CREATE_REPWIZ_PRE_SEL:
1343 bAutoPilot = sal_True;
1344 // run through
1345 case SID_APP_NEW_FORM:
1346 eType = E_FORM;
1347 break;
1348 case ID_DOCUMENT_CREATE_REPWIZ:
1349 case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
1350 bAutoPilot = sal_True;
1351 // run through
1352 case SID_APP_NEW_REPORT:
1353 case SID_APP_NEW_REPORT_PRE_SEL:
1354 eType = E_REPORT;
1355 break;
1356 case ID_APP_NEW_QUERY_AUTO_PILOT:
1357 bAutoPilot = sal_True;
1358 eType = E_QUERY;
1359 break;
1360 case ID_NEW_QUERY_SQL:
1361 bSQLView = sal_True;
1362 // run through
1363 case ID_NEW_QUERY_DESIGN:
1364 eType = E_QUERY;
1365 break;
1366 case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
1367 bAutoPilot = sal_True;
1368 // run through
1369 case ID_NEW_TABLE_DESIGN:
1370 break;
1371 default:
1372 OSL_ENSURE(0,"illegal switch call!");
1374 if ( bAutoPilot )
1375 getContainer()->PostUserEvent( LINK( this, OApplicationController, OnCreateWithPilot ), reinterpret_cast< void* >( eType ) );
1376 else
1377 newElement( eType, bSQLView );
1379 break;
1380 case SID_APP_NEW_FOLDER:
1382 ElementType eType = getContainer()->getElementType();
1383 ::rtl::OUString sName = getContainer()->getQualifiedName( NULL );
1384 insertHierachyElement(eType,sName);
1386 break;
1387 case ID_NEW_VIEW_DESIGN:
1388 case SID_DB_NEW_VIEW_SQL:
1390 SharedConnection xConnection( ensureConnection() );
1391 if ( xConnection.is() )
1393 QueryDesigner aDesigner( getORB(), this, getFrame(), true, SID_DB_NEW_VIEW_SQL == _nId );
1395 Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
1396 Reference< XComponent > xComponent( aDesigner.createNew( xDataSource ), UNO_QUERY );
1397 onDocumentOpened( ::rtl::OUString(), E_QUERY, E_OPEN_DESIGN, xComponent, NULL );
1400 break;
1401 case SID_DB_APP_DELETE:
1402 case SID_DB_APP_TABLE_DELETE:
1403 case SID_DB_APP_QUERY_DELETE:
1404 case SID_DB_APP_FORM_DELETE:
1405 case SID_DB_APP_REPORT_DELETE:
1406 deleteEntries();
1407 break;
1408 case SID_DB_APP_RENAME:
1409 case SID_DB_APP_TABLE_RENAME:
1410 case SID_DB_APP_QUERY_RENAME:
1411 case SID_DB_APP_FORM_RENAME:
1412 case SID_DB_APP_REPORT_RENAME:
1413 renameEntry();
1414 break;
1415 case SID_DB_APP_EDIT:
1416 case SID_DB_APP_EDIT_SQL_VIEW:
1417 case SID_DB_APP_TABLE_EDIT:
1418 case SID_DB_APP_QUERY_EDIT:
1419 case SID_DB_APP_FORM_EDIT:
1420 case SID_DB_APP_REPORT_EDIT:
1421 doAction( _nId, E_OPEN_DESIGN );
1422 break;
1423 case SID_DB_APP_OPEN:
1424 case SID_DB_APP_TABLE_OPEN:
1425 case SID_DB_APP_QUERY_OPEN:
1426 case SID_DB_APP_FORM_OPEN:
1427 case SID_DB_APP_REPORT_OPEN:
1428 doAction( _nId, E_OPEN_NORMAL );
1429 break;
1430 case SID_DB_APP_CONVERTTOVIEW:
1431 doAction( _nId, E_OPEN_NORMAL );
1432 break;
1433 case SID_SELECTALL:
1434 getContainer()->selectAll();
1435 InvalidateAll();
1436 break;
1437 case SID_DB_APP_DSRELDESIGN:
1438 if ( !m_pSubComponentManager->activateSubFrame( ::rtl::OUString(), SID_DB_APP_DSRELDESIGN, E_OPEN_DESIGN ) )
1440 SharedConnection xConnection( ensureConnection() );
1441 if ( xConnection.is() )
1443 RelationDesigner aDesigner( getORB(), this, m_aCurrentFrame.getFrame() );
1445 Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
1446 Reference< XComponent > xComponent( aDesigner.createNew( xDataSource ), UNO_QUERY );
1447 onDocumentOpened( ::rtl::OUString(), SID_DB_APP_DSRELDESIGN, E_OPEN_DESIGN, xComponent, NULL );
1450 break;
1451 case SID_DB_APP_DSUSERADMIN:
1453 SharedConnection xConnection( ensureConnection() );
1454 if ( xConnection.is() )
1455 openDialog(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.UserAdministrationDialog")));
1457 break;
1458 case SID_DB_APP_TABLEFILTER:
1459 openTableFilterDialog();
1460 askToReconnect();
1461 break;
1462 case SID_DB_APP_REFRESH_TABLES:
1463 refreshTables();
1464 break;
1465 case SID_DB_APP_DSPROPS:
1466 openDataSourceAdminDialog();
1467 askToReconnect();
1468 break;
1469 case SID_DB_APP_DSADVANCED_SETTINGS:
1470 openDialog(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.AdvancedDatabaseSettingsDialog")));
1471 askToReconnect();
1472 break;
1473 case SID_DB_APP_DSCONNECTION_TYPE:
1474 openDialog(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DataSourceTypeChangeDialog")));
1475 askToReconnect();
1476 break;
1477 case ID_DIRECT_SQL:
1479 SharedConnection xConnection( ensureConnection() );
1480 if ( xConnection.is() )
1481 openDirectSQLDialog();
1483 break;
1484 case ID_MIGRATE_SCRIPTS:
1485 impl_migrateScripts_nothrow();
1486 break;
1487 case SID_DB_APP_VIEW_TABLES:
1488 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_TABLE ) );
1489 break;
1490 case SID_DB_APP_VIEW_QUERIES:
1491 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_QUERY ) );
1492 break;
1493 case SID_DB_APP_VIEW_FORMS:
1494 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_FORM ) );
1495 break;
1496 case SID_DB_APP_VIEW_REPORTS:
1497 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_REPORT ) );
1498 break;
1499 case SID_DB_APP_DISABLE_PREVIEW:
1500 m_ePreviewMode = E_PREVIEWNONE;
1501 getContainer()->switchPreview(m_ePreviewMode);
1502 break;
1503 case SID_DB_APP_VIEW_DOCINFO_PREVIEW:
1504 m_ePreviewMode = E_DOCUMENTINFO;
1505 getContainer()->switchPreview(m_ePreviewMode);
1506 break;
1507 case SID_DB_APP_VIEW_DOC_PREVIEW:
1508 m_ePreviewMode = E_DOCUMENT;
1509 getContainer()->switchPreview(m_ePreviewMode);
1510 break;
1511 case SID_MAIL_SENDDOC:
1513 SfxMailModel aSendMail;
1514 if ( aSendMail.AttachDocument(rtl::OUString(),getModel(), rtl::OUString()) == SfxMailModel::SEND_MAIL_OK )
1515 aSendMail.Send( getFrame() );
1517 break;
1518 case SID_DB_APP_SENDREPORTASMAIL:
1519 doAction( _nId, E_OPEN_FOR_MAIL );
1520 break;
1523 catch( const Exception& )
1525 DBG_UNHANDLED_EXCEPTION();
1527 InvalidateFeature(_nId);
1529 // -----------------------------------------------------------------------------
1530 void OApplicationController::describeSupportedFeatures()
1532 OApplicationController_CBASE::describeSupportedFeatures();
1534 implDescribeSupportedFeature( ".uno:Save", ID_BROWSER_SAVEDOC, CommandGroup::DOCUMENT );
1535 implDescribeSupportedFeature( ".uno:SaveAs", ID_BROWSER_SAVEASDOC, CommandGroup::DOCUMENT );
1536 implDescribeSupportedFeature( ".uno:SendMail", SID_MAIL_SENDDOC, CommandGroup::DOCUMENT );
1537 implDescribeSupportedFeature( ".uno:DBSendReportAsMail",SID_DB_APP_SENDREPORTASMAIL,
1538 CommandGroup::DOCUMENT );
1539 implDescribeSupportedFeature( ".uno:DBSendReportToWriter",SID_DB_APP_SENDREPORTTOWRITER,
1540 CommandGroup::DOCUMENT );
1541 implDescribeSupportedFeature( ".uno:DBNewForm", SID_APP_NEW_FORM, CommandGroup::INSERT );
1542 implDescribeSupportedFeature( ".uno:DBNewFolder", SID_APP_NEW_FOLDER, CommandGroup::INSERT );
1543 implDescribeSupportedFeature( ".uno:DBNewFormAutoPilot", SID_DB_FORM_NEW_PILOT, CommandGroup::INSERT );
1544 implDescribeSupportedFeature( ".uno:DBNewFormAutoPilotWithPreSelection",
1545 SID_FORM_CREATE_REPWIZ_PRE_SEL,
1546 CommandGroup::APPLICATION );
1548 implDescribeSupportedFeature( ".uno:DBNewReport", SID_APP_NEW_REPORT, CommandGroup::INSERT );
1549 implDescribeSupportedFeature( ".uno:DBNewReportAutoPilot",
1550 ID_DOCUMENT_CREATE_REPWIZ, CommandGroup::INSERT );
1551 implDescribeSupportedFeature( ".uno:DBNewReportAutoPilotWithPreSelection",
1552 SID_REPORT_CREATE_REPWIZ_PRE_SEL,
1553 CommandGroup::APPLICATION );
1554 implDescribeSupportedFeature( ".uno:DBNewQuery", ID_NEW_QUERY_DESIGN, CommandGroup::INSERT );
1555 implDescribeSupportedFeature( ".uno:DBNewQuerySql", ID_NEW_QUERY_SQL, CommandGroup::INSERT );
1556 implDescribeSupportedFeature( ".uno:DBNewQueryAutoPilot",ID_APP_NEW_QUERY_AUTO_PILOT,
1557 CommandGroup::INSERT );
1558 implDescribeSupportedFeature( ".uno:DBNewTable", ID_NEW_TABLE_DESIGN, CommandGroup::INSERT );
1559 implDescribeSupportedFeature( ".uno:DBNewTableAutoPilot",ID_NEW_TABLE_DESIGN_AUTO_PILOT,
1560 CommandGroup::INSERT );
1561 implDescribeSupportedFeature( ".uno:DBNewView", ID_NEW_VIEW_DESIGN, CommandGroup::INSERT );
1562 implDescribeSupportedFeature( ".uno:DBNewViewSQL", SID_DB_NEW_VIEW_SQL, CommandGroup::INSERT );
1564 implDescribeSupportedFeature( ".uno:DBDelete", SID_DB_APP_DELETE, CommandGroup::EDIT );
1565 implDescribeSupportedFeature( ".uno:Delete", SID_DB_APP_DELETE, CommandGroup::EDIT );
1566 implDescribeSupportedFeature( ".uno:DBRename", SID_DB_APP_RENAME, CommandGroup::EDIT );
1567 implDescribeSupportedFeature( ".uno:DBEdit", SID_DB_APP_EDIT, CommandGroup::EDIT );
1568 implDescribeSupportedFeature( ".uno:DBEditSqlView", SID_DB_APP_EDIT_SQL_VIEW, CommandGroup::EDIT );
1569 implDescribeSupportedFeature( ".uno:DBOpen", SID_DB_APP_OPEN, CommandGroup::EDIT );
1571 implDescribeSupportedFeature( ".uno:DBTableDelete", SID_DB_APP_TABLE_DELETE, CommandGroup::EDIT );
1572 implDescribeSupportedFeature( ".uno:DBTableRename", SID_DB_APP_TABLE_RENAME, CommandGroup::EDIT );
1573 implDescribeSupportedFeature( ".uno:DBTableEdit", SID_DB_APP_TABLE_EDIT, CommandGroup::EDIT );
1574 implDescribeSupportedFeature( ".uno:DBTableOpen", SID_DB_APP_TABLE_OPEN, CommandGroup::EDIT );
1576 implDescribeSupportedFeature( ".uno:DBQueryDelete", SID_DB_APP_QUERY_DELETE, CommandGroup::EDIT );
1577 implDescribeSupportedFeature( ".uno:DBQueryRename", SID_DB_APP_QUERY_RENAME, CommandGroup::EDIT );
1578 implDescribeSupportedFeature( ".uno:DBQueryEdit", SID_DB_APP_QUERY_EDIT, CommandGroup::EDIT );
1579 implDescribeSupportedFeature( ".uno:DBQueryOpen", SID_DB_APP_QUERY_OPEN, CommandGroup::EDIT );
1581 implDescribeSupportedFeature( ".uno:DBFormDelete", SID_DB_APP_FORM_DELETE, CommandGroup::EDIT );
1582 implDescribeSupportedFeature( ".uno:DBFormRename", SID_DB_APP_FORM_RENAME, CommandGroup::EDIT );
1583 implDescribeSupportedFeature( ".uno:DBFormEdit", SID_DB_APP_FORM_EDIT, CommandGroup::EDIT );
1584 implDescribeSupportedFeature( ".uno:DBFormOpen", SID_DB_APP_FORM_OPEN, CommandGroup::EDIT );
1586 implDescribeSupportedFeature( ".uno:DBReportDelete", SID_DB_APP_REPORT_DELETE, CommandGroup::EDIT );
1587 implDescribeSupportedFeature( ".uno:DBReportRename", SID_DB_APP_REPORT_RENAME, CommandGroup::EDIT );
1588 implDescribeSupportedFeature( ".uno:DBReportEdit", SID_DB_APP_REPORT_EDIT, CommandGroup::EDIT );
1589 implDescribeSupportedFeature( ".uno:DBReportOpen", SID_DB_APP_REPORT_OPEN, CommandGroup::EDIT );
1591 implDescribeSupportedFeature( ".uno:SelectAll", SID_SELECTALL, CommandGroup::EDIT );
1592 implDescribeSupportedFeature( ".uno:Undo", ID_BROWSER_UNDO, CommandGroup::EDIT );
1594 implDescribeSupportedFeature( ".uno:Sortup", ID_BROWSER_SORTUP, CommandGroup::VIEW );
1595 implDescribeSupportedFeature( ".uno:SortDown", ID_BROWSER_SORTDOWN, CommandGroup::VIEW );
1596 implDescribeSupportedFeature( ".uno:DBRelationDesign", SID_DB_APP_DSRELDESIGN, CommandGroup::APPLICATION );
1597 implDescribeSupportedFeature( ".uno:DBUserAdmin", SID_DB_APP_DSUSERADMIN, CommandGroup::APPLICATION );
1598 implDescribeSupportedFeature( ".uno:DBTableFilter", SID_DB_APP_TABLEFILTER, CommandGroup::APPLICATION );
1599 implDescribeSupportedFeature( ".uno:DBDSProperties", SID_DB_APP_DSPROPS, CommandGroup::EDIT );
1600 implDescribeSupportedFeature( ".uno:DBDSConnectionType", SID_DB_APP_DSCONNECTION_TYPE,
1601 CommandGroup::EDIT );
1602 implDescribeSupportedFeature( ".uno:DBDSAdvancedSettings",
1603 SID_DB_APP_DSADVANCED_SETTINGS,
1604 CommandGroup::EDIT );
1605 implDescribeSupportedFeature( ".uno:PasteSpecial", SID_DB_APP_PASTE_SPECIAL, CommandGroup::EDIT );
1606 implDescribeSupportedFeature( ".uno:DBConvertToView", SID_DB_APP_CONVERTTOVIEW, CommandGroup::EDIT );
1607 implDescribeSupportedFeature( ".uno:DBRefreshTables", SID_DB_APP_REFRESH_TABLES, CommandGroup::APPLICATION );
1608 implDescribeSupportedFeature( ".uno:DBDirectSQL", ID_DIRECT_SQL, CommandGroup::APPLICATION );
1609 implDescribeSupportedFeature( ".uno:DBMigrateScripts", ID_MIGRATE_SCRIPTS, CommandGroup::APPLICATION );
1610 implDescribeSupportedFeature( ".uno:DBViewTables", SID_DB_APP_VIEW_TABLES, CommandGroup::VIEW );
1611 implDescribeSupportedFeature( ".uno:DBViewQueries", SID_DB_APP_VIEW_QUERIES, CommandGroup::VIEW );
1612 implDescribeSupportedFeature( ".uno:DBViewForms", SID_DB_APP_VIEW_FORMS, CommandGroup::VIEW );
1613 implDescribeSupportedFeature( ".uno:DBViewReports", SID_DB_APP_VIEW_REPORTS, CommandGroup::VIEW );
1614 implDescribeSupportedFeature( ".uno:DBDisablePreview", SID_DB_APP_DISABLE_PREVIEW,CommandGroup::VIEW );
1615 implDescribeSupportedFeature( ".uno:DBShowDocInfoPreview",
1616 SID_DB_APP_VIEW_DOCINFO_PREVIEW,
1617 CommandGroup::VIEW );
1618 implDescribeSupportedFeature( ".uno:DBShowDocPreview", SID_DB_APP_VIEW_DOC_PREVIEW,
1619 CommandGroup::VIEW );
1621 implDescribeSupportedFeature( ".uno:OpenUrl", SID_OPENURL, CommandGroup::APPLICATION );
1623 // this one should not appear under Tools->Customize->Keyboard
1624 implDescribeSupportedFeature( ".uno:DBNewReportWithPreSelection",
1625 SID_APP_NEW_REPORT_PRE_SEL,CommandGroup::INTERNAL );
1626 implDescribeSupportedFeature( ".uno:DBDSImport", SID_DB_APP_DSIMPORT, CommandGroup::INTERNAL);
1627 implDescribeSupportedFeature( ".uno:DBDSExport", SID_DB_APP_DSEXPORT, CommandGroup::INTERNAL);
1628 implDescribeSupportedFeature( ".uno:DBDBAdmin", SID_DB_APP_DBADMIN, CommandGroup::INTERNAL);
1630 // status info
1631 implDescribeSupportedFeature( ".uno:DBStatusType", SID_DB_APP_STATUS_TYPE, CommandGroup::INTERNAL);
1632 implDescribeSupportedFeature( ".uno:DBStatusDBName", SID_DB_APP_STATUS_DBNAME, CommandGroup::INTERNAL);
1633 implDescribeSupportedFeature( ".uno:DBStatusUserName", SID_DB_APP_STATUS_USERNAME, CommandGroup::INTERNAL);
1634 implDescribeSupportedFeature( ".uno:DBStatusHostName", SID_DB_APP_STATUS_HOSTNAME, CommandGroup::INTERNAL);
1636 // -----------------------------------------------------------------------------
1637 OApplicationView* OApplicationController::getContainer() const
1639 return static_cast< OApplicationView* >( getView() );
1642 // -----------------------------------------------------------------------------
1643 // ::com::sun::star::container::XContainerListener
1644 void SAL_CALL OApplicationController::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
1646 ::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1647 ::osl::MutexGuard aGuard( getMutex() );
1649 Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
1650 if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
1652 OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1653 if ( getContainer() )
1655 ::rtl::OUString sName;
1656 _rEvent.Accessor >>= sName;
1657 ElementType eType = getElementType(xContainer);
1659 switch( eType )
1661 case E_TABLE:
1662 ensureConnection();
1663 break;
1664 case E_FORM:
1665 case E_REPORT:
1667 Reference< XContainer > xSubContainer(_rEvent.Element,UNO_QUERY);
1668 if ( xSubContainer.is() )
1669 containerFound(xSubContainer);
1671 break;
1672 default:
1673 break;
1675 getContainer()->elementAdded(eType,sName,_rEvent.Element);
1679 // -----------------------------------------------------------------------------
1680 void SAL_CALL OApplicationController::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
1682 ::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1683 ::osl::MutexGuard aGuard( getMutex() );
1685 Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
1686 if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
1688 OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1689 ::rtl::OUString sName;
1690 _rEvent.Accessor >>= sName;
1691 ElementType eType = getElementType(xContainer);
1692 switch( eType )
1694 case E_TABLE:
1695 ensureConnection();
1696 break;
1697 case E_FORM:
1698 case E_REPORT:
1700 Reference<XContent> xContent(xContainer,UNO_QUERY);
1701 if ( xContent.is() )
1703 sName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sName;
1706 break;
1707 default:
1708 break;
1710 getContainer()->elementRemoved(eType,sName);
1713 // -----------------------------------------------------------------------------
1714 void SAL_CALL OApplicationController::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
1716 ::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1717 ::osl::MutexGuard aGuard( getMutex() );
1719 Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
1720 if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
1722 OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1723 ::rtl::OUString sName;
1726 _rEvent.Accessor >>= sName;
1727 Reference<XConnection> xConnection;
1728 Reference<XPropertySet> xProp(_rEvent.Element,UNO_QUERY);
1729 ::rtl::OUString sNewName;
1731 ElementType eType = getElementType(xContainer);
1732 switch( eType )
1734 case E_TABLE:
1736 ensureConnection();
1737 if ( xProp.is() && m_xMetaData.is() )
1738 sNewName = ::dbaui::composeTableName( m_xMetaData, xProp, ::dbtools::eInDataManipulation, false, false, false );
1740 break;
1741 case E_FORM:
1742 case E_REPORT:
1744 Reference<XContent> xContent(xContainer,UNO_QUERY);
1745 if ( xContent.is() )
1747 sName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sName;
1750 break;
1751 default:
1752 break;
1754 // getContainer()->elementReplaced(getContainer()->getElementType(),sName,sNewName);
1756 catch( Exception& )
1758 DBG_UNHANDLED_EXCEPTION();
1762 namespace
1764 ::rtl::OUString lcl_getToolBarResource(ElementType _eType)
1766 ::rtl::OUString sToolbar;
1767 switch(_eType)
1769 case E_TABLE:
1770 sToolbar = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/tableobjectbar" ));
1771 break;
1772 case E_QUERY:
1773 sToolbar = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/queryobjectbar" ));
1774 break;
1775 case E_FORM:
1776 sToolbar = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/formobjectbar" ));
1777 break;
1778 case E_REPORT:
1779 sToolbar = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/reportobjectbar" ));
1780 break;
1781 case E_NONE:
1782 break;
1783 default:
1784 OSL_ENSURE(0,"Invalid ElementType!");
1785 break;
1787 return sToolbar;
1790 // -----------------------------------------------------------------------------
1791 sal_Bool OApplicationController::onContainerSelect(ElementType _eType)
1793 OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1795 if ( m_eCurrentType != _eType && _eType != E_NONE )
1797 SelectionGuard aSelGuard( *m_pSelectionNotifier );
1799 if ( _eType == E_TABLE )
1803 SharedConnection xConnection( ensureConnection() );
1804 if ( xConnection.is() && getContainer()->getDetailView() )
1806 getContainer()->getDetailView()->createTablesPage(xConnection);
1807 Reference<XTablesSupplier> xTabSup(xConnection,UNO_QUERY);
1808 if ( xTabSup.is() )
1809 addContainerListener(xTabSup->getTables());
1811 else
1813 return sal_False;
1816 catch( const Exception& )
1818 return sal_False;
1821 Reference< XLayoutManager > xLayoutManager = getLayoutManager( getFrame() );
1822 if ( xLayoutManager.is() )
1824 ::rtl::OUString sToolbar = lcl_getToolBarResource(_eType);
1825 ::rtl::OUString sDestroyToolbar = lcl_getToolBarResource(m_eCurrentType);
1827 xLayoutManager->lock();
1828 xLayoutManager->destroyElement( sDestroyToolbar );
1829 if ( sToolbar.getLength() )
1831 xLayoutManager->createElement( sToolbar );
1832 xLayoutManager->requestElement( sToolbar );
1834 xLayoutManager->unlock();
1835 xLayoutManager->doLayout();
1838 if ( _eType != E_TABLE && getContainer()->getDetailView() )
1840 Reference< XNameAccess > xContainer = getElements(_eType);
1841 addContainerListener(xContainer);
1842 getContainer()->getDetailView()->createPage(_eType,xContainer);
1845 SelectionByElementType::iterator pendingSelection = m_aPendingSelection.find( _eType );
1846 if ( pendingSelection != m_aPendingSelection.end() )
1848 Sequence< ::rtl::OUString > aSelected( pendingSelection->second.size() );
1849 ::std::copy( pendingSelection->second.begin(), pendingSelection->second.end(), aSelected.getArray() );
1850 getContainer()->selectElements( aSelected );
1852 m_aPendingSelection.erase( pendingSelection );
1855 InvalidateAll();
1857 m_eCurrentType = _eType;
1859 return sal_True;
1861 // -----------------------------------------------------------------------------
1862 bool OApplicationController::onEntryDoubleClick( SvTreeListBox& _rTree )
1864 if ( getContainer() && getContainer()->isLeaf( _rTree.GetHdlEntry() ) )
1868 openElement(
1869 getContainer()->getQualifiedName( _rTree.GetHdlEntry() ),
1870 getContainer()->getElementType(),
1871 E_OPEN_NORMAL
1873 return true; // handled
1875 catch(const Exception&)
1877 OSL_ENSURE(0,"Could not open element!");
1880 return false; // not handled
1882 // -----------------------------------------------------------------------------
1883 bool OApplicationController::impl_isAlterableView_nothrow( const ::rtl::OUString& _rTableOrViewName ) const
1885 OSL_PRECOND( m_xDataSourceConnection.is(), "OApplicationController::impl_isAlterableView_nothrow: no connection!" );
1887 bool bIsAlterableView( false );
1890 Reference< XViewsSupplier > xViewsSupp( m_xDataSourceConnection, UNO_QUERY );
1891 Reference< XNameAccess > xViews;
1892 if ( xViewsSupp.is() )
1893 xViews = xViewsSupp->getViews();
1895 Reference< XAlterView > xAsAlterableView;
1896 if ( xViews.is() && xViews->hasByName( _rTableOrViewName ) )
1897 xAsAlterableView.set( xViews->getByName( _rTableOrViewName ), UNO_QUERY );
1899 bIsAlterableView = xAsAlterableView.is();
1901 catch( const Exception& )
1903 DBG_UNHANDLED_EXCEPTION();
1905 return bIsAlterableView;
1908 // -----------------------------------------------------------------------------
1909 Reference< XComponent > OApplicationController::openElement(const ::rtl::OUString& _sName, ElementType _eType,
1910 ElementOpenMode _eOpenMode, sal_uInt16 _nInstigatorCommand )
1912 return openElementWithArguments( _sName, _eType, _eOpenMode, _nInstigatorCommand, ::comphelper::NamedValueCollection() );
1915 // -----------------------------------------------------------------------------
1916 Reference< XComponent > OApplicationController::openElementWithArguments( const ::rtl::OUString& _sName, ElementType _eType,
1917 ElementOpenMode _eOpenMode, sal_uInt16 _nInstigatorCommand, const ::comphelper::NamedValueCollection& _rAdditionalArguments )
1919 OSL_PRECOND( getContainer(), "OApplicationController::openElementWithArguments: no view!" );
1920 if ( !getContainer() )
1921 return NULL;
1923 Reference< XComponent > xRet;
1924 if ( _eOpenMode == E_OPEN_DESIGN )
1926 // OJ: http://www.openoffice.org/issues/show_bug.cgi?id=30382
1927 getContainer()->showPreview(NULL);
1930 switch ( _eType )
1932 case E_REPORT:
1933 case E_FORM:
1935 ::std::auto_ptr< OLinkedDocumentsAccess > aHelper = getDocumentsAccess( _eType );
1936 if ( !aHelper->isConnected() )
1937 break;
1939 Reference< XComponent > xDefinition;
1940 xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments );
1942 onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition );
1944 break;
1946 case E_QUERY:
1947 case E_TABLE:
1949 if ( !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode ) )
1951 SharedConnection xConnection( ensureConnection() );
1952 if ( !xConnection.is() )
1953 break;
1955 ::std::auto_ptr< DatabaseObjectView > pDesigner;
1956 ::comphelper::NamedValueCollection aArguments( _rAdditionalArguments );
1958 Any aDataSource;
1959 if ( _eOpenMode == E_OPEN_DESIGN )
1961 sal_Bool bQuerySQLMode =( _nInstigatorCommand == SID_DB_APP_EDIT_SQL_VIEW );
1963 if ( _eType == E_TABLE )
1965 if ( impl_isAlterableView_nothrow( _sName ) )
1966 pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), true, bQuerySQLMode ) );
1967 else
1968 pDesigner.reset( new TableDesigner( getORB(), this, m_aCurrentFrame.getFrame() ) );
1970 else if ( _eType == E_QUERY )
1972 pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), false, bQuerySQLMode ) );
1974 aDataSource <<= m_xDataSource;
1976 else
1978 pDesigner.reset( new ResultSetBrowser( getORB(), this, m_aCurrentFrame.getFrame(), _eType == E_TABLE ) );
1980 if ( !aArguments.has( (::rtl::OUString)PROPERTY_SHOWMENU ) )
1981 aArguments.put( (::rtl::OUString)PROPERTY_SHOWMENU, makeAny( (sal_Bool)sal_True ) );
1983 aDataSource <<= getDatabaseName();
1986 xRet.set( pDesigner->openExisting( aDataSource, _sName, aArguments.getPropertyValues() ) );
1987 onDocumentOpened( _sName, _eType, _eOpenMode, xRet, NULL );
1990 break;
1992 default:
1993 OSL_ENSURE( false, "OApplicationController::openElement: illegal object type!" );
1994 break;
1996 return xRet;
1998 // -----------------------------------------------------------------------------
1999 IMPL_LINK( OApplicationController, OnSelectContainer, void*, _pType )
2001 ElementType eType = (ElementType)reinterpret_cast< sal_IntPtr >( _pType );
2002 getContainer()->selectContainer(eType);
2003 return 0L;
2005 // -----------------------------------------------------------------------------
2006 IMPL_LINK( OApplicationController, OnCreateWithPilot, void*, _pType )
2008 ElementType eType = (ElementType)reinterpret_cast< sal_IntPtr >( _pType );
2009 newElementWithPilot( eType );
2010 return 0L;
2013 // -----------------------------------------------------------------------------
2014 void OApplicationController::newElementWithPilot( ElementType _eType )
2016 OSL_ENSURE( getContainer(), "OApplicationController::newElementWithPilot: without a view?" );
2018 switch ( _eType )
2020 case E_REPORT:
2021 case E_FORM:
2023 ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType);
2024 if ( aHelper->isConnected() )
2026 sal_Int32 nCommandType = -1;
2027 const ::rtl::OUString sName(getCurrentlySelectedName(nCommandType));
2028 Reference< XComponent > xComponent,xDefinition;
2029 if ( E_REPORT == _eType )
2030 xComponent = aHelper->newReportWithPilot(xDefinition,nCommandType,sName);
2031 else
2032 xComponent = aHelper->newFormWithPilot(xDefinition,nCommandType,sName);
2034 onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, xDefinition );
2037 break;
2038 case E_QUERY:
2039 case E_TABLE:
2041 ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType);
2042 if ( aHelper->isConnected() )
2044 Reference< XComponent > xComponent;
2045 if ( E_QUERY == _eType )
2046 xComponent = aHelper->newQueryWithPilot();
2047 else
2048 xComponent = aHelper->newTableWithPilot();
2050 onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, NULL );
2053 break;
2054 case E_NONE:
2055 break;
2059 // -----------------------------------------------------------------------------
2060 void OApplicationController::newElement( ElementType _eType, sal_Bool _bSQLView )
2062 OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
2064 switch ( _eType )
2066 case E_FORM:
2067 case E_REPORT:
2069 ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType);
2070 if ( aHelper->isConnected() )
2072 Reference< XComponent > xComponent,xDefinition;
2073 sal_Int32 nCommandType = -1;
2074 const ::rtl::OUString sName(getCurrentlySelectedName(nCommandType));
2075 xComponent = aHelper->newDocument(_eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT,xDefinition,nCommandType,sName);
2076 onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, xDefinition );
2079 break;
2080 case E_QUERY:
2081 case E_TABLE:
2083 ::std::auto_ptr< DatabaseObjectView > pDesigner;
2084 SharedConnection xConnection( ensureConnection() );
2085 if ( xConnection.is() )
2087 if ( _eType == E_TABLE )
2089 pDesigner.reset( new TableDesigner( getORB(), this, getFrame() ) );
2091 else if ( _eType == E_QUERY )
2093 pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false, _bSQLView ) );
2096 Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
2097 Reference< XComponent > xComponent( pDesigner->createNew( xDataSource ), UNO_QUERY );
2098 onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, NULL );
2101 break;
2102 default:
2103 break;
2106 // -----------------------------------------------------------------------------
2107 void OApplicationController::addContainerListener(const Reference<XNameAccess>& _xCollection)
2111 Reference< XContainer > xCont(_xCollection, UNO_QUERY);
2112 if ( xCont.is() )
2114 // add as listener to get notified if elements are inserted or removed
2115 TContainerVector::iterator aFind = ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xCont);
2116 if ( aFind == m_aCurrentContainers.end() )
2118 xCont->addContainerListener(this);
2119 m_aCurrentContainers.push_back(xCont);
2123 catch( const Exception& )
2125 DBG_UNHANDLED_EXCEPTION();
2128 // -----------------------------------------------------------------------------
2129 void OApplicationController::renameEntry()
2131 ::vos::OGuard aSolarGuard(Application::GetSolarMutex());
2132 ::osl::MutexGuard aGuard( getMutex() );
2134 OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
2135 ::std::vector< ::rtl::OUString> aList;
2136 getSelectionElementNames(aList);
2138 Reference< XNameAccess > xContainer = getElements(getContainer()->getElementType());
2139 OSL_ENSURE(aList.size() == 1,"Invalid rename call here. More than one element!");
2140 if ( aList.empty() )
2141 return;
2145 if ( xContainer.is() )
2147 ::std::auto_ptr< IObjectNameCheck > pNameChecker;
2148 ::std::auto_ptr< OSaveAsDlg > aDialog;
2150 Reference<XRename> xRename;
2151 const ElementType eType = getContainer()->getElementType();
2152 switch( eType )
2154 case E_FORM:
2155 case E_REPORT:
2157 Reference<XHierarchicalNameContainer> xHNames(xContainer, UNO_QUERY);
2158 if ( xHNames.is() )
2160 String sLabel;
2161 if ( eType == E_FORM )
2162 sLabel = String(ModuleRes( STR_FRM_LABEL ));
2163 else
2164 sLabel = String(ModuleRes( STR_RPT_LABEL ));
2166 ::rtl::OUString sName = *aList.begin();
2167 if ( xHNames->hasByHierarchicalName(sName) )
2169 xRename.set(xHNames->getByHierarchicalName(sName),UNO_QUERY);
2170 Reference<XChild> xChild(xRename,UNO_QUERY);
2171 if ( xChild.is() )
2173 Reference<XHierarchicalNameContainer> xParent(xChild->getParent(),UNO_QUERY);
2174 if ( xParent.is() )
2176 xHNames = xParent;
2177 Reference<XPropertySet>(xRename,UNO_QUERY)->getPropertyValue(PROPERTY_NAME) >>= sName;
2180 pNameChecker.reset( new HierarchicalNameCheck( xHNames.get(), String() ) );
2181 aDialog.reset( new OSaveAsDlg(
2182 getView(), getORB(), sName, sLabel, *pNameChecker, SAD_TITLE_RENAME ) );
2186 break;
2187 case E_TABLE:
2188 ensureConnection();
2189 if ( !getConnection().is() )
2190 break;
2191 // NO break
2192 case E_QUERY:
2193 if ( xContainer->hasByName(*aList.begin()) )
2195 xRename.set(xContainer->getByName(*aList.begin()),UNO_QUERY);
2196 sal_Int32 nCommandType = eType == E_QUERY ? CommandType::QUERY : CommandType::TABLE;
2198 ensureConnection();
2199 pNameChecker.reset( new DynamicTableOrQueryNameCheck( getConnection(), nCommandType ) );
2200 aDialog.reset( new OSaveAsDlg(
2201 getView(), nCommandType, getORB(), getConnection(),
2202 *aList.begin(), *pNameChecker, SAD_TITLE_RENAME ) );
2204 break;
2205 default:
2206 break;
2209 if ( xRename.is() && aDialog.get() )
2212 sal_Bool bTryAgain = sal_True;
2213 while( bTryAgain )
2215 if ( aDialog->Execute() == RET_OK )
2219 ::rtl::OUString sNewName;
2220 if ( eType == E_TABLE )
2222 ::rtl::OUString sName = aDialog->getName();
2223 ::rtl::OUString sCatalog = aDialog->getCatalog();
2224 ::rtl::OUString sSchema = aDialog->getSchema();
2226 sNewName = ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sName, sal_False, ::dbtools::eInDataManipulation );
2228 else
2229 sNewName = aDialog->getName();
2231 ::rtl::OUString sOldName = *aList.begin();
2232 if ( eType == E_FORM || eType == E_REPORT )
2234 Reference<XContent> xContent(xRename,UNO_QUERY);
2235 if ( xContent.is() )
2237 sOldName = xContent->getIdentifier()->getContentIdentifier();
2241 xRename->rename(sNewName);
2243 if ( eType == E_TABLE )
2245 Reference<XPropertySet> xProp(xRename,UNO_QUERY);
2246 sNewName = ::dbaui::composeTableName( m_xMetaData, xProp, ::dbtools::eInDataManipulation, false, false, false );
2248 getContainer()->elementReplaced( eType , sOldName, sNewName );
2250 bTryAgain = sal_False;
2252 catch(const SQLException& )
2254 showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
2257 catch(const ElementExistException& e)
2259 static ::rtl::OUString sStatus = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000"));
2260 String sMsg = String( ModuleRes( STR_NAME_ALREADY_EXISTS ) );
2261 sMsg.SearchAndReplace('#',e.Message);
2262 showError(SQLExceptionInfo(SQLException(sMsg, e.Context, sStatus, 0, Any())));
2264 catch(const Exception& )
2266 DBG_UNHANDLED_EXCEPTION();
2269 else
2270 bTryAgain = sal_False;
2275 catch(const Exception& )
2277 DBG_UNHANDLED_EXCEPTION();
2281 // -----------------------------------------------------------------------------
2282 void OApplicationController::onSelectionChanged()
2284 InvalidateAll();
2286 SelectionGuard aSelGuard( *m_pSelectionNotifier );
2288 OApplicationView* pView = getContainer();
2289 if ( !pView )
2290 return;
2292 if ( pView->getSelectionCount() == 1 )
2294 const ElementType eType = pView->getElementType();
2295 if ( pView->isALeafSelected() )
2297 const ::rtl::OUString sName = pView->getQualifiedName( NULL /* means 'first selected' */ );
2298 showPreviewFor( eType, sName );
2302 // -----------------------------------------------------------------------------
2303 void OApplicationController::showPreviewFor(const ElementType _eType,const ::rtl::OUString& _sName)
2305 if ( m_ePreviewMode == E_PREVIEWNONE )
2306 return;
2308 OApplicationView* pView = getContainer();
2309 if ( !pView )
2310 return;
2314 switch( _eType )
2316 case E_FORM:
2317 case E_REPORT:
2319 Reference< XHierarchicalNameAccess > xContainer( getElements( _eType ), UNO_QUERY_THROW );
2320 Reference< XContent> xContent( xContainer->getByHierarchicalName( _sName ), UNO_QUERY_THROW );
2321 pView->showPreview( xContent );
2323 break;
2325 case E_TABLE:
2326 case E_QUERY:
2328 SharedConnection xConnection( ensureConnection() );
2329 if ( xConnection.is() )
2330 pView->showPreview( getDatabaseName(), xConnection, _sName, _eType == E_TABLE );
2332 return;
2334 default:
2335 OSL_ENSURE( false, "OApplicationController::showPreviewFor: unexpected element type!" );
2336 break;
2339 catch( const SQLException& )
2341 showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
2343 catch(const Exception& )
2345 DBG_UNHANDLED_EXCEPTION();
2349 //------------------------------------------------------------------------------
2350 IMPL_LINK( OApplicationController, OnClipboardChanged, void*, EMPTYARG )
2352 return OnInvalidateClipboard( NULL );
2354 //------------------------------------------------------------------------------
2355 IMPL_LINK(OApplicationController, OnInvalidateClipboard, void*, EMPTYARG)
2357 InvalidateFeature(ID_BROWSER_CUT);
2358 InvalidateFeature(ID_BROWSER_COPY);
2359 InvalidateFeature(ID_BROWSER_PASTE);
2360 InvalidateFeature(SID_DB_APP_PASTE_SPECIAL);
2361 return 0L;
2363 // -----------------------------------------------------------------------------
2364 void OApplicationController::onCutEntry()
2367 // -----------------------------------------------------------------------------
2368 void OApplicationController::onCopyEntry()
2370 Execute(ID_BROWSER_COPY,Sequence<PropertyValue>());
2372 // -----------------------------------------------------------------------------
2373 void OApplicationController::onPasteEntry()
2375 Execute(ID_BROWSER_PASTE,Sequence<PropertyValue>());
2377 // -----------------------------------------------------------------------------
2378 void OApplicationController::onDeleteEntry()
2380 ElementType eType = getContainer()->getElementType();
2381 sal_uInt16 nId = 0;
2382 switch(eType)
2384 case E_TABLE:
2385 nId = SID_DB_APP_TABLE_DELETE;
2386 break;
2387 case E_QUERY:
2388 nId = SID_DB_APP_QUERY_DELETE;
2389 break;
2390 case E_FORM:
2391 nId = SID_DB_APP_FORM_DELETE;
2392 break;
2393 case E_REPORT:
2394 nId = SID_DB_APP_REPORT_DELETE;
2395 break;
2396 default:
2397 OSL_ENSURE(0,"Invalid ElementType!");
2398 break;
2400 executeChecked(nId,Sequence<PropertyValue>());
2403 // -----------------------------------------------------------------------------
2404 void OApplicationController::executeUnChecked(const URL& _rCommand, const Sequence< PropertyValue>& aArgs)
2406 OApplicationController_CBASE::executeUnChecked( _rCommand, aArgs );
2409 // -----------------------------------------------------------------------------
2410 void OApplicationController::executeChecked(const URL& _rCommand, const Sequence< PropertyValue>& aArgs)
2412 OApplicationController_CBASE::executeChecked( _rCommand, aArgs );
2415 // -----------------------------------------------------------------------------
2416 void OApplicationController::executeUnChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue>& aArgs)
2418 OApplicationController_CBASE::executeUnChecked( _nCommandId, aArgs );
2421 // -----------------------------------------------------------------------------
2422 void OApplicationController::executeChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue>& aArgs)
2424 OApplicationController_CBASE::executeChecked( _nCommandId, aArgs );
2427 // -----------------------------------------------------------------------------
2428 sal_Bool OApplicationController::isCommandEnabled(sal_uInt16 _nCommandId) const
2430 return OApplicationController_CBASE::isCommandEnabled( _nCommandId );
2433 // -----------------------------------------------------------------------------
2434 sal_Bool OApplicationController::isCommandEnabled( const ::rtl::OUString& _rCompleteCommandURL ) const
2436 return OApplicationController_CBASE::isCommandEnabled( _rCompleteCommandURL );
2439 // -----------------------------------------------------------------------------
2440 sal_uInt16 OApplicationController::registerCommandURL( const ::rtl::OUString& _rCompleteCommandURL )
2442 return OApplicationController_CBASE::registerCommandURL( _rCompleteCommandURL );
2445 // -----------------------------------------------------------------------------
2446 void OApplicationController::notifyHiContrastChanged()
2448 OApplicationController_CBASE::notifyHiContrastChanged();
2451 // -----------------------------------------------------------------------------
2452 Reference< XController > OApplicationController::getXController() throw( RuntimeException )
2454 return OApplicationController_CBASE::getXController();
2457 // -----------------------------------------------------------------------------
2458 bool OApplicationController::interceptUserInput( const NotifyEvent& _rEvent )
2460 return OApplicationController_CBASE::interceptUserInput( _rEvent );
2463 // -----------------------------------------------------------------------------
2464 PopupMenu* OApplicationController::getContextMenu( Control& /*_rControl*/ ) const
2466 return new PopupMenu( ModuleRes( RID_MENU_APP_EDIT ) );
2469 // -----------------------------------------------------------------------------
2470 IController& OApplicationController::getCommandController()
2472 return *static_cast< IApplicationController* >( this );
2475 // -----------------------------------------------------------------------------
2476 ::cppu::OInterfaceContainerHelper* OApplicationController::getContextMenuInterceptors()
2478 return &m_aContextMenuInterceptors;
2481 // -----------------------------------------------------------------------------
2482 Any OApplicationController::getCurrentSelection( Control& _rControl ) const
2484 Sequence< NamedDatabaseObject > aSelection;
2485 getContainer()->describeCurrentSelectionForControl( _rControl, aSelection );
2486 return makeAny( aSelection );
2489 // -----------------------------------------------------------------------------
2490 sal_Bool OApplicationController::requestQuickHelp( const SvLBoxEntry* /*_pEntry*/, String& /*_rText*/ ) const
2492 return sal_False;
2495 // -----------------------------------------------------------------------------
2496 sal_Bool OApplicationController::requestDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
2498 TransferableHelper* pTransfer = NULL;
2499 if ( getContainer() && getContainer()->getSelectionCount() )
2503 pTransfer = copyObject( );
2504 Reference< XTransferable> xEnsureDelete = pTransfer;
2506 if ( pTransfer && getContainer()->getDetailView() )
2508 ElementType eType = getContainer()->getElementType();
2509 pTransfer->StartDrag( getContainer()->getDetailView()->getTreeWindow(), ((eType == E_FORM || eType == E_REPORT) ? DND_ACTION_COPYMOVE : DND_ACTION_COPY) );
2512 catch(const Exception& )
2514 DBG_UNHANDLED_EXCEPTION();
2518 return NULL != pTransfer;
2520 // -----------------------------------------------------------------------------
2521 sal_Int8 OApplicationController::queryDrop( const AcceptDropEvent& _rEvt, const DataFlavorExVector& _rFlavors )
2523 sal_Int8 nActionAskedFor = _rEvt.mnAction;
2524 // check if we're a table or query container
2525 OApplicationView* pView = getContainer();
2526 if ( pView && !isDataSourceReadOnly() )
2528 ElementType eType = pView->getElementType();
2529 if ( eType != E_NONE && (eType != E_TABLE || !isConnectionReadOnly()) )
2531 // check for the concrete type
2532 if(::std::find_if(_rFlavors.begin(),_rFlavors.end(),TAppSupportedSotFunctor(eType,sal_True)) != _rFlavors.end())
2533 return DND_ACTION_COPY;
2534 if ( eType == E_FORM || eType == E_REPORT )
2536 sal_Int8 nAction = OComponentTransferable::canExtractComponentDescriptor(_rFlavors,eType == E_FORM) ? DND_ACTION_COPY : DND_ACTION_NONE;
2537 if ( nAction != DND_ACTION_NONE )
2539 SvLBoxEntry* pHitEntry = pView->getEntry(_rEvt.maPosPixel);
2540 ::rtl::OUString sName;
2541 if ( pHitEntry )
2543 sName = pView->getQualifiedName( pHitEntry );
2544 if ( sName.getLength() )
2546 Reference< XHierarchicalNameAccess > xContainer(getElements(pView->getElementType()),UNO_QUERY);
2547 if ( xContainer.is() && xContainer->hasByHierarchicalName(sName) )
2549 Reference< XHierarchicalNameAccess > xHitObject(xContainer->getByHierarchicalName(sName),UNO_QUERY);
2550 if ( xHitObject.is() )
2551 nAction = nActionAskedFor & DND_ACTION_COPYMOVE;
2553 else
2554 nAction = DND_ACTION_NONE;
2557 /*else
2558 nAction = nActionAskedFor & DND_ACTION_COPYMOVE;
2561 return nAction;
2566 return DND_ACTION_NONE;
2568 // -----------------------------------------------------------------------------
2569 sal_Int8 OApplicationController::executeDrop( const ExecuteDropEvent& _rEvt )
2571 OApplicationView* pView = getContainer();
2572 if ( !pView || pView->getElementType() == E_NONE )
2574 DBG_ERROR("OApplicationController::executeDrop: what the hell did queryDrop do?");
2575 // queryDrop shoud not have allowed us to reach this situation ....
2576 return DND_ACTION_NONE;
2579 // a TransferableDataHelper for accessing the dropped data
2580 TransferableDataHelper aDroppedData(_rEvt.maDropEvent.Transferable);
2583 // reset the data of the previous async drop (if any)
2584 if ( m_nAsyncDrop )
2585 Application::RemoveUserEvent(m_nAsyncDrop);
2588 m_nAsyncDrop = 0;
2589 m_aAsyncDrop.aDroppedData.clear();
2590 m_aAsyncDrop.nType = pView->getElementType();
2591 m_aAsyncDrop.nAction = _rEvt.mnAction;
2592 m_aAsyncDrop.bError = sal_False;
2593 m_aAsyncDrop.bHtml = sal_False;
2594 m_aAsyncDrop.aUrl = ::rtl::OUString();
2597 // loop through the available formats and see what we can do ...
2598 // first we have to check if it is our own format, if not we have to copy the stream :-(
2599 if ( ODataAccessObjectTransferable::canExtractObjectDescriptor(aDroppedData.GetDataFlavorExVector()) )
2601 m_aAsyncDrop.aDroppedData = ODataAccessObjectTransferable::extractObjectDescriptor(aDroppedData);
2603 // asyncron because we some dialogs and we aren't allowed to show them while in D&D
2604 m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
2605 return DND_ACTION_COPY;
2607 else if ( OComponentTransferable::canExtractComponentDescriptor(aDroppedData.GetDataFlavorExVector(),m_aAsyncDrop.nType == E_FORM) )
2609 m_aAsyncDrop.aDroppedData = OComponentTransferable::extractComponentDescriptor(aDroppedData);
2610 SvLBoxEntry* pHitEntry = pView->getEntry(_rEvt.maPosPixel);
2611 if ( pHitEntry )
2612 m_aAsyncDrop.aUrl = pView->getQualifiedName( pHitEntry );
2614 sal_Int8 nAction = _rEvt.mnAction;
2615 Reference<XContent> xContent;
2616 m_aAsyncDrop.aDroppedData[daComponent] >>= xContent;
2617 if ( xContent.is() )
2619 ::rtl::OUString sName = xContent->getIdentifier()->getContentIdentifier();
2620 sal_Int32 nIndex = 0;
2621 sName = sName.copy(sName.getToken(0,'/',nIndex).getLength() + 1);
2622 if ( m_aAsyncDrop.aUrl.Len() >= sName.getLength() && 0 == sName.compareTo(m_aAsyncDrop.aUrl,sName.getLength()) )
2624 m_aAsyncDrop.aDroppedData.clear();
2625 return DND_ACTION_NONE;
2628 // check if move is allowed, if another object with the same name exists only copy is allowed
2629 Reference< XHierarchicalNameAccess > xContainer(getElements(m_aAsyncDrop.nType),UNO_QUERY);
2630 Reference<XNameAccess> xNameAccess(xContainer,UNO_QUERY);
2632 if ( m_aAsyncDrop.aUrl.Len() && xContainer.is() && xContainer->hasByHierarchicalName(m_aAsyncDrop.aUrl) )
2633 xNameAccess.set(xContainer->getByHierarchicalName(m_aAsyncDrop.aUrl),UNO_QUERY);
2635 if ( xNameAccess.is() )
2637 Reference<XPropertySet> xProp(xContent,UNO_QUERY);
2638 if ( xProp.is() )
2640 xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
2641 if ( xNameAccess.is() && xNameAccess->hasByName(sName) )
2642 nAction &= ~DND_ACTION_MOVE;
2644 else
2645 nAction &= ~DND_ACTION_MOVE;
2648 if ( nAction != DND_ACTION_NONE )
2650 m_aAsyncDrop.nAction = nAction;
2651 // asyncron because we some dialogs and we aren't allowed to show them while in D&D
2652 m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
2654 else
2655 m_aAsyncDrop.aDroppedData.clear();
2656 return nAction;
2658 else
2660 SharedConnection xConnection( ensureConnection() );
2661 if ( xConnection.is() && m_aTableCopyHelper.copyTagTable( aDroppedData, m_aAsyncDrop, xConnection ) )
2663 // asyncron because we some dialogs and we aren't allowed to show them while in D&D
2664 m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
2665 return DND_ACTION_COPY;
2669 return DND_ACTION_NONE;
2671 // -----------------------------------------------------------------------------
2672 Reference< XModel > SAL_CALL OApplicationController::getModel(void) throw( RuntimeException )
2674 return m_xModel;
2677 // -----------------------------------------------------------------------------
2678 void OApplicationController::onConnectedModel()
2680 sal_Int32 nConnectedControllers( 0 );
2683 Reference< XModel2 > xModel( m_xModel, UNO_QUERY_THROW );
2684 Reference< XEnumeration > xEnumControllers( xModel->getControllers(), UNO_SET_THROW );
2685 while ( xEnumControllers->hasMoreElements() )
2687 Reference< XController > xController( xEnumControllers->nextElement(), UNO_QUERY_THROW );
2688 ++nConnectedControllers;
2691 catch( const Exception& )
2693 DBG_UNHANDLED_EXCEPTION();
2696 if ( nConnectedControllers > 1 )
2697 { // we are not the first connected controller, there were already others
2698 return;
2701 m_aControllerConnectedEvent.Call();
2704 // -----------------------------------------------------------------------------
2705 IMPL_LINK( OApplicationController, OnFirstControllerConnected, void*, /**/ )
2707 // if we have forms or reports which contain macros/scripts, then show a warning
2708 // which suggests the user to migrate them to the database document
2710 Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
2711 if ( xDocumentScripts.is() )
2713 // no need to show this warning, obviously the document supports embedding scripts
2714 // into itself, so there are no "old-style" forms/reports which have macros/scripts
2715 // themselves
2716 return 0L;
2721 // If the migration just happened, but was not successful, the document is reloaded.
2722 // In this case, we should not show the warning, again.
2723 ::comphelper::NamedValueCollection aModelArgs( m_xModel->getArgs() );
2724 if ( aModelArgs.getOrDefault( "SuppressMigrationWarning", sal_False ) )
2725 return 0L;
2727 // also, if the document is read-only, then no migration is possible, and the
2728 // respective menu entry is hidden. So, don't show the warning in this case, too.
2729 if ( Reference< XStorable >( m_xModel, UNO_QUERY_THROW )->isReadonly() )
2730 return 0L;
2732 SQLWarning aWarning;
2733 aWarning.Message = String( ModuleRes( STR_SUB_DOCS_WITH_SCRIPTS ) );
2734 SQLException aDetail;
2735 aDetail.Message = String( ModuleRes( STR_SUB_DOCS_WITH_SCRIPTS_DETAIL ) );
2736 aWarning.NextException <<= aDetail;
2738 ::comphelper::ComponentContext aContext( getORB() );
2739 Sequence< Any > aArgs(1);
2740 aArgs[0] <<= NamedValue( PROPERTY_SQLEXCEPTION, makeAny( aWarning ) );
2741 Reference< XExecutableDialog > xDialog(
2742 aContext.createComponentWithArguments( "com.sun.star.sdb.ErrorMessageDialog", aArgs ),
2743 UNO_QUERY_THROW );
2744 xDialog->execute();
2746 catch( const Exception& )
2748 DBG_UNHANDLED_EXCEPTION();
2751 return 1L;
2754 // -----------------------------------------------------------------------------
2755 sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > & _rxModel) throw( RuntimeException )
2757 ::osl::MutexGuard aGuard( getMutex() );
2758 Reference< XOfficeDatabaseDocument > xOfficeDoc( _rxModel, UNO_QUERY );
2759 if ( !xOfficeDoc.is() && _rxModel.is() )
2761 DBG_ERROR( "OApplicationController::attachModel: invalid model!" );
2762 return sal_False;
2765 DBG_ASSERT( !( m_xModel.is() && ( m_xModel != _rxModel ) ),
2766 "OApplicationController::attachModel: missing implementation: setting a new model while we have another one!" );
2767 // at least: remove as property change listener from the old model/data source
2769 m_xModel = _rxModel;
2770 if ( _rxModel.is() )
2772 m_xDocumentModify.set( m_xModel, UNO_QUERY_THROW );
2773 m_aModelConnector.connect( _rxModel, this );
2774 onConnectedModel();
2776 else
2778 m_xDocumentModify.clear();
2779 m_aModelConnector.clear();
2782 m_xDataSource.set(xOfficeDoc.is() ? xOfficeDoc->getDataSource() : Reference<XDataSource>(),UNO_QUERY);
2783 if ( m_xDataSource.is() )
2787 m_xDataSource->addPropertyChangeListener(PROPERTY_INFO, this);
2788 m_xDataSource->addPropertyChangeListener(PROPERTY_URL, this);
2789 m_xDataSource->addPropertyChangeListener(PROPERTY_ISPASSWORDREQUIRED, this);
2790 m_xDataSource->addPropertyChangeListener(PROPERTY_LAYOUTINFORMATION, this);
2791 m_xDataSource->addPropertyChangeListener(PROPERTY_SUPPRESSVERSIONCL, this);
2792 m_xDataSource->addPropertyChangeListener(PROPERTY_TABLEFILTER, this);
2793 m_xDataSource->addPropertyChangeListener(PROPERTY_TABLETYPEFILTER, this);
2794 m_xDataSource->addPropertyChangeListener(PROPERTY_USER, this);
2795 // to get the 'modified' for the data source
2796 Reference< XModifyBroadcaster > xBroadcaster(m_xModel, UNO_QUERY);
2797 if ( xBroadcaster.is() )
2798 xBroadcaster->addModifyListener(static_cast<XModifyListener*>(this));
2800 Sequence<PropertyValue> aFields;
2801 m_xDataSource->getPropertyValue(PROPERTY_LAYOUTINFORMATION) >>= aFields;
2802 PropertyValue *pIter = aFields.getArray();
2803 PropertyValue *pEnd = pIter + aFields.getLength();
2804 for (; pIter != pEnd && pIter->Name != INFO_PREVIEW; ++pIter)
2807 if ( pIter != pEnd )
2809 sal_Int32 nValue = 0;
2810 pIter->Value >>= nValue;
2811 m_ePreviewMode = static_cast<PreviewMode>(nValue);
2812 if ( getView() )
2814 getContainer()->switchPreview(m_ePreviewMode);
2818 catch( const Exception& )
2820 DBG_UNHANDLED_EXCEPTION();
2824 return sal_True;
2826 // -----------------------------------------------------------------------------
2827 void OApplicationController::containerFound( const Reference< XContainer >& _xContainer)
2831 if ( _xContainer.is() )
2833 m_aCurrentContainers.push_back(_xContainer);
2834 _xContainer->addContainerListener(this);
2837 catch(Exception)
2839 OSL_ENSURE(0,"Could not listener on the container!");
2842 // -----------------------------------------------------------------------------
2843 ::rtl::OUString OApplicationController::getCurrentlySelectedName(sal_Int32& _rnCommandType) const
2845 _rnCommandType = ( (getContainer()->getElementType() == E_QUERY)
2846 ? CommandType::QUERY : ( (getContainer()->getElementType() == E_TABLE) ? CommandType::TABLE : -1 ));
2849 ::rtl::OUString sName;
2850 if ( _rnCommandType != -1 )
2854 sName = getContainer()->getQualifiedName( NULL );
2855 OSL_ENSURE( sName.getLength(), "OApplicationController::newElementWithPilot: no name given!" );
2857 catch( const Exception& )
2859 DBG_UNHANDLED_EXCEPTION();
2862 return sName;
2865 // -----------------------------------------------------------------------------
2866 void SAL_CALL OApplicationController::addSelectionChangeListener( const Reference< view::XSelectionChangeListener >& _Listener ) throw (RuntimeException)
2868 m_pSelectionNotifier->addListener( _Listener );
2871 // -----------------------------------------------------------------------------
2872 void SAL_CALL OApplicationController::removeSelectionChangeListener( const Reference< view::XSelectionChangeListener >& _Listener ) throw (RuntimeException)
2874 m_pSelectionNotifier->removeListener( _Listener );
2877 // -----------------------------------------------------------------------------
2878 ::sal_Bool SAL_CALL OApplicationController::select( const Any& _aSelection ) throw (IllegalArgumentException, RuntimeException)
2880 ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
2881 ::osl::MutexGuard aGuard( getMutex() );
2882 Sequence< ::rtl::OUString> aSelection;
2883 if ( !_aSelection.hasValue() || !getView() )
2885 getContainer()->selectElements(aSelection);
2886 return sal_True;
2889 // --------------------------------------------------------------
2890 // BEGIN compatibility
2891 Sequence< NamedValue > aCurrentSelection;
2892 if ( (_aSelection >>= aCurrentSelection) && aCurrentSelection.getLength() )
2894 ElementType eType = E_NONE;
2895 const NamedValue* pIter = aCurrentSelection.getConstArray();
2896 const NamedValue* pEnd = pIter + aCurrentSelection.getLength();
2897 for(;pIter != pEnd;++pIter)
2899 if ( pIter->Name.equalsAscii("Type") )
2901 sal_Int32 nType = 0;
2902 pIter->Value >>= nType;
2903 if ( nType < DatabaseObject::TABLE || nType > DatabaseObject::REPORT )
2904 throw IllegalArgumentException();
2905 eType = static_cast< ElementType >( nType );
2907 else if ( pIter->Name.equalsAscii("Selection") )
2908 pIter->Value >>= aSelection;
2911 m_aSelectContainerEvent.CancelCall(); // just in case the async select request was running
2912 getContainer()->selectContainer(eType);
2913 getContainer()->selectElements(aSelection);
2914 return sal_True;
2916 // END compatibility
2917 // --------------------------------------------------------------
2919 Sequence< NamedDatabaseObject > aSelectedObjects;
2920 if ( !( _aSelection >>= aSelectedObjects ) )
2922 aSelectedObjects.realloc( 1 );
2923 if ( !( _aSelection >>= aSelectedObjects[0] ) )
2924 throw IllegalArgumentException();
2927 SelectionByElementType aSelectedElements;
2928 ElementType eSelectedCategory = E_NONE;
2929 for ( const NamedDatabaseObject* pObject = aSelectedObjects.getConstArray();
2930 pObject != aSelectedObjects.getConstArray() + aSelectedObjects.getLength();
2931 ++pObject
2934 switch ( pObject->Type )
2936 case DatabaseObject::TABLE:
2937 case DatabaseObjectContainer::SCHEMA:
2938 case DatabaseObjectContainer::CATALOG:
2939 aSelectedElements[ E_TABLE ].push_back( pObject->Name );
2940 break;
2941 case DatabaseObject::QUERY:
2942 aSelectedElements[ E_QUERY ].push_back( pObject->Name );
2943 break;
2944 case DatabaseObject::FORM:
2945 case DatabaseObjectContainer::FORMS_FOLDER:
2946 aSelectedElements[ E_FORM ].push_back( pObject->Name );
2947 break;
2948 case DatabaseObject::REPORT:
2949 case DatabaseObjectContainer::REPORTS_FOLDER:
2950 aSelectedElements[ E_REPORT ].push_back( pObject->Name );
2951 break;
2952 case DatabaseObjectContainer::TABLES:
2953 case DatabaseObjectContainer::QUERIES:
2954 case DatabaseObjectContainer::FORMS:
2955 case DatabaseObjectContainer::REPORTS:
2956 if ( eSelectedCategory != E_NONE )
2957 throw IllegalArgumentException(
2958 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "You cannot select different categories." ) ),
2959 // TODO: resource
2960 *this, sal_Int16( pObject - aSelectedObjects.getConstArray() ) );
2961 eSelectedCategory =
2962 ( pObject->Type == DatabaseObjectContainer::TABLES ) ? E_TABLE
2963 : ( pObject->Type == DatabaseObjectContainer::QUERIES ) ? E_QUERY
2964 : ( pObject->Type == DatabaseObjectContainer::FORMS ) ? E_FORM
2965 : ( pObject->Type == DatabaseObjectContainer::REPORTS ) ? E_REPORT
2966 : E_NONE;
2967 break;
2969 default:
2970 case DatabaseObjectContainer::DATA_SOURCE:
2972 ::rtl::OUStringBuffer aMessage;
2973 aMessage.appendAscii( "Unsupported object type found (" );
2974 aMessage.append ( sal_Int32( pObject->Type ) );
2975 aMessage.appendAscii( ")." );
2976 // TODO: resource
2977 throw IllegalArgumentException(
2978 aMessage.makeStringAndClear(), *this, sal_Int16( pObject - aSelectedObjects.getConstArray() ) );
2983 for ( SelectionByElementType::const_iterator sel = aSelectedElements.begin();
2984 sel != aSelectedElements.end();
2985 ++sel
2988 if ( sel->first == m_eCurrentType )
2990 Sequence< ::rtl::OUString > aSelected( sel->second.size() );
2991 ::std::copy( sel->second.begin(), sel->second.end(), aSelected.getArray() );
2992 getContainer()->selectElements( aSelected );
2994 else
2996 m_aPendingSelection[ sel->first ] = sel->second;
3000 m_aSelectContainerEvent.CancelCall(); // just in case the async select request was running
3001 getContainer()->selectContainer( eSelectedCategory );
3003 return sal_True;
3005 // -----------------------------------------------------------------------------
3006 Any SAL_CALL OApplicationController::getSelection( ) throw (RuntimeException)
3008 ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
3009 ::osl::MutexGuard aGuard( getMutex() );
3011 Sequence< NamedDatabaseObject > aCurrentSelection;
3012 const ElementType eType( getContainer()->getElementType() );
3013 if ( eType != E_NONE )
3015 getContainer()->describeCurrentSelectionForType( eType, aCurrentSelection );
3016 if ( aCurrentSelection.getLength() == 0 )
3017 { // if no objects are selected, add an entry to the sequence which describes the overall category
3018 // which is selected currently
3019 aCurrentSelection.realloc(1);
3020 aCurrentSelection[0].Name = getDatabaseName();
3021 switch ( eType )
3023 case E_TABLE: aCurrentSelection[0].Type = DatabaseObjectContainer::TABLES; break;
3024 case E_QUERY: aCurrentSelection[0].Type = DatabaseObjectContainer::QUERIES; break;
3025 case E_FORM: aCurrentSelection[0].Type = DatabaseObjectContainer::FORMS; break;
3026 case E_REPORT: aCurrentSelection[0].Type = DatabaseObjectContainer::REPORTS; break;
3027 default:
3028 OSL_ENSURE( false, "OApplicationController::getSelection: unexpected current element type!" );
3029 break;
3033 return makeAny( aCurrentSelection );
3035 // -----------------------------------------------------------------------------
3036 void OApplicationController::impl_migrateScripts_nothrow()
3040 ::rtl::OUString sDialogService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.application.MacroMigrationWizard" ) );
3041 ::comphelper::ComponentContext aContext( getORB() );
3042 Sequence< Any > aDialogArgs(1);
3043 aDialogArgs[0] <<= Reference< XOfficeDatabaseDocument >( m_xModel, UNO_QUERY_THROW );
3044 Reference< XExecutableDialog > xDialog(
3045 aContext.createComponentWithArguments( sDialogService, aDialogArgs ),
3046 UNO_QUERY );
3048 if ( !xDialog.is() )
3050 ShowServiceNotAvailableError( getView(), sDialogService, true );
3051 return;
3054 xDialog->execute();
3056 catch( const Exception& )
3058 DBG_UNHANDLED_EXCEPTION();
3062 //........................................................................
3063 } // namespace dbaui
3064 //........................................................................