merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / dlg / RelationDlg.cxx
blob3a51d0af2a151b70b422080f0b0ecd786fcbe258
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: RelationDlg.cxx,v $
10 * $Revision: 1.29.24.1 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 //#ifndef _SVX_TABWIN_HXX
34 //#include "tabwin.hxx"
35 //#endif
36 #ifndef DBAUI_RELATIONDIALOG_HRC
37 #include "RelationDlg.hrc"
38 #endif
39 #ifndef DBAUI_RELATIONDIALOG_HXX
40 #include "RelationDlg.hxx"
41 #endif
43 #ifndef _WRKWIN_HXX //autogen
44 #include <vcl/wrkwin.hxx>
45 #endif
47 #ifndef _SV_SVAPP_HXX //autogen
48 #include <vcl/svapp.hxx>
49 #endif
50 #ifndef _DBU_DLG_HRC_
51 #include "dbu_dlg.hrc"
52 #endif
53 #ifndef _DBA_DBACCESS_HELPID_HRC_
54 #include "dbaccess_helpid.hrc"
55 #endif
56 #ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_
57 #include <com/sun/star/sdbc/KeyRule.hpp>
58 #endif
60 #ifndef _TOOLS_DEBUG_HXX
61 #include <tools/debug.hxx>
62 #endif
63 #ifndef TOOLS_DIAGNOSE_EX_H
64 #include <tools/diagnose_ex.h>
65 #endif
66 #ifndef DBAUI_TOOLS_HXX
67 #include "UITools.hxx"
68 #endif
69 #ifndef DBAUI_JOINDESIGNVIEW_HXX
70 #include "JoinDesignView.hxx"
71 #endif
72 #ifndef DBAUI_JOINCONTROLLER_HXX
73 #include "JoinController.hxx"
74 #endif
75 #ifndef _DBHELPER_DBEXCEPTION_HXX_
76 #include <connectivity/dbexception.hxx>
77 #endif
78 #ifndef DBAUI_RTABLECONNECTIONDATA_HXX
79 #include "RTableConnectionData.hxx"
80 #endif
81 #ifndef DBAUI_RELATIONCONTROL_HXX
82 #include "RelationControl.hxx"
83 #endif
84 #ifndef _CPPUHELPER_EXC_HLP_HXX_
85 #include <cppuhelper/exc_hlp.hxx>
86 #endif
88 #include <algorithm>
90 using namespace ::com::sun::star::uno;
91 using namespace ::com::sun::star::sdbc;
92 using namespace ::com::sun::star::container;
93 using namespace ::com::sun::star::beans;
94 using namespace ::dbaui;
95 using namespace ::dbtools;
97 //========================================================================
98 // class ORelationDialog
99 DBG_NAME(ORelationDialog)
100 //========================================================================
101 ORelationDialog::ORelationDialog( OJoinTableView* pParent,
102 const TTableConnectionData::value_type& pConnectionData,
103 BOOL bAllowTableSelect )
104 :ModalDialog( pParent, ModuleRes(DLG_REL_PROPERTIES) )
105 ,m_pTableMap(pParent->GetTabWinMap())
107 ,aFL_CascUpd( this, ModuleRes(FL_CASC_UPD) )
108 ,aRB_NoCascUpd( this, ModuleRes(RB_NO_CASC_UPD) )
109 ,aRB_CascUpd( this, ModuleRes(RB_CASC_UPD) )
110 ,aRB_CascUpdNull( this, ModuleRes(RB_CASC_UPD_NULL) )
111 ,aRB_CascUpdDefault( this, ModuleRes(RB_CASC_UPD_DEFAULT) )
112 ,aFL_CascDel( this, ModuleRes(FL_CASC_DEL) )
113 ,aRB_NoCascDel( this, ModuleRes(RB_NO_CASC_DEL) )
114 ,aRB_CascDel( this, ModuleRes(RB_CASC_DEL) )
115 ,aRB_CascDelNull( this, ModuleRes(RB_CASC_DEL_NULL) )
116 ,aRB_CascDelDefault( this, ModuleRes(RB_CASC_DEL_DEFAULT) )
118 ,aPB_OK( this, ModuleRes( PB_OK ) )
119 ,aPB_CANCEL( this, ModuleRes( PB_CANCEL ) )
120 ,aPB_HELP( this, ModuleRes( PB_HELP ) )
122 ,m_pOrigConnData( pConnectionData )
123 ,m_bTriedOneUpdate(FALSE)
125 DBG_CTOR(ORelationDialog,NULL);
127 m_xConnection = pParent->getDesignView()->getController().getConnection();
129 //////////////////////////////////////////////////////////////////////
130 // Connection kopieren
131 m_pConnData.reset( static_cast<ORelationTableConnectionData*>(pConnectionData->NewInstance()) );
132 m_pConnData->CopyFrom( *pConnectionData );
134 Init(m_pConnData);
135 m_pTableControl.reset( new OTableListBoxControl(this,ModuleRes(WND_CONTROL),m_pTableMap,this) );
137 aPB_OK.SetClickHdl( LINK(this, ORelationDialog, OKClickHdl) );
139 m_pTableControl->Init( m_pConnData );
140 if ( bAllowTableSelect )
141 m_pTableControl->fillListBoxes();
142 else
143 m_pTableControl->fillAndDisable(pConnectionData);
145 m_pTableControl->lateInit();
147 m_pTableControl->NotifyCellChange();
149 FreeResource();
152 //------------------------------------------------------------------------
153 void ORelationDialog::Init(const TTableConnectionData::value_type& _pConnectionData)
155 ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(_pConnectionData.get());
156 // Update Rules
157 switch (pConnData->GetUpdateRules())
159 case KeyRule::NO_ACTION:
160 case KeyRule::RESTRICT:
161 aRB_NoCascUpd.Check( TRUE );
162 break;
164 case KeyRule::CASCADE:
165 aRB_CascUpd.Check( TRUE );
166 break;
168 case KeyRule::SET_NULL:
169 aRB_CascUpdNull.Check( TRUE );
170 break;
171 case KeyRule::SET_DEFAULT:
172 aRB_CascUpdDefault.Check( TRUE );
173 break;
176 // Delete Rules
177 switch (pConnData->GetDeleteRules())
179 case KeyRule::NO_ACTION:
180 case KeyRule::RESTRICT:
181 aRB_NoCascDel.Check( TRUE );
182 break;
184 case KeyRule::CASCADE:
185 aRB_CascDel.Check( TRUE );
186 break;
188 case KeyRule::SET_NULL:
189 aRB_CascDelNull.Check( TRUE );
190 break;
191 case KeyRule::SET_DEFAULT:
192 aRB_CascDelDefault.Check( TRUE );
193 break;
197 //------------------------------------------------------------------------
198 ORelationDialog::~ORelationDialog()
200 DBG_DTOR(ORelationDialog,NULL);
203 //------------------------------------------------------------------------
206 //------------------------------------------------------------------------
207 IMPL_LINK( ORelationDialog, OKClickHdl, Button*, /*pButton*/ )
209 //////////////////////////////////////////////////////////////////////
210 // RadioButtons auslesen
211 UINT16 nAttrib = 0;
213 // Delete Rules
214 if( aRB_NoCascDel.IsChecked() )
215 nAttrib |= KeyRule::NO_ACTION;
216 if( aRB_CascDel.IsChecked() )
217 nAttrib |= KeyRule::CASCADE;
218 if( aRB_CascDelNull.IsChecked() )
219 nAttrib |= KeyRule::SET_NULL;
220 if( aRB_CascDelDefault.IsChecked() )
221 nAttrib |= KeyRule::SET_DEFAULT;
223 ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(m_pConnData.get());
224 pConnData->SetDeleteRules( nAttrib );
226 // Update Rules
227 nAttrib = 0;
228 if( aRB_NoCascUpd.IsChecked() )
229 nAttrib |= KeyRule::NO_ACTION;
230 if( aRB_CascUpd.IsChecked() )
231 nAttrib |= KeyRule::CASCADE;
232 if( aRB_CascUpdNull.IsChecked() )
233 nAttrib |= KeyRule::SET_NULL;
234 if( aRB_CascUpdDefault.IsChecked() )
235 nAttrib |= KeyRule::SET_DEFAULT;
236 pConnData->SetUpdateRules( nAttrib );
238 m_pTableControl->SaveModified();
240 //// wenn die ComboBoxen fuer die Tabellenauswahl enabled sind (Constructor mit bAllowTableSelect==TRUE), dann muss ich in die
241 //// Connection auch die Tabellennamen stecken
242 //m_pConnData->SetSourceWinName(m_pTableControl->getSourceWinName());
243 //m_pConnData->SetDestWinName(m_pTableControl->getDestWinName());
245 // try to create the relation
248 ORelationTableConnectionData* pOrigConnData = static_cast<ORelationTableConnectionData*>(m_pOrigConnData.get());
249 if ( *pConnData == *pOrigConnData || pConnData->Update())
251 m_pOrigConnData->CopyFrom( *m_pConnData );
252 EndDialog( RET_OK );
253 return 0L;
256 catch( const SQLException& )
258 ::dbaui::showError( SQLExceptionInfo( ::cppu::getCaughtException() ),
259 this,
260 static_cast<OJoinTableView*>(GetParent())->getDesignView()->getController().getORB());
262 catch( const Exception& )
264 DBG_UNHANDLED_EXCEPTION();
267 m_bTriedOneUpdate = TRUE;
268 // this means that the original connection may be lost (if m_pConnData was not a newly created but an
269 // existent conn to be modified), which we reflect by returning RET_NO (see ::Execute)
271 // try again
272 Init(m_pConnData);
273 m_pTableControl->Init( m_pConnData );
274 m_pTableControl->lateInit();
276 return 0;
280 //------------------------------------------------------------------------
281 short ORelationDialog::Execute()
283 short nResult = ModalDialog::Execute();
284 if ((nResult != RET_OK) && m_bTriedOneUpdate)
285 return RET_NO;
287 return nResult;
289 // -----------------------------------------------------------------------------
290 TTableConnectionData::value_type ORelationDialog::getConnectionData() const
292 return m_pConnData;
294 // -----------------------------------------------------------------------------
295 void ORelationDialog::setValid(sal_Bool _bValid)
297 aPB_OK.Enable(_bValid);
299 // -----------------------------------------------------------------------------
300 void ORelationDialog::notifyConnectionChange()
302 Init(m_pConnData);
304 // -----------------------------------------------------------------------------