1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
36 #ifndef DBAUI_RELATIONDIALOG_HRC
37 #include "RelationDlg.hrc"
39 #ifndef DBAUI_RELATIONDIALOG_HXX
40 #include "RelationDlg.hxx"
43 #ifndef _WRKWIN_HXX //autogen
44 #include <vcl/wrkwin.hxx>
47 #ifndef _SV_SVAPP_HXX //autogen
48 #include <vcl/svapp.hxx>
51 #include "dbu_dlg.hrc"
53 #ifndef _DBA_DBACCESS_HELPID_HRC_
54 #include "dbaccess_helpid.hrc"
56 #ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_
57 #include <com/sun/star/sdbc/KeyRule.hpp>
60 #ifndef _TOOLS_DEBUG_HXX
61 #include <tools/debug.hxx>
63 #ifndef TOOLS_DIAGNOSE_EX_H
64 #include <tools/diagnose_ex.h>
66 #ifndef DBAUI_TOOLS_HXX
67 #include "UITools.hxx"
69 #ifndef DBAUI_JOINDESIGNVIEW_HXX
70 #include "JoinDesignView.hxx"
72 #ifndef DBAUI_JOINCONTROLLER_HXX
73 #include "JoinController.hxx"
75 #ifndef _DBHELPER_DBEXCEPTION_HXX_
76 #include <connectivity/dbexception.hxx>
78 #ifndef DBAUI_RTABLECONNECTIONDATA_HXX
79 #include "RTableConnectionData.hxx"
81 #ifndef DBAUI_RELATIONCONTROL_HXX
82 #include "RelationControl.hxx"
84 #ifndef _CPPUHELPER_EXC_HLP_HXX_
85 #include <cppuhelper/exc_hlp.hxx>
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
);
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();
143 m_pTableControl
->fillAndDisable(pConnectionData
);
145 m_pTableControl
->lateInit();
147 m_pTableControl
->NotifyCellChange();
152 //------------------------------------------------------------------------
153 void ORelationDialog::Init(const TTableConnectionData::value_type
& _pConnectionData
)
155 ORelationTableConnectionData
* pConnData
= static_cast<ORelationTableConnectionData
*>(_pConnectionData
.get());
157 switch (pConnData
->GetUpdateRules())
159 case KeyRule::NO_ACTION
:
160 case KeyRule::RESTRICT
:
161 aRB_NoCascUpd
.Check( TRUE
);
164 case KeyRule::CASCADE
:
165 aRB_CascUpd
.Check( TRUE
);
168 case KeyRule::SET_NULL
:
169 aRB_CascUpdNull
.Check( TRUE
);
171 case KeyRule::SET_DEFAULT
:
172 aRB_CascUpdDefault
.Check( TRUE
);
177 switch (pConnData
->GetDeleteRules())
179 case KeyRule::NO_ACTION
:
180 case KeyRule::RESTRICT
:
181 aRB_NoCascDel
.Check( TRUE
);
184 case KeyRule::CASCADE
:
185 aRB_CascDel
.Check( TRUE
);
188 case KeyRule::SET_NULL
:
189 aRB_CascDelNull
.Check( TRUE
);
191 case KeyRule::SET_DEFAULT
:
192 aRB_CascDelDefault
.Check( TRUE
);
197 //------------------------------------------------------------------------
198 ORelationDialog::~ORelationDialog()
200 DBG_DTOR(ORelationDialog
,NULL
);
203 //------------------------------------------------------------------------
206 //------------------------------------------------------------------------
207 IMPL_LINK( ORelationDialog
, OKClickHdl
, Button
*, /*pButton*/ )
209 //////////////////////////////////////////////////////////////////////
210 // RadioButtons auslesen
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
);
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
);
256 catch( const SQLException
& )
258 ::dbaui::showError( SQLExceptionInfo( ::cppu::getCaughtException() ),
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)
273 m_pTableControl
->Init( m_pConnData
);
274 m_pTableControl
->lateInit();
280 //------------------------------------------------------------------------
281 short ORelationDialog::Execute()
283 short nResult
= ModalDialog::Execute();
284 if ((nResult
!= RET_OK
) && m_bTriedOneUpdate
)
289 // -----------------------------------------------------------------------------
290 TTableConnectionData::value_type
ORelationDialog::getConnectionData() const
294 // -----------------------------------------------------------------------------
295 void ORelationDialog::setValid(sal_Bool _bValid
)
297 aPB_OK
.Enable(_bValid
);
299 // -----------------------------------------------------------------------------
300 void ORelationDialog::notifyConnectionChange()
304 // -----------------------------------------------------------------------------