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 EXTENSIONS_SOURCE_PROPCTRLR_SQLCOMMANDDESIGN_HXX
29*cdf0e10cSrcweir #define EXTENSIONS_SOURCE_PROPCTRLR_SQLCOMMANDDESIGN_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir /** === begin UNO includes === **/
32*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyChangeListener.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
38*cdf0e10cSrcweir /** === end UNO includes === **/
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
41*cdf0e10cSrcweir #include <tools/link.hxx>
42*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
43*cdf0e10cSrcweir #include <rtl/ref.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir //........................................................................
46*cdf0e10cSrcweir namespace pcr
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir //........................................................................
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir     class ISQLCommandAdapter;
51*cdf0e10cSrcweir 	//====================================================================
52*cdf0e10cSrcweir 	//= SQLCommandDesigner
53*cdf0e10cSrcweir 	//====================================================================
54*cdf0e10cSrcweir     typedef ::cppu::WeakImplHelper1 <   ::com::sun::star::beans::XPropertyChangeListener
55*cdf0e10cSrcweir                                     >   SQLCommandDesigner_Base;
56*cdf0e10cSrcweir     /** encapsulates the code for calling and managing a query design frame, used
57*cdf0e10cSrcweir         for interactively designing the Command property of a ->RowSet
58*cdf0e10cSrcweir     */
59*cdf0e10cSrcweir     class SQLCommandDesigner : public SQLCommandDesigner_Base
60*cdf0e10cSrcweir 	{
61*cdf0e10cSrcweir     private:
62*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >        m_xContext;
63*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiComponentFactory >  m_xORB;
64*cdf0e10cSrcweir         ::dbtools::SharedConnection                                                         m_xConnection;
65*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >            m_xDesigner;
66*cdf0e10cSrcweir         ::rtl::Reference< ISQLCommandAdapter >                                              m_xObjectAdapter;
67*cdf0e10cSrcweir         Link                                                                                m_aCloseLink;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     public:
70*cdf0e10cSrcweir         /** creates the instance, and immediately opens the SQL command design frame
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir         @param  _rxContext
73*cdf0e10cSrcweir             our component context. Must not be <NULL/>, and must provide a non-<NULL/> XMultiComponentFactory
74*cdf0e10cSrcweir         @param  _rxPropertyAdapter
75*cdf0e10cSrcweir             an adapter to the object's SQL command related properties
76*cdf0e10cSrcweir         @param  _rConnection
77*cdf0e10cSrcweir             the current connection of ->_rxRowSet. Must not be <NULL/>.
78*cdf0e10cSrcweir         @param _rCloseLink
79*cdf0e10cSrcweir             link to call when the component has been closed
80*cdf0e10cSrcweir         @throws ::com::sun::star::lang::NullPointerException
81*cdf0e10cSrcweir             if any of the arguments (except ->_rCloseLink) is <NULL/>, or if the component context
82*cdf0e10cSrcweir             does not provide a valid component factory.
83*cdf0e10cSrcweir         */
84*cdf0e10cSrcweir         SQLCommandDesigner(
85*cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
86*cdf0e10cSrcweir             const ::rtl::Reference< ISQLCommandAdapter >& _rxPropertyAdapter,
87*cdf0e10cSrcweir             const ::dbtools::SharedConnection& _rConnection,
88*cdf0e10cSrcweir             const Link& _rCloseLink
89*cdf0e10cSrcweir         );
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir         /** determines whether the SQL Command designer is currently active, i.e.
92*cdf0e10cSrcweir             if there currently exists a frame which allows the user entering the SQL command
93*cdf0e10cSrcweir         */
94*cdf0e10cSrcweir         inline bool isActive() const { return m_xDesigner.is(); }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir         /** returns the property adapter used by the instance
97*cdf0e10cSrcweir         */
98*cdf0e10cSrcweir         inline const ::rtl::Reference< ISQLCommandAdapter >& getPropertyAdapter() const { return m_xObjectAdapter; }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir         /** raises the designer window to top
101*cdf0e10cSrcweir             @precond
102*cdf0e10cSrcweir                 the designer is active (->isActive)
103*cdf0e10cSrcweir             @precond
104*cdf0e10cSrcweir                 the instance is not disposed
105*cdf0e10cSrcweir         */
106*cdf0e10cSrcweir         void    raise() const;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir         /** suspends the designer
109*cdf0e10cSrcweir             @precond
110*cdf0e10cSrcweir                 the designer is active (->isActive)
111*cdf0e10cSrcweir             @precond
112*cdf0e10cSrcweir                 the instance is not disposed
113*cdf0e10cSrcweir         */
114*cdf0e10cSrcweir         bool    suspend() const;
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir         /** disposes the instance so that it becomes non-functional
117*cdf0e10cSrcweir         */
118*cdf0e10cSrcweir         void    dispose();
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     protected:
121*cdf0e10cSrcweir         // XPropertyChangeListener
122*cdf0e10cSrcweir         virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir         // XEventListener
125*cdf0e10cSrcweir         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     protected:
128*cdf0e10cSrcweir         ~SQLCommandDesigner();
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir         /** opens a new frame for interactively designing an SQL command
131*cdf0e10cSrcweir             @precond
132*cdf0e10cSrcweir                 the designer is not currently active (see ->isActive)
133*cdf0e10cSrcweir             @precond
134*cdf0e10cSrcweir                 ->m_xConnection is not <NULL/>
135*cdf0e10cSrcweir         */
136*cdf0e10cSrcweir         void impl_doOpenDesignerFrame_nothrow();
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir         /** impl-version of ->raise
139*cdf0e10cSrcweir         */
140*cdf0e10cSrcweir         void impl_raise_nothrow() const;
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         /** determines whether we are already disposed
143*cdf0e10cSrcweir         */
144*cdf0e10cSrcweir         bool impl_isDisposed() const
145*cdf0e10cSrcweir         {
146*cdf0e10cSrcweir             return !m_xContext.is();
147*cdf0e10cSrcweir         }
148*cdf0e10cSrcweir         /** checks whether we are already disposed
149*cdf0e10cSrcweir             @throws ::com::sun::star::lang::DisposedException
150*cdf0e10cSrcweir                 if we in fact are disposed
151*cdf0e10cSrcweir         */
152*cdf0e10cSrcweir         void impl_checkDisposed_throw() const;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         /** create an empty top-level frame, which does not belong to the desktop's frame list
155*cdf0e10cSrcweir             @precond
156*cdf0e10cSrcweir                 ->m_xORB is not <NULL/>
157*cdf0e10cSrcweir         */
158*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >
159*cdf0e10cSrcweir             impl_createEmptyParentlessTask_nothrow() const;
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir         /** called whenever the component denoted by m_xDesigner has been closed
162*cdf0e10cSrcweir             <em>by an external instance</em>
163*cdf0e10cSrcweir         */
164*cdf0e10cSrcweir         void impl_designerClosed_nothrow();
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir         /** closes the component denoted by m_xDesigner
167*cdf0e10cSrcweir             @precond
168*cdf0e10cSrcweir                 our designer component is actually active (->isActive)
169*cdf0e10cSrcweir             @precond
170*cdf0e10cSrcweir                 we're not disposed already
171*cdf0e10cSrcweir         */
172*cdf0e10cSrcweir         void impl_closeDesigner_nothrow();
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir         /** suspends our designer component
175*cdf0e10cSrcweir             @precond
176*cdf0e10cSrcweir                 the designer component is actually active (->isActive)
177*cdf0e10cSrcweir             @return
178*cdf0e10cSrcweir                 <TRUE/> if the suspension was successful, <FALSE/> if it was vetoed
179*cdf0e10cSrcweir         */
180*cdf0e10cSrcweir         bool impl_trySuspendDesigner_nothrow() const;
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir         /** gets the current value of the command property
183*cdf0e10cSrcweir         */
184*cdf0e10cSrcweir         ::rtl::OUString
185*cdf0e10cSrcweir                 impl_getCommandPropertyValue_nothrow();
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir         /** sets anew value for the command property
188*cdf0e10cSrcweir         */
189*cdf0e10cSrcweir         void    impl_setCommandPropertyValue_nothrow( const ::rtl::OUString& _rCommand ) const;
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     private:
192*cdf0e10cSrcweir         SQLCommandDesigner();                                       // never implemented
193*cdf0e10cSrcweir         SQLCommandDesigner( const SQLCommandDesigner& );            // never implemented
194*cdf0e10cSrcweir         SQLCommandDesigner& operator=( const SQLCommandDesigner& ); // never implemented
195*cdf0e10cSrcweir 	};
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 	//====================================================================
198*cdf0e10cSrcweir 	//= ISQLCommandAdapter
199*cdf0e10cSrcweir 	//====================================================================
200*cdf0e10cSrcweir     /** an adapter to forward changed SQL command property values to a component
201*cdf0e10cSrcweir     */
202*cdf0e10cSrcweir     class ISQLCommandAdapter : public ::rtl::IReference
203*cdf0e10cSrcweir     {
204*cdf0e10cSrcweir     public:
205*cdf0e10cSrcweir         /// retrieves the current SQL command of the component
206*cdf0e10cSrcweir         virtual ::rtl::OUString getSQLCommand() const = 0;
207*cdf0e10cSrcweir         /// retrieves the current value of the EscapeProcessing property of the component
208*cdf0e10cSrcweir         virtual sal_Bool        getEscapeProcessing() const = 0;
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir         /// sets a new SQL command
211*cdf0e10cSrcweir         virtual void    setSQLCommand( const ::rtl::OUString& _rCommand ) const = 0;
212*cdf0e10cSrcweir         /// sets a new EscapeProcessing property value
213*cdf0e10cSrcweir         virtual void    setEscapeProcessing( const sal_Bool _bEscapeProcessing ) const = 0;
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir         virtual ~ISQLCommandAdapter();
216*cdf0e10cSrcweir     };
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir //........................................................................
219*cdf0e10cSrcweir } // namespace pcr
220*cdf0e10cSrcweir //........................................................................
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir #endif // EXTENSIONS_SOURCE_PROPCTRLR_SQLCOMMANDDESIGN_HXX
223*cdf0e10cSrcweir 
224