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