LCOV - code coverage report
Current view: top level - sw/source/ui/dbui - dbtree.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 247 0.0 %
Date: 2012-08-25 Functions: 0 28 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 564 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <sot/formats.hxx>
      31                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      32                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      33                 :            : #include <com/sun/star/sdbc/XDataSource.hpp>
      34                 :            : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      35                 :            : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      36                 :            : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      37                 :            : #include <com/sun/star/sdb/XDatabaseAccess.hpp>
      38                 :            : #include <com/sun/star/sdb/CommandType.hpp>
      39                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      40                 :            : #include <comphelper/processfactory.hxx>
      41                 :            : #include <com/sun/star/sdb/XCompletedConnection.hpp>
      42                 :            : #include <com/sun/star/container/XContainerListener.hpp>
      43                 :            : #include <com/sun/star/container/XContainer.hpp>
      44                 :            : #include <cppuhelper/implbase1.hxx>
      45                 :            : #include <svx/dbaexchange.hxx>
      46                 :            : 
      47                 :            : #include <dbmgr.hxx>
      48                 :            : #include <swmodule.hxx>
      49                 :            : #include <view.hxx>
      50                 :            : #include <wrtsh.hxx>
      51                 :            : #include <dbtree.hxx>
      52                 :            : #include <osl/mutex.hxx>
      53                 :            : #include <vcl/svapp.hxx>
      54                 :            : 
      55                 :            : #include <helpid.h>
      56                 :            : #include <utlui.hrc>
      57                 :            : 
      58                 :            : #include <unomid.h>
      59                 :            : 
      60                 :            : #include <boost/ptr_container/ptr_vector.hpp>
      61                 :            : 
      62                 :            : using namespace ::com::sun::star;
      63                 :            : using namespace ::com::sun::star::uno;
      64                 :            : using namespace ::com::sun::star::container;
      65                 :            : using namespace ::com::sun::star::lang;
      66                 :            : using namespace ::com::sun::star::sdb;
      67                 :            : using namespace ::com::sun::star::sdbc;
      68                 :            : using namespace ::com::sun::star::sdbcx;
      69                 :            : using namespace ::com::sun::star::task;
      70                 :            : using namespace ::com::sun::star::beans;
      71                 :            : 
      72                 :          0 : struct SwConnectionData
      73                 :            : {
      74                 :            :     ::rtl::OUString                sSourceName;
      75                 :            :     Reference<XConnection>  xConnection;
      76                 :            : };
      77                 :            : 
      78                 :            : typedef boost::ptr_vector<SwConnectionData> SwConnectionArr;
      79                 :            : 
      80                 :            : class SwDBTreeList_Impl : public cppu::WeakImplHelper1 < XContainerListener >
      81                 :            : {
      82                 :            :     Reference< XNameAccess > xDBContext;
      83                 :            :     SwConnectionArr aConnections;
      84                 :            :     SwWrtShell* pWrtSh;
      85                 :            : 
      86                 :            :     public:
      87                 :          0 :         SwDBTreeList_Impl(SwWrtShell* pShell) :
      88         [ #  # ]:          0 :             pWrtSh(pShell) {}
      89                 :            :         ~SwDBTreeList_Impl();
      90                 :            : 
      91                 :            :     virtual void SAL_CALL elementInserted( const ContainerEvent& Event ) throw (RuntimeException);
      92                 :            :     virtual void SAL_CALL elementRemoved( const ContainerEvent& Event ) throw (RuntimeException);
      93                 :            :     virtual void SAL_CALL elementReplaced( const ContainerEvent& Event ) throw (RuntimeException);
      94                 :            :     virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
      95                 :            : 
      96                 :            :     sal_Bool                        HasContext();
      97                 :          0 :     SwWrtShell*                 GetWrtShell() { return pWrtSh;}
      98                 :          0 :     void                        SetWrtShell(SwWrtShell& rSh) { pWrtSh = &rSh;}
      99                 :          0 :     Reference< XNameAccess >    GetContext() const {return xDBContext;}
     100                 :            :     Reference<XConnection>      GetConnection(const rtl::OUString& rSourceName);
     101                 :            : };
     102                 :            : 
     103         [ #  # ]:          0 : SwDBTreeList_Impl::~SwDBTreeList_Impl()
     104                 :            : {
     105         [ #  # ]:          0 :     Reference<XContainer> xContainer(xDBContext, UNO_QUERY);
     106         [ #  # ]:          0 :     if(xContainer.is())
     107                 :            :     {
     108                 :          0 :         m_refCount++;
     109                 :            :         //block necessary due to solaris' compiler behaviour to
     110                 :            :         //remove temporaries at the block's end
     111                 :            :         {
     112 [ #  # ][ #  # ]:          0 :             xContainer->removeContainerListener( this );
                 [ #  # ]
     113                 :            :         }
     114                 :          0 :         m_refCount--;
     115                 :          0 :     }
     116         [ #  # ]:          0 : }
     117                 :            : 
     118                 :          0 : void SwDBTreeList_Impl::elementInserted( const ContainerEvent&  ) throw (RuntimeException)
     119                 :            : {
     120                 :            :     // information not needed
     121                 :          0 : }
     122                 :            : 
     123                 :          0 : void SwDBTreeList_Impl::elementRemoved( const ContainerEvent& rEvent ) throw (RuntimeException)
     124                 :            : {
     125         [ #  # ]:          0 :     SolarMutexGuard aGuard;
     126                 :          0 :     ::rtl::OUString sSource;
     127                 :          0 :     rEvent.Accessor >>= sSource;
     128 [ #  # ][ #  # ]:          0 :     for(SwConnectionArr::iterator i = aConnections.begin(); i != aConnections.end(); ++i)
         [ #  # ][ #  # ]
                 [ #  # ]
     129                 :            :     {
     130 [ #  # ][ #  # ]:          0 :         if(i->sSourceName == sSource)
     131                 :            :         {
     132         [ #  # ]:          0 :             aConnections.erase(i);
     133                 :          0 :             break;
     134                 :            :         }
     135         [ #  # ]:          0 :     }
     136                 :          0 : }
     137                 :            : 
     138                 :          0 : void SwDBTreeList_Impl::disposing( const EventObject&  ) throw (RuntimeException)
     139                 :            : {
     140                 :          0 :     xDBContext = 0;
     141                 :          0 : }
     142                 :            : 
     143                 :          0 : void SwDBTreeList_Impl::elementReplaced( const ContainerEvent& rEvent ) throw (RuntimeException)
     144                 :            : {
     145                 :          0 :     elementRemoved(rEvent);
     146                 :          0 : }
     147                 :            : 
     148                 :          0 : sal_Bool SwDBTreeList_Impl::HasContext()
     149                 :            : {
     150         [ #  # ]:          0 :     if(!xDBContext.is())
     151                 :            :     {
     152         [ #  # ]:          0 :         Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
     153         [ #  # ]:          0 :         if( xMgr.is() )
     154                 :            :         {
     155         [ #  # ]:          0 :             Reference<XInterface> xInstance = xMgr->createInstance(
     156 [ #  # ][ #  # ]:          0 :                         C2U( "com.sun.star.sdb.DatabaseContext" ));
     157 [ #  # ][ #  # ]:          0 :             xDBContext = Reference<XNameAccess>(xInstance, UNO_QUERY) ;
     158         [ #  # ]:          0 :             Reference<XContainer> xContainer(xDBContext, UNO_QUERY);
     159         [ #  # ]:          0 :             if(xContainer.is())
     160 [ #  # ][ #  # ]:          0 :                 xContainer->addContainerListener( this );
                 [ #  # ]
     161                 :            :         }
     162                 :          0 :         OSL_ENSURE(xDBContext.is(), "com.sun.star.sdb.DataBaseContext: service not available");
     163                 :            :     }
     164                 :          0 :     return xDBContext.is();
     165                 :            : }
     166                 :            : 
     167                 :          0 : Reference<XConnection>  SwDBTreeList_Impl::GetConnection(const rtl::OUString& rSourceName)
     168                 :            : {
     169                 :          0 :     Reference<XConnection> xRet;
     170 [ #  # ][ #  # ]:          0 :     for(SwConnectionArr::const_iterator i = aConnections.begin(); i != aConnections.end(); ++i)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     171                 :            :     {
     172 [ #  # ][ #  # ]:          0 :         if(i->sSourceName == rSourceName)
     173                 :            :         {
     174 [ #  # ][ #  # ]:          0 :             xRet = i->xConnection;
     175                 :          0 :             break;
     176                 :            :         }
     177                 :            :     }
     178 [ #  # ][ #  # ]:          0 :     if(!xRet.is() && xDBContext.is() && pWrtSh)
         [ #  # ][ #  # ]
     179                 :            :     {
     180 [ #  # ][ #  # ]:          0 :         SwConnectionData* pPtr = new SwConnectionData();
     181                 :          0 :         pPtr->sSourceName = rSourceName;
     182 [ #  # ][ #  # ]:          0 :         xRet = pWrtSh->GetNewDBMgr()->RegisterConnection(pPtr->sSourceName);
                 [ #  # ]
     183         [ #  # ]:          0 :         aConnections.push_back(pPtr);
     184                 :            :     }
     185                 :          0 :     return xRet;
     186                 :            : }
     187                 :            : 
     188                 :          0 : SwDBTreeList::SwDBTreeList(Window *pParent, const ResId& rResId,
     189                 :            :                         SwWrtShell* pSh,
     190                 :            :                         const String& rDefDBName, const sal_Bool bShowCol):
     191                 :            : 
     192                 :            :     SvTreeListBox   (pParent, rResId),
     193                 :            :     aImageList      (SW_RES(ILIST_DB_DLG    )),
     194                 :            :     sDefDBName      (rDefDBName),
     195                 :            :     bInitialized    (sal_False),
     196                 :            :     bShowColumns    (bShowCol),
     197 [ #  # ][ #  # ]:          0 :     pImpl(new SwDBTreeList_Impl(pSh))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     198                 :            : {
     199         [ #  # ]:          0 :     SetHelpId(HID_DB_SELECTION_TLB);
     200                 :            : 
     201 [ #  # ][ #  # ]:          0 :     if (IsVisible())
     202         [ #  # ]:          0 :         InitTreeList();
     203                 :          0 : }
     204                 :            : 
     205 [ #  # ][ #  # ]:          0 : SwDBTreeList::~SwDBTreeList()
         [ #  # ][ #  # ]
                 [ #  # ]
     206                 :            : {
     207 [ #  # ][ #  # ]:          0 :     delete pImpl;
     208         [ #  # ]:          0 : }
     209                 :            : 
     210                 :          0 : void SwDBTreeList::InitTreeList()
     211                 :            : {
     212 [ #  # ][ #  # ]:          0 :     if(!pImpl->HasContext() && pImpl->GetWrtShell())
         [ #  # ][ #  # ]
     213                 :          0 :         return;
     214         [ #  # ]:          0 :     SetSelectionMode(SINGLE_SELECTION);
     215 [ #  # ][ #  # ]:          0 :     SetStyle(GetStyle()|WB_HASLINES|WB_CLIPCHILDREN|WB_HASBUTTONS|WB_HASBUTTONSATROOT|WB_HSCROLL);
     216                 :            :     // don't set font, so that the Control's font is being applied!
     217         [ #  # ]:          0 :     SetSpaceBetweenEntries(0);
     218                 :            :     SetNodeBitmaps( aImageList.GetImage(IMG_COLLAPSE),
     219 [ #  # ][ #  # ]:          0 :                     aImageList.GetImage(IMG_EXPAND  ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     220                 :            : 
     221         [ #  # ]:          0 :     SetDragDropMode(SV_DRAGDROP_APP_COPY);
     222                 :            : 
     223         [ #  # ]:          0 :     GetModel()->SetCompareHdl(LINK(this, SwDBTreeList, DBCompare));
     224                 :            : 
     225 [ #  # ][ #  # ]:          0 :     Sequence< ::rtl::OUString > aDBNames = pImpl->GetContext()->getElementNames();
                 [ #  # ]
     226                 :          0 :     const ::rtl::OUString* pDBNames = aDBNames.getConstArray();
     227                 :          0 :     long nCount = aDBNames.getLength();
     228                 :            : 
     229         [ #  # ]:          0 :     Image aImg = aImageList.GetImage(IMG_DB);
     230         [ #  # ]:          0 :     for(long i = 0; i < nCount; i++)
     231                 :            :     {
     232         [ #  # ]:          0 :         String sDBName(pDBNames[i]);
     233         [ #  # ]:          0 :         InsertEntry(sDBName, aImg, aImg, NULL, sal_True);
     234         [ #  # ]:          0 :     }
     235         [ #  # ]:          0 :     String sDBName(sDefDBName.GetToken(0, DB_DELIM));
     236         [ #  # ]:          0 :     String sTableName(sDefDBName.GetToken(1, DB_DELIM));
     237         [ #  # ]:          0 :     String sColumnName(sDefDBName.GetToken(2, DB_DELIM));
     238         [ #  # ]:          0 :     Select(sDBName, sTableName, sColumnName);
     239                 :            : 
     240 [ #  # ][ #  # ]:          0 :     bInitialized = sal_True;
         [ #  # ][ #  # ]
                 [ #  # ]
     241                 :            : }
     242                 :            : 
     243                 :          0 : void    SwDBTreeList::AddDataSource(const String& rSource)
     244                 :            : {
     245         [ #  # ]:          0 :     Image aImg = aImageList.GetImage(IMG_DB);
     246         [ #  # ]:          0 :     SvLBoxEntry* pEntry = InsertEntry(rSource, aImg, aImg, NULL, sal_True);
     247 [ #  # ][ #  # ]:          0 :     SvTreeListBox::Select(pEntry);
     248                 :          0 : }
     249                 :            : 
     250                 :          0 : void SwDBTreeList::ShowColumns(sal_Bool bShowCol)
     251                 :            : {
     252         [ #  # ]:          0 :     if (bShowCol != bShowColumns)
     253                 :            :     {
     254                 :          0 :         bShowColumns = bShowCol;
     255 [ #  # ][ #  # ]:          0 :         String sTableName, sColumnName;
     256         [ #  # ]:          0 :         String  sDBName(GetDBName(sTableName, sColumnName));
     257                 :            : 
     258         [ #  # ]:          0 :         SetUpdateMode(sal_False);
     259                 :            : 
     260         [ #  # ]:          0 :         SvLBoxEntry* pEntry = First();
     261                 :            : 
     262         [ #  # ]:          0 :         while (pEntry)
     263                 :            :         {
     264         [ #  # ]:          0 :             pEntry = (SvLBoxEntry*)GetRootLevelParent( pEntry );
     265         [ #  # ]:          0 :             Collapse(pEntry);       // zuklappen
     266                 :            : 
     267                 :            :             SvLBoxEntry* pChild;
     268 [ #  # ][ #  # ]:          0 :             while ((pChild = FirstChild(pEntry)) != 0L)
     269         [ #  # ]:          0 :                 GetModel()->Remove(pChild);
     270                 :            : 
     271         [ #  # ]:          0 :             pEntry = Next(pEntry);
     272                 :            :         }
     273                 :            : 
     274         [ #  # ]:          0 :         if (sDBName.Len())
     275                 :            :         {
     276         [ #  # ]:          0 :             Select(sDBName, sTableName, sColumnName);   // force RequestingChildren
     277                 :            :         }
     278 [ #  # ][ #  # ]:          0 :         SetUpdateMode(sal_True);
         [ #  # ][ #  # ]
     279                 :            :     }
     280                 :          0 : }
     281                 :            : 
     282                 :          0 : void  SwDBTreeList::RequestingChildren(SvLBoxEntry* pParent)
     283                 :            : {
     284         [ #  # ]:          0 :     if (!pParent->HasChildren())
     285                 :            :     {
     286         [ #  # ]:          0 :         if (GetParent(pParent)) // column names
     287                 :            :         {
     288                 :            :             try
     289                 :            :             {
     290                 :            : 
     291 [ #  # ][ #  # ]:          0 :                 String sSourceName = GetEntryText(GetParent(pParent));
     292         [ #  # ]:          0 :                 String sTableName = GetEntryText(pParent);
     293                 :            : 
     294 [ #  # ][ #  # ]:          0 :                 if(!pImpl->GetContext()->hasByName(sSourceName))
         [ #  # ][ #  # ]
                 [ #  # ]
     295                 :            :                     return;
     296 [ #  # ][ #  # ]:          0 :                 Reference<XConnection> xConnection = pImpl->GetConnection(sSourceName);
     297                 :          0 :                 sal_Bool bTable = pParent->GetUserData() == 0;
     298                 :          0 :                 Reference<XColumnsSupplier> xColsSupplier;
     299         [ #  # ]:          0 :                 if(bTable)
     300                 :            :                 {
     301         [ #  # ]:          0 :                     Reference<XTablesSupplier> xTSupplier = Reference<XTablesSupplier>(xConnection, UNO_QUERY);
     302         [ #  # ]:          0 :                     if(xTSupplier.is())
     303                 :            :                     {
     304 [ #  # ][ #  # ]:          0 :                         Reference<XNameAccess> xTbls = xTSupplier->getTables();
     305                 :            :                         OSL_ENSURE(xTbls->hasByName(sTableName), "table not available anymore?");
     306                 :            :                         try
     307                 :            :                         {
     308 [ #  # ][ #  # ]:          0 :                             Any aTable = xTbls->getByName(sTableName);
                 [ #  # ]
     309                 :          0 :                             Reference<XPropertySet> xPropSet;
     310         [ #  # ]:          0 :                             aTable >>= xPropSet;
     311 [ #  # ][ #  # ]:          0 :                             xColsSupplier = Reference<XColumnsSupplier>(xPropSet, UNO_QUERY);
                 [ #  # ]
     312                 :            :                         }
     313         [ #  # ]:          0 :                         catch (const Exception&)
     314                 :            :                         {
     315                 :          0 :                         }
     316                 :          0 :                     }
     317                 :            :                 }
     318                 :            :                 else
     319                 :            :                 {
     320         [ #  # ]:          0 :                     Reference<XQueriesSupplier> xQSupplier = Reference<XQueriesSupplier>(xConnection, UNO_QUERY);
     321         [ #  # ]:          0 :                     if(xQSupplier.is())
     322                 :            :                     {
     323 [ #  # ][ #  # ]:          0 :                         Reference<XNameAccess> xQueries = xQSupplier->getQueries();
     324                 :            :                         OSL_ENSURE(xQueries->hasByName(sTableName), "table not available anymore?");
     325                 :            :                         try
     326                 :            :                         {
     327 [ #  # ][ #  # ]:          0 :                             Any aQuery = xQueries->getByName(sTableName);
                 [ #  # ]
     328                 :          0 :                             Reference<XPropertySet> xPropSet;
     329         [ #  # ]:          0 :                             aQuery >>= xPropSet;
     330 [ #  # ][ #  # ]:          0 :                             xColsSupplier = Reference<XColumnsSupplier>(xPropSet, UNO_QUERY);
                 [ #  # ]
     331                 :            :                         }
     332         [ #  # ]:          0 :                         catch (const Exception&)
     333                 :            :                         {
     334                 :          0 :                         }
     335                 :          0 :                     }
     336                 :            :                 }
     337                 :            : 
     338         [ #  # ]:          0 :                 if(xColsSupplier.is())
     339                 :            :                 {
     340 [ #  # ][ #  # ]:          0 :                     Reference <XNameAccess> xCols = xColsSupplier->getColumns();
     341 [ #  # ][ #  # ]:          0 :                     Sequence< ::rtl::OUString> aColNames = xCols->getElementNames();
     342                 :          0 :                     const ::rtl::OUString* pColNames = aColNames.getConstArray();
     343                 :          0 :                     long nCount = aColNames.getLength();
     344         [ #  # ]:          0 :                     for (long i = 0; i < nCount; i++)
     345                 :            :                     {
     346         [ #  # ]:          0 :                         String sName = pColNames[i];
     347         [ #  # ]:          0 :                         InsertEntry(sName, pParent);
     348 [ #  # ][ #  # ]:          0 :                     }
     349 [ #  # ][ #  # ]:          0 :                 }
         [ #  # ][ #  # ]
                 [ #  # ]
     350                 :            :             }
     351                 :          0 :             catch (const Exception&)
     352                 :            :             {
     353                 :            :             }
     354                 :            :         }
     355                 :            :         else    // table names
     356                 :            :         {
     357                 :            :             try
     358                 :            :             {
     359         [ #  # ]:          0 :                 String sSourceName = GetEntryText(pParent);
     360 [ #  # ][ #  # ]:          0 :                 if(!pImpl->GetContext()->hasByName(sSourceName))
         [ #  # ][ #  # ]
                 [ #  # ]
     361                 :            :                     return;
     362 [ #  # ][ #  # ]:          0 :                 Reference<XConnection> xConnection = pImpl->GetConnection(sSourceName);
     363         [ #  # ]:          0 :                 if (xConnection.is())
     364                 :            :                 {
     365         [ #  # ]:          0 :                     Reference<XTablesSupplier> xTSupplier = Reference<XTablesSupplier>(xConnection, UNO_QUERY);
     366         [ #  # ]:          0 :                     if(xTSupplier.is())
     367                 :            :                     {
     368 [ #  # ][ #  # ]:          0 :                         Reference<XNameAccess> xTbls = xTSupplier->getTables();
     369 [ #  # ][ #  # ]:          0 :                         Sequence< ::rtl::OUString> aTblNames = xTbls->getElementNames();
     370         [ #  # ]:          0 :                         String sTableName;
     371                 :          0 :                         long nCount = aTblNames.getLength();
     372                 :          0 :                         const ::rtl::OUString* pTblNames = aTblNames.getConstArray();
     373         [ #  # ]:          0 :                         Image aImg = aImageList.GetImage(IMG_DBTABLE);
     374         [ #  # ]:          0 :                         for (long i = 0; i < nCount; i++)
     375                 :            :                         {
     376         [ #  # ]:          0 :                             sTableName = pTblNames[i];
     377         [ #  # ]:          0 :                             SvLBoxEntry* pTableEntry = InsertEntry(sTableName, aImg, aImg, pParent, bShowColumns);
     378                 :            :                             //to discriminate between queries and tables the user data of table entries is set
     379                 :          0 :                             pTableEntry->SetUserData((void*)0);
     380 [ #  # ][ #  # ]:          0 :                         }
                 [ #  # ]
     381                 :            :                     }
     382                 :            : 
     383         [ #  # ]:          0 :                     Reference<XQueriesSupplier> xQSupplier = Reference<XQueriesSupplier>(xConnection, UNO_QUERY);
     384         [ #  # ]:          0 :                     if(xQSupplier.is())
     385                 :            :                     {
     386 [ #  # ][ #  # ]:          0 :                         Reference<XNameAccess> xQueries = xQSupplier->getQueries();
     387 [ #  # ][ #  # ]:          0 :                         Sequence< ::rtl::OUString> aQueryNames = xQueries->getElementNames();
     388         [ #  # ]:          0 :                         String sQueryName;
     389                 :          0 :                         long nCount = aQueryNames.getLength();
     390                 :          0 :                         const ::rtl::OUString* pQueryNames = aQueryNames.getConstArray();
     391         [ #  # ]:          0 :                         Image aImg = aImageList.GetImage(IMG_DBQUERY);
     392         [ #  # ]:          0 :                         for (long i = 0; i < nCount; i++)
     393                 :            :                         {
     394         [ #  # ]:          0 :                             sQueryName = pQueryNames[i];
     395         [ #  # ]:          0 :                             SvLBoxEntry* pQueryEntry = InsertEntry(sQueryName, aImg, aImg, pParent, bShowColumns);
     396                 :          0 :                             pQueryEntry->SetUserData((void*)1);
     397 [ #  # ][ #  # ]:          0 :                         }
                 [ #  # ]
     398                 :          0 :                     }
     399 [ #  # ][ #  # ]:          0 :                 }
                 [ #  # ]
     400                 :            :             }
     401                 :          0 :             catch (const Exception&)
     402                 :            :             {
     403                 :            :             }
     404                 :            :         }
     405                 :            :     }
     406                 :            : }
     407                 :            : 
     408                 :          0 : IMPL_LINK( SwDBTreeList, DBCompare, SvSortData*, pData )
     409                 :            : {
     410                 :          0 :     SvLBoxEntry* pRight = (SvLBoxEntry*)(pData->pRight );
     411                 :            : 
     412 [ #  # ][ #  # ]:          0 :     if (GetParent(pRight) && GetParent(GetParent(pRight)))
                 [ #  # ]
     413                 :          0 :         return COMPARE_GREATER; // don't sort column names
     414                 :            : 
     415                 :          0 :     return DefaultCompare(pData);   // otherwise call base class
     416                 :            : }
     417                 :            : 
     418                 :          0 : String  SwDBTreeList::GetDBName(String& rTableName, String& rColumnName, sal_Bool* pbIsTable)
     419                 :            : {
     420                 :          0 :     String sDBName;
     421         [ #  # ]:          0 :     SvLBoxEntry* pEntry = FirstSelected();
     422                 :            : 
     423 [ #  # ][ #  # ]:          0 :     if (pEntry && GetParent(pEntry))
         [ #  # ][ #  # ]
     424                 :            :     {
     425 [ #  # ][ #  # ]:          0 :         if (GetParent(GetParent(pEntry)))
                 [ #  # ]
     426                 :            :         {
     427 [ #  # ][ #  # ]:          0 :             rColumnName = GetEntryText(pEntry);
                 [ #  # ]
     428         [ #  # ]:          0 :             pEntry = GetParent(pEntry); // column name was selected
     429                 :            :         }
     430 [ #  # ][ #  # ]:          0 :         sDBName = GetEntryText(GetParent(pEntry));
         [ #  # ][ #  # ]
     431         [ #  # ]:          0 :         if(pbIsTable)
     432                 :            :         {
     433                 :          0 :             *pbIsTable = pEntry->GetUserData() == 0;
     434                 :            :         }
     435 [ #  # ][ #  # ]:          0 :         rTableName = GetEntryText(pEntry);
                 [ #  # ]
     436                 :            :     }
     437                 :          0 :     return sDBName;
     438                 :            : }
     439                 :            : 
     440                 :            : /*------------------------------------------------------------------------
     441                 :            :  Description:   Format: database.table
     442                 :            : ------------------------------------------------------------------------*/
     443                 :          0 : void SwDBTreeList::Select(const String& rDBName, const String& rTableName, const String& rColumnName)
     444                 :            : {
     445                 :            :     SvLBoxEntry* pParent;
     446                 :            :     SvLBoxEntry* pChild;
     447                 :          0 :     sal_uInt16 nParent = 0;
     448                 :          0 :     sal_uInt16 nChild = 0;
     449                 :            : 
     450         [ #  # ]:          0 :     while ((pParent = GetEntry(nParent++)) != NULL)
     451                 :            :     {
     452 [ #  # ][ #  # ]:          0 :         if (rDBName == GetEntryText(pParent))
     453                 :            :         {
     454         [ #  # ]:          0 :             if (!pParent->HasChildren())
     455                 :          0 :                 RequestingChildren(pParent);
     456         [ #  # ]:          0 :             while ((pChild = GetEntry(pParent, nChild++)) != NULL)
     457                 :            :             {
     458 [ #  # ][ #  # ]:          0 :                 if (rTableName == GetEntryText(pChild))
     459                 :            :                 {
     460                 :          0 :                     pParent = pChild;
     461                 :            : 
     462 [ #  # ][ #  # ]:          0 :                     if (bShowColumns && rColumnName.Len())
                 [ #  # ]
     463                 :            :                     {
     464                 :          0 :                         nChild = 0;
     465                 :            : 
     466         [ #  # ]:          0 :                         if (!pParent->HasChildren())
     467                 :          0 :                             RequestingChildren(pParent);
     468                 :            : 
     469         [ #  # ]:          0 :                         while ((pChild = GetEntry(pParent, nChild++)) != NULL)
     470 [ #  # ][ #  # ]:          0 :                             if (rColumnName == GetEntryText(pChild))
     471                 :          0 :                                 break;
     472                 :            :                     }
     473         [ #  # ]:          0 :                     if (!pChild)
     474                 :          0 :                         pChild = pParent;
     475                 :            : 
     476                 :          0 :                     MakeVisible(pChild);
     477                 :          0 :                     SvTreeListBox::Select(pChild);
     478                 :          0 :                     return;
     479                 :            :                 }
     480                 :            :             }
     481                 :            :         }
     482                 :            :     }
     483                 :            : }
     484                 :            : 
     485                 :          0 : void SwDBTreeList::StartDrag( sal_Int8 /*nAction*/, const Point& /*rPosPixel*/ )
     486                 :            : {
     487 [ #  # ][ #  # ]:          0 :     String sTableName, sColumnName;
     488         [ #  # ]:          0 :     String  sDBName( GetDBName( sTableName, sColumnName ));
     489         [ #  # ]:          0 :     if( sDBName.Len() )
     490                 :            :     {
     491         [ #  # ]:          0 :         TransferDataContainer* pContainer = new TransferDataContainer;
     492 [ #  # ][ #  # ]:          0 :         ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xRef( pContainer );
     493         [ #  # ]:          0 :         if( sColumnName.Len() )
     494                 :            :         {
     495                 :            :             // drag database field
     496                 :            :             svx::OColumnTransferable aColTransfer(
     497                 :            :                             sDBName
     498                 :            :                             ,::rtl::OUString()
     499                 :            :                             , sdb::CommandType::TABLE
     500                 :            :                             ,sTableName
     501                 :            :                             , sColumnName
     502 [ #  # ][ #  # ]:          0 :                             ,(CTF_FIELD_DESCRIPTOR |CTF_COLUMN_DESCRIPTOR ));
         [ #  # ][ #  # ]
     503 [ #  # ][ #  # ]:          0 :             aColTransfer.addDataToContainer( pContainer );
     504                 :            :         }
     505                 :            : 
     506         [ #  # ]:          0 :         sDBName += '.';
     507         [ #  # ]:          0 :         sDBName += sTableName;
     508         [ #  # ]:          0 :         if( sColumnName.Len() )
     509                 :            :         {
     510         [ #  # ]:          0 :             sDBName += '.';
     511         [ #  # ]:          0 :             sDBName += sColumnName;
     512                 :            :         }
     513                 :            : 
     514         [ #  # ]:          0 :         pContainer->CopyString( FORMAT_STRING, sDBName );
     515                 :            :         pContainer->StartDrag( this, DND_ACTION_COPY | DND_ACTION_LINK,
     516 [ #  # ][ #  # ]:          0 :                                 Link() );
     517 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
     518                 :          0 : }
     519                 :            : 
     520                 :          0 : sal_Int8 SwDBTreeList::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
     521                 :            : {
     522                 :          0 :     return DND_ACTION_NONE;
     523                 :            : }
     524                 :            : 
     525                 :          0 : void SwDBTreeList::SetWrtShell(SwWrtShell& rSh)
     526                 :            : {
     527                 :          0 :     pImpl->SetWrtShell(rSh);
     528 [ #  # ][ #  # ]:          0 :     if (IsVisible() && !bInitialized)
                 [ #  # ]
     529                 :          0 :         InitTreeList();
     530                 :          0 : }
     531                 :            : 
     532                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10