Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / dlg / RelationDlg.cxx
blob69609f7ffd5447787f29402c8085f29d5aaab6df
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "RelationDlg.hrc"
30 #include "RelationDlg.hxx"
32 #include <vcl/wrkwin.hxx>
34 #include <vcl/svapp.hxx>
35 #include "dbu_dlg.hrc"
36 #include "dbaccess_helpid.hrc"
37 #include <com/sun/star/sdbc/KeyRule.hpp>
39 #include <tools/debug.hxx>
40 #include <tools/diagnose_ex.h>
41 #include "UITools.hxx"
42 #include "JoinDesignView.hxx"
43 #include "JoinController.hxx"
44 #include <connectivity/dbexception.hxx>
45 #include "RTableConnectionData.hxx"
46 #include "RelationControl.hxx"
47 #include <cppuhelper/exc_hlp.hxx>
49 #include <algorithm>
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::sdbc;
53 using namespace ::com::sun::star::container;
54 using namespace ::com::sun::star::beans;
55 using namespace ::dbaui;
56 using namespace ::dbtools;
58 //========================================================================
59 // class ORelationDialog
60 DBG_NAME(ORelationDialog)
61 //========================================================================
62 ORelationDialog::ORelationDialog( OJoinTableView* pParent,
63 const TTableConnectionData::value_type& pConnectionData,
64 sal_Bool bAllowTableSelect )
65 :ModalDialog( pParent, ModuleRes(DLG_REL_PROPERTIES) )
66 ,m_pTableMap(pParent->GetTabWinMap())
68 ,aFL_CascUpd( this, ModuleRes(FL_CASC_UPD) )
69 ,aRB_NoCascUpd( this, ModuleRes(RB_NO_CASC_UPD) )
70 ,aRB_CascUpd( this, ModuleRes(RB_CASC_UPD) )
71 ,aRB_CascUpdNull( this, ModuleRes(RB_CASC_UPD_NULL) )
72 ,aRB_CascUpdDefault( this, ModuleRes(RB_CASC_UPD_DEFAULT) )
73 ,aFL_CascDel( this, ModuleRes(FL_CASC_DEL) )
74 ,aRB_NoCascDel( this, ModuleRes(RB_NO_CASC_DEL) )
75 ,aRB_CascDel( this, ModuleRes(RB_CASC_DEL) )
76 ,aRB_CascDelNull( this, ModuleRes(RB_CASC_DEL_NULL) )
77 ,aRB_CascDelDefault( this, ModuleRes(RB_CASC_DEL_DEFAULT) )
79 ,aPB_OK( this, ModuleRes( PB_OK ) )
80 ,aPB_CANCEL( this, ModuleRes( PB_CANCEL ) )
81 ,aPB_HELP( this, ModuleRes( PB_HELP ) )
83 ,m_pOrigConnData( pConnectionData )
84 ,m_bTriedOneUpdate(sal_False)
86 DBG_CTOR(ORelationDialog,NULL);
88 m_xConnection = pParent->getDesignView()->getController().getConnection();
90 //////////////////////////////////////////////////////////////////////
91 // Connection kopieren
92 m_pConnData.reset( static_cast<ORelationTableConnectionData*>(pConnectionData->NewInstance()) );
93 m_pConnData->CopyFrom( *pConnectionData );
95 Init(m_pConnData);
96 m_pTableControl.reset( new OTableListBoxControl(this,ModuleRes(WND_CONTROL),m_pTableMap,this) );
98 aPB_OK.SetClickHdl( LINK(this, ORelationDialog, OKClickHdl) );
100 m_pTableControl->Init( m_pConnData );
101 if ( bAllowTableSelect )
102 m_pTableControl->fillListBoxes();
103 else
104 m_pTableControl->fillAndDisable(pConnectionData);
106 m_pTableControl->lateInit();
108 m_pTableControl->NotifyCellChange();
110 FreeResource();
113 //------------------------------------------------------------------------
114 void ORelationDialog::Init(const TTableConnectionData::value_type& _pConnectionData)
116 ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(_pConnectionData.get());
117 // Update Rules
118 switch (pConnData->GetUpdateRules())
120 case KeyRule::NO_ACTION:
121 case KeyRule::RESTRICT:
122 aRB_NoCascUpd.Check( sal_True );
123 break;
125 case KeyRule::CASCADE:
126 aRB_CascUpd.Check( sal_True );
127 break;
129 case KeyRule::SET_NULL:
130 aRB_CascUpdNull.Check( sal_True );
131 break;
132 case KeyRule::SET_DEFAULT:
133 aRB_CascUpdDefault.Check( sal_True );
134 break;
137 // Delete Rules
138 switch (pConnData->GetDeleteRules())
140 case KeyRule::NO_ACTION:
141 case KeyRule::RESTRICT:
142 aRB_NoCascDel.Check( sal_True );
143 break;
145 case KeyRule::CASCADE:
146 aRB_CascDel.Check( sal_True );
147 break;
149 case KeyRule::SET_NULL:
150 aRB_CascDelNull.Check( sal_True );
151 break;
152 case KeyRule::SET_DEFAULT:
153 aRB_CascDelDefault.Check( sal_True );
154 break;
158 //------------------------------------------------------------------------
159 ORelationDialog::~ORelationDialog()
161 DBG_DTOR(ORelationDialog,NULL);
164 //------------------------------------------------------------------------
167 //------------------------------------------------------------------------
168 IMPL_LINK( ORelationDialog, OKClickHdl, Button*, /*pButton*/ )
170 //////////////////////////////////////////////////////////////////////
171 // RadioButtons auslesen
172 sal_uInt16 nAttrib = 0;
174 // Delete Rules
175 if( aRB_NoCascDel.IsChecked() )
176 nAttrib |= KeyRule::NO_ACTION;
177 if( aRB_CascDel.IsChecked() )
178 nAttrib |= KeyRule::CASCADE;
179 if( aRB_CascDelNull.IsChecked() )
180 nAttrib |= KeyRule::SET_NULL;
181 if( aRB_CascDelDefault.IsChecked() )
182 nAttrib |= KeyRule::SET_DEFAULT;
184 ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(m_pConnData.get());
185 pConnData->SetDeleteRules( nAttrib );
187 // Update Rules
188 nAttrib = 0;
189 if( aRB_NoCascUpd.IsChecked() )
190 nAttrib |= KeyRule::NO_ACTION;
191 if( aRB_CascUpd.IsChecked() )
192 nAttrib |= KeyRule::CASCADE;
193 if( aRB_CascUpdNull.IsChecked() )
194 nAttrib |= KeyRule::SET_NULL;
195 if( aRB_CascUpdDefault.IsChecked() )
196 nAttrib |= KeyRule::SET_DEFAULT;
197 pConnData->SetUpdateRules( nAttrib );
199 m_pTableControl->SaveModified();
201 //// wenn die ComboBoxen fuer die Tabellenauswahl enabled sind (Constructor mit bAllowTableSelect==sal_True), dann muss ich in die
202 //// Connection auch die Tabellennamen stecken
203 //m_pConnData->SetSourceWinName(m_pTableControl->getSourceWinName());
204 //m_pConnData->SetDestWinName(m_pTableControl->getDestWinName());
206 // try to create the relation
209 ORelationTableConnectionData* pOrigConnData = static_cast<ORelationTableConnectionData*>(m_pOrigConnData.get());
210 if ( *pConnData == *pOrigConnData || pConnData->Update())
212 m_pOrigConnData->CopyFrom( *m_pConnData );
213 EndDialog( RET_OK );
214 return 0L;
217 catch( const SQLException& )
219 ::dbaui::showError( SQLExceptionInfo( ::cppu::getCaughtException() ),
220 this,
221 static_cast<OJoinTableView*>(GetParent())->getDesignView()->getController().getORB());
223 catch( const Exception& )
225 DBG_UNHANDLED_EXCEPTION();
228 m_bTriedOneUpdate = sal_True;
229 // this means that the original connection may be lost (if m_pConnData was not a newly created but an
230 // existent conn to be modified), which we reflect by returning RET_NO (see ::Execute)
232 // try again
233 Init(m_pConnData);
234 m_pTableControl->Init( m_pConnData );
235 m_pTableControl->lateInit();
237 return 0;
241 //------------------------------------------------------------------------
242 short ORelationDialog::Execute()
244 short nResult = ModalDialog::Execute();
245 if ((nResult != RET_OK) && m_bTriedOneUpdate)
246 return RET_NO;
248 return nResult;
250 // -----------------------------------------------------------------------------
251 TTableConnectionData::value_type ORelationDialog::getConnectionData() const
253 return m_pConnData;
255 // -----------------------------------------------------------------------------
256 void ORelationDialog::setValid(sal_Bool _bValid)
258 aPB_OK.Enable(_bValid);
260 // -----------------------------------------------------------------------------
261 void ORelationDialog::notifyConnectionChange()
263 Init(m_pConnData);
265 // -----------------------------------------------------------------------------
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */