Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / dbaccess / source / ui / inc / unodatbr.hxx
blob02673fb6a1fb44db80664914b3e0d48636ace8fc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_UNODATBR_HXX
21 #define INCLUDED_DBACCESS_SOURCE_UI_INC_UNODATBR_HXX
23 #include "brwctrlr.hxx"
24 #include <com/sun/star/sdbc/XConnection.hpp>
25 #include <com/sun/star/frame/XStatusListener.hpp>
26 #include <com/sun/star/frame/XDispatch.hpp>
27 #include <com/sun/star/container/XContainerListener.hpp>
28 #include <com/sun/star/i18n/XCollator.hpp>
29 #include <com/sun/star/view/XSelectionSupplier.hpp>
30 #include <com/sun/star/awt/XWindow.hpp>
31 #include <com/sun/star/document/XScriptInvocationContext.hpp>
32 #include <com/sun/star/ui/XContextMenuInterception.hpp>
33 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
34 #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
35 #include <com/sun/star/sdb/XDatabaseRegistrationsListener.hpp>
36 #include <cppuhelper/implbase5.hxx>
37 #include "callbacks.hxx"
38 #include <vcl/timer.hxx>
39 #include <svtools/transfer.hxx>
40 #include <svx/dataaccessdescriptor.hxx>
41 #include <sot/storage.hxx>
42 #include "TableCopyHelper.hxx"
43 #include "commontypes.hxx"
45 class SvTreeListEntry;
46 class Splitter;
47 struct SvSortData;
49 namespace com { namespace sun{ namespace star { namespace container { class XNameContainer; } } } }
51 class SvTreeList;
52 namespace dbaui
55 class DBTreeView;
56 struct DBTreeEditedEntry;
57 class ImageProvider;
59 typedef ::cppu::ImplHelper5 < css::frame::XStatusListener
60 , css::view::XSelectionSupplier
61 , css::document::XScriptInvocationContext
62 , css::ui::XContextMenuInterception
63 , css::sdb::XDatabaseRegistrationsListener
64 > SbaTableQueryBrowser_Base;
65 class SbaTableQueryBrowser
66 :public SbaXDataBrowserController
67 ,public SbaTableQueryBrowser_Base
68 ,public IControlActionListener
69 ,public IContextMenuProvider
71 protected:
73 css::uno::Reference< css::i18n::XCollator > m_xCollator;
74 css::uno::Reference< css::frame::XFrame > m_xCurrentFrameParent;
75 css::uno::Reference< css::awt::XWindow > m_xMainToolbar;
77 struct ExternalFeature
79 css::util::URL aURL;
80 css::uno::Reference< css::frame::XDispatch >
81 xDispatcher;
82 bool bEnabled;
84 ExternalFeature() : bEnabled( false ) { }
85 ExternalFeature( const css::util::URL& _rURL ) : aURL( _rURL ), bEnabled( false ) { }
88 typedef ::std::map< sal_uInt16, ExternalFeature, ::std::less< sal_uInt16 > > ExternalFeaturesMap;
89 ExternalFeaturesMap m_aExternalFeatures;
91 svx::ODataAccessDescriptor m_aDocumentDataSource;
92 // if we're part of a document, this is the state of the DocumentDataSource slot
94 ::comphelper::OInterfaceContainerHelper2 m_aSelectionListeners;
95 ::comphelper::OInterfaceContainerHelper2 m_aContextMenuInterceptors;
97 OTableCopyHelper::DropDescriptor m_aAsyncDrop;
98 OTableCopyHelper m_aTableCopyHelper;
100 OUString m_sQueryCommand; // the command of the query currently loaded (if any)
101 //OUString m_sToBeLoaded; // contains the element name which should be loaded if any
103 VclPtr<DBTreeView> m_pTreeView;
104 VclPtr<Splitter> m_pSplitter;
105 SvTreeList* m_pTreeModel; // contains the datasources of the registry
106 SvTreeListEntry* m_pCurrentlyDisplayed;
107 ImplSVEvent * m_nAsyncDrop;
109 bool m_bQueryEscapeProcessing : 1; // the escape processing flag of the query currently loaded (if any)
110 bool m_bShowMenu; // if sal_True the menu should be visible otherwise not
111 bool m_bInSuspend;
112 bool m_bEnableBrowser;
113 ::boost::optional< bool >
114 m_aDocScriptSupport; // relevant if and only if we are associated with exactly one DBDoc
116 virtual OUString getPrivateTitle( ) const override;
117 // attribute access
118 public:
119 SbaTableQueryBrowser(const css::uno::Reference< css::uno::XComponentContext >& _rM);
120 virtual ~SbaTableQueryBrowser();
122 enum EntryType
124 // don't change the above definitions! There are places (in particular SbaTableQueryBrowser::getCurrentSelection)
125 // which rely on the fact that the EntryType values really equal the DatabaseObject(Container) values!
126 etDatasource = css::sdb::application::DatabaseObjectContainer::DATA_SOURCE,
127 etQueryContainer = css::sdb::application::DatabaseObjectContainer::QUERIES,
128 etTableContainer = css::sdb::application::DatabaseObjectContainer::TABLES,
129 etQuery = css::sdb::application::DatabaseObject::QUERY,
130 etTableOrView = css::sdb::application::DatabaseObject::TABLE,
131 etUnknown = -1
134 /** returns a DatabaseObject value corresponding to the given EntryType
135 @param _eType
136 the entry type. Must not be etUnknown.
138 static sal_Int32 getDatabaseObjectType( EntryType _eType );
140 // need by registration
141 static OUString getImplementationName_Static() throw( css::uno::RuntimeException );
142 static css::uno::Sequence< OUString > getSupportedServiceNames_Static() throw( css::uno::RuntimeException );
143 static css::uno::Reference< css::uno::XInterface >
144 SAL_CALL Create(const css::uno::Reference< css::lang::XMultiServiceFactory >&);
146 DECLARE_UNO3_DEFAULTS(SbaTableQueryBrowser,SbaXDataBrowserController)
147 // late construction
148 virtual bool Construct(vcl::Window* pParent) override;
149 // XInterface
150 virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) throw (css::uno::RuntimeException, std::exception) override;
152 // XTypeProvider
153 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) throw (css::uno::RuntimeException, std::exception) override;
154 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (css::uno::RuntimeException, std::exception) override;
156 // css::beans::XPropertyChangeListener
157 virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent& evt) throw(css::uno::RuntimeException, std::exception) override;
159 // css::frame::XController
160 virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( css::uno::RuntimeException, std::exception ) override;
161 virtual void SAL_CALL attachFrame(const css::uno::Reference< css::frame::XFrame > & xFrame) throw( css::uno::RuntimeException, std::exception ) override;
163 // css::lang::XComponent
164 virtual void SAL_CALL disposing() override;
166 // XStatusListener
167 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) throw(css::uno::RuntimeException, std::exception) override;
169 // XEventListener
170 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) throw(css::uno::RuntimeException, std::exception) override;
172 // XSelectionSupplier
173 virtual sal_Bool SAL_CALL select( const css::uno::Any& aSelection ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) override;
174 virtual css::uno::Any SAL_CALL getSelection( ) throw (css::uno::RuntimeException, std::exception) override;
175 virtual void SAL_CALL addSelectionChangeListener( const css::uno::Reference< css::view::XSelectionChangeListener >& xListener ) throw (css::uno::RuntimeException, std::exception) override;
176 virtual void SAL_CALL removeSelectionChangeListener( const css::uno::Reference< css::view::XSelectionChangeListener >& xListener ) throw (css::uno::RuntimeException, std::exception) override;
178 // XServiceInfo
179 virtual OUString SAL_CALL getImplementationName() throw(css::uno::RuntimeException, std::exception) override;
180 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() throw(css::uno::RuntimeException, std::exception) override;
182 // XContainerListener
183 virtual void SAL_CALL elementInserted( const css::container::ContainerEvent& Event ) throw(css::uno::RuntimeException, std::exception) override;
184 virtual void SAL_CALL elementRemoved( const css::container::ContainerEvent& Event ) throw(css::uno::RuntimeException, std::exception) override;
185 virtual void SAL_CALL elementReplaced( const css::container::ContainerEvent& Event ) throw(css::uno::RuntimeException, std::exception) override;
186 // css::frame::XFrameActionListener
187 virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent) throw( css::uno::RuntimeException, std::exception ) override;
189 //IController
190 virtual void notifyHiContrastChanged() override;
192 // XScriptInvocationContext
193 virtual css::uno::Reference< css::document::XEmbeddedScripts > SAL_CALL getScriptContainer() throw (css::uno::RuntimeException, std::exception) override;
195 // XContextMenuInterception
196 virtual void SAL_CALL registerContextMenuInterceptor( const css::uno::Reference< css::ui::XContextMenuInterceptor >& Interceptor ) throw (css::uno::RuntimeException, std::exception) override;
197 virtual void SAL_CALL releaseContextMenuInterceptor( const css::uno::Reference< css::ui::XContextMenuInterceptor >& Interceptor ) throw (css::uno::RuntimeException, std::exception) override;
199 // XDatabaseRegistrationsListener
200 virtual void SAL_CALL registeredDatabaseLocation( const css::sdb::DatabaseRegistrationEvent& Event ) throw (css::uno::RuntimeException, std::exception) override;
201 virtual void SAL_CALL revokedDatabaseLocation( const css::sdb::DatabaseRegistrationEvent& Event ) throw (css::uno::RuntimeException, std::exception) override;
202 virtual void SAL_CALL changedDatabaseLocation( const css::sdb::DatabaseRegistrationEvent& Event ) throw (css::uno::RuntimeException, std::exception) override;
204 protected:
205 // SbaXDataBrowserController overridables
206 virtual bool InitializeForm( const css::uno::Reference< css::beans::XPropertySet >& i_formProperties ) override;
207 virtual bool InitializeGridModel(const css::uno::Reference< css::form::XFormComponent > & xGrid) override;
209 virtual bool preReloadForm() override;
210 virtual void postReloadForm() override;
212 virtual void addModelListeners(const css::uno::Reference< css::awt::XControlModel > & _xGridControlModel) override;
213 virtual void removeModelListeners(const css::uno::Reference< css::awt::XControlModel > & _xGridControlModel) override;
215 virtual void AddColumnListener(const css::uno::Reference< css::beans::XPropertySet > & xCol) override;
216 virtual void RemoveColumnListener(const css::uno::Reference< css::beans::XPropertySet > & xCol) override;
218 virtual void LoadFinished(bool _bWasSynch) override;
220 virtual void criticalFail() override;
222 virtual void describeSupportedFeatures() override;
223 virtual FeatureState GetState(sal_uInt16 nId) const override;
224 virtual void Execute(sal_uInt16 nId, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override;
226 // IControlActionListener overridables
227 virtual bool requestQuickHelp( const SvTreeListEntry* _pEntry, OUString& _rText ) const override;
228 virtual bool requestDrag( sal_Int8 _nAction, const Point& _rPosPixel ) override;
229 virtual sal_Int8 queryDrop( const AcceptDropEvent& _rEvt, const DataFlavorExVector& _rFlavors ) override;
230 virtual sal_Int8 executeDrop( const ExecuteDropEvent& _rEvt ) override;
232 // IContextMenuProvider
233 virtual PopupMenu* getContextMenu( Control& _rControl ) const override;
234 virtual IController& getCommandController() override;
235 virtual ::comphelper::OInterfaceContainerHelper2*
236 getContextMenuInterceptors() override;
237 virtual css::uno::Any
238 getCurrentSelection( Control& _rControl ) const override;
240 virtual void impl_initialize() override;
242 // SbaGridListener overridables
243 virtual void RowChanged() override;
244 virtual void ColumnChanged() override;
245 virtual void SelectionChanged() override;
247 // methods for showing/hiding the explorer part
248 bool haveExplorer() const;
249 void hideExplorer();
250 void showExplorer();
251 void toggleExplorer() { if (haveExplorer()) hideExplorer(); else showExplorer(); }
253 // methods for handling the 'selection' (painting them bold) of SvLBoxEntries
254 // returns <TRUE/> if the entry is selected (which means it's part of the selected path)
255 static bool isSelected(SvTreeListEntry* _pEntry);
256 // select the entry (and only the entry, not the whole path)
257 void select(SvTreeListEntry* _pEntry, bool _bSelect = true);
258 // select the path of the entry (which must be an entry without children)
259 void selectPath(SvTreeListEntry* _pEntry, bool _bSelect = true);
261 virtual void loadMenu(const css::uno::Reference< css::frame::XFrame >& _xFrame) override;
263 private:
264 // check the state of the external slot given, update any UI elements if necessary
265 void implCheckExternalSlot( sal_uInt16 _nId );
267 // connect to the external dispatchers (if any)
268 void connectExternalDispatches();
270 /** get the state of an external slot
271 <p>The slot is available if an external dispatcher is responsible for it, _and_ if this dispatcher
272 told us the slot is available.</p>
274 bool getExternalSlotState( sal_uInt16 _nId ) const;
276 /** add an entry (including the subentries for queries/tables) to the list model
278 <p>The given names and images may be empty, in this case they're filled with the correct
279 values. This way they may be reused for the next call, which saves some resource manager calls.</p>
281 void implAddDatasource(const OUString& _rDbName, Image& _rDbImage,
282 OUString& _rQueryName, Image& _rQueryImage,
283 OUString& _rTableName, Image& _rTableImage,
284 const SharedConnection& _rxConnection
287 void implAddDatasource( const OUString& _rDataSourceName, const SharedConnection& _rxConnection );
289 /// removes (and cleans up) the entry for the given data source
290 void impl_cleanupDataSourceEntry( const OUString& _rDataSourceName );
292 /// clears the tree list box
293 void clearTreeModel();
295 /** unloads the form, empties the grid model, cleans up anything related to the currently displayed object
296 @param _bDisposeConnection
297 <TRUE/> if the connection should be disposed
298 @param _bFlushData
299 <TRUE/> if the currently displayed object (if any) should be flushed
301 void unloadAndCleanup( bool _bDisposeConnection = true );
303 // disposes the connection associated with the given entry (which must represent a data source)
304 void disposeConnection( SvTreeListEntry* _pDSEntry );
306 /// flushes and disposes the given connection, and de-registers as listener
307 void impl_releaseConnection( SharedConnection& _rxConnection );
309 /** close the connection (and collapse the list entries) of the given list entries
311 void closeConnection(SvTreeListEntry* _pEntry, bool _bDisposeConnection = true);
313 void populateTree(const css::uno::Reference< css::container::XNameAccess>& _xNameAccess, SvTreeListEntry* _pParent, EntryType _eEntryType);
314 void initializeTreeModel();
316 /** search in the tree for query- or tablecontainer equal to this interface and return
317 this container entry
319 SvTreeListEntry* getEntryFromContainer(const css::uno::Reference< css::container::XNameAccess>& _rxNameAccess);
320 // return true when there is connection available
321 bool ensureConnection(SvTreeListEntry* _pDSEntry, void * pDSData, SharedConnection& _rConnection );
322 bool ensureConnection(SvTreeListEntry* _pAnyEntry, SharedConnection& _rConnection );
324 bool getExistentConnectionFor( SvTreeListEntry* _pDSEntry, SharedConnection& _rConnection );
325 /** returns an image provider which works with the connection belonging to the given entry
327 ::std::unique_ptr< ImageProvider >
328 getImageProviderFor( SvTreeListEntry* _pAnyEntry );
330 void implAdministrate( SvTreeListEntry* _pApplyTo );
332 TransferableHelper*
333 implCopyObject( SvTreeListEntry* _pApplyTo, sal_Int32 _nCommandType );
335 EntryType getEntryType( const SvTreeListEntry* _pEntry ) const;
336 EntryType getChildType( SvTreeListEntry* _pEntry ) const;
337 static bool isObject( EntryType _eType ) { return ( etTableOrView== _eType ) || ( etQuery == _eType ); }
338 static bool isContainer( EntryType _eType ) { return (etTableContainer == _eType) || (etQueryContainer == _eType); }
339 bool isContainer( const SvTreeListEntry* _pEntry ) const { return isContainer( getEntryType( _pEntry ) ); }
341 // ensure that the xObject for the given entry is set on the user data
342 bool ensureEntryObject( SvTreeListEntry* _pEntry );
344 // get the display text of the entry given
345 OUString GetEntryText( SvTreeListEntry* _pEntry ) const;
347 // is called when a table or a query was selected
348 DECL_LINK_TYPED( OnSelectionChange, LinkParamNone*, void );
349 DECL_LINK_TYPED( OnExpandEntry, SvTreeListEntry*, bool );
351 DECL_LINK_TYPED( OnCopyEntry, LinkParamNone*, void );
353 DECL_LINK_TYPED( OnTreeEntryCompare, const SvSortData&, sal_Int32 );
355 DECL_LINK_TYPED( OnAsyncDrop, void*, void );
357 void implRemoveStatusListeners();
359 bool implSelect(const svx::ODataAccessDescriptor& _rDescriptor, bool _bSelectDirect = false);
360 bool implSelect( SvTreeListEntry* _pEntry );
362 /// selects the entry given and loads the grid control with the object's data
363 bool implSelect(
364 const OUString& _rDataSourceName,
365 const OUString& _rCommand,
366 const sal_Int32 _nCommandType,
367 const bool _bEscapeProcessing,
368 const SharedConnection& _rxConnection,
369 bool _bSelectDirect = false
372 SvTreeListEntry* implGetConnectionEntry(SvTreeListEntry* _pEntry) const;
373 /// inserts an entry into the tree
374 SvTreeListEntry* implAppendEntry(
375 SvTreeListEntry* _pParent,
376 const OUString& _rName,
377 void* _pUserData,
378 EntryType _eEntryType
381 /// loads the grid control with the data object specified (which may be a table, a query or a command)
382 bool implLoadAnything(const OUString& _rDataSourceName, const OUString& _rCommand,
383 const sal_Int32 _nCommandType, const bool _bEscapeProcessing, const SharedConnection& _rxConnection = SharedConnection() );
385 /** retrieves the tree entry for the object described by <arg>_rDescriptor</arg>
386 @param _rDescriptor
387 the object descriptor
388 @param _ppDataSourceEntry
389 If not <NULL/>, the data source tree entry will be returned here
390 @param _ppContainerEntry
391 If not <NULL/>, the object container tree entry will be returned here
393 SvTreeListEntry* getObjectEntry(const svx::ODataAccessDescriptor& _rDescriptor,
394 SvTreeListEntry** _ppDataSourceEntry = nullptr, SvTreeListEntry** _ppContainerEntry = nullptr
396 /** retrieves the tree entry for the object described by data source name, command and command type
397 @param _rDataSource
398 the data source name
399 @param _rCommand
400 the command
401 @param _nCommandType
402 the command type
403 @param _rDescriptor
404 the object descriptor
405 @param _ppDataSourceEntry
406 If not <NULL/>, the data source tree entry will be returned here
407 @param _ppContainerEntry
408 If not <NULL/>, the object container tree entry will be returned here
409 @param _bExpandAncestors
410 If <TRUE/>, all ancestor on the way to the entry will be expanded
412 SvTreeListEntry* getObjectEntry(
413 const OUString& _rDataSource, const OUString& _rCommand, sal_Int32 _nCommandType,
414 SvTreeListEntry** _ppDataSourceEntry = nullptr, SvTreeListEntry** _ppContainerEntry = nullptr,
415 bool _bExpandAncestors = true,
416 const SharedConnection& _rxConnection = SharedConnection()
419 /// checks if m_aDocumentDataSource describes a known object
420 void checkDocumentDataSource();
422 static void extractDescriptorProps(const svx::ODataAccessDescriptor& _rDescriptor,
423 OUString& _rDataSource, OUString& _rCommand, sal_Int32& _rCommandType, bool& _rEscapeProcessing);
425 void transferChangedControlProperty(const OUString& _rProperty, const css::uno::Any& _rNewValue);
427 // checks whether the given tree entry denotes a data source
428 bool impl_isDataSourceEntry( SvTreeListEntry* _pEntry ) const;
430 /// retrieves the data source URL/name for the given entry representing a data source
431 OUString getDataSourceAcessor( SvTreeListEntry* _pDataSourceEntry ) const;
433 /** get the signature (command/escape processing) of the query the form is based on
434 <p>If the for is not based on a query or not even loaded, nothing happens and <FALSE/> is returned.</p>
436 bool implGetQuerySignature( OUString& _rCommand, bool& _bEscapeProcessing );
438 bool isEntryCopyAllowed(SvTreeListEntry* _pEntry) const;
440 void copyEntry(SvTreeListEntry* _pEntry);
442 // remove all grid columns and dispose them
443 static void clearGridColumns(const css::uno::Reference< css::container::XNameContainer >& _xColContainer);
445 /** checks if the currently displayed entry changed
446 @param _sName
447 Name of the changed entry
448 @param _pContainer
449 The container of the displayed entry
450 @return
451 <TRUE/> if it is the currently displayed otherwise <FALSE/>
453 bool isCurrentlyDisplayedChanged(const OUString& _sName, SvTreeListEntry* _pContainer);
455 /** called whenever the content of the browser is used for preview, as the very last action
456 of the load process
458 void initializePreviewMode();
460 /** checks whether the Order/Filter clauses set at our row set are valid, removes them if not so
462 void impl_sanitizeRowSetClauses_nothrow();
465 } // namespace dbaui
467 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_UNODATBR_HXX
469 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */