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

Generated by: LCOV version 1.10