1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _DBAUI_TABLETREE_HXX_
25 #define _DBAUI_TABLETREE_HXX_
26 
27 #ifndef _DBAUI_MARKTREE_HXX_
28 #include "marktree.hxx"
29 #endif
30 
31 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #endif
34 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
35 #include <com/sun/star/container/XNameAccess.hpp>
36 #endif
37 #ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_
38 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
39 #endif
40 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
41 #include <com/sun/star/sdbc/XConnection.hpp>
42 #endif
43 #ifndef _COM_SUN_STAR_SDBC_XDRIVER_HPP_
44 #include <com/sun/star/sdbc/XDriver.hpp>
45 #endif
46 #ifndef _COM_SUN_STAR_SDB_APPLICATION_NAMEDDATABASEOBJECT_HPP_
47 #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp>
48 #endif
49 
50 #include <memory>
51 
52 //.........................................................................
53 namespace dbaui
54 {
55 //.........................................................................
56 
57 class ImageProvider;
58 
59 //========================================================================
60 //= OTableTreeListBox
61 //========================================================================
62 class OTableTreeListBox : public OMarkableTreeListBox
63 {
64 protected:
65     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
66                     m_xConnection;      // the connection we're working for, set in implOnNewConnection, called by UpdateTableList
67     ::std::auto_ptr< ImageProvider >
68                     m_pImageProvider;   // provider for our images
69 	sal_Bool		m_bVirtualRoot; // should the first entry be visible
70     bool            m_bNoEmptyFolders;  // should empty catalogs/schematas be prevented from being displayed?
71 
72 public:
73 	OTableTreeListBox(
74         Window* pParent,
75 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
76         WinBits nWinStyle,
77         sal_Bool _bVirtualRoot );
78 
79 	OTableTreeListBox(
80         Window* pParent,
81 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
82         const ResId& rResId,
83         sal_Bool _bVirtualRoot );
84 
85     ~OTableTreeListBox();
86 
87 	typedef ::std::pair< ::rtl::OUString,sal_Bool>	TTableViewName;
88 	typedef ::std::vector< TTableViewName >			TNames;
89 
suppressEmptyFolders()90     void    suppressEmptyFolders() { m_bNoEmptyFolders = true; }
91 
92     /** call when HiContrast change.
93 	*/
94 	void notifyHiContrastChanged();
95 
96     /** determines whether the given entry denotes a tables folder
97     */
98     bool    isFolderEntry( const SvLBoxEntry* _pEntry ) const;
99 
100     /** determines whether the given entry denotes a table or view
101     */
isTableOrViewEntry(const SvLBoxEntry * _pEntry) const102     bool    isTableOrViewEntry( const SvLBoxEntry* _pEntry ) const
103     {
104         return !isFolderEntry( _pEntry );
105     }
106 
107 	/** fill the table list with the tables belonging to the connection described by the parameters
108 		@param _rxConnection
109 			the connection, which must support the service com.sun.star.sdb.Connection
110 		@throws
111 			<type scope="com::sun::star::sdbc">SQLException</type> if no connection could be created
112 	*/
113 	void    UpdateTableList(
114 				const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection
115 			)	throw(::com::sun::star::sdbc::SQLException);
116 
117 	/** fill the table list with the tables and views determined by the two given containers.
118 		The views sequence is used to determine which table is of type view.
119 		@param		_rxConnection   the connection where you got the object names from. Must not be NULL.
120 									Used to split the full qualified names into it's parts.
121 		@param		_rTables		table/view sequence
122 		@param		_rViews			view sequence
123 	*/
124 	void	UpdateTableList(
125 				const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
126 				const ::com::sun::star::uno::Sequence< ::rtl::OUString>& _rTables,
127 				const ::com::sun::star::uno::Sequence< ::rtl::OUString>& _rViews
128 			);
129 
130     /** returns a NamedDatabaseObject record which describes the given entry
131     */
132     ::com::sun::star::sdb::application::NamedDatabaseObject
133             describeObject( SvLBoxEntry* _pEntry );
134 
135 	/** to be used if a foreign instance added a table
136 	*/
137 	SvLBoxEntry* addedTable( const ::rtl::OUString& _rName );
138 
139 	/** to be used if a foreign instance removed a table
140 	*/
141 	void	removedTable( const ::rtl::OUString& _rName );
142 
143     /** returns the fully qualified name of a table entry
144         @param _pEntry
145             the entry whose name is to be obtained. Must not denote a folder entry.
146     */
147     String getQualifiedTableName( SvLBoxEntry* _pEntry ) const;
148 
149 	SvLBoxEntry*	getEntryByQualifiedName( const ::rtl::OUString& _rName );
150 
151 	SvLBoxEntry*	getAllObjectsEntry() const;
152 
153 	/** does a wildcard check of the given entry
154 		<p>There are two different 'checked' states: If the user checks all children of an entry, this is different
155 		from checking the entry itself. The second is called 'wildcard' checking, 'cause in the resulting
156 		table filter it's represented by a wildcard.</p>
157 	*/
158 	void			checkWildcard(SvLBoxEntry* _pEntry);
159 
160 	/** determine if the given entry is 'wildcard checked'
161 		@see checkWildcard
162 	*/
163 	sal_Bool		isWildcardChecked(SvLBoxEntry* _pEntry) const;
164 
165 protected:
166 	virtual void InitEntry(SvLBoxEntry* _pEntry, const XubString& _rString, const Image& _rCollapsedBitmap, const Image& _rExpandedBitmap, SvLBoxButtonKind _eButtonKind);
167 
168 	virtual void checkedButton_noBroadcast(SvLBoxEntry* _pEntry);
169 
170 	void implEmphasize(SvLBoxEntry* _pEntry, sal_Bool _bChecked, sal_Bool _bUpdateDescendants = sal_True, sal_Bool _bUpdateAncestors = sal_True);
171 
172     /** adds the given entry to our list
173         @precond
174             our image provider must already have been reset to the connection to which the meta data
175             belong.
176     */
177 	SvLBoxEntry* implAddEntry(
178 			const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _rxMeta,
179 			const ::rtl::OUString& _rTableName,
180 			sal_Bool _bCheckName = sal_True
181 		);
182 
183     void    implSetDefaultImages();
184 
185     void    implOnNewConnection( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection );
186 
187     bool    impl_getAndAssertMetaData( ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _out_rMetaData ) const;
188 
haveVirtualRoot() const189 	sal_Bool haveVirtualRoot() const { return m_bVirtualRoot; }
190 
191 	/** fill the table list with the tables and views determined by the two given containers
192 		@param		_rxConnection	the connection where you got the object names from. Must not be NULL.
193 									Used to split the full qualified names into it's parts.
194 		@param		_rTables		table/view sequence, the second argument is <TRUE/> if it is a table, otherwise it is a view.
195 	*/
196 	void	UpdateTableList(
197 				const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
198 				const TNames& _rTables
199 			);
200 
201 };
202 
203 //.........................................................................
204 }	// namespace dbaui
205 //.........................................................................
206 
207 #endif // _DBAUI_TABLETREE_HXX_
208 
209