LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - databaseobjectview.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 121 0.8 %
Date: 2014-11-03 Functions: 2 18 11.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 "databaseobjectview.hxx"
      21             : #include "dbustrings.hrc"
      22             : #include "asyncmodaldialog.hxx"
      23             : 
      24             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      25             : #include <com/sun/star/frame/TaskCreator.hpp>
      26             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      27             : #include <com/sun/star/frame/XFrame.hpp>
      28             : #include <com/sun/star/frame/XFrames.hpp>
      29             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      30             : #include <com/sun/star/sdb/CommandType.hpp>
      31             : #include <com/sun/star/sdb/application/XTableUIProvider.hpp>
      32             : #include <com/sun/star/beans/NamedValue.hpp>
      33             : #include <com/sun/star/awt/Rectangle.hpp>
      34             : 
      35             : #include <comphelper/extract.hxx>
      36             : #include <comphelper/sequence.hxx>
      37             : #include <connectivity/dbtools.hxx>
      38             : #include <osl/diagnose.h>
      39             : #include <toolkit/helper/vclunohelper.hxx>
      40             : #include <tools/diagnose_ex.h>
      41             : #include <vcl/window.hxx>
      42             : 
      43             : namespace dbaui
      44             : {
      45             : 
      46             :     using namespace ::com::sun::star::uno;
      47             :     using namespace ::com::sun::star::sdbc;
      48             :     using namespace ::com::sun::star::sdb;
      49             :     using namespace ::com::sun::star::sdb::application;
      50             :     using namespace ::com::sun::star::ui::dialogs;
      51             :     using namespace ::com::sun::star::frame;
      52             :     using namespace ::com::sun::star::lang;
      53             :     using namespace ::com::sun::star::beans;
      54             :     using namespace ::com::sun::star::awt;
      55             : 
      56             :     // DatabaseObjectView
      57           0 :     DatabaseObjectView::DatabaseObjectView( const Reference< XComponentContext >& _rxORB,
      58             :             const Reference< XDatabaseDocumentUI >& _rxApplication,
      59             :             const Reference< XFrame >& _rxParentFrame,
      60             :             const OUString& _rComponentURL )
      61             :         :m_xORB             ( _rxORB            )
      62             :         ,m_xParentFrame     ( _rxParentFrame    )
      63             :         ,m_xFrameLoader     (                   )
      64             :         ,m_xApplication     ( _rxApplication    )
      65           0 :         ,m_sComponentURL    ( _rComponentURL    )
      66             :     {
      67             :         OSL_ENSURE( m_xORB.is(), "DatabaseObjectView::DatabaseObjectView: invalid service factory!" );
      68             :         OSL_ENSURE( m_xApplication.is(), "DatabaseObjectView::DatabaseObjectView: invalid connection!" );
      69           0 :     }
      70             : 
      71           0 :     Reference< XConnection > DatabaseObjectView::getConnection() const
      72             :     {
      73           0 :         Reference< XConnection > xConnection;
      74           0 :         if ( m_xApplication.is() )
      75           0 :             xConnection = m_xApplication->getActiveConnection();
      76           0 :         return xConnection;
      77             :     }
      78             : 
      79           0 :     Reference< XComponent > DatabaseObjectView::createNew( const Reference< XDataSource >& _xDataSource, const ::comphelper::NamedValueCollection& i_rDispatchArgs )
      80             :     {
      81           0 :         return doCreateView( makeAny( _xDataSource ), OUString(), i_rDispatchArgs );
      82             :     }
      83             : 
      84           0 :     Reference< XComponent > DatabaseObjectView::openExisting( const Any& _rDataSource, const OUString& _rName,
      85             :             const ::comphelper::NamedValueCollection& i_rDispatchArgs )
      86             :     {
      87           0 :         return doCreateView( _rDataSource, _rName, i_rDispatchArgs );
      88             :     }
      89             : 
      90           0 :     Reference< XComponent > DatabaseObjectView::doCreateView( const Any& _rDataSource, const OUString& _rObjectName,
      91             :         const ::comphelper::NamedValueCollection& i_rCreationArgs )
      92             :     {
      93           0 :         ::comphelper::NamedValueCollection aDispatchArgs;
      94             : 
      95           0 :         aDispatchArgs.merge( i_rCreationArgs, false );    // false => do not overwrite
      96           0 :         fillDispatchArgs( aDispatchArgs, _rDataSource, _rObjectName );
      97           0 :         aDispatchArgs.merge( i_rCreationArgs, true );    // true => do overwrite
      98             : 
      99           0 :         return doDispatch( aDispatchArgs );
     100             :     }
     101             : 
     102           0 :     Reference< XComponent > DatabaseObjectView::doDispatch( const ::comphelper::NamedValueCollection& i_rDispatchArgs )
     103             :     {
     104           0 :         Reference< XComponent > xReturn;
     105           0 :         if ( m_xORB.is() )
     106             :         {
     107             :             try
     108             :             {
     109             :                 // if we have no externally provided frame, create one
     110           0 :                 if ( !m_xFrameLoader.is() )
     111             :                 {
     112           0 :                     Reference< XSingleServiceFactory > xFact = TaskCreator::create(m_xORB);
     113           0 :                     Sequence< Any > lArgs(3);
     114           0 :                     NamedValue      aProp;
     115           0 :                     sal_Int32       nArg = 0;
     116             : 
     117           0 :                     aProp.Name    = "ParentFrame";
     118           0 :                     aProp.Value <<= m_xParentFrame;
     119           0 :                     lArgs[nArg++] <<= aProp;
     120             : 
     121           0 :                     aProp.Name    = "TopWindow";
     122           0 :                     aProp.Value <<= sal_True;
     123           0 :                     lArgs[nArg++] <<= aProp;
     124             : 
     125           0 :                     aProp.Name    = "SupportPersistentWindowState";
     126           0 :                     aProp.Value <<= sal_True;
     127           0 :                     lArgs[nArg++] <<= aProp;
     128             : 
     129           0 :                     m_xFrameLoader.set(xFact->createInstanceWithArguments(lArgs), UNO_QUERY_THROW);
     130             : 
     131             :                     // everything we load can be considered a "top level document", so set the respective bit at the window.
     132             :                     // This, amongst other things, triggers that the component in this task participates in the
     133             :                     // "ThisComponent"-game for the global application Basic.
     134           0 :                     const Reference< XFrame > xFrame( m_xFrameLoader, UNO_QUERY_THROW );
     135           0 :                     const Reference< XWindow > xFrameWindow( xFrame->getContainerWindow(), UNO_SET_THROW );
     136           0 :                     vcl::Window* pContainerWindow = VCLUnoHelper::GetWindow( xFrameWindow );
     137           0 :                     ENSURE_OR_THROW( pContainerWindow, "no implementation access to the frame's container window!" );
     138           0 :                     pContainerWindow->SetExtendedStyle( pContainerWindow->GetExtendedStyle() | WB_EXT_DOCUMENT );
     139             :                 }
     140             : 
     141           0 :                 Reference< XComponentLoader > xFrameLoader( m_xFrameLoader, UNO_QUERY_THROW );
     142           0 :                 xReturn = xFrameLoader->loadComponentFromURL(
     143             :                     m_sComponentURL,
     144             :                     OUString("_self"),
     145             :                     0,
     146             :                     i_rDispatchArgs.getPropertyValues()
     147           0 :                 );
     148             :             }
     149           0 :             catch( const Exception& )
     150             :             {
     151             :                 DBG_UNHANDLED_EXCEPTION();
     152             :             }
     153             :         }
     154           0 :         return xReturn;
     155             :     }
     156             : 
     157           0 :     void DatabaseObjectView::fillDispatchArgs(
     158             :             ::comphelper::NamedValueCollection& i_rDispatchArgs,
     159             :             const Any& _aDataSource,
     160             :             const OUString& /* _rName */
     161             :         )
     162             :     {
     163           0 :         OUString sDataSource;
     164           0 :         Reference<XDataSource> xDataSource;
     165           0 :         if ( _aDataSource >>= sDataSource )
     166             :         {
     167           0 :             i_rDispatchArgs.put( OUString(PROPERTY_DATASOURCENAME), sDataSource );
     168             :         }
     169           0 :         else if ( _aDataSource >>= xDataSource )
     170             :         {
     171           0 :             i_rDispatchArgs.put( OUString(PROPERTY_DATASOURCE), xDataSource );
     172             :         }
     173             : 
     174           0 :         i_rDispatchArgs.put( OUString(PROPERTY_ACTIVE_CONNECTION), getConnection() );
     175           0 :     }
     176             : 
     177             :     // QueryDesigner
     178           0 :     QueryDesigner::QueryDesigner( const Reference< XComponentContext >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication,
     179             :         const Reference< XFrame >& _rxParentFrame, bool _bCreateView )
     180             :         :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, _bCreateView ? OUString(URL_COMPONENT_VIEWDESIGN) : OUString(URL_COMPONENT_QUERYDESIGN) )
     181           0 :         ,m_nCommandType( _bCreateView ? CommandType::TABLE : CommandType::QUERY )
     182             :     {
     183           0 :     }
     184             : 
     185           0 :     void QueryDesigner::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource,
     186             :         const OUString& _rObjectName )
     187             :     {
     188           0 :         DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rObjectName );
     189             : 
     190           0 :         const bool bIncludeQueryName = !_rObjectName.isEmpty();
     191           0 :         const bool bGraphicalDesign = i_rDispatchArgs.getOrDefault( OUString(PROPERTY_GRAPHICAL_DESIGN), sal_True );
     192           0 :         const bool bEditViewAsSQLCommand = ( m_nCommandType == CommandType::TABLE ) && !bGraphicalDesign;
     193             : 
     194           0 :         i_rDispatchArgs.put( OUString(PROPERTY_COMMAND_TYPE), m_nCommandType );
     195             : 
     196           0 :         if ( bIncludeQueryName )
     197             :         {
     198           0 :             i_rDispatchArgs.put( OUString(PROPERTY_COMMAND), _rObjectName );
     199             :         }
     200             : 
     201           0 :         if ( bEditViewAsSQLCommand )
     202             :         {
     203           0 :             i_rDispatchArgs.put( OUString(PROPERTY_ESCAPE_PROCESSING), sal_False );
     204             :         }
     205           0 :     }
     206             : 
     207             :     // TableDesigner
     208           0 :     TableDesigner::TableDesigner( const Reference< XComponentContext >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication, const Reference< XFrame >& _rxParentFrame )
     209           0 :         :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, static_cast< OUString >( URL_COMPONENT_TABLEDESIGN ) )
     210             :     {
     211           0 :     }
     212             : 
     213           0 :     void TableDesigner::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource,
     214             :         const OUString& _rObjectName )
     215             :     {
     216           0 :         DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rObjectName );
     217             : 
     218           0 :         if ( !_rObjectName.isEmpty() )
     219             :         {
     220           0 :             i_rDispatchArgs.put( OUString(PROPERTY_CURRENTTABLE), _rObjectName );
     221             :         }
     222           0 :     }
     223             : 
     224           0 :     Reference< XComponent > TableDesigner::doCreateView( const Any& _rDataSource, const OUString& _rObjectName,
     225             :         const ::comphelper::NamedValueCollection& i_rCreationArgs )
     226             :     {
     227           0 :         bool bIsNewDesign =  _rObjectName.isEmpty();
     228             : 
     229             :         // let's see whether the connection can provide a dedicated table desginer
     230           0 :         Reference< XInterface > xDesigner;
     231           0 :         if ( !bIsNewDesign )
     232           0 :             xDesigner = impl_getConnectionProvidedDesigner_nothrow( _rObjectName );
     233             : 
     234           0 :         if ( !xDesigner.is() )
     235           0 :             return DatabaseObjectView::doCreateView( _rDataSource, _rObjectName, i_rCreationArgs );
     236             : 
     237             :         // try whether the designer is a dialog
     238           0 :         Reference< XExecutableDialog > xDialog( xDesigner, UNO_QUERY_THROW );
     239           0 :         if ( xDialog.is() )
     240             :         {
     241           0 :             try { AsyncDialogExecutor::executeModalDialogAsync( xDialog ); }
     242           0 :             catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
     243           0 :             return NULL;
     244             :         }
     245             : 
     246           0 :         Reference< XComponent > xDesignerComponent( xDesigner, UNO_QUERY );
     247             :         OSL_ENSURE( xDesignerComponent.is(), "TableDesigner::doCreateView: a designer which is no dialog and no component?" );
     248           0 :         return xDesignerComponent;
     249             :     }
     250             : 
     251           0 :     Reference< XInterface > TableDesigner::impl_getConnectionProvidedDesigner_nothrow( const OUString& _rTableName )
     252             :     {
     253           0 :         Reference< XInterface > xDesigner;
     254             :         try
     255             :         {
     256           0 :             Reference< XTableUIProvider > xTableUIProv( getConnection(), UNO_QUERY );
     257           0 :             if ( xTableUIProv.is() )
     258           0 :                 xDesigner = xTableUIProv->getTableEditor( getApplicationUI(), _rTableName );
     259             :         }
     260           0 :         catch( const Exception& )
     261             :         {
     262             :             DBG_UNHANDLED_EXCEPTION();
     263             :         }
     264           0 :         return xDesigner;
     265             :     }
     266             : 
     267             :     // ResultSetBrowser
     268           0 :     ResultSetBrowser::ResultSetBrowser( const Reference< XComponentContext >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication, const Reference< XFrame >& _rxParentFrame,
     269             :             bool _bTable )
     270             :         :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, static_cast < OUString >( URL_COMPONENT_DATASOURCEBROWSER ) )
     271           0 :         ,m_bTable(_bTable)
     272             :     {
     273           0 :     }
     274             : 
     275           0 :     void ResultSetBrowser::fillDispatchArgs( ::comphelper::NamedValueCollection& i_rDispatchArgs, const Any& _aDataSource,
     276             :         const OUString& _rQualifiedName)
     277             :     {
     278           0 :         DatabaseObjectView::fillDispatchArgs( i_rDispatchArgs, _aDataSource, _rQualifiedName );
     279             :         OSL_ENSURE( !_rQualifiedName.isEmpty(),"A Table name must be set");
     280           0 :         OUString sCatalog;
     281           0 :         OUString sSchema;
     282           0 :         OUString sTable;
     283           0 :         if ( m_bTable )
     284           0 :             ::dbtools::qualifiedNameComponents( getConnection()->getMetaData(), _rQualifiedName, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation );
     285             : 
     286           0 :         i_rDispatchArgs.put( OUString(PROPERTY_COMMAND_TYPE), (m_bTable ? CommandType::TABLE : CommandType::QUERY) );
     287           0 :         i_rDispatchArgs.put( OUString(PROPERTY_COMMAND), _rQualifiedName );
     288           0 :         i_rDispatchArgs.put( OUString(PROPERTY_ENABLE_BROWSER), sal_False );
     289             : 
     290           0 :         if ( m_bTable )
     291             :         {
     292           0 :             i_rDispatchArgs.put( OUString(PROPERTY_UPDATE_CATALOGNAME), sCatalog );
     293           0 :             i_rDispatchArgs.put( OUString(PROPERTY_UPDATE_SCHEMANAME), sSchema );
     294           0 :             i_rDispatchArgs.put( OUString(PROPERTY_UPDATE_TABLENAME), sTable );
     295           0 :         }
     296           0 :     }
     297             : 
     298             :     // RelationDesigner
     299           0 :     RelationDesigner::RelationDesigner( const Reference< XComponentContext >& _rxORB, const Reference< XDatabaseDocumentUI >& _rxApplication, const Reference< XFrame >& _rxParentFrame )
     300           0 :         :DatabaseObjectView( _rxORB, _rxApplication, _rxParentFrame, static_cast< OUString >( URL_COMPONENT_RELATIONDESIGN ) )
     301             :     {
     302           0 :     }
     303          72 : }   // namespace dbaui
     304             : 
     305             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10