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