LCOV - code coverage report
Current view: top level - dbaccess/source/ui/browser - dsbrowserDnD.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 16 115 13.9 %
Date: 2014-04-11 Functions: 1 11 9.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "dbexchange.hxx"
      21             : #include "dbtreelistbox.hxx"
      22             : #include "dbtreemodel.hxx"
      23             : #include "dbtreeview.hxx"
      24             : #include "dbu_brw.hrc"
      25             : #include "dbustrings.hrc"
      26             : #include "QEnumTypes.hxx"
      27             : #include "UITools.hxx"
      28             : #include "unodatbr.hxx"
      29             : 
      30             : #include <com/sun/star/frame/XStorable.hpp>
      31             : #include <com/sun/star/sdb/CommandType.hpp>
      32             : #include <com/sun/star/sdbc/XConnection.hpp>
      33             : 
      34             : #include <connectivity/dbexception.hxx>
      35             : #include <connectivity/dbtools.hxx>
      36             : #include <cppuhelper/exc_hlp.hxx>
      37             : #include <svx/dataaccessdescriptor.hxx>
      38             : #include <tools/diagnose_ex.h>
      39             : #include <osl/diagnose.h>
      40             : #include "svtools/treelistentry.hxx"
      41             : 
      42             : #include <functional>
      43             : namespace dbaui
      44             : {
      45             : 
      46             :     using namespace ::com::sun::star::uno;
      47             :     using namespace ::com::sun::star::sdb;
      48             :     using namespace ::com::sun::star::sdbc;
      49             :     using namespace ::com::sun::star::sdbcx;
      50             :     using namespace ::com::sun::star::beans;
      51             :     using namespace ::com::sun::star::util;
      52             :     using namespace ::com::sun::star::frame;
      53             :     using namespace ::com::sun::star::container;
      54             :     using namespace ::com::sun::star::lang;
      55             :     using namespace ::com::sun::star::form;
      56             :     using namespace ::com::sun::star::io;
      57             :     using namespace ::com::sun::star::i18n;
      58             :     using namespace ::com::sun::star::task;
      59             :     using namespace ::com::sun::star::datatransfer;
      60             :     using namespace ::dbtools;
      61             :     using namespace ::svx;
      62             : 
      63           0 :     TransferableHelper* SbaTableQueryBrowser::implCopyObject( SvTreeListEntry* _pApplyTo, sal_Int32 _nCommandType, sal_Bool _bAllowConnection )
      64             :     {
      65             :         try
      66             :         {
      67           0 :             OUString aName = GetEntryText( _pApplyTo );
      68           0 :             OUString aDSName = getDataSourceAcessor( m_pTreeView->getListBox().GetRootLevelParent( _pApplyTo ) );
      69             : 
      70           0 :             ODataClipboard* pData = NULL;
      71           0 :             SharedConnection xConnection;
      72           0 :             if ( CommandType::QUERY != _nCommandType )
      73             :             {
      74           0 :                 if ( _bAllowConnection && !ensureConnection( _pApplyTo, xConnection) )
      75           0 :                     return NULL;
      76           0 :                 pData = new ODataClipboard(aDSName, _nCommandType, aName, xConnection, getNumberFormatter(), getORB());
      77             :             }
      78             :             else
      79           0 :                 pData = new ODataClipboard(aDSName, _nCommandType, aName, getNumberFormatter(), getORB());
      80             : 
      81             :             // the owner ship goes to ODataClipboards
      82           0 :             return pData;
      83             :         }
      84           0 :         catch(const SQLException& )
      85             :         {
      86           0 :             showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
      87             :         }
      88           0 :         catch( const Exception& )
      89             :         {
      90             :             DBG_UNHANDLED_EXCEPTION();
      91             :         }
      92           0 :         return NULL;
      93             :     }
      94           0 :     sal_Int8 SbaTableQueryBrowser::queryDrop( const AcceptDropEvent& _rEvt, const DataFlavorExVector& _rFlavors )
      95             :     {
      96             :         // check if we're a table or query container
      97           0 :         SvTreeListEntry* pHitEntry = m_pTreeView->getListBox().GetEntry( _rEvt.maPosPixel );
      98             : 
      99           0 :         if ( pHitEntry ) // no drop if no entry was hit ....
     100             :         {
     101             :             // it must be a container
     102           0 :             EntryType eEntryType = getEntryType( pHitEntry );
     103           0 :             SharedConnection xConnection;
     104           0 :             if ( eEntryType == etTableContainer && ensureConnection( pHitEntry, xConnection ) && xConnection.is() )
     105             :             {
     106           0 :                 Reference<XChild> xChild(xConnection,UNO_QUERY);
     107           0 :                 Reference<XStorable> xStore;
     108           0 :                 xStore = Reference<XStorable>( xChild.is() ? getDataSourceOrModel(xChild->getParent()) : Reference<XInterface>(),UNO_QUERY );
     109             :                 // check for the concrete type
     110           0 :                 if ( xStore.is() && !xStore->isReadonly() && ::std::find_if(_rFlavors.begin(),_rFlavors.end(),TAppSupportedSotFunctor(E_TABLE,sal_True)) != _rFlavors.end())
     111           0 :                     return DND_ACTION_COPY;
     112           0 :             }
     113             :         }
     114             : 
     115           0 :         return DND_ACTION_NONE;
     116             :     }
     117           0 :     sal_Int8 SbaTableQueryBrowser::executeDrop( const ExecuteDropEvent& _rEvt )
     118             :     {
     119           0 :         SvTreeListEntry* pHitEntry = m_pTreeView->getListBox().GetEntry( _rEvt.maPosPixel );
     120           0 :         EntryType eEntryType = getEntryType( pHitEntry );
     121           0 :         if (!isContainer(eEntryType))
     122             :         {
     123             :             OSL_FAIL("SbaTableQueryBrowser::executeDrop: what the hell did queryDrop do?");
     124             :                 // queryDrop shoud not have allowed us to reach this situation ....
     125           0 :             return DND_ACTION_NONE;
     126             :         }
     127             :         // a TransferableDataHelper for accessing the dropped data
     128           0 :         TransferableDataHelper aDroppedData(_rEvt.maDropEvent.Transferable);
     129             : 
     130             :         // reset the data of the previous async drop (if any)
     131           0 :         if ( m_nAsyncDrop )
     132           0 :             Application::RemoveUserEvent(m_nAsyncDrop);
     133             : 
     134           0 :         m_nAsyncDrop = 0;
     135           0 :         m_aAsyncDrop.aDroppedData.clear();
     136           0 :         m_aAsyncDrop.nType          = E_TABLE;
     137           0 :         m_aAsyncDrop.nAction        = _rEvt.mnAction;
     138           0 :         m_aAsyncDrop.bError         = sal_False;
     139           0 :         m_aAsyncDrop.bHtml          = sal_False;
     140           0 :         m_aAsyncDrop.pDroppedAt     = NULL;
     141           0 :         m_aAsyncDrop.aUrl           = OUString();
     142             : 
     143             :         // loop through the available formats and see what we can do ...
     144             :         // first we have to check if it is our own format, if not we have to copy the stream :-(
     145           0 :         if ( ODataAccessObjectTransferable::canExtractObjectDescriptor(aDroppedData.GetDataFlavorExVector()) )
     146             :         {
     147           0 :             m_aAsyncDrop.aDroppedData   = ODataAccessObjectTransferable::extractObjectDescriptor(aDroppedData);
     148           0 :             m_aAsyncDrop.pDroppedAt     = pHitEntry;
     149             : 
     150             :             // asyncron because we some dialogs and we aren't allowed to show them while in D&D
     151           0 :             m_nAsyncDrop = Application::PostUserEvent(LINK(this, SbaTableQueryBrowser, OnAsyncDrop));
     152           0 :             return DND_ACTION_COPY;
     153             :         }
     154             :         else
     155             :         {
     156           0 :             SharedConnection xDestConnection;
     157           0 :             if (  ensureConnection( pHitEntry, xDestConnection )
     158           0 :                && xDestConnection.is()
     159           0 :                && m_aTableCopyHelper.copyTagTable( aDroppedData, m_aAsyncDrop, xDestConnection )
     160             :                )
     161             :             {
     162           0 :                 m_aAsyncDrop.pDroppedAt = pHitEntry;
     163             : 
     164             :                 // asyncron because we some dialogs and we aren't allowed to show them while in D&D
     165           0 :                 m_nAsyncDrop = Application::PostUserEvent(LINK(this, SbaTableQueryBrowser, OnAsyncDrop));
     166           0 :                 return DND_ACTION_COPY;
     167           0 :             }
     168             :         }
     169             : 
     170           0 :         return DND_ACTION_NONE;
     171             :     }
     172             : 
     173           0 :     sal_Bool SbaTableQueryBrowser::requestDrag( sal_Int8 /*_nAction*/, const Point& _rPosPixel )
     174             :     {
     175             :         // get the affected list entry
     176             :         // ensure that the entry which the user clicked at is selected
     177           0 :         SvTreeListEntry* pHitEntry = m_pTreeView->getListBox().GetEntry( _rPosPixel );
     178           0 :         if (!pHitEntry)
     179             :             // no drag of no entry was hit ....
     180           0 :             return sal_False;
     181             : 
     182             :         // it must be a query/table
     183           0 :         EntryType eEntryType = getEntryType( pHitEntry );
     184           0 :         if (!isObject(eEntryType))
     185           0 :             return DND_ACTION_NONE;
     186             : 
     187           0 :         TransferableHelper* pTransfer = implCopyObject( pHitEntry, ( etTableOrView == eEntryType ) ? CommandType::TABLE : CommandType::QUERY);
     188           0 :         Reference< XTransferable> xEnsureDelete = pTransfer;
     189             : 
     190           0 :         if (pTransfer)
     191           0 :             pTransfer->StartDrag( &m_pTreeView->getListBox(), DND_ACTION_COPY );
     192             : 
     193           0 :         return NULL != pTransfer;
     194             :     }
     195           0 :     IMPL_LINK(SbaTableQueryBrowser, OnCopyEntry, void*, /*NOTINTERESIN*/)
     196             :     {
     197           0 :         SvTreeListEntry* pSelected = m_pTreeView->getListBox().FirstSelected();
     198           0 :         if( isEntryCopyAllowed( pSelected ) )
     199           0 :             copyEntry( pSelected );
     200           0 :         return 0;
     201             :     }
     202           0 :     sal_Bool SbaTableQueryBrowser::isEntryCopyAllowed(SvTreeListEntry* _pEntry) const
     203             :     {
     204           0 :         EntryType eType = getEntryType(_pEntry);
     205           0 :         return  ( eType == etTableOrView || eType == etQuery );
     206             :     }
     207           0 :     void SbaTableQueryBrowser::copyEntry(SvTreeListEntry* _pEntry)
     208             :     {
     209           0 :         TransferableHelper* pTransfer = NULL;
     210           0 :         Reference< XTransferable> aEnsureDelete;
     211           0 :         EntryType eType = getEntryType(_pEntry);
     212           0 :         pTransfer       = implCopyObject( _pEntry, eType == etQuery ? CommandType::QUERY : CommandType::TABLE);
     213           0 :         aEnsureDelete   = pTransfer;
     214           0 :         if (pTransfer)
     215           0 :             pTransfer->CopyToClipboard(getView());
     216           0 :     }
     217           0 :     IMPL_LINK( SbaTableQueryBrowser, OnAsyncDrop, void*, /*NOTINTERESTEDIN*/ )
     218             :     {
     219           0 :         m_nAsyncDrop = 0;
     220           0 :         SolarMutexGuard aSolarGuard;
     221           0 :         ::osl::MutexGuard aGuard( getMutex() );
     222             : 
     223           0 :         if ( m_aAsyncDrop.nType == E_TABLE )
     224             :         {
     225           0 :             SharedConnection xDestConnection;
     226           0 :             if ( ensureConnection( m_aAsyncDrop.pDroppedAt, xDestConnection ) && xDestConnection.is() )
     227             :             {
     228           0 :                 SvTreeListEntry* pDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent(m_aAsyncDrop.pDroppedAt);
     229           0 :                 m_aTableCopyHelper.asyncCopyTagTable( m_aAsyncDrop, getDataSourceAcessor( pDataSourceEntry ), xDestConnection );
     230           0 :             }
     231             :         }
     232             : 
     233           0 :         m_aAsyncDrop.aDroppedData.clear();
     234             : 
     235           0 :         return 0L;
     236             :     }
     237           1 :     void SbaTableQueryBrowser::clearTreeModel()
     238             :     {
     239           1 :         if (m_pTreeModel)
     240             :         {
     241             :             // clear the user data of the tree model
     242           1 :             SvTreeListEntry* pEntryLoop = m_pTreeModel->First();
     243           6 :             while (pEntryLoop)
     244             :             {
     245           4 :                 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pEntryLoop->GetUserData());
     246           4 :                 if(pData)
     247             :                 {
     248           4 :                     pEntryLoop->SetUserData(NULL);
     249           4 :                     Reference< XContainer > xContainer(pData->xContainer, UNO_QUERY);
     250           4 :                     if (xContainer.is())
     251           1 :                         xContainer->removeContainerListener(this);
     252             : 
     253           4 :                     if ( pData->xConnection.is() )
     254             :                     {
     255             :                         OSL_ENSURE( impl_isDataSourceEntry( pEntryLoop ), "SbaTableQueryBrowser::clearTreeModel: no data source entry, but a connection?" );
     256             :                         // connections are to be stored *only* at the data source entries
     257           1 :                         impl_releaseConnection( pData->xConnection );
     258             :                     }
     259             : 
     260           4 :                     delete pData;
     261             :                 }
     262           4 :                 pEntryLoop = m_pTreeModel->Next(pEntryLoop);
     263             :             }
     264             :         }
     265           1 :         m_pCurrentlyDisplayed = NULL;
     266           1 :     }
     267             : }   // namespace dbaui
     268             : 
     269             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10