1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef DBAUI_SUBCOMPONENTCONTROLLER_HXX
29 #define DBAUI_SUBCOMPONENTCONTROLLER_HXX
30 
31 #include "genericcontroller.hxx"
32 
33 /** === begin UNO includes === **/
34 #include <com/sun/star/document/XScriptInvocationContext.hpp>
35 #include <com/sun/star/sdbc/XConnection.hpp>
36 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
37 #include <com/sun/star/sdbc/XDataSource.hpp>
38 #include <com/sun/star/util/XNumberFormatter.hpp>
39 #include <com/sun/star/util/XModifiable.hpp>
40 /** === end UNO includes === **/
41 
42 #include <comphelper/broadcasthelper.hxx>
43 #include <comphelper/proparrhlp.hxx>
44 #include <comphelper/propertycontainer.hxx>
45 #include <connectivity/dbmetadata.hxx>
46 #include <cppuhelper/implbase2.hxx>
47 
48 #include <memory>
49 
50 //........................................................................
51 namespace dbaui
52 {
53 //........................................................................
54 
55 	//====================================================================
56 	//= DBSubComponentController
57 	//====================================================================
58 	class DBSubComponentController;
59 
60     typedef ::cppu::ImplInheritanceHelper2  <   OGenericUnoController
61                                             ,   ::com::sun::star::document::XScriptInvocationContext
62                                             ,   ::com::sun::star::util::XModifiable
63                                             >   DBSubComponentController_Base;
64 
65     struct DBSubComponentController_Impl;
66 	class DBACCESS_DLLPUBLIC DBSubComponentController : public DBSubComponentController_Base
67 	{
68 	private:
69         ::std::auto_ptr<DBSubComponentController_Impl> m_pImpl;
70 
71     private:
72 		/** forces usage of a connection which we do not own
73 			<p>To be used from within XInitialization::initialize, resp. impl_initialize, only.</p>
74 		*/
75 		void		initializeConnection( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxForeignConn );
76 
77 	protected:
78         // OGenericUnoController - initialization
79         virtual void impl_initialize();
80 
81         // OGenericUnoController
82 		virtual void			Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs);
83 
84         virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > getPrivateModel() const;
85 
86                 sal_Bool impl_isModified() const;
87         virtual void     impl_onModifyChanged();
88 
89 	public:
90 
91 		sal_Bool		isReadOnly()			const;
92 		sal_Bool		isEditable()			const;
93         void            setEditable(sal_Bool _bEditable);
94 
95 		// ----------------------------------------------------------------
96 		// asking for connection-related stuff
97 
98 		sal_Bool	isConnected() const;
99 
100 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >
101 					getMetaData( ) const;
102 
103         // ----------------------------------------------------------------
104 		// access to the data source / document
105 		::rtl::OUString getDataSourceName() const;
106 		const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >&
107 					getDataSource() const;
108 		sal_Bool	haveDataSource() const;
109 
110         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
111                     getDatabaseDocument() const;
112 
113         /** provides access to the SDB-level database meta data of the current connection
114         */
115         const ::dbtools::DatabaseMetaData& getSdbMetaData() const;
116 
117 		/** appends an error in the current environment.
118 		*/
119         void appendError(
120                         const ::rtl::OUString& _rErrorMessage,
121                         const ::dbtools::StandardSQLState _eSQLState = ::dbtools::SQL_GENERAL_ERROR,
122                         const sal_Int32 _nErrorCode = 1000
123                      );
124 
125 		/** clears the error state.
126 		*/
127 		void clearError();
128 
129 		/** @return
130 			    <TRUE/> when an error was set otherwise <FALSE/>
131 		*/
132 		sal_Bool hasError() const;
133 
134         /** returns the current error
135         */
136         const ::dbtools::SQLExceptionInfo& getError() const;
137 
138         /** displays the current error, or does nothing if there is no current error
139         */
140         void displayError();
141 
142 		/** shows an info box with the string conntection lost.
143 		*/
144 		void connectionLostMessage() const;
145 
146 		/** gives access to the currently used connection
147 			@return
148 				the currently used connection.
149 		*/
150 		const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >&
151 					getConnection() const;
152 
153 		/** returns the number formatter
154 		*/
155 		::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > 	getNumberFormatter() const;
156 
157 		// ::com::sun::star::frame::XController
158 		virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException );
159 		virtual sal_Bool SAL_CALL attachModel(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & xModel) throw( ::com::sun::star::uno::RuntimeException );
160 
161         // XScriptInvocationContext
162         virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > SAL_CALL getScriptContainer() throw (::com::sun::star::uno::RuntimeException);
163 
164         // XModifiable
165         virtual ::sal_Bool SAL_CALL isModified(  ) throw (::com::sun::star::uno::RuntimeException);
166         virtual void SAL_CALL setModified( ::sal_Bool bModified ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException);
167 
168         // XModifyBroadcaster
169         virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
170         virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
171 
172         // XTitle
173         virtual ::rtl::OUString SAL_CALL getTitle(  ) throw (::com::sun::star::uno::RuntimeException);
174 
175 	protected:
176 		DBSubComponentController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxORB);
177         virtual ~DBSubComponentController();
178 
179 		virtual void        disconnect();
180 		virtual void        reconnect( sal_Bool _bUI );
181                 sal_Bool    ensureConnected( sal_Bool _bUI )	{ if ( !isConnected() ) reconnect( _bUI ); return isConnected(); }
182 
183 		/** called when our connection is beeing disposed
184 			<p>The default implementation does a reconnect</p>
185 		*/
186 		virtual void losingConnection( );
187 
188 	protected:
189 		// XEventListener
190 		virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
191 
192 		// OComponentHelper
193 		virtual void SAL_CALL disposing();
194 
195 		// XInterface
196 		virtual ::com::sun::star::uno::Any	SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException);
197 
198 		// XTypeProvider
199 		virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw (::com::sun::star::uno::RuntimeException);
200 
201     protected:
202         sal_Int32 getCurrentStartNumber() const;
203 
204     private:
205         DBSubComponentController();    // never implemented
206 	};
207 
208 //........................................................................
209 }	// namespace dbaui
210 //........................................................................
211 
212 #endif // DBAUI_SUBCOMPONENTCONTROLLER_HXX
213 
214