xref: /AOO41X/main/dbaccess/source/ui/app/AppController.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "AppController.hxx"
32*cdf0e10cSrcweir #include "dbustrings.hrc"
33*cdf0e10cSrcweir #include "advancedsettingsdlg.hxx"
34*cdf0e10cSrcweir #include "subcomponentmanager.hxx"
35*cdf0e10cSrcweir #include "closeveto.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir /** === begin UNO includes === **/
38*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAlterView.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAppend.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XRename.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/util/XFlushable.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatter.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
65*cdf0e10cSrcweir #include <com/sun/star/document/XEmbeddedScripts.hpp>
66*cdf0e10cSrcweir #include <com/sun/star/frame/XModel2.hpp>
67*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
68*cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
69*cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
70*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
71*cdf0e10cSrcweir #include <com/sun/star/util/XFlushable.hpp>
72*cdf0e10cSrcweir #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
73*cdf0e10cSrcweir #include "com/sun/star/beans/NamedValue.hpp"
74*cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
75*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
76*cdf0e10cSrcweir #include <com/sun/star/sdb/application/DatabaseObject.hpp>
77*cdf0e10cSrcweir #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
78*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
79*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalName.hpp>
80*cdf0e10cSrcweir /** === end UNO includes === **/
81*cdf0e10cSrcweir #include <tools/debug.hxx>
82*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
83*cdf0e10cSrcweir #include <tools/string.hxx>
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir #include <svl/urihelper.hxx>
86*cdf0e10cSrcweir #include <svl/filenotation.hxx>
87*cdf0e10cSrcweir #include <svtools/svtreebx.hxx>
88*cdf0e10cSrcweir #include <svtools/transfer.hxx>
89*cdf0e10cSrcweir #include <svtools/cliplistener.hxx>
90*cdf0e10cSrcweir #include <svtools/svlbitm.hxx>
91*cdf0e10cSrcweir #include <svtools/insdlg.hxx>
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
94*cdf0e10cSrcweir #include <comphelper/uno3.hxx>
95*cdf0e10cSrcweir #include <comphelper/string.hxx>
96*cdf0e10cSrcweir #include <comphelper/types.hxx>
97*cdf0e10cSrcweir #include <comphelper/interaction.hxx>
98*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
101*cdf0e10cSrcweir #include <vcl/stdtext.hxx>
102*cdf0e10cSrcweir #include <vcl/svapp.hxx>
103*cdf0e10cSrcweir #include <vcl/menu.hxx>
104*cdf0e10cSrcweir #include <vcl/lstbox.hxx>
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
107*cdf0e10cSrcweir #include <unotools/tempfile.hxx>
108*cdf0e10cSrcweir #include <unotools/internaloptions.hxx>
109*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
110*cdf0e10cSrcweir #include <unotools/historyoptions.hxx>
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir #include <sfx2/mailmodelapi.hxx>
113*cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
114*cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
115*cdf0e10cSrcweir #include <sfx2/QuerySaveDocument.hxx>
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
118*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
121*cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir #include <svx/dbaexchange.hxx>
124*cdf0e10cSrcweir #include <svx/dbaobjectex.hxx>
125*cdf0e10cSrcweir #include <svx/svxdlg.hxx>
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir #include <vos/mutex.hxx>
128*cdf0e10cSrcweir #include "AppView.hxx"
129*cdf0e10cSrcweir #include "browserids.hxx"
130*cdf0e10cSrcweir #include "dbu_reghelper.hxx"
131*cdf0e10cSrcweir #include "dbu_app.hrc"
132*cdf0e10cSrcweir #include "defaultobjectnamecheck.hxx"
133*cdf0e10cSrcweir #include "databaseobjectview.hxx"
134*cdf0e10cSrcweir #include "listviewitems.hxx"
135*cdf0e10cSrcweir #include "AppDetailView.hxx"
136*cdf0e10cSrcweir #include "linkeddocuments.hxx"
137*cdf0e10cSrcweir #include "sqlmessage.hxx"
138*cdf0e10cSrcweir #include "UITools.hxx"
139*cdf0e10cSrcweir #include "dsntypes.hxx"
140*cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
141*cdf0e10cSrcweir #include "dlgsave.hxx"
142*cdf0e10cSrcweir #include "dbaccess_slotid.hrc"
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir #include <algorithm>
145*cdf0e10cSrcweir #include <functional>
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir #include <boost/noncopyable.hpp>
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_ODBApplication()
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir 	static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OApplicationController > aAutoRegistration;
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir //........................................................................
154*cdf0e10cSrcweir namespace dbaui
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir //........................................................................
157*cdf0e10cSrcweir using namespace ::dbtools;
158*cdf0e10cSrcweir using namespace ::svx;
159*cdf0e10cSrcweir using namespace ::com::sun::star;
160*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
161*cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
162*cdf0e10cSrcweir using namespace ::com::sun::star::view;
163*cdf0e10cSrcweir using namespace ::com::sun::star::util;
164*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
165*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
166*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
167*cdf0e10cSrcweir using namespace ::com::sun::star::container;
168*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
169*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
170*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
171*cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer;
172*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
173*cdf0e10cSrcweir using namespace ::com::sun::star::task;
174*cdf0e10cSrcweir using ::com::sun::star::document::XEmbeddedScripts;
175*cdf0e10cSrcweir using ::com::sun::star::document::XDocumentEventBroadcaster;
176*cdf0e10cSrcweir using ::com::sun::star::document::DocumentEvent;
177*cdf0e10cSrcweir using ::com::sun::star::sdb::application::NamedDatabaseObject;
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
180*cdf0e10cSrcweir namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir //------------------------------------------------------------------------------
183*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OApplicationController::getImplementationName() throw( RuntimeException )
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir 	return getImplementationName_Static();
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir //------------------------------------------------------------------------------
189*cdf0e10cSrcweir ::rtl::OUString OApplicationController::getImplementationName_Static() throw( RuntimeException )
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir 	return ::rtl::OUString(SERVICE_SDB_APPLICATIONCONTROLLER);
192*cdf0e10cSrcweir }
193*cdf0e10cSrcweir //------------------------------------------------------------------------------
194*cdf0e10cSrcweir Sequence< ::rtl::OUString> OApplicationController::getSupportedServiceNames_Static(void) throw( RuntimeException )
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir 	Sequence< ::rtl::OUString> aSupported(1);
197*cdf0e10cSrcweir 	aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.application.DefaultViewController");
198*cdf0e10cSrcweir 	return aSupported;
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir //-------------------------------------------------------------------------
201*cdf0e10cSrcweir Sequence< ::rtl::OUString> SAL_CALL OApplicationController::getSupportedServiceNames() throw(RuntimeException)
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir 	return getSupportedServiceNames_Static();
204*cdf0e10cSrcweir }
205*cdf0e10cSrcweir // -------------------------------------------------------------------------
206*cdf0e10cSrcweir Reference< XInterface > SAL_CALL OApplicationController::Create(const Reference<XMultiServiceFactory >& _rxFactory)
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir 	return *(new OApplicationController(_rxFactory));
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir // -----------------------------------------------------------------------------
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir struct XContainerFunctor : public ::std::unary_function< OApplicationController::TContainerVector::value_type , bool>
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir 	Reference<XContainerListener> m_xContainerListener;
215*cdf0e10cSrcweir 	XContainerFunctor( const Reference<XContainerListener>& _xContainerListener)
216*cdf0e10cSrcweir 		: m_xContainerListener(_xContainerListener){}
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 	bool operator() (const OApplicationController::TContainerVector::value_type& lhs) const
219*cdf0e10cSrcweir 	{
220*cdf0e10cSrcweir 		if ( lhs.is() )
221*cdf0e10cSrcweir 			lhs->removeContainerListener(m_xContainerListener);
222*cdf0e10cSrcweir 		return true;
223*cdf0e10cSrcweir 	}
224*cdf0e10cSrcweir };
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir //====================================================================
227*cdf0e10cSrcweir //= OApplicationController
228*cdf0e10cSrcweir //====================================================================
229*cdf0e10cSrcweir class SelectionNotifier : public ::boost::noncopyable
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir private:
232*cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper   m_aSelectionListeners;
233*cdf0e10cSrcweir     ::cppu::OWeakObject&                m_rContext;
234*cdf0e10cSrcweir     sal_Int32                           m_nSelectionNestingLevel;
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir public:
237*cdf0e10cSrcweir     SelectionNotifier( ::osl::Mutex& _rMutex, ::cppu::OWeakObject& _rContext )
238*cdf0e10cSrcweir         :m_aSelectionListeners( _rMutex )
239*cdf0e10cSrcweir         ,m_rContext( _rContext )
240*cdf0e10cSrcweir         ,m_nSelectionNestingLevel( 0 )
241*cdf0e10cSrcweir     {
242*cdf0e10cSrcweir     }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir     void addListener( const Reference< XSelectionChangeListener >& _Listener )
245*cdf0e10cSrcweir     {
246*cdf0e10cSrcweir         m_aSelectionListeners.addInterface( _Listener );
247*cdf0e10cSrcweir     }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir     void removeListener( const Reference< XSelectionChangeListener >& _Listener )
250*cdf0e10cSrcweir     {
251*cdf0e10cSrcweir         m_aSelectionListeners.removeInterface( _Listener );
252*cdf0e10cSrcweir     }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir     void disposing()
255*cdf0e10cSrcweir     {
256*cdf0e10cSrcweir         EventObject aEvent( m_rContext );
257*cdf0e10cSrcweir         m_aSelectionListeners.disposeAndClear( aEvent );
258*cdf0e10cSrcweir     }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     ~SelectionNotifier()
261*cdf0e10cSrcweir     {
262*cdf0e10cSrcweir     }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     struct SelectionGuardAccess { friend class SelectionGuard; private: SelectionGuardAccess() { }  };
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir     /** enters a block which modifies the selection of our owner.
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir         Can be called multiple times, the only important thing is to call leaveSelection
269*cdf0e10cSrcweir         equally often.
270*cdf0e10cSrcweir     */
271*cdf0e10cSrcweir     void    enterSelection( SelectionGuardAccess )
272*cdf0e10cSrcweir     {
273*cdf0e10cSrcweir         ++m_nSelectionNestingLevel;
274*cdf0e10cSrcweir     }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir     /** leaves a block which modifies the selection of our owner
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir         Must be paired with enterSelection calls.
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir         When the last block is left, i.e. the last leaveSelection call is made on the current stack,
281*cdf0e10cSrcweir         then our SelectionChangeListeners are notified
282*cdf0e10cSrcweir     */
283*cdf0e10cSrcweir     void    leaveSelection( SelectionGuardAccess )
284*cdf0e10cSrcweir     {
285*cdf0e10cSrcweir         if ( --m_nSelectionNestingLevel == 0 )
286*cdf0e10cSrcweir         {
287*cdf0e10cSrcweir             EventObject aEvent( m_rContext );
288*cdf0e10cSrcweir             m_aSelectionListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aEvent );
289*cdf0e10cSrcweir         }
290*cdf0e10cSrcweir     }
291*cdf0e10cSrcweir };
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir class SelectionGuard : public ::boost::noncopyable
294*cdf0e10cSrcweir {
295*cdf0e10cSrcweir public:
296*cdf0e10cSrcweir     SelectionGuard( SelectionNotifier& _rNotifier )
297*cdf0e10cSrcweir         :m_rNotifier( _rNotifier )
298*cdf0e10cSrcweir     {
299*cdf0e10cSrcweir         m_rNotifier.enterSelection( SelectionNotifier::SelectionGuardAccess() );
300*cdf0e10cSrcweir     }
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir     ~SelectionGuard()
303*cdf0e10cSrcweir     {
304*cdf0e10cSrcweir         m_rNotifier.leaveSelection( SelectionNotifier::SelectionGuardAccess() );
305*cdf0e10cSrcweir     }
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir private:
308*cdf0e10cSrcweir     SelectionNotifier&  m_rNotifier;
309*cdf0e10cSrcweir };
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir //====================================================================
312*cdf0e10cSrcweir //= OApplicationController
313*cdf0e10cSrcweir //====================================================================
314*cdf0e10cSrcweir DBG_NAME(OApplicationController)
315*cdf0e10cSrcweir //--------------------------------------------------------------------
316*cdf0e10cSrcweir OApplicationController::OApplicationController(const Reference< XMultiServiceFactory >& _rxORB)
317*cdf0e10cSrcweir 	:OApplicationController_CBASE( _rxORB )
318*cdf0e10cSrcweir     ,m_aContextMenuInterceptors( getMutex() )
319*cdf0e10cSrcweir     ,m_pSubComponentManager( new SubComponentManager( *this, getSharedMutex() ) )
320*cdf0e10cSrcweir     ,m_aTypeCollection(_rxORB)
321*cdf0e10cSrcweir     ,m_aTableCopyHelper(this)
322*cdf0e10cSrcweir 	,m_pClipbordNotifier(NULL)
323*cdf0e10cSrcweir 	,m_nAsyncDrop(0)
324*cdf0e10cSrcweir     ,m_aControllerConnectedEvent( LINK( this, OApplicationController, OnFirstControllerConnected ) )
325*cdf0e10cSrcweir     ,m_aSelectContainerEvent( LINK( this, OApplicationController, OnSelectContainer ) )
326*cdf0e10cSrcweir 	,m_ePreviewMode(E_PREVIEWNONE)
327*cdf0e10cSrcweir 	,m_eCurrentType(E_NONE)
328*cdf0e10cSrcweir 	,m_bNeedToReconnect(sal_False)
329*cdf0e10cSrcweir     ,m_bSuspended( sal_False )
330*cdf0e10cSrcweir     ,m_pSelectionNotifier( new SelectionNotifier( getMutex(), *this ) )
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir     DBG_CTOR(OApplicationController,NULL);
333*cdf0e10cSrcweir }
334*cdf0e10cSrcweir //------------------------------------------------------------------------------
335*cdf0e10cSrcweir OApplicationController::~OApplicationController()
336*cdf0e10cSrcweir {
337*cdf0e10cSrcweir 	if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
338*cdf0e10cSrcweir 	{
339*cdf0e10cSrcweir 		OSL_ENSURE(0,"Please check who doesn't dispose this component!");
340*cdf0e10cSrcweir         // increment ref count to prevent double call of Dtor
341*cdf0e10cSrcweir         osl_incrementInterlockedCount( &m_refCount );
342*cdf0e10cSrcweir         dispose();
343*cdf0e10cSrcweir 	}
344*cdf0e10cSrcweir 	::std::auto_ptr< Window> aTemp( getView() );
345*cdf0e10cSrcweir     clearView();
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir     DBG_DTOR(OApplicationController,NULL);
348*cdf0e10cSrcweir }
349*cdf0e10cSrcweir //--------------------------------------------------------------------
350*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
351*cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
352*cdf0e10cSrcweir // -----------------------------------------------------------------------------
353*cdf0e10cSrcweir void OApplicationController::disconnect()
354*cdf0e10cSrcweir {
355*cdf0e10cSrcweir     if ( m_xDataSourceConnection.is() )
356*cdf0e10cSrcweir 	    stopConnectionListening( m_xDataSourceConnection );
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir     try
359*cdf0e10cSrcweir     {
360*cdf0e10cSrcweir         // temporary (hopefully!) hack for #i55274#
361*cdf0e10cSrcweir         Reference< XFlushable > xFlush( m_xDataSourceConnection, UNO_QUERY );
362*cdf0e10cSrcweir         if ( xFlush.is() && m_xMetaData.is() && !m_xMetaData->isReadOnly() )
363*cdf0e10cSrcweir             xFlush->flush();
364*cdf0e10cSrcweir     }
365*cdf0e10cSrcweir     catch( const Exception& )
366*cdf0e10cSrcweir     {
367*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
368*cdf0e10cSrcweir     }
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir     m_xDataSourceConnection.clear();
371*cdf0e10cSrcweir     m_xMetaData.clear();
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir 	InvalidateAll();
374*cdf0e10cSrcweir }
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir //--------------------------------------------------------------------
377*cdf0e10cSrcweir void SAL_CALL OApplicationController::disposing()
378*cdf0e10cSrcweir {
379*cdf0e10cSrcweir     m_aControllerConnectedEvent.CancelCall();
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 	::std::for_each(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),XContainerFunctor(this));
382*cdf0e10cSrcweir 	m_aCurrentContainers.clear();
383*cdf0e10cSrcweir     m_pSubComponentManager->disposing();
384*cdf0e10cSrcweir     m_pSelectionNotifier->disposing();
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 	if ( getView() )
387*cdf0e10cSrcweir 	{
388*cdf0e10cSrcweir 		getContainer()->showPreview(NULL);
389*cdf0e10cSrcweir 		m_pClipbordNotifier->ClearCallbackLink();
390*cdf0e10cSrcweir 		m_pClipbordNotifier->AddRemoveListener( getView(), sal_False );
391*cdf0e10cSrcweir 		m_pClipbordNotifier->release();
392*cdf0e10cSrcweir 		m_pClipbordNotifier = NULL;
393*cdf0e10cSrcweir 	}
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir 	disconnect();
396*cdf0e10cSrcweir 	try
397*cdf0e10cSrcweir 	{
398*cdf0e10cSrcweir 		Reference < XFrame > xFrame;
399*cdf0e10cSrcweir 		attachFrame( xFrame );
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir         if ( m_xDataSource.is() )
402*cdf0e10cSrcweir 		{
403*cdf0e10cSrcweir 		    m_xDataSource->removePropertyChangeListener(::rtl::OUString(), this);
404*cdf0e10cSrcweir             m_xDataSource->removePropertyChangeListener(PROPERTY_INFO, this);
405*cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_URL, this);
406*cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_ISPASSWORDREQUIRED, this);
407*cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_LAYOUTINFORMATION, this);
408*cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_SUPPRESSVERSIONCL, this);
409*cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_TABLEFILTER, this);
410*cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_TABLETYPEFILTER, this);
411*cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_USER, this);
412*cdf0e10cSrcweir 			// otherwise we may delete our datasource twice
413*cdf0e10cSrcweir 			Reference<XPropertySet> xProp = m_xDataSource;
414*cdf0e10cSrcweir 			m_xDataSource = NULL;
415*cdf0e10cSrcweir 		}
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 		Reference< XModifyBroadcaster > xBroadcaster( m_xModel, UNO_QUERY );
418*cdf0e10cSrcweir 		if ( xBroadcaster.is() )
419*cdf0e10cSrcweir 			xBroadcaster->removeModifyListener(static_cast<XModifyListener*>(this));
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir 		if ( m_xModel.is() )
422*cdf0e10cSrcweir 		{
423*cdf0e10cSrcweir 			::rtl::OUString sUrl = m_xModel->getURL();
424*cdf0e10cSrcweir 			if ( sUrl.getLength() )
425*cdf0e10cSrcweir 	    	{
426*cdf0e10cSrcweir                 ::comphelper::NamedValueCollection aArgs( m_xModel->getArgs() );
427*cdf0e10cSrcweir                 if ( true == aArgs.getOrDefault( "PickListEntry", true ) )
428*cdf0e10cSrcweir                 {
429*cdf0e10cSrcweir     				::rtl::OUString		aFilter;
430*cdf0e10cSrcweir     				INetURLObject		aURL( m_xModel->getURL() );
431*cdf0e10cSrcweir     				const SfxFilter* pFilter = getStandardDatabaseFilter();
432*cdf0e10cSrcweir     				if ( pFilter )
433*cdf0e10cSrcweir     					aFilter = pFilter->GetFilterName();
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir     				// add to svtool history options
436*cdf0e10cSrcweir     				SvtHistoryOptions().AppendItem( ePICKLIST,
437*cdf0e10cSrcweir     						aURL.GetURLNoPass( INetURLObject::NO_DECODE ),
438*cdf0e10cSrcweir     						aFilter,
439*cdf0e10cSrcweir     						getStrippedDatabaseName(),
440*cdf0e10cSrcweir     						::rtl::OUString() );
441*cdf0e10cSrcweir                 }
442*cdf0e10cSrcweir             }
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir             m_xModel->disconnectController( this );
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir             m_xModel.clear();
447*cdf0e10cSrcweir 		}
448*cdf0e10cSrcweir 	}
449*cdf0e10cSrcweir 	catch(Exception)
450*cdf0e10cSrcweir 	{
451*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
452*cdf0e10cSrcweir 	}
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir     clearView();
455*cdf0e10cSrcweir 	OApplicationController_CBASE::disposing(); // here the m_refCount must be equal 5
456*cdf0e10cSrcweir }
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir //--------------------------------------------------------------------
459*cdf0e10cSrcweir sal_Bool OApplicationController::Construct(Window* _pParent)
460*cdf0e10cSrcweir {
461*cdf0e10cSrcweir 	setView( * new OApplicationView( _pParent, getORB(), *this, m_ePreviewMode ) );
462*cdf0e10cSrcweir 	getView()->SetUniqueId(UID_APP_VIEW);
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir 	// late construction
465*cdf0e10cSrcweir 	sal_Bool bSuccess = sal_False;
466*cdf0e10cSrcweir 	try
467*cdf0e10cSrcweir 	{
468*cdf0e10cSrcweir 		getContainer()->Construct();
469*cdf0e10cSrcweir 		bSuccess = sal_True;
470*cdf0e10cSrcweir 	}
471*cdf0e10cSrcweir 	catch(SQLException&)
472*cdf0e10cSrcweir 	{
473*cdf0e10cSrcweir 	}
474*cdf0e10cSrcweir 	catch(Exception&)
475*cdf0e10cSrcweir 	{
476*cdf0e10cSrcweir 		DBG_ERROR("OApplicationController::Construct : the construction of UnoDataBrowserView failed !");
477*cdf0e10cSrcweir 	}
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir 	if ( !bSuccess )
480*cdf0e10cSrcweir 	{
481*cdf0e10cSrcweir 		::std::auto_ptr< Window> aTemp( getView() );
482*cdf0e10cSrcweir         clearView();
483*cdf0e10cSrcweir 		return sal_False;
484*cdf0e10cSrcweir 	}
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir 	// now that we have a view we can create the clipboard listener
487*cdf0e10cSrcweir 	m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( getView() );
488*cdf0e10cSrcweir 	m_aSystemClipboard.StartClipboardListening( );
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir 	m_pClipbordNotifier = new TransferableClipboardListener( LINK( this, OApplicationController, OnClipboardChanged ) );
491*cdf0e10cSrcweir 	m_pClipbordNotifier->acquire();
492*cdf0e10cSrcweir 	m_pClipbordNotifier->AddRemoveListener( getView(), sal_True );
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir 	OApplicationController_CBASE::Construct( _pParent );
495*cdf0e10cSrcweir 	getView()->Show();
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir 	return sal_True;
498*cdf0e10cSrcweir }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir //--------------------------------------------------------------------
501*cdf0e10cSrcweir void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) throw( RuntimeException )
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getMutex() );
504*cdf0e10cSrcweir 	Reference<XConnection> xCon(_rSource.Source, UNO_QUERY);
505*cdf0e10cSrcweir 	if ( xCon.is() )
506*cdf0e10cSrcweir 	{
507*cdf0e10cSrcweir         DBG_ASSERT( m_xDataSourceConnection == xCon,
508*cdf0e10cSrcweir             "OApplicationController::disposing: which connection does this come from?" );
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir         if ( getContainer() && getContainer()->getElementType() == E_TABLE )
511*cdf0e10cSrcweir             getContainer()->clearPages();
512*cdf0e10cSrcweir         if ( m_xDataSourceConnection == xCon )
513*cdf0e10cSrcweir         {
514*cdf0e10cSrcweir 			m_xMetaData.clear();
515*cdf0e10cSrcweir             m_xDataSourceConnection.clear();
516*cdf0e10cSrcweir 		}
517*cdf0e10cSrcweir 	}
518*cdf0e10cSrcweir 	else if ( _rSource.Source == m_xModel )
519*cdf0e10cSrcweir 	{
520*cdf0e10cSrcweir 		m_xModel.clear();
521*cdf0e10cSrcweir 	}
522*cdf0e10cSrcweir 	else if ( _rSource.Source == m_xDataSource )
523*cdf0e10cSrcweir 	{
524*cdf0e10cSrcweir 		m_xDataSource = NULL;
525*cdf0e10cSrcweir 	}
526*cdf0e10cSrcweir 	else
527*cdf0e10cSrcweir 	{
528*cdf0e10cSrcweir 		Reference<XContainer> xContainer( _rSource.Source, UNO_QUERY );
529*cdf0e10cSrcweir 		if ( xContainer.is() )
530*cdf0e10cSrcweir 		{
531*cdf0e10cSrcweir 			TContainerVector::iterator aFind = ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer);
532*cdf0e10cSrcweir 			if ( aFind != m_aCurrentContainers.end() )
533*cdf0e10cSrcweir 				m_aCurrentContainers.erase(aFind);
534*cdf0e10cSrcweir 		}
535*cdf0e10cSrcweir 		OApplicationController_CBASE::disposing( _rSource );
536*cdf0e10cSrcweir 	}
537*cdf0e10cSrcweir }
538*cdf0e10cSrcweir //--------------------------------------------------------------------
539*cdf0e10cSrcweir sal_Bool SAL_CALL OApplicationController::suspend(sal_Bool bSuspend) throw( RuntimeException )
540*cdf0e10cSrcweir {
541*cdf0e10cSrcweir     // notify the OnPrepareViewClosing event (before locking any mutex)
542*cdf0e10cSrcweir     Reference< XDocumentEventBroadcaster > xBroadcaster( m_xModel, UNO_QUERY );
543*cdf0e10cSrcweir     if ( xBroadcaster.is() )
544*cdf0e10cSrcweir     {
545*cdf0e10cSrcweir         xBroadcaster->notifyDocumentEvent(
546*cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnPrepareViewClosing" ) ),
547*cdf0e10cSrcweir             this,
548*cdf0e10cSrcweir             Any()
549*cdf0e10cSrcweir         );
550*cdf0e10cSrcweir     }
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
553*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getMutex() );
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir     if ( getView() && getView()->IsInModalMode() )
556*cdf0e10cSrcweir         return sal_False;
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir     sal_Bool bCanSuspend = sal_True;
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir     if ( m_bSuspended != bSuspend )
561*cdf0e10cSrcweir     {
562*cdf0e10cSrcweir 	    if ( bSuspend && !closeSubComponents() )
563*cdf0e10cSrcweir 		    return sal_False;
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir 	    Reference<XModifiable> xModi(m_xModel,UNO_QUERY);
566*cdf0e10cSrcweir         Reference<XStorable> xStor(getModel(),UNO_QUERY);
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir 	    if  (   bSuspend
569*cdf0e10cSrcweir             &&  xStor.is()
570*cdf0e10cSrcweir             &&  !xStor->isReadonly()
571*cdf0e10cSrcweir             &&  (   xModi.is()
572*cdf0e10cSrcweir                 &&  xModi->isModified()
573*cdf0e10cSrcweir                 )
574*cdf0e10cSrcweir             )
575*cdf0e10cSrcweir 	    {
576*cdf0e10cSrcweir 		    switch (ExecuteQuerySaveDocument(getView(),getStrippedDatabaseName()))
577*cdf0e10cSrcweir 		    {
578*cdf0e10cSrcweir 			    case RET_YES:
579*cdf0e10cSrcweir 				    Execute(ID_BROWSER_SAVEDOC,Sequence<PropertyValue>());
580*cdf0e10cSrcweir 				    bCanSuspend = !xModi->isModified();
581*cdf0e10cSrcweir                     // when we save the document this must be false else some press cancel
582*cdf0e10cSrcweir 				    break;
583*cdf0e10cSrcweir 			    case RET_CANCEL:
584*cdf0e10cSrcweir 				    bCanSuspend = sal_False;
585*cdf0e10cSrcweir 			    default:
586*cdf0e10cSrcweir 				    break;
587*cdf0e10cSrcweir 		    }
588*cdf0e10cSrcweir 	    }
589*cdf0e10cSrcweir     }
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir     if ( bCanSuspend )
592*cdf0e10cSrcweir 	    m_bSuspended = bSuspend;
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir 	return bCanSuspend;
595*cdf0e10cSrcweir }
596*cdf0e10cSrcweir // -----------------------------------------------------------------------------
597*cdf0e10cSrcweir FeatureState OApplicationController::GetState(sal_uInt16 _nId) const
598*cdf0e10cSrcweir {
599*cdf0e10cSrcweir 	FeatureState aReturn;
600*cdf0e10cSrcweir 	aReturn.bEnabled = sal_False;
601*cdf0e10cSrcweir 	// check this first
602*cdf0e10cSrcweir 	if ( !getContainer() || m_bReadOnly )
603*cdf0e10cSrcweir 		return aReturn;
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir 	try
606*cdf0e10cSrcweir 	{
607*cdf0e10cSrcweir 		switch (_nId)
608*cdf0e10cSrcweir 		{
609*cdf0e10cSrcweir             case SID_OPENURL:
610*cdf0e10cSrcweir                 aReturn.bEnabled = sal_True;
611*cdf0e10cSrcweir                 if ( m_xModel.is() )
612*cdf0e10cSrcweir 				    aReturn.sTitle = m_xModel->getURL();
613*cdf0e10cSrcweir                 break;
614*cdf0e10cSrcweir 			case ID_BROWSER_COPY:
615*cdf0e10cSrcweir 				{
616*cdf0e10cSrcweir 					sal_Int32 nCount = getContainer()->getSelectionCount();
617*cdf0e10cSrcweir 					aReturn.bEnabled = nCount >= 1;
618*cdf0e10cSrcweir 					if ( aReturn.bEnabled && nCount == 1 && getContainer()->getElementType() == E_TABLE )
619*cdf0e10cSrcweir 						aReturn.bEnabled = getContainer()->isALeafSelected();
620*cdf0e10cSrcweir 				}
621*cdf0e10cSrcweir 				break;
622*cdf0e10cSrcweir 			case ID_BROWSER_CUT:
623*cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() >= 1;
624*cdf0e10cSrcweir 				aReturn.bEnabled = aReturn.bEnabled && ( (ID_BROWSER_CUT == _nId && getContainer()->getElementType() == E_TABLE) ? getContainer()->isCutAllowed() : sal_True);
625*cdf0e10cSrcweir 				break;
626*cdf0e10cSrcweir 			case ID_BROWSER_PASTE:
627*cdf0e10cSrcweir 				switch( getContainer()->getElementType() )
628*cdf0e10cSrcweir 				{
629*cdf0e10cSrcweir 					case E_TABLE:
630*cdf0e10cSrcweir 						aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly() && isTableFormat();
631*cdf0e10cSrcweir 						break;
632*cdf0e10cSrcweir 					case E_QUERY:
633*cdf0e10cSrcweir 						aReturn.bEnabled = !isDataSourceReadOnly() && getViewClipboard().HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY);
634*cdf0e10cSrcweir 						break;
635*cdf0e10cSrcweir 					default:
636*cdf0e10cSrcweir 						aReturn.bEnabled = !isDataSourceReadOnly() && OComponentTransferable::canExtractComponentDescriptor(getViewClipboard().GetDataFlavorExVector(),getContainer()->getElementType() == E_FORM);
637*cdf0e10cSrcweir 				}
638*cdf0e10cSrcweir 				break;
639*cdf0e10cSrcweir 			case SID_DB_APP_PASTE_SPECIAL:
640*cdf0e10cSrcweir 				aReturn.bEnabled = getContainer()->getElementType() == E_TABLE && !isDataSourceReadOnly() && !isConnectionReadOnly() && isTableFormat();
641*cdf0e10cSrcweir 				break;
642*cdf0e10cSrcweir 			case SID_OPENDOC:
643*cdf0e10cSrcweir 			case SID_HELP_INDEX:
644*cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
645*cdf0e10cSrcweir 				break;
646*cdf0e10cSrcweir 			case ID_BROWSER_SAVEDOC:
647*cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly() && m_xDocumentModify.is() && m_xDocumentModify->isModified();
648*cdf0e10cSrcweir 				break;
649*cdf0e10cSrcweir 			case ID_BROWSER_SAVEASDOC:
650*cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
651*cdf0e10cSrcweir 				break;
652*cdf0e10cSrcweir 			case ID_BROWSER_SORTUP:
653*cdf0e10cSrcweir 				aReturn.bEnabled = getContainer()->isFilled() && getContainer()->getElementCount();
654*cdf0e10cSrcweir 				aReturn.bChecked = aReturn.bEnabled && getContainer()->isSortUp();
655*cdf0e10cSrcweir 				break;
656*cdf0e10cSrcweir 			case ID_BROWSER_SORTDOWN:
657*cdf0e10cSrcweir 				aReturn.bEnabled = getContainer()->isFilled() && getContainer()->getElementCount();
658*cdf0e10cSrcweir 				aReturn.bChecked = aReturn.bEnabled && !getContainer()->isSortUp();
659*cdf0e10cSrcweir 				break;
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir 			case SID_NEWDOC:
662*cdf0e10cSrcweir 			case SID_APP_NEW_FORM:
663*cdf0e10cSrcweir 			case ID_DOCUMENT_CREATE_REPWIZ:
664*cdf0e10cSrcweir                 aReturn.bEnabled = !isDataSourceReadOnly() && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER);
665*cdf0e10cSrcweir 				break;
666*cdf0e10cSrcweir 			case SID_APP_NEW_REPORT:
667*cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly()
668*cdf0e10cSrcweir                                     && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER);
669*cdf0e10cSrcweir                 if ( aReturn.bEnabled )
670*cdf0e10cSrcweir                 {
671*cdf0e10cSrcweir                     Reference< XContentEnumerationAccess > xEnumAccess(m_xServiceFactory, UNO_QUERY);
672*cdf0e10cSrcweir 					aReturn.bEnabled = xEnumAccess.is();
673*cdf0e10cSrcweir 	                if ( aReturn.bEnabled )
674*cdf0e10cSrcweir                     {
675*cdf0e10cSrcweir                         const ::rtl::OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_xServiceFactory);
676*cdf0e10cSrcweir                         aReturn.bEnabled = sReportEngineServiceName.getLength() != 0;
677*cdf0e10cSrcweir                         if ( aReturn.bEnabled )
678*cdf0e10cSrcweir                         {
679*cdf0e10cSrcweir                     	    const Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(sReportEngineServiceName);
680*cdf0e10cSrcweir                             aReturn.bEnabled = xEnumDrivers.is() && xEnumDrivers->hasMoreElements();
681*cdf0e10cSrcweir                         }
682*cdf0e10cSrcweir                     }
683*cdf0e10cSrcweir                 }
684*cdf0e10cSrcweir 				break;
685*cdf0e10cSrcweir 			case SID_DB_APP_VIEW_TABLES:
686*cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
687*cdf0e10cSrcweir 				aReturn.bChecked = getContainer()->getElementType() == E_TABLE;
688*cdf0e10cSrcweir 				break;
689*cdf0e10cSrcweir 			case SID_DB_APP_VIEW_QUERIES:
690*cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
691*cdf0e10cSrcweir 				aReturn.bChecked = getContainer()->getElementType() == E_QUERY;
692*cdf0e10cSrcweir 				break;
693*cdf0e10cSrcweir 			case SID_DB_APP_VIEW_FORMS:
694*cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
695*cdf0e10cSrcweir 				aReturn.bChecked = getContainer()->getElementType() == E_FORM;
696*cdf0e10cSrcweir 				break;
697*cdf0e10cSrcweir 			case SID_DB_APP_VIEW_REPORTS:
698*cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
699*cdf0e10cSrcweir 				aReturn.bChecked = getContainer()->getElementType() == E_REPORT;
700*cdf0e10cSrcweir 				break;
701*cdf0e10cSrcweir 			case ID_NEW_QUERY_DESIGN:
702*cdf0e10cSrcweir 			case ID_NEW_QUERY_SQL:
703*cdf0e10cSrcweir 			case ID_APP_NEW_QUERY_AUTO_PILOT:
704*cdf0e10cSrcweir 			case SID_DB_FORM_NEW_PILOT:
705*cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly();
706*cdf0e10cSrcweir 				break;
707*cdf0e10cSrcweir 			case ID_NEW_VIEW_DESIGN:
708*cdf0e10cSrcweir 			case SID_DB_NEW_VIEW_SQL:
709*cdf0e10cSrcweir 			case ID_NEW_VIEW_DESIGN_AUTO_PILOT:
710*cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly();
711*cdf0e10cSrcweir 				if ( aReturn.bEnabled )
712*cdf0e10cSrcweir 				{
713*cdf0e10cSrcweir 					Reference<XViewsSupplier> xViewsSup( getConnection(), UNO_QUERY );
714*cdf0e10cSrcweir 					aReturn.bEnabled = xViewsSup.is();
715*cdf0e10cSrcweir 				}
716*cdf0e10cSrcweir 				break;
717*cdf0e10cSrcweir 			case ID_NEW_TABLE_DESIGN:
718*cdf0e10cSrcweir 			case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
719*cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly();
720*cdf0e10cSrcweir 				break;
721*cdf0e10cSrcweir 			case ID_DIRECT_SQL:
722*cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
723*cdf0e10cSrcweir 				break;
724*cdf0e10cSrcweir             case ID_MIGRATE_SCRIPTS:
725*cdf0e10cSrcweir             {
726*cdf0e10cSrcweir                 // Our document supports embedding scripts into it, if and only if there are no
727*cdf0e10cSrcweir                 // forms/reports with macros/scripts into them. So, we need to enable migration
728*cdf0e10cSrcweir                 // if and only if the database document does *not* support embedding scripts.
729*cdf0e10cSrcweir                 bool bAvailable =
730*cdf0e10cSrcweir                         !Reference< XEmbeddedScripts >( m_xModel, UNO_QUERY ).is()
731*cdf0e10cSrcweir                     &&  !Reference< XStorable >( m_xModel, UNO_QUERY_THROW )->isReadonly();
732*cdf0e10cSrcweir                 aReturn.bEnabled = bAvailable;
733*cdf0e10cSrcweir                 if ( !bAvailable )
734*cdf0e10cSrcweir                     aReturn.bInvisible = true;
735*cdf0e10cSrcweir             }
736*cdf0e10cSrcweir             break;
737*cdf0e10cSrcweir 			case SID_APP_NEW_FOLDER:
738*cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() <= 1;
739*cdf0e10cSrcweir 				if ( aReturn.bEnabled )
740*cdf0e10cSrcweir 				{
741*cdf0e10cSrcweir 					const ElementType eType = getContainer()->getElementType();
742*cdf0e10cSrcweir 					aReturn.bEnabled = eType == E_REPORT || eType == E_FORM;
743*cdf0e10cSrcweir 				}
744*cdf0e10cSrcweir 				break;
745*cdf0e10cSrcweir 			case SID_FORM_CREATE_REPWIZ_PRE_SEL:
746*cdf0e10cSrcweir 			case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
747*cdf0e10cSrcweir             case SID_APP_NEW_REPORT_PRE_SEL:
748*cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly()
749*cdf0e10cSrcweir 									&& SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER)
750*cdf0e10cSrcweir 									&& getContainer()->isALeafSelected();
751*cdf0e10cSrcweir 				if ( aReturn.bEnabled )
752*cdf0e10cSrcweir 				{
753*cdf0e10cSrcweir 					ElementType eType = getContainer()->getElementType();
754*cdf0e10cSrcweir 					aReturn.bEnabled = eType == E_QUERY || eType == E_TABLE;
755*cdf0e10cSrcweir                     if ( aReturn.bEnabled && SID_APP_NEW_REPORT_PRE_SEL == _nId )
756*cdf0e10cSrcweir                     {
757*cdf0e10cSrcweir                         Reference< XContentEnumerationAccess > xEnumAccess(m_xServiceFactory, UNO_QUERY);
758*cdf0e10cSrcweir 					    aReturn.bEnabled = xEnumAccess.is();
759*cdf0e10cSrcweir 	                    if ( aReturn.bEnabled )
760*cdf0e10cSrcweir                         {
761*cdf0e10cSrcweir                             static ::rtl::OUString s_sReportDesign(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.pentaho.SOReportJobFactory"));
762*cdf0e10cSrcweir                     	    Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(s_sReportDesign);
763*cdf0e10cSrcweir                             aReturn.bEnabled = xEnumDrivers.is() && xEnumDrivers->hasMoreElements();
764*cdf0e10cSrcweir                         }
765*cdf0e10cSrcweir                     }
766*cdf0e10cSrcweir 				}
767*cdf0e10cSrcweir 				break;
768*cdf0e10cSrcweir 			case SID_DB_APP_DELETE:
769*cdf0e10cSrcweir 			case SID_DB_APP_RENAME:
770*cdf0e10cSrcweir 				aReturn.bEnabled = isRenameDeleteAllowed(getContainer()->getElementType(), _nId == SID_DB_APP_DELETE);
771*cdf0e10cSrcweir 				break;
772*cdf0e10cSrcweir 			case SID_DB_APP_TABLE_DELETE:
773*cdf0e10cSrcweir 			case SID_DB_APP_TABLE_RENAME:
774*cdf0e10cSrcweir 				aReturn.bEnabled = isRenameDeleteAllowed(E_TABLE, _nId == SID_DB_APP_TABLE_DELETE);
775*cdf0e10cSrcweir 				break;
776*cdf0e10cSrcweir 			case SID_DB_APP_QUERY_DELETE:
777*cdf0e10cSrcweir 			case SID_DB_APP_QUERY_RENAME:
778*cdf0e10cSrcweir 				aReturn.bEnabled = isRenameDeleteAllowed(E_QUERY, _nId == SID_DB_APP_QUERY_DELETE);
779*cdf0e10cSrcweir 				break;
780*cdf0e10cSrcweir 			case SID_DB_APP_FORM_DELETE:
781*cdf0e10cSrcweir 			case SID_DB_APP_FORM_RENAME:
782*cdf0e10cSrcweir 				aReturn.bEnabled = isRenameDeleteAllowed(E_FORM, _nId == SID_DB_APP_FORM_DELETE);
783*cdf0e10cSrcweir 				break;
784*cdf0e10cSrcweir 			case SID_DB_APP_REPORT_DELETE:
785*cdf0e10cSrcweir 			case SID_DB_APP_REPORT_RENAME:
786*cdf0e10cSrcweir 				aReturn.bEnabled = isRenameDeleteAllowed(E_REPORT, _nId == SID_DB_APP_REPORT_DELETE);
787*cdf0e10cSrcweir 				break;
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir 			case SID_SELECTALL:
790*cdf0e10cSrcweir 				aReturn.bEnabled = getContainer()->getElementCount() > 0 && getContainer()->getSelectionCount() != getContainer()->getElementCount();
791*cdf0e10cSrcweir 				break;
792*cdf0e10cSrcweir 			case SID_DB_APP_EDIT:
793*cdf0e10cSrcweir 			case SID_DB_APP_TABLE_EDIT:
794*cdf0e10cSrcweir 			case SID_DB_APP_QUERY_EDIT:
795*cdf0e10cSrcweir 			case SID_DB_APP_FORM_EDIT:
796*cdf0e10cSrcweir 			case SID_DB_APP_REPORT_EDIT:
797*cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() > 0
798*cdf0e10cSrcweir 									&& getContainer()->isALeafSelected();
799*cdf0e10cSrcweir 				break;
800*cdf0e10cSrcweir 			case SID_DB_APP_EDIT_SQL_VIEW:
801*cdf0e10cSrcweir                 if ( isDataSourceReadOnly() )
802*cdf0e10cSrcweir 				    aReturn.bEnabled = sal_False;
803*cdf0e10cSrcweir                 else
804*cdf0e10cSrcweir                 {
805*cdf0e10cSrcweir                     switch ( getContainer()->getElementType() )
806*cdf0e10cSrcweir                     {
807*cdf0e10cSrcweir                     case E_QUERY:
808*cdf0e10cSrcweir                         aReturn.bEnabled =  ( getContainer()->getSelectionCount() > 0 )
809*cdf0e10cSrcweir                                         &&  ( getContainer()->isALeafSelected() );
810*cdf0e10cSrcweir                         break;
811*cdf0e10cSrcweir                     case E_TABLE:
812*cdf0e10cSrcweir                         aReturn.bEnabled = sal_False;
813*cdf0e10cSrcweir                         // there's one exception: views which support altering their underlying
814*cdf0e10cSrcweir                         // command can be edited in SQL view, too
815*cdf0e10cSrcweir                         if  (   ( getContainer()->getSelectionCount() > 0 )
816*cdf0e10cSrcweir                             &&  ( getContainer()->isALeafSelected() )
817*cdf0e10cSrcweir                             )
818*cdf0e10cSrcweir                         {
819*cdf0e10cSrcweir 						    ::std::vector< ::rtl::OUString > aSelected;
820*cdf0e10cSrcweir 						    getSelectionElementNames( aSelected );
821*cdf0e10cSrcweir                             bool bAlterableViews = true;
822*cdf0e10cSrcweir                             for (   ::std::vector< ::rtl::OUString >::const_iterator selectedName = aSelected.begin();
823*cdf0e10cSrcweir                                     bAlterableViews && ( selectedName != aSelected.end() ) ;
824*cdf0e10cSrcweir                                     ++selectedName
825*cdf0e10cSrcweir                                 )
826*cdf0e10cSrcweir                             {
827*cdf0e10cSrcweir                                 bAlterableViews &= impl_isAlterableView_nothrow( *selectedName );
828*cdf0e10cSrcweir                             }
829*cdf0e10cSrcweir                             aReturn.bEnabled = bAlterableViews;
830*cdf0e10cSrcweir                         }
831*cdf0e10cSrcweir                         break;
832*cdf0e10cSrcweir                     default:
833*cdf0e10cSrcweir                         break;
834*cdf0e10cSrcweir                     }
835*cdf0e10cSrcweir                 }
836*cdf0e10cSrcweir                 break;
837*cdf0e10cSrcweir 			case SID_DB_APP_OPEN:
838*cdf0e10cSrcweir 			case SID_DB_APP_TABLE_OPEN:
839*cdf0e10cSrcweir 			case SID_DB_APP_QUERY_OPEN:
840*cdf0e10cSrcweir 			case SID_DB_APP_FORM_OPEN:
841*cdf0e10cSrcweir 			case SID_DB_APP_REPORT_OPEN:
842*cdf0e10cSrcweir 				aReturn.bEnabled = getContainer()->getSelectionCount() > 0 && getContainer()->isALeafSelected();
843*cdf0e10cSrcweir 				break;
844*cdf0e10cSrcweir 			case SID_DB_APP_DSUSERADMIN:
845*cdf0e10cSrcweir 				aReturn.bEnabled = !m_aTypeCollection.isEmbeddedDatabase(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
846*cdf0e10cSrcweir 			    break;
847*cdf0e10cSrcweir 			case SID_DB_APP_DSRELDESIGN:
848*cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
849*cdf0e10cSrcweir 				break;
850*cdf0e10cSrcweir 			case SID_DB_APP_TABLEFILTER:
851*cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly();
852*cdf0e10cSrcweir 				break;
853*cdf0e10cSrcweir 			case SID_DB_APP_REFRESH_TABLES:
854*cdf0e10cSrcweir 				aReturn.bEnabled = getContainer()->getElementType() == E_TABLE && isConnected();
855*cdf0e10cSrcweir 				break;
856*cdf0e10cSrcweir 			case SID_DB_APP_DSPROPS:
857*cdf0e10cSrcweir                 aReturn.bEnabled = m_xDataSource.is() && m_aTypeCollection.isShowPropertiesEnabled(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
858*cdf0e10cSrcweir 				break;
859*cdf0e10cSrcweir 			case SID_DB_APP_DSCONNECTION_TYPE:
860*cdf0e10cSrcweir                 aReturn.bEnabled = !isDataSourceReadOnly() && m_xDataSource.is() && !m_aTypeCollection.isEmbeddedDatabase(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
861*cdf0e10cSrcweir 				break;
862*cdf0e10cSrcweir 			case SID_DB_APP_DSADVANCED_SETTINGS:
863*cdf0e10cSrcweir                 aReturn.bEnabled = m_xDataSource.is() && AdvancedSettingsDialog::doesHaveAnyAdvancedSettings( m_aTypeCollection.getType(::comphelper::getString( m_xDataSource->getPropertyValue( PROPERTY_URL ) )) );
864*cdf0e10cSrcweir 				break;
865*cdf0e10cSrcweir 			case SID_DB_APP_CONVERTTOVIEW:
866*cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly();
867*cdf0e10cSrcweir 				if ( aReturn.bEnabled )
868*cdf0e10cSrcweir 				{
869*cdf0e10cSrcweir 					ElementType eType = getContainer()->getElementType();
870*cdf0e10cSrcweir 					aReturn.bEnabled = eType == E_QUERY && getContainer()->getSelectionCount() > 0;
871*cdf0e10cSrcweir 					if ( aReturn.bEnabled )
872*cdf0e10cSrcweir 					{
873*cdf0e10cSrcweir 						Reference<XViewsSupplier> xViewSup( getConnection(), UNO_QUERY );
874*cdf0e10cSrcweir 						aReturn.bEnabled = xViewSup.is() && Reference<XAppend>(xViewSup->getViews(),UNO_QUERY).is();
875*cdf0e10cSrcweir 					}
876*cdf0e10cSrcweir 				}
877*cdf0e10cSrcweir 				break;
878*cdf0e10cSrcweir 			case SID_DB_APP_DISABLE_PREVIEW:
879*cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
880*cdf0e10cSrcweir 				aReturn.bChecked = getContainer()->getPreviewMode() == E_PREVIEWNONE;
881*cdf0e10cSrcweir 				break;
882*cdf0e10cSrcweir 			case SID_DB_APP_VIEW_DOCINFO_PREVIEW:
883*cdf0e10cSrcweir 				{
884*cdf0e10cSrcweir 					ElementType eType = getContainer()->getElementType();
885*cdf0e10cSrcweir 					aReturn.bEnabled = (E_REPORT == eType || E_FORM == eType);
886*cdf0e10cSrcweir 					aReturn.bChecked = getContainer()->getPreviewMode() == E_DOCUMENTINFO;
887*cdf0e10cSrcweir 				}
888*cdf0e10cSrcweir 				break;
889*cdf0e10cSrcweir 			case SID_DB_APP_VIEW_DOC_PREVIEW:
890*cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
891*cdf0e10cSrcweir 				aReturn.bChecked = getContainer()->getPreviewMode() == E_DOCUMENT;
892*cdf0e10cSrcweir 				break;
893*cdf0e10cSrcweir             case ID_BROWSER_UNDO:
894*cdf0e10cSrcweir                 aReturn.bEnabled = sal_False;
895*cdf0e10cSrcweir                 break;
896*cdf0e10cSrcweir 			case SID_MAIL_SENDDOC:
897*cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
898*cdf0e10cSrcweir 				break;
899*cdf0e10cSrcweir 			case SID_DB_APP_SENDREPORTASMAIL:
900*cdf0e10cSrcweir 				{
901*cdf0e10cSrcweir 					ElementType eType = getContainer()->getElementType();
902*cdf0e10cSrcweir 					aReturn.bEnabled = E_REPORT == eType && getContainer()->getSelectionCount() > 0 && getContainer()->isALeafSelected();
903*cdf0e10cSrcweir 				}
904*cdf0e10cSrcweir 				break;
905*cdf0e10cSrcweir 			case SID_DB_APP_SENDREPORTTOWRITER:
906*cdf0e10cSrcweir 			case SID_DB_APP_DBADMIN:
907*cdf0e10cSrcweir 				aReturn.bEnabled = sal_False;
908*cdf0e10cSrcweir 				break;
909*cdf0e10cSrcweir 			case SID_DB_APP_STATUS_TYPE:
910*cdf0e10cSrcweir                 aReturn.bEnabled = m_xDataSource.is();
911*cdf0e10cSrcweir 				if ( aReturn.bEnabled )
912*cdf0e10cSrcweir 				{
913*cdf0e10cSrcweir                     ::rtl::OUString sURL;
914*cdf0e10cSrcweir                     m_xDataSource->getPropertyValue(PROPERTY_URL) >>= sURL;
915*cdf0e10cSrcweir                     ::rtl::OUString sDSTypeName;
916*cdf0e10cSrcweir                     if ( m_aTypeCollection.isEmbeddedDatabase( sURL ) )
917*cdf0e10cSrcweir                     {
918*cdf0e10cSrcweir                         sDSTypeName = String( ModuleRes( RID_STR_EMBEDDED_DATABASE ) );
919*cdf0e10cSrcweir                     }
920*cdf0e10cSrcweir                     else
921*cdf0e10cSrcweir                     {
922*cdf0e10cSrcweir 					    sDSTypeName = m_aTypeCollection.getTypeDisplayName(sURL);
923*cdf0e10cSrcweir                     }
924*cdf0e10cSrcweir 				    aReturn.sTitle = sDSTypeName;
925*cdf0e10cSrcweir 				}
926*cdf0e10cSrcweir 				break;
927*cdf0e10cSrcweir 			case SID_DB_APP_STATUS_DBNAME:
928*cdf0e10cSrcweir 				aReturn.bEnabled = m_xDataSource.is();
929*cdf0e10cSrcweir 				if ( aReturn.bEnabled )
930*cdf0e10cSrcweir 				{
931*cdf0e10cSrcweir 					::rtl::OUString sURL;
932*cdf0e10cSrcweir 					m_xDataSource->getPropertyValue(PROPERTY_URL) >>= sURL;
933*cdf0e10cSrcweir                     String sDatabaseName;
934*cdf0e10cSrcweir 					String sHostName;
935*cdf0e10cSrcweir 					sal_Int32 nPortNumber( -1 );
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir 					m_aTypeCollection.extractHostNamePort( sURL, sDatabaseName, sHostName, nPortNumber );
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir                     if ( !sDatabaseName.Len() )
940*cdf0e10cSrcweir 						sDatabaseName = m_aTypeCollection.cutPrefix( sURL );
941*cdf0e10cSrcweir 					if ( m_aTypeCollection.isFileSystemBased(sURL) )
942*cdf0e10cSrcweir 					{
943*cdf0e10cSrcweir 						sDatabaseName = SvtPathOptions().SubstituteVariable( sDatabaseName );
944*cdf0e10cSrcweir 						if ( sDatabaseName.Len() )
945*cdf0e10cSrcweir 						{
946*cdf0e10cSrcweir 							::svt::OFileNotation aFileNotation(sDatabaseName);
947*cdf0e10cSrcweir 							// set this decoded URL as text
948*cdf0e10cSrcweir 							sDatabaseName = aFileNotation.get(::svt::OFileNotation::N_SYSTEM);
949*cdf0e10cSrcweir 						}
950*cdf0e10cSrcweir 					}
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir                     if ( sDatabaseName.Len() == 0 )
953*cdf0e10cSrcweir                         sDatabaseName = m_aTypeCollection.getTypeDisplayName( sURL );
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir                     aReturn.sTitle = sDatabaseName;
956*cdf0e10cSrcweir 				}
957*cdf0e10cSrcweir 				break;
958*cdf0e10cSrcweir 			case SID_DB_APP_STATUS_USERNAME:
959*cdf0e10cSrcweir 				aReturn.bEnabled = m_xDataSource.is();
960*cdf0e10cSrcweir 				if ( aReturn.bEnabled )
961*cdf0e10cSrcweir                     m_xDataSource->getPropertyValue( PROPERTY_USER ) >>= aReturn.sTitle;
962*cdf0e10cSrcweir 				break;
963*cdf0e10cSrcweir 			case SID_DB_APP_STATUS_HOSTNAME:
964*cdf0e10cSrcweir 				aReturn.bEnabled = m_xDataSource.is();
965*cdf0e10cSrcweir 				if ( aReturn.bEnabled )
966*cdf0e10cSrcweir 				{
967*cdf0e10cSrcweir 					::rtl::OUString sURL;
968*cdf0e10cSrcweir 					m_xDataSource->getPropertyValue( PROPERTY_URL ) >>= sURL;
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir 					String sHostName, sDatabaseName;
971*cdf0e10cSrcweir 					sal_Int32 nPortNumber = -1;
972*cdf0e10cSrcweir 					m_aTypeCollection.extractHostNamePort( sURL, sDatabaseName, sHostName, nPortNumber );
973*cdf0e10cSrcweir 					aReturn.sTitle = sHostName;
974*cdf0e10cSrcweir 				}
975*cdf0e10cSrcweir 				break;
976*cdf0e10cSrcweir 			default:
977*cdf0e10cSrcweir 				aReturn = OApplicationController_CBASE::GetState(_nId);
978*cdf0e10cSrcweir 		}
979*cdf0e10cSrcweir 	}
980*cdf0e10cSrcweir 	catch(const Exception& )
981*cdf0e10cSrcweir 	{
982*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
983*cdf0e10cSrcweir 	}
984*cdf0e10cSrcweir 	return aReturn;
985*cdf0e10cSrcweir }
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir // -----------------------------------------------------------------------------
988*cdf0e10cSrcweir namespace
989*cdf0e10cSrcweir {
990*cdf0e10cSrcweir     bool lcl_handleException_nothrow( const Reference< XModel >& _rxDocument, const Any& _rException )
991*cdf0e10cSrcweir     {
992*cdf0e10cSrcweir         bool bHandled = false;
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir         // try handling the error with an interaction handler
995*cdf0e10cSrcweir         ::comphelper::NamedValueCollection aArgs( _rxDocument->getArgs() );
996*cdf0e10cSrcweir         Reference< XInteractionHandler > xHandler( aArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) );
997*cdf0e10cSrcweir         if ( xHandler.is() )
998*cdf0e10cSrcweir         {
999*cdf0e10cSrcweir             ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( _rException ) );
1000*cdf0e10cSrcweir             ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
1001*cdf0e10cSrcweir             pRequest->addContinuation( pApprove.get() );
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir             try
1004*cdf0e10cSrcweir             {
1005*cdf0e10cSrcweir                 xHandler->handle( pRequest.get() );
1006*cdf0e10cSrcweir             }
1007*cdf0e10cSrcweir             catch( const Exception& )
1008*cdf0e10cSrcweir             {
1009*cdf0e10cSrcweir                 DBG_UNHANDLED_EXCEPTION();
1010*cdf0e10cSrcweir             }
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir             bHandled = pApprove->wasSelected();
1013*cdf0e10cSrcweir         }
1014*cdf0e10cSrcweir         return bHandled;
1015*cdf0e10cSrcweir     }
1016*cdf0e10cSrcweir }
1017*cdf0e10cSrcweir 
1018*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1019*cdf0e10cSrcweir void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
1020*cdf0e10cSrcweir {
1021*cdf0e10cSrcweir 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1022*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
1023*cdf0e10cSrcweir 
1024*cdf0e10cSrcweir     if ( isUserDefinedFeature( _nId ) )
1025*cdf0e10cSrcweir     {
1026*cdf0e10cSrcweir         OApplicationController_CBASE::Execute( _nId, aArgs );
1027*cdf0e10cSrcweir         return;
1028*cdf0e10cSrcweir     }
1029*cdf0e10cSrcweir 
1030*cdf0e10cSrcweir 	if ( !getContainer() || m_bReadOnly )
1031*cdf0e10cSrcweir 		return; // return without execution
1032*cdf0e10cSrcweir 
1033*cdf0e10cSrcweir 	try
1034*cdf0e10cSrcweir 	{
1035*cdf0e10cSrcweir 		switch(_nId)
1036*cdf0e10cSrcweir 		{
1037*cdf0e10cSrcweir 			case ID_BROWSER_CUT:
1038*cdf0e10cSrcweir 				getContainer()->cut();
1039*cdf0e10cSrcweir 				break;
1040*cdf0e10cSrcweir 			case ID_BROWSER_COPY:
1041*cdf0e10cSrcweir 				{
1042*cdf0e10cSrcweir 					TransferableHelper* pTransfer = copyObject( );
1043*cdf0e10cSrcweir 					Reference< XTransferable> aEnsureDelete = pTransfer;
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir 					if ( pTransfer )
1046*cdf0e10cSrcweir 						pTransfer->CopyToClipboard(getView());
1047*cdf0e10cSrcweir 				}
1048*cdf0e10cSrcweir 				break;
1049*cdf0e10cSrcweir 			case ID_BROWSER_PASTE:
1050*cdf0e10cSrcweir 				{
1051*cdf0e10cSrcweir 					const TransferableDataHelper& rTransferData( getViewClipboard() );
1052*cdf0e10cSrcweir 					ElementType eType = getContainer()->getElementType();
1053*cdf0e10cSrcweir 
1054*cdf0e10cSrcweir 					switch( eType )
1055*cdf0e10cSrcweir 					{
1056*cdf0e10cSrcweir 						case E_TABLE:
1057*cdf0e10cSrcweir 							{
1058*cdf0e10cSrcweir 								// get the selected tablename
1059*cdf0e10cSrcweir 								::std::vector< ::rtl::OUString > aList;
1060*cdf0e10cSrcweir 								getSelectionElementNames( aList );
1061*cdf0e10cSrcweir 								if ( !aList.empty() )
1062*cdf0e10cSrcweir 									m_aTableCopyHelper.SetTableNameForAppend( *aList.begin() );
1063*cdf0e10cSrcweir                                 else
1064*cdf0e10cSrcweir                                     m_aTableCopyHelper.ResetTableNameForAppend();
1065*cdf0e10cSrcweir 
1066*cdf0e10cSrcweir 								m_aTableCopyHelper.pasteTable( rTransferData , getDatabaseName(), ensureConnection() );
1067*cdf0e10cSrcweir 							}
1068*cdf0e10cSrcweir 							break;
1069*cdf0e10cSrcweir 
1070*cdf0e10cSrcweir 						case E_QUERY:
1071*cdf0e10cSrcweir                             if ( rTransferData.HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY) )
1072*cdf0e10cSrcweir 							    paste( E_QUERY, ODataAccessObjectTransferable::extractObjectDescriptor( rTransferData ) );
1073*cdf0e10cSrcweir 							break;
1074*cdf0e10cSrcweir 						default:
1075*cdf0e10cSrcweir 							{
1076*cdf0e10cSrcweir 								::std::vector< ::rtl::OUString> aList;
1077*cdf0e10cSrcweir 								getSelectionElementNames(aList);
1078*cdf0e10cSrcweir 								::rtl::OUString sFolderNameToInsertInto;
1079*cdf0e10cSrcweir 								if ( !aList.empty() )
1080*cdf0e10cSrcweir 								{
1081*cdf0e10cSrcweir 									Reference< XHierarchicalNameAccess > xContainer(getElements(eType),UNO_QUERY);
1082*cdf0e10cSrcweir 									if ( xContainer.is()
1083*cdf0e10cSrcweir 										&& xContainer->hasByHierarchicalName(*aList.begin())
1084*cdf0e10cSrcweir 										&& (xContainer->getByHierarchicalName(*aList.begin()) >>= xContainer)
1085*cdf0e10cSrcweir 										&& xContainer.is()
1086*cdf0e10cSrcweir 										)
1087*cdf0e10cSrcweir 										sFolderNameToInsertInto = *aList.begin();
1088*cdf0e10cSrcweir 								}
1089*cdf0e10cSrcweir 								paste( eType, OComponentTransferable::extractComponentDescriptor( rTransferData ),
1090*cdf0e10cSrcweir                                     sFolderNameToInsertInto );
1091*cdf0e10cSrcweir 							}
1092*cdf0e10cSrcweir 							break;
1093*cdf0e10cSrcweir 					}
1094*cdf0e10cSrcweir 				}
1095*cdf0e10cSrcweir 				break;
1096*cdf0e10cSrcweir 			case SID_DB_APP_PASTE_SPECIAL:
1097*cdf0e10cSrcweir 				{
1098*cdf0e10cSrcweir 					if ( !aArgs.getLength() )
1099*cdf0e10cSrcweir 					{
1100*cdf0e10cSrcweir                         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1101*cdf0e10cSrcweir                         ::std::auto_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( getView() ));
1102*cdf0e10cSrcweir 						::std::vector<SotFormatStringId> aFormatIds;
1103*cdf0e10cSrcweir 						getSupportedFormats(getContainer()->getElementType(),aFormatIds);
1104*cdf0e10cSrcweir 						const ::std::vector<SotFormatStringId>::iterator aEnd = aFormatIds.end();
1105*cdf0e10cSrcweir                         ::rtl::OUString sEmpty;
1106*cdf0e10cSrcweir 						for (::std::vector<SotFormatStringId>::iterator aIter = aFormatIds.begin();aIter != aEnd; ++aIter)
1107*cdf0e10cSrcweir 							pDlg->Insert(*aIter,sEmpty);
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir 						const TransferableDataHelper& rClipboard = getViewClipboard();
1110*cdf0e10cSrcweir 						pasteFormat(pDlg->GetFormat(rClipboard.GetTransferable()));
1111*cdf0e10cSrcweir 					}
1112*cdf0e10cSrcweir 					else
1113*cdf0e10cSrcweir 					{
1114*cdf0e10cSrcweir 						const PropertyValue* pIter = aArgs.getConstArray();
1115*cdf0e10cSrcweir 						const PropertyValue* pEnd  = pIter + aArgs.getLength();
1116*cdf0e10cSrcweir 						for( ; pIter != pEnd ; ++pIter)
1117*cdf0e10cSrcweir 						{
1118*cdf0e10cSrcweir 							if ( pIter->Name.equalsAscii("FormatStringId") )
1119*cdf0e10cSrcweir 							{
1120*cdf0e10cSrcweir 								SotFormatStringId nFormatId = 0;
1121*cdf0e10cSrcweir 								if ( pIter->Value >>= nFormatId )
1122*cdf0e10cSrcweir 									pasteFormat(nFormatId);
1123*cdf0e10cSrcweir 								break;
1124*cdf0e10cSrcweir 							}
1125*cdf0e10cSrcweir 						}
1126*cdf0e10cSrcweir 					}
1127*cdf0e10cSrcweir 				}
1128*cdf0e10cSrcweir 				break;
1129*cdf0e10cSrcweir 			case SID_OPENDOC:
1130*cdf0e10cSrcweir 			case SID_HELP_INDEX:
1131*cdf0e10cSrcweir 				{
1132*cdf0e10cSrcweir 					Reference < XDispatchProvider > xProv( getFrame(), UNO_QUERY );
1133*cdf0e10cSrcweir 					if ( xProv.is() )
1134*cdf0e10cSrcweir 					{
1135*cdf0e10cSrcweir 						URL aURL;
1136*cdf0e10cSrcweir 						switch(_nId)
1137*cdf0e10cSrcweir 						{
1138*cdf0e10cSrcweir 							case SID_HELP_INDEX:
1139*cdf0e10cSrcweir 								aURL.Complete = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:HelpIndex"));
1140*cdf0e10cSrcweir 								break;
1141*cdf0e10cSrcweir 							case SID_OPENDOC:
1142*cdf0e10cSrcweir 								aURL.Complete = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Open"));
1143*cdf0e10cSrcweir 								break;
1144*cdf0e10cSrcweir 						}
1145*cdf0e10cSrcweir 
1146*cdf0e10cSrcweir 						if ( m_xUrlTransformer.is() )
1147*cdf0e10cSrcweir 							m_xUrlTransformer->parseStrict( aURL );
1148*cdf0e10cSrcweir 						Reference < XDispatch > xDisp = xProv->queryDispatch( aURL, String(), 0 );
1149*cdf0e10cSrcweir             			if ( xDisp.is() )
1150*cdf0e10cSrcweir                 			xDisp->dispatch( aURL, Sequence < PropertyValue >() );
1151*cdf0e10cSrcweir 					}
1152*cdf0e10cSrcweir 				}
1153*cdf0e10cSrcweir 				break;
1154*cdf0e10cSrcweir 			case ID_BROWSER_SAVEDOC:
1155*cdf0e10cSrcweir 				{
1156*cdf0e10cSrcweir 					Reference< XStorable > xStore( m_xModel, UNO_QUERY_THROW );
1157*cdf0e10cSrcweir                     try
1158*cdf0e10cSrcweir                     {
1159*cdf0e10cSrcweir                         xStore->store();
1160*cdf0e10cSrcweir                     }
1161*cdf0e10cSrcweir                     catch( const Exception& )
1162*cdf0e10cSrcweir                     {
1163*cdf0e10cSrcweir                         lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() );
1164*cdf0e10cSrcweir                     }
1165*cdf0e10cSrcweir 				}
1166*cdf0e10cSrcweir 				break;
1167*cdf0e10cSrcweir 
1168*cdf0e10cSrcweir             case ID_BROWSER_SAVEASDOC:
1169*cdf0e10cSrcweir 				{
1170*cdf0e10cSrcweir 					WinBits nBits(WB_STDMODAL|WB_SAVEAS);
1171*cdf0e10cSrcweir                     ::rtl::OUString sUrl;
1172*cdf0e10cSrcweir 			        if ( m_xModel.is() )
1173*cdf0e10cSrcweir 				        sUrl = m_xModel->getURL();
1174*cdf0e10cSrcweir 			        if ( !sUrl.getLength() )
1175*cdf0e10cSrcweir                         sUrl = SvtPathOptions().GetWorkPath();
1176*cdf0e10cSrcweir 
1177*cdf0e10cSrcweir 					::sfx2::FileDialogHelper aFileDlg( com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,static_cast<sal_uInt32>(nBits) ,getView());
1178*cdf0e10cSrcweir 					aFileDlg.SetDisplayDirectory( sUrl );
1179*cdf0e10cSrcweir 
1180*cdf0e10cSrcweir 					const SfxFilter* pFilter = getStandardDatabaseFilter();
1181*cdf0e10cSrcweir 					if ( pFilter )
1182*cdf0e10cSrcweir 					{
1183*cdf0e10cSrcweir 						aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
1184*cdf0e10cSrcweir 						aFileDlg.SetCurrentFilter(pFilter->GetUIName());
1185*cdf0e10cSrcweir 					}
1186*cdf0e10cSrcweir 
1187*cdf0e10cSrcweir 					if ( aFileDlg.Execute() != ERRCODE_NONE )
1188*cdf0e10cSrcweir                         break;
1189*cdf0e10cSrcweir 
1190*cdf0e10cSrcweir                     Reference<XStorable> xStore( m_xModel, UNO_QUERY_THROW );
1191*cdf0e10cSrcweir 					INetURLObject aURL( aFileDlg.GetPath() );
1192*cdf0e10cSrcweir                     try
1193*cdf0e10cSrcweir                     {
1194*cdf0e10cSrcweir                         xStore->storeAsURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), Sequence< PropertyValue >() );
1195*cdf0e10cSrcweir                     }
1196*cdf0e10cSrcweir                     catch( const Exception& )
1197*cdf0e10cSrcweir                     {
1198*cdf0e10cSrcweir                         lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() );
1199*cdf0e10cSrcweir                     }
1200*cdf0e10cSrcweir 
1201*cdf0e10cSrcweir 					/*updateTitle();*/
1202*cdf0e10cSrcweir 					m_bCurrentlyModified = sal_False;
1203*cdf0e10cSrcweir 					InvalidateFeature(ID_BROWSER_SAVEDOC);
1204*cdf0e10cSrcweir                     if ( getContainer()->getElementType() == E_NONE )
1205*cdf0e10cSrcweir                     {
1206*cdf0e10cSrcweir                         getContainer()->selectContainer(E_NONE);
1207*cdf0e10cSrcweir                         getContainer()->selectContainer(E_TABLE);
1208*cdf0e10cSrcweir                         // #i95524#
1209*cdf0e10cSrcweir                         getContainer()->Invalidate();
1210*cdf0e10cSrcweir                         refreshTables();
1211*cdf0e10cSrcweir                     }
1212*cdf0e10cSrcweir 
1213*cdf0e10cSrcweir 				}
1214*cdf0e10cSrcweir 				break;
1215*cdf0e10cSrcweir 			case ID_BROWSER_SORTUP:
1216*cdf0e10cSrcweir 				getContainer()->sortUp();
1217*cdf0e10cSrcweir 				InvalidateFeature(ID_BROWSER_SORTDOWN);
1218*cdf0e10cSrcweir 				break;
1219*cdf0e10cSrcweir 			case ID_BROWSER_SORTDOWN:
1220*cdf0e10cSrcweir 				getContainer()->sortDown();
1221*cdf0e10cSrcweir 				InvalidateFeature(ID_BROWSER_SORTUP);
1222*cdf0e10cSrcweir 				break;
1223*cdf0e10cSrcweir 
1224*cdf0e10cSrcweir 			case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
1225*cdf0e10cSrcweir 			case ID_NEW_VIEW_DESIGN_AUTO_PILOT:
1226*cdf0e10cSrcweir 			case ID_APP_NEW_QUERY_AUTO_PILOT:
1227*cdf0e10cSrcweir 			case SID_DB_FORM_NEW_PILOT:
1228*cdf0e10cSrcweir 			case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
1229*cdf0e10cSrcweir             case SID_APP_NEW_REPORT_PRE_SEL:
1230*cdf0e10cSrcweir 			case SID_FORM_CREATE_REPWIZ_PRE_SEL:
1231*cdf0e10cSrcweir 			case ID_DOCUMENT_CREATE_REPWIZ:
1232*cdf0e10cSrcweir 			case SID_APP_NEW_FORM:
1233*cdf0e10cSrcweir 			case SID_APP_NEW_REPORT:
1234*cdf0e10cSrcweir 			case ID_NEW_QUERY_SQL:
1235*cdf0e10cSrcweir 			case ID_NEW_QUERY_DESIGN:
1236*cdf0e10cSrcweir 			case ID_NEW_TABLE_DESIGN:
1237*cdf0e10cSrcweir 				{
1238*cdf0e10cSrcweir 					ElementType eType = E_TABLE;
1239*cdf0e10cSrcweir 					sal_Bool bAutoPilot = sal_False;
1240*cdf0e10cSrcweir                     ::comphelper::NamedValueCollection aCreationArgs;
1241*cdf0e10cSrcweir 
1242*cdf0e10cSrcweir 					switch( _nId )
1243*cdf0e10cSrcweir 					{
1244*cdf0e10cSrcweir 						case SID_DB_FORM_NEW_PILOT:
1245*cdf0e10cSrcweir 						case SID_FORM_CREATE_REPWIZ_PRE_SEL:
1246*cdf0e10cSrcweir 							bAutoPilot = sal_True;
1247*cdf0e10cSrcweir 							// run through
1248*cdf0e10cSrcweir 						case SID_APP_NEW_FORM:
1249*cdf0e10cSrcweir 							eType = E_FORM;
1250*cdf0e10cSrcweir 							break;
1251*cdf0e10cSrcweir 						case ID_DOCUMENT_CREATE_REPWIZ:
1252*cdf0e10cSrcweir 						case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
1253*cdf0e10cSrcweir 							bAutoPilot = sal_True;
1254*cdf0e10cSrcweir 							// run through
1255*cdf0e10cSrcweir 						case SID_APP_NEW_REPORT:
1256*cdf0e10cSrcweir                         case SID_APP_NEW_REPORT_PRE_SEL:
1257*cdf0e10cSrcweir 							eType = E_REPORT;
1258*cdf0e10cSrcweir 							break;
1259*cdf0e10cSrcweir 						case ID_APP_NEW_QUERY_AUTO_PILOT:
1260*cdf0e10cSrcweir 							bAutoPilot = sal_True;
1261*cdf0e10cSrcweir 							eType = E_QUERY;
1262*cdf0e10cSrcweir 							break;
1263*cdf0e10cSrcweir 						case ID_NEW_QUERY_DESIGN:
1264*cdf0e10cSrcweir                             aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, sal_True );
1265*cdf0e10cSrcweir 							// run through
1266*cdf0e10cSrcweir 						case ID_NEW_QUERY_SQL:
1267*cdf0e10cSrcweir 							eType = E_QUERY;
1268*cdf0e10cSrcweir 							break;
1269*cdf0e10cSrcweir  						case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
1270*cdf0e10cSrcweir  							bAutoPilot = sal_True;
1271*cdf0e10cSrcweir  							// run through
1272*cdf0e10cSrcweir 						case ID_NEW_TABLE_DESIGN:
1273*cdf0e10cSrcweir 							break;
1274*cdf0e10cSrcweir 						default:
1275*cdf0e10cSrcweir 							OSL_ENSURE(0,"illegal switch call!");
1276*cdf0e10cSrcweir 					}
1277*cdf0e10cSrcweir                     if ( bAutoPilot )
1278*cdf0e10cSrcweir                         getContainer()->PostUserEvent( LINK( this, OApplicationController, OnCreateWithPilot ), reinterpret_cast< void* >( eType ) );
1279*cdf0e10cSrcweir                     else
1280*cdf0e10cSrcweir                     {
1281*cdf0e10cSrcweir                         Reference< XComponent > xDocDefinition;
1282*cdf0e10cSrcweir 					    newElement( eType, aCreationArgs, xDocDefinition );
1283*cdf0e10cSrcweir                     }
1284*cdf0e10cSrcweir 				}
1285*cdf0e10cSrcweir 				break;
1286*cdf0e10cSrcweir 			case SID_APP_NEW_FOLDER:
1287*cdf0e10cSrcweir 				{
1288*cdf0e10cSrcweir 					ElementType eType = getContainer()->getElementType();
1289*cdf0e10cSrcweir 					::rtl::OUString sName = getContainer()->getQualifiedName( NULL );
1290*cdf0e10cSrcweir 					insertHierachyElement(eType,sName);
1291*cdf0e10cSrcweir 				}
1292*cdf0e10cSrcweir 				break;
1293*cdf0e10cSrcweir 			case ID_NEW_VIEW_DESIGN:
1294*cdf0e10cSrcweir 			case SID_DB_NEW_VIEW_SQL:
1295*cdf0e10cSrcweir 				{
1296*cdf0e10cSrcweir                     SharedConnection xConnection( ensureConnection() );
1297*cdf0e10cSrcweir 					if ( xConnection.is() )
1298*cdf0e10cSrcweir 					{
1299*cdf0e10cSrcweir 						QueryDesigner aDesigner( getORB(), this, getFrame(), true );
1300*cdf0e10cSrcweir 
1301*cdf0e10cSrcweir                         ::comphelper::NamedValueCollection aCreationArgs;
1302*cdf0e10cSrcweir                         aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, ID_NEW_VIEW_DESIGN == _nId );
1303*cdf0e10cSrcweir 
1304*cdf0e10cSrcweir                         const Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
1305*cdf0e10cSrcweir 						const Reference< XComponent > xComponent( aDesigner.createNew( xDataSource, aCreationArgs ), UNO_QUERY );
1306*cdf0e10cSrcweir                         onDocumentOpened( ::rtl::OUString(), E_QUERY, E_OPEN_DESIGN, xComponent, NULL );
1307*cdf0e10cSrcweir 					}
1308*cdf0e10cSrcweir 				}
1309*cdf0e10cSrcweir 				break;
1310*cdf0e10cSrcweir 			case SID_DB_APP_DELETE:
1311*cdf0e10cSrcweir 			case SID_DB_APP_TABLE_DELETE:
1312*cdf0e10cSrcweir 			case SID_DB_APP_QUERY_DELETE:
1313*cdf0e10cSrcweir 			case SID_DB_APP_FORM_DELETE:
1314*cdf0e10cSrcweir 			case SID_DB_APP_REPORT_DELETE:
1315*cdf0e10cSrcweir 				deleteEntries();
1316*cdf0e10cSrcweir 				break;
1317*cdf0e10cSrcweir 			case SID_DB_APP_RENAME:
1318*cdf0e10cSrcweir 			case SID_DB_APP_TABLE_RENAME:
1319*cdf0e10cSrcweir 			case SID_DB_APP_QUERY_RENAME:
1320*cdf0e10cSrcweir 			case SID_DB_APP_FORM_RENAME:
1321*cdf0e10cSrcweir 			case SID_DB_APP_REPORT_RENAME:
1322*cdf0e10cSrcweir 				renameEntry();
1323*cdf0e10cSrcweir 				break;
1324*cdf0e10cSrcweir 			case SID_DB_APP_EDIT:
1325*cdf0e10cSrcweir 			case SID_DB_APP_EDIT_SQL_VIEW:
1326*cdf0e10cSrcweir 			case SID_DB_APP_TABLE_EDIT:
1327*cdf0e10cSrcweir 			case SID_DB_APP_QUERY_EDIT:
1328*cdf0e10cSrcweir 			case SID_DB_APP_FORM_EDIT:
1329*cdf0e10cSrcweir 			case SID_DB_APP_REPORT_EDIT:
1330*cdf0e10cSrcweir 				doAction( _nId, E_OPEN_DESIGN );
1331*cdf0e10cSrcweir                 break;
1332*cdf0e10cSrcweir 			case SID_DB_APP_OPEN:
1333*cdf0e10cSrcweir 			case SID_DB_APP_TABLE_OPEN:
1334*cdf0e10cSrcweir 			case SID_DB_APP_QUERY_OPEN:
1335*cdf0e10cSrcweir 			case SID_DB_APP_FORM_OPEN:
1336*cdf0e10cSrcweir 			case SID_DB_APP_REPORT_OPEN:
1337*cdf0e10cSrcweir 				doAction( _nId, E_OPEN_NORMAL );
1338*cdf0e10cSrcweir 				break;
1339*cdf0e10cSrcweir 			case SID_DB_APP_CONVERTTOVIEW:
1340*cdf0e10cSrcweir 				doAction( _nId, E_OPEN_NORMAL );
1341*cdf0e10cSrcweir 				break;
1342*cdf0e10cSrcweir 			case SID_SELECTALL:
1343*cdf0e10cSrcweir 				getContainer()->selectAll();
1344*cdf0e10cSrcweir 				InvalidateAll();
1345*cdf0e10cSrcweir 				break;
1346*cdf0e10cSrcweir 			case SID_DB_APP_DSRELDESIGN:
1347*cdf0e10cSrcweir             {
1348*cdf0e10cSrcweir                 Reference< XComponent > xRelationDesigner;
1349*cdf0e10cSrcweir                 if ( !m_pSubComponentManager->activateSubFrame( ::rtl::OUString(), SID_DB_APP_DSRELDESIGN, E_OPEN_DESIGN, xRelationDesigner ) )
1350*cdf0e10cSrcweir                 {
1351*cdf0e10cSrcweir 				    SharedConnection xConnection( ensureConnection() );
1352*cdf0e10cSrcweir 				    if ( xConnection.is() )
1353*cdf0e10cSrcweir 				    {
1354*cdf0e10cSrcweir 					    RelationDesigner aDesigner( getORB(), this, m_aCurrentFrame.getFrame() );
1355*cdf0e10cSrcweir 
1356*cdf0e10cSrcweir                         const Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
1357*cdf0e10cSrcweir 					    const Reference< XComponent > xComponent( aDesigner.createNew( xDataSource ), UNO_QUERY );
1358*cdf0e10cSrcweir                         onDocumentOpened( ::rtl::OUString(), SID_DB_APP_DSRELDESIGN, E_OPEN_DESIGN, xComponent, NULL );
1359*cdf0e10cSrcweir 				    }
1360*cdf0e10cSrcweir                 }
1361*cdf0e10cSrcweir             }
1362*cdf0e10cSrcweir 			break;
1363*cdf0e10cSrcweir 			case SID_DB_APP_DSUSERADMIN:
1364*cdf0e10cSrcweir 				{
1365*cdf0e10cSrcweir 					SharedConnection xConnection( ensureConnection() );
1366*cdf0e10cSrcweir 					if ( xConnection.is() )
1367*cdf0e10cSrcweir 						openDialog(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.UserAdministrationDialog")));
1368*cdf0e10cSrcweir 				}
1369*cdf0e10cSrcweir 				break;
1370*cdf0e10cSrcweir 			case SID_DB_APP_TABLEFILTER:
1371*cdf0e10cSrcweir 				openTableFilterDialog();
1372*cdf0e10cSrcweir 				askToReconnect();
1373*cdf0e10cSrcweir 				break;
1374*cdf0e10cSrcweir 			case SID_DB_APP_REFRESH_TABLES:
1375*cdf0e10cSrcweir 				refreshTables();
1376*cdf0e10cSrcweir 				break;
1377*cdf0e10cSrcweir 			case SID_DB_APP_DSPROPS:
1378*cdf0e10cSrcweir 				openDataSourceAdminDialog();
1379*cdf0e10cSrcweir 				askToReconnect();
1380*cdf0e10cSrcweir 				break;
1381*cdf0e10cSrcweir 			case SID_DB_APP_DSADVANCED_SETTINGS:
1382*cdf0e10cSrcweir 				openDialog(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.AdvancedDatabaseSettingsDialog")));
1383*cdf0e10cSrcweir 				askToReconnect();
1384*cdf0e10cSrcweir 				break;
1385*cdf0e10cSrcweir 			case SID_DB_APP_DSCONNECTION_TYPE:
1386*cdf0e10cSrcweir 				openDialog(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DataSourceTypeChangeDialog")));
1387*cdf0e10cSrcweir 				askToReconnect();
1388*cdf0e10cSrcweir 				break;
1389*cdf0e10cSrcweir 			case ID_DIRECT_SQL:
1390*cdf0e10cSrcweir 				{
1391*cdf0e10cSrcweir 					SharedConnection xConnection( ensureConnection() );
1392*cdf0e10cSrcweir 					if ( xConnection.is() )
1393*cdf0e10cSrcweir 						openDirectSQLDialog();
1394*cdf0e10cSrcweir 				}
1395*cdf0e10cSrcweir 				break;
1396*cdf0e10cSrcweir             case ID_MIGRATE_SCRIPTS:
1397*cdf0e10cSrcweir                 impl_migrateScripts_nothrow();
1398*cdf0e10cSrcweir                 break;
1399*cdf0e10cSrcweir 			case SID_DB_APP_VIEW_TABLES:
1400*cdf0e10cSrcweir                 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_TABLE ) );
1401*cdf0e10cSrcweir 				break;
1402*cdf0e10cSrcweir 			case SID_DB_APP_VIEW_QUERIES:
1403*cdf0e10cSrcweir                 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_QUERY ) );
1404*cdf0e10cSrcweir 				break;
1405*cdf0e10cSrcweir 			case SID_DB_APP_VIEW_FORMS:
1406*cdf0e10cSrcweir                 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_FORM ) );
1407*cdf0e10cSrcweir 				break;
1408*cdf0e10cSrcweir 			case SID_DB_APP_VIEW_REPORTS:
1409*cdf0e10cSrcweir                 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_REPORT ) );
1410*cdf0e10cSrcweir 				break;
1411*cdf0e10cSrcweir 			case SID_DB_APP_DISABLE_PREVIEW:
1412*cdf0e10cSrcweir 				m_ePreviewMode = E_PREVIEWNONE;
1413*cdf0e10cSrcweir 				getContainer()->switchPreview(m_ePreviewMode);
1414*cdf0e10cSrcweir 				break;
1415*cdf0e10cSrcweir 			case SID_DB_APP_VIEW_DOCINFO_PREVIEW:
1416*cdf0e10cSrcweir 				m_ePreviewMode = E_DOCUMENTINFO;
1417*cdf0e10cSrcweir 				getContainer()->switchPreview(m_ePreviewMode);
1418*cdf0e10cSrcweir 				break;
1419*cdf0e10cSrcweir 			case SID_DB_APP_VIEW_DOC_PREVIEW:
1420*cdf0e10cSrcweir 				m_ePreviewMode = E_DOCUMENT;
1421*cdf0e10cSrcweir 				getContainer()->switchPreview(m_ePreviewMode);
1422*cdf0e10cSrcweir 				break;
1423*cdf0e10cSrcweir 			case SID_MAIL_SENDDOC:
1424*cdf0e10cSrcweir 				{
1425*cdf0e10cSrcweir 					SfxMailModel aSendMail;
1426*cdf0e10cSrcweir                     if ( aSendMail.AttachDocument(rtl::OUString(),getModel(), rtl::OUString()) == SfxMailModel::SEND_MAIL_OK )
1427*cdf0e10cSrcweir 						aSendMail.Send( getFrame() );
1428*cdf0e10cSrcweir 				}
1429*cdf0e10cSrcweir 				break;
1430*cdf0e10cSrcweir 			case SID_DB_APP_SENDREPORTASMAIL:
1431*cdf0e10cSrcweir 				doAction( _nId, E_OPEN_FOR_MAIL );
1432*cdf0e10cSrcweir 				break;
1433*cdf0e10cSrcweir 		}
1434*cdf0e10cSrcweir 	}
1435*cdf0e10cSrcweir 	catch( const Exception& )
1436*cdf0e10cSrcweir 	{
1437*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
1438*cdf0e10cSrcweir 	}
1439*cdf0e10cSrcweir 	InvalidateFeature(_nId);
1440*cdf0e10cSrcweir }
1441*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1442*cdf0e10cSrcweir void OApplicationController::describeSupportedFeatures()
1443*cdf0e10cSrcweir {
1444*cdf0e10cSrcweir 	OApplicationController_CBASE::describeSupportedFeatures();
1445*cdf0e10cSrcweir 
1446*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:Save",               ID_BROWSER_SAVEDOC,        CommandGroup::DOCUMENT );
1447*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:SaveAs",             ID_BROWSER_SAVEASDOC,      CommandGroup::DOCUMENT );
1448*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:SendMail",			 SID_MAIL_SENDDOC,			CommandGroup::DOCUMENT );
1449*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBSendReportAsMail",SID_DB_APP_SENDREPORTASMAIL,
1450*cdf0e10cSrcweir 																						CommandGroup::DOCUMENT );
1451*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBSendReportToWriter",SID_DB_APP_SENDREPORTTOWRITER,
1452*cdf0e10cSrcweir 																						CommandGroup::DOCUMENT );
1453*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewForm",          SID_APP_NEW_FORM,          CommandGroup::INSERT );
1454*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewFolder",        SID_APP_NEW_FOLDER,        CommandGroup::INSERT );
1455*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewFormAutoPilot", SID_DB_FORM_NEW_PILOT,     CommandGroup::INSERT );
1456*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewFormAutoPilotWithPreSelection",
1457*cdf0e10cSrcweir                                                              SID_FORM_CREATE_REPWIZ_PRE_SEL,
1458*cdf0e10cSrcweir                                                                                         CommandGroup::APPLICATION );
1459*cdf0e10cSrcweir 
1460*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBNewReport",		 SID_APP_NEW_REPORT,		CommandGroup::INSERT );
1461*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewReportAutoPilot",
1462*cdf0e10cSrcweir                                                              ID_DOCUMENT_CREATE_REPWIZ, CommandGroup::INSERT );
1463*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewReportAutoPilotWithPreSelection",
1464*cdf0e10cSrcweir                                                              SID_REPORT_CREATE_REPWIZ_PRE_SEL,
1465*cdf0e10cSrcweir                                                                                         CommandGroup::APPLICATION );
1466*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewQuery",         ID_NEW_QUERY_DESIGN,       CommandGroup::INSERT );
1467*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewQuerySql",      ID_NEW_QUERY_SQL,          CommandGroup::INSERT );
1468*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewQueryAutoPilot",ID_APP_NEW_QUERY_AUTO_PILOT,
1469*cdf0e10cSrcweir                                                                                         CommandGroup::INSERT );
1470*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewTable",         ID_NEW_TABLE_DESIGN,       CommandGroup::INSERT );
1471*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewTableAutoPilot",ID_NEW_TABLE_DESIGN_AUTO_PILOT,
1472*cdf0e10cSrcweir                                                                                         CommandGroup::INSERT );
1473*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewView",          ID_NEW_VIEW_DESIGN,        CommandGroup::INSERT );
1474*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewViewSQL",       SID_DB_NEW_VIEW_SQL,       CommandGroup::INSERT );
1475*cdf0e10cSrcweir 
1476*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDelete",           SID_DB_APP_DELETE,         CommandGroup::EDIT );
1477*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:Delete",			 SID_DB_APP_DELETE,         CommandGroup::EDIT );
1478*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBRename",           SID_DB_APP_RENAME,         CommandGroup::EDIT );
1479*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBEdit",             SID_DB_APP_EDIT,           CommandGroup::EDIT );
1480*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBEditSqlView",      SID_DB_APP_EDIT_SQL_VIEW,  CommandGroup::EDIT );
1481*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBOpen",             SID_DB_APP_OPEN,           CommandGroup::EDIT );
1482*cdf0e10cSrcweir 
1483*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBTableDelete",      SID_DB_APP_TABLE_DELETE,   CommandGroup::EDIT );
1484*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBTableRename",      SID_DB_APP_TABLE_RENAME,   CommandGroup::EDIT );
1485*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBTableEdit",        SID_DB_APP_TABLE_EDIT,     CommandGroup::EDIT );
1486*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBTableOpen",        SID_DB_APP_TABLE_OPEN,     CommandGroup::EDIT );
1487*cdf0e10cSrcweir 
1488*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBQueryDelete",      SID_DB_APP_QUERY_DELETE,   CommandGroup::EDIT );
1489*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBQueryRename",      SID_DB_APP_QUERY_RENAME,   CommandGroup::EDIT );
1490*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBQueryEdit",        SID_DB_APP_QUERY_EDIT,     CommandGroup::EDIT );
1491*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBQueryOpen",        SID_DB_APP_QUERY_OPEN,     CommandGroup::EDIT );
1492*cdf0e10cSrcweir 
1493*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBFormDelete",       SID_DB_APP_FORM_DELETE,    CommandGroup::EDIT );
1494*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBFormRename",       SID_DB_APP_FORM_RENAME,    CommandGroup::EDIT );
1495*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBFormEdit",         SID_DB_APP_FORM_EDIT,      CommandGroup::EDIT );
1496*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBFormOpen",         SID_DB_APP_FORM_OPEN,      CommandGroup::EDIT );
1497*cdf0e10cSrcweir 
1498*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBReportDelete",     SID_DB_APP_REPORT_DELETE,  CommandGroup::EDIT );
1499*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBReportRename",     SID_DB_APP_REPORT_RENAME,  CommandGroup::EDIT );
1500*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBReportEdit",       SID_DB_APP_REPORT_EDIT,    CommandGroup::EDIT );
1501*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBReportOpen",       SID_DB_APP_REPORT_OPEN,    CommandGroup::EDIT );
1502*cdf0e10cSrcweir 
1503*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:SelectAll",          SID_SELECTALL,             CommandGroup::EDIT );
1504*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:Undo",               ID_BROWSER_UNDO,           CommandGroup::EDIT );
1505*cdf0e10cSrcweir 
1506*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:Sortup",             ID_BROWSER_SORTUP,         CommandGroup::VIEW );
1507*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:SortDown",           ID_BROWSER_SORTDOWN,       CommandGroup::VIEW );
1508*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBRelationDesign",   SID_DB_APP_DSRELDESIGN,    CommandGroup::APPLICATION );
1509*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBUserAdmin",        SID_DB_APP_DSUSERADMIN,    CommandGroup::APPLICATION );
1510*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBTableFilter",      SID_DB_APP_TABLEFILTER,    CommandGroup::APPLICATION );
1511*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDSProperties",     SID_DB_APP_DSPROPS,        CommandGroup::EDIT );
1512*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDSConnectionType", SID_DB_APP_DSCONNECTION_TYPE,
1513*cdf0e10cSrcweir                                                                                         CommandGroup::EDIT );
1514*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDSAdvancedSettings",
1515*cdf0e10cSrcweir                                                              SID_DB_APP_DSADVANCED_SETTINGS,
1516*cdf0e10cSrcweir                                                                                         CommandGroup::EDIT );
1517*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:PasteSpecial",       SID_DB_APP_PASTE_SPECIAL,  CommandGroup::EDIT );
1518*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBConvertToView",    SID_DB_APP_CONVERTTOVIEW,  CommandGroup::EDIT );
1519*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBRefreshTables",    SID_DB_APP_REFRESH_TABLES, CommandGroup::APPLICATION );
1520*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDirectSQL",        ID_DIRECT_SQL,             CommandGroup::APPLICATION );
1521*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBMigrateScripts",   ID_MIGRATE_SCRIPTS,        CommandGroup::APPLICATION );
1522*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBViewTables",       SID_DB_APP_VIEW_TABLES,    CommandGroup::VIEW );
1523*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBViewQueries",      SID_DB_APP_VIEW_QUERIES,   CommandGroup::VIEW );
1524*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBViewForms",        SID_DB_APP_VIEW_FORMS,     CommandGroup::VIEW );
1525*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBViewReports",      SID_DB_APP_VIEW_REPORTS,   CommandGroup::VIEW );
1526*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDisablePreview",   SID_DB_APP_DISABLE_PREVIEW,CommandGroup::VIEW );
1527*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBShowDocInfoPreview",
1528*cdf0e10cSrcweir                                                              SID_DB_APP_VIEW_DOCINFO_PREVIEW,
1529*cdf0e10cSrcweir                                                                                         CommandGroup::VIEW );
1530*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBShowDocPreview",   SID_DB_APP_VIEW_DOC_PREVIEW,
1531*cdf0e10cSrcweir                                                                                         CommandGroup::VIEW );
1532*cdf0e10cSrcweir 
1533*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:OpenUrl",            SID_OPENURL,               CommandGroup::APPLICATION );
1534*cdf0e10cSrcweir 
1535*cdf0e10cSrcweir     // this one should not appear under Tools->Customize->Keyboard
1536*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewReportWithPreSelection",
1537*cdf0e10cSrcweir                                                              SID_APP_NEW_REPORT_PRE_SEL,CommandGroup::INTERNAL );
1538*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBDSImport",		SID_DB_APP_DSIMPORT, CommandGroup::INTERNAL);
1539*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBDSExport",		SID_DB_APP_DSEXPORT, CommandGroup::INTERNAL);
1540*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBDBAdmin",			SID_DB_APP_DBADMIN, CommandGroup::INTERNAL);
1541*cdf0e10cSrcweir 
1542*cdf0e10cSrcweir 	// status info
1543*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBStatusType",		SID_DB_APP_STATUS_TYPE, CommandGroup::INTERNAL);
1544*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBStatusDBName",	SID_DB_APP_STATUS_DBNAME, CommandGroup::INTERNAL);
1545*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBStatusUserName",	SID_DB_APP_STATUS_USERNAME, CommandGroup::INTERNAL);
1546*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBStatusHostName",	SID_DB_APP_STATUS_HOSTNAME, CommandGroup::INTERNAL);
1547*cdf0e10cSrcweir }
1548*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1549*cdf0e10cSrcweir OApplicationView*	OApplicationController::getContainer() const
1550*cdf0e10cSrcweir {
1551*cdf0e10cSrcweir 	return static_cast< OApplicationView* >( getView() );
1552*cdf0e10cSrcweir }
1553*cdf0e10cSrcweir 
1554*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1555*cdf0e10cSrcweir // ::com::sun::star::container::XContainerListener
1556*cdf0e10cSrcweir void SAL_CALL OApplicationController::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
1557*cdf0e10cSrcweir {
1558*cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1559*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
1560*cdf0e10cSrcweir 
1561*cdf0e10cSrcweir 	Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
1562*cdf0e10cSrcweir 	if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
1563*cdf0e10cSrcweir 	{
1564*cdf0e10cSrcweir 		OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1565*cdf0e10cSrcweir 		if ( getContainer() )
1566*cdf0e10cSrcweir 		{
1567*cdf0e10cSrcweir 			::rtl::OUString sName;
1568*cdf0e10cSrcweir 			_rEvent.Accessor >>= sName;
1569*cdf0e10cSrcweir 			ElementType eType = getElementType(xContainer);
1570*cdf0e10cSrcweir 
1571*cdf0e10cSrcweir 			switch( eType )
1572*cdf0e10cSrcweir 			{
1573*cdf0e10cSrcweir 				case E_TABLE:
1574*cdf0e10cSrcweir 					ensureConnection();
1575*cdf0e10cSrcweir 					break;
1576*cdf0e10cSrcweir 				case E_FORM:
1577*cdf0e10cSrcweir 				case E_REPORT:
1578*cdf0e10cSrcweir 					{
1579*cdf0e10cSrcweir 						Reference< XContainer > xSubContainer(_rEvent.Element,UNO_QUERY);
1580*cdf0e10cSrcweir 						if ( xSubContainer.is() )
1581*cdf0e10cSrcweir 							containerFound(xSubContainer);
1582*cdf0e10cSrcweir 					}
1583*cdf0e10cSrcweir 					break;
1584*cdf0e10cSrcweir                 default:
1585*cdf0e10cSrcweir                     break;
1586*cdf0e10cSrcweir 			}
1587*cdf0e10cSrcweir 			getContainer()->elementAdded(eType,sName,_rEvent.Element);
1588*cdf0e10cSrcweir 		}
1589*cdf0e10cSrcweir 	}
1590*cdf0e10cSrcweir }
1591*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1592*cdf0e10cSrcweir void SAL_CALL OApplicationController::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
1593*cdf0e10cSrcweir {
1594*cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1595*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
1596*cdf0e10cSrcweir 
1597*cdf0e10cSrcweir 	Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
1598*cdf0e10cSrcweir 	if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
1599*cdf0e10cSrcweir 	{
1600*cdf0e10cSrcweir 		OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1601*cdf0e10cSrcweir 		::rtl::OUString sName;
1602*cdf0e10cSrcweir 		_rEvent.Accessor >>= sName;
1603*cdf0e10cSrcweir 		ElementType eType = getElementType(xContainer);
1604*cdf0e10cSrcweir 		switch( eType )
1605*cdf0e10cSrcweir 		{
1606*cdf0e10cSrcweir 			case E_TABLE:
1607*cdf0e10cSrcweir 				ensureConnection();
1608*cdf0e10cSrcweir 				break;
1609*cdf0e10cSrcweir 			case E_FORM:
1610*cdf0e10cSrcweir 			case E_REPORT:
1611*cdf0e10cSrcweir 				{
1612*cdf0e10cSrcweir 					Reference<XContent> xContent(xContainer,UNO_QUERY);
1613*cdf0e10cSrcweir 					if ( xContent.is() )
1614*cdf0e10cSrcweir 					{
1615*cdf0e10cSrcweir 						sName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sName;
1616*cdf0e10cSrcweir 					}
1617*cdf0e10cSrcweir 				}
1618*cdf0e10cSrcweir 				break;
1619*cdf0e10cSrcweir             default:
1620*cdf0e10cSrcweir                 break;
1621*cdf0e10cSrcweir 		}
1622*cdf0e10cSrcweir 		getContainer()->elementRemoved(eType,sName);
1623*cdf0e10cSrcweir 	}
1624*cdf0e10cSrcweir }
1625*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1626*cdf0e10cSrcweir void SAL_CALL OApplicationController::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
1627*cdf0e10cSrcweir {
1628*cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1629*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
1630*cdf0e10cSrcweir 
1631*cdf0e10cSrcweir 	Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
1632*cdf0e10cSrcweir 	if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
1633*cdf0e10cSrcweir 	{
1634*cdf0e10cSrcweir 		OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1635*cdf0e10cSrcweir 		::rtl::OUString sName;
1636*cdf0e10cSrcweir 		try
1637*cdf0e10cSrcweir 		{
1638*cdf0e10cSrcweir 			_rEvent.Accessor >>= sName;
1639*cdf0e10cSrcweir 			Reference<XConnection> xConnection;
1640*cdf0e10cSrcweir 			Reference<XPropertySet> xProp(_rEvent.Element,UNO_QUERY);
1641*cdf0e10cSrcweir 			::rtl::OUString sNewName;
1642*cdf0e10cSrcweir 
1643*cdf0e10cSrcweir 			ElementType eType = getElementType(xContainer);
1644*cdf0e10cSrcweir 			switch( eType )
1645*cdf0e10cSrcweir 			{
1646*cdf0e10cSrcweir 				case E_TABLE:
1647*cdf0e10cSrcweir                 {
1648*cdf0e10cSrcweir 					ensureConnection();
1649*cdf0e10cSrcweir 					if ( xProp.is() && m_xMetaData.is() )
1650*cdf0e10cSrcweir 						sNewName = ::dbaui::composeTableName( m_xMetaData, xProp, ::dbtools::eInDataManipulation, false, false, false );
1651*cdf0e10cSrcweir                 }
1652*cdf0e10cSrcweir 				break;
1653*cdf0e10cSrcweir 				case E_FORM:
1654*cdf0e10cSrcweir 				case E_REPORT:
1655*cdf0e10cSrcweir 					{
1656*cdf0e10cSrcweir 						Reference<XContent> xContent(xContainer,UNO_QUERY);
1657*cdf0e10cSrcweir 						if ( xContent.is() )
1658*cdf0e10cSrcweir 						{
1659*cdf0e10cSrcweir 							sName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sName;
1660*cdf0e10cSrcweir 						}
1661*cdf0e10cSrcweir 					}
1662*cdf0e10cSrcweir 					break;
1663*cdf0e10cSrcweir                 default:
1664*cdf0e10cSrcweir                     break;
1665*cdf0e10cSrcweir 			}
1666*cdf0e10cSrcweir 			//	getContainer()->elementReplaced(getContainer()->getElementType(),sName,sNewName);
1667*cdf0e10cSrcweir 		}
1668*cdf0e10cSrcweir 		catch( Exception& )
1669*cdf0e10cSrcweir 		{
1670*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
1671*cdf0e10cSrcweir 		}
1672*cdf0e10cSrcweir 	}
1673*cdf0e10cSrcweir }
1674*cdf0e10cSrcweir namespace
1675*cdf0e10cSrcweir {
1676*cdf0e10cSrcweir 	::rtl::OUString lcl_getToolBarResource(ElementType _eType)
1677*cdf0e10cSrcweir 	{
1678*cdf0e10cSrcweir 		::rtl::OUString sToolbar;
1679*cdf0e10cSrcweir 		switch(_eType)
1680*cdf0e10cSrcweir 		{
1681*cdf0e10cSrcweir 			case E_TABLE:
1682*cdf0e10cSrcweir 				sToolbar = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/tableobjectbar" ));
1683*cdf0e10cSrcweir 				break;
1684*cdf0e10cSrcweir 			case E_QUERY:
1685*cdf0e10cSrcweir 				sToolbar = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/queryobjectbar" ));
1686*cdf0e10cSrcweir 				break;
1687*cdf0e10cSrcweir 			case E_FORM:
1688*cdf0e10cSrcweir 				sToolbar = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/formobjectbar" ));
1689*cdf0e10cSrcweir 				break;
1690*cdf0e10cSrcweir 			case E_REPORT:
1691*cdf0e10cSrcweir 				sToolbar = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/reportobjectbar" ));
1692*cdf0e10cSrcweir 				break;
1693*cdf0e10cSrcweir 			case E_NONE:
1694*cdf0e10cSrcweir 				break;
1695*cdf0e10cSrcweir 			default:
1696*cdf0e10cSrcweir 				OSL_ENSURE(0,"Invalid ElementType!");
1697*cdf0e10cSrcweir 				break;
1698*cdf0e10cSrcweir 		}
1699*cdf0e10cSrcweir 		return sToolbar;
1700*cdf0e10cSrcweir 	}
1701*cdf0e10cSrcweir }
1702*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1703*cdf0e10cSrcweir sal_Bool OApplicationController::onContainerSelect(ElementType _eType)
1704*cdf0e10cSrcweir {
1705*cdf0e10cSrcweir 	OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1706*cdf0e10cSrcweir 
1707*cdf0e10cSrcweir     if ( m_eCurrentType != _eType && _eType != E_NONE )
1708*cdf0e10cSrcweir 	{
1709*cdf0e10cSrcweir         SelectionGuard aSelGuard( *m_pSelectionNotifier );
1710*cdf0e10cSrcweir 
1711*cdf0e10cSrcweir         if ( _eType == E_TABLE )
1712*cdf0e10cSrcweir 		{
1713*cdf0e10cSrcweir 			try
1714*cdf0e10cSrcweir 			{
1715*cdf0e10cSrcweir 				SharedConnection xConnection( ensureConnection() );
1716*cdf0e10cSrcweir 				if ( xConnection.is() && getContainer()->getDetailView() )
1717*cdf0e10cSrcweir 				{
1718*cdf0e10cSrcweir 					getContainer()->getDetailView()->createTablesPage(xConnection);
1719*cdf0e10cSrcweir 					Reference<XTablesSupplier> xTabSup(xConnection,UNO_QUERY);
1720*cdf0e10cSrcweir 					if ( xTabSup.is() )
1721*cdf0e10cSrcweir 						addContainerListener(xTabSup->getTables());
1722*cdf0e10cSrcweir 				}
1723*cdf0e10cSrcweir 				else
1724*cdf0e10cSrcweir 				{
1725*cdf0e10cSrcweir 					return sal_False;
1726*cdf0e10cSrcweir 				}
1727*cdf0e10cSrcweir 			}
1728*cdf0e10cSrcweir 			catch( const Exception& )
1729*cdf0e10cSrcweir 			{
1730*cdf0e10cSrcweir 				return sal_False;
1731*cdf0e10cSrcweir 			}
1732*cdf0e10cSrcweir 		}
1733*cdf0e10cSrcweir         Reference< XLayoutManager > xLayoutManager = getLayoutManager( getFrame() );
1734*cdf0e10cSrcweir         if ( xLayoutManager.is() )
1735*cdf0e10cSrcweir         {
1736*cdf0e10cSrcweir 		    ::rtl::OUString sToolbar = lcl_getToolBarResource(_eType);
1737*cdf0e10cSrcweir 		    ::rtl::OUString sDestroyToolbar = lcl_getToolBarResource(m_eCurrentType);
1738*cdf0e10cSrcweir 
1739*cdf0e10cSrcweir 		    xLayoutManager->lock();
1740*cdf0e10cSrcweir 		    xLayoutManager->destroyElement( sDestroyToolbar );
1741*cdf0e10cSrcweir 		    if ( sToolbar.getLength() )
1742*cdf0e10cSrcweir 		    {
1743*cdf0e10cSrcweir 			    xLayoutManager->createElement( sToolbar );
1744*cdf0e10cSrcweir 			    xLayoutManager->requestElement( sToolbar );
1745*cdf0e10cSrcweir 		    }
1746*cdf0e10cSrcweir 		    xLayoutManager->unlock();
1747*cdf0e10cSrcweir 		    xLayoutManager->doLayout();
1748*cdf0e10cSrcweir         }
1749*cdf0e10cSrcweir 
1750*cdf0e10cSrcweir 		if ( _eType != E_TABLE && getContainer()->getDetailView() )
1751*cdf0e10cSrcweir 		{
1752*cdf0e10cSrcweir 			Reference< XNameAccess > xContainer = getElements(_eType);
1753*cdf0e10cSrcweir 			addContainerListener(xContainer);
1754*cdf0e10cSrcweir 			getContainer()->getDetailView()->createPage(_eType,xContainer);
1755*cdf0e10cSrcweir 		}
1756*cdf0e10cSrcweir 
1757*cdf0e10cSrcweir         SelectionByElementType::iterator pendingSelection = m_aPendingSelection.find( _eType );
1758*cdf0e10cSrcweir         if ( pendingSelection != m_aPendingSelection.end() )
1759*cdf0e10cSrcweir         {
1760*cdf0e10cSrcweir             Sequence< ::rtl::OUString > aSelected( pendingSelection->second.size() );
1761*cdf0e10cSrcweir             ::std::copy( pendingSelection->second.begin(), pendingSelection->second.end(), aSelected.getArray() );
1762*cdf0e10cSrcweir             getContainer()->selectElements( aSelected );
1763*cdf0e10cSrcweir 
1764*cdf0e10cSrcweir             m_aPendingSelection.erase( pendingSelection );
1765*cdf0e10cSrcweir         }
1766*cdf0e10cSrcweir 
1767*cdf0e10cSrcweir 		InvalidateAll();
1768*cdf0e10cSrcweir 	}
1769*cdf0e10cSrcweir 	m_eCurrentType = _eType;
1770*cdf0e10cSrcweir 
1771*cdf0e10cSrcweir 	return sal_True;
1772*cdf0e10cSrcweir }
1773*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1774*cdf0e10cSrcweir bool OApplicationController::onEntryDoubleClick( SvTreeListBox& _rTree )
1775*cdf0e10cSrcweir {
1776*cdf0e10cSrcweir 	if ( getContainer() && getContainer()->isLeaf( _rTree.GetHdlEntry() ) )
1777*cdf0e10cSrcweir 	{
1778*cdf0e10cSrcweir 		try
1779*cdf0e10cSrcweir 		{
1780*cdf0e10cSrcweir 			openElement(
1781*cdf0e10cSrcweir                 getContainer()->getQualifiedName( _rTree.GetHdlEntry() ),
1782*cdf0e10cSrcweir                 getContainer()->getElementType(),
1783*cdf0e10cSrcweir                 E_OPEN_NORMAL
1784*cdf0e10cSrcweir             );
1785*cdf0e10cSrcweir             return true;    // handled
1786*cdf0e10cSrcweir 		}
1787*cdf0e10cSrcweir 		catch(const Exception&)
1788*cdf0e10cSrcweir 		{
1789*cdf0e10cSrcweir 			DBG_UNHANDLED_EXCEPTION();
1790*cdf0e10cSrcweir 		}
1791*cdf0e10cSrcweir 	}
1792*cdf0e10cSrcweir     return false;   // not handled
1793*cdf0e10cSrcweir }
1794*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1795*cdf0e10cSrcweir bool OApplicationController::impl_isAlterableView_nothrow( const ::rtl::OUString& _rTableOrViewName ) const
1796*cdf0e10cSrcweir {
1797*cdf0e10cSrcweir     OSL_PRECOND( m_xDataSourceConnection.is(), "OApplicationController::impl_isAlterableView_nothrow: no connection!" );
1798*cdf0e10cSrcweir 
1799*cdf0e10cSrcweir     bool bIsAlterableView( false );
1800*cdf0e10cSrcweir     try
1801*cdf0e10cSrcweir     {
1802*cdf0e10cSrcweir         Reference< XViewsSupplier > xViewsSupp( m_xDataSourceConnection, UNO_QUERY );
1803*cdf0e10cSrcweir         Reference< XNameAccess > xViews;
1804*cdf0e10cSrcweir         if ( xViewsSupp.is() )
1805*cdf0e10cSrcweir             xViews = xViewsSupp->getViews();
1806*cdf0e10cSrcweir 
1807*cdf0e10cSrcweir         Reference< XAlterView > xAsAlterableView;
1808*cdf0e10cSrcweir         if ( xViews.is() && xViews->hasByName( _rTableOrViewName ) )
1809*cdf0e10cSrcweir             xAsAlterableView.set( xViews->getByName( _rTableOrViewName ), UNO_QUERY );
1810*cdf0e10cSrcweir 
1811*cdf0e10cSrcweir         bIsAlterableView = xAsAlterableView.is();
1812*cdf0e10cSrcweir     }
1813*cdf0e10cSrcweir     catch( const Exception& )
1814*cdf0e10cSrcweir     {
1815*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
1816*cdf0e10cSrcweir     }
1817*cdf0e10cSrcweir     return bIsAlterableView;
1818*cdf0e10cSrcweir }
1819*cdf0e10cSrcweir 
1820*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1821*cdf0e10cSrcweir Reference< XComponent > OApplicationController::openElement(const ::rtl::OUString& _sName, ElementType _eType,
1822*cdf0e10cSrcweir     ElementOpenMode _eOpenMode, sal_uInt16 _nInstigatorCommand )
1823*cdf0e10cSrcweir {
1824*cdf0e10cSrcweir     return openElementWithArguments( _sName, _eType, _eOpenMode, _nInstigatorCommand, ::comphelper::NamedValueCollection() );
1825*cdf0e10cSrcweir }
1826*cdf0e10cSrcweir 
1827*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1828*cdf0e10cSrcweir Reference< XComponent > OApplicationController::openElementWithArguments( const ::rtl::OUString& _sName, ElementType _eType,
1829*cdf0e10cSrcweir     ElementOpenMode _eOpenMode, sal_uInt16 _nInstigatorCommand, const ::comphelper::NamedValueCollection& _rAdditionalArguments )
1830*cdf0e10cSrcweir {
1831*cdf0e10cSrcweir     OSL_PRECOND( getContainer(), "OApplicationController::openElementWithArguments: no view!" );
1832*cdf0e10cSrcweir     if ( !getContainer() )
1833*cdf0e10cSrcweir         return NULL;
1834*cdf0e10cSrcweir 
1835*cdf0e10cSrcweir 	Reference< XComponent > xRet;
1836*cdf0e10cSrcweir 	if ( _eOpenMode == E_OPEN_DESIGN )
1837*cdf0e10cSrcweir 	{
1838*cdf0e10cSrcweir 		// OJ: http://www.openoffice.org/issues/show_bug.cgi?id=30382
1839*cdf0e10cSrcweir 		getContainer()->showPreview(NULL);
1840*cdf0e10cSrcweir 	}
1841*cdf0e10cSrcweir 
1842*cdf0e10cSrcweir     bool isStandaloneDocument = false;
1843*cdf0e10cSrcweir     switch ( _eType )
1844*cdf0e10cSrcweir 	{
1845*cdf0e10cSrcweir 	case E_REPORT:
1846*cdf0e10cSrcweir         if ( _eOpenMode != E_OPEN_DESIGN )
1847*cdf0e10cSrcweir         {
1848*cdf0e10cSrcweir             // reports which are opened in a mode other than design are no sub components of our application
1849*cdf0e10cSrcweir             // component, but standalone documents.
1850*cdf0e10cSrcweir             isStandaloneDocument = true;
1851*cdf0e10cSrcweir         }
1852*cdf0e10cSrcweir         // NO break!
1853*cdf0e10cSrcweir 	case E_FORM:
1854*cdf0e10cSrcweir 	{
1855*cdf0e10cSrcweir         if ( isStandaloneDocument || !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode, xRet ) )
1856*cdf0e10cSrcweir         {
1857*cdf0e10cSrcweir 		    ::std::auto_ptr< OLinkedDocumentsAccess > aHelper = getDocumentsAccess( _eType );
1858*cdf0e10cSrcweir             if ( !aHelper->isConnected() )
1859*cdf0e10cSrcweir                 break;
1860*cdf0e10cSrcweir 
1861*cdf0e10cSrcweir 		    Reference< XComponent > xDefinition;
1862*cdf0e10cSrcweir 		    xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments );
1863*cdf0e10cSrcweir 
1864*cdf0e10cSrcweir             if ( !isStandaloneDocument )
1865*cdf0e10cSrcweir 		        onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition );
1866*cdf0e10cSrcweir         }
1867*cdf0e10cSrcweir 	}
1868*cdf0e10cSrcweir 	break;
1869*cdf0e10cSrcweir 
1870*cdf0e10cSrcweir 	case E_QUERY:
1871*cdf0e10cSrcweir 	case E_TABLE:
1872*cdf0e10cSrcweir 	{
1873*cdf0e10cSrcweir         if ( !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode, xRet ) )
1874*cdf0e10cSrcweir         {
1875*cdf0e10cSrcweir 		    SharedConnection xConnection( ensureConnection() );
1876*cdf0e10cSrcweir 		    if ( !xConnection.is() )
1877*cdf0e10cSrcweir                 break;
1878*cdf0e10cSrcweir 
1879*cdf0e10cSrcweir             ::std::auto_ptr< DatabaseObjectView > pDesigner;
1880*cdf0e10cSrcweir             ::comphelper::NamedValueCollection aArguments( _rAdditionalArguments );
1881*cdf0e10cSrcweir 
1882*cdf0e10cSrcweir             Any aDataSource;
1883*cdf0e10cSrcweir 		    if ( _eOpenMode == E_OPEN_DESIGN )
1884*cdf0e10cSrcweir 		    {
1885*cdf0e10cSrcweir                 bool bAddViewTypeArg = false;
1886*cdf0e10cSrcweir 
1887*cdf0e10cSrcweir 			    if ( _eType == E_TABLE )
1888*cdf0e10cSrcweir 			    {
1889*cdf0e10cSrcweir                     if ( impl_isAlterableView_nothrow( _sName ) )
1890*cdf0e10cSrcweir                     {
1891*cdf0e10cSrcweir                         pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), true ) );
1892*cdf0e10cSrcweir                         bAddViewTypeArg = true;
1893*cdf0e10cSrcweir                     }
1894*cdf0e10cSrcweir                     else
1895*cdf0e10cSrcweir                     {
1896*cdf0e10cSrcweir                         pDesigner.reset( new TableDesigner( getORB(), this, m_aCurrentFrame.getFrame() ) );
1897*cdf0e10cSrcweir                     }
1898*cdf0e10cSrcweir 			    }
1899*cdf0e10cSrcweir 			    else if ( _eType == E_QUERY )
1900*cdf0e10cSrcweir 			    {
1901*cdf0e10cSrcweir                     pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), false ) );
1902*cdf0e10cSrcweir                     bAddViewTypeArg = true;
1903*cdf0e10cSrcweir 			    }
1904*cdf0e10cSrcweir 			    aDataSource <<= m_xDataSource;
1905*cdf0e10cSrcweir 
1906*cdf0e10cSrcweir                 if ( bAddViewTypeArg )
1907*cdf0e10cSrcweir                 {
1908*cdf0e10cSrcweir                     const bool bQueryGraphicalMode =( _nInstigatorCommand != SID_DB_APP_EDIT_SQL_VIEW );
1909*cdf0e10cSrcweir                     aArguments.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, bQueryGraphicalMode );
1910*cdf0e10cSrcweir                 }
1911*cdf0e10cSrcweir 
1912*cdf0e10cSrcweir 		    }
1913*cdf0e10cSrcweir 		    else
1914*cdf0e10cSrcweir 		    {
1915*cdf0e10cSrcweir 			    pDesigner.reset( new ResultSetBrowser( getORB(), this, m_aCurrentFrame.getFrame(), _eType == E_TABLE ) );
1916*cdf0e10cSrcweir 
1917*cdf0e10cSrcweir                 if ( !aArguments.has( (::rtl::OUString)PROPERTY_SHOWMENU ) )
1918*cdf0e10cSrcweir                     aArguments.put( (::rtl::OUString)PROPERTY_SHOWMENU, makeAny( (sal_Bool)sal_True ) );
1919*cdf0e10cSrcweir 
1920*cdf0e10cSrcweir 		        aDataSource <<= getDatabaseName();
1921*cdf0e10cSrcweir 		    }
1922*cdf0e10cSrcweir 
1923*cdf0e10cSrcweir 		    xRet.set( pDesigner->openExisting( aDataSource, _sName, aArguments ) );
1924*cdf0e10cSrcweir 	        onDocumentOpened( _sName, _eType, _eOpenMode, xRet, NULL );
1925*cdf0e10cSrcweir         }
1926*cdf0e10cSrcweir 	}
1927*cdf0e10cSrcweir 	break;
1928*cdf0e10cSrcweir 
1929*cdf0e10cSrcweir     default:
1930*cdf0e10cSrcweir         OSL_ENSURE( false, "OApplicationController::openElement: illegal object type!" );
1931*cdf0e10cSrcweir         break;
1932*cdf0e10cSrcweir 	}
1933*cdf0e10cSrcweir 	return xRet;
1934*cdf0e10cSrcweir }
1935*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1936*cdf0e10cSrcweir IMPL_LINK( OApplicationController, OnSelectContainer, void*, _pType )
1937*cdf0e10cSrcweir {
1938*cdf0e10cSrcweir     ElementType eType = (ElementType)reinterpret_cast< sal_IntPtr >( _pType );
1939*cdf0e10cSrcweir     getContainer()->selectContainer(eType);
1940*cdf0e10cSrcweir     return 0L;
1941*cdf0e10cSrcweir }
1942*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1943*cdf0e10cSrcweir IMPL_LINK( OApplicationController, OnCreateWithPilot, void*, _pType )
1944*cdf0e10cSrcweir {
1945*cdf0e10cSrcweir     ElementType eType = (ElementType)reinterpret_cast< sal_IntPtr >( _pType );
1946*cdf0e10cSrcweir     newElementWithPilot( eType );
1947*cdf0e10cSrcweir     return 0L;
1948*cdf0e10cSrcweir }
1949*cdf0e10cSrcweir 
1950*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1951*cdf0e10cSrcweir void OApplicationController::newElementWithPilot( ElementType _eType )
1952*cdf0e10cSrcweir {
1953*cdf0e10cSrcweir     CloseVeto aKeepDoc( getFrame() );
1954*cdf0e10cSrcweir         // prevent the document being closed while the wizard is open
1955*cdf0e10cSrcweir 
1956*cdf0e10cSrcweir     OSL_ENSURE( getContainer(), "OApplicationController::newElementWithPilot: without a view?" );
1957*cdf0e10cSrcweir 
1958*cdf0e10cSrcweir 	switch ( _eType )
1959*cdf0e10cSrcweir 	{
1960*cdf0e10cSrcweir 		case E_REPORT:
1961*cdf0e10cSrcweir 		case E_FORM:
1962*cdf0e10cSrcweir 		{
1963*cdf0e10cSrcweir 			::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType);
1964*cdf0e10cSrcweir             if ( aHelper->isConnected() )
1965*cdf0e10cSrcweir 			{
1966*cdf0e10cSrcweir                 sal_Int32 nCommandType = -1;
1967*cdf0e10cSrcweir                 const ::rtl::OUString sCurrentSelected( getCurrentlySelectedName( nCommandType ) );
1968*cdf0e10cSrcweir 				if ( E_REPORT == _eType )
1969*cdf0e10cSrcweir 					aHelper->newReportWithPilot( nCommandType, sCurrentSelected );
1970*cdf0e10cSrcweir 				else
1971*cdf0e10cSrcweir 					aHelper->newFormWithPilot( nCommandType, sCurrentSelected );
1972*cdf0e10cSrcweir 			}
1973*cdf0e10cSrcweir         }
1974*cdf0e10cSrcweir         break;
1975*cdf0e10cSrcweir         case E_QUERY:
1976*cdf0e10cSrcweir         case E_TABLE:
1977*cdf0e10cSrcweir  		{
1978*cdf0e10cSrcweir 		    ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType);
1979*cdf0e10cSrcweir             if ( aHelper->isConnected() )
1980*cdf0e10cSrcweir             {
1981*cdf0e10cSrcweir 		        if ( E_QUERY == _eType )
1982*cdf0e10cSrcweir 			        aHelper->newQueryWithPilot();
1983*cdf0e10cSrcweir 		        else
1984*cdf0e10cSrcweir 			        aHelper->newTableWithPilot();
1985*cdf0e10cSrcweir 		    }
1986*cdf0e10cSrcweir  		}
1987*cdf0e10cSrcweir  		break;
1988*cdf0e10cSrcweir         case E_NONE:
1989*cdf0e10cSrcweir             break;
1990*cdf0e10cSrcweir     }
1991*cdf0e10cSrcweir 
1992*cdf0e10cSrcweir     // no need for onDocumentOpened, the table wizard opens the created table by using
1993*cdf0e10cSrcweir     // XDatabaseDocumentUI::loadComponent method.
1994*cdf0e10cSrcweir }
1995*cdf0e10cSrcweir 
1996*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1997*cdf0e10cSrcweir Reference< XComponent > OApplicationController::newElement( ElementType _eType, const ::comphelper::NamedValueCollection& i_rAdditionalArguments,
1998*cdf0e10cSrcweir                                                            Reference< XComponent >& o_rDocumentDefinition )
1999*cdf0e10cSrcweir {
2000*cdf0e10cSrcweir 	OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
2001*cdf0e10cSrcweir 
2002*cdf0e10cSrcweir     Reference< XComponent > xComponent;
2003*cdf0e10cSrcweir     o_rDocumentDefinition.clear();
2004*cdf0e10cSrcweir 
2005*cdf0e10cSrcweir 	switch ( _eType )
2006*cdf0e10cSrcweir 	{
2007*cdf0e10cSrcweir         case E_FORM:
2008*cdf0e10cSrcweir 		case E_REPORT:
2009*cdf0e10cSrcweir 		{
2010*cdf0e10cSrcweir 			::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess( _eType );
2011*cdf0e10cSrcweir             if ( !aHelper->isConnected() )
2012*cdf0e10cSrcweir                 break;
2013*cdf0e10cSrcweir 
2014*cdf0e10cSrcweir             xComponent = aHelper->newDocument( _eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT, i_rAdditionalArguments, o_rDocumentDefinition );
2015*cdf0e10cSrcweir 		}
2016*cdf0e10cSrcweir 		break;
2017*cdf0e10cSrcweir 
2018*cdf0e10cSrcweir 		case E_QUERY:
2019*cdf0e10cSrcweir 		case E_TABLE:
2020*cdf0e10cSrcweir 		{
2021*cdf0e10cSrcweir 			::std::auto_ptr< DatabaseObjectView > pDesigner;
2022*cdf0e10cSrcweir 			SharedConnection xConnection( ensureConnection() );
2023*cdf0e10cSrcweir 			if ( !xConnection.is() )
2024*cdf0e10cSrcweir                 break;
2025*cdf0e10cSrcweir 
2026*cdf0e10cSrcweir             if ( _eType == E_TABLE )
2027*cdf0e10cSrcweir 			{
2028*cdf0e10cSrcweir 				pDesigner.reset( new TableDesigner( getORB(), this, getFrame() ) );
2029*cdf0e10cSrcweir 			}
2030*cdf0e10cSrcweir 			else if ( _eType == E_QUERY )
2031*cdf0e10cSrcweir 			{
2032*cdf0e10cSrcweir 				pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false ) );
2033*cdf0e10cSrcweir 			}
2034*cdf0e10cSrcweir 
2035*cdf0e10cSrcweir             Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
2036*cdf0e10cSrcweir 			xComponent.set( pDesigner->createNew( xDataSource, i_rAdditionalArguments ), UNO_QUERY );
2037*cdf0e10cSrcweir 		}
2038*cdf0e10cSrcweir 		break;
2039*cdf0e10cSrcweir 
2040*cdf0e10cSrcweir         default:
2041*cdf0e10cSrcweir             OSL_ENSURE( false, "OApplicationController::newElement: illegal type!" );
2042*cdf0e10cSrcweir             break;
2043*cdf0e10cSrcweir 	}
2044*cdf0e10cSrcweir 
2045*cdf0e10cSrcweir     if ( xComponent.is() )
2046*cdf0e10cSrcweir         onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, o_rDocumentDefinition );
2047*cdf0e10cSrcweir 
2048*cdf0e10cSrcweir     return xComponent;
2049*cdf0e10cSrcweir }
2050*cdf0e10cSrcweir 
2051*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2052*cdf0e10cSrcweir void OApplicationController::addContainerListener(const Reference<XNameAccess>& _xCollection)
2053*cdf0e10cSrcweir {
2054*cdf0e10cSrcweir 	try
2055*cdf0e10cSrcweir 	{
2056*cdf0e10cSrcweir 		Reference< XContainer > xCont(_xCollection, UNO_QUERY);
2057*cdf0e10cSrcweir 		if ( xCont.is() )
2058*cdf0e10cSrcweir 		{
2059*cdf0e10cSrcweir 			// add as listener to get notified if elements are inserted or removed
2060*cdf0e10cSrcweir 			TContainerVector::iterator aFind = ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xCont);
2061*cdf0e10cSrcweir 			if ( aFind == m_aCurrentContainers.end() )
2062*cdf0e10cSrcweir 			{
2063*cdf0e10cSrcweir 				xCont->addContainerListener(this);
2064*cdf0e10cSrcweir 				m_aCurrentContainers.push_back(xCont);
2065*cdf0e10cSrcweir 			}
2066*cdf0e10cSrcweir 		}
2067*cdf0e10cSrcweir 	}
2068*cdf0e10cSrcweir 	catch( const Exception& )
2069*cdf0e10cSrcweir 	{
2070*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
2071*cdf0e10cSrcweir 	}
2072*cdf0e10cSrcweir }
2073*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2074*cdf0e10cSrcweir void OApplicationController::renameEntry()
2075*cdf0e10cSrcweir {
2076*cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
2077*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
2078*cdf0e10cSrcweir 
2079*cdf0e10cSrcweir 	OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
2080*cdf0e10cSrcweir 	::std::vector< ::rtl::OUString> aList;
2081*cdf0e10cSrcweir 	getSelectionElementNames(aList);
2082*cdf0e10cSrcweir 
2083*cdf0e10cSrcweir 	Reference< XNameAccess > xContainer = getElements(getContainer()->getElementType());
2084*cdf0e10cSrcweir 	OSL_ENSURE(aList.size() == 1,"Invalid rename call here. More than one element!");
2085*cdf0e10cSrcweir     if ( aList.empty() )
2086*cdf0e10cSrcweir         return;
2087*cdf0e10cSrcweir 
2088*cdf0e10cSrcweir 	try
2089*cdf0e10cSrcweir 	{
2090*cdf0e10cSrcweir 		if ( xContainer.is() )
2091*cdf0e10cSrcweir 		{
2092*cdf0e10cSrcweir             ::std::auto_ptr< IObjectNameCheck > pNameChecker;
2093*cdf0e10cSrcweir             ::std::auto_ptr< OSaveAsDlg > aDialog;
2094*cdf0e10cSrcweir 
2095*cdf0e10cSrcweir 			Reference<XRename> xRename;
2096*cdf0e10cSrcweir 			const ElementType eType = getContainer()->getElementType();
2097*cdf0e10cSrcweir 			switch( eType )
2098*cdf0e10cSrcweir 			{
2099*cdf0e10cSrcweir 				case E_FORM:
2100*cdf0e10cSrcweir 				case E_REPORT:
2101*cdf0e10cSrcweir 					{
2102*cdf0e10cSrcweir 						Reference<XHierarchicalNameContainer> xHNames(xContainer, UNO_QUERY);
2103*cdf0e10cSrcweir 						if ( xHNames.is() )
2104*cdf0e10cSrcweir 						{
2105*cdf0e10cSrcweir 							String sLabel;
2106*cdf0e10cSrcweir 							if ( eType == E_FORM )
2107*cdf0e10cSrcweir 								sLabel = String(ModuleRes( STR_FRM_LABEL ));
2108*cdf0e10cSrcweir 							else
2109*cdf0e10cSrcweir 								sLabel = String(ModuleRes( STR_RPT_LABEL ));
2110*cdf0e10cSrcweir 
2111*cdf0e10cSrcweir 							::rtl::OUString sName = *aList.begin();
2112*cdf0e10cSrcweir 							if ( xHNames->hasByHierarchicalName(sName) )
2113*cdf0e10cSrcweir 							{
2114*cdf0e10cSrcweir 								xRename.set(xHNames->getByHierarchicalName(sName),UNO_QUERY);
2115*cdf0e10cSrcweir 								Reference<XChild> xChild(xRename,UNO_QUERY);
2116*cdf0e10cSrcweir 								if ( xChild.is() )
2117*cdf0e10cSrcweir 								{
2118*cdf0e10cSrcweir 									Reference<XHierarchicalNameContainer> xParent(xChild->getParent(),UNO_QUERY);
2119*cdf0e10cSrcweir 									if ( xParent.is() )
2120*cdf0e10cSrcweir 									{
2121*cdf0e10cSrcweir 										xHNames = xParent;
2122*cdf0e10cSrcweir 										Reference<XPropertySet>(xRename,UNO_QUERY)->getPropertyValue(PROPERTY_NAME) >>= sName;
2123*cdf0e10cSrcweir 									}
2124*cdf0e10cSrcweir 								}
2125*cdf0e10cSrcweir                                 pNameChecker.reset( new HierarchicalNameCheck( xHNames.get(), String() ) );
2126*cdf0e10cSrcweir 								aDialog.reset( new OSaveAsDlg(
2127*cdf0e10cSrcweir                                     getView(), getORB(), sName, sLabel, *pNameChecker, SAD_TITLE_RENAME ) );
2128*cdf0e10cSrcweir 							}
2129*cdf0e10cSrcweir 						}
2130*cdf0e10cSrcweir 					}
2131*cdf0e10cSrcweir 					break;
2132*cdf0e10cSrcweir 				case E_TABLE:
2133*cdf0e10cSrcweir                     ensureConnection();
2134*cdf0e10cSrcweir                     if ( !getConnection().is() )
2135*cdf0e10cSrcweir                         break;
2136*cdf0e10cSrcweir                     // NO break
2137*cdf0e10cSrcweir 				case E_QUERY:
2138*cdf0e10cSrcweir 					if ( xContainer->hasByName(*aList.begin()) )
2139*cdf0e10cSrcweir 					{
2140*cdf0e10cSrcweir 						xRename.set(xContainer->getByName(*aList.begin()),UNO_QUERY);
2141*cdf0e10cSrcweir                         sal_Int32 nCommandType = eType == E_QUERY ? CommandType::QUERY : CommandType::TABLE;
2142*cdf0e10cSrcweir 
2143*cdf0e10cSrcweir                         ensureConnection();
2144*cdf0e10cSrcweir                         pNameChecker.reset( new DynamicTableOrQueryNameCheck( getConnection(), nCommandType ) );
2145*cdf0e10cSrcweir 					    aDialog.reset( new OSaveAsDlg(
2146*cdf0e10cSrcweir                             getView(), nCommandType, getORB(), getConnection(),
2147*cdf0e10cSrcweir                                 *aList.begin(), *pNameChecker, SAD_TITLE_RENAME ) );
2148*cdf0e10cSrcweir 					}
2149*cdf0e10cSrcweir 					break;
2150*cdf0e10cSrcweir                 default:
2151*cdf0e10cSrcweir                     break;
2152*cdf0e10cSrcweir 			}
2153*cdf0e10cSrcweir 
2154*cdf0e10cSrcweir 			if ( xRename.is() && aDialog.get() )
2155*cdf0e10cSrcweir 			{
2156*cdf0e10cSrcweir 
2157*cdf0e10cSrcweir 				sal_Bool bTryAgain = sal_True;
2158*cdf0e10cSrcweir 				while( bTryAgain )
2159*cdf0e10cSrcweir 				{
2160*cdf0e10cSrcweir 					if ( aDialog->Execute() == RET_OK )
2161*cdf0e10cSrcweir 					{
2162*cdf0e10cSrcweir 						try
2163*cdf0e10cSrcweir 						{
2164*cdf0e10cSrcweir 							::rtl::OUString sNewName;
2165*cdf0e10cSrcweir 							if ( eType == E_TABLE )
2166*cdf0e10cSrcweir 							{
2167*cdf0e10cSrcweir 								::rtl::OUString sName = aDialog->getName();
2168*cdf0e10cSrcweir 								::rtl::OUString sCatalog = aDialog->getCatalog();
2169*cdf0e10cSrcweir 								::rtl::OUString sSchema	 = aDialog->getSchema();
2170*cdf0e10cSrcweir 
2171*cdf0e10cSrcweir 								sNewName = ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sName, sal_False, ::dbtools::eInDataManipulation );
2172*cdf0e10cSrcweir 							}
2173*cdf0e10cSrcweir 							else
2174*cdf0e10cSrcweir 								sNewName = aDialog->getName();
2175*cdf0e10cSrcweir 
2176*cdf0e10cSrcweir 							::rtl::OUString sOldName = *aList.begin();
2177*cdf0e10cSrcweir 							if ( eType == E_FORM || eType == E_REPORT )
2178*cdf0e10cSrcweir 							{
2179*cdf0e10cSrcweir 								Reference<XContent> xContent(xRename,UNO_QUERY);
2180*cdf0e10cSrcweir 								if ( xContent.is() )
2181*cdf0e10cSrcweir 								{
2182*cdf0e10cSrcweir 									sOldName = xContent->getIdentifier()->getContentIdentifier();
2183*cdf0e10cSrcweir 								}
2184*cdf0e10cSrcweir 							}
2185*cdf0e10cSrcweir 
2186*cdf0e10cSrcweir 							xRename->rename(sNewName);
2187*cdf0e10cSrcweir 
2188*cdf0e10cSrcweir                             if ( eType == E_TABLE )
2189*cdf0e10cSrcweir                             {
2190*cdf0e10cSrcweir                                 Reference<XPropertySet> xProp(xRename,UNO_QUERY);
2191*cdf0e10cSrcweir                                 sNewName = ::dbaui::composeTableName( m_xMetaData, xProp, ::dbtools::eInDataManipulation, false, false, false );
2192*cdf0e10cSrcweir                             }
2193*cdf0e10cSrcweir 							getContainer()->elementReplaced( eType , sOldName, sNewName );
2194*cdf0e10cSrcweir 
2195*cdf0e10cSrcweir 							bTryAgain = sal_False;
2196*cdf0e10cSrcweir 						}
2197*cdf0e10cSrcweir 						catch(const SQLException& )
2198*cdf0e10cSrcweir                         {
2199*cdf0e10cSrcweir                             showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
2200*cdf0e10cSrcweir 
2201*cdf0e10cSrcweir 						}
2202*cdf0e10cSrcweir 						catch(const ElementExistException& e)
2203*cdf0e10cSrcweir 						{
2204*cdf0e10cSrcweir 							static ::rtl::OUString sStatus = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000"));
2205*cdf0e10cSrcweir 							String sMsg = String( ModuleRes( STR_NAME_ALREADY_EXISTS ) );
2206*cdf0e10cSrcweir 							sMsg.SearchAndReplace('#',e.Message);
2207*cdf0e10cSrcweir 							showError(SQLExceptionInfo(SQLException(sMsg, e.Context, sStatus, 0, Any())));
2208*cdf0e10cSrcweir 						}
2209*cdf0e10cSrcweir 						catch(const Exception& )
2210*cdf0e10cSrcweir 						{
2211*cdf0e10cSrcweir                             DBG_UNHANDLED_EXCEPTION();
2212*cdf0e10cSrcweir 						}
2213*cdf0e10cSrcweir 					}
2214*cdf0e10cSrcweir 					else
2215*cdf0e10cSrcweir 						bTryAgain = sal_False;
2216*cdf0e10cSrcweir 				}
2217*cdf0e10cSrcweir 			}
2218*cdf0e10cSrcweir 		}
2219*cdf0e10cSrcweir 	}
2220*cdf0e10cSrcweir 	catch(const Exception& )
2221*cdf0e10cSrcweir 	{
2222*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
2223*cdf0e10cSrcweir 	}
2224*cdf0e10cSrcweir }
2225*cdf0e10cSrcweir 
2226*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2227*cdf0e10cSrcweir void OApplicationController::onSelectionChanged()
2228*cdf0e10cSrcweir {
2229*cdf0e10cSrcweir 	InvalidateAll();
2230*cdf0e10cSrcweir 
2231*cdf0e10cSrcweir     SelectionGuard aSelGuard( *m_pSelectionNotifier );
2232*cdf0e10cSrcweir 
2233*cdf0e10cSrcweir 	OApplicationView* pView = getContainer();
2234*cdf0e10cSrcweir     if ( !pView )
2235*cdf0e10cSrcweir         return;
2236*cdf0e10cSrcweir 
2237*cdf0e10cSrcweir     if ( pView->getSelectionCount() == 1 )
2238*cdf0e10cSrcweir     {
2239*cdf0e10cSrcweir         const ElementType eType = pView->getElementType();
2240*cdf0e10cSrcweir   	    if ( pView->isALeafSelected() )
2241*cdf0e10cSrcweir         {
2242*cdf0e10cSrcweir             const ::rtl::OUString sName = pView->getQualifiedName( NULL /* means 'first selected' */ );
2243*cdf0e10cSrcweir             showPreviewFor( eType, sName );
2244*cdf0e10cSrcweir         }
2245*cdf0e10cSrcweir     }
2246*cdf0e10cSrcweir }
2247*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2248*cdf0e10cSrcweir void OApplicationController::showPreviewFor(const ElementType _eType,const ::rtl::OUString& _sName)
2249*cdf0e10cSrcweir {
2250*cdf0e10cSrcweir     if ( m_ePreviewMode == E_PREVIEWNONE )
2251*cdf0e10cSrcweir         return;
2252*cdf0e10cSrcweir 
2253*cdf0e10cSrcweir     OApplicationView* pView = getContainer();
2254*cdf0e10cSrcweir     if ( !pView )
2255*cdf0e10cSrcweir         return;
2256*cdf0e10cSrcweir 
2257*cdf0e10cSrcweir 	try
2258*cdf0e10cSrcweir 	{
2259*cdf0e10cSrcweir 		switch( _eType )
2260*cdf0e10cSrcweir 		{
2261*cdf0e10cSrcweir 			case E_FORM:
2262*cdf0e10cSrcweir 			case E_REPORT:
2263*cdf0e10cSrcweir             {
2264*cdf0e10cSrcweir 				Reference< XHierarchicalNameAccess > xContainer( getElements( _eType ), UNO_QUERY_THROW );
2265*cdf0e10cSrcweir                 Reference< XContent> xContent( xContainer->getByHierarchicalName( _sName ), UNO_QUERY_THROW );
2266*cdf0e10cSrcweir 	            pView->showPreview( xContent );
2267*cdf0e10cSrcweir             }
2268*cdf0e10cSrcweir 			break;
2269*cdf0e10cSrcweir 
2270*cdf0e10cSrcweir             case E_TABLE:
2271*cdf0e10cSrcweir 			case E_QUERY:
2272*cdf0e10cSrcweir                 {
2273*cdf0e10cSrcweir                     SharedConnection xConnection( ensureConnection() );
2274*cdf0e10cSrcweir 					if ( xConnection.is() )
2275*cdf0e10cSrcweir 						pView->showPreview( getDatabaseName(), xConnection, _sName, _eType == E_TABLE );
2276*cdf0e10cSrcweir                 }
2277*cdf0e10cSrcweir 				return;
2278*cdf0e10cSrcweir 
2279*cdf0e10cSrcweir             default:
2280*cdf0e10cSrcweir                 OSL_ENSURE( false, "OApplicationController::showPreviewFor: unexpected element type!" );
2281*cdf0e10cSrcweir                 break;
2282*cdf0e10cSrcweir 		}
2283*cdf0e10cSrcweir 	}
2284*cdf0e10cSrcweir 	catch( const SQLException& )
2285*cdf0e10cSrcweir 	{
2286*cdf0e10cSrcweir         showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
2287*cdf0e10cSrcweir 	}
2288*cdf0e10cSrcweir 	catch(const Exception& )
2289*cdf0e10cSrcweir 	{
2290*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
2291*cdf0e10cSrcweir 	}
2292*cdf0e10cSrcweir }
2293*cdf0e10cSrcweir 
2294*cdf0e10cSrcweir //------------------------------------------------------------------------------
2295*cdf0e10cSrcweir IMPL_LINK( OApplicationController, OnClipboardChanged, void*, EMPTYARG )
2296*cdf0e10cSrcweir {
2297*cdf0e10cSrcweir 	return OnInvalidateClipboard( NULL );
2298*cdf0e10cSrcweir }
2299*cdf0e10cSrcweir //------------------------------------------------------------------------------
2300*cdf0e10cSrcweir IMPL_LINK(OApplicationController, OnInvalidateClipboard, void*, EMPTYARG)
2301*cdf0e10cSrcweir {
2302*cdf0e10cSrcweir 	InvalidateFeature(ID_BROWSER_CUT);
2303*cdf0e10cSrcweir 	InvalidateFeature(ID_BROWSER_COPY);
2304*cdf0e10cSrcweir 	InvalidateFeature(ID_BROWSER_PASTE);
2305*cdf0e10cSrcweir 	InvalidateFeature(SID_DB_APP_PASTE_SPECIAL);
2306*cdf0e10cSrcweir 	return 0L;
2307*cdf0e10cSrcweir }
2308*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2309*cdf0e10cSrcweir void OApplicationController::onCutEntry()
2310*cdf0e10cSrcweir {
2311*cdf0e10cSrcweir }
2312*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2313*cdf0e10cSrcweir void OApplicationController::onCopyEntry()
2314*cdf0e10cSrcweir {
2315*cdf0e10cSrcweir 	Execute(ID_BROWSER_COPY,Sequence<PropertyValue>());
2316*cdf0e10cSrcweir }
2317*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2318*cdf0e10cSrcweir void OApplicationController::onPasteEntry()
2319*cdf0e10cSrcweir {
2320*cdf0e10cSrcweir 	Execute(ID_BROWSER_PASTE,Sequence<PropertyValue>());
2321*cdf0e10cSrcweir }
2322*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2323*cdf0e10cSrcweir void OApplicationController::onDeleteEntry()
2324*cdf0e10cSrcweir {
2325*cdf0e10cSrcweir 	ElementType eType = getContainer()->getElementType();
2326*cdf0e10cSrcweir 	sal_uInt16 nId = 0;
2327*cdf0e10cSrcweir 	switch(eType)
2328*cdf0e10cSrcweir 	{
2329*cdf0e10cSrcweir 		case E_TABLE:
2330*cdf0e10cSrcweir 			nId = SID_DB_APP_TABLE_DELETE;
2331*cdf0e10cSrcweir 			break;
2332*cdf0e10cSrcweir 		case E_QUERY:
2333*cdf0e10cSrcweir 			nId = SID_DB_APP_QUERY_DELETE;
2334*cdf0e10cSrcweir 			break;
2335*cdf0e10cSrcweir 		case E_FORM:
2336*cdf0e10cSrcweir 			nId = SID_DB_APP_FORM_DELETE;
2337*cdf0e10cSrcweir 			break;
2338*cdf0e10cSrcweir 		case E_REPORT:
2339*cdf0e10cSrcweir 			nId = SID_DB_APP_REPORT_DELETE;
2340*cdf0e10cSrcweir 			break;
2341*cdf0e10cSrcweir 		default:
2342*cdf0e10cSrcweir 			OSL_ENSURE(0,"Invalid ElementType!");
2343*cdf0e10cSrcweir 			break;
2344*cdf0e10cSrcweir 	}
2345*cdf0e10cSrcweir 	executeChecked(nId,Sequence<PropertyValue>());
2346*cdf0e10cSrcweir }
2347*cdf0e10cSrcweir 
2348*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2349*cdf0e10cSrcweir void OApplicationController::executeUnChecked(const URL& _rCommand, const Sequence< PropertyValue>& aArgs)
2350*cdf0e10cSrcweir {
2351*cdf0e10cSrcweir     OApplicationController_CBASE::executeUnChecked( _rCommand, aArgs );
2352*cdf0e10cSrcweir }
2353*cdf0e10cSrcweir 
2354*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2355*cdf0e10cSrcweir void OApplicationController::executeChecked(const URL& _rCommand, const Sequence< PropertyValue>& aArgs)
2356*cdf0e10cSrcweir {
2357*cdf0e10cSrcweir     OApplicationController_CBASE::executeChecked( _rCommand, aArgs );
2358*cdf0e10cSrcweir }
2359*cdf0e10cSrcweir 
2360*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2361*cdf0e10cSrcweir void OApplicationController::executeUnChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue>& aArgs)
2362*cdf0e10cSrcweir {
2363*cdf0e10cSrcweir     OApplicationController_CBASE::executeUnChecked( _nCommandId, aArgs );
2364*cdf0e10cSrcweir }
2365*cdf0e10cSrcweir 
2366*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2367*cdf0e10cSrcweir void OApplicationController::executeChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue>& aArgs)
2368*cdf0e10cSrcweir {
2369*cdf0e10cSrcweir     OApplicationController_CBASE::executeChecked( _nCommandId, aArgs );
2370*cdf0e10cSrcweir }
2371*cdf0e10cSrcweir 
2372*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2373*cdf0e10cSrcweir sal_Bool OApplicationController::isCommandEnabled(sal_uInt16 _nCommandId) const
2374*cdf0e10cSrcweir {
2375*cdf0e10cSrcweir     return OApplicationController_CBASE::isCommandEnabled( _nCommandId );
2376*cdf0e10cSrcweir }
2377*cdf0e10cSrcweir 
2378*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2379*cdf0e10cSrcweir sal_Bool OApplicationController::isCommandEnabled( const ::rtl::OUString& _rCompleteCommandURL ) const
2380*cdf0e10cSrcweir {
2381*cdf0e10cSrcweir     return OApplicationController_CBASE::isCommandEnabled( _rCompleteCommandURL );
2382*cdf0e10cSrcweir }
2383*cdf0e10cSrcweir 
2384*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2385*cdf0e10cSrcweir sal_uInt16 OApplicationController::registerCommandURL( const ::rtl::OUString& _rCompleteCommandURL )
2386*cdf0e10cSrcweir {
2387*cdf0e10cSrcweir     return OApplicationController_CBASE::registerCommandURL( _rCompleteCommandURL );
2388*cdf0e10cSrcweir }
2389*cdf0e10cSrcweir 
2390*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2391*cdf0e10cSrcweir void OApplicationController::notifyHiContrastChanged()
2392*cdf0e10cSrcweir {
2393*cdf0e10cSrcweir     OApplicationController_CBASE::notifyHiContrastChanged();
2394*cdf0e10cSrcweir }
2395*cdf0e10cSrcweir 
2396*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2397*cdf0e10cSrcweir Reference< XController > OApplicationController::getXController() throw( RuntimeException )
2398*cdf0e10cSrcweir {
2399*cdf0e10cSrcweir     return OApplicationController_CBASE::getXController();
2400*cdf0e10cSrcweir }
2401*cdf0e10cSrcweir 
2402*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2403*cdf0e10cSrcweir bool OApplicationController::interceptUserInput( const NotifyEvent& _rEvent )
2404*cdf0e10cSrcweir {
2405*cdf0e10cSrcweir     return OApplicationController_CBASE::interceptUserInput( _rEvent );
2406*cdf0e10cSrcweir }
2407*cdf0e10cSrcweir 
2408*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2409*cdf0e10cSrcweir PopupMenu* OApplicationController::getContextMenu( Control& /*_rControl*/ ) const
2410*cdf0e10cSrcweir {
2411*cdf0e10cSrcweir     return new PopupMenu( ModuleRes( RID_MENU_APP_EDIT ) );
2412*cdf0e10cSrcweir }
2413*cdf0e10cSrcweir 
2414*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2415*cdf0e10cSrcweir IController& OApplicationController::getCommandController()
2416*cdf0e10cSrcweir {
2417*cdf0e10cSrcweir     return *static_cast< IApplicationController* >( this );
2418*cdf0e10cSrcweir }
2419*cdf0e10cSrcweir 
2420*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2421*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* OApplicationController::getContextMenuInterceptors()
2422*cdf0e10cSrcweir {
2423*cdf0e10cSrcweir     return &m_aContextMenuInterceptors;
2424*cdf0e10cSrcweir }
2425*cdf0e10cSrcweir 
2426*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2427*cdf0e10cSrcweir Any OApplicationController::getCurrentSelection( Control& _rControl ) const
2428*cdf0e10cSrcweir {
2429*cdf0e10cSrcweir     Sequence< NamedDatabaseObject > aSelection;
2430*cdf0e10cSrcweir 	getContainer()->describeCurrentSelectionForControl( _rControl, aSelection );
2431*cdf0e10cSrcweir     return makeAny( aSelection );
2432*cdf0e10cSrcweir }
2433*cdf0e10cSrcweir 
2434*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2435*cdf0e10cSrcweir sal_Bool OApplicationController::requestQuickHelp( const SvLBoxEntry* /*_pEntry*/, String& /*_rText*/ ) const
2436*cdf0e10cSrcweir {
2437*cdf0e10cSrcweir     return sal_False;
2438*cdf0e10cSrcweir }
2439*cdf0e10cSrcweir 
2440*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2441*cdf0e10cSrcweir sal_Bool OApplicationController::requestDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
2442*cdf0e10cSrcweir {
2443*cdf0e10cSrcweir 	TransferableHelper* pTransfer = NULL;
2444*cdf0e10cSrcweir 	if ( getContainer() && getContainer()->getSelectionCount() )
2445*cdf0e10cSrcweir 	{
2446*cdf0e10cSrcweir 		try
2447*cdf0e10cSrcweir 		{
2448*cdf0e10cSrcweir 			pTransfer = copyObject( );
2449*cdf0e10cSrcweir 			Reference< XTransferable> xEnsureDelete = pTransfer;
2450*cdf0e10cSrcweir 
2451*cdf0e10cSrcweir 			if ( pTransfer && getContainer()->getDetailView() )
2452*cdf0e10cSrcweir 			{
2453*cdf0e10cSrcweir 				ElementType eType = getContainer()->getElementType();
2454*cdf0e10cSrcweir 				pTransfer->StartDrag( getContainer()->getDetailView()->getTreeWindow(), ((eType == E_FORM || eType == E_REPORT) ? DND_ACTION_COPYMOVE : DND_ACTION_COPY) );
2455*cdf0e10cSrcweir 			}
2456*cdf0e10cSrcweir 		}
2457*cdf0e10cSrcweir 		catch(const Exception& )
2458*cdf0e10cSrcweir 		{
2459*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
2460*cdf0e10cSrcweir 		}
2461*cdf0e10cSrcweir 	}
2462*cdf0e10cSrcweir 
2463*cdf0e10cSrcweir 	return NULL != pTransfer;
2464*cdf0e10cSrcweir }
2465*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2466*cdf0e10cSrcweir sal_Int8 OApplicationController::queryDrop( const AcceptDropEvent& _rEvt, const DataFlavorExVector& _rFlavors )
2467*cdf0e10cSrcweir {
2468*cdf0e10cSrcweir 	sal_Int8 nActionAskedFor = _rEvt.mnAction;
2469*cdf0e10cSrcweir 	// check if we're a table or query container
2470*cdf0e10cSrcweir 	OApplicationView* pView = getContainer();
2471*cdf0e10cSrcweir 	if ( pView && !isDataSourceReadOnly() )
2472*cdf0e10cSrcweir 	{
2473*cdf0e10cSrcweir 		ElementType eType = pView->getElementType();
2474*cdf0e10cSrcweir 		if ( eType != E_NONE && (eType != E_TABLE || !isConnectionReadOnly()) )
2475*cdf0e10cSrcweir 		{
2476*cdf0e10cSrcweir 			// check for the concrete type
2477*cdf0e10cSrcweir 			if(::std::find_if(_rFlavors.begin(),_rFlavors.end(),TAppSupportedSotFunctor(eType,sal_True)) != _rFlavors.end())
2478*cdf0e10cSrcweir 				return DND_ACTION_COPY;
2479*cdf0e10cSrcweir 			if ( eType == E_FORM || eType == E_REPORT )
2480*cdf0e10cSrcweir 			{
2481*cdf0e10cSrcweir 				sal_Int8 nAction = OComponentTransferable::canExtractComponentDescriptor(_rFlavors,eType == E_FORM) ? DND_ACTION_COPY : DND_ACTION_NONE;
2482*cdf0e10cSrcweir 				if ( nAction != DND_ACTION_NONE )
2483*cdf0e10cSrcweir 				{
2484*cdf0e10cSrcweir 					SvLBoxEntry* pHitEntry = pView->getEntry(_rEvt.maPosPixel);
2485*cdf0e10cSrcweir 					::rtl::OUString sName;
2486*cdf0e10cSrcweir 					if ( pHitEntry )
2487*cdf0e10cSrcweir 					{
2488*cdf0e10cSrcweir 						sName = pView->getQualifiedName( pHitEntry );
2489*cdf0e10cSrcweir 						if ( sName.getLength() )
2490*cdf0e10cSrcweir 						{
2491*cdf0e10cSrcweir 							Reference< XHierarchicalNameAccess > xContainer(getElements(pView->getElementType()),UNO_QUERY);
2492*cdf0e10cSrcweir 							if ( xContainer.is() && xContainer->hasByHierarchicalName(sName) )
2493*cdf0e10cSrcweir 							{
2494*cdf0e10cSrcweir 								Reference< XHierarchicalNameAccess > xHitObject(xContainer->getByHierarchicalName(sName),UNO_QUERY);
2495*cdf0e10cSrcweir 								if ( xHitObject.is() )
2496*cdf0e10cSrcweir 									nAction = nActionAskedFor & DND_ACTION_COPYMOVE;
2497*cdf0e10cSrcweir 							}
2498*cdf0e10cSrcweir 							else
2499*cdf0e10cSrcweir 								nAction = DND_ACTION_NONE;
2500*cdf0e10cSrcweir 						}
2501*cdf0e10cSrcweir 					}
2502*cdf0e10cSrcweir 					/*else
2503*cdf0e10cSrcweir 						nAction = nActionAskedFor & DND_ACTION_COPYMOVE;
2504*cdf0e10cSrcweir                     */
2505*cdf0e10cSrcweir 				}
2506*cdf0e10cSrcweir 				return nAction;
2507*cdf0e10cSrcweir 			}
2508*cdf0e10cSrcweir 		}
2509*cdf0e10cSrcweir 	}
2510*cdf0e10cSrcweir 
2511*cdf0e10cSrcweir 	return DND_ACTION_NONE;
2512*cdf0e10cSrcweir }
2513*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2514*cdf0e10cSrcweir sal_Int8 OApplicationController::executeDrop( const ExecuteDropEvent& _rEvt )
2515*cdf0e10cSrcweir {
2516*cdf0e10cSrcweir 	OApplicationView* pView = getContainer();
2517*cdf0e10cSrcweir 	if ( !pView || pView->getElementType() == E_NONE )
2518*cdf0e10cSrcweir 	{
2519*cdf0e10cSrcweir 		DBG_ERROR("OApplicationController::executeDrop: what the hell did queryDrop do?");
2520*cdf0e10cSrcweir 			// queryDrop shoud not have allowed us to reach this situation ....
2521*cdf0e10cSrcweir 		return DND_ACTION_NONE;
2522*cdf0e10cSrcweir 	}
2523*cdf0e10cSrcweir 
2524*cdf0e10cSrcweir 	// a TransferableDataHelper for accessing the dropped data
2525*cdf0e10cSrcweir 	TransferableDataHelper aDroppedData(_rEvt.maDropEvent.Transferable);
2526*cdf0e10cSrcweir 
2527*cdf0e10cSrcweir 
2528*cdf0e10cSrcweir 	// reset the data of the previous async drop (if any)
2529*cdf0e10cSrcweir 	if ( m_nAsyncDrop )
2530*cdf0e10cSrcweir 		Application::RemoveUserEvent(m_nAsyncDrop);
2531*cdf0e10cSrcweir 
2532*cdf0e10cSrcweir 
2533*cdf0e10cSrcweir 	m_nAsyncDrop = 0;
2534*cdf0e10cSrcweir 	m_aAsyncDrop.aDroppedData.clear();
2535*cdf0e10cSrcweir 	m_aAsyncDrop.nType			= pView->getElementType();
2536*cdf0e10cSrcweir 	m_aAsyncDrop.nAction		= _rEvt.mnAction;
2537*cdf0e10cSrcweir 	m_aAsyncDrop.bError			= sal_False;
2538*cdf0e10cSrcweir 	m_aAsyncDrop.bHtml			= sal_False;
2539*cdf0e10cSrcweir 	m_aAsyncDrop.aUrl			= ::rtl::OUString();
2540*cdf0e10cSrcweir 
2541*cdf0e10cSrcweir 
2542*cdf0e10cSrcweir 	// loop through the available formats and see what we can do ...
2543*cdf0e10cSrcweir 	// first we have to check if it is our own format, if not we have to copy the stream :-(
2544*cdf0e10cSrcweir 	if ( ODataAccessObjectTransferable::canExtractObjectDescriptor(aDroppedData.GetDataFlavorExVector()) )
2545*cdf0e10cSrcweir 	{
2546*cdf0e10cSrcweir 		m_aAsyncDrop.aDroppedData	= ODataAccessObjectTransferable::extractObjectDescriptor(aDroppedData);
2547*cdf0e10cSrcweir 
2548*cdf0e10cSrcweir 		// asyncron because we some dialogs and we aren't allowed to show them while in D&D
2549*cdf0e10cSrcweir 		m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
2550*cdf0e10cSrcweir 		return DND_ACTION_COPY;
2551*cdf0e10cSrcweir 	}
2552*cdf0e10cSrcweir 	else if ( OComponentTransferable::canExtractComponentDescriptor(aDroppedData.GetDataFlavorExVector(),m_aAsyncDrop.nType == E_FORM) )
2553*cdf0e10cSrcweir 	{
2554*cdf0e10cSrcweir 		m_aAsyncDrop.aDroppedData = OComponentTransferable::extractComponentDescriptor(aDroppedData);
2555*cdf0e10cSrcweir 		SvLBoxEntry* pHitEntry = pView->getEntry(_rEvt.maPosPixel);
2556*cdf0e10cSrcweir 		if ( pHitEntry )
2557*cdf0e10cSrcweir 			m_aAsyncDrop.aUrl = pView->getQualifiedName( pHitEntry );
2558*cdf0e10cSrcweir 
2559*cdf0e10cSrcweir 		sal_Int8 nAction = _rEvt.mnAction;
2560*cdf0e10cSrcweir 		Reference<XContent> xContent;
2561*cdf0e10cSrcweir 		m_aAsyncDrop.aDroppedData[daComponent] >>= xContent;
2562*cdf0e10cSrcweir 		if ( xContent.is() )
2563*cdf0e10cSrcweir 		{
2564*cdf0e10cSrcweir 			::rtl::OUString sName = xContent->getIdentifier()->getContentIdentifier();
2565*cdf0e10cSrcweir 			sal_Int32 nIndex = 0;
2566*cdf0e10cSrcweir 			sName = sName.copy(sName.getToken(0,'/',nIndex).getLength() + 1);
2567*cdf0e10cSrcweir 			if ( m_aAsyncDrop.aUrl.Len() >= sName.getLength() && 0 == sName.compareTo(m_aAsyncDrop.aUrl,sName.getLength()) )
2568*cdf0e10cSrcweir 			{
2569*cdf0e10cSrcweir 				m_aAsyncDrop.aDroppedData.clear();
2570*cdf0e10cSrcweir 				return DND_ACTION_NONE;
2571*cdf0e10cSrcweir 			}
2572*cdf0e10cSrcweir 
2573*cdf0e10cSrcweir 			// check if move is allowed, if another object with the same name exists only copy is allowed
2574*cdf0e10cSrcweir 			Reference< XHierarchicalNameAccess > xContainer(getElements(m_aAsyncDrop.nType),UNO_QUERY);
2575*cdf0e10cSrcweir 			Reference<XNameAccess> xNameAccess(xContainer,UNO_QUERY);
2576*cdf0e10cSrcweir 
2577*cdf0e10cSrcweir 			if ( m_aAsyncDrop.aUrl.Len() && xContainer.is() && xContainer->hasByHierarchicalName(m_aAsyncDrop.aUrl) )
2578*cdf0e10cSrcweir 				xNameAccess.set(xContainer->getByHierarchicalName(m_aAsyncDrop.aUrl),UNO_QUERY);
2579*cdf0e10cSrcweir 
2580*cdf0e10cSrcweir 			if ( xNameAccess.is() )
2581*cdf0e10cSrcweir 			{
2582*cdf0e10cSrcweir 				Reference<XPropertySet> xProp(xContent,UNO_QUERY);
2583*cdf0e10cSrcweir 				if ( xProp.is() )
2584*cdf0e10cSrcweir 				{
2585*cdf0e10cSrcweir 					xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
2586*cdf0e10cSrcweir 					if ( xNameAccess.is() && xNameAccess->hasByName(sName) )
2587*cdf0e10cSrcweir 						nAction &= ~DND_ACTION_MOVE;
2588*cdf0e10cSrcweir 				}
2589*cdf0e10cSrcweir 				else
2590*cdf0e10cSrcweir 					nAction &= ~DND_ACTION_MOVE;
2591*cdf0e10cSrcweir 			}
2592*cdf0e10cSrcweir 		}
2593*cdf0e10cSrcweir 		if ( nAction != DND_ACTION_NONE )
2594*cdf0e10cSrcweir 		{
2595*cdf0e10cSrcweir 			m_aAsyncDrop.nAction = nAction;
2596*cdf0e10cSrcweir 			// asyncron because we some dialogs and we aren't allowed to show them while in D&D
2597*cdf0e10cSrcweir 			m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
2598*cdf0e10cSrcweir 		}
2599*cdf0e10cSrcweir 		else
2600*cdf0e10cSrcweir 			m_aAsyncDrop.aDroppedData.clear();
2601*cdf0e10cSrcweir 		return nAction;
2602*cdf0e10cSrcweir 	}
2603*cdf0e10cSrcweir 	else
2604*cdf0e10cSrcweir 	{
2605*cdf0e10cSrcweir         SharedConnection xConnection( ensureConnection() );
2606*cdf0e10cSrcweir         if ( xConnection.is() && m_aTableCopyHelper.copyTagTable( aDroppedData, m_aAsyncDrop, xConnection ) )
2607*cdf0e10cSrcweir         {
2608*cdf0e10cSrcweir 			// asyncron because we some dialogs and we aren't allowed to show them while in D&D
2609*cdf0e10cSrcweir 			m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
2610*cdf0e10cSrcweir 			return DND_ACTION_COPY;
2611*cdf0e10cSrcweir 		}
2612*cdf0e10cSrcweir 	}
2613*cdf0e10cSrcweir 
2614*cdf0e10cSrcweir 	return DND_ACTION_NONE;
2615*cdf0e10cSrcweir }
2616*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2617*cdf0e10cSrcweir Reference< XModel >  SAL_CALL OApplicationController::getModel(void) throw( RuntimeException )
2618*cdf0e10cSrcweir {
2619*cdf0e10cSrcweir 	return m_xModel;
2620*cdf0e10cSrcweir }
2621*cdf0e10cSrcweir 
2622*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2623*cdf0e10cSrcweir void OApplicationController::onAttachedFrame()
2624*cdf0e10cSrcweir {
2625*cdf0e10cSrcweir     sal_Int32 nConnectedControllers( 0 );
2626*cdf0e10cSrcweir     try
2627*cdf0e10cSrcweir     {
2628*cdf0e10cSrcweir         Reference< XModel2 > xModel( m_xModel, UNO_QUERY_THROW );
2629*cdf0e10cSrcweir         Reference< XEnumeration > xEnumControllers( xModel->getControllers(), UNO_SET_THROW );
2630*cdf0e10cSrcweir         while ( xEnumControllers->hasMoreElements() )
2631*cdf0e10cSrcweir         {
2632*cdf0e10cSrcweir             Reference< XController > xController( xEnumControllers->nextElement(), UNO_QUERY_THROW );
2633*cdf0e10cSrcweir             ++nConnectedControllers;
2634*cdf0e10cSrcweir         }
2635*cdf0e10cSrcweir     }
2636*cdf0e10cSrcweir     catch( const Exception& )
2637*cdf0e10cSrcweir     {
2638*cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
2639*cdf0e10cSrcweir     }
2640*cdf0e10cSrcweir 
2641*cdf0e10cSrcweir     if ( nConnectedControllers > 1 )
2642*cdf0e10cSrcweir     {   // we are not the first connected controller, there were already others
2643*cdf0e10cSrcweir         return;
2644*cdf0e10cSrcweir     }
2645*cdf0e10cSrcweir 
2646*cdf0e10cSrcweir     m_aControllerConnectedEvent.Call();
2647*cdf0e10cSrcweir }
2648*cdf0e10cSrcweir 
2649*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2650*cdf0e10cSrcweir IMPL_LINK( OApplicationController, OnFirstControllerConnected, void*, /**/ )
2651*cdf0e10cSrcweir {
2652*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
2653*cdf0e10cSrcweir 
2654*cdf0e10cSrcweir     if ( !m_xModel.is() )
2655*cdf0e10cSrcweir     {
2656*cdf0e10cSrcweir         OSL_ENSURE( false, "OApplicationController::OnFirstControllerConnected: too late!" );
2657*cdf0e10cSrcweir     }
2658*cdf0e10cSrcweir 
2659*cdf0e10cSrcweir     // if we have forms or reports which contain macros/scripts, then show a warning
2660*cdf0e10cSrcweir     // which suggests the user to migrate them to the database document
2661*cdf0e10cSrcweir     Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
2662*cdf0e10cSrcweir     if ( xDocumentScripts.is() )
2663*cdf0e10cSrcweir     {
2664*cdf0e10cSrcweir         // no need to show this warning, obviously the document supports embedding scripts
2665*cdf0e10cSrcweir         // into itself, so there are no "old-style" forms/reports which have macros/scripts
2666*cdf0e10cSrcweir         // themselves
2667*cdf0e10cSrcweir         return 0L;
2668*cdf0e10cSrcweir     }
2669*cdf0e10cSrcweir 
2670*cdf0e10cSrcweir     try
2671*cdf0e10cSrcweir     {
2672*cdf0e10cSrcweir         // If the migration just happened, but was not successful, the document is reloaded.
2673*cdf0e10cSrcweir         // In this case, we should not show the warning, again.
2674*cdf0e10cSrcweir         ::comphelper::NamedValueCollection aModelArgs( m_xModel->getArgs() );
2675*cdf0e10cSrcweir         if ( aModelArgs.getOrDefault( "SuppressMigrationWarning", sal_False ) )
2676*cdf0e10cSrcweir             return 0L;
2677*cdf0e10cSrcweir 
2678*cdf0e10cSrcweir         // also, if the document is read-only, then no migration is possible, and the
2679*cdf0e10cSrcweir         // respective menu entry is hidden. So, don't show the warning in this case, too.
2680*cdf0e10cSrcweir         if ( Reference< XStorable >( m_xModel, UNO_QUERY_THROW )->isReadonly() )
2681*cdf0e10cSrcweir             return 0L;
2682*cdf0e10cSrcweir 
2683*cdf0e10cSrcweir         SQLWarning aWarning;
2684*cdf0e10cSrcweir         aWarning.Message = String( ModuleRes( STR_SUB_DOCS_WITH_SCRIPTS ) );
2685*cdf0e10cSrcweir         SQLException aDetail;
2686*cdf0e10cSrcweir         aDetail.Message = String( ModuleRes( STR_SUB_DOCS_WITH_SCRIPTS_DETAIL ) );
2687*cdf0e10cSrcweir         aWarning.NextException <<= aDetail;
2688*cdf0e10cSrcweir 
2689*cdf0e10cSrcweir         ::comphelper::ComponentContext aContext( getORB() );
2690*cdf0e10cSrcweir         Sequence< Any > aArgs(1);
2691*cdf0e10cSrcweir         aArgs[0] <<= NamedValue( PROPERTY_SQLEXCEPTION, makeAny( aWarning ) );
2692*cdf0e10cSrcweir         Reference< XExecutableDialog > xDialog(
2693*cdf0e10cSrcweir             aContext.createComponentWithArguments( "com.sun.star.sdb.ErrorMessageDialog", aArgs ),
2694*cdf0e10cSrcweir             UNO_QUERY_THROW );
2695*cdf0e10cSrcweir         xDialog->execute();
2696*cdf0e10cSrcweir     }
2697*cdf0e10cSrcweir     catch( const Exception& )
2698*cdf0e10cSrcweir     {
2699*cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
2700*cdf0e10cSrcweir     }
2701*cdf0e10cSrcweir 
2702*cdf0e10cSrcweir     return 1L;
2703*cdf0e10cSrcweir }
2704*cdf0e10cSrcweir 
2705*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2706*cdf0e10cSrcweir void SAL_CALL OApplicationController::attachFrame( const Reference< XFrame > & i_rxFrame ) throw( RuntimeException )
2707*cdf0e10cSrcweir {
2708*cdf0e10cSrcweir     OApplicationController_CBASE::attachFrame( i_rxFrame );
2709*cdf0e10cSrcweir     if ( getFrame().is() )
2710*cdf0e10cSrcweir         onAttachedFrame();
2711*cdf0e10cSrcweir }
2712*cdf0e10cSrcweir 
2713*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2714*cdf0e10cSrcweir sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > & _rxModel) throw( RuntimeException )
2715*cdf0e10cSrcweir {
2716*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
2717*cdf0e10cSrcweir     const Reference< XOfficeDatabaseDocument > xOfficeDoc( _rxModel, UNO_QUERY );
2718*cdf0e10cSrcweir     const Reference< XModifiable > xDocModify( _rxModel, UNO_QUERY );
2719*cdf0e10cSrcweir     if ( ( !xOfficeDoc.is() || !xDocModify.is() ) && _rxModel.is() )
2720*cdf0e10cSrcweir     {
2721*cdf0e10cSrcweir         DBG_ERROR( "OApplicationController::attachModel: invalid model!" );
2722*cdf0e10cSrcweir         return sal_False;
2723*cdf0e10cSrcweir     }
2724*cdf0e10cSrcweir 
2725*cdf0e10cSrcweir     if ( m_xModel.is() && ( m_xModel != _rxModel ) && ( _rxModel.is() ) )
2726*cdf0e10cSrcweir     {
2727*cdf0e10cSrcweir         OSL_ENSURE( false, "OApplicationController::attachModel: missing implementation: setting a new model while we have another one!" );
2728*cdf0e10cSrcweir         // we'd need to completely update our view here, close sub components, and the like
2729*cdf0e10cSrcweir         return sal_False;
2730*cdf0e10cSrcweir     }
2731*cdf0e10cSrcweir 
2732*cdf0e10cSrcweir     const ::rtl::OUString aPropertyNames[] =
2733*cdf0e10cSrcweir     {
2734*cdf0e10cSrcweir         PROPERTY_URL, PROPERTY_USER
2735*cdf0e10cSrcweir     };
2736*cdf0e10cSrcweir 
2737*cdf0e10cSrcweir     // disconnect from old model
2738*cdf0e10cSrcweir     try
2739*cdf0e10cSrcweir     {
2740*cdf0e10cSrcweir         if ( m_xDataSource.is() )
2741*cdf0e10cSrcweir         {
2742*cdf0e10cSrcweir             for ( size_t i=0; i < sizeof( aPropertyNames ) / sizeof( aPropertyNames[0] ); ++i )
2743*cdf0e10cSrcweir             {
2744*cdf0e10cSrcweir                 m_xDataSource->removePropertyChangeListener( aPropertyNames[i], this );
2745*cdf0e10cSrcweir             }
2746*cdf0e10cSrcweir         }
2747*cdf0e10cSrcweir 
2748*cdf0e10cSrcweir 		Reference< XModifyBroadcaster >  xBroadcaster( m_xModel, UNO_QUERY );
2749*cdf0e10cSrcweir         if ( xBroadcaster.is() )
2750*cdf0e10cSrcweir 		    xBroadcaster->removeModifyListener( this );
2751*cdf0e10cSrcweir     }
2752*cdf0e10cSrcweir     catch( const Exception& )
2753*cdf0e10cSrcweir     {
2754*cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
2755*cdf0e10cSrcweir     }
2756*cdf0e10cSrcweir 
2757*cdf0e10cSrcweir     m_xModel = _rxModel;
2758*cdf0e10cSrcweir     m_xDocumentModify = xDocModify;
2759*cdf0e10cSrcweir     m_xDataSource.set( xOfficeDoc.is() ? xOfficeDoc->getDataSource() : Reference< XDataSource >(), UNO_QUERY );
2760*cdf0e10cSrcweir 
2761*cdf0e10cSrcweir     // connect to new model
2762*cdf0e10cSrcweir     try
2763*cdf0e10cSrcweir     {
2764*cdf0e10cSrcweir         if ( m_xDataSource.is() )
2765*cdf0e10cSrcweir         {
2766*cdf0e10cSrcweir             for ( size_t i=0; i < sizeof( aPropertyNames ) / sizeof( aPropertyNames[0] ); ++i )
2767*cdf0e10cSrcweir             {
2768*cdf0e10cSrcweir                 m_xDataSource->addPropertyChangeListener( aPropertyNames[i], this );
2769*cdf0e10cSrcweir             }
2770*cdf0e10cSrcweir         }
2771*cdf0e10cSrcweir 
2772*cdf0e10cSrcweir 		Reference< XModifyBroadcaster >  xBroadcaster( m_xModel, UNO_QUERY_THROW );
2773*cdf0e10cSrcweir 		xBroadcaster->addModifyListener( this );
2774*cdf0e10cSrcweir 
2775*cdf0e10cSrcweir     }
2776*cdf0e10cSrcweir     catch( const Exception& )
2777*cdf0e10cSrcweir     {
2778*cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
2779*cdf0e10cSrcweir     }
2780*cdf0e10cSrcweir 
2781*cdf0e10cSrcweir     // initial preview mode
2782*cdf0e10cSrcweir 	if ( m_xDataSource.is() )
2783*cdf0e10cSrcweir 	{
2784*cdf0e10cSrcweir 		try
2785*cdf0e10cSrcweir 		{
2786*cdf0e10cSrcweir 			// to get the 'modified' for the data source
2787*cdf0e10cSrcweir             ::comphelper::NamedValueCollection aLayoutInfo( m_xDataSource->getPropertyValue( PROPERTY_LAYOUTINFORMATION ) );
2788*cdf0e10cSrcweir             if ( aLayoutInfo.has( (rtl::OUString)INFO_PREVIEW ) )
2789*cdf0e10cSrcweir             {
2790*cdf0e10cSrcweir                 const sal_Int32 nPreviewMode( aLayoutInfo.getOrDefault( (rtl::OUString)INFO_PREVIEW, (sal_Int32)0 ) );
2791*cdf0e10cSrcweir 				m_ePreviewMode = static_cast< PreviewMode >( nPreviewMode );
2792*cdf0e10cSrcweir                 if ( getView() )
2793*cdf0e10cSrcweir                     getContainer()->switchPreview( m_ePreviewMode );
2794*cdf0e10cSrcweir 			}
2795*cdf0e10cSrcweir 		}
2796*cdf0e10cSrcweir 		catch( const Exception& )
2797*cdf0e10cSrcweir 		{
2798*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
2799*cdf0e10cSrcweir 		}
2800*cdf0e10cSrcweir 	}
2801*cdf0e10cSrcweir 
2802*cdf0e10cSrcweir 	return sal_True;
2803*cdf0e10cSrcweir }
2804*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2805*cdf0e10cSrcweir void OApplicationController::containerFound( const Reference< XContainer >& _xContainer)
2806*cdf0e10cSrcweir {
2807*cdf0e10cSrcweir 	try
2808*cdf0e10cSrcweir 	{
2809*cdf0e10cSrcweir 		if ( _xContainer.is() )
2810*cdf0e10cSrcweir 		{
2811*cdf0e10cSrcweir 			m_aCurrentContainers.push_back(_xContainer);
2812*cdf0e10cSrcweir 			_xContainer->addContainerListener(this);
2813*cdf0e10cSrcweir 		}
2814*cdf0e10cSrcweir 	}
2815*cdf0e10cSrcweir 	catch(const Exception&)
2816*cdf0e10cSrcweir 	{
2817*cdf0e10cSrcweir 		DBG_UNHANDLED_EXCEPTION();
2818*cdf0e10cSrcweir 	}
2819*cdf0e10cSrcweir }
2820*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2821*cdf0e10cSrcweir ::rtl::OUString OApplicationController::getCurrentlySelectedName(sal_Int32& _rnCommandType) const
2822*cdf0e10cSrcweir {
2823*cdf0e10cSrcweir     _rnCommandType = ( (getContainer()->getElementType() == E_QUERY)
2824*cdf0e10cSrcweir 								? CommandType::QUERY : ( (getContainer()->getElementType() == E_TABLE) ? CommandType::TABLE : -1 ));
2825*cdf0e10cSrcweir 
2826*cdf0e10cSrcweir 
2827*cdf0e10cSrcweir 	::rtl::OUString sName;
2828*cdf0e10cSrcweir 	if ( _rnCommandType != -1 )
2829*cdf0e10cSrcweir 	{
2830*cdf0e10cSrcweir 		try
2831*cdf0e10cSrcweir 		{
2832*cdf0e10cSrcweir 			sName = getContainer()->getQualifiedName( NULL );
2833*cdf0e10cSrcweir             OSL_ENSURE( sName.getLength(), "OApplicationController::getCurrentlySelectedName: no name given!" );
2834*cdf0e10cSrcweir 		}
2835*cdf0e10cSrcweir 		catch( const Exception& )
2836*cdf0e10cSrcweir 		{
2837*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
2838*cdf0e10cSrcweir 		}
2839*cdf0e10cSrcweir 	}
2840*cdf0e10cSrcweir     return sName;
2841*cdf0e10cSrcweir }
2842*cdf0e10cSrcweir 
2843*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2844*cdf0e10cSrcweir void SAL_CALL OApplicationController::addSelectionChangeListener( const Reference< view::XSelectionChangeListener >& _Listener ) throw (RuntimeException)
2845*cdf0e10cSrcweir {
2846*cdf0e10cSrcweir     m_pSelectionNotifier->addListener( _Listener );
2847*cdf0e10cSrcweir }
2848*cdf0e10cSrcweir 
2849*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2850*cdf0e10cSrcweir void SAL_CALL OApplicationController::removeSelectionChangeListener( const Reference< view::XSelectionChangeListener >& _Listener ) throw (RuntimeException)
2851*cdf0e10cSrcweir {
2852*cdf0e10cSrcweir     m_pSelectionNotifier->removeListener( _Listener );
2853*cdf0e10cSrcweir }
2854*cdf0e10cSrcweir 
2855*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2856*cdf0e10cSrcweir ::sal_Bool SAL_CALL OApplicationController::select( const Any& _aSelection ) throw (IllegalArgumentException, RuntimeException)
2857*cdf0e10cSrcweir {
2858*cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
2859*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
2860*cdf0e10cSrcweir     Sequence< ::rtl::OUString> aSelection;
2861*cdf0e10cSrcweir     if ( !_aSelection.hasValue() || !getView() )
2862*cdf0e10cSrcweir     {
2863*cdf0e10cSrcweir         getContainer()->selectElements(aSelection);
2864*cdf0e10cSrcweir         return sal_True;
2865*cdf0e10cSrcweir     }
2866*cdf0e10cSrcweir 
2867*cdf0e10cSrcweir     // --------------------------------------------------------------
2868*cdf0e10cSrcweir     // BEGIN compatibility
2869*cdf0e10cSrcweir     Sequence< NamedValue > aCurrentSelection;
2870*cdf0e10cSrcweir     if ( (_aSelection >>= aCurrentSelection) && aCurrentSelection.getLength() )
2871*cdf0e10cSrcweir     {
2872*cdf0e10cSrcweir         ElementType eType = E_NONE;
2873*cdf0e10cSrcweir         const NamedValue* pIter = aCurrentSelection.getConstArray();
2874*cdf0e10cSrcweir         const NamedValue* pEnd	= pIter + aCurrentSelection.getLength();
2875*cdf0e10cSrcweir         for(;pIter != pEnd;++pIter)
2876*cdf0e10cSrcweir         {
2877*cdf0e10cSrcweir             if ( pIter->Name.equalsAscii("Type") )
2878*cdf0e10cSrcweir             {
2879*cdf0e10cSrcweir                 sal_Int32 nType = 0;
2880*cdf0e10cSrcweir                 pIter->Value >>= nType;
2881*cdf0e10cSrcweir                 if ( nType < DatabaseObject::TABLE || nType > DatabaseObject::REPORT )
2882*cdf0e10cSrcweir                     throw IllegalArgumentException();
2883*cdf0e10cSrcweir                 eType = static_cast< ElementType >( nType );
2884*cdf0e10cSrcweir             }
2885*cdf0e10cSrcweir             else if ( pIter->Name.equalsAscii("Selection") )
2886*cdf0e10cSrcweir                 pIter->Value >>= aSelection;
2887*cdf0e10cSrcweir         }
2888*cdf0e10cSrcweir 
2889*cdf0e10cSrcweir         m_aSelectContainerEvent.CancelCall();   // just in case the async select request was running
2890*cdf0e10cSrcweir         getContainer()->selectContainer(eType);
2891*cdf0e10cSrcweir         getContainer()->selectElements(aSelection);
2892*cdf0e10cSrcweir         return sal_True;
2893*cdf0e10cSrcweir     }
2894*cdf0e10cSrcweir     // END compatibility
2895*cdf0e10cSrcweir     // --------------------------------------------------------------
2896*cdf0e10cSrcweir 
2897*cdf0e10cSrcweir     Sequence< NamedDatabaseObject > aSelectedObjects;
2898*cdf0e10cSrcweir     if ( !( _aSelection >>= aSelectedObjects ) )
2899*cdf0e10cSrcweir     {
2900*cdf0e10cSrcweir         aSelectedObjects.realloc( 1 );
2901*cdf0e10cSrcweir         if ( !( _aSelection >>= aSelectedObjects[0] ) )
2902*cdf0e10cSrcweir             throw IllegalArgumentException();
2903*cdf0e10cSrcweir     }
2904*cdf0e10cSrcweir 
2905*cdf0e10cSrcweir     SelectionByElementType aSelectedElements;
2906*cdf0e10cSrcweir     ElementType eSelectedCategory = E_NONE;
2907*cdf0e10cSrcweir     for (   const NamedDatabaseObject* pObject = aSelectedObjects.getConstArray();
2908*cdf0e10cSrcweir             pObject != aSelectedObjects.getConstArray() + aSelectedObjects.getLength();
2909*cdf0e10cSrcweir             ++pObject
2910*cdf0e10cSrcweir         )
2911*cdf0e10cSrcweir     {
2912*cdf0e10cSrcweir         switch ( pObject->Type )
2913*cdf0e10cSrcweir         {
2914*cdf0e10cSrcweir             case DatabaseObject::TABLE:
2915*cdf0e10cSrcweir             case DatabaseObjectContainer::SCHEMA:
2916*cdf0e10cSrcweir             case DatabaseObjectContainer::CATALOG:
2917*cdf0e10cSrcweir                 aSelectedElements[ E_TABLE ].push_back( pObject->Name );
2918*cdf0e10cSrcweir                 break;
2919*cdf0e10cSrcweir             case DatabaseObject::QUERY:
2920*cdf0e10cSrcweir                 aSelectedElements[ E_QUERY ].push_back( pObject->Name );
2921*cdf0e10cSrcweir                 break;
2922*cdf0e10cSrcweir             case DatabaseObject::FORM:
2923*cdf0e10cSrcweir             case DatabaseObjectContainer::FORMS_FOLDER:
2924*cdf0e10cSrcweir                 aSelectedElements[ E_FORM ].push_back( pObject->Name );
2925*cdf0e10cSrcweir                 break;
2926*cdf0e10cSrcweir             case DatabaseObject::REPORT:
2927*cdf0e10cSrcweir             case DatabaseObjectContainer::REPORTS_FOLDER:
2928*cdf0e10cSrcweir                 aSelectedElements[ E_REPORT ].push_back( pObject->Name );
2929*cdf0e10cSrcweir                 break;
2930*cdf0e10cSrcweir             case DatabaseObjectContainer::TABLES:
2931*cdf0e10cSrcweir             case DatabaseObjectContainer::QUERIES:
2932*cdf0e10cSrcweir             case DatabaseObjectContainer::FORMS:
2933*cdf0e10cSrcweir             case DatabaseObjectContainer::REPORTS:
2934*cdf0e10cSrcweir                 if ( eSelectedCategory != E_NONE )
2935*cdf0e10cSrcweir                     throw IllegalArgumentException(
2936*cdf0e10cSrcweir                         String(ModuleRes(RID_STR_NO_DIFF_CAT)),
2937*cdf0e10cSrcweir                         *this, sal_Int16( pObject - aSelectedObjects.getConstArray() ) );
2938*cdf0e10cSrcweir                 eSelectedCategory =
2939*cdf0e10cSrcweir                         ( pObject->Type == DatabaseObjectContainer::TABLES )  ? E_TABLE
2940*cdf0e10cSrcweir                     :   ( pObject->Type == DatabaseObjectContainer::QUERIES ) ? E_QUERY
2941*cdf0e10cSrcweir                     :   ( pObject->Type == DatabaseObjectContainer::FORMS )   ? E_FORM
2942*cdf0e10cSrcweir                     :   ( pObject->Type == DatabaseObjectContainer::REPORTS ) ? E_REPORT
2943*cdf0e10cSrcweir                     :   E_NONE;
2944*cdf0e10cSrcweir                 break;
2945*cdf0e10cSrcweir 
2946*cdf0e10cSrcweir             default:
2947*cdf0e10cSrcweir             case DatabaseObjectContainer::DATA_SOURCE:
2948*cdf0e10cSrcweir             {
2949*cdf0e10cSrcweir                 ::rtl::OUString sMessage = String(ModuleRes( RID_STR_UNSUPPORTED_OBJECT_TYPE ));
2950*cdf0e10cSrcweir                 ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$type$", ::rtl::OUString::valueOf(sal_Int32( pObject->Type )) );
2951*cdf0e10cSrcweir                 throw IllegalArgumentException(sMessage, *this, sal_Int16( pObject - aSelectedObjects.getConstArray() ));
2952*cdf0e10cSrcweir             }
2953*cdf0e10cSrcweir         }
2954*cdf0e10cSrcweir     }
2955*cdf0e10cSrcweir 
2956*cdf0e10cSrcweir     for (   SelectionByElementType::const_iterator sel = aSelectedElements.begin();
2957*cdf0e10cSrcweir             sel != aSelectedElements.end();
2958*cdf0e10cSrcweir             ++sel
2959*cdf0e10cSrcweir         )
2960*cdf0e10cSrcweir     {
2961*cdf0e10cSrcweir         if ( sel->first == m_eCurrentType )
2962*cdf0e10cSrcweir         {
2963*cdf0e10cSrcweir             Sequence< ::rtl::OUString > aSelected( sel->second.size() );
2964*cdf0e10cSrcweir             ::std::copy( sel->second.begin(), sel->second.end(), aSelected.getArray() );
2965*cdf0e10cSrcweir             getContainer()->selectElements( aSelected );
2966*cdf0e10cSrcweir         }
2967*cdf0e10cSrcweir         else
2968*cdf0e10cSrcweir         {
2969*cdf0e10cSrcweir             m_aPendingSelection[ sel->first ] = sel->second;
2970*cdf0e10cSrcweir         }
2971*cdf0e10cSrcweir     }
2972*cdf0e10cSrcweir 
2973*cdf0e10cSrcweir     m_aSelectContainerEvent.CancelCall();   // just in case the async select request was running
2974*cdf0e10cSrcweir     getContainer()->selectContainer( eSelectedCategory );
2975*cdf0e10cSrcweir 
2976*cdf0e10cSrcweir     return sal_True;
2977*cdf0e10cSrcweir }
2978*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2979*cdf0e10cSrcweir Any SAL_CALL OApplicationController::getSelection(  ) throw (RuntimeException)
2980*cdf0e10cSrcweir {
2981*cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
2982*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getMutex() );
2983*cdf0e10cSrcweir 
2984*cdf0e10cSrcweir     Sequence< NamedDatabaseObject > aCurrentSelection;
2985*cdf0e10cSrcweir     const ElementType eType( getContainer()->getElementType() );
2986*cdf0e10cSrcweir     if ( eType != E_NONE )
2987*cdf0e10cSrcweir     {
2988*cdf0e10cSrcweir         getContainer()->describeCurrentSelectionForType( eType, aCurrentSelection );
2989*cdf0e10cSrcweir         if ( aCurrentSelection.getLength() == 0 )
2990*cdf0e10cSrcweir         {   // if no objects are selected, add an entry to the sequence which describes the overall category
2991*cdf0e10cSrcweir             // which is selected currently
2992*cdf0e10cSrcweir             aCurrentSelection.realloc(1);
2993*cdf0e10cSrcweir             aCurrentSelection[0].Name = getDatabaseName();
2994*cdf0e10cSrcweir             switch ( eType )
2995*cdf0e10cSrcweir             {
2996*cdf0e10cSrcweir             case E_TABLE:   aCurrentSelection[0].Type = DatabaseObjectContainer::TABLES;   break;
2997*cdf0e10cSrcweir             case E_QUERY:   aCurrentSelection[0].Type = DatabaseObjectContainer::QUERIES;  break;
2998*cdf0e10cSrcweir             case E_FORM:    aCurrentSelection[0].Type = DatabaseObjectContainer::FORMS;    break;
2999*cdf0e10cSrcweir             case E_REPORT:  aCurrentSelection[0].Type = DatabaseObjectContainer::REPORTS;  break;
3000*cdf0e10cSrcweir             default:
3001*cdf0e10cSrcweir                 OSL_ENSURE( false, "OApplicationController::getSelection: unexpected current element type!" );
3002*cdf0e10cSrcweir                 break;
3003*cdf0e10cSrcweir             }
3004*cdf0e10cSrcweir         }
3005*cdf0e10cSrcweir     }
3006*cdf0e10cSrcweir     return makeAny( aCurrentSelection );
3007*cdf0e10cSrcweir }
3008*cdf0e10cSrcweir // -----------------------------------------------------------------------------
3009*cdf0e10cSrcweir void OApplicationController::impl_migrateScripts_nothrow()
3010*cdf0e10cSrcweir {
3011*cdf0e10cSrcweir     try
3012*cdf0e10cSrcweir     {
3013*cdf0e10cSrcweir         ::rtl::OUString sDialogService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.application.MacroMigrationWizard" ) );
3014*cdf0e10cSrcweir         ::comphelper::ComponentContext aContext( getORB() );
3015*cdf0e10cSrcweir         Sequence< Any > aDialogArgs(1);
3016*cdf0e10cSrcweir         aDialogArgs[0] <<= Reference< XOfficeDatabaseDocument >( m_xModel, UNO_QUERY_THROW );
3017*cdf0e10cSrcweir         Reference< XExecutableDialog > xDialog(
3018*cdf0e10cSrcweir             aContext.createComponentWithArguments( sDialogService, aDialogArgs ),
3019*cdf0e10cSrcweir             UNO_QUERY );
3020*cdf0e10cSrcweir 
3021*cdf0e10cSrcweir         if ( !xDialog.is() )
3022*cdf0e10cSrcweir         {
3023*cdf0e10cSrcweir             ShowServiceNotAvailableError( getView(), sDialogService, true );
3024*cdf0e10cSrcweir             return;
3025*cdf0e10cSrcweir         }
3026*cdf0e10cSrcweir 
3027*cdf0e10cSrcweir         xDialog->execute();
3028*cdf0e10cSrcweir     }
3029*cdf0e10cSrcweir     catch( const Exception& )
3030*cdf0e10cSrcweir     {
3031*cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
3032*cdf0e10cSrcweir     }
3033*cdf0e10cSrcweir }
3034*cdf0e10cSrcweir 
3035*cdf0e10cSrcweir //........................................................................
3036*cdf0e10cSrcweir }	// namespace dbaui
3037*cdf0e10cSrcweir //........................................................................
3038*cdf0e10cSrcweir 
3039