1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_SQLCOMMANDDESIGN_HXX
25 #define EXTENSIONS_SOURCE_PROPCTRLR_SQLCOMMANDDESIGN_HXX
26 
27 /** === begin UNO includes === **/
28 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
29 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
30 #include <com/sun/star/frame/XController.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
33 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
34 /** === end UNO includes === **/
35 
36 #include <connectivity/dbtools.hxx>
37 #include <tools/link.hxx>
38 #include <cppuhelper/implbase1.hxx>
39 #include <rtl/ref.hxx>
40 
41 //........................................................................
42 namespace pcr
43 {
44 //........................................................................
45 
46     class ISQLCommandAdapter;
47 	//====================================================================
48 	//= SQLCommandDesigner
49 	//====================================================================
50     typedef ::cppu::WeakImplHelper1 <   ::com::sun::star::beans::XPropertyChangeListener
51                                     >   SQLCommandDesigner_Base;
52     /** encapsulates the code for calling and managing a query design frame, used
53         for interactively designing the Command property of a ->RowSet
54     */
55     class SQLCommandDesigner : public SQLCommandDesigner_Base
56 	{
57     private:
58         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >        m_xContext;
59         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiComponentFactory >  m_xORB;
60         ::dbtools::SharedConnection                                                         m_xConnection;
61         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >            m_xDesigner;
62         ::rtl::Reference< ISQLCommandAdapter >                                              m_xObjectAdapter;
63         Link                                                                                m_aCloseLink;
64 
65     public:
66         /** creates the instance, and immediately opens the SQL command design frame
67 
68         @param  _rxContext
69             our component context. Must not be <NULL/>, and must provide a non-<NULL/> XMultiComponentFactory
70         @param  _rxPropertyAdapter
71             an adapter to the object's SQL command related properties
72         @param  _rConnection
73             the current connection of ->_rxRowSet. Must not be <NULL/>.
74         @param _rCloseLink
75             link to call when the component has been closed
76         @throws ::com::sun::star::lang::NullPointerException
77             if any of the arguments (except ->_rCloseLink) is <NULL/>, or if the component context
78             does not provide a valid component factory.
79         */
80         SQLCommandDesigner(
81             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
82             const ::rtl::Reference< ISQLCommandAdapter >& _rxPropertyAdapter,
83             const ::dbtools::SharedConnection& _rConnection,
84             const Link& _rCloseLink
85         );
86 
87         /** determines whether the SQL Command designer is currently active, i.e.
88             if there currently exists a frame which allows the user entering the SQL command
89         */
isActive() const90         inline bool isActive() const { return m_xDesigner.is(); }
91 
92         /** returns the property adapter used by the instance
93         */
getPropertyAdapter() const94         inline const ::rtl::Reference< ISQLCommandAdapter >& getPropertyAdapter() const { return m_xObjectAdapter; }
95 
96         /** raises the designer window to top
97             @precond
98                 the designer is active (->isActive)
99             @precond
100                 the instance is not disposed
101         */
102         void    raise() const;
103 
104         /** suspends the designer
105             @precond
106                 the designer is active (->isActive)
107             @precond
108                 the instance is not disposed
109         */
110         bool    suspend() const;
111 
112         /** disposes the instance so that it becomes non-functional
113         */
114         void    dispose();
115 
116     protected:
117         // XPropertyChangeListener
118         virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException);
119 
120         // XEventListener
121         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
122 
123     protected:
124         ~SQLCommandDesigner();
125 
126         /** opens a new frame for interactively designing an SQL command
127             @precond
128                 the designer is not currently active (see ->isActive)
129             @precond
130                 ->m_xConnection is not <NULL/>
131         */
132         void impl_doOpenDesignerFrame_nothrow();
133 
134         /** impl-version of ->raise
135         */
136         void impl_raise_nothrow() const;
137 
138         /** determines whether we are already disposed
139         */
impl_isDisposed() const140         bool impl_isDisposed() const
141         {
142             return !m_xContext.is();
143         }
144         /** checks whether we are already disposed
145             @throws ::com::sun::star::lang::DisposedException
146                 if we in fact are disposed
147         */
148         void impl_checkDisposed_throw() const;
149 
150         /** create an empty top-level frame, which does not belong to the desktop's frame list
151             @precond
152                 ->m_xORB is not <NULL/>
153         */
154         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >
155             impl_createEmptyParentlessTask_nothrow() const;
156 
157         /** called whenever the component denoted by m_xDesigner has been closed
158             <em>by an external instance</em>
159         */
160         void impl_designerClosed_nothrow();
161 
162         /** closes the component denoted by m_xDesigner
163             @precond
164                 our designer component is actually active (->isActive)
165             @precond
166                 we're not disposed already
167         */
168         void impl_closeDesigner_nothrow();
169 
170         /** suspends our designer component
171             @precond
172                 the designer component is actually active (->isActive)
173             @return
174                 <TRUE/> if the suspension was successful, <FALSE/> if it was vetoed
175         */
176         bool impl_trySuspendDesigner_nothrow() const;
177 
178         /** gets the current value of the command property
179         */
180         ::rtl::OUString
181                 impl_getCommandPropertyValue_nothrow();
182 
183         /** sets anew value for the command property
184         */
185         void    impl_setCommandPropertyValue_nothrow( const ::rtl::OUString& _rCommand ) const;
186 
187     private:
188         SQLCommandDesigner();                                       // never implemented
189         SQLCommandDesigner( const SQLCommandDesigner& );            // never implemented
190         SQLCommandDesigner& operator=( const SQLCommandDesigner& ); // never implemented
191 	};
192 
193 	//====================================================================
194 	//= ISQLCommandAdapter
195 	//====================================================================
196     /** an adapter to forward changed SQL command property values to a component
197     */
198     class ISQLCommandAdapter : public ::rtl::IReference
199     {
200     public:
201         /// retrieves the current SQL command of the component
202         virtual ::rtl::OUString getSQLCommand() const = 0;
203         /// retrieves the current value of the EscapeProcessing property of the component
204         virtual sal_Bool        getEscapeProcessing() const = 0;
205 
206         /// sets a new SQL command
207         virtual void    setSQLCommand( const ::rtl::OUString& _rCommand ) const = 0;
208         /// sets a new EscapeProcessing property value
209         virtual void    setEscapeProcessing( const sal_Bool _bEscapeProcessing ) const = 0;
210 
211         virtual ~ISQLCommandAdapter();
212     };
213 
214 //........................................................................
215 } // namespace pcr
216 //........................................................................
217 
218 #endif // EXTENSIONS_SOURCE_PROPCTRLR_SQLCOMMANDDESIGN_HXX
219 
220