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