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 DBACCESS_DATABASE_OBJECT_VIEW_HXX
25 #define DBACCESS_DATABASE_OBJECT_VIEW_HXX
26 
27 #ifndef _RTL_USTRING_HXX_
28 #include <rtl/ustring.hxx>
29 #endif
30 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
31 #include <com/sun/star/sdbc/XConnection.hpp>
32 #endif
33 #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
34 #include <com/sun/star/sdbc/XDataSource.hpp>
35 #endif
36 #ifndef _COM_SUN_STAR_FRAME_XDISPATCH_HPP_
37 #include <com/sun/star/frame/XDispatch.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
40 #include <com/sun/star/lang/XComponent.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
46 #include <com/sun/star/frame/XComponentLoader.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_FRAME_XFRAME_HPP_
49 #include <com/sun/star/frame/XFrame.hpp>
50 #endif
51 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
52 #include <com/sun/star/beans/PropertyValue.hpp>
53 #endif
54 #ifndef _COM_SUN_STAR_UI_DIALOGS_XEXECUTABLEDIALOG_HPP_
55 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
56 #endif
57 #ifndef _COM_SUN_STAR_SDB_APPLICATION_XDATABASEDOCUMENTUI_HPP_
58 #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp>
59 #endif
60 #ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
61 #include <com/sun/star/uno/Sequence.hxx>
62 #endif
63 #include <comphelper/namedvaluecollection.hxx>
64 
65 #include <boost/shared_ptr.hpp>
66 
67 
68 // .........................................................................
69 namespace dbaui
70 {
71 // .........................................................................
72     /** encapsulates access to the view of a database object.
73 
74         @todo
75             this is to be merged with the OLinkedDocumentAccess class
76     */
77 	class DatabaseObjectView
78 	{
79 	private:
80 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
81 					    m_xORB;
82 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >
83 					    m_xParentFrame;
84 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XComponentLoader >
85 					    m_xFrameLoader;
86         ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >
87                         m_xApplication;
88         ::rtl::OUString m_sComponentURL;
89 
90 
91 	private:
92 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
93                 doDispatch(
94                     const ::comphelper::NamedValueCollection& i_rDispatchArgs
95                 );
96 
97 	protected:
98         /** creates the desired view
99 
100             The default implementation will call <member>fillDispatchArgs</member>, followed
101             by <member>doDispatch</member>.
102 
103             @param _rDataSource
104                 the data source, as passed to the <member>createNew</member> or <member>openExisting</member> method.
105             @param _rObjectName
106                 the name of the object for which the view is to be opened,
107                 or an empty string if a view for a new object should be created.
108             @param _rCreationArgs
109                 the arguments for the view's creation
110         */
111 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > doCreateView(
112 			const ::com::sun::star::uno::Any& _rDataSource,
113 			const ::rtl::OUString& _rObjectName,
114             const ::comphelper::NamedValueCollection& i_rCreationArgs
115 		);
116 
117         virtual void fillDispatchArgs(
118                           ::comphelper::NamedValueCollection& i_rDispatchArgs,
119 			        const ::com::sun::star::uno::Any& _rDataSource,
120 			        const ::rtl::OUString& _rObjectName
121                 );
122 
123         const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >&
getApplicationUI() const124                 getApplicationUI() const { return m_xApplication; }
125         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
126                 getConnection() const;
127 
128 	public:
129 		DatabaseObjectView(
130             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
131             const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxApplication,
132             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxParentFrame,
133             const ::rtl::OUString& _rComponentURL
134         );
~DatabaseObjectView()135 		virtual ~DatabaseObjectView(){}
136 
137         /** sets the target frame into which the view should be loaded.
138 
139             By default, the view is loaded into a top-level frame not being part of the
140             Desktop.
141         */
setTargetFrame(const::com::sun::star::uno::Reference<::com::sun::star::frame::XFrame> & _rxFrame)142         void setTargetFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame )
143         {
144             m_xFrameLoader.set( _rxFrame, ::com::sun::star::uno::UNO_QUERY );
145         }
146 
147 		/** opens a view for a to-be-created object
148 
149             @param _xDataSource
150 				the data source for which a new object is to be created
151 			@return
152 				the controller of the newly created document
153 		*/
154 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
155 			createNew(
156 				const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource >& _xDataSource,
157                 const ::comphelper::NamedValueCollection& i_rDispatchArgs = ::comphelper::NamedValueCollection()
158 			);
159 
160 		/** opens a view for an existent object
161 
162             @param _xDataSource
163 				the data source for which a new object is to be created
164 			@param _rObjectName
165 				the name of the object to be edited
166 			@param	_rArgs
167 				Additional settings which should be forwarded to the frame
168 			@return
169 				the frame into which the view has been loaded
170 		*/
171 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
172 			openExisting(
173 				const ::com::sun::star::uno::Any& _aDataSource,
174 				const ::rtl::OUString& _rName,
175                 const ::comphelper::NamedValueCollection& i_rDispatchArgs
176 			);
177 	};
178 
179 	//======================================================================
180 	//= QueryDesigner
181 	//======================================================================
182 	class QueryDesigner : public DatabaseObjectView
183 	{
184 	protected:
185         sal_Int32                           m_nCommandType;
186 
187 	protected:
188 		virtual void fillDispatchArgs(
189 			      ::comphelper::NamedValueCollection& i_rDispatchArgs,
190 			const ::com::sun::star::uno::Any& _aDataSource,
191 			const ::rtl::OUString& _rObjectName
192 		);
193 
194 	public:
195 		QueryDesigner(
196             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
197             const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxApplication,
198             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxParentFrame,
199 			bool _bCreateView
200         );
201 	};
202 
203 	//======================================================================
204 	//= TableDesigner
205 	//======================================================================
206 	class TableDesigner : public DatabaseObjectView
207 	{
208 	protected:
209 		virtual void fillDispatchArgs(
210 			      ::comphelper::NamedValueCollection& i_rDispatchArgs,
211 			const ::com::sun::star::uno::Any& _aDataSource,
212 			const ::rtl::OUString& _rObjectName
213 		);
214 
215 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > doCreateView(
216 			const ::com::sun::star::uno::Any& _rDataSource,
217 			const ::rtl::OUString& _rObjectName,
218             const ::comphelper::NamedValueCollection& i_rCreationArgs
219 		);
220 
221 	public:
222 		TableDesigner(
223             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
224             const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxApplication,
225             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxParentFrame
226         );
227 
228     private:
229         /** retrieves the table designer component as provided by the connection, if any
230             @param  _rTableName
231                 the name of the table for which a designer is to be obtained
232             @return
233                 the designer component, as provided by the connection, or <NULL/>, if the connection
234                 does not provide a specialized designer.
235             @see com::sun::star::sdb::application::XTableUIProvider
236         */
237         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
238                 impl_getConnectionProvidedDesigner_nothrow( const ::rtl::OUString& _rTableName );
239 	};
240 
241 	//======================================================================
242 	//= ResultSetBrowser
243 	//======================================================================
244 	class ResultSetBrowser : public DatabaseObjectView
245 	{
246     private:
247 		sal_Bool	m_bTable;
248 
249 	protected:
250 		virtual void fillDispatchArgs(
251 			      ::comphelper::NamedValueCollection& i_rDispatchArgs,
252 			const ::com::sun::star::uno::Any& _aDataSource,
253 			const ::rtl::OUString& _rQualifiedName
254 		);
255 
256 	public:
257 		ResultSetBrowser(
258             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
259             const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxApplication,
260             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxParentFrame,
261 			sal_Bool _bTable
262         );
263 
264 	};
265 	//======================================================================
266 	//= RelationDesigner
267 	//======================================================================
268 	class RelationDesigner : public DatabaseObjectView
269 	{
270 	public:
271 		RelationDesigner(
272             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
273             const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& _rxApplication,
274             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxParentFrame
275         );
276 	};
277 // .........................................................................
278 }	// namespace dbaui
279 // .........................................................................
280 
281 #endif // DBACCESS_DATABASE_OBJECT_VIEW_HXX
282 
283