LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/uno - composerdialogs.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 9 91 9.9 %
Date: 2013-07-09 Functions: 7 32 21.9 %
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 "composerdialogs.hxx"
      22             : 
      23             : #include "dbu_reghelper.hxx"
      24             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      25             : #include "dbustrings.hrc"
      26             : #include "queryfilter.hxx"
      27             : #include "queryorder.hxx"
      28             : #include <comphelper/processfactory.hxx>
      29             : #include <connectivity/dbtools.hxx>
      30             : #include <tools/diagnose_ex.h>
      31             : #include <osl/diagnose.h>
      32             : 
      33           4 : extern "C" void SAL_CALL createRegistryInfo_ComposerDialogs()
      34             : {
      35           4 :     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::RowsetOrderDialog > aOrderDialogRegistration;
      36           4 :     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::RowsetFilterDialog > aFilterDialogRegistration;
      37           4 : }
      38             : 
      39             : //.........................................................................
      40             : namespace dbaui
      41             : {
      42             : //.........................................................................
      43             : 
      44             : #define PROPERTY_ID_QUERYCOMPOSER       100
      45             : #define PROPERTY_ID_ROWSET              101
      46             : 
      47             : #define  PROPERTY_QUERYCOMPOSER   "QueryComposer"
      48             : #define  PROPERTY_ROWSET          "RowSet"
      49             : 
      50             :     using namespace ::com::sun::star::uno;
      51             :     using namespace ::com::sun::star::lang;
      52             :     using namespace ::com::sun::star::beans;
      53             :     using namespace ::com::sun::star::container;
      54             :     using namespace ::com::sun::star::sdbcx;
      55             :     using namespace ::com::sun::star::sdbc;
      56             :     using namespace ::com::sun::star::sdb;
      57             : 
      58             :     //=====================================================================
      59             :     //= ComposerDialog
      60             :     //=====================================================================
      61             :     DBG_NAME(ComposerDialog)
      62             :     //---------------------------------------------------------------------
      63           0 :     ComposerDialog::ComposerDialog(const Reference< XComponentContext >& _rxORB)
      64           0 :         :OGenericUnoDialog( _rxORB )
      65             :     {
      66             :         DBG_CTOR(ComposerDialog,NULL);
      67             : 
      68             :         registerProperty( PROPERTY_QUERYCOMPOSER, PROPERTY_ID_QUERYCOMPOSER, PropertyAttribute::TRANSIENT,
      69           0 :             &m_xComposer, ::getCppuType( &m_xComposer ) );
      70             :         registerProperty( PROPERTY_ROWSET, PROPERTY_ID_ROWSET, PropertyAttribute::TRANSIENT,
      71           0 :             &m_xRowSet, ::getCppuType( &m_xRowSet ) );
      72           0 :     }
      73             : 
      74             :     //---------------------------------------------------------------------
      75           0 :     ComposerDialog::~ComposerDialog()
      76             :     {
      77             : 
      78             :         DBG_DTOR(ComposerDialog,NULL);
      79           0 :     }
      80             : 
      81             :     //---------------------------------------------------------------------
      82           0 :     IMPLEMENT_IMPLEMENTATION_ID( ComposerDialog )
      83             : 
      84             :     //---------------------------------------------------------------------
      85           0 :     IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( ComposerDialog )
      86             : 
      87             :     //---------------------------------------------------------------------
      88           0 :     Dialog* ComposerDialog::createDialog(Window* _pParent)
      89             :     {
      90             :         // obtain all the objects needed for the dialog
      91           0 :         Reference< XConnection > xConnection;
      92           0 :         Reference< XNameAccess > xColumns;
      93             :         try
      94             :         {
      95             :             // the connection the row set is working with
      96           0 :             if ( !::dbtools::isEmbeddedInDatabase( m_xRowSet, xConnection ) )
      97             :             {
      98           0 :                 Reference< XPropertySet > xRowsetProps( m_xRowSet, UNO_QUERY );
      99           0 :                 if ( xRowsetProps.is() )
     100           0 :                     xRowsetProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xConnection;
     101             :             }
     102             : 
     103             :             // fallback: if there is a connection and thus a row set, but no composer, create one
     104           0 :             if ( xConnection.is() && !m_xComposer.is() )
     105           0 :                 m_xComposer = ::dbtools::getCurrentSettingsComposer( Reference< XPropertySet >( m_xRowSet, UNO_QUERY ), m_aContext );
     106             : 
     107             :             // the columns of the row set
     108           0 :             Reference< XColumnsSupplier > xSuppColumns( m_xRowSet, UNO_QUERY );
     109           0 :             if ( xSuppColumns.is() )
     110           0 :                 xColumns = xSuppColumns->getColumns();
     111             : 
     112           0 :             if ( !xColumns.is() || !xColumns->hasElements() )
     113             :             {   // perhaps the composer can supply us with columns? This is necessary for cases
     114             :                 // where the dialog is invoked for a rowset which is not yet loaded
     115             :                 // #i22878#
     116           0 :                 xSuppColumns = xSuppColumns.query( m_xComposer );
     117           0 :                 if ( xSuppColumns.is() )
     118           0 :                     xColumns = xSuppColumns->getColumns();
     119             :             }
     120             : 
     121           0 :             OSL_ENSURE( xColumns.is() && xColumns->hasElements(), "ComposerDialog::createDialog: not much fun without any columns!" );
     122             :         }
     123           0 :         catch( const Exception& )
     124             :         {
     125             :             DBG_UNHANDLED_EXCEPTION();
     126             :         }
     127             : 
     128           0 :         if ( !xConnection.is() || !xColumns.is() || !m_xComposer.is() )
     129             :             // can't create the dialog if I have improper settings
     130           0 :             return NULL;
     131             : 
     132           0 :         return createComposerDialog( _pParent, xConnection, xColumns );
     133             :     }
     134             : 
     135             :     //=====================================================================
     136             :     //= RowsetFilterDialog
     137             :     //=====================================================================
     138             :     //---------------------------------------------------------------------
     139           0 :     RowsetFilterDialog::RowsetFilterDialog( const Reference< XComponentContext >& _rxORB )
     140           0 :         :ComposerDialog( _rxORB )
     141             :     {
     142           0 :     }
     143             : 
     144             :     //---------------------------------------------------------------------
     145           8 :     IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(RowsetFilterDialog, "com.sun.star.uno.comp.sdb.RowsetFilterDialog")
     146           0 :     IMPLEMENT_SERVICE_INFO_SUPPORTS(RowsetFilterDialog)
     147           4 :     IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(RowsetFilterDialog, "com.sun.star.sdb.FilterDialog")
     148             : 
     149             :     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
     150           0 :         SAL_CALL RowsetFilterDialog::Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB)
     151             :     {
     152           0 :         return static_cast< XServiceInfo* >(new RowsetFilterDialog( comphelper::getComponentContext(_rxORB)));
     153             :     }
     154             : 
     155             : 
     156             :     //---------------------------------------------------------------------
     157           0 :     Dialog* RowsetFilterDialog::createComposerDialog( Window* _pParent, const Reference< XConnection >& _rxConnection, const Reference< XNameAccess >& _rxColumns )
     158             :     {
     159           0 :         return new DlgFilterCrit( _pParent, m_aContext, _rxConnection, m_xComposer, _rxColumns );
     160             :     }
     161             : 
     162           0 :     void SAL_CALL RowsetFilterDialog::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
     163             :     {
     164           0 :         if( aArguments.getLength() == 3 )
     165             :         {
     166             :             // this is the FilterDialog::createWithQuery method
     167           0 :             Reference<com::sun::star::sdb::XSingleSelectQueryComposer> xQueryComposer;
     168           0 :             aArguments[0] >>= xQueryComposer;
     169           0 :             Reference<com::sun::star::sdbc::XRowSet> xRowSet;
     170           0 :             aArguments[1] >>= xRowSet;
     171           0 :             Reference<com::sun::star::awt::XWindow> xParentWindow;
     172           0 :             aArguments[2] >>= xParentWindow;
     173           0 :             setPropertyValue( "QueryComposer", makeAny( xQueryComposer ) );
     174           0 :             setPropertyValue( "RowSet",        makeAny( xRowSet ) );
     175           0 :             setPropertyValue( "ParentWindow",  makeAny( xParentWindow ) );
     176             :         }
     177             :         else
     178           0 :             ComposerDialog::initialize(aArguments);
     179           0 :     }
     180             : 
     181             :     //---------------------------------------------------------------------
     182           0 :     void RowsetFilterDialog::executedDialog( sal_Int16 _nExecutionResult )
     183             :     {
     184           0 :         ComposerDialog::executedDialog( _nExecutionResult );
     185             : 
     186           0 :         if ( _nExecutionResult && m_pDialog )
     187           0 :             static_cast< DlgFilterCrit* >( m_pDialog )->BuildWherePart();
     188           0 :     }
     189             : 
     190             :     //=====================================================================
     191             :     //= RowsetOrderDialog
     192             :     //=====================================================================
     193             :     //---------------------------------------------------------------------
     194           0 :     RowsetOrderDialog::RowsetOrderDialog( const Reference< XComponentContext >& _rxORB )
     195           0 :         :ComposerDialog( _rxORB )
     196             :     {
     197           0 :     }
     198             : 
     199             :     //---------------------------------------------------------------------
     200           8 :     IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(RowsetOrderDialog, "com.sun.star.uno.comp.sdb.RowsetOrderDialog")
     201           0 :     IMPLEMENT_SERVICE_INFO_SUPPORTS(RowsetOrderDialog)
     202           4 :     IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(RowsetOrderDialog, "com.sun.star.sdb.OrderDialog")
     203             : 
     204             :     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
     205           0 :         SAL_CALL RowsetOrderDialog::Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB)
     206             :     {
     207           0 :         return static_cast< XServiceInfo* >(new RowsetOrderDialog( comphelper::getComponentContext(_rxORB)));
     208             :     }
     209             : 
     210             :     //---------------------------------------------------------------------
     211           0 :     Dialog* RowsetOrderDialog::createComposerDialog( Window* _pParent, const Reference< XConnection >& _rxConnection, const Reference< XNameAccess >& _rxColumns )
     212             :     {
     213           0 :         return new DlgOrderCrit( _pParent, _rxConnection, m_xComposer, _rxColumns );
     214             :     }
     215             : 
     216             :     //---------------------------------------------------------------------
     217           0 :     void SAL_CALL RowsetOrderDialog::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
     218             :     {
     219           0 :         if( aArguments.getLength() == 2 )
     220             :         {
     221           0 :             Reference<com::sun::star::sdb::XSingleSelectQueryComposer> xQueryComposer;
     222           0 :             aArguments[0] >>= xQueryComposer;
     223           0 :             Reference<com::sun::star::beans::XPropertySet> xRowSet;
     224           0 :             aArguments[1] >>= xRowSet;
     225           0 :             setPropertyValue( "QueryComposer", makeAny( xQueryComposer ) );
     226           0 :             setPropertyValue( "RowSet",        makeAny( xRowSet ) );
     227             :         }
     228             :         else
     229           0 :             ComposerDialog::initialize(aArguments);
     230           0 :     }
     231             : 
     232             :     //---------------------------------------------------------------------
     233           0 :     void RowsetOrderDialog::executedDialog( sal_Int16 _nExecutionResult )
     234             :     {
     235           0 :         ComposerDialog::executedDialog( _nExecutionResult );
     236             : 
     237           0 :         if ( !m_pDialog )
     238           0 :             return;
     239             : 
     240           0 :         if ( _nExecutionResult )
     241           0 :             static_cast< DlgOrderCrit* >( m_pDialog )->BuildOrderPart();
     242           0 :         else if ( m_xComposer.is() )
     243           0 :             m_xComposer->setOrder( static_cast< DlgOrderCrit* >( m_pDialog )->GetOrignalOrder() );
     244             :     }
     245             : 
     246             : //.........................................................................
     247          12 : }   // namespace dbaui
     248             : //.........................................................................
     249             : 
     250             : 
     251             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10