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