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 #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_TABLETREE_HXX
21 #define INCLUDED_DBACCESS_SOURCE_UI_INC_TABLETREE_HXX
22 
23 #include "imageprovider.hxx"
24 #include "marktree.hxx"
25 
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
29 #include <com/sun/star/sdbc/XConnection.hpp>
30 #include <com/sun/star/sdbc/XDriver.hpp>
31 #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp>
32 #include <vcl/weld.hxx>
33 #include <memory>
34 
35 namespace dbaui
36 {
37 
38 // OTableTreeListBox
39 class OTableTreeListBox final : public OMarkableTreeListBox
40 {
41     css::uno::Reference< css::sdbc::XConnection >
42                     m_xConnection;      // the connection we're working for, set in implOnNewConnection, called by UpdateTableList
43     std::unique_ptr< ImageProvider >
44                     m_xImageProvider;   // provider for our images
45 
46 public:
47     OTableTreeListBox(vcl::Window* pParent, WinBits nWinStyle);
48 
49     typedef std::pair< OUString, bool > TTableViewName;
50     typedef std::vector< TTableViewName >         TNames;
51 
52     /** call when HiContrast change.
53     */
54     void notifyHiContrastChanged();
55 
56     /** determines whether the given entry denotes a tables folder
57     */
58     static bool isFolderEntry( const SvTreeListEntry* _pEntry );
59 
60     /** fill the table list with the tables belonging to the connection described by the parameters
61         @param _rxConnection
62             the connection, which must support the service com.sun.star.sdb.Connection
63         @throws
64             <type scope="css::sdbc">SQLException</type> if no connection could be created
65     */
66     void    UpdateTableList(
67                 const css::uno::Reference< css::sdbc::XConnection >& _rxConnection
68             );
69 
70     /** fill the table list with the tables and views determined by the two given containers.
71         The views sequence is used to determine which table is of type view.
72         @param      _rxConnection   the connection where you got the object names from. Must not be NULL.
73                                     Used to split the full qualified names into its parts.
74         @param      _rTables        table/view sequence
75         @param      _rViews         view sequence
76     */
77     void    UpdateTableList(
78                 const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,
79                 const css::uno::Sequence< OUString>& _rTables,
80                 const css::uno::Sequence< OUString>& _rViews
81             );
82 
83     /** returns a NamedDatabaseObject record which describes the given entry
84     */
85     css::sdb::application::NamedDatabaseObject
86             describeObject( SvTreeListEntry* _pEntry );
87 
88     /** to be used if a foreign instance added a table
89     */
90     SvTreeListEntry* addedTable( const OUString& _rName );
91 
92     /** to be used if a foreign instance removed a table
93     */
94     void    removedTable( const OUString& _rName );
95 
96     /** returns the fully qualified name of a table entry
97         @param _pEntry
98             the entry whose name is to be obtained. Must not denote a folder entry.
99     */
100     OUString getQualifiedTableName( SvTreeListEntry* _pEntry ) const;
101 
102     SvTreeListEntry*    getEntryByQualifiedName( const OUString& _rName );
103 
104 private:
105     virtual void InitEntry(SvTreeListEntry* _pEntry, const OUString& _rString, const Image& _rCollapsedBitmap, const Image& _rExpandedBitmap) override;
106 
107     virtual void checkedButton_noBroadcast(SvTreeListEntry* _pEntry) override;
108 
109     void implEmphasize(SvTreeListEntry* _pEntry, bool _bChecked, bool _bUpdateDescendants = true, bool _bUpdateAncestors = true);
110 
111     /** adds the given entry to our list
112         @precond
113             our image provider must already have been reset to the connection to which the meta data
114             belong.
115     */
116     SvTreeListEntry* implAddEntry(
117             const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rxMeta,
118             const OUString& _rTableName,
119             bool _bCheckName = true
120         );
121 
122     void    implSetDefaultImages();
123 
124     void    implOnNewConnection( const css::uno::Reference< css::sdbc::XConnection >& _rxConnection );
125 
126     bool    impl_getAndAssertMetaData( css::uno::Reference< css::sdbc::XDatabaseMetaData >& _out_rMetaData ) const;
127 
128     /** fill the table list with the tables and views determined by the two given containers
129         @param      _rxConnection   the connection where you got the object names from. Must not be NULL.
130                                     Used to split the full qualified names into its parts.
131         @param      _rTables        table/view sequence, the second argument is <TRUE/> if it is a table, otherwise it is a view.
132     */
133     void    UpdateTableList(
134                 const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,
135                 const TNames& _rTables
136             );
137 
138 };
139 
140 class TableTreeListBox
141 {
142     css::uno::Reference< css::sdbc::XConnection >
143                     m_xConnection;      // the connection we're working for, set in implOnNewConnection, called by UpdateTableList
144     std::unique_ptr< ImageProvider >
145                     m_xImageProvider;   // provider for our images
146     bool            m_bVirtualRoot;     // should the first entry be visible
147     bool            m_bNoEmptyFolders;  // should empty catalogs/schematas be prevented from being displayed?
148     bool            m_bShowToggles;     // show toggle buttons
149     int             m_nTextColumn;      // column text is in, depends on if toggles are shown
150     std::unique_ptr<weld::TreeView> m_xTreeView;
151 
152 public:
153     TableTreeListBox(std::unique_ptr<weld::TreeView> xTreeView);
154 
GetWidget()155     weld::TreeView& GetWidget() { return *m_xTreeView; }
156 
init()157     void init() { m_bVirtualRoot = true; }
158 
159     typedef std::pair< OUString, bool > TTableViewName;
160     typedef std::vector< TTableViewName >         TNames;
161 
SuppressEmptyFolders()162     void    SuppressEmptyFolders() { m_bNoEmptyFolders = true; }
163     void    DisableCheckButtons();
164 
165     /** fill the table list with the tables belonging to the connection described by the parameters
166         @param _rxConnection
167             the connection, which must support the service com.sun.star.sdb.Connection
168         @throws
169             <type scope="css::sdbc">SQLException</type> if no connection could be created
170     */
171     void    UpdateTableList(
172                 const css::uno::Reference< css::sdbc::XConnection >& _rxConnection
173             );
174 
175     /** fill the table list with the tables and views determined by the two given containers.
176         The views sequence is used to determine which table is of type view.
177         @param      _rxConnection   the connection where you got the object names from. Must not be NULL.
178                                     Used to split the full qualified names into its parts.
179         @param      _rTables        table/view sequence
180         @param      _rViews         view sequence
181     */
182     void    UpdateTableList(
183                 const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,
184                 const css::uno::Sequence< OUString>& _rTables,
185                 const css::uno::Sequence< OUString>& _rViews
186             );
187 
188     std::unique_ptr<weld::TreeIter>    getAllObjectsEntry() const;
189 
190     /** does a wildcard check of the given entry
191         <p>There are two different 'checked' states: If the user checks all children of an entry, this is different
192         from checking the entry itself. The second is called 'wildcard' checking, 'cause in the resulting
193         table filter it's represented by a wildcard.</p>
194     */
195     void            checkWildcard(weld::TreeIter& rEntry);
196 
197     /** determine if the given entry is 'wildcard checked'
198         @see checkWildcard
199     */
200     bool            isWildcardChecked(const weld::TreeIter& rEntry);
201 
202     std::unique_ptr<weld::TreeIter> GetEntryPosByName(const OUString& aName, const weld::TreeIter* pStart = nullptr, const IEntryFilter* _pFilter = nullptr) const;
203 
204     void            CheckButtons();     // make the button states consistent (bottom-up)
205 
206     void            checkedButton_noBroadcast(weld::TreeIter& rEntry);
207 private:
208     TriState implDetermineState(weld::TreeIter& rEntry);
209 
210     void implEmphasize(weld::TreeIter& rEntry, bool _bChecked, bool _bUpdateDescendants = true, bool _bUpdateAncestors = true);
211 
212     /** adds the given entry to our list
213         @precond
214             our image provider must already have been reset to the connection to which the meta data
215             belong.
216     */
217     void implAddEntry(
218             const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rxMeta,
219             const OUString& _rTableName
220         );
221 
222     void    implOnNewConnection( const css::uno::Reference< css::sdbc::XConnection >& _rxConnection );
223 
haveVirtualRoot() const224     bool haveVirtualRoot() const { return m_bVirtualRoot; }
225 
226     /** fill the table list with the tables and views determined by the two given containers
227         @param      _rxConnection   the connection where you got the object names from. Must not be NULL.
228                                     Used to split the full qualified names into its parts.
229         @param      _rTables        table/view sequence, the second argument is <TRUE/> if it is a table, otherwise it is a view.
230     */
231     void    UpdateTableList(
232                 const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,
233                 const TNames& _rTables
234             );
235 };
236 
237 }   // namespace dbaui
238 
239 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_TABLETREE_HXX
240 
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
242