LCOV - code coverage report
Current view: top level - dbaccess/source/ui/querydesign - JoinController.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 198 0.0 %
Date: 2014-04-14 Functions: 0 30 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sfx2/sfxsids.hrc>
      21             : #include "dbu_qry.hrc"
      22             : #include "browserids.hxx"
      23             : #include <comphelper/types.hxx>
      24             : #include "dbustrings.hrc"
      25             : #include <connectivity/dbtools.hxx>
      26             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      27             : #include <comphelper/extract.hxx>
      28             : #include <com/sun/star/container/XChild.hpp>
      29             : #include <com/sun/star/container/XNameContainer.hpp>
      30             : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
      31             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      32             : #include <com/sun/star/sdbcx/KeyType.hpp>
      33             : #include <com/sun/star/sdbcx/XDrop.hpp>
      34             : #include <com/sun/star/sdbcx/XAlterTable.hpp>
      35             : #include <com/sun/star/sdbcx/XAppend.hpp>
      36             : #include <com/sun/star/sdb/SQLContext.hpp>
      37             : #include <com/sun/star/sdbc/SQLWarning.hpp>
      38             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      39             : #include <com/sun/star/sdbc/XRow.hpp>
      40             : #include <connectivity/dbexception.hxx>
      41             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      42             : #include <comphelper/streamsection.hxx>
      43             : #include <comphelper/seqstream.hxx>
      44             : #include <com/sun/star/io/XActiveDataSource.hpp>
      45             : #include <com/sun/star/io/XActiveDataSink.hpp>
      46             : #include "sqlmessage.hxx"
      47             : #include "JoinController.hxx"
      48             : #include <vcl/msgbox.hxx>
      49             : #include "TableWindowData.hxx"
      50             : #include "TableWindow.hxx"
      51             : #include "TableConnectionData.hxx"
      52             : #include "adtabdlg.hxx"
      53             : #include <vcl/waitobj.hxx>
      54             : #include <vcl/svapp.hxx>
      55             : #include <osl/mutex.hxx>
      56             : #include "UITools.hxx"
      57             : #include <osl/diagnose.h>
      58             : 
      59             : #include <boost/optional.hpp>
      60             : #include <boost/scoped_ptr.hpp>
      61             : 
      62             : using namespace ::com::sun::star::uno;
      63             : using namespace ::com::sun::star::io;
      64             : using namespace ::com::sun::star::beans;
      65             : using namespace ::com::sun::star::frame;
      66             : using namespace ::com::sun::star::util;
      67             : using namespace ::com::sun::star::lang;
      68             : using namespace ::com::sun::star::container;
      69             : using namespace ::com::sun::star::sdbcx;
      70             : using namespace ::com::sun::star::sdbc;
      71             : using namespace ::com::sun::star::sdb;
      72             : using namespace ::com::sun::star::ui::dialogs;
      73             : using namespace ::dbtools;
      74             : using namespace ::comphelper;
      75             : 
      76             : namespace dbaui
      77             : {
      78             : 
      79             : // AddTableDialogContext
      80             : class AddTableDialogContext : public IAddTableDialogContext
      81             : {
      82             :     OJoinController& m_rController;
      83             : 
      84             : public:
      85           0 :     AddTableDialogContext( OJoinController& _rController )
      86           0 :         :m_rController( _rController )
      87             :     {
      88           0 :     }
      89             : 
      90           0 :     virtual ~AddTableDialogContext() {}
      91             : 
      92             :     // IAddTableDialogContext
      93             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
      94             :                     getConnection() const SAL_OVERRIDE;
      95             :     virtual bool    allowViews() const SAL_OVERRIDE;
      96             :     virtual bool    allowQueries() const SAL_OVERRIDE;
      97             :     virtual bool    allowAddition() const SAL_OVERRIDE;
      98             :     virtual void    addTableWindow( const OUString& _rQualifiedTableName, const OUString& _rAliasName ) SAL_OVERRIDE;
      99             :     virtual void    onWindowClosing( const Window* _pWindow ) SAL_OVERRIDE;
     100             : 
     101             : private:
     102             :     OJoinTableView* getTableView() const;
     103             : };
     104             : 
     105           0 : Reference< XConnection > AddTableDialogContext::getConnection() const
     106             : {
     107           0 :     return m_rController.getConnection();
     108             : }
     109             : 
     110           0 : bool AddTableDialogContext::allowViews() const
     111             : {
     112           0 :     return m_rController.allowViews();
     113             : }
     114             : 
     115           0 : bool AddTableDialogContext::allowQueries() const
     116             : {
     117           0 :     return m_rController.allowQueries();
     118             : }
     119             : 
     120           0 : bool AddTableDialogContext::allowAddition() const
     121             : {
     122           0 :     return const_cast< OJoinController& >( m_rController ).getJoinView()->getTableView()->IsAddAllowed();
     123             : }
     124             : 
     125           0 : void AddTableDialogContext::addTableWindow( const OUString& _rQualifiedTableName, const OUString& _rAliasName )
     126             : {
     127           0 :     getTableView()->AddTabWin( _rQualifiedTableName, _rAliasName, sal_True );
     128           0 : }
     129             : 
     130           0 : void AddTableDialogContext::onWindowClosing( const Window* _pWindow )
     131             : {
     132           0 :     if ( !m_rController.getView() )
     133           0 :         return;
     134             : 
     135             :     ::dbaui::notifySystemWindow(
     136           0 :         m_rController.getView(), const_cast< Window* >( _pWindow ), ::comphelper::mem_fun( &TaskPaneList::RemoveWindow ) );
     137             : 
     138           0 :     m_rController.InvalidateFeature( ID_BROWSER_ADDTABLE );
     139           0 :     m_rController.getView()->GrabFocus();
     140             : }
     141             : 
     142           0 : OJoinTableView* AddTableDialogContext::getTableView() const
     143             : {
     144           0 :     if ( m_rController.getJoinView() )
     145           0 :         return m_rController.getJoinView()->getTableView();
     146           0 :     return NULL;
     147             : }
     148             : 
     149             : // OJoinController
     150             : 
     151           0 : OJoinController::OJoinController(const Reference< XComponentContext >& _rM)
     152             :     :OJoinController_BASE(_rM)
     153           0 :     ,m_pAddTableDialog(NULL)
     154             : {
     155           0 : }
     156             : 
     157           0 : OJoinController::~OJoinController()
     158             : {
     159           0 : }
     160             : 
     161           0 : void SAL_CALL OJoinController::disposing( const EventObject& _rSource ) throw(RuntimeException, std::exception)
     162             : {
     163           0 :     OJoinController_BASE::disposing( _rSource );
     164           0 : }
     165             : 
     166           0 : OJoinDesignView* OJoinController::getJoinView()
     167             : {
     168           0 :     return static_cast< OJoinDesignView* >( getView() );
     169             : }
     170             : 
     171           0 : void OJoinController::disposing()
     172             : {
     173             :     {
     174           0 :         boost::scoped_ptr< Window > pEnsureDelete( m_pAddTableDialog );
     175           0 :         m_pAddTableDialog   = NULL;
     176             :     }
     177             : 
     178           0 :     OJoinController_BASE::disposing();
     179             : 
     180           0 :     clearView();
     181             : 
     182           0 :     m_vTableConnectionData.clear();
     183           0 :     m_vTableData.clear();
     184           0 : }
     185             : 
     186           0 : void OJoinController::reconnect( bool _bUI )
     187             : {
     188           0 :     OJoinController_BASE::reconnect( _bUI );
     189           0 :     if ( isConnected() && m_pAddTableDialog )
     190           0 :         m_pAddTableDialog->Update();
     191           0 : }
     192             : 
     193           0 : void OJoinController::impl_onModifyChanged()
     194             : {
     195           0 :     OJoinController_BASE::impl_onModifyChanged();
     196           0 :     InvalidateFeature( SID_RELATION_ADD_RELATION );
     197           0 : }
     198             : 
     199           0 : void OJoinController::SaveTabWinPosSize(OTableWindow* pTabWin, long nOffsetX, long nOffsetY)
     200             : {
     201             :     // the data for the window
     202           0 :     TTableWindowData::value_type pData = pTabWin->GetData();
     203             :     OSL_ENSURE(pData != 0, "SaveTabWinPosSize : TabWin hat keine Daten !");
     204             : 
     205             :     // set Position & Size of data anew (with current window parameters)
     206           0 :     Point aPos = pTabWin->GetPosPixel();
     207           0 :     aPos.X() += nOffsetX;
     208           0 :     aPos.Y() += nOffsetY;
     209           0 :     pData->SetPosition(aPos);
     210           0 :     pData->SetSize(pTabWin->GetSizePixel());
     211             : 
     212           0 : }
     213             : 
     214           0 : FeatureState OJoinController::GetState(sal_uInt16 _nId) const
     215             : {
     216           0 :     FeatureState aReturn;
     217             :         // (disabled automatically)
     218           0 :     aReturn.bEnabled = true;
     219             : 
     220           0 :     switch (_nId)
     221             :     {
     222             :         case ID_BROWSER_EDITDOC:
     223           0 :             aReturn.bChecked = isEditable();
     224           0 :             break;
     225             :         case ID_BROWSER_ADDTABLE:
     226           0 :             aReturn.bEnabled = ( getView() != NULL )
     227           0 :                             && const_cast< OJoinController* >( this )->getJoinView()->getTableView()->IsAddAllowed();
     228           0 :             aReturn.bChecked = aReturn.bEnabled && m_pAddTableDialog != NULL && m_pAddTableDialog->IsVisible() ;
     229           0 :             if ( aReturn.bEnabled )
     230           0 :                 aReturn.sTitle = OAddTableDlg::getDialogTitleForContext( impl_getDialogContext() );
     231           0 :             break;
     232             : 
     233             :         default:
     234           0 :             aReturn = OJoinController_BASE::GetState(_nId);
     235             :     }
     236           0 :     return aReturn;
     237             : }
     238             : 
     239           0 : AddTableDialogContext& OJoinController::impl_getDialogContext() const
     240             : {
     241           0 :     if ( !m_pDialogContext.get() )
     242             :     {
     243           0 :         OJoinController* pNonConstThis = const_cast< OJoinController* >( this );
     244           0 :         pNonConstThis->m_pDialogContext.reset( new AddTableDialogContext( *pNonConstThis ) );
     245             :     }
     246           0 :     return *m_pDialogContext;
     247             : }
     248             : 
     249           0 : void OJoinController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
     250             : {
     251           0 :     switch(_nId)
     252             :     {
     253             :         case ID_BROWSER_EDITDOC:
     254           0 :             if(isEditable())
     255             :             { // the state should be changed to not editable
     256           0 :                 switch (saveModified())
     257             :                 {
     258             :                     case RET_CANCEL:
     259             :                         // don't change anything here so return
     260           0 :                         return;
     261             :                     case RET_NO:
     262           0 :                         reset();
     263           0 :                         setModified(sal_False);     // and we are not modified yet
     264           0 :                         break;
     265             :                     default:
     266           0 :                         break;
     267             :                 }
     268             :             }
     269           0 :             setEditable(!isEditable());
     270           0 :             getJoinView()->setReadOnly(!isEditable());
     271           0 :             InvalidateAll();
     272           0 :             return;
     273             :         case ID_BROWSER_ADDTABLE:
     274           0 :             if ( !m_pAddTableDialog )
     275           0 :                 m_pAddTableDialog = new OAddTableDlg( getView(), impl_getDialogContext() );
     276             : 
     277           0 :             if ( m_pAddTableDialog->IsVisible() )
     278             :             {
     279           0 :                 m_pAddTableDialog->Show( false );
     280           0 :                 getView()->GrabFocus();
     281             :             }
     282             :             else
     283             :             {
     284             :                 {
     285           0 :                     WaitObject aWaitCursor( getView() );
     286           0 :                     m_pAddTableDialog->Update();
     287             :                 }
     288           0 :                 m_pAddTableDialog->Show( true );
     289           0 :                 ::dbaui::notifySystemWindow(getView(),m_pAddTableDialog,::comphelper::mem_fun(&TaskPaneList::AddWindow));
     290             :             }
     291           0 :             break;
     292             :         default:
     293           0 :             OJoinController_BASE::Execute(_nId,aArgs);
     294             :     }
     295           0 :     InvalidateFeature(_nId);
     296             : }
     297             : 
     298           0 : void OJoinController::SaveTabWinsPosSize( OJoinTableView::OTableWindowMap* pTabWinList, long nOffsetX, long nOffsetY )
     299             : {
     300             :     // Deletion and recreation of the old implementation with the current model is not correct anymore:
     301             :     // The TabWins have a pointer to their data, but they are managed by me. When I delete the old ones, the TabWins suddenly have a pointer to objects, which no longer exist.
     302             :     // If the TabWins had a SetData, I could save that effort... but they don't, further I also would still have to set information anew, which actually didn't change.
     303             :     // So I don't delete the TabWinDatas, but only update them.
     304             :     OSL_ENSURE(m_vTableData.size() == pTabWinList->size(),
     305             :         "OJoinController::SaveTabWinsPosSize : inkonsistenter Zustand : sollte genausviel TabWinDatas haben wie TabWins !");
     306             : 
     307           0 :     OJoinTableView::OTableWindowMap::iterator aIter = pTabWinList->begin();
     308           0 :     OJoinTableView::OTableWindowMap::iterator aEnd = pTabWinList->end();
     309           0 :     for(;aIter != aEnd;++aIter)
     310           0 :         SaveTabWinPosSize(aIter->second, nOffsetX, nOffsetY);
     311           0 : }
     312             : 
     313           0 : void OJoinController::removeConnectionData(const TTableConnectionData::value_type& _pData)
     314             : {
     315           0 :     m_vTableConnectionData.erase( ::std::remove(m_vTableConnectionData.begin(),m_vTableConnectionData.end(),_pData),m_vTableConnectionData.end());
     316           0 : }
     317             : 
     318           0 : void OJoinController::describeSupportedFeatures()
     319             : {
     320           0 :     OJoinController_BASE::describeSupportedFeatures();
     321           0 :     implDescribeSupportedFeature( ".uno:Redo",      ID_BROWSER_REDO,    CommandGroup::EDIT );
     322           0 :     implDescribeSupportedFeature( ".uno:Save",      ID_BROWSER_SAVEDOC, CommandGroup::DOCUMENT );
     323           0 :     implDescribeSupportedFeature( ".uno:Undo",      ID_BROWSER_UNDO,    CommandGroup::EDIT );
     324           0 :     implDescribeSupportedFeature( ".uno:AddTable",  ID_BROWSER_ADDTABLE,CommandGroup::EDIT );
     325           0 :     implDescribeSupportedFeature( ".uno:EditDoc",   ID_BROWSER_EDITDOC, CommandGroup::EDIT );
     326           0 : }
     327             : 
     328           0 : sal_Bool SAL_CALL OJoinController::suspend(sal_Bool _bSuspend) throw( RuntimeException, std::exception )
     329             : {
     330           0 :     if ( getBroadcastHelper().bInDispose || getBroadcastHelper().bDisposed )
     331           0 :         return sal_True;
     332             : 
     333           0 :     SolarMutexGuard aSolarGuard;
     334           0 :     ::osl::MutexGuard aGuard( getMutex() );
     335           0 :     if ( getView() && getView()->IsInModalMode() )
     336           0 :         return sal_False;
     337           0 :     sal_Bool bCheck = sal_True;
     338           0 :     if ( _bSuspend )
     339             :     {
     340           0 :         bCheck = saveModified() != RET_CANCEL;
     341           0 :         if ( bCheck )
     342           0 :             OSingleDocumentController::suspend(_bSuspend);
     343             :     }
     344           0 :     return bCheck;
     345             : }
     346             : 
     347           0 : void OJoinController::loadTableWindows( const ::comphelper::NamedValueCollection& i_rViewSettings )
     348             : {
     349           0 :     m_vTableData.clear();
     350             : 
     351           0 :     m_aMinimumTableViewSize = Point();
     352             : 
     353           0 :     Sequence< PropertyValue > aWindowData;
     354           0 :     aWindowData = i_rViewSettings.getOrDefault( "Tables", aWindowData );
     355             : 
     356           0 :     const PropertyValue* pTablesIter = aWindowData.getConstArray();
     357           0 :     const PropertyValue* pTablesEnd = pTablesIter + aWindowData.getLength();
     358           0 :     for ( ; pTablesIter != pTablesEnd; ++pTablesIter )
     359             :     {
     360           0 :         ::comphelper::NamedValueCollection aSingleTableData( pTablesIter->Value );
     361           0 :         loadTableWindow( aSingleTableData );
     362           0 :     }
     363           0 :     if ( m_aMinimumTableViewSize != Point() )
     364             :     {
     365           0 :         getJoinView()->getScrollHelper()->resetRange( m_aMinimumTableViewSize );
     366           0 :     }
     367           0 : }
     368             : 
     369           0 : void OJoinController::loadTableWindow( const ::comphelper::NamedValueCollection& i_rTableWindowSettings )
     370             : {
     371           0 :     sal_Int32 nX = -1, nY = -1, nHeight = -1, nWidth = -1;
     372             : 
     373           0 :     OUString sComposedName,sTableName,sWindowName;
     374           0 :     sal_Bool bShowAll = false;
     375             : 
     376           0 :     sComposedName = i_rTableWindowSettings.getOrDefault( "ComposedName", sComposedName );
     377           0 :     sTableName = i_rTableWindowSettings.getOrDefault( "TableName", sTableName );
     378           0 :     sWindowName = i_rTableWindowSettings.getOrDefault( "WindowName", sWindowName );
     379           0 :     nY = i_rTableWindowSettings.getOrDefault( "WindowTop", nY );
     380           0 :     nX = i_rTableWindowSettings.getOrDefault( "WindowLeft", nX );
     381           0 :     nWidth = i_rTableWindowSettings.getOrDefault( "WindowWidth", nWidth );
     382           0 :     nHeight = i_rTableWindowSettings.getOrDefault( "WindowHeight", nHeight );
     383           0 :     bShowAll = i_rTableWindowSettings.getOrDefault( "ShowAll", bShowAll );
     384             : 
     385           0 :     TTableWindowData::value_type pData = createTableWindowData(sComposedName,sTableName,sWindowName);
     386           0 :     if ( pData )
     387             :     {
     388           0 :         pData->SetPosition(Point(nX,nY));
     389           0 :         pData->SetSize( Size( nWidth, nHeight ) );
     390           0 :         pData->ShowAll(bShowAll);
     391           0 :         m_vTableData.push_back(pData);
     392           0 :         if ( m_aMinimumTableViewSize.X() < (nX+nWidth) )
     393           0 :             m_aMinimumTableViewSize.X() = (nX+nWidth);
     394           0 :         if ( m_aMinimumTableViewSize.Y() < (nY+nHeight) )
     395           0 :             m_aMinimumTableViewSize.Y() = (nY+nHeight);
     396           0 :     }
     397           0 : }
     398             : 
     399           0 : void OJoinController::saveTableWindows( ::comphelper::NamedValueCollection& o_rViewSettings ) const
     400             : {
     401           0 :     if ( !m_vTableData.empty() )
     402             :     {
     403           0 :         ::comphelper::NamedValueCollection aAllTablesData;
     404             : 
     405           0 :         TTableWindowData::const_iterator aIter = m_vTableData.begin();
     406           0 :         TTableWindowData::const_iterator aEnd = m_vTableData.end();
     407           0 :         for ( sal_Int32 i = 1; aIter != aEnd; ++aIter, ++i )
     408             :         {
     409           0 :             ::comphelper::NamedValueCollection aWindowData;
     410           0 :             aWindowData.put( "ComposedName", (*aIter)->GetComposedName() );
     411           0 :             aWindowData.put( "TableName", (*aIter)->GetTableName() );
     412           0 :             aWindowData.put( "WindowName", (*aIter)->GetWinName() );
     413           0 :             aWindowData.put( "WindowTop", static_cast<sal_Int32>((*aIter)->GetPosition().Y()) );
     414           0 :             aWindowData.put( "WindowLeft", static_cast<sal_Int32>((*aIter)->GetPosition().X()) );
     415           0 :             aWindowData.put( "WindowWidth", static_cast<sal_Int32>((*aIter)->GetSize().Width()) );
     416           0 :             aWindowData.put( "WindowHeight", static_cast<sal_Int32>((*aIter)->GetSize().Height()) );
     417           0 :             aWindowData.put( "ShowAll", (*aIter)->IsShowAll() );
     418             : 
     419           0 :             const OUString sTableName( OUString( "Table" ) + OUString::number( i ) );
     420           0 :             aAllTablesData.put( sTableName, aWindowData.getPropertyValues() );
     421           0 :         }
     422             : 
     423           0 :         o_rViewSettings.put( "Tables", aAllTablesData.getPropertyValues() );
     424             :     }
     425           0 : }
     426             : 
     427           0 : TTableWindowData::value_type OJoinController::createTableWindowData(const OUString& _sComposedName,const OUString& _sTableName,const OUString& _sWindowName)
     428             : {
     429           0 :     OJoinDesignView* pView = getJoinView();
     430           0 :     if( pView )
     431           0 :         return pView->getTableView()->createTableWindowData(_sComposedName,_sTableName,_sWindowName);
     432             :     OSL_FAIL("We should never ever reach this point!");
     433             : 
     434           0 :     return TTableWindowData::value_type();
     435             : }
     436             : 
     437             : }   // namespace dbaui
     438             : 
     439             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10