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 #ifndef DBAUI_JOINCONTROLLER_HXX
24 #define DBAUI_JOINCONTROLLER_HXX
25 
26 #include "singledoccontroller.hxx"
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include "moduledbu.hxx"
29 #include "JoinTableView.hxx"
30 #include "JoinDesignView.hxx"
31 #include "TableConnectionData.hxx"
32 #include "TableWindowData.hxx"
33 #include <memory>
34 #include <boost/shared_ptr.hpp>
35 
36 namespace comphelper
37 {
38     class NamedValueCollection;
39 }
40 
41 class VCLXWindow;
42 namespace dbaui
43 {
44 	class OAddTableDlg;
45     class AddTableDialogContext;
46 	class OTableConnectionData;
47 	class OTableWindowData;
48 	class OTableWindow;
49 	typedef OSingleDocumentController OJoinController_BASE;
50 
51     class OJoinController : public OJoinController_BASE
52 	{
53         OModuleClient                    m_aModuleClient;
54 	protected:
55         TTableConnectionData m_vTableConnectionData;
56 		TTableWindowData     m_vTableData;
57 
58 		Fraction								m_aZoom;
59 		::dbtools::SQLExceptionInfo				m_aExceptionInfo;
60 
61 		OAddTableDlg*	                            m_pAddTableDialog;
62         ::std::auto_ptr< AddTableDialogContext >    m_pDialogContext;
63         Point                                   m_aMinimumTableViewSize;
64 
65 		// 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.
66 		virtual FeatureState	GetState(sal_uInt16 nId) const;
67 		// execute a feature
68 		virtual void			Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs);
69 
70 		/** loads the information for the windows.
71 			@param	i_rViewSettings
72 				The properties which comes from the layout information.
73 		*/
74         void loadTableWindows( const ::comphelper::NamedValueCollection& i_rViewSettings );
75 
76 		/** loads the information for one window.
77 			@param	_rTable
78 				The properties which comes from the layout information.
79 		*/
80 		void loadTableWindow( const ::comphelper::NamedValueCollection& i_rTableWindowSettings );
81 
82 		/** saves the TableWindows structure in a sequence of property values
83 			@param	_rViewProps
84 				Contains the new sequence.
85 		*/
86         void saveTableWindows( ::comphelper::NamedValueCollection& o_rViewSettings ) const;
87 
88 		virtual ~OJoinController();
89 	public:
90 		OJoinController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM);
91 
92         // ---------------------------------------------------------------
93         // attribute access
94 		inline TTableWindowData*		getTableWindowData()     { return &m_vTableData; }
95 		inline TTableConnectionData*	getTableConnectionData() { return &m_vTableConnectionData;}
96         inline OAddTableDlg*            getAddTableDialog()const { return m_pAddTableDialog; }
97 
98         // ---------------------------------------------------------------
99         // OSingleDocumentController overridables
100 		virtual void        reconnect( sal_Bool _bUI );
101 		virtual void        impl_onModifyChanged();
102 
103         // ---------------------------------------------------------------
104         // own overridables
105         /** determines whether or not it's allowed for database views to participate in the game
106         */
107         virtual bool allowViews() const = 0;
108 
109         /** determines whether or not it's allowed for queries to participate in the game
110         */
111         virtual bool allowQueries() const = 0;
112 
113         /** provides access to the OJoinDesignView belonging to the controller, which might
114             or might not be the direct view (getView)
115         */
116 		virtual OJoinDesignView*	getJoinView();
117 
118 
119         // ---------------------------------------------------------------
120         /** erase the data in the data vector
121 			@param	_pData
122 					the data whioch should be erased
123 		*/
124 		void    removeConnectionData(const TTableConnectionData::value_type& _pData);
125 
126 		void    SaveTabWinsPosSize( OJoinTableView::OTableWindowMap* pTabWinList, long nOffsetX, long nOffsetY );
127 
128         void	SaveTabWinPosSize(OTableWindow* pTabWin, long nOffsetX, long nOffsetY);
129 
130         // ---------------------------------------------------------------
131         // UNO interface overridables
132 		// XEventListener
133 		virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
134 
135 		// ::com::sun::star::lang::XComponent
136 		virtual void	SAL_CALL disposing();
137 		// ::com::sun::star::frame::XController
138 		virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException );
139 
140 
141         // ---------------------------------------------------------------
142         // misc
143 		/** only defines a method to save a SQLException in d&d methods to show the error at a later state
144 			set the internal member m_aExceptionInfo to _rInfo
145 		*/
146 		void setErrorOccured(const ::dbtools::SQLExceptionInfo& _rInfo)
147 		{
148 			m_aExceptionInfo = _rInfo;
149 		}
150 		/**
151 			just returns the internal member and clears it
152 		*/
153 		::dbtools::SQLExceptionInfo clearOccuredError()
154 		{
155 			::dbtools::SQLExceptionInfo aInfo = m_aExceptionInfo;
156 			m_aExceptionInfo = ::dbtools::SQLExceptionInfo();
157 			return aInfo;
158 		}
159 
160     protected:
161 		TTableWindowData::value_type createTableWindowData(const ::rtl::OUString& _sComposedName,const ::rtl::OUString& _sTableName,const ::rtl::OUString& _sWindowName);
162 		// ask the user if the design should be saved when it is modified
163 		virtual short saveModified() = 0;
164 		// called when the orignal state should be reseted (first time load)
165 		virtual void reset()		 = 0;
166 		virtual void describeSupportedFeatures();
167 
168         AddTableDialogContext&  impl_getDialogContext() const;
169 	};
170 }
171 #endif // DBAUI_JOINCONTROLLER_HXX
172 
173