LCOV - code coverage report
Current view: top level - dbaccess/source/ui/control - RelationControl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 316 0.0 %
Date: 2014-04-11 Functions: 0 44 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 "RelationControl.hxx"
      21             : #include "RelationControl.hrc"
      22             : 
      23             : #include <svtools/editbrowsebox.hxx>
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : #include <tools/diagnose_ex.h>
      26             : #include <vcl/builder.hxx>
      27             : #include "TableConnectionData.hxx"
      28             : #include "TableConnection.hxx"
      29             : #include "TableWindow.hxx"
      30             : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
      31             : #include "UITools.hxx"
      32             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      33             : #include <com/sun/star/container/XNameAccess.hpp>
      34             : #include "RelControliFace.hxx"
      35             : #include "dbu_control.hrc"
      36             : #include "dbaccess_helpid.hrc"
      37             : #include <osl/diagnose.h>
      38             : 
      39             : #include <algorithm>
      40             : #include <list>
      41             : using std::list;
      42             : #include <utility>
      43             : using std::pair;
      44             : using std::make_pair;
      45             : 
      46             : #define SOURCE_COLUMN   1
      47             : #define DEST_COLUMN     2
      48             : 
      49             : namespace dbaui
      50             : {
      51             :     using namespace ::com::sun::star::uno;
      52             :     using namespace ::com::sun::star::beans;
      53             :     using namespace ::com::sun::star::sdbc;
      54             :     using namespace ::com::sun::star::sdbcx;
      55             :     using namespace ::com::sun::star::container;
      56             :     using namespace svt;
      57             : 
      58             :     typedef ::svt::EditBrowseBox ORelationControl_Base;
      59             :     class ORelationControl : public ORelationControl_Base
      60             :     {
      61             :         friend class OTableListBoxControl;
      62             : 
      63             :         ::std::auto_ptr< ::svt::ListBoxControl> m_pListCell;
      64             :         TTableConnectionData::value_type        m_pConnData;
      65             :         OTableListBoxControl*                   m_pBoxControl;
      66             :         long                                    m_nDataPos;
      67             :         Reference< XPropertySet>                m_xSourceDef;
      68             :         Reference< XPropertySet>                m_xDestDef;
      69             :         enum opcode { DELETE, INSERT, MODIFY };
      70             :         typedef list< pair < opcode, pair < OConnectionLineDataVec::size_type, OConnectionLineDataVec::size_type> > > ops_type;
      71             :         ops_type                                m_ops;
      72             : 
      73             :         void fillListBox(const Reference< XPropertySet>& _xDest,long nRow,sal_uInt16 nColumnId);
      74             :         /** returns the column id for the editbrowsebox
      75             :             @param  _nColId
      76             :                     the column id SOURCE_COLUMN or DEST_COLUMN
      77             : 
      78             :             @return the current column id eihter SOURCE_COLUMN or DEST_COLUMN depends on the connection data
      79             :         */
      80             :         sal_uInt16 getColumnIdent( sal_uInt16 _nColId ) const;
      81             :     public:
      82             :         ORelationControl(Window *pParent);
      83           0 :         void SetController(OTableListBoxControl* pController)
      84             :         {
      85           0 :             m_pBoxControl = pController;
      86           0 :         }
      87             :         virtual ~ORelationControl();
      88             : 
      89             :         /** searches for a connection between these two tables
      90             :             @param  _pSource
      91             :                     the left table
      92             :             @param  _pDest
      93             :                     the right window
      94             :         */
      95             :         void setWindowTables(const OTableWindow* _pSource,const OTableWindow* _pDest);
      96             : 
      97             :         /** allows to access the connection data from outside
      98             : 
      99             :             @return rthe connection data
     100             :         */
     101           0 :         inline TTableConnectionData::value_type getData() const { return m_pConnData; }
     102             : 
     103             :         void lateInit();
     104             : 
     105             :     protected:
     106             :         virtual void Resize() SAL_OVERRIDE;
     107             :         virtual Size GetOptimalSize() const SAL_OVERRIDE;
     108             :         virtual bool PreNotify(NotifyEvent& rNEvt ) SAL_OVERRIDE;
     109             : 
     110             :         virtual bool IsTabAllowed(bool bForward) const SAL_OVERRIDE;
     111             : 
     112             :         virtual void Init(const TTableConnectionData::value_type& _pConnData);
     113           0 :         virtual void Init() SAL_OVERRIDE { ORelationControl_Base::Init(); }
     114             :         virtual void InitController( ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol ) SAL_OVERRIDE;
     115             :         virtual ::svt::CellController* GetController( long nRow, sal_uInt16 nCol ) SAL_OVERRIDE;
     116             :         virtual void PaintCell( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColId ) const SAL_OVERRIDE;
     117             :         virtual bool SeekRow( long nRow ) SAL_OVERRIDE;
     118             :         virtual bool SaveModified() SAL_OVERRIDE;
     119             :         virtual OUString GetCellText( long nRow, sal_uInt16 nColId ) const SAL_OVERRIDE;
     120             : 
     121             :         virtual void CellModified() SAL_OVERRIDE;
     122             : 
     123             :         DECL_LINK( AsynchDeactivate, void* );
     124             :     private:
     125             : 
     126             :         DECL_LINK( AsynchActivate, void* );
     127             : 
     128             :     };
     129             : 
     130             :     // class ORelationControl
     131           0 :     ORelationControl::ORelationControl(Window *pParent)
     132             :         : EditBrowseBox(pParent,
     133             :             EBBF_SMART_TAB_TRAVEL | EBBF_NOROWPICTURE,
     134             :             WB_TABSTOP | WB_BORDER | BROWSER_AUTOSIZE_LASTCOL)
     135             :         , m_pBoxControl(NULL)
     136             :         , m_nDataPos(0)
     137             :         , m_xSourceDef(NULL)
     138           0 :         , m_xDestDef(NULL)
     139             :     {
     140           0 :     }
     141             : 
     142           0 :     extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeORelationControl(Window *pParent, VclBuilder::stringmap &)
     143             :     {
     144           0 :         return new ORelationControl(pParent);
     145             :     }
     146             : 
     147           0 :     ORelationControl::~ORelationControl()
     148             :     {
     149           0 :     }
     150             : 
     151           0 :     void ORelationControl::Init(const TTableConnectionData::value_type& _pConnData)
     152             :     {
     153             : 
     154           0 :         m_pConnData = _pConnData;
     155             :         OSL_ENSURE(m_pConnData, "No data supplied!");
     156             : 
     157           0 :         m_pConnData->normalizeLines();
     158           0 :     }
     159             : 
     160           0 :     void ORelationControl::lateInit()
     161             :     {
     162           0 :         if ( !m_pConnData.get() )
     163           0 :             return;
     164           0 :         m_xSourceDef = m_pConnData->getReferencingTable()->getTable();
     165           0 :         m_xDestDef = m_pConnData->getReferencedTable()->getTable();
     166             : 
     167           0 :         if ( ColCount() == 0 )
     168             :         {
     169           0 :             InsertDataColumn( SOURCE_COLUMN, m_pConnData->getReferencingTable()->GetWinName(), 100);
     170           0 :             InsertDataColumn( DEST_COLUMN, m_pConnData->getReferencedTable()->GetWinName(), 100);
     171             :             // If the Defs do not yet exits, we need to set them with SetSource-/-DestDef
     172             : 
     173           0 :             m_pListCell.reset( new ListBoxControl( &GetDataWindow() ) );
     174             : 
     175             :             // set browse mode
     176             :             SetMode(    BROWSER_COLUMNSELECTION |
     177             :                         BROWSER_HLINESFULL      |
     178             :                         BROWSER_VLINESFULL      |
     179             :                         BROWSER_HIDECURSOR      |
     180             :                         BROWSER_HIDESELECT      |
     181             :                         BROWSER_AUTO_HSCROLL    |
     182           0 :                         BROWSER_AUTO_VSCROLL);
     183             :         }
     184             :         else
     185             :             // not the first call
     186           0 :             RowRemoved(0, GetRowCount());
     187             : 
     188           0 :         RowInserted(0, m_pConnData->GetConnLineDataList()->size() + 1, true); // add one extra row
     189             :     }
     190             : 
     191           0 :     void ORelationControl::Resize()
     192             :     {
     193           0 :         EditBrowseBox::Resize();
     194           0 :         long nOutputWidth = GetOutputSizePixel().Width() - 1;
     195           0 :         SetColumnWidth(1, (nOutputWidth / 2));
     196           0 :         SetColumnWidth(2, (nOutputWidth / 2));
     197           0 :     }
     198             : 
     199           0 :     bool ORelationControl::PreNotify(NotifyEvent& rNEvt)
     200             :     {
     201           0 :         if (rNEvt.GetType() == EVENT_LOSEFOCUS && !HasChildPathFocus() )
     202           0 :             PostUserEvent(LINK(this, ORelationControl, AsynchDeactivate));
     203           0 :         else if (rNEvt.GetType() == EVENT_GETFOCUS)
     204           0 :             PostUserEvent(LINK(this, ORelationControl, AsynchActivate));
     205             : 
     206           0 :         return EditBrowseBox::PreNotify(rNEvt);
     207             :     }
     208             : 
     209           0 :     IMPL_LINK_NOARG(ORelationControl, AsynchActivate)
     210             :     {
     211           0 :         ActivateCell();
     212           0 :         return 0L;
     213             :     }
     214             : 
     215           0 :     IMPL_LINK_NOARG(ORelationControl, AsynchDeactivate)
     216             :     {
     217           0 :         DeactivateCell();
     218           0 :         return 0L;
     219             :     }
     220             : 
     221           0 :     bool ORelationControl::IsTabAllowed(bool bForward) const
     222             :     {
     223           0 :         long nRow = GetCurRow();
     224           0 :         sal_uInt16 nCol = GetCurColumnId();
     225             : 
     226           0 :         bool bRet = !((     ( bForward && (nCol == DEST_COLUMN)     && (nRow == GetRowCount() - 1)))
     227           0 :                         ||  (!bForward && (nCol == SOURCE_COLUMN)   && (nRow == 0)));
     228             : 
     229           0 :         return bRet && EditBrowseBox::IsTabAllowed(bForward);
     230             :     }
     231             : 
     232           0 :     bool ORelationControl::SaveModified()
     233             :     {
     234           0 :         long nRow = GetCurRow();
     235           0 :         if ( nRow != BROWSER_ENDOFSELECTION )
     236             :         {
     237           0 :             OUString sFieldName(m_pListCell->GetSelectEntry());
     238           0 :             OConnectionLineDataVec* pLines = m_pConnData->GetConnLineDataList();
     239           0 :             if ( pLines->size() <= static_cast<OConnectionLineDataVec::size_type>(nRow) )
     240             :             {
     241           0 :                 pLines->push_back(new OConnectionLineData());
     242           0 :                 nRow = pLines->size() - 1;
     243             :                 // add new past-pLines row
     244           0 :                 m_ops.push_back(make_pair(INSERT, make_pair(nRow+1, nRow+2)));
     245             :             }
     246             : 
     247           0 :             OConnectionLineDataRef pConnLineData = (*pLines)[nRow];
     248             : 
     249           0 :             switch( getColumnIdent( GetCurColumnId() ) )
     250             :             {
     251             :             case SOURCE_COLUMN:
     252           0 :                 pConnLineData->SetSourceFieldName( sFieldName );
     253           0 :                 break;
     254             :             case DEST_COLUMN:
     255           0 :                 pConnLineData->SetDestFieldName( sFieldName );
     256           0 :                 break;
     257           0 :             }
     258             :             // the modification we just did does *not* need to be registered in m_ops;
     259             :             // it is already taken into account (by the codepath that called us)
     260             :             //m_ops.push_back(make_pair(MODIFY, make_pair(nRow, nRow+1)));
     261             :         }
     262             : 
     263           0 :         const OConnectionLineDataVec::size_type oldSize = m_pConnData->GetConnLineDataList()->size();
     264           0 :         OConnectionLineDataVec::size_type line = m_pConnData->normalizeLines();
     265           0 :         const OConnectionLineDataVec::size_type newSize = m_pConnData->GetConnLineDataList()->size();
     266             :         assert(newSize <= oldSize);
     267           0 :         m_ops.push_back(make_pair(MODIFY, make_pair(line, newSize)));
     268           0 :         m_ops.push_back(make_pair(DELETE, make_pair(newSize, oldSize)));
     269             : 
     270           0 :         return true;
     271             :     }
     272             : 
     273           0 :     sal_uInt16 ORelationControl::getColumnIdent( sal_uInt16 _nColId ) const
     274             :     {
     275           0 :         sal_uInt16 nId = _nColId;
     276           0 :         if ( m_pConnData->getReferencingTable() != m_pBoxControl->getReferencingTable() )
     277           0 :             nId = ( _nColId == SOURCE_COLUMN) ? DEST_COLUMN : SOURCE_COLUMN;
     278           0 :         return nId;
     279             :     }
     280             : 
     281           0 :     OUString ORelationControl::GetCellText( long nRow, sal_uInt16 nColId ) const
     282             :     {
     283           0 :         OUString sText;
     284           0 :         if ( m_pConnData->GetConnLineDataList()->size() > static_cast<size_t>(nRow) )
     285             :         {
     286           0 :             OConnectionLineDataRef pConnLineData = (*m_pConnData->GetConnLineDataList())[nRow];
     287           0 :             switch( getColumnIdent( nColId ) )
     288             :             {
     289             :             case SOURCE_COLUMN:
     290           0 :                 sText  = pConnLineData->GetSourceFieldName();
     291           0 :                 break;
     292             :             case DEST_COLUMN:
     293           0 :                 sText  = pConnLineData->GetDestFieldName();
     294           0 :                 break;
     295           0 :             }
     296             :         }
     297           0 :         return sText;
     298             :     }
     299             : 
     300           0 :     void ORelationControl::InitController( CellControllerRef& /*rController*/, long nRow, sal_uInt16 nColumnId )
     301             :     {
     302             : 
     303           0 :         OString sHelpId( HID_RELATIONDIALOG_LEFTFIELDCELL );
     304             : 
     305           0 :         Reference< XPropertySet> xDef;
     306           0 :         switch ( getColumnIdent(nColumnId) )
     307             :         {
     308             :             case SOURCE_COLUMN:
     309           0 :                 xDef    = m_xSourceDef;
     310           0 :                 sHelpId = HID_RELATIONDIALOG_LEFTFIELDCELL;
     311           0 :                 break;
     312             :             case DEST_COLUMN:
     313           0 :                 xDef    = m_xDestDef;
     314           0 :                 sHelpId = HID_RELATIONDIALOG_RIGHTFIELDCELL;
     315           0 :                 break;
     316             :             default:
     317             :                 //  ?????????
     318           0 :                 break;
     319             :         }
     320             : 
     321           0 :         if ( xDef.is() )
     322             :         {
     323           0 :             fillListBox(xDef,nRow,nColumnId);
     324           0 :             OUString sName = GetCellText( nRow, nColumnId );
     325           0 :             m_pListCell->SelectEntry( sName );
     326           0 :             if ( m_pListCell->GetSelectEntry() != sName )
     327             :             {
     328           0 :                 m_pListCell->InsertEntry( sName );
     329           0 :                 m_pListCell->SelectEntry( sName );
     330             :             }
     331             : 
     332           0 :             m_pListCell->SetHelpId(sHelpId);
     333           0 :         }
     334           0 :     }
     335             : 
     336           0 :     CellController* ORelationControl::GetController( long /*nRow*/, sal_uInt16 /*nColumnId*/ )
     337             :     {
     338           0 :         return new ListBoxCellController( m_pListCell.get() );
     339             :     }
     340             : 
     341           0 :     bool ORelationControl::SeekRow( long nRow )
     342             :     {
     343           0 :         m_nDataPos = nRow;
     344           0 :         return true;
     345             :     }
     346             : 
     347           0 :     void ORelationControl::PaintCell( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId ) const
     348             :     {
     349           0 :         OUString aText = const_cast< ORelationControl*>(this)->GetCellText( m_nDataPos, nColumnId );
     350             : 
     351           0 :         Point aPos( rRect.TopLeft() );
     352           0 :         Size aTextSize( GetDataWindow().GetTextHeight(),GetDataWindow().GetTextWidth( aText ));
     353             : 
     354           0 :         if( aPos.X() < rRect.Right() || aPos.X() + aTextSize.Width() > rRect.Right() ||
     355           0 :             aPos.Y() < rRect.Top() || aPos.Y() + aTextSize.Height() > rRect.Bottom() )
     356             :         {
     357           0 :             rDev.SetClipRegion(Region(rRect));
     358             :         }
     359             : 
     360           0 :         rDev.DrawText( aPos, aText );
     361             : 
     362           0 :         if( rDev.IsClipRegion() )
     363           0 :             rDev.SetClipRegion();
     364           0 :     }
     365           0 :     void ORelationControl::fillListBox(const Reference< XPropertySet>& _xDest,long /*_nRow*/,sal_uInt16 /*nColumnId*/)
     366             :     {
     367           0 :         m_pListCell->Clear();
     368             :         try
     369             :         {
     370           0 :             if ( _xDest.is() )
     371             :             {
     372             :                 //sal_Int32 nRows = GetRowCount();
     373           0 :                 Reference<XColumnsSupplier> xSup(_xDest,UNO_QUERY);
     374           0 :                 Reference<XNameAccess> xColumns = xSup->getColumns();
     375           0 :                 Sequence< OUString> aNames = xColumns->getElementNames();
     376           0 :                 const OUString* pIter = aNames.getConstArray();
     377           0 :                 const OUString* pEnd = pIter + aNames.getLength();
     378           0 :                 for(;pIter != pEnd;++pIter)
     379             :                 {
     380           0 :                     m_pListCell->InsertEntry( *pIter );
     381             :                 }
     382           0 :                 m_pListCell->InsertEntry(OUString(), 0);
     383             :             }
     384             :         }
     385           0 :         catch( const Exception& )
     386             :         {
     387             :             DBG_UNHANDLED_EXCEPTION();
     388             :         }
     389           0 :     }
     390           0 :     void ORelationControl::setWindowTables(const OTableWindow* _pSource,const OTableWindow* _pDest)
     391             :     {
     392             :         // If I edit here, hide
     393           0 :         sal_Bool bWasEditing = IsEditing();
     394           0 :         if ( bWasEditing )
     395           0 :             DeactivateCell();
     396             : 
     397           0 :         if ( _pSource && _pDest )
     398             :         {
     399           0 :             m_xSourceDef = _pSource->GetTable();
     400           0 :             SetColumnTitle(1, _pSource->GetName());
     401             : 
     402           0 :             m_xDestDef = _pDest->GetTable();
     403           0 :             SetColumnTitle(2, _pDest->GetName());
     404             : 
     405           0 :             const OJoinTableView* pView = _pSource->getTableView();
     406           0 :             OTableConnection* pConn = pView->GetTabConn(_pSource,_pDest);
     407           0 :             if ( pConn && !m_pConnData->GetConnLineDataList()->empty() )
     408             :             {
     409           0 :                 m_pConnData->CopyFrom(*pConn->GetData());
     410           0 :                 m_pBoxControl->getContainer()->notifyConnectionChange();
     411             :             }
     412             :             else
     413             :             {
     414             :                 // no connection found so we clear our data
     415           0 :                 OConnectionLineDataVec* pLines = m_pConnData->GetConnLineDataList();
     416             :                 ::std::for_each(pLines->begin(),
     417             :                                 pLines->end(),
     418           0 :                                 OUnaryRefFunctor<OConnectionLineData>( ::std::mem_fun(&OConnectionLineData::Reset))
     419           0 :                                 );
     420             : 
     421           0 :                 m_pConnData->setReferencingTable(_pSource->GetData());
     422           0 :                 m_pConnData->setReferencedTable(_pDest->GetData());
     423             :             }
     424           0 :             m_pConnData->normalizeLines();
     425             : 
     426             :         }
     427             :         // Repaint
     428           0 :         Invalidate();
     429             : 
     430           0 :         if ( bWasEditing )
     431             :         {
     432           0 :             GoToRow(0);
     433           0 :             ActivateCell();
     434             :         }
     435           0 :     }
     436             : 
     437           0 :     void ORelationControl::CellModified()
     438             :     {
     439           0 :         EditBrowseBox::CellModified();
     440           0 :         SaveModified();
     441             :         assert(m_pBoxControl);
     442           0 :         m_pBoxControl->NotifyCellChange();
     443           0 :     }
     444             : 
     445           0 :     Size ORelationControl::GetOptimalSize() const
     446             :     {
     447           0 :         return LogicToPixel(Size(140, 80), MAP_APPFONT);
     448             :     }
     449             : 
     450             :     // class OTableListBoxControl
     451           0 :     OTableListBoxControl::OTableListBoxControl(VclBuilderContainer* _pParent,
     452             :         const OJoinTableView::OTableWindowMap* _pTableMap,
     453             :         IRelationControlInterface* _pParentDialog)
     454             :         : m_pTableMap(_pTableMap)
     455           0 :         , m_pParentDialog(_pParentDialog)
     456             :     {
     457           0 :         _pParent->get(m_pLeftTable, "table1");
     458           0 :         _pParent->get(m_pRightTable, "table2");
     459             : 
     460           0 :         _pParent->get(m_pRC_Tables, "relations");
     461           0 :         m_pRC_Tables->SetController(this);
     462           0 :         m_pRC_Tables->Init();
     463             : 
     464           0 :         lateUIInit();
     465             : 
     466           0 :         Link aLink(LINK(this, OTableListBoxControl, OnTableChanged));
     467           0 :         m_pLeftTable->SetSelectHdl(aLink);
     468           0 :         m_pRightTable->SetSelectHdl(aLink);
     469           0 :     }
     470             : 
     471           0 :     OTableListBoxControl::~OTableListBoxControl()
     472             :     {
     473           0 :     }
     474             : 
     475           0 :     void OTableListBoxControl::fillListBoxes()
     476             :     {
     477             :         OSL_ENSURE( !m_pTableMap->empty(), "OTableListBoxControl::fillListBoxes: no table window!");
     478           0 :         OTableWindow* pInitialLeft = NULL;
     479           0 :         OTableWindow* pInitialRight = NULL;
     480             : 
     481             :         // Collect the names of all TabWins
     482           0 :         OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->begin();
     483           0 :         OJoinTableView::OTableWindowMap::const_iterator aEnd = m_pTableMap->end();
     484           0 :         for(;aIter != aEnd;++aIter)
     485             :         {
     486           0 :             m_pLeftTable->InsertEntry(aIter->first);
     487           0 :             m_pRightTable->InsertEntry(aIter->first);
     488             : 
     489           0 :             if (!pInitialLeft)
     490             :             {
     491           0 :                 pInitialLeft = aIter->second;
     492           0 :                 m_strCurrentLeft = aIter->first;
     493             :             }
     494           0 :             else if (!pInitialRight)
     495             :             {
     496           0 :                 pInitialRight = aIter->second;
     497           0 :                 m_strCurrentRight = aIter->first;
     498             :             }
     499             :         }
     500             : 
     501           0 :         if ( !pInitialRight )
     502             :         {
     503           0 :             pInitialRight = pInitialLeft;
     504           0 :             m_strCurrentRight = m_strCurrentLeft;
     505             :         }
     506             : 
     507             :         // The corresponding Defs for my Controls
     508           0 :         m_pRC_Tables->setWindowTables(pInitialLeft,pInitialRight);
     509             : 
     510             :         // The table selected in a ComboBox must not be available in the other
     511             : 
     512           0 :         if ( m_pTableMap->size() > 2 )
     513             :         {
     514           0 :             m_pLeftTable->RemoveEntry(m_strCurrentRight);
     515           0 :             m_pRightTable->RemoveEntry(m_strCurrentLeft);
     516             :         }
     517             : 
     518             :         // Select the first one on the left side and on the right side,
     519             :         // select the second one
     520           0 :         m_pLeftTable->SelectEntry(m_strCurrentLeft);
     521           0 :         m_pRightTable->SelectEntry(m_strCurrentRight);
     522             : 
     523           0 :         m_pLeftTable->GrabFocus();
     524           0 :     }
     525             : 
     526           0 :     IMPL_LINK( OTableListBoxControl, OnTableChanged, ListBox*, pListBox )
     527             :     {
     528           0 :         OUString strSelected(pListBox->GetSelectEntry());
     529           0 :         OTableWindow* pLeft     = NULL;
     530           0 :         OTableWindow* pRight    = NULL;
     531             : 
     532             :         // Special treatment: If there are only two tables, we need to switch the other one too when changing in a LB
     533           0 :         if ( m_pTableMap->size() == 2 )
     534             :         {
     535             :             ListBox* pOther;
     536           0 :             if (pListBox == m_pLeftTable)
     537           0 :                 pOther = m_pRightTable;
     538             :             else
     539           0 :                 pOther = m_pLeftTable;
     540           0 :             pOther->SelectEntryPos(1 - pOther->GetSelectEntryPos());
     541             : 
     542           0 :             OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->begin();
     543           0 :             OTableWindow* pFirst = aIter->second;
     544           0 :             ++aIter;
     545           0 :             OTableWindow* pSecond = aIter->second;
     546             : 
     547           0 :             if ( m_pLeftTable->GetSelectEntry() == pFirst->GetName() )
     548             :             {
     549           0 :                 pLeft   = pFirst;
     550           0 :                 pRight  = pSecond;
     551             :             }
     552             :             else
     553             :             {
     554           0 :                 pLeft   = pSecond;
     555           0 :                 pRight  = pFirst;
     556             :             }
     557             :         }
     558             :         else
     559             :         {
     560             :             // First we need the TableDef to the Table and with it the TabWin
     561           0 :             OJoinTableView::OTableWindowMap::const_iterator aFind = m_pTableMap->find(strSelected);
     562           0 :             OTableWindow* pLoop = NULL;
     563           0 :             if( aFind != m_pTableMap->end() )
     564           0 :                 pLoop = aFind->second;
     565             :             OSL_ENSURE(pLoop != NULL, "ORelationDialog::OnTableChanged: invalid ListBox entry!");
     566             :                 // We need to find strSelect, because we filled the ListBoxes with the table names with which we compare now
     567           0 :             if (pListBox == m_pLeftTable)
     568             :             {
     569             :                 // Insert the previously selected Entry on the left side on the right side
     570           0 :                 m_pRightTable->InsertEntry(m_strCurrentLeft);
     571             :                 // Remove the currently selected Entry
     572           0 :                 m_pRightTable->RemoveEntry(strSelected);
     573           0 :                 m_strCurrentLeft    = strSelected;
     574             : 
     575           0 :                 pLeft = pLoop;
     576             : 
     577           0 :                 OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->find(m_pRightTable->GetSelectEntry());
     578             :                 OSL_ENSURE( aIter != m_pTableMap->end(), "Invalid name");
     579           0 :                 if ( aIter != m_pTableMap->end() )
     580           0 :                     pRight = aIter->second;
     581             : 
     582           0 :                 m_pLeftTable->GrabFocus();
     583             :             }
     584             :             else
     585             :             {
     586             :                 // Insert the previously selected Entry on the right side on the left side
     587           0 :                 m_pLeftTable->InsertEntry(m_strCurrentRight);
     588             :                 // Remove the currently selected Entry
     589           0 :                 m_pLeftTable->RemoveEntry(strSelected);
     590           0 :                 m_strCurrentRight = strSelected;
     591             : 
     592           0 :                 pRight = pLoop;
     593           0 :                 OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->find(m_pLeftTable->GetSelectEntry());
     594             :                 OSL_ENSURE( aIter != m_pTableMap->end(), "Invalid name");
     595           0 :                 if ( aIter != m_pTableMap->end() )
     596           0 :                     pLeft = aIter->second;
     597             :             }
     598             :         }
     599             : 
     600           0 :         pListBox->GrabFocus();
     601             : 
     602           0 :         m_pRC_Tables->setWindowTables(pLeft,pRight);
     603             : 
     604           0 :         NotifyCellChange();
     605           0 :         return 0;
     606             :     }
     607             : 
     608           0 :     void OTableListBoxControl::NotifyCellChange()
     609             :     {
     610             :         // Enable/disable the OK button, depending on having a valid situation
     611           0 :         TTableConnectionData::value_type pConnData = m_pRC_Tables->getData();
     612           0 :         const OConnectionLineDataVec* pLines = pConnData->GetConnLineDataList();
     613           0 :         bool bValid = !pLines->empty();
     614           0 :         if (bValid)
     615             :         {
     616           0 :             OConnectionLineDataVec::const_iterator l(pLines->begin());
     617           0 :             const OConnectionLineDataVec::const_iterator le(pLines->end());
     618           0 :             for (; bValid && l!=le; ++l)
     619             :             {
     620           0 :                 bValid = ! ((*l)->GetSourceFieldName().isEmpty() || (*l)->GetDestFieldName().isEmpty());
     621             :             }
     622             :         }
     623           0 :         m_pParentDialog->setValid(bValid);
     624             : 
     625           0 :         ORelationControl::ops_type::iterator i (m_pRC_Tables->m_ops.begin());
     626           0 :         const ORelationControl::ops_type::const_iterator e (m_pRC_Tables->m_ops.end());
     627           0 :         m_pRC_Tables->DeactivateCell();
     628           0 :         for(; i != e; ++i)
     629             :         {
     630           0 :             switch(i->first)
     631             :             {
     632             :             case ORelationControl::DELETE:
     633           0 :                 m_pRC_Tables->RowRemoved(i->second.first, i->second.second - i->second.first);
     634           0 :                 break;
     635             :             case ORelationControl::INSERT:
     636           0 :                 m_pRC_Tables->RowInserted(i->second.first, i->second.second - i->second.first);
     637           0 :                 break;
     638             :             case ORelationControl::MODIFY:
     639           0 :                 for(OConnectionLineDataVec::size_type j = i->second.first; j < i->second.second; ++j)
     640           0 :                     m_pRC_Tables->RowModified(j);
     641           0 :                 break;
     642             :             }
     643             :         }
     644           0 :         m_pRC_Tables->ActivateCell();
     645           0 :         m_pRC_Tables->m_ops.clear();
     646           0 :     }
     647             : 
     648           0 :     void fillEntryAndDisable(ListBox& _rListBox,const OUString& _sEntry)
     649             :     {
     650           0 :         _rListBox.InsertEntry(_sEntry);
     651           0 :         _rListBox.SelectEntryPos(0);
     652           0 :         _rListBox.Disable();
     653           0 :     }
     654             : 
     655           0 :     void OTableListBoxControl::fillAndDisable(const TTableConnectionData::value_type& _pConnectionData)
     656             :     {
     657           0 :         fillEntryAndDisable(*m_pLeftTable, _pConnectionData->getReferencingTable()->GetWinName());
     658           0 :         fillEntryAndDisable(*m_pRightTable, _pConnectionData->getReferencedTable()->GetWinName());
     659           0 :     }
     660             : 
     661           0 :     void OTableListBoxControl::Init(const TTableConnectionData::value_type& _pConnData)
     662             :     {
     663           0 :         m_pRC_Tables->Init(_pConnData);
     664           0 :     }
     665             : 
     666           0 :     void OTableListBoxControl::lateUIInit()
     667             :     {
     668           0 :         m_pRC_Tables->Show();
     669           0 :         lateInit();
     670           0 :     }
     671             : 
     672           0 :     void OTableListBoxControl::lateInit()
     673             :     {
     674           0 :         m_pRC_Tables->lateInit();
     675           0 :     }
     676             : 
     677           0 :     void OTableListBoxControl::Disable()
     678             :     {
     679           0 :         m_pLeftTable->Disable();
     680           0 :         m_pRightTable->Disable();
     681           0 :         m_pRC_Tables->Disable();
     682           0 :     }
     683             : 
     684           0 :     void OTableListBoxControl::Invalidate()
     685             :     {
     686           0 :         m_pLeftTable->Invalidate();
     687           0 :         m_pRightTable->Invalidate();
     688           0 :         m_pRC_Tables->Invalidate();
     689           0 :     }
     690             : 
     691           0 :     sal_Bool OTableListBoxControl::SaveModified()
     692             :     {
     693           0 :         return m_pRC_Tables->SaveModified();
     694             :     }
     695             : 
     696           0 :     TTableWindowData::value_type OTableListBoxControl::getReferencingTable()    const
     697             :     {
     698           0 :         return m_pRC_Tables->getData()->getReferencingTable();
     699             :     }
     700             : 
     701           0 :     void OTableListBoxControl::enableRelation(bool _bEnable)
     702             :     {
     703           0 :         if ( !_bEnable )
     704           0 :             m_pRC_Tables->PostUserEvent(LINK(m_pRC_Tables, ORelationControl, AsynchDeactivate));
     705           0 :         m_pRC_Tables->Enable(_bEnable);
     706             : 
     707           0 :     }
     708             : }
     709             : 
     710             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10