12e2212a7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32e2212a7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42e2212a7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52e2212a7SAndrew Rist  * distributed with this work for additional information
62e2212a7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72e2212a7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
82e2212a7SAndrew Rist  * "License"); you may not use this file except in compliance
92e2212a7SAndrew Rist  * with the License.  You may obtain a copy of the License at
102e2212a7SAndrew Rist  *
112e2212a7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
122e2212a7SAndrew Rist  *
132e2212a7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
142e2212a7SAndrew Rist  * software distributed under the License is distributed on an
152e2212a7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162e2212a7SAndrew Rist  * KIND, either express or implied.  See the License for the
172e2212a7SAndrew Rist  * specific language governing permissions and limitations
182e2212a7SAndrew Rist  * under the License.
192e2212a7SAndrew Rist  *
202e2212a7SAndrew Rist  *************************************************************/
212e2212a7SAndrew Rist 
222e2212a7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef DBAUI_SUBCOMPONENTCONTROLLER_HXX
25cdf0e10cSrcweir #define DBAUI_SUBCOMPONENTCONTROLLER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "genericcontroller.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir /** === begin UNO includes === **/
30cdf0e10cSrcweir #include <com/sun/star/document/XScriptInvocationContext.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
32cdf0e10cSrcweir #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
33cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp>
34cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatter.hpp>
35cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
36cdf0e10cSrcweir /** === end UNO includes === **/
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <comphelper/broadcasthelper.hxx>
39cdf0e10cSrcweir #include <comphelper/proparrhlp.hxx>
40cdf0e10cSrcweir #include <comphelper/propertycontainer.hxx>
41cdf0e10cSrcweir #include <connectivity/dbmetadata.hxx>
42cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <memory>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir //........................................................................
47cdf0e10cSrcweir namespace dbaui
48cdf0e10cSrcweir {
49cdf0e10cSrcweir //........................................................................
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 	//====================================================================
52cdf0e10cSrcweir 	//= DBSubComponentController
53cdf0e10cSrcweir 	//====================================================================
54cdf0e10cSrcweir 	class DBSubComponentController;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     typedef ::cppu::ImplInheritanceHelper2  <   OGenericUnoController
57cdf0e10cSrcweir                                             ,   ::com::sun::star::document::XScriptInvocationContext
58cdf0e10cSrcweir                                             ,   ::com::sun::star::util::XModifiable
59cdf0e10cSrcweir                                             >   DBSubComponentController_Base;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     struct DBSubComponentController_Impl;
62cdf0e10cSrcweir 	class DBACCESS_DLLPUBLIC DBSubComponentController : public DBSubComponentController_Base
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir 	private:
65cdf0e10cSrcweir         ::std::auto_ptr<DBSubComponentController_Impl> m_pImpl;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     private:
68cdf0e10cSrcweir 		/** forces usage of a connection which we do not own
69cdf0e10cSrcweir 			<p>To be used from within XInitialization::initialize, resp. impl_initialize, only.</p>
70cdf0e10cSrcweir 		*/
71cdf0e10cSrcweir 		void		initializeConnection( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxForeignConn );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	protected:
74cdf0e10cSrcweir         // OGenericUnoController - initialization
75cdf0e10cSrcweir         virtual void impl_initialize();
76cdf0e10cSrcweir 
77cdf0e10cSrcweir         // OGenericUnoController
78cdf0e10cSrcweir 		virtual void			Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs);
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > getPrivateModel() const;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir                 sal_Bool impl_isModified() const;
83cdf0e10cSrcweir         virtual void     impl_onModifyChanged();
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	public:
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 		sal_Bool		isReadOnly()			const;
88cdf0e10cSrcweir 		sal_Bool		isEditable()			const;
89cdf0e10cSrcweir         void            setEditable(sal_Bool _bEditable);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 		// ----------------------------------------------------------------
92cdf0e10cSrcweir 		// asking for connection-related stuff
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 		sal_Bool	isConnected() const;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >
97cdf0e10cSrcweir 					getMetaData( ) const;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         // ----------------------------------------------------------------
100cdf0e10cSrcweir 		// access to the data source / document
101cdf0e10cSrcweir 		::rtl::OUString getDataSourceName() const;
102cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >&
103cdf0e10cSrcweir 					getDataSource() const;
104cdf0e10cSrcweir 		sal_Bool	haveDataSource() const;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
107cdf0e10cSrcweir                     getDatabaseDocument() const;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         /** provides access to the SDB-level database meta data of the current connection
110cdf0e10cSrcweir         */
111cdf0e10cSrcweir         const ::dbtools::DatabaseMetaData& getSdbMetaData() const;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 		/** appends an error in the current environment.
114cdf0e10cSrcweir 		*/
115cdf0e10cSrcweir         void appendError(
116cdf0e10cSrcweir                         const ::rtl::OUString& _rErrorMessage,
117cdf0e10cSrcweir                         const ::dbtools::StandardSQLState _eSQLState = ::dbtools::SQL_GENERAL_ERROR,
118cdf0e10cSrcweir                         const sal_Int32 _nErrorCode = 1000
119cdf0e10cSrcweir                      );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 		/** clears the error state.
122cdf0e10cSrcweir 		*/
123cdf0e10cSrcweir 		void clearError();
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 		/** @return
126cdf0e10cSrcweir 			    <TRUE/> when an error was set otherwise <FALSE/>
127cdf0e10cSrcweir 		*/
128cdf0e10cSrcweir 		sal_Bool hasError() const;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         /** returns the current error
131cdf0e10cSrcweir         */
132cdf0e10cSrcweir         const ::dbtools::SQLExceptionInfo& getError() const;
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         /** displays the current error, or does nothing if there is no current error
135cdf0e10cSrcweir         */
136cdf0e10cSrcweir         void displayError();
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 		/** shows an info box with the string conntection lost.
139cdf0e10cSrcweir 		*/
140cdf0e10cSrcweir 		void connectionLostMessage() const;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 		/** gives access to the currently used connection
143cdf0e10cSrcweir 			@return
144cdf0e10cSrcweir 				the currently used connection.
145cdf0e10cSrcweir 		*/
146cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >&
147cdf0e10cSrcweir 					getConnection() const;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 		/** returns the number formatter
150cdf0e10cSrcweir 		*/
151cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > 	getNumberFormatter() const;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 		// ::com::sun::star::frame::XController
154cdf0e10cSrcweir 		virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException );
155cdf0e10cSrcweir 		virtual sal_Bool SAL_CALL attachModel(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & xModel) throw( ::com::sun::star::uno::RuntimeException );
156cdf0e10cSrcweir 
157cdf0e10cSrcweir         // XScriptInvocationContext
158cdf0e10cSrcweir         virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > SAL_CALL getScriptContainer() throw (::com::sun::star::uno::RuntimeException);
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         // XModifiable
161cdf0e10cSrcweir         virtual ::sal_Bool SAL_CALL isModified(  ) throw (::com::sun::star::uno::RuntimeException);
162cdf0e10cSrcweir         virtual void SAL_CALL setModified( ::sal_Bool bModified ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException);
163cdf0e10cSrcweir 
164cdf0e10cSrcweir         // XModifyBroadcaster
165cdf0e10cSrcweir         virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
166cdf0e10cSrcweir         virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         // XTitle
169cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL getTitle(  ) throw (::com::sun::star::uno::RuntimeException);
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 	protected:
172cdf0e10cSrcweir 		DBSubComponentController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxORB);
173cdf0e10cSrcweir         virtual ~DBSubComponentController();
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 		virtual void        disconnect();
176cdf0e10cSrcweir 		virtual void        reconnect( sal_Bool _bUI );
ensureConnected(sal_Bool _bUI)177cdf0e10cSrcweir                 sal_Bool    ensureConnected( sal_Bool _bUI )	{ if ( !isConnected() ) reconnect( _bUI ); return isConnected(); }
178cdf0e10cSrcweir 
179*30acf5e8Spfg 		/** called when our connection is being disposed
180cdf0e10cSrcweir 			<p>The default implementation does a reconnect</p>
181cdf0e10cSrcweir 		*/
182cdf0e10cSrcweir 		virtual void losingConnection( );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	protected:
185cdf0e10cSrcweir 		// XEventListener
186cdf0e10cSrcweir 		virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 		// OComponentHelper
189cdf0e10cSrcweir 		virtual void SAL_CALL disposing();
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 		// XInterface
192cdf0e10cSrcweir 		virtual ::com::sun::star::uno::Any	SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException);
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 		// XTypeProvider
195cdf0e10cSrcweir 		virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw (::com::sun::star::uno::RuntimeException);
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     protected:
198cdf0e10cSrcweir         sal_Int32 getCurrentStartNumber() const;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     private:
201cdf0e10cSrcweir         DBSubComponentController();    // never implemented
202cdf0e10cSrcweir 	};
203cdf0e10cSrcweir 
204cdf0e10cSrcweir //........................................................................
205cdf0e10cSrcweir }	// namespace dbaui
206cdf0e10cSrcweir //........................................................................
207cdf0e10cSrcweir 
208cdf0e10cSrcweir #endif // DBAUI_SUBCOMPONENTCONTROLLER_HXX
209cdf0e10cSrcweir 
210