LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/querydesign - querydlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 169 0.0 %
Date: 2012-12-17 Functions: 0 16 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 "querydlg.hxx"
      21             : #include "dbu_qry.hrc"
      22             : #include "querydlg.hrc"
      23             : #include <tools/debug.hxx>
      24             : #include <tools/diagnose_ex.h>
      25             : #include "QTableConnectionData.hxx"
      26             : #include "querycontroller.hxx"
      27             : #include "QueryTableView.hxx"
      28             : #include "QueryDesignView.hxx"
      29             : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
      30             : #include "RelationControl.hxx"
      31             : #include <vcl/msgbox.hxx>
      32             : 
      33             : using namespace dbaui;
      34             : using namespace ::com::sun::star::uno;
      35             : using namespace ::com::sun::star::container;
      36             : using namespace ::com::sun::star::sdbc;
      37             : 
      38             : namespace dbaui
      39             : {
      40           0 : class OJoinControl  : public Window
      41             : {
      42             : public:
      43             :     FixedLine               aFL_Join;
      44             :     FixedText               aFT_Title;
      45             :     ListBox                 aLB_JoinType;
      46             :     CheckBox                m_aCBNatural;
      47             : 
      48             :     OJoinControl(Window* _pParent,const ResId& _rResId);
      49             : };
      50           0 : OJoinControl::OJoinControl(Window* _pParent,const ResId& _rResId)
      51             :     : Window(_pParent,_rResId)
      52           0 :     ,aFL_Join( this, ResId( FL_JOIN,*_rResId.GetResMgr() ) )
      53           0 :     ,aFT_Title( this, ResId(FT_LISTBOXTITLE,*_rResId.GetResMgr()) )
      54           0 :     ,aLB_JoinType( this, ResId(LB_JOINTYPE,*_rResId.GetResMgr()) )
      55           0 :     ,m_aCBNatural( this, ResId(CB_NATURAL,*_rResId.GetResMgr()) )
      56             : {
      57           0 :     FreeResource();
      58           0 : }
      59             : // -----------------------------------------------------------------------------
      60             : } // dbaui
      61             : // -----------------------------------------------------------------------------
      62             : DBG_NAME(DlgQryJoin)
      63           0 : DlgQryJoin::DlgQryJoin( OQueryTableView * pParent,
      64             :                        const TTableConnectionData::value_type& _pData,
      65             :                        OJoinTableView::OTableWindowMap* _pTableMap,
      66             :                        const Reference< XConnection >& _xConnection,
      67             :                        sal_Bool _bAllowTableSelect)
      68             :     :ModalDialog( pParent, ModuleRes(DLG_QRY_JOIN) )
      69             :     ,aML_HelpText( this, ModuleRes(ML_HELPTEXT) )
      70             :     ,aPB_OK( this, ModuleRes( PB_OK ) )
      71             :     ,aPB_CANCEL( this, ModuleRes( PB_CANCEL ) )
      72             :     ,aPB_HELP( this, ModuleRes( PB_HELP ) )
      73             :     ,m_pJoinControl( NULL )
      74             :     ,m_pTableControl( NULL )
      75             :     ,m_pTableMap(_pTableMap)
      76             :     ,m_pTableView(pParent)
      77           0 :     ,eJoinType(static_cast<OQueryTableConnectionData*>(_pData.get())->GetJoinType())
      78             :     ,m_pOrigConnData(_pData)
      79           0 :     ,m_xConnection(_xConnection)
      80             : {
      81             :     DBG_CTOR(DlgQryJoin,NULL);
      82             : 
      83           0 :     aML_HelpText.SetControlBackground( GetSettings().GetStyleSettings().GetFaceColor() );
      84             :     //////////////////////////////////////////////////////////////////////
      85             :     // Connection kopieren
      86           0 :     m_pConnData.reset(_pData->NewInstance());
      87           0 :     m_pConnData->CopyFrom(*_pData);
      88             : 
      89           0 :     m_pTableControl = new OTableListBoxControl(this,ModuleRes(WND_CONTROL),m_pTableMap,this);
      90             : 
      91           0 :     m_pJoinControl = new OJoinControl(m_pTableControl,ModuleRes(WND_JOIN_CONTROL));
      92             : 
      93           0 :     m_pJoinControl->Show();
      94           0 :     m_pJoinControl->m_aCBNatural.Check(static_cast<OQueryTableConnectionData*>(m_pConnData.get())->isNatural());
      95           0 :     m_pTableControl->Show();
      96             : 
      97           0 :     if( _bAllowTableSelect )
      98             :     {
      99           0 :         m_pTableControl->Init( m_pConnData );
     100           0 :         m_pTableControl->fillListBoxes();
     101             :     }
     102             :     else
     103             :     {
     104           0 :         m_pTableControl->fillAndDisable(m_pConnData);
     105           0 :         m_pTableControl->Init( m_pConnData );
     106             :     }
     107             : 
     108           0 :     m_pTableControl->lateUIInit(m_pJoinControl);
     109             : 
     110           0 :     sal_Bool bSupportFullJoin = sal_False;
     111           0 :     Reference<XDatabaseMetaData> xMeta;
     112             :     try
     113             :     {
     114           0 :         xMeta = m_xConnection->getMetaData();
     115           0 :         if ( xMeta.is() )
     116           0 :             bSupportFullJoin = xMeta->supportsFullOuterJoins();
     117             :     }
     118           0 :     catch(SQLException&)
     119             :     {
     120             :     }
     121           0 :     sal_Bool bSupportOuterJoin = sal_False;
     122             :     try
     123             :     {
     124           0 :         if ( xMeta.is() )
     125           0 :             bSupportOuterJoin= xMeta->supportsOuterJoins();
     126             :     }
     127           0 :     catch(SQLException&)
     128             :     {
     129             :     }
     130             : 
     131           0 :     setJoinType(eJoinType);
     132             : 
     133           0 :     aPB_OK.SetClickHdl( LINK(this, DlgQryJoin, OKClickHdl) );
     134             : 
     135           0 :     m_pJoinControl->aLB_JoinType.SetSelectHdl(LINK(this,DlgQryJoin,LBChangeHdl));
     136           0 :     m_pJoinControl->m_aCBNatural.SetToggleHdl(LINK(this,DlgQryJoin,NaturalToggleHdl));
     137             : 
     138           0 :     if ( static_cast<OQueryTableView*>(pParent)->getDesignView()->getController().isReadOnly() )
     139             :     {
     140           0 :         m_pJoinControl->aLB_JoinType.Disable();
     141           0 :         m_pJoinControl->m_aCBNatural.Disable();
     142           0 :         m_pTableControl->Disable();
     143             :     }
     144             :     else
     145             :     {
     146           0 :         const sal_uInt16 nCount = m_pJoinControl->aLB_JoinType.GetEntryCount();
     147           0 :         for (sal_uInt16 i = 0; i < nCount; ++i)
     148             :         {
     149           0 :             const long nJoinTyp = reinterpret_cast<long>(m_pJoinControl->aLB_JoinType.GetEntryData(i));
     150           0 :             if ( !bSupportFullJoin && nJoinTyp == ID_FULL_JOIN )
     151           0 :                 m_pJoinControl->aLB_JoinType.RemoveEntry(i);
     152           0 :             else if ( !bSupportOuterJoin && (nJoinTyp == ID_LEFT_JOIN || nJoinTyp == ID_RIGHT_JOIN) )
     153           0 :                 m_pJoinControl->aLB_JoinType.RemoveEntry(i);
     154             :         }
     155             : 
     156           0 :         m_pTableControl->NotifyCellChange();
     157           0 :         m_pTableControl->enableRelation(!static_cast<OQueryTableConnectionData*>(m_pConnData.get())->isNatural() && eJoinType != CROSS_JOIN );
     158             :     }
     159             : 
     160           0 :     FreeResource();
     161           0 : }
     162             : 
     163             : //------------------------------------------------------------------------
     164           0 : DlgQryJoin::~DlgQryJoin()
     165             : {
     166             :     DBG_DTOR(DlgQryJoin,NULL);
     167           0 :     delete m_pJoinControl;
     168           0 :     delete m_pTableControl;
     169           0 : }
     170             : // -----------------------------------------------------------------------------
     171           0 : IMPL_LINK( DlgQryJoin, LBChangeHdl, ListBox*, /*pListBox*/ )
     172             : {
     173             :     DBG_CHKTHIS(DlgQryJoin,NULL);
     174           0 :     if (m_pJoinControl->aLB_JoinType.GetSelectEntryPos() == m_pJoinControl->aLB_JoinType.GetSavedValue() )
     175           0 :         return 1;
     176             : 
     177           0 :     m_pJoinControl->aLB_JoinType.SaveValue();
     178           0 :     aML_HelpText.SetText(String());
     179             : 
     180           0 :     m_pTableControl->enableRelation(true);
     181             : 
     182           0 :     String sFirstWinName    = m_pConnData->getReferencingTable()->GetWinName();
     183           0 :     String sSecondWinName   = m_pConnData->getReferencedTable()->GetWinName();
     184           0 :     const EJoinType eOldJoinType = eJoinType;
     185           0 :     sal_uInt16 nResId = 0;
     186           0 :     const sal_uInt16 nPos = m_pJoinControl->aLB_JoinType.GetSelectEntryPos();
     187           0 :     const long nJoinType = reinterpret_cast<long>(m_pJoinControl->aLB_JoinType.GetEntryData(nPos));
     188           0 :     sal_Bool bAddHint = sal_True;
     189           0 :     switch ( nJoinType )
     190             :     {
     191             :         default:
     192             :         case ID_INNER_JOIN:
     193           0 :             nResId = STR_QUERY_INNER_JOIN;
     194           0 :             bAddHint = sal_False;
     195           0 :             eJoinType = INNER_JOIN;
     196           0 :             break;
     197             :         case ID_LEFT_JOIN:
     198           0 :             nResId = STR_QUERY_LEFTRIGHT_JOIN;
     199           0 :             eJoinType = LEFT_JOIN;
     200           0 :             break;
     201             :         case ID_RIGHT_JOIN:
     202             :             {
     203           0 :                 nResId = STR_QUERY_LEFTRIGHT_JOIN;
     204           0 :                 eJoinType = RIGHT_JOIN;
     205           0 :                 String sTemp = sFirstWinName;
     206           0 :                 sFirstWinName = sSecondWinName;
     207           0 :                 sSecondWinName = sTemp;
     208             :             }
     209           0 :             break;
     210             :         case ID_FULL_JOIN:
     211           0 :             nResId = STR_QUERY_FULL_JOIN;
     212           0 :             eJoinType = FULL_JOIN;
     213           0 :             break;
     214             :         case ID_CROSS_JOIN:
     215             :             {
     216           0 :                 nResId = STR_QUERY_CROSS_JOIN;
     217           0 :                 eJoinType = CROSS_JOIN;
     218             : 
     219           0 :                 m_pConnData->ResetConnLines();
     220           0 :                 m_pTableControl->lateInit();
     221           0 :                 m_pJoinControl->m_aCBNatural.Check(sal_False);
     222           0 :                 m_pTableControl->enableRelation(false);
     223           0 :                 ::rtl::OUString sEmpty;
     224           0 :                 m_pConnData->AppendConnLine(sEmpty,sEmpty);
     225           0 :                 aPB_OK.Enable(sal_True);
     226             :             }
     227           0 :             break;
     228             :     }
     229             : 
     230           0 :     m_pJoinControl->m_aCBNatural.Enable(eJoinType != CROSS_JOIN);
     231             : 
     232           0 :     if ( eJoinType != eOldJoinType && eOldJoinType == CROSS_JOIN )
     233             :     {
     234           0 :         m_pConnData->ResetConnLines();
     235             :     }
     236           0 :     if ( eJoinType != CROSS_JOIN )
     237             :     {
     238           0 :         m_pTableControl->NotifyCellChange();
     239           0 :         NaturalToggleHdl(&m_pJoinControl->m_aCBNatural);
     240             :     }
     241             : 
     242           0 :     m_pTableControl->Invalidate();
     243             : 
     244           0 :     String sHelpText = String( ModuleRes( nResId ) );
     245           0 :     if( nPos )
     246             :     {
     247           0 :         sHelpText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%1" ) ), sFirstWinName );
     248           0 :         sHelpText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%2" ) ), sSecondWinName );
     249             :     }
     250           0 :     if ( bAddHint )
     251             :     {
     252           0 :         sHelpText += String( RTL_CONSTASCII_USTRINGPARAM( "\n" ) );
     253           0 :         sHelpText += String( ModuleRes( STR_JOIN_TYPE_HINT ) );
     254             :     }
     255             : 
     256           0 :     aML_HelpText.SetText( sHelpText );
     257           0 :     return 1;
     258             : }
     259             : // -----------------------------------------------------------------------------
     260             : 
     261           0 : IMPL_LINK( DlgQryJoin, OKClickHdl, Button*, /*pButton*/ )
     262             : {
     263             :     DBG_CHKTHIS(DlgQryJoin,NULL);
     264             : 
     265           0 :     m_pConnData->Update();
     266           0 :     m_pOrigConnData->CopyFrom( *m_pConnData );
     267             : 
     268           0 :     EndDialog(RET_OK);
     269           0 :     return 1;
     270             : }
     271             : // -----------------------------------------------------------------------------
     272             : 
     273           0 : IMPL_LINK( DlgQryJoin, NaturalToggleHdl, CheckBox*, /*pButton*/ )
     274             : {
     275             :     DBG_CHKTHIS(DlgQryJoin,NULL);
     276           0 :     sal_Bool bChecked = m_pJoinControl->m_aCBNatural.IsChecked();
     277           0 :     static_cast<OQueryTableConnectionData*>(m_pConnData.get())->setNatural(bChecked);
     278           0 :     m_pTableControl->enableRelation(!bChecked);
     279           0 :     if ( bChecked )
     280             :     {
     281           0 :         m_pConnData->ResetConnLines();
     282             :         try
     283             :         {
     284           0 :             Reference<XNameAccess> xReferencedTableColumns(m_pConnData->getReferencedTable()->getColumns());
     285           0 :             Sequence< ::rtl::OUString> aSeq = m_pConnData->getReferencingTable()->getColumns()->getElementNames();
     286           0 :             const ::rtl::OUString* pIter = aSeq.getConstArray();
     287           0 :             const ::rtl::OUString* pEnd   = pIter + aSeq.getLength();
     288           0 :             for(;pIter != pEnd;++pIter)
     289             :             {
     290           0 :                 if ( xReferencedTableColumns->hasByName(*pIter) )
     291           0 :                     m_pConnData->AppendConnLine(*pIter,*pIter);
     292           0 :             }
     293             :         }
     294           0 :         catch( const Exception& )
     295             :         {
     296             :             DBG_UNHANDLED_EXCEPTION();
     297             :         }
     298           0 :         m_pTableControl->NotifyCellChange();
     299           0 :         m_pTableControl->Invalidate();
     300             :     }
     301             : 
     302           0 :     return 1;
     303             : }
     304             : // -----------------------------------------------------------------------------
     305           0 : TTableConnectionData::value_type DlgQryJoin::getConnectionData() const
     306             : {
     307           0 :     return m_pConnData;
     308             : }
     309             : // -----------------------------------------------------------------------------
     310           0 : void DlgQryJoin::setValid(sal_Bool _bValid)
     311             : {
     312           0 :     aPB_OK.Enable(_bValid || eJoinType == CROSS_JOIN );
     313           0 : }
     314             : // -----------------------------------------------------------------------------
     315           0 : void DlgQryJoin::notifyConnectionChange( )
     316             : {
     317           0 :     setJoinType( static_cast<OQueryTableConnectionData*>(m_pConnData.get())->GetJoinType() );
     318           0 :     m_pJoinControl->m_aCBNatural.Check(static_cast<OQueryTableConnectionData*>(m_pConnData.get())->isNatural());
     319           0 :     NaturalToggleHdl(&m_pJoinControl->m_aCBNatural);
     320           0 : }
     321             : // -----------------------------------------------------------------------------
     322           0 : void DlgQryJoin::setJoinType(EJoinType _eNewJoinType)
     323             : {
     324           0 :     eJoinType = _eNewJoinType;
     325           0 :     m_pJoinControl->m_aCBNatural.Enable(eJoinType != CROSS_JOIN);
     326             : 
     327           0 :     long nJoinType = 0;
     328           0 :     switch ( eJoinType )
     329             :     {
     330             :         default:
     331             :         case INNER_JOIN:
     332           0 :             nJoinType = ID_INNER_JOIN;
     333           0 :             break;
     334             :         case LEFT_JOIN:
     335           0 :             nJoinType = ID_LEFT_JOIN;
     336           0 :             break;
     337             :         case RIGHT_JOIN:
     338           0 :             nJoinType = ID_RIGHT_JOIN;
     339           0 :             break;
     340             :         case FULL_JOIN:
     341           0 :             nJoinType = ID_FULL_JOIN;
     342           0 :             break;
     343             :         case CROSS_JOIN:
     344           0 :             nJoinType = ID_CROSS_JOIN;
     345           0 :             break;
     346             :     }
     347             : 
     348           0 :     const sal_uInt16 nCount = m_pJoinControl->aLB_JoinType.GetEntryCount();
     349           0 :     for (sal_uInt16 i = 0; i < nCount; ++i)
     350             :     {
     351           0 :         if ( nJoinType == reinterpret_cast<long>(m_pJoinControl->aLB_JoinType.GetEntryData(i)) )
     352             :         {
     353           0 :             m_pJoinControl->aLB_JoinType.SelectEntryPos(i);
     354           0 :             break;
     355             :         }
     356             :     }
     357             : 
     358           0 :     LBChangeHdl(&m_pJoinControl->aLB_JoinType);
     359           0 : }
     360             : // -----------------------------------------------------------------------------
     361             : 
     362             : 
     363             : 
     364             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10