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