merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / inc / querycontroller.hxx
blobe77d8106dbb7d5e16271fc603e3f0286a4e48197
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: querycontroller.hxx,v $
10 * $Revision: 1.40 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef DBAUI_QUERYCONTROLLER_HXX
32 #define DBAUI_QUERYCONTROLLER_HXX
34 #include "JoinController.hxx"
35 #include "JoinTableView.hxx"
36 #include "querycontainerwindow.hxx"
37 #include "queryview.hxx"
38 #include "svx/ParseContext.hxx"
39 #include "TableFieldDescription.hxx"
41 /** === begin UNO includes === **/
42 #include <com/sun/star/io/XObjectInputStream.hpp>
43 #include <com/sun/star/io/XObjectOutputStream.hpp>
44 #include <com/sun/star/sdb/CommandType.hpp>
45 #include <com/sun/star/sdb/XSQLQueryComposer.hpp>
46 #include <com/sun/star/sdbc/XConnection.hpp>
47 #include <com/sun/star/sdbcx/XAlterView.hpp>
48 /** === end UNO includes === **/
50 #include <comphelper/proparrhlp.hxx>
51 #include <comphelper/propertycontainer.hxx>
52 #include <comphelper/uno3.hxx>
53 #include <comphelper/uno3.hxx>
54 #include <connectivity/sqliterator.hxx>
55 #include <connectivity/sqlnode.hxx>
56 #include <connectivity/sqlparse.hxx>
57 #include <svtools/undo.hxx>
59 class VCLXWindow;
60 namespace dbaui
62 class OQueryView;
63 class OQueryContainerWindow;
64 class OTableConnectionData;
65 class OTableWindowData;
66 class OAddTableDlg;
67 class OTableFieldDesc;
68 class OQueryTableWindow;
70 class OQueryController;
71 typedef ::comphelper::OPropertyContainer OQueryController_PBase;
72 typedef ::comphelper::OPropertyArrayUsageHelper< OQueryController > OQueryController_PABase;
73 class OQueryController :public OJoinController
74 ,public OQueryController_PBase
75 ,public OQueryController_PABase
77 OTableFields m_vTableFieldDesc;
78 OTableFields m_vUnUsedFieldsDesc; // contains fields which aren't visible and don't have any criteria
80 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aFieldInformation;
82 ::svxform::OSystemParseContext* m_pParseContext;
83 ::connectivity::OSQLParser m_aSqlParser;
84 ::connectivity::OSQLParseTreeIterator* m_pSqlIterator;
86 ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLQueryComposer > m_xComposer;
87 /// if we're editing an existing view, this is non-NULL
88 ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XAlterView > m_xAlterView;
90 ::rtl::OUString m_sStatement; // contains the current sql statement
91 ::rtl::OUString m_sUpdateCatalogName; // catalog for update data
92 ::rtl::OUString m_sUpdateSchemaName; // schema for update data
93 ::rtl::OUString m_sUpdateTableName; // table for update data
94 mutable ::rtl::OUString
95 m_sName; // name of the query
97 sal_Int32 m_nVisibleRows; // which rows the selection browse should show
98 sal_Int32 m_nSplitPos; // the position of the splitter
99 sal_Int32 m_nCommandType; // the type of the object we're designing
100 sal_Bool m_bGraphicalDesign; // are we in the graphical design mode (TRUE) or in the text design (FALSE)?
101 sal_Bool m_bDistinct; // true when you want "select distinct" otherwise false
102 sal_Bool m_bViewAlias; // show the alias row in the design view
103 sal_Bool m_bViewTable; // show the table row in the design view
104 sal_Bool m_bViewFunction; // show the function row in the design view
105 sal_Bool m_bEscapeProcessing;// is true when we shouldn't parse the statement
108 /** returns the container of queries, views, or command definitions, depending on what object type
109 we design currently.
111 Not allowed to be called if we design an independent SQL command.
113 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
114 getObjectContainer() const;
116 inline bool editingView() const { return m_nCommandType == ::com::sun::star::sdb::CommandType::TABLE; }
117 inline bool editingQuery() const { return m_nCommandType == ::com::sun::star::sdb::CommandType::QUERY; }
118 inline bool editingCommand() const { return m_nCommandType == ::com::sun::star::sdb::CommandType::COMMAND; }
120 sal_Bool askForNewName( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xElements,
121 sal_Bool _bSaveAs);
122 // creates the querycomposer
123 void setQueryComposer();
124 void deleteIterator();
125 void executeQuery();
126 bool doSaveAsDoc(sal_Bool _bSaveAs);
128 void saveViewSettings(::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rViewProps);
129 void loadViewSettings(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& _rViewProps);
130 ::rtl::OUString translateStatement( bool _bFireStatementChange = true );
132 ::rtl::OUString getDefaultName() const;
134 protected:
135 // all the features which should be handled by this class
136 virtual void describeSupportedFeatures();
137 // state of a feature. 'feature' may be the handle of a ::com::sun::star::util::URL somebody requested a dispatch interface for OR a toolbar slot.
138 virtual FeatureState GetState(sal_uInt16 nId) const;
139 // execute a feature
140 virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs);
142 virtual void reconnect( sal_Bool _bUI );
143 virtual ::rtl::OUString getPrivateTitle( ) const;
145 OQueryContainerWindow* getContainer() const { return static_cast< OQueryContainerWindow* >( getView() ); }
147 public:
148 OQueryController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM);
150 virtual ~OQueryController();
151 OTableFields& getTableFieldDesc() { return m_vTableFieldDesc; }
152 OTableFields& getUnUsedFields() { return m_vUnUsedFieldsDesc; }
154 void clearFields();
156 virtual void setModified(sal_Bool _bModified=sal_True);
158 // should the statement be parsed by our own sql parser
159 sal_Bool isEsacpeProcessing() const { return m_bEscapeProcessing; }
160 sal_Bool isGraphicalDesign() const { return m_bGraphicalDesign; }
161 sal_Bool isDistinct() const { return m_bDistinct; }
163 ::rtl::OUString getStatement() const { return m_sStatement; }
164 sal_Int32 getSplitPos() const { return m_nSplitPos;}
165 sal_Int32 getVisibleRows() const { return m_nVisibleRows; }
167 void setDistinct(sal_Bool _bDistinct) { m_bDistinct = _bDistinct;}
168 void setSplitPos(sal_Int32 _nSplitPos) { m_nSplitPos = _nSplitPos;}
169 void setVisibleRows(sal_Int32 _nVisibleRows) { m_nVisibleRows = _nVisibleRows;}
171 sal_Int32 getColWidth(sal_uInt16 _nColPos) const;
173 ::connectivity::OSQLParser& getParser() { return m_aSqlParser; }
174 ::connectivity::OSQLParseTreeIterator& getParseIterator() { return *m_pSqlIterator; }
176 virtual sal_Bool Construct(Window* pParent);
178 DECLARE_XINTERFACE( )
179 DECLARE_XTYPEPROVIDER( )
180 // XPropertySet
181 virtual com::sun::star::uno::Reference<com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(com::sun::star::uno::RuntimeException);
182 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
184 // XEventListener
185 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
187 // ::com::sun::star::lang::XComponent
188 virtual void SAL_CALL disposing();
190 virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
191 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
192 // need by registration
193 static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException );
194 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
195 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
196 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
198 private:
199 virtual void onLoadedMenu(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager >& _xLayoutManager);
200 // OPropertyArrayUsageHelper
201 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
203 virtual OJoinDesignView* getJoinView();
204 // ask the user if the design should be saved when it is modified
205 virtual short saveModified();
206 virtual void reset();
207 virtual void impl_initialize();
209 void impl_reset();
210 /// tells the user that we needed to switch to SQL view automatically
211 void impl_showAutoSQLViewError( const ::com::sun::star::uno::Any& _rErrorDetails );
213 /** switches to the graphical or SQL view mode, as determined by m_bGraphicalDesign
215 bool impl_setViewMode( ::dbtools::SQLExceptionInfo* _pErrorInfo );
217 /// sets m_sStatement, and notifies our respective property change listeners
218 void setStatement_fireEvent( const ::rtl::OUString& _rNewStatement, bool _bFireStatementChange = true );
219 /// sets the m_bEscapeProcessing member, and notifies our respective property change listeners
220 void setEscapeProcessing_fireEvent( const sal_Bool _bEscapeProcessing );
222 // OJoinController overridables
223 virtual bool allowViews() const;
224 virtual bool allowQueries() const;
226 private:
227 DECL_LINK( OnExecuteAddTable, void* );
230 #endif // DBAUI_QUERYCONTROLLER_HXX