1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir //#ifndef _SVX_TABWIN_HXX
27cdf0e10cSrcweir //#include "tabwin.hxx"
28cdf0e10cSrcweir //#endif
29cdf0e10cSrcweir #ifndef DBAUI_RELATIONDIALOG_HRC
30cdf0e10cSrcweir #include "RelationDlg.hrc"
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #ifndef DBAUI_RELATIONDIALOG_HXX
33cdf0e10cSrcweir #include "RelationDlg.hxx"
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #ifndef _WRKWIN_HXX //autogen
37cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX //autogen
41cdf0e10cSrcweir #include <vcl/svapp.hxx>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir #ifndef _DBU_DLG_HRC_
44cdf0e10cSrcweir #include "dbu_dlg.hrc"
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_
47cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
48cdf0e10cSrcweir #endif
49cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_
50cdf0e10cSrcweir #include <com/sun/star/sdbc/KeyRule.hpp>
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
54cdf0e10cSrcweir #include <tools/debug.hxx>
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir #ifndef TOOLS_DIAGNOSE_EX_H
57cdf0e10cSrcweir #include <tools/diagnose_ex.h>
58cdf0e10cSrcweir #endif
59cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
60cdf0e10cSrcweir #include "UITools.hxx"
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir #ifndef DBAUI_JOINDESIGNVIEW_HXX
63cdf0e10cSrcweir #include "JoinDesignView.hxx"
64cdf0e10cSrcweir #endif
65cdf0e10cSrcweir #ifndef DBAUI_JOINCONTROLLER_HXX
66cdf0e10cSrcweir #include "JoinController.hxx"
67cdf0e10cSrcweir #endif
68cdf0e10cSrcweir #ifndef _DBHELPER_DBEXCEPTION_HXX_
69cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
70cdf0e10cSrcweir #endif
71cdf0e10cSrcweir #ifndef DBAUI_RTABLECONNECTIONDATA_HXX
72cdf0e10cSrcweir #include "RTableConnectionData.hxx"
73cdf0e10cSrcweir #endif
74cdf0e10cSrcweir #ifndef DBAUI_RELATIONCONTROL_HXX
75cdf0e10cSrcweir #include "RelationControl.hxx"
76cdf0e10cSrcweir #endif
77cdf0e10cSrcweir #ifndef _CPPUHELPER_EXC_HLP_HXX_
78cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
79cdf0e10cSrcweir #endif
80cdf0e10cSrcweir 
81cdf0e10cSrcweir #include <algorithm>
82cdf0e10cSrcweir 
83cdf0e10cSrcweir using namespace ::com::sun::star::uno;
84cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
85cdf0e10cSrcweir using namespace ::com::sun::star::container;
86cdf0e10cSrcweir using namespace ::com::sun::star::beans;
87cdf0e10cSrcweir using namespace ::dbaui;
88cdf0e10cSrcweir using namespace ::dbtools;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir //========================================================================
91cdf0e10cSrcweir // class ORelationDialog
DBG_NAME(ORelationDialog)92cdf0e10cSrcweir DBG_NAME(ORelationDialog)
93cdf0e10cSrcweir //========================================================================
94cdf0e10cSrcweir ORelationDialog::ORelationDialog( OJoinTableView* pParent,
95cdf0e10cSrcweir 								 const TTableConnectionData::value_type& pConnectionData,
96cdf0e10cSrcweir 								 sal_Bool bAllowTableSelect )
97cdf0e10cSrcweir 	:ModalDialog( pParent, ModuleRes(DLG_REL_PROPERTIES) )
98cdf0e10cSrcweir 	,m_pTableMap(pParent->GetTabWinMap())
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     ,aFL_CascUpd(           this, ModuleRes(FL_CASC_UPD) )
101cdf0e10cSrcweir 	,aRB_NoCascUpd(			this, ModuleRes(RB_NO_CASC_UPD) )
102cdf0e10cSrcweir 	,aRB_CascUpd(			this, ModuleRes(RB_CASC_UPD) )
103cdf0e10cSrcweir 	,aRB_CascUpdNull(		this, ModuleRes(RB_CASC_UPD_NULL) )
104cdf0e10cSrcweir 	,aRB_CascUpdDefault(	this, ModuleRes(RB_CASC_UPD_DEFAULT) )
105cdf0e10cSrcweir     ,aFL_CascDel(           this, ModuleRes(FL_CASC_DEL) )
106cdf0e10cSrcweir 	,aRB_NoCascDel(			this, ModuleRes(RB_NO_CASC_DEL) )
107cdf0e10cSrcweir 	,aRB_CascDel(			this, ModuleRes(RB_CASC_DEL) )
108cdf0e10cSrcweir 	,aRB_CascDelNull(		this, ModuleRes(RB_CASC_DEL_NULL) )
109cdf0e10cSrcweir 	,aRB_CascDelDefault(	this, ModuleRes(RB_CASC_DEL_DEFAULT) )
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     ,aPB_OK( this, ModuleRes( PB_OK ) )
112cdf0e10cSrcweir 	,aPB_CANCEL( this, ModuleRes( PB_CANCEL ) )
113cdf0e10cSrcweir 	,aPB_HELP( this, ModuleRes( PB_HELP ) )
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     ,m_pOrigConnData( pConnectionData )
116cdf0e10cSrcweir 	,m_bTriedOneUpdate(sal_False)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     DBG_CTOR(ORelationDialog,NULL);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	m_xConnection = pParent->getDesignView()->getController().getConnection();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
123cdf0e10cSrcweir 	// Connection kopieren
124cdf0e10cSrcweir 	m_pConnData.reset( static_cast<ORelationTableConnectionData*>(pConnectionData->NewInstance()) );
125cdf0e10cSrcweir 	m_pConnData->CopyFrom( *pConnectionData );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	Init(m_pConnData);
128cdf0e10cSrcweir 	m_pTableControl.reset( new OTableListBoxControl(this,ModuleRes(WND_CONTROL),m_pTableMap,this) );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	aPB_OK.SetClickHdl( LINK(this, ORelationDialog, OKClickHdl) );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	m_pTableControl->Init( m_pConnData );
133cdf0e10cSrcweir 	if ( bAllowTableSelect )
134cdf0e10cSrcweir 		m_pTableControl->fillListBoxes();
135cdf0e10cSrcweir 	else
136cdf0e10cSrcweir 		m_pTableControl->fillAndDisable(pConnectionData);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	m_pTableControl->lateInit();
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	m_pTableControl->NotifyCellChange();
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	FreeResource();
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir //------------------------------------------------------------------------
Init(const TTableConnectionData::value_type & _pConnectionData)146cdf0e10cSrcweir void ORelationDialog::Init(const TTableConnectionData::value_type& _pConnectionData)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir     ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(_pConnectionData.get());
149cdf0e10cSrcweir 	// Update Rules
150cdf0e10cSrcweir 	switch (pConnData->GetUpdateRules())
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 	case KeyRule::NO_ACTION:
153cdf0e10cSrcweir 	case KeyRule::RESTRICT:
154cdf0e10cSrcweir 		aRB_NoCascUpd.Check( sal_True );
155cdf0e10cSrcweir 		break;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	case KeyRule::CASCADE:
158cdf0e10cSrcweir 		aRB_CascUpd.Check( sal_True );
159cdf0e10cSrcweir 		break;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	case KeyRule::SET_NULL:
162cdf0e10cSrcweir 		aRB_CascUpdNull.Check( sal_True );
163cdf0e10cSrcweir 		break;
164cdf0e10cSrcweir 	case KeyRule::SET_DEFAULT:
165cdf0e10cSrcweir 		aRB_CascUpdDefault.Check( sal_True );
166cdf0e10cSrcweir 		break;
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	// Delete Rules
170cdf0e10cSrcweir 	switch (pConnData->GetDeleteRules())
171cdf0e10cSrcweir 	{
172cdf0e10cSrcweir 	case KeyRule::NO_ACTION:
173cdf0e10cSrcweir 	case KeyRule::RESTRICT:
174cdf0e10cSrcweir 		aRB_NoCascDel.Check( sal_True );
175cdf0e10cSrcweir 		break;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	case KeyRule::CASCADE:
178cdf0e10cSrcweir 		aRB_CascDel.Check( sal_True );
179cdf0e10cSrcweir 		break;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 	case KeyRule::SET_NULL:
182cdf0e10cSrcweir 		aRB_CascDelNull.Check( sal_True );
183cdf0e10cSrcweir 		break;
184cdf0e10cSrcweir 	case KeyRule::SET_DEFAULT:
185cdf0e10cSrcweir 		aRB_CascDelDefault.Check( sal_True );
186cdf0e10cSrcweir 		break;
187cdf0e10cSrcweir 	}
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir //------------------------------------------------------------------------
~ORelationDialog()191cdf0e10cSrcweir ORelationDialog::~ORelationDialog()
192cdf0e10cSrcweir {
193cdf0e10cSrcweir     DBG_DTOR(ORelationDialog,NULL);
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir //------------------------------------------------------------------------
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 
199cdf0e10cSrcweir //------------------------------------------------------------------------
200cdf0e10cSrcweir IMPL_LINK( ORelationDialog, OKClickHdl, Button*, /*pButton*/ )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
203cdf0e10cSrcweir 	// RadioButtons auslesen
204cdf0e10cSrcweir 	sal_uInt16 nAttrib = 0;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 	// Delete Rules
207cdf0e10cSrcweir 	if( aRB_NoCascDel.IsChecked() )
208cdf0e10cSrcweir 		nAttrib |= KeyRule::NO_ACTION;
209cdf0e10cSrcweir 	if( aRB_CascDel.IsChecked() )
210cdf0e10cSrcweir 		nAttrib |= KeyRule::CASCADE;
211cdf0e10cSrcweir 	if( aRB_CascDelNull.IsChecked() )
212cdf0e10cSrcweir 		nAttrib |= KeyRule::SET_NULL;
213cdf0e10cSrcweir 	if( aRB_CascDelDefault.IsChecked() )
214cdf0e10cSrcweir 		nAttrib |= KeyRule::SET_DEFAULT;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(m_pConnData.get());
217cdf0e10cSrcweir 	pConnData->SetDeleteRules( nAttrib );
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	// Update Rules
220cdf0e10cSrcweir 	nAttrib = 0;
221cdf0e10cSrcweir 	if( aRB_NoCascUpd.IsChecked() )
222cdf0e10cSrcweir 		nAttrib |= KeyRule::NO_ACTION;
223cdf0e10cSrcweir 	if( aRB_CascUpd.IsChecked() )
224cdf0e10cSrcweir 		nAttrib |= KeyRule::CASCADE;
225cdf0e10cSrcweir 	if( aRB_CascUpdNull.IsChecked() )
226cdf0e10cSrcweir 		nAttrib |= KeyRule::SET_NULL;
227cdf0e10cSrcweir 	if( aRB_CascUpdDefault.IsChecked() )
228cdf0e10cSrcweir 		nAttrib |= KeyRule::SET_DEFAULT;
229cdf0e10cSrcweir 	pConnData->SetUpdateRules( nAttrib );
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	m_pTableControl->SaveModified();
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 	//// wenn die ComboBoxen fuer die Tabellenauswahl enabled sind (Constructor mit bAllowTableSelect==sal_True), dann muss ich in die
234cdf0e10cSrcweir 	//// Connection auch die Tabellennamen stecken
235cdf0e10cSrcweir 	//m_pConnData->SetSourceWinName(m_pTableControl->getSourceWinName());
236cdf0e10cSrcweir 	//m_pConnData->SetDestWinName(m_pTableControl->getDestWinName());
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 	// try to create the relation
239cdf0e10cSrcweir 	try
240cdf0e10cSrcweir 	{
241cdf0e10cSrcweir     	ORelationTableConnectionData* pOrigConnData = static_cast<ORelationTableConnectionData*>(m_pOrigConnData.get());
242cdf0e10cSrcweir 		if ( *pConnData == *pOrigConnData || pConnData->Update())
243cdf0e10cSrcweir 		{
244cdf0e10cSrcweir 			m_pOrigConnData->CopyFrom( *m_pConnData );
245cdf0e10cSrcweir 			EndDialog( RET_OK );
246cdf0e10cSrcweir 			return 0L;
247cdf0e10cSrcweir 		}
248cdf0e10cSrcweir 	}
249cdf0e10cSrcweir 	catch( const SQLException& )
250cdf0e10cSrcweir 	{
251cdf0e10cSrcweir         ::dbaui::showError(	SQLExceptionInfo( ::cppu::getCaughtException() ),
252cdf0e10cSrcweir 							this,
253cdf0e10cSrcweir 							static_cast<OJoinTableView*>(GetParent())->getDesignView()->getController().getORB());
254cdf0e10cSrcweir 	}
255cdf0e10cSrcweir     catch( const Exception& )
256cdf0e10cSrcweir     {
257cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
258cdf0e10cSrcweir     }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 	m_bTriedOneUpdate = sal_True;
261cdf0e10cSrcweir 	// this means that the original connection may be lost (if m_pConnData was not a newly created but an
262cdf0e10cSrcweir 	// existent conn to be modified), which we reflect by returning RET_NO (see ::Execute)
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 	// try again
265cdf0e10cSrcweir 	Init(m_pConnData);
266cdf0e10cSrcweir 	m_pTableControl->Init( m_pConnData );
267cdf0e10cSrcweir 	m_pTableControl->lateInit();
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 	return 0;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 
273cdf0e10cSrcweir //------------------------------------------------------------------------
Execute()274cdf0e10cSrcweir short ORelationDialog::Execute()
275cdf0e10cSrcweir {
276cdf0e10cSrcweir 	short nResult = ModalDialog::Execute();
277cdf0e10cSrcweir 	if ((nResult != RET_OK) && m_bTriedOneUpdate)
278cdf0e10cSrcweir 		return RET_NO;
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 	return nResult;
281cdf0e10cSrcweir }
282cdf0e10cSrcweir // -----------------------------------------------------------------------------
getConnectionData() const283cdf0e10cSrcweir TTableConnectionData::value_type ORelationDialog::getConnectionData() const
284cdf0e10cSrcweir {
285cdf0e10cSrcweir 	return m_pConnData;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir // -----------------------------------------------------------------------------
setValid(sal_Bool _bValid)288cdf0e10cSrcweir void ORelationDialog::setValid(sal_Bool _bValid)
289cdf0e10cSrcweir {
290cdf0e10cSrcweir 	aPB_OK.Enable(_bValid);
291cdf0e10cSrcweir }
292cdf0e10cSrcweir // -----------------------------------------------------------------------------
notifyConnectionChange()293cdf0e10cSrcweir void ORelationDialog::notifyConnectionChange()
294cdf0e10cSrcweir {
295cdf0e10cSrcweir 	Init(m_pConnData);
296cdf0e10cSrcweir }
297cdf0e10cSrcweir // -----------------------------------------------------------------------------
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 
300