LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/dlg - RelationDlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 89 0.0 %
Date: 2012-12-17 Functions: 0 10 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "RelationDlg.hrc"
      21             : #include "RelationDlg.hxx"
      22             : 
      23             : #include <vcl/wrkwin.hxx>
      24             : 
      25             : #include <vcl/svapp.hxx>
      26             : #include "dbu_dlg.hrc"
      27             : #include "dbaccess_helpid.hrc"
      28             : #include <com/sun/star/sdbc/KeyRule.hpp>
      29             : 
      30             : #include <tools/debug.hxx>
      31             : #include <tools/diagnose_ex.h>
      32             : #include "UITools.hxx"
      33             : #include "JoinDesignView.hxx"
      34             : #include "JoinController.hxx"
      35             : #include <connectivity/dbexception.hxx>
      36             : #include "RTableConnectionData.hxx"
      37             : #include "RelationControl.hxx"
      38             : #include <cppuhelper/exc_hlp.hxx>
      39             : #include <comphelper/processfactory.hxx>
      40             : 
      41             : #include <algorithm>
      42             : 
      43             : using namespace ::com::sun::star::uno;
      44             : using namespace ::com::sun::star::sdbc;
      45             : using namespace ::com::sun::star::container;
      46             : using namespace ::com::sun::star::beans;
      47             : using namespace ::dbaui;
      48             : using namespace ::dbtools;
      49             : 
      50             : //========================================================================
      51             : // class ORelationDialog
      52             : DBG_NAME(ORelationDialog)
      53             : //========================================================================
      54           0 : ORelationDialog::ORelationDialog( OJoinTableView* pParent,
      55             :                                  const TTableConnectionData::value_type& pConnectionData,
      56             :                                  sal_Bool bAllowTableSelect )
      57             :     :ModalDialog( pParent, ModuleRes(DLG_REL_PROPERTIES) )
      58           0 :     ,m_pTableMap(pParent->GetTabWinMap())
      59             : 
      60             :     ,aFL_CascUpd(           this, ModuleRes(FL_CASC_UPD) )
      61             :     ,aRB_NoCascUpd(         this, ModuleRes(RB_NO_CASC_UPD) )
      62             :     ,aRB_CascUpd(           this, ModuleRes(RB_CASC_UPD) )
      63             :     ,aRB_CascUpdNull(       this, ModuleRes(RB_CASC_UPD_NULL) )
      64             :     ,aRB_CascUpdDefault(    this, ModuleRes(RB_CASC_UPD_DEFAULT) )
      65             :     ,aFL_CascDel(           this, ModuleRes(FL_CASC_DEL) )
      66             :     ,aRB_NoCascDel(         this, ModuleRes(RB_NO_CASC_DEL) )
      67             :     ,aRB_CascDel(           this, ModuleRes(RB_CASC_DEL) )
      68             :     ,aRB_CascDelNull(       this, ModuleRes(RB_CASC_DEL_NULL) )
      69             :     ,aRB_CascDelDefault(    this, ModuleRes(RB_CASC_DEL_DEFAULT) )
      70             : 
      71             :     ,aPB_OK( this, ModuleRes( PB_OK ) )
      72             :     ,aPB_CANCEL( this, ModuleRes( PB_CANCEL ) )
      73             :     ,aPB_HELP( this, ModuleRes( PB_HELP ) )
      74             : 
      75             :     ,m_pOrigConnData( pConnectionData )
      76           0 :     ,m_bTriedOneUpdate(sal_False)
      77             : {
      78             :     DBG_CTOR(ORelationDialog,NULL);
      79             : 
      80           0 :     m_xConnection = pParent->getDesignView()->getController().getConnection();
      81             : 
      82             :     //////////////////////////////////////////////////////////////////////
      83             :     // Connection kopieren
      84           0 :     m_pConnData.reset( static_cast<ORelationTableConnectionData*>(pConnectionData->NewInstance()) );
      85           0 :     m_pConnData->CopyFrom( *pConnectionData );
      86             : 
      87           0 :     Init(m_pConnData);
      88           0 :     m_pTableControl.reset( new OTableListBoxControl(this,ModuleRes(WND_CONTROL),m_pTableMap,this) );
      89             : 
      90           0 :     aPB_OK.SetClickHdl( LINK(this, ORelationDialog, OKClickHdl) );
      91             : 
      92           0 :     m_pTableControl->Init( m_pConnData );
      93           0 :     if ( bAllowTableSelect )
      94           0 :         m_pTableControl->fillListBoxes();
      95             :     else
      96           0 :         m_pTableControl->fillAndDisable(pConnectionData);
      97             : 
      98           0 :     m_pTableControl->lateInit();
      99             : 
     100           0 :     m_pTableControl->NotifyCellChange();
     101             : 
     102           0 :     FreeResource();
     103           0 : }
     104             : 
     105             : //------------------------------------------------------------------------
     106           0 : void ORelationDialog::Init(const TTableConnectionData::value_type& _pConnectionData)
     107             : {
     108           0 :     ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(_pConnectionData.get());
     109             :     // Update Rules
     110           0 :     switch (pConnData->GetUpdateRules())
     111             :     {
     112             :     case KeyRule::NO_ACTION:
     113             :     case KeyRule::RESTRICT:
     114           0 :         aRB_NoCascUpd.Check( sal_True );
     115           0 :         break;
     116             : 
     117             :     case KeyRule::CASCADE:
     118           0 :         aRB_CascUpd.Check( sal_True );
     119           0 :         break;
     120             : 
     121             :     case KeyRule::SET_NULL:
     122           0 :         aRB_CascUpdNull.Check( sal_True );
     123           0 :         break;
     124             :     case KeyRule::SET_DEFAULT:
     125           0 :         aRB_CascUpdDefault.Check( sal_True );
     126           0 :         break;
     127             :     }
     128             : 
     129             :     // Delete Rules
     130           0 :     switch (pConnData->GetDeleteRules())
     131             :     {
     132             :     case KeyRule::NO_ACTION:
     133             :     case KeyRule::RESTRICT:
     134           0 :         aRB_NoCascDel.Check( sal_True );
     135           0 :         break;
     136             : 
     137             :     case KeyRule::CASCADE:
     138           0 :         aRB_CascDel.Check( sal_True );
     139           0 :         break;
     140             : 
     141             :     case KeyRule::SET_NULL:
     142           0 :         aRB_CascDelNull.Check( sal_True );
     143           0 :         break;
     144             :     case KeyRule::SET_DEFAULT:
     145           0 :         aRB_CascDelDefault.Check( sal_True );
     146           0 :         break;
     147             :     }
     148           0 : }
     149             : 
     150             : //------------------------------------------------------------------------
     151           0 : ORelationDialog::~ORelationDialog()
     152             : {
     153             :     DBG_DTOR(ORelationDialog,NULL);
     154           0 : }
     155             : 
     156             : //------------------------------------------------------------------------
     157             : 
     158             : 
     159             : //------------------------------------------------------------------------
     160           0 : IMPL_LINK( ORelationDialog, OKClickHdl, Button*, /*pButton*/ )
     161             : {
     162             :     //////////////////////////////////////////////////////////////////////
     163             :     // RadioButtons auslesen
     164           0 :     sal_uInt16 nAttrib = 0;
     165             : 
     166             :     // Delete Rules
     167           0 :     if( aRB_NoCascDel.IsChecked() )
     168           0 :         nAttrib |= KeyRule::NO_ACTION;
     169           0 :     if( aRB_CascDel.IsChecked() )
     170           0 :         nAttrib |= KeyRule::CASCADE;
     171           0 :     if( aRB_CascDelNull.IsChecked() )
     172           0 :         nAttrib |= KeyRule::SET_NULL;
     173           0 :     if( aRB_CascDelDefault.IsChecked() )
     174           0 :         nAttrib |= KeyRule::SET_DEFAULT;
     175             : 
     176           0 :     ORelationTableConnectionData* pConnData = static_cast<ORelationTableConnectionData*>(m_pConnData.get());
     177           0 :     pConnData->SetDeleteRules( nAttrib );
     178             : 
     179             :     // Update Rules
     180           0 :     nAttrib = 0;
     181           0 :     if( aRB_NoCascUpd.IsChecked() )
     182           0 :         nAttrib |= KeyRule::NO_ACTION;
     183           0 :     if( aRB_CascUpd.IsChecked() )
     184           0 :         nAttrib |= KeyRule::CASCADE;
     185           0 :     if( aRB_CascUpdNull.IsChecked() )
     186           0 :         nAttrib |= KeyRule::SET_NULL;
     187           0 :     if( aRB_CascUpdDefault.IsChecked() )
     188           0 :         nAttrib |= KeyRule::SET_DEFAULT;
     189           0 :     pConnData->SetUpdateRules( nAttrib );
     190             : 
     191           0 :     m_pTableControl->SaveModified();
     192             : 
     193             :     //// wenn die ComboBoxen fuer die Tabellenauswahl enabled sind (Constructor mit bAllowTableSelect==sal_True), dann muss ich in die
     194             :     //// Connection auch die Tabellennamen stecken
     195             :     //m_pConnData->SetSourceWinName(m_pTableControl->getSourceWinName());
     196             :     //m_pConnData->SetDestWinName(m_pTableControl->getDestWinName());
     197             : 
     198             :     // try to create the relation
     199             :     try
     200             :     {
     201           0 :         ORelationTableConnectionData* pOrigConnData = static_cast<ORelationTableConnectionData*>(m_pOrigConnData.get());
     202           0 :         if ( *pConnData == *pOrigConnData || pConnData->Update())
     203             :         {
     204           0 :             m_pOrigConnData->CopyFrom( *m_pConnData );
     205           0 :             EndDialog( RET_OK );
     206           0 :             return 0L;
     207             :         }
     208             :     }
     209           0 :     catch( const SQLException& )
     210             :     {
     211             :         ::dbaui::showError( SQLExceptionInfo( ::cppu::getCaughtException() ),
     212             :                             this,
     213           0 :                             comphelper::getComponentContext(static_cast<OJoinTableView*>(GetParent())->getDesignView()->getController().getORB()));
     214             :     }
     215           0 :     catch( const Exception& )
     216             :     {
     217             :         DBG_UNHANDLED_EXCEPTION();
     218             :     }
     219             : 
     220           0 :     m_bTriedOneUpdate = sal_True;
     221             :     // this means that the original connection may be lost (if m_pConnData was not a newly created but an
     222             :     // existent conn to be modified), which we reflect by returning RET_NO (see ::Execute)
     223             : 
     224             :     // try again
     225           0 :     Init(m_pConnData);
     226           0 :     m_pTableControl->Init( m_pConnData );
     227           0 :     m_pTableControl->lateInit();
     228             : 
     229           0 :     return 0;
     230             : }
     231             : 
     232             : 
     233             : //------------------------------------------------------------------------
     234           0 : short ORelationDialog::Execute()
     235             : {
     236           0 :     short nResult = ModalDialog::Execute();
     237           0 :     if ((nResult != RET_OK) && m_bTriedOneUpdate)
     238           0 :         return RET_NO;
     239             : 
     240           0 :     return nResult;
     241             : }
     242             : // -----------------------------------------------------------------------------
     243           0 : TTableConnectionData::value_type ORelationDialog::getConnectionData() const
     244             : {
     245           0 :     return m_pConnData;
     246             : }
     247             : // -----------------------------------------------------------------------------
     248           0 : void ORelationDialog::setValid(sal_Bool _bValid)
     249             : {
     250           0 :     aPB_OK.Enable(_bValid);
     251           0 : }
     252             : // -----------------------------------------------------------------------------
     253           0 : void ORelationDialog::notifyConnectionChange()
     254             : {
     255           0 :     Init(m_pConnData);
     256           0 : }
     257             : // -----------------------------------------------------------------------------
     258             : 
     259             : 
     260             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10