xref: /AOO41X/main/dbaccess/source/ui/querydesign/JoinController.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir #ifndef _SFXSIDS_HRC
31*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir #ifndef _DBU_QRY_HRC_
34*cdf0e10cSrcweir #include "dbu_qry.hrc"
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
37*cdf0e10cSrcweir #include "browserids.hxx"
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #ifndef _COMPHELPER_TYPES_HXX_
40*cdf0e10cSrcweir #include <comphelper/types.hxx>
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
43*cdf0e10cSrcweir #include "dbustrings.hrc"
44*cdf0e10cSrcweir #endif
45*cdf0e10cSrcweir #ifndef _CONNECTIVITY_DBTOOLS_HXX_
46*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
47*cdf0e10cSrcweir #endif
48*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
49*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
50*cdf0e10cSrcweir #endif
51*cdf0e10cSrcweir #ifndef _COMPHELPER_EXTRACT_HXX_
52*cdf0e10cSrcweir #include <comphelper/extract.hxx>
53*cdf0e10cSrcweir #endif
54*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
55*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
56*cdf0e10cSrcweir #endif
57*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
58*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
59*cdf0e10cSrcweir #endif
60*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
61*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
62*cdf0e10cSrcweir #endif
63*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
64*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
65*cdf0e10cSrcweir #endif
66*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_
67*cdf0e10cSrcweir #include <com/sun/star/sdbcx/KeyType.hpp>
68*cdf0e10cSrcweir #endif
69*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XDROP_HPP_
70*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDrop.hpp>
71*cdf0e10cSrcweir #endif
72*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XALTERTABLE_HPP_
73*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAlterTable.hpp>
74*cdf0e10cSrcweir #endif
75*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
76*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAppend.hpp>
77*cdf0e10cSrcweir #endif
78*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
79*cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
80*cdf0e10cSrcweir #endif
81*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_SQLWARNING_HPP_
82*cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
83*cdf0e10cSrcweir #endif
84*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_
85*cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
86*cdf0e10cSrcweir #endif
87*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
88*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
89*cdf0e10cSrcweir #endif
90*cdf0e10cSrcweir #ifndef _DBHELPER_DBEXCEPTION_HXX_
91*cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
92*cdf0e10cSrcweir #endif
93*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_DIALOGS_XEXECUTABLEDIALOG_HPP_
94*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
95*cdf0e10cSrcweir #endif
96*cdf0e10cSrcweir #ifndef _COMPHELPER_STREAMSECTION_HXX_
97*cdf0e10cSrcweir #include <comphelper/streamsection.hxx>
98*cdf0e10cSrcweir #endif
99*cdf0e10cSrcweir #ifndef _COMPHELPER_BASIC_IO_HXX_
100*cdf0e10cSrcweir #include <comphelper/basicio.hxx>
101*cdf0e10cSrcweir #endif
102*cdf0e10cSrcweir #ifndef _COMPHELPER_SEQSTREAM_HXX
103*cdf0e10cSrcweir #include <comphelper/seqstream.hxx>
104*cdf0e10cSrcweir #endif
105*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP_
106*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
107*cdf0e10cSrcweir #endif
108*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_IO_XACTIVEDATASINK_HPP_
109*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
110*cdf0e10cSrcweir #endif
111*cdf0e10cSrcweir #ifndef _DBAUI_SQLMESSAGE_HXX_
112*cdf0e10cSrcweir #include "sqlmessage.hxx"
113*cdf0e10cSrcweir #endif
114*cdf0e10cSrcweir #ifndef DBAUI_JOINCONTROLLER_HXX
115*cdf0e10cSrcweir #include "JoinController.hxx"
116*cdf0e10cSrcweir #endif
117*cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX
118*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
119*cdf0e10cSrcweir #endif
120*cdf0e10cSrcweir #ifndef DBAUI_TABLEWINDOWDATA_HXX
121*cdf0e10cSrcweir #include "TableWindowData.hxx"
122*cdf0e10cSrcweir #endif
123*cdf0e10cSrcweir #ifndef DBAUI_TABLEWINDOW_HXX
124*cdf0e10cSrcweir #include "TableWindow.hxx"
125*cdf0e10cSrcweir #endif
126*cdf0e10cSrcweir #ifndef DBAUI_TABLECONNECTIONDATA_HXX
127*cdf0e10cSrcweir #include "TableConnectionData.hxx"
128*cdf0e10cSrcweir #endif
129*cdf0e10cSrcweir #ifndef DBAUI_QYDLGTAB_HXX
130*cdf0e10cSrcweir #include "adtabdlg.hxx"
131*cdf0e10cSrcweir #endif
132*cdf0e10cSrcweir #ifndef _SV_WAITOBJ_HXX
133*cdf0e10cSrcweir #include <vcl/waitobj.hxx>
134*cdf0e10cSrcweir #endif
135*cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX
136*cdf0e10cSrcweir #include <vcl/svapp.hxx>
137*cdf0e10cSrcweir #endif
138*cdf0e10cSrcweir #ifndef _VOS_MUTEX_HXX_
139*cdf0e10cSrcweir #include <vos/mutex.hxx>
140*cdf0e10cSrcweir #endif
141*cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
142*cdf0e10cSrcweir #include "UITools.hxx"
143*cdf0e10cSrcweir #endif
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir #include <boost/optional.hpp>
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
148*cdf0e10cSrcweir using namespace ::com::sun::star::io;
149*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
150*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
151*cdf0e10cSrcweir using namespace ::com::sun::star::util;
152*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
153*cdf0e10cSrcweir using namespace ::com::sun::star::container;
154*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
155*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
156*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
157*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
158*cdf0e10cSrcweir using namespace ::dbtools;
159*cdf0e10cSrcweir using namespace ::comphelper;
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir // .............................................................................
162*cdf0e10cSrcweir namespace dbaui
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir // .............................................................................
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir // =============================================================================
167*cdf0e10cSrcweir // = AddTableDialogContext
168*cdf0e10cSrcweir // =============================================================================
169*cdf0e10cSrcweir class AddTableDialogContext : public IAddTableDialogContext
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir     OJoinController& m_rController;
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir public:
174*cdf0e10cSrcweir     AddTableDialogContext( OJoinController& _rController )
175*cdf0e10cSrcweir         :m_rController( _rController )
176*cdf0e10cSrcweir     {
177*cdf0e10cSrcweir     }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir     // IAddTableDialogContext
180*cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
181*cdf0e10cSrcweir                     getConnection() const;
182*cdf0e10cSrcweir     virtual bool    allowViews() const;
183*cdf0e10cSrcweir     virtual bool    allowQueries() const;
184*cdf0e10cSrcweir     virtual bool    allowAddition() const;
185*cdf0e10cSrcweir     virtual void    addTableWindow( const String& _rQualifiedTableName, const String& _rAliasName );
186*cdf0e10cSrcweir     virtual void    onWindowClosing( const Window* _pWindow );
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir private:
189*cdf0e10cSrcweir     OJoinTableView* getTableView() const;
190*cdf0e10cSrcweir };
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir // -----------------------------------------------------------------------------
193*cdf0e10cSrcweir Reference< XConnection > AddTableDialogContext::getConnection() const
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir     return m_rController.getConnection();
196*cdf0e10cSrcweir }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir // -----------------------------------------------------------------------------
199*cdf0e10cSrcweir bool AddTableDialogContext::allowViews() const
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir     return m_rController.allowViews();
202*cdf0e10cSrcweir }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir // -----------------------------------------------------------------------------
205*cdf0e10cSrcweir bool AddTableDialogContext::allowQueries() const
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir     return m_rController.allowQueries();
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir // -----------------------------------------------------------------------------
211*cdf0e10cSrcweir bool AddTableDialogContext::allowAddition() const
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir     return const_cast< OJoinController& >( m_rController ).getJoinView()->getTableView()->IsAddAllowed();
214*cdf0e10cSrcweir }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir // -----------------------------------------------------------------------------
217*cdf0e10cSrcweir void AddTableDialogContext::addTableWindow( const String& _rQualifiedTableName, const String& _rAliasName )
218*cdf0e10cSrcweir {
219*cdf0e10cSrcweir     getTableView()->AddTabWin( _rQualifiedTableName, _rAliasName, sal_True );
220*cdf0e10cSrcweir }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir // -----------------------------------------------------------------------------
223*cdf0e10cSrcweir void AddTableDialogContext::onWindowClosing( const Window* _pWindow )
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     if ( !m_rController.getView() )
226*cdf0e10cSrcweir         return;
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir     ::dbaui::notifySystemWindow(
229*cdf0e10cSrcweir         m_rController.getView(), const_cast< Window* >( _pWindow ), ::comphelper::mem_fun( &TaskPaneList::RemoveWindow ) );
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 	m_rController.InvalidateFeature( ID_BROWSER_ADDTABLE );
232*cdf0e10cSrcweir 	m_rController.getView()->GrabFocus();
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir // -----------------------------------------------------------------------------
236*cdf0e10cSrcweir OJoinTableView* AddTableDialogContext::getTableView() const
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     if ( m_rController.getJoinView() )
239*cdf0e10cSrcweir         return m_rController.getJoinView()->getTableView();
240*cdf0e10cSrcweir     return NULL;
241*cdf0e10cSrcweir }
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir // =============================================================================
244*cdf0e10cSrcweir // = OJoinController
245*cdf0e10cSrcweir // =============================================================================
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir DBG_NAME(OJoinController)
248*cdf0e10cSrcweir // -----------------------------------------------------------------------------
249*cdf0e10cSrcweir OJoinController::OJoinController(const Reference< XMultiServiceFactory >& _rM)
250*cdf0e10cSrcweir     :OJoinController_BASE(_rM)
251*cdf0e10cSrcweir     ,m_pAddTableDialog(NULL)
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir 	DBG_CTOR(OJoinController,NULL);
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir // -----------------------------------------------------------------------------
256*cdf0e10cSrcweir OJoinController::~OJoinController()
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir 	DBG_DTOR(OJoinController,NULL);
259*cdf0e10cSrcweir }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir // -----------------------------------------------------------------------------
262*cdf0e10cSrcweir void SAL_CALL OJoinController::disposing( const EventObject& _rSource ) throw(RuntimeException)
263*cdf0e10cSrcweir {
264*cdf0e10cSrcweir 	OJoinController_BASE::disposing( _rSource );
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir // -----------------------------------------------------------------------------
268*cdf0e10cSrcweir OJoinDesignView* OJoinController::getJoinView()
269*cdf0e10cSrcweir {
270*cdf0e10cSrcweir 	return static_cast< OJoinDesignView* >( getView() );
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir // -----------------------------------------------------------------------------
274*cdf0e10cSrcweir void OJoinController::disposing()
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     {
277*cdf0e10cSrcweir 	    ::std::auto_ptr< Window > pEnsureDelete( m_pAddTableDialog );
278*cdf0e10cSrcweir 	    m_pAddTableDialog   = NULL;
279*cdf0e10cSrcweir     }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir     OJoinController_BASE::disposing();
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir     clearView();
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir 	m_vTableConnectionData.clear();
286*cdf0e10cSrcweir 	m_vTableData.clear();
287*cdf0e10cSrcweir }
288*cdf0e10cSrcweir // -----------------------------------------------------------------------------
289*cdf0e10cSrcweir void OJoinController::reconnect( sal_Bool _bUI )
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir     OJoinController_BASE::reconnect( _bUI );
292*cdf0e10cSrcweir     if ( isConnected() && m_pAddTableDialog )
293*cdf0e10cSrcweir         m_pAddTableDialog->Update();
294*cdf0e10cSrcweir }
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir // -----------------------------------------------------------------------------
297*cdf0e10cSrcweir void OJoinController::impl_onModifyChanged()
298*cdf0e10cSrcweir {
299*cdf0e10cSrcweir     OJoinController_BASE::impl_onModifyChanged();
300*cdf0e10cSrcweir     InvalidateFeature( SID_RELATION_ADD_RELATION );
301*cdf0e10cSrcweir }
302*cdf0e10cSrcweir // -----------------------------------------------------------------------------
303*cdf0e10cSrcweir void OJoinController::SaveTabWinPosSize(OTableWindow* pTabWin, long nOffsetX, long nOffsetY)
304*cdf0e10cSrcweir {
305*cdf0e10cSrcweir 	// die Daten zum Fenster
306*cdf0e10cSrcweir 	TTableWindowData::value_type pData = pTabWin->GetData();
307*cdf0e10cSrcweir 	OSL_ENSURE(pData != NULL, "SaveTabWinPosSize : TabWin hat keine Daten !");
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 	// Position & Size der Daten neu setzen (aus den aktuellen Fenster-Parametern)
310*cdf0e10cSrcweir 	Point aPos = pTabWin->GetPosPixel();
311*cdf0e10cSrcweir 	aPos.X() += nOffsetX;
312*cdf0e10cSrcweir 	aPos.Y() += nOffsetY;
313*cdf0e10cSrcweir 	pData->SetPosition(aPos);
314*cdf0e10cSrcweir 	pData->SetSize(pTabWin->GetSizePixel());
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir }
317*cdf0e10cSrcweir // -----------------------------------------------------------------------------
318*cdf0e10cSrcweir FeatureState OJoinController::GetState(sal_uInt16 _nId) const
319*cdf0e10cSrcweir {
320*cdf0e10cSrcweir 	FeatureState aReturn;
321*cdf0e10cSrcweir 		// (disabled automatically)
322*cdf0e10cSrcweir 	aReturn.bEnabled = sal_True;
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir 	switch (_nId)
325*cdf0e10cSrcweir 	{
326*cdf0e10cSrcweir 		case ID_BROWSER_EDITDOC:
327*cdf0e10cSrcweir 			aReturn.bChecked = isEditable();
328*cdf0e10cSrcweir 			break;
329*cdf0e10cSrcweir 		case ID_BROWSER_ADDTABLE:
330*cdf0e10cSrcweir             aReturn.bEnabled = ( getView() != NULL )
331*cdf0e10cSrcweir                             && const_cast< OJoinController* >( this )->getJoinView()->getTableView()->IsAddAllowed();
332*cdf0e10cSrcweir             aReturn.bChecked = aReturn.bEnabled && m_pAddTableDialog != NULL && m_pAddTableDialog->IsVisible() ;
333*cdf0e10cSrcweir             if ( aReturn.bEnabled )
334*cdf0e10cSrcweir                 aReturn.sTitle = OAddTableDlg::getDialogTitleForContext( impl_getDialogContext() );
335*cdf0e10cSrcweir 			break;
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir         default:
338*cdf0e10cSrcweir 			aReturn = OJoinController_BASE::GetState(_nId);
339*cdf0e10cSrcweir 	}
340*cdf0e10cSrcweir 	return aReturn;
341*cdf0e10cSrcweir }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir // -----------------------------------------------------------------------------
344*cdf0e10cSrcweir AddTableDialogContext& OJoinController::impl_getDialogContext() const
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir     if ( !m_pDialogContext.get() )
347*cdf0e10cSrcweir     {
348*cdf0e10cSrcweir         OJoinController* pNonConstThis = const_cast< OJoinController* >( this );
349*cdf0e10cSrcweir         pNonConstThis->m_pDialogContext.reset( new AddTableDialogContext( *pNonConstThis ) );
350*cdf0e10cSrcweir     }
351*cdf0e10cSrcweir     return *m_pDialogContext;
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir // -----------------------------------------------------------------------------
355*cdf0e10cSrcweir void OJoinController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
356*cdf0e10cSrcweir {
357*cdf0e10cSrcweir 	switch(_nId)
358*cdf0e10cSrcweir 	{
359*cdf0e10cSrcweir 		case ID_BROWSER_EDITDOC:
360*cdf0e10cSrcweir 			if(isEditable())
361*cdf0e10cSrcweir 			{ // the state should be changed to not editable
362*cdf0e10cSrcweir 				switch (saveModified())
363*cdf0e10cSrcweir 				{
364*cdf0e10cSrcweir 					case RET_CANCEL:
365*cdf0e10cSrcweir 						// don't change anything here so return
366*cdf0e10cSrcweir 						return;
367*cdf0e10cSrcweir 					case RET_NO:
368*cdf0e10cSrcweir 						reset();
369*cdf0e10cSrcweir 						setModified(sal_False);		// and we are not modified yet
370*cdf0e10cSrcweir 						break;
371*cdf0e10cSrcweir 					default:
372*cdf0e10cSrcweir 						break;
373*cdf0e10cSrcweir 				}
374*cdf0e10cSrcweir 			}
375*cdf0e10cSrcweir 			setEditable(!isEditable());
376*cdf0e10cSrcweir 			getJoinView()->setReadOnly(!isEditable());
377*cdf0e10cSrcweir 			InvalidateAll();
378*cdf0e10cSrcweir 			return;
379*cdf0e10cSrcweir 		case ID_BROWSER_ADDTABLE:
380*cdf0e10cSrcweir 			if ( !m_pAddTableDialog )
381*cdf0e10cSrcweir 				m_pAddTableDialog = new OAddTableDlg( getView(), impl_getDialogContext() );
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir             if ( m_pAddTableDialog->IsVisible() )
384*cdf0e10cSrcweir 			{
385*cdf0e10cSrcweir 				m_pAddTableDialog->Show( sal_False );
386*cdf0e10cSrcweir 				getView()->GrabFocus();
387*cdf0e10cSrcweir 			}
388*cdf0e10cSrcweir 			else
389*cdf0e10cSrcweir 			{
390*cdf0e10cSrcweir 				{
391*cdf0e10cSrcweir 					WaitObject aWaitCursor( getView() );
392*cdf0e10cSrcweir 					m_pAddTableDialog->Update();
393*cdf0e10cSrcweir 				}
394*cdf0e10cSrcweir 				m_pAddTableDialog->Show( sal_True );
395*cdf0e10cSrcweir 				::dbaui::notifySystemWindow(getView(),m_pAddTableDialog,::comphelper::mem_fun(&TaskPaneList::AddWindow));
396*cdf0e10cSrcweir 			}
397*cdf0e10cSrcweir 			break;
398*cdf0e10cSrcweir 		default:
399*cdf0e10cSrcweir 			OJoinController_BASE::Execute(_nId,aArgs);
400*cdf0e10cSrcweir 	}
401*cdf0e10cSrcweir 	InvalidateFeature(_nId);
402*cdf0e10cSrcweir }
403*cdf0e10cSrcweir // -----------------------------------------------------------------------------
404*cdf0e10cSrcweir void OJoinController::SaveTabWinsPosSize( OJoinTableView::OTableWindowMap* pTabWinList, long nOffsetX, long nOffsetY )
405*cdf0e10cSrcweir {
406*cdf0e10cSrcweir 	// Das Loeschen und Neuanlegen der alten Implementation ist unter dem aktuellen Modell nicht mehr richtig : Die TabWins
407*cdf0e10cSrcweir 	// habe einen Zeiger auf ihre Daten, verwaltet werden sie aber von mir. Wenn ich die alten loesche, haben die TabWins
408*cdf0e10cSrcweir 	// ploetzlich Zeiger auf nicht mehr existente Objekte.
409*cdf0e10cSrcweir 	// Wenn die TabWins ein SetData haetten, koennte ich mir das sparen ... haben sie aber nicht, ausserdem muesste ich dann immer
410*cdf0e10cSrcweir 	// noch Informationen, die sich eigentlich nicht geaendert haben, auch neu setzen.
411*cdf0e10cSrcweir 	// Also loesche ich die TabWinDatas nicht, sondern aktualisiere sie nur.
412*cdf0e10cSrcweir 	DBG_ASSERT(m_vTableData.size() == pTabWinList->size(),
413*cdf0e10cSrcweir 		"OJoinController::SaveTabWinsPosSize : inkonsistenter Zustand : sollte genausviel TabWinDatas haben wie TabWins !");
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 	OJoinTableView::OTableWindowMap::iterator aIter = pTabWinList->begin();
416*cdf0e10cSrcweir     OJoinTableView::OTableWindowMap::iterator aEnd = pTabWinList->end();
417*cdf0e10cSrcweir 	for(;aIter != aEnd;++aIter)
418*cdf0e10cSrcweir 		SaveTabWinPosSize(aIter->second, nOffsetX, nOffsetY);
419*cdf0e10cSrcweir }
420*cdf0e10cSrcweir // -----------------------------------------------------------------------------
421*cdf0e10cSrcweir void OJoinController::removeConnectionData(const TTableConnectionData::value_type& _pData)
422*cdf0e10cSrcweir {
423*cdf0e10cSrcweir 	m_vTableConnectionData.erase( ::std::remove(m_vTableConnectionData.begin(),m_vTableConnectionData.end(),_pData),m_vTableConnectionData.end());
424*cdf0e10cSrcweir }
425*cdf0e10cSrcweir // -----------------------------------------------------------------------------
426*cdf0e10cSrcweir void OJoinController::describeSupportedFeatures()
427*cdf0e10cSrcweir {
428*cdf0e10cSrcweir 	OJoinController_BASE::describeSupportedFeatures();
429*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:Redo",      ID_BROWSER_REDO,    CommandGroup::EDIT );
430*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:Save",      ID_BROWSER_SAVEDOC, CommandGroup::DOCUMENT );
431*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:Undo",      ID_BROWSER_UNDO,    CommandGroup::EDIT );
432*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:AddTable",  ID_BROWSER_ADDTABLE,CommandGroup::EDIT );
433*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:EditDoc",   ID_BROWSER_EDITDOC, CommandGroup::EDIT );
434*cdf0e10cSrcweir }
435*cdf0e10cSrcweir // -----------------------------------------------------------------------------
436*cdf0e10cSrcweir sal_Bool SAL_CALL OJoinController::suspend(sal_Bool _bSuspend) throw( RuntimeException )
437*cdf0e10cSrcweir {
438*cdf0e10cSrcweir 	if ( getBroadcastHelper().bInDispose || getBroadcastHelper().bDisposed )
439*cdf0e10cSrcweir 		return sal_True;
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
442*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
443*cdf0e10cSrcweir     if ( getView() && getView()->IsInModalMode() )
444*cdf0e10cSrcweir         return sal_False;
445*cdf0e10cSrcweir 	sal_Bool bCheck = sal_True;
446*cdf0e10cSrcweir 	if ( _bSuspend )
447*cdf0e10cSrcweir 	{
448*cdf0e10cSrcweir 		bCheck = saveModified() != RET_CANCEL;
449*cdf0e10cSrcweir 		if ( bCheck )
450*cdf0e10cSrcweir 			OSingleDocumentController::suspend(_bSuspend);
451*cdf0e10cSrcweir 	}
452*cdf0e10cSrcweir 	return bCheck;
453*cdf0e10cSrcweir }
454*cdf0e10cSrcweir // -----------------------------------------------------------------------------
455*cdf0e10cSrcweir void OJoinController::loadTableWindows( const ::comphelper::NamedValueCollection& i_rViewSettings )
456*cdf0e10cSrcweir {
457*cdf0e10cSrcweir     m_vTableData.clear();
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir     m_aMinimumTableViewSize = Point();
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir     Sequence< PropertyValue > aWindowData;
462*cdf0e10cSrcweir     aWindowData = i_rViewSettings.getOrDefault( "Tables", aWindowData );
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir     const PropertyValue* pTablesIter = aWindowData.getConstArray();
465*cdf0e10cSrcweir     const PropertyValue* pTablesEnd = pTablesIter + aWindowData.getLength();
466*cdf0e10cSrcweir     for ( ; pTablesIter != pTablesEnd; ++pTablesIter )
467*cdf0e10cSrcweir     {
468*cdf0e10cSrcweir         ::comphelper::NamedValueCollection aSingleTableData( pTablesIter->Value );
469*cdf0e10cSrcweir         loadTableWindow( aSingleTableData );
470*cdf0e10cSrcweir     }
471*cdf0e10cSrcweir     if ( m_aMinimumTableViewSize != Point() )
472*cdf0e10cSrcweir     {
473*cdf0e10cSrcweir         getJoinView()->getScrollHelper()->resetRange( m_aMinimumTableViewSize );
474*cdf0e10cSrcweir     }
475*cdf0e10cSrcweir }
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir // -----------------------------------------------------------------------------
478*cdf0e10cSrcweir void OJoinController::loadTableWindow( const ::comphelper::NamedValueCollection& i_rTableWindowSettings )
479*cdf0e10cSrcweir {
480*cdf0e10cSrcweir 	sal_Int32 nX = -1, nY = -1, nHeight = -1, nWidth = -1;
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir     ::rtl::OUString sComposedName,sTableName,sWindowName;
483*cdf0e10cSrcweir     sal_Bool bShowAll = false;
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir     sComposedName = i_rTableWindowSettings.getOrDefault( "ComposedName", sComposedName );
486*cdf0e10cSrcweir     sTableName = i_rTableWindowSettings.getOrDefault( "TableName", sTableName );
487*cdf0e10cSrcweir     sWindowName = i_rTableWindowSettings.getOrDefault( "WindowName", sWindowName );
488*cdf0e10cSrcweir     nY = i_rTableWindowSettings.getOrDefault( "WindowTop", nY );
489*cdf0e10cSrcweir     nX = i_rTableWindowSettings.getOrDefault( "WindowLeft", nX );
490*cdf0e10cSrcweir     nWidth = i_rTableWindowSettings.getOrDefault( "WindowWidth", nWidth );
491*cdf0e10cSrcweir     nHeight = i_rTableWindowSettings.getOrDefault( "WindowHeight", nHeight );
492*cdf0e10cSrcweir     bShowAll = i_rTableWindowSettings.getOrDefault( "ShowAll", bShowAll );
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir     TTableWindowData::value_type pData = createTableWindowData(sComposedName,sTableName,sWindowName);
495*cdf0e10cSrcweir     if ( pData )
496*cdf0e10cSrcweir     {
497*cdf0e10cSrcweir 	    pData->SetPosition(Point(nX,nY));
498*cdf0e10cSrcweir 	    pData->SetSize( Size( nWidth, nHeight ) );
499*cdf0e10cSrcweir         pData->ShowAll(bShowAll);
500*cdf0e10cSrcweir 	    m_vTableData.push_back(pData);
501*cdf0e10cSrcweir         if ( m_aMinimumTableViewSize.X() < (nX+nWidth) )
502*cdf0e10cSrcweir             m_aMinimumTableViewSize.X() = (nX+nWidth);
503*cdf0e10cSrcweir         if ( m_aMinimumTableViewSize.Y() < (nY+nHeight) )
504*cdf0e10cSrcweir             m_aMinimumTableViewSize.Y() = (nY+nHeight);
505*cdf0e10cSrcweir     }
506*cdf0e10cSrcweir }
507*cdf0e10cSrcweir // -----------------------------------------------------------------------------
508*cdf0e10cSrcweir void OJoinController::saveTableWindows( ::comphelper::NamedValueCollection& o_rViewSettings ) const
509*cdf0e10cSrcweir {
510*cdf0e10cSrcweir 	if ( !m_vTableData.empty() )
511*cdf0e10cSrcweir 	{
512*cdf0e10cSrcweir         ::comphelper::NamedValueCollection aAllTablesData;
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir         TTableWindowData::const_iterator aIter = m_vTableData.begin();
515*cdf0e10cSrcweir 		TTableWindowData::const_iterator aEnd = m_vTableData.end();
516*cdf0e10cSrcweir 		for ( sal_Int32 i = 1; aIter != aEnd; ++aIter, ++i )
517*cdf0e10cSrcweir 		{
518*cdf0e10cSrcweir             ::comphelper::NamedValueCollection aWindowData;
519*cdf0e10cSrcweir 			aWindowData.put( "ComposedName", (*aIter)->GetComposedName() );
520*cdf0e10cSrcweir 			aWindowData.put( "TableName", (*aIter)->GetTableName() );
521*cdf0e10cSrcweir 			aWindowData.put( "WindowName", (*aIter)->GetWinName() );
522*cdf0e10cSrcweir 			aWindowData.put( "WindowTop", static_cast<sal_Int32>((*aIter)->GetPosition().Y()) );
523*cdf0e10cSrcweir 			aWindowData.put( "WindowLeft", static_cast<sal_Int32>((*aIter)->GetPosition().X()) );
524*cdf0e10cSrcweir 			aWindowData.put( "WindowWidth", static_cast<sal_Int32>((*aIter)->GetSize().Width()) );
525*cdf0e10cSrcweir 			aWindowData.put( "WindowHeight", static_cast<sal_Int32>((*aIter)->GetSize().Height()) );
526*cdf0e10cSrcweir 			aWindowData.put( "ShowAll", (*aIter)->IsShowAll() );
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir             const ::rtl::OUString sTableName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Table" ) ) + ::rtl::OUString::valueOf( i ) );
529*cdf0e10cSrcweir             aAllTablesData.put( sTableName, aWindowData.getPropertyValues() );
530*cdf0e10cSrcweir 		}
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir         o_rViewSettings.put( "Tables", aAllTablesData.getPropertyValues() );
533*cdf0e10cSrcweir 	}
534*cdf0e10cSrcweir }
535*cdf0e10cSrcweir // -----------------------------------------------------------------------------
536*cdf0e10cSrcweir TTableWindowData::value_type OJoinController::createTableWindowData(const ::rtl::OUString& _sComposedName,const ::rtl::OUString& _sTableName,const ::rtl::OUString& _sWindowName)
537*cdf0e10cSrcweir {
538*cdf0e10cSrcweir     OJoinDesignView* pView = getJoinView();
539*cdf0e10cSrcweir 	if( pView )
540*cdf0e10cSrcweir 		return pView->getTableView()->createTableWindowData(_sComposedName,_sTableName,_sWindowName);
541*cdf0e10cSrcweir     OSL_ENSURE(0,"We should never ever reach this point!");
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir     return TTableWindowData::value_type();
544*cdf0e10cSrcweir }
545*cdf0e10cSrcweir // .............................................................................
546*cdf0e10cSrcweir }   // namespace dbaui
547*cdf0e10cSrcweir // .............................................................................
548