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