LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/querydesign - QueryTableView.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 454 0.2 %
Date: 2013-07-09 Functions: 2 37 5.4 %
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             : 
      21             : #include "QueryTableView.hxx"
      22             : #include "TableFieldInfo.hxx"
      23             : #include "TableFieldDescription.hxx"
      24             : #include <tools/diagnose_ex.h>
      25             : #include <osl/diagnose.h>
      26             : #include "dbaccess_helpid.hrc"
      27             : #include "QTableWindow.hxx"
      28             : #include "QTableConnection.hxx"
      29             : #include "QTableConnectionData.hxx"
      30             : #include "QueryDesignView.hxx"
      31             : #include "querycontroller.hxx"
      32             : #include "QueryAddTabConnUndoAction.hxx"
      33             : #include "QueryTabWinShowUndoAct.hxx"
      34             : #include "browserids.hxx"
      35             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      36             : #include <com/sun/star/sdbc/XConnection.hpp>
      37             : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
      38             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      39             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      40             : #include "JAccess.hxx"
      41             : #include <com/sun/star/sdbcx/KeyType.hpp>
      42             : #include <com/sun/star/container/XIndexAccess.hpp>
      43             : #include <com/sun/star/beans/XPropertySet.hpp>
      44             : #include "dbustrings.hrc"
      45             : #include <connectivity/dbtools.hxx>
      46             : #include <comphelper/sequence.hxx>
      47             : #include "querydlg.hxx"
      48             : #include "JoinExchange.hxx"
      49             : #include <comphelper/extract.hxx>
      50             : #include "dbu_qry.hrc"
      51             : #include <vcl/msgbox.hxx>
      52             : #include "svtools/treelistentry.hxx"
      53             : 
      54             : using namespace dbaui;
      55             : using namespace ::com::sun::star::uno;
      56             : using namespace ::com::sun::star::sdbc;
      57             : using namespace ::com::sun::star::sdbcx;
      58             : using namespace ::com::sun::star::beans;
      59             : using namespace ::com::sun::star::container;
      60             : using namespace ::com::sun::star::accessibility;
      61             : 
      62             : //------------------------------------------------------------------------------
      63             : namespace
      64             : {
      65             :     // -----------------------------------------------------------------------------
      66           0 :     sal_Bool isColumnInKeyType(const Reference<XIndexAccess>& _rxKeys,const OUString& _rColumnName,sal_Int32 _nKeyType)
      67             :     {
      68           0 :         sal_Bool bReturn = sal_False;
      69           0 :         if(_rxKeys.is())
      70             :         {
      71           0 :             Reference<XColumnsSupplier> xColumnsSupplier;
      72             :             // search the one and only primary key
      73           0 :             const sal_Int32 nCount = _rxKeys->getCount();
      74           0 :             for(sal_Int32 i=0;i< nCount;++i)
      75             :             {
      76           0 :                 Reference<XPropertySet> xProp(_rxKeys->getByIndex(i),UNO_QUERY);
      77           0 :                 if(xProp.is())
      78             :                 {
      79           0 :                     sal_Int32 nKeyType = 0;
      80           0 :                     xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
      81           0 :                     if(_nKeyType == nKeyType)
      82             :                     {
      83           0 :                         xColumnsSupplier.set(xProp,UNO_QUERY);
      84           0 :                         if(xColumnsSupplier.is())
      85             :                         {
      86           0 :                             Reference<XNameAccess> xColumns = xColumnsSupplier->getColumns();
      87           0 :                             if(xColumns.is() && xColumns->hasByName(_rColumnName))
      88             :                             {
      89           0 :                                 bReturn = sal_True;
      90           0 :                                 break;
      91           0 :                             }
      92             :                         }
      93             :                     }
      94             :                 }
      95           0 :             }
      96             :         }
      97           0 :         return bReturn;
      98             :     }
      99             :     // -----------------------------------------------------------------------------
     100             :     /** appends a new TabAdd Undo action at controller
     101             :         @param  _pView          the view which we use
     102             :         @param  _pUndoAction    the undo action which should be added
     103             :         @param  _pConnection    the connection for which the undo action should be appended
     104             :         @param  _bOwner         is the undo action the owner
     105             :     */
     106             :     // -----------------------------------------------------------------------------
     107           0 :     void addUndoAction( OQueryTableView* _pView,
     108             :                         OQueryTabConnUndoAction* _pUndoAction,
     109             :                         OQueryTableConnection* _pConnection,
     110             :                         sal_Bool _bOwner = sal_False)
     111             :     {
     112           0 :         _pUndoAction->SetOwnership(_bOwner);
     113           0 :         _pUndoAction->SetConnection(_pConnection);
     114           0 :         _pView->getDesignView()->getController().addUndoActionAndInvalidate(_pUndoAction);
     115           0 :     }
     116             :     // -----------------------------------------------------------------------------
     117             :     /** openJoinDialog opens the join dialog with this connection data
     118             :         @param  _pView              the view which we use
     119             :         @param  _pConnectionData    the connection data
     120             : 
     121             :         @return true when OK was pressed otherwise false
     122             :     */
     123           0 :     sal_Bool openJoinDialog(OQueryTableView* _pView,const TTableConnectionData::value_type& _pConnectionData,sal_Bool _bSelectableTables)
     124             :     {
     125           0 :         OQueryTableConnectionData* pData = static_cast< OQueryTableConnectionData*>(_pConnectionData.get());
     126             : 
     127           0 :         DlgQryJoin aDlg(_pView,_pConnectionData,_pView->GetTabWinMap(),_pView->getDesignView()->getController().getConnection(),_bSelectableTables);
     128           0 :         sal_Bool bOk = aDlg.Execute() == RET_OK;
     129           0 :         if( bOk )
     130             :         {
     131           0 :             pData->SetJoinType(aDlg.GetJoinType());
     132           0 :             _pView->getDesignView()->getController().setModified(sal_True);
     133             :         }
     134             : 
     135           0 :         return bOk;
     136             :     }
     137             :     // -----------------------------------------------------------------------------
     138             :     /** connectionModified adds an undo action for the modified connection and forces an redraw
     139             :         @param  _pView              the view which we use
     140             :         @param  _pConnection    the connection which was modified
     141             :         @param  _bAddUndo       true when an undo action should be appended
     142             :     */
     143           0 :     void connectionModified(OQueryTableView* _pView,
     144             :                             OTableConnection* _pConnection,
     145             :                             sal_Bool _bAddUndo)
     146             :     {
     147             :         OSL_ENSURE(_pConnection,"Invalid connection!");
     148           0 :         _pConnection->UpdateLineList();
     149             : 
     150             :         // add an undo action
     151           0 :         if ( _bAddUndo )
     152             :             addUndoAction(  _pView,
     153           0 :                             new OQueryAddTabConnUndoAction(_pView),
     154           0 :                             static_cast< OQueryTableConnection*>(_pConnection));
     155             :         // redraw
     156           0 :         _pConnection->RecalcLines();
     157             :         // force an invalidation of the bounding rectangle
     158           0 :         _pConnection->InvalidateConnection();
     159             : 
     160           0 :         _pView->Invalidate(INVALIDATE_NOCHILDREN);
     161           0 :     }
     162             :     // -----------------------------------------------------------------------------
     163           0 :     void addConnections(OQueryTableView* _pView,
     164             :                         const OQueryTableWindow& _rSource,
     165             :                         const OQueryTableWindow& _rDest,
     166             :                         const Reference<XNameAccess>& _rxSourceForeignKeyColumns)
     167             :     {
     168           0 :         if ( _rSource.GetData()->isQuery() || _rDest.GetData()->isQuery() )
     169             :             // nothing to do if one of both denotes a query
     170           0 :             return;
     171             : 
     172             :         // we found a table in our view where we can insert some connections
     173             :         // the key columns have a property called RelatedColumn
     174             :         // OQueryTableConnectionData aufbauen
     175           0 :         OQueryTableConnectionData* pNewConnData = new OQueryTableConnectionData( _rSource.GetData(), _rDest.GetData() );
     176           0 :         TTableConnectionData::value_type aNewConnData(pNewConnData);
     177             : 
     178           0 :         Reference<XIndexAccess> xReferencedKeys( _rDest.GetData()->getKeys());
     179           0 :         OUString sRelatedColumn;
     180             : 
     181             :         // iterate through all foreignkey columns to create the connections
     182           0 :         Sequence< OUString> aElements(_rxSourceForeignKeyColumns->getElementNames());
     183           0 :         const OUString* pIter = aElements.getConstArray();
     184           0 :         const OUString* pEnd   = pIter + aElements.getLength();
     185           0 :         for(sal_Int32 i=0;pIter != pEnd;++pIter,++i)
     186             :         {
     187           0 :             Reference<XPropertySet> xColumn;
     188           0 :             if ( !( _rxSourceForeignKeyColumns->getByName(*pIter) >>= xColumn ) )
     189             :             {
     190             :                 OSL_FAIL( "addConnections: invalid foreign key column!" );
     191           0 :                 continue;
     192             :             }
     193             : 
     194           0 :             pNewConnData->SetFieldType(JTCS_FROM,TAB_NORMAL_FIELD);
     195             : 
     196           0 :             xColumn->getPropertyValue(PROPERTY_RELATEDCOLUMN) >>= sRelatedColumn;
     197           0 :             pNewConnData->SetFieldType(JTCS_TO,isColumnInKeyType(xReferencedKeys,sRelatedColumn,KeyType::PRIMARY) ? TAB_PRIMARY_FIELD : TAB_NORMAL_FIELD);
     198             : 
     199             :             {
     200           0 :                 Sequence< sal_Int16> aFind(::comphelper::findValue(_rSource.GetOriginalColumns()->getElementNames(),*pIter,sal_True));
     201           0 :                 if(aFind.getLength())
     202           0 :                     pNewConnData->SetFieldIndex(JTCS_FROM,aFind[0]+1);
     203             :                 else
     204           0 :                     OSL_FAIL("Column not found!");
     205             :             }
     206             :             // get the position inside the tabe
     207           0 :             Reference<XNameAccess> xRefColumns = _rDest.GetOriginalColumns();
     208           0 :             if(xRefColumns.is())
     209             :             {
     210           0 :                 Sequence< sal_Int16> aFind(::comphelper::findValue(xRefColumns->getElementNames(),sRelatedColumn,sal_True));
     211           0 :                 if(aFind.getLength())
     212           0 :                     pNewConnData->SetFieldIndex(JTCS_TO,aFind[0]+1);
     213             :                 else
     214           0 :                     OSL_FAIL("Column not found!");
     215             :             }
     216           0 :             pNewConnData->AppendConnLine(*pIter,sRelatedColumn);
     217             : 
     218             :             // now add the Conn itself
     219           0 :             OQueryTableConnection aNewConn(_pView, aNewConnData);
     220             :             // refering to the local variable is not important, as NotifyQueryTabConn creates a new copy
     221             :             // to add me (if not existent)
     222           0 :             _pView->NotifyTabConnection(aNewConn, sal_False);
     223             :                 // don't create an Undo-Action for the new connection : the connection is
     224             :                 // covered by the Undo-Action for the tabwin, as the "Undo the insert" will
     225             :                 // automatically remove all connections adjacent to the win.
     226             :                 // (Because of this automatism we would have an ownerhsip ambiguity for
     227             :                 // the connection data if we would insert the conn-Undo-Action)
     228           0 :         }
     229             :     }
     230             : }
     231             : //==================================================================
     232             : // class OQueryTableView
     233             : //==================================================================
     234             : DBG_NAME(OQueryTableView)
     235             : //------------------------------------------------------------------------
     236           0 : OQueryTableView::OQueryTableView( Window* pParent,OQueryDesignView* pView)
     237           0 :     : OJoinTableView( pParent,pView)
     238             : {
     239             :     DBG_CTOR(OQueryTableView,NULL);
     240           0 :     SetHelpId(HID_CTL_QRYDGNTAB);
     241           0 : }
     242             : 
     243             : //------------------------------------------------------------------------
     244           0 : OQueryTableView::~OQueryTableView()
     245             : {
     246             :     DBG_DTOR(OQueryTableView,NULL);
     247           0 : }
     248             : 
     249             : //------------------------------------------------------------------------
     250           0 : sal_Int32 OQueryTableView::CountTableAlias(const String& rName, sal_Int32& rMax)
     251             : {
     252             :     DBG_CHKTHIS(OQueryTableView,NULL);
     253           0 :     sal_Int32 nRet = 0;
     254             : 
     255           0 :     OTableWindowMapIterator aIter = GetTabWinMap()->find(rName);
     256           0 :     while(aIter != GetTabWinMap()->end())
     257             :     {
     258           0 :         OUString aNewName = OUString(rName) + "_" + OUString::number(++nRet);
     259           0 :         aIter = GetTabWinMap()->find(aNewName);
     260           0 :     }
     261             : 
     262           0 :     rMax = nRet;
     263             : 
     264           0 :     return nRet;
     265             : }
     266             : //------------------------------------------------------------------------
     267           0 : void OQueryTableView::ReSync()
     268             : {
     269             :     DBG_CHKTHIS(OQueryTableView,NULL);
     270           0 :     TTableWindowData* pTabWinDataList = m_pView->getController().getTableWindowData();
     271             :     OSL_ENSURE((getTableConnections()->size()==0) && (GetTabWinMap()->size()==0),
     272             :         "before calling OQueryTableView::ReSync() please call ClearAll !");
     273             : 
     274             : 
     275             :     // I need a collection of all window names that cannot be created so that I do not initialize connections for them.
     276           0 :     ::std::vector<String> arrInvalidTables;
     277             : 
     278           0 :     TTableWindowData::reverse_iterator aIter = pTabWinDataList->rbegin();
     279             :     // Create the window and add it
     280             : 
     281           0 :     for(;aIter != pTabWinDataList->rend();++aIter)
     282             :     {
     283           0 :         OQueryTableWindowData* pData = static_cast<OQueryTableWindowData*>(aIter->get());
     284           0 :         OTableWindow* pTabWin = createWindow(*aIter);
     285             : 
     286             :         // I dont't use ShowTabWin as this adds the window data to the list of documents.
     287             :         // This would be bad as I am getting them from there.
     288             :         // Instead, I do it step by step
     289           0 :         if (!pTabWin->Init())
     290             :         {
     291             :             // The initialisation has gone wrong, this TabWin is not available, so
     292             :             // I must clean up the data and the document
     293           0 :             pTabWin->clearListBox();
     294           0 :             delete pTabWin;
     295           0 :             arrInvalidTables.push_back(pData->GetAliasName());
     296             : 
     297           0 :             pTabWinDataList->erase( ::std::remove(pTabWinDataList->begin(),pTabWinDataList->end(),*aIter) ,pTabWinDataList->end());
     298           0 :             continue;
     299             :         }
     300             : 
     301           0 :         (*GetTabWinMap())[pData->GetAliasName()] = pTabWin; // add at the beginning as I am going backwards through the DataList
     302             :         // Use the default if there is no position or size
     303           0 :         if (!pData->HasPosition() && !pData->HasSize())
     304           0 :             SetDefaultTabWinPosSize(pTabWin);
     305             : 
     306           0 :         pTabWin->Show();
     307             :     }
     308             : 
     309             :     // Add the connections
     310           0 :     TTableConnectionData* pTabConnDataList = m_pView->getController().getTableConnectionData();
     311           0 :     TTableConnectionData::reverse_iterator aConIter = pTabConnDataList->rbegin();
     312             : 
     313           0 :     for(;aConIter != pTabConnDataList->rend();++aConIter)
     314             :     {
     315           0 :         OQueryTableConnectionData* pTabConnData =  static_cast<OQueryTableConnectionData*>(aConIter->get());
     316             : 
     317             :         // do both tables for the connection exist ?
     318           0 :         String strTabExistenceTest = pTabConnData->getReferencingTable()->GetWinName();
     319           0 :         sal_Bool bInvalid = ::std::find(arrInvalidTables.begin(),arrInvalidTables.end(),strTabExistenceTest) != arrInvalidTables.end();
     320           0 :         strTabExistenceTest = pTabConnData->getReferencedTable()->GetWinName();
     321           0 :         bInvalid = bInvalid && ::std::find(arrInvalidTables.begin(),arrInvalidTables.end(),strTabExistenceTest) != arrInvalidTables.end();
     322             : 
     323           0 :         if (bInvalid)
     324             :         {
     325             :             // no -> bad luck, no connection
     326           0 :             pTabConnDataList->erase( ::std::remove(pTabConnDataList->begin(),pTabConnDataList->end(),*aConIter) ,pTabConnDataList->end());
     327           0 :             continue;
     328             :         }
     329             : 
     330             :         // adds a new connection to join view and notifies our accessible and invaldates the controller
     331           0 :         addConnection(new OQueryTableConnection(this, *aConIter));
     332           0 :     }
     333           0 : }
     334             : 
     335             : //------------------------------------------------------------------------
     336           0 : void OQueryTableView::ClearAll()
     337             : {
     338             :     DBG_CHKTHIS(OQueryTableView,NULL);
     339           0 :     OJoinTableView::ClearAll();
     340             : 
     341           0 :     SetUpdateMode(sal_True);
     342           0 :     m_pView->getController().setModified(sal_True);
     343           0 : }
     344             : 
     345             : // -----------------------------------------------------------------------------
     346           0 : OTableWindow* OQueryTableView::createWindow(const TTableWindowData::value_type& _pData)
     347             : {
     348           0 :     return new OQueryTableWindow(this,_pData);
     349             : }
     350             : 
     351             : //------------------------------------------------------------------------------
     352           0 : void OQueryTableView::NotifyTabConnection(const OQueryTableConnection& rNewConn, sal_Bool _bCreateUndoAction)
     353             : {
     354             :     DBG_CHKTHIS(OQueryTableView,NULL);
     355             :     // let's first check if I have the connection already
     356           0 :     OQueryTableConnection* pTabConn = NULL;
     357           0 :     const ::std::vector<OTableConnection*>* pConnections = getTableConnections();
     358           0 :     ::std::vector<OTableConnection*>::const_iterator aEnd = pConnections->end();
     359             :     ::std::vector<OTableConnection*>::const_iterator aIter = ::std::find(   pConnections->begin(),
     360             :                                                     aEnd,
     361             :                                                     static_cast<const OTableConnection*>(&rNewConn)
     362           0 :                                                     );
     363           0 :     if(aIter == aEnd )
     364             :     {
     365           0 :         aIter = pConnections->begin();
     366           0 :         for(;aIter != aEnd;++aIter)
     367             :         {
     368           0 :             if(*static_cast<OQueryTableConnection*>(*aIter) == rNewConn)
     369             :             {
     370           0 :                 pTabConn = static_cast<OQueryTableConnection*>(*aIter);
     371           0 :                 break;
     372             :             }
     373             :         }
     374             :     }
     375             :     else
     376           0 :         pTabConn = static_cast<OQueryTableConnection*>(*aIter);
     377             : 
     378             :     // no -> insert
     379           0 :     if (pTabConn == NULL)
     380             :     {
     381             :         // the new data ...
     382           0 :         OQueryTableConnectionData* pNewData = static_cast< OQueryTableConnectionData*>(rNewConn.GetData()->NewInstance());
     383           0 :         pNewData->CopyFrom(*rNewConn.GetData());
     384           0 :         TTableConnectionData::value_type aData(pNewData);
     385           0 :         OQueryTableConnection* pNewConn = new OQueryTableConnection(this, aData);
     386           0 :         GetConnection(pNewConn);
     387             : 
     388           0 :         connectionModified(this,pNewConn,_bCreateUndoAction);
     389             :     }
     390           0 : }
     391             : // -----------------------------------------------------------------------------
     392           0 : OTableWindowData* OQueryTableView::CreateImpl(const OUString& _rComposedName
     393             :                                              ,const OUString& _sTableName
     394             :                                              ,const OUString& _rWinName)
     395             : {
     396           0 :     return new OQueryTableWindowData( _rComposedName, _sTableName,_rWinName );
     397             : }
     398             : //------------------------------------------------------------------------------
     399           0 : void OQueryTableView::AddTabWin(const OUString& _rTableName, const OUString& _rAliasName, sal_Bool bNewTable)
     400             : {
     401             :     DBG_CHKTHIS(OQueryTableView,NULL);
     402             :     // this method has been inherited from the base class, linking back to the parent and which constructs
     403             :     // an Alias and which passes on to my other AddTabWin
     404             : 
     405             :     // pity _rTableName is fully qualified, OQueryDesignView expects a string which only
     406             :     // contains schema and tables but no catalog.
     407           0 :     Reference< XConnection> xConnection = m_pView->getController().getConnection();
     408           0 :     if(!xConnection.is())
     409           0 :         return;
     410             :     try
     411             :     {
     412           0 :         Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
     413           0 :         OUString sCatalog, sSchema, sTable;
     414             :         ::dbtools::qualifiedNameComponents(xMetaData,
     415             :                                     _rTableName,
     416             :                                     sCatalog,
     417             :                                     sSchema,
     418             :                                     sTable,
     419           0 :                                     ::dbtools::eInDataManipulation);
     420           0 :         OUString sRealName(sSchema);
     421           0 :         if (!sRealName.isEmpty())
     422           0 :             sRealName+= OUString('.');
     423           0 :         sRealName += sTable;
     424             : 
     425           0 :         AddTabWin(_rTableName, sRealName, _rAliasName, bNewTable);
     426             :     }
     427           0 :     catch(SQLException&)
     428             :     {
     429             :         OSL_FAIL("qualifiedNameComponents");
     430           0 :     }
     431             : }
     432             : // -----------------------------------------------------------------------------
     433             : // find the table which has a foreign key with this referencedTable name
     434           0 : Reference<XPropertySet> getKeyReferencedTo(const Reference<XIndexAccess>& _rxKeys,const OUString& _rReferencedTable)
     435             : {
     436           0 :     if(!_rxKeys.is())
     437           0 :         return Reference<XPropertySet>();
     438             : 
     439           0 :     if ( !_rxKeys.is() )
     440           0 :         return Reference<XPropertySet>();
     441             :     // search the one and only primary key
     442           0 :     const sal_Int32 nCount = _rxKeys->getCount();
     443           0 :     for(sal_Int32 i=0;i<nCount ;++i)
     444             :     {
     445           0 :         Reference<XPropertySet> xKey(_rxKeys->getByIndex(i),UNO_QUERY);
     446           0 :         if(xKey.is())
     447             :         {
     448           0 :             sal_Int32 nKeyType = 0;
     449           0 :             xKey->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
     450           0 :             if(KeyType::FOREIGN == nKeyType)
     451             :             {
     452           0 :                 OUString sReferencedTable;
     453           0 :                 xKey->getPropertyValue(PROPERTY_REFERENCEDTABLE) >>= sReferencedTable;
     454             :                 // TODO check case
     455           0 :                 if(sReferencedTable == _rReferencedTable)
     456           0 :                     return xKey;
     457             :             }
     458             :         }
     459           0 :     }
     460           0 :     return Reference<XPropertySet>();
     461             : }
     462             : //------------------------------------------------------------------------------
     463           0 : void OQueryTableView::AddTabWin(const OUString& _rComposedName, const OUString& _rTableName, const OUString& strAlias, sal_Bool bNewTable)
     464             : {
     465             :     DBG_CHKTHIS(OQueryTableView,NULL);
     466             :     OSL_ENSURE(!_rTableName.isEmpty() || !strAlias.isEmpty(), "OQueryTableView::AddTabWin : no tables or aliases !");
     467             :         // If the table is not set, then it is a dummy window, but at least the alias must be set
     468             : 
     469             :     // build a new data structure
     470             :     // first check if this already has its data
     471           0 :     sal_Bool bAppend = bNewTable;
     472           0 :     TTableWindowData::value_type pNewTabWinData;
     473           0 :     TTableWindowData* pWindowData = getDesignView()->getController().getTableWindowData();
     474           0 :     TTableWindowData::iterator aWinIter = pWindowData->begin();
     475           0 :     TTableWindowData::iterator aWinEnd = pWindowData->end();
     476           0 :     for(;aWinIter != aWinEnd;++aWinIter)
     477             :     {
     478           0 :         pNewTabWinData = *aWinIter;
     479           0 :         if (pNewTabWinData && pNewTabWinData->GetWinName() == strAlias && pNewTabWinData->GetComposedName() == _rComposedName && pNewTabWinData->GetTableName() == _rTableName)
     480           0 :             break;
     481             :     }
     482           0 :     if ( !bAppend )
     483           0 :         bAppend = ( aWinIter == aWinEnd );
     484           0 :     if ( bAppend )
     485           0 :         pNewTabWinData = createTableWindowData(_rComposedName, _rTableName, strAlias);
     486             :         // I do not need to add TabWinData to the DocShell list, ShowTabWin does that.
     487             : 
     488             :     // Create a new window
     489           0 :     OQueryTableWindow* pNewTabWin = static_cast<OQueryTableWindow*>(createWindow(pNewTabWinData));
     490             :     // No need to initialize, as that happens in ShowTabWin
     491             : 
     492             :     // New UndoAction
     493           0 :     OQueryTabWinShowUndoAct* pUndoAction = new OQueryTabWinShowUndoAct(this);
     494           0 :     pUndoAction->SetTabWin(pNewTabWin); // Window
     495           0 :     sal_Bool bSuccess = ShowTabWin(pNewTabWin, pUndoAction,bAppend);
     496           0 :     if(!bSuccess)
     497             :     {
     498             :         // reset table window
     499           0 :         pUndoAction->SetTabWin(NULL);
     500           0 :         pUndoAction->SetOwnership(sal_False);
     501             : 
     502           0 :         delete pUndoAction;
     503           0 :         return;
     504             :     }
     505             : 
     506             :     // Show the relations between the individual tables
     507           0 :     OTableWindowMap* pTabWins = GetTabWinMap();
     508           0 :     if(bNewTable && !pTabWins->empty() && !_rTableName.isEmpty())
     509             :     {
     510           0 :         modified();
     511           0 :         if ( m_pAccessible )
     512             :             m_pAccessible->notifyAccessibleEvent(   AccessibleEventId::CHILD,
     513             :                                                     Any(),
     514             :                                                     makeAny(pNewTabWin->GetAccessible())
     515           0 :                                                     );
     516             : 
     517             :         do {
     518             : 
     519           0 :         if ( pNewTabWin->GetData()->isQuery() )
     520           0 :             break;
     521             : 
     522             :         try
     523             :         {
     524             :             //////////////////////////////////////////////////////////////////////
     525             :             // find relations between the table an the tables already inserted
     526           0 :             Reference< XIndexAccess> xKeyIndex = pNewTabWin->GetData()->getKeys();
     527           0 :             if ( !xKeyIndex.is() )
     528           0 :                 break;
     529             : 
     530           0 :             Reference<XNameAccess> xFKeyColumns;
     531           0 :             OUString aReferencedTable;
     532           0 :             Reference<XColumnsSupplier> xColumnsSupplier;
     533             : 
     534           0 :             const sal_Int32 nKeyCount = xKeyIndex->getCount();
     535           0 :             for ( sal_Int32 i=0; i<nKeyCount ; ++i )
     536             :             {
     537           0 :                 Reference< XPropertySet > xProp( xKeyIndex->getByIndex(i), UNO_QUERY_THROW );
     538           0 :                 xColumnsSupplier.set( xProp, UNO_QUERY_THROW );
     539           0 :                 xFKeyColumns.set( xColumnsSupplier->getColumns(), UNO_QUERY_THROW );
     540             : 
     541           0 :                 sal_Int32 nKeyType = 0;
     542           0 :                 xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
     543             : 
     544           0 :                 switch ( nKeyType )
     545             :                 {
     546             :                 case KeyType::FOREIGN:
     547             :                 {   // our new table has a foreign key
     548             :                     // so look if the referenced table is already in our list
     549           0 :                     xProp->getPropertyValue(PROPERTY_REFERENCEDTABLE) >>= aReferencedTable;
     550             :                     OSL_ENSURE(!aReferencedTable.isEmpty(),"Foreign key without referencedTableName");
     551             : 
     552           0 :                     OTableWindowMap::const_iterator aIter = pTabWins->find(aReferencedTable);
     553           0 :                     OTableWindowMap::const_iterator aEnd  = pTabWins->end();
     554           0 :                     if(aIter == aEnd)
     555             :                     {
     556           0 :                         for(aIter = pTabWins->begin();aIter != aEnd;++aIter)
     557             :                         {
     558           0 :                             OQueryTableWindow* pTabWinTmp = static_cast<OQueryTableWindow*>(aIter->second);
     559             :                             OSL_ENSURE( pTabWinTmp,"TableWindow is null!" );
     560           0 :                             if ( pTabWinTmp != pNewTabWin && pTabWinTmp->GetComposedName() == aReferencedTable )
     561           0 :                                 break;
     562             :                         }
     563             :                     }
     564           0 :                     if ( aIter != aEnd && pNewTabWin != aIter->second )
     565           0 :                         addConnections( this, *pNewTabWin, *static_cast<OQueryTableWindow*>(aIter->second), xFKeyColumns );
     566             :                 }
     567           0 :                 break;
     568             : 
     569             :                 case KeyType::PRIMARY:
     570             :                 {
     571             :                     // we have a primary key so look in our list if there exsits a key which this is refered to
     572           0 :                     OTableWindowMap::const_iterator aIter = pTabWins->begin();
     573           0 :                     OTableWindowMap::const_iterator aEnd  = pTabWins->end();
     574           0 :                     for(;aIter != aEnd;++aIter)
     575             :                     {
     576           0 :                         OQueryTableWindow* pTabWinTmp = static_cast<OQueryTableWindow*>(aIter->second);
     577           0 :                         if ( pTabWinTmp == pNewTabWin )
     578           0 :                             continue;
     579             : 
     580           0 :                         if ( pTabWinTmp->GetData()->isQuery() )
     581           0 :                             continue;
     582             : 
     583             :                         OSL_ENSURE(pTabWinTmp,"TableWindow is null!");
     584           0 :                         Reference< XPropertySet > xFKKey = getKeyReferencedTo( pTabWinTmp->GetData()->getKeys(), pNewTabWin->GetComposedName() );
     585           0 :                         if ( !xFKKey.is() )
     586           0 :                             continue;
     587             : 
     588           0 :                         Reference<XColumnsSupplier> xFKColumnsSupplier( xFKKey, UNO_QUERY_THROW );
     589           0 :                         Reference< XNameAccess > xTColumns( xFKColumnsSupplier->getColumns(), UNO_QUERY_THROW );
     590           0 :                         addConnections( this, *pTabWinTmp, *pNewTabWin, xTColumns );
     591           0 :                     }
     592             :                 }
     593           0 :                 break;
     594             :                 }
     595           0 :             }
     596             :         }
     597           0 :         catch( const Exception& )
     598             :         {
     599             :             DBG_UNHANDLED_EXCEPTION();
     600             :         }
     601             : 
     602             :         } while ( false );
     603             :     }
     604             : 
     605             :     // My parent needs to be informed about the delete
     606           0 :     m_pView->getController().addUndoActionAndInvalidate( pUndoAction );
     607             : 
     608           0 :     if (bSuccess && m_lnkTabWinsChangeHandler.IsSet())
     609             :     {
     610           0 :         TabWinsChangeNotification aHint(TabWinsChangeNotification::AT_ADDED_WIN, pNewTabWin->GetAliasName());
     611           0 :         m_lnkTabWinsChangeHandler.Call(&aHint);
     612           0 :     }
     613             : }
     614             : // -----------------------------------------------------------------------------
     615             : // -----------------------------------------------------------------------------
     616           0 : void OQueryTableView::AddConnection(const OJoinExchangeData& jxdSource, const OJoinExchangeData& jxdDest)
     617             : {
     618             :     DBG_CHKTHIS(OQueryTableView,NULL);
     619           0 :     OQueryTableWindow* pSourceWin = static_cast< OQueryTableWindow*>(jxdSource.pListBox->GetTabWin());
     620           0 :     OQueryTableWindow* pDestWin = static_cast< OQueryTableWindow*>(jxdDest.pListBox->GetTabWin());
     621             : 
     622           0 :     String aSourceFieldName, aDestFieldName;
     623           0 :     aSourceFieldName    = jxdSource.pListBox->GetEntryText(jxdSource.pEntry);
     624           0 :     aDestFieldName      = jxdDest.pListBox->GetEntryText(jxdDest.pEntry);
     625             : 
     626           0 :     OTableConnection* pConn = GetTabConn(pSourceWin,pDestWin,true);
     627           0 :     if ( !pConn )
     628             :     {
     629             :         // new data object
     630           0 :         OQueryTableConnectionData* pNewConnectionData = new OQueryTableConnectionData(pSourceWin->GetData(), pDestWin->GetData());
     631           0 :         TTableConnectionData::value_type aNewConnectionData(pNewConnectionData);
     632             : 
     633             :         sal_uInt32          nSourceFieldIndex, nDestFieldIndex;
     634             :         ETableFieldType eSourceFieldType, eDestFieldType;
     635             : 
     636             :         // Get name/position/type of both affected fields ...
     637             :         // Source
     638             : 
     639           0 :         nSourceFieldIndex = jxdSource.pListBox->GetModel()->GetAbsPos(jxdSource.pEntry);
     640           0 :         eSourceFieldType = static_cast< OTableFieldInfo*>(jxdSource.pEntry->GetUserData())->GetKeyType();
     641             : 
     642             :         // Dest
     643             : 
     644           0 :         nDestFieldIndex = jxdDest.pListBox->GetModel()->GetAbsPos(jxdDest.pEntry);
     645           0 :         eDestFieldType = static_cast< OTableFieldInfo*>(jxdDest.pEntry->GetUserData())->GetKeyType();
     646             : 
     647             :         // ... and set them
     648           0 :         pNewConnectionData->SetFieldIndex(JTCS_FROM, nSourceFieldIndex);
     649           0 :         pNewConnectionData->SetFieldIndex(JTCS_TO, nDestFieldIndex);
     650             : 
     651           0 :         pNewConnectionData->SetFieldType(JTCS_FROM, eSourceFieldType);
     652           0 :         pNewConnectionData->SetFieldType(JTCS_TO, eDestFieldType);
     653             : 
     654           0 :         pNewConnectionData->AppendConnLine( aSourceFieldName,aDestFieldName );
     655             : 
     656           0 :         OQueryTableConnection aNewConnection(this, aNewConnectionData);
     657           0 :         NotifyTabConnection(aNewConnection);
     658             :         // As usual with NotifyTabConnection, using a local variable is fine because a copy is made
     659             :     }
     660             :     else
     661             :     {
     662             :         // the connection could point on the other side
     663           0 :         if(pConn->GetSourceWin() == pDestWin)
     664             :         {
     665           0 :             String aTmp(aSourceFieldName);
     666           0 :             aSourceFieldName = aDestFieldName;
     667           0 :             aDestFieldName = aTmp;
     668             :         }
     669             : 
     670           0 :         pConn->GetData()->AppendConnLine( aSourceFieldName,aDestFieldName );
     671             : 
     672           0 :         connectionModified(this,pConn,sal_False);
     673           0 :     }
     674           0 : }
     675             : // -----------------------------------------------------------------------------
     676           0 : void OQueryTableView::ConnDoubleClicked(OTableConnection* pConnection)
     677             : {
     678             :     DBG_CHKTHIS(OQueryTableView,NULL);
     679           0 :     if( openJoinDialog(this,pConnection->GetData(),sal_False) )
     680             :     {
     681           0 :         connectionModified(this,pConnection,sal_False);
     682           0 :         SelectConn( pConnection );
     683             :     }
     684           0 : }
     685             : // -----------------------------------------------------------------------------
     686           0 : void OQueryTableView::createNewConnection()
     687             : {
     688           0 :     TTableConnectionData::value_type pData(new OQueryTableConnectionData());
     689           0 :     if( openJoinDialog(this,pData,sal_True) )
     690             :     {
     691           0 :         OTableWindowMap* pMap = GetTabWinMap();
     692           0 :         OQueryTableWindow* pSourceWin   = static_cast< OQueryTableWindow*>((*pMap)[pData->getReferencingTable()->GetWinName()]);
     693           0 :         OQueryTableWindow* pDestWin     = static_cast< OQueryTableWindow*>((*pMap)[pData->getReferencedTable()->GetWinName()]);
     694             :         // first we have to look if the this connection already exists
     695           0 :         OTableConnection* pConn = GetTabConn(pSourceWin,pDestWin,true);
     696           0 :         sal_Bool bNew = sal_True;
     697           0 :         if ( pConn )
     698             :         {
     699           0 :             pConn->GetData()->CopyFrom( *pData );
     700           0 :             bNew = sal_False;
     701             :         }
     702             :         else
     703             :         {
     704             :             // create a new conenction and append it
     705           0 :             OQueryTableConnection* pQConn = new OQueryTableConnection(this, pData);
     706           0 :             GetConnection(pQConn);
     707           0 :             pConn = pQConn;
     708             :         }
     709           0 :         connectionModified(this,pConn,bNew);
     710           0 :         if ( !bNew && pConn == GetSelectedConn() ) // our connection was selected before so we have to reselect it
     711           0 :             SelectConn( pConn );
     712           0 :     }
     713           0 : }
     714             : //------------------------------------------------------------------------------
     715           0 : bool OQueryTableView::RemoveConnection( OTableConnection* _pConnection,sal_Bool /*_bDelete*/ )
     716             : {
     717             :     DBG_CHKTHIS(OQueryTableView,NULL);
     718             : 
     719             :     // we don't want that our connection will be deleted, we put it in the undo manager
     720           0 :     bool bRet = OJoinTableView::RemoveConnection( _pConnection,sal_False);
     721             : 
     722             :     // add undo action
     723             :     addUndoAction(  this,
     724           0 :                     new OQueryDelTabConnUndoAction(this),
     725             :                     static_cast< OQueryTableConnection*>(_pConnection),
     726           0 :                     sal_True);
     727           0 :     return bRet;
     728             : }
     729             : 
     730             : //------------------------------------------------------------------------------
     731           0 : void OQueryTableView::KeyInput( const KeyEvent& rEvt )
     732             : {
     733             :     DBG_CHKTHIS(OQueryTableView,NULL);
     734           0 :     OJoinTableView::KeyInput( rEvt );
     735           0 : }
     736             : 
     737             : //------------------------------------------------------------------------------
     738           0 : OQueryTableWindow* OQueryTableView::FindTable(const String& rAliasName)
     739             : {
     740             :     DBG_CHKTHIS(OQueryTableView,NULL);
     741             :     OSL_ENSURE(rAliasName.Len(), "OQueryTableView::FindTable : the  AliasName should not be empty !");
     742             :         // (it is harmless but does not make sense and indicates that there is probably an error in the caller)
     743           0 :     OTableWindowMap::const_iterator aIter = GetTabWinMap()->find(rAliasName);
     744           0 :     if(aIter != GetTabWinMap()->end())
     745           0 :         return static_cast<OQueryTableWindow*>(aIter->second);
     746           0 :     return NULL;
     747             : }
     748             : 
     749             : //------------------------------------------------------------------------------
     750           0 : sal_Bool OQueryTableView::FindTableFromField(const String& rFieldName, OTableFieldDescRef& rInfo, sal_uInt16& rCnt)
     751             : {
     752             :     DBG_CHKTHIS(OQueryTableView,NULL);
     753           0 :     rCnt = 0;
     754           0 :     OTableWindowMap::const_iterator aIter = GetTabWinMap()->begin();
     755           0 :     OTableWindowMap::const_iterator aEnd  = GetTabWinMap()->end();
     756           0 :     for(;aIter != aEnd;++aIter)
     757             :     {
     758           0 :         if(static_cast<OQueryTableWindow*>(aIter->second)->ExistsField(rFieldName, rInfo))
     759           0 :             ++rCnt;
     760             :     }
     761             : 
     762           0 :     return rCnt == 1;
     763             : }
     764             : 
     765             : //------------------------------------------------------------------------------
     766           0 : bool OQueryTableView::ContainsTabWin(const OTableWindow& rTabWin)
     767             : {
     768           0 :     OTableWindowMap* pTabWins = GetTabWinMap();
     769             :     OSL_ENSURE(pTabWins != NULL, "OQueryTableView::RemoveTabWin : Window should not be NULL !");
     770             : 
     771           0 :     OTableWindowMap::iterator aIter = pTabWins->begin();
     772           0 :     OTableWindowMap::iterator aEnd  = pTabWins->end();
     773             : 
     774           0 :     for ( ;aIter != aEnd ; ++aIter )
     775             :     {
     776           0 :         if ( aIter->second == &rTabWin )
     777             :         {
     778           0 :             return true;
     779             :         }
     780             :     }
     781             : 
     782           0 :     return false;
     783             : }
     784             : 
     785             : //------------------------------------------------------------------------------
     786           0 : void OQueryTableView::RemoveTabWin(OTableWindow* pTabWin)
     787             : {
     788             :     DBG_CHKTHIS(OQueryTableView,NULL);
     789             :     OSL_ENSURE(pTabWin != NULL, "OQueryTableView::RemoveTabWin : Window should not be NULL !");
     790             : 
     791           0 :     if(pTabWin && ContainsTabWin(*pTabWin)) // #i122589# check if registered before deleting
     792             :     {
     793             :         // I need my parent so it can be informed about the deletion
     794           0 :         OQueryDesignView* pParent = static_cast<OQueryDesignView*>(getDesignView());
     795             : 
     796           0 :         SfxUndoManager& rUndoMgr = m_pView->getController().GetUndoManager();
     797           0 :         rUndoMgr.EnterListAction( String( ModuleRes(STR_QUERY_UNDO_TABWINDELETE) ), String() );
     798             : 
     799             :         // add the Undo-Action
     800           0 :         OQueryTabWinDelUndoAct* pUndoAction = new OQueryTabWinDelUndoAct(this);
     801           0 :         pUndoAction->SetTabWin(static_cast< OQueryTableWindow*>(pTabWin));
     802             : 
     803             :         // and hide the window
     804           0 :         HideTabWin(static_cast< OQueryTableWindow*>(pTabWin), pUndoAction);
     805             : 
     806             :         // Undo Actions and delete the fields in SelectionBrowseBox
     807           0 :         pParent->TableDeleted( static_cast< OQueryTableWindowData*>(pTabWin->GetData().get())->GetAliasName() );
     808             : 
     809           0 :         m_pView->getController().addUndoActionAndInvalidate( pUndoAction );
     810           0 :         rUndoMgr.LeaveListAction();
     811             : 
     812           0 :         if (m_lnkTabWinsChangeHandler.IsSet())
     813             :         {
     814           0 :             TabWinsChangeNotification aHint(TabWinsChangeNotification::AT_REMOVED_WIN, static_cast< OQueryTableWindow*>(pTabWin)->GetAliasName());
     815           0 :             m_lnkTabWinsChangeHandler.Call(&aHint);
     816             :         }
     817             : 
     818           0 :         modified();
     819           0 :         if ( m_pAccessible )
     820             :             m_pAccessible->notifyAccessibleEvent(   AccessibleEventId::CHILD,
     821             :                                                     makeAny(pTabWin->GetAccessible()),
     822             :                                                     Any()
     823           0 :                                                     );
     824             :     }
     825           0 : }
     826             : 
     827             : //------------------------------------------------------------------------
     828           0 : void OQueryTableView::EnsureVisible(const OTableWindow* pWin)
     829             : {
     830             :     DBG_CHKTHIS(OQueryTableView,NULL);
     831             : 
     832           0 :     Invalidate(INVALIDATE_NOCHILDREN);
     833           0 :     OJoinTableView::EnsureVisible(pWin);
     834           0 : }
     835             : 
     836             : //------------------------------------------------------------------------
     837           0 : void OQueryTableView::GetConnection(OQueryTableConnection* pConn)
     838             : {
     839             :     DBG_CHKTHIS(OQueryTableView,NULL);
     840             :     // add to me and the document
     841             : 
     842           0 :     addConnection( pConn );
     843           0 : }
     844             : 
     845             : //------------------------------------------------------------------------
     846           0 : void OQueryTableView::DropConnection(OQueryTableConnection* pConn)
     847             : {
     848             :     DBG_CHKTHIS(OQueryTableView,NULL);
     849             :     // Pay attention to the selection
     850             :     // remove from me and the document
     851           0 :     RemoveConnection( pConn ,sal_False);
     852           0 : }
     853             : 
     854             : //------------------------------------------------------------------------
     855           0 : void OQueryTableView::HideTabWin( OQueryTableWindow* pTabWin, OQueryTabWinUndoAct* pUndoAction )
     856             : {
     857             :     DBG_CHKTHIS(OQueryTableView,NULL);
     858           0 :     OTableWindowMap* pTabWins = GetTabWinMap();
     859             :     OSL_ENSURE(pTabWins != NULL, "OQueryTableView::HideTabWin : have no TabWins !");
     860             : 
     861           0 :     if (pTabWin)
     862             :     {
     863             :         // Window
     864             :         // save the position in its data
     865           0 :         getDesignView()->SaveTabWinUIConfig(pTabWin);
     866             :         // (I need to go via the parent, as only the parent knows the position of the scrollbars)
     867             :         // and then out of the TabWins list and hide
     868           0 :         OTableWindowMap::iterator aIter = pTabWins->begin();
     869           0 :         OTableWindowMap::iterator aEnd  = pTabWins->end();
     870           0 :         for ( ;aIter != aEnd ; ++aIter )
     871           0 :             if ( aIter->second == pTabWin )
     872             :             {
     873           0 :                 pTabWins->erase( aIter );
     874           0 :                 break;
     875             :             }
     876             : 
     877           0 :         pTabWin->Hide();    // do not destroy it, as it is still in the undo list!!
     878             : 
     879             :         // the TabWin data must also be passed out of my responsibility
     880           0 :         TTableWindowData* pTabWinDataList = m_pView->getController().getTableWindowData();
     881           0 :         pTabWinDataList->erase( ::std::remove(pTabWinDataList->begin(),pTabWinDataList->end(),pTabWin->GetData()),pTabWinDataList->end());
     882             :             // The data should not be destroyed as TabWin itself - which is still alive - needs them
     883             :             // Either it goes back into my responsibility, (via ShowTabWin), then I add the data back,
     884             :             // or the Undo-Action, which currently has full responsibility for the window
     885             :             // and its data, gets destroyed and destroys both the window and its data
     886             : 
     887           0 :         if (m_pLastFocusTabWin == pTabWin)
     888           0 :             m_pLastFocusTabWin = NULL;
     889             : 
     890             :         // collect connections belonging to the window and pass to UndoAction
     891           0 :         sal_Int16 nCnt = 0;
     892           0 :         const ::std::vector<OTableConnection*>* pTabConList = getTableConnections();
     893           0 :         ::std::vector<OTableConnection*>::const_iterator aIter2 = pTabConList->begin();
     894           0 :         for(;aIter2 != pTabConList->end();)// the end may change
     895             :         {
     896           0 :             OQueryTableConnection* pTmpEntry = static_cast<OQueryTableConnection*>(*aIter2);
     897             :             OSL_ENSURE(pTmpEntry,"OQueryTableConnection is null!");
     898           0 :             if( pTmpEntry->GetAliasName(JTCS_FROM) == pTabWin->GetAliasName() ||
     899           0 :                 pTmpEntry->GetAliasName(JTCS_TO) == pTabWin->GetAliasName() )
     900             :             {
     901             :                 // add to undo list
     902           0 :                 pUndoAction->InsertConnection(pTmpEntry);
     903             : 
     904             :                 // call base class because we append an undo action
     905             :                 // but this time we are in a undo action list
     906           0 :                 OJoinTableView::RemoveConnection(pTmpEntry,sal_False);
     907           0 :                 aIter2 = pTabConList->begin();
     908           0 :                 ++nCnt;
     909             :             }
     910             :             else
     911           0 :                 ++aIter2;
     912             :         }
     913             : 
     914           0 :         if (nCnt)
     915           0 :             InvalidateConnections();
     916             : 
     917           0 :         m_pView->getController().InvalidateFeature(ID_BROWSER_ADDTABLE);
     918             : 
     919             :         // inform the UndoAction that the window and connections belong to it
     920           0 :         pUndoAction->SetOwnership(sal_True);
     921             : 
     922             :         // by doing so, we have modified the document
     923           0 :         m_pView->getController().setModified( sal_True );
     924           0 :         m_pView->getController().InvalidateFeature(SID_BROWSER_CLEAR_QUERY);
     925             :     }
     926           0 : }
     927             : 
     928             : //------------------------------------------------------------------------
     929           0 : sal_Bool OQueryTableView::ShowTabWin( OQueryTableWindow* pTabWin, OQueryTabWinUndoAct* pUndoAction,sal_Bool _bAppend )
     930             : {
     931             :     DBG_CHKTHIS(OQueryTableView,NULL);
     932             : 
     933           0 :     sal_Bool bSuccess = sal_False;
     934             : 
     935           0 :     if (pTabWin)
     936             :     {
     937           0 :         if (pTabWin->Init())
     938             :         {
     939           0 :             TTableWindowData::value_type pData = pTabWin->GetData();
     940             :             OSL_ENSURE(pData != 0, "OQueryTableView::ShowTabWin : TabWin has no data !");
     941             :             // If there is a position and size defined, we use them
     942           0 :             if (pData->HasPosition() && pData->HasSize())
     943             :             {
     944           0 :                 Size aSize(CalcZoom(pData->GetSize().Width()),CalcZoom(pData->GetSize().Height()));
     945           0 :                 pTabWin->SetPosSizePixel(pData->GetPosition(), aSize);
     946             :             }
     947             :             else
     948             :                 // else set a default position
     949           0 :                 SetDefaultTabWinPosSize(pTabWin);
     950             : 
     951             :             // Show the window and add to the list
     952           0 :             OUString sName = static_cast< OQueryTableWindowData*>(pData.get())->GetAliasName();
     953             :             OSL_ENSURE(GetTabWinMap()->find(sName) == GetTabWinMap()->end(),"Alias name already in list!");
     954           0 :             GetTabWinMap()->insert(OTableWindowMap::value_type(sName,pTabWin));
     955             : 
     956           0 :             pTabWin->Show();
     957             : 
     958           0 :             pTabWin->Update();
     959             :             // We must call Update() in order to show the connections in the window correctly. This sounds strange,
     960             :             // but the Listbox  has an internal Member which is initialized when the Listbox is first shown (after the Listbox
     961             :             // is filled in Init). This Member will eventually be needed for
     962             :             // GetEntryPos, and then in turn by the Connection, when its starting point to the window must be determined.
     963             : 
     964             :             // the Connections
     965           0 :             ::std::vector<OTableConnection*>* pTableCon = pUndoAction->GetTabConnList();
     966           0 :             ::std::vector<OTableConnection*>::iterator aIter = pTableCon->begin();
     967           0 :             ::std::vector<OTableConnection*>::iterator aEnd = pTableCon->end();
     968             : 
     969           0 :             for(;aIter != aEnd;++aIter)
     970           0 :                 addConnection(*aIter); // add all connections from the undo action
     971             : 
     972           0 :             pTableCon->clear();
     973             : 
     974             :             // and add the window's data to the list (of the document)
     975           0 :             if(_bAppend)
     976           0 :                 m_pView->getController().getTableWindowData()->push_back(pTabWin->GetData());
     977             : 
     978           0 :             m_pView->getController().InvalidateFeature(ID_BROWSER_ADDTABLE);
     979             : 
     980             :             // and inform the UndoAction  that the window belongs to me
     981           0 :             pUndoAction->SetOwnership(sal_False);
     982             : 
     983           0 :             bSuccess = sal_True;
     984             :         }
     985             :         else
     986             :         {
     987             :             // Initialisation failed
     988             :             // (for example when the Connection to the database is not available at the moment)
     989           0 :             pTabWin->clearListBox();
     990           0 :             delete pTabWin;
     991             :         }
     992             :     }
     993             : 
     994             :     // show that I have changed the document
     995           0 :     if(!m_pView->getController().isReadOnly())
     996           0 :         m_pView->getController().setModified( sal_True );
     997             : 
     998           0 :     m_pView->getController().InvalidateFeature(SID_BROWSER_CLEAR_QUERY);
     999             : 
    1000           0 :     return bSuccess;
    1001             : }
    1002             : //------------------------------------------------------------------------
    1003           0 : void OQueryTableView::InsertField(const OTableFieldDescRef& rInfo)
    1004             : {
    1005             :     DBG_CHKTHIS(OQueryTableView,NULL);
    1006             :     OSL_ENSURE(getDesignView() != NULL, "OQueryTableView::InsertField : has no Parent !");
    1007           0 :     static_cast<OQueryDesignView*>(getDesignView())->InsertField(rInfo);
    1008           0 : }
    1009             : //------------------------------------------------------------------------------
    1010           0 : sal_Bool OQueryTableView::ExistsAVisitedConn(const OQueryTableWindow* pFrom) const
    1011             : {
    1012             :     DBG_CHKTHIS(OQueryTableView,NULL);
    1013           0 :     const ::std::vector<OTableConnection*>* pList = getTableConnections();
    1014           0 :     if (pList)
    1015             :     {
    1016           0 :         ::std::vector<OTableConnection*>::const_iterator aIter = pList->begin();
    1017           0 :         ::std::vector<OTableConnection*>::const_iterator aEnd = pList->end();
    1018           0 :         for(;aIter != aEnd;++aIter)
    1019             :         {
    1020           0 :             OQueryTableConnection* pTemp = static_cast<OQueryTableConnection*>(*aIter);
    1021           0 :             if (pTemp->IsVisited() &&
    1022           0 :                 (pFrom == static_cast< OQueryTableWindow*>(pTemp->GetSourceWin()) || pFrom == static_cast< OQueryTableWindow*>(pTemp->GetDestWin())))
    1023           0 :                 return pTemp != NULL;
    1024             :         }
    1025             :     }
    1026             : 
    1027           0 :     return sal_False;
    1028             : }
    1029             : // -----------------------------------------------------------------------------
    1030           0 : void OQueryTableView::onNoColumns_throw()
    1031             : {
    1032           0 :     String sError( ModuleRes( STR_STATEMENT_WITHOUT_RESULT_SET ) );
    1033           0 :     ::dbtools::throwSQLException( sError, ::dbtools::SQL_GENERAL_ERROR, NULL );
    1034           0 : }
    1035             : //------------------------------------------------------------------------------
    1036           0 : bool OQueryTableView::supressCrossNaturalJoin(const TTableConnectionData::value_type& _pData) const
    1037             : {
    1038           0 :     OQueryTableConnectionData* pQueryData = static_cast<OQueryTableConnectionData*>(_pData.get());
    1039           0 :     return pQueryData && (pQueryData->GetJoinType() == CROSS_JOIN);
    1040          12 : }
    1041             : // -----------------------------------------------------------------------------
    1042             : 
    1043             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10