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