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

Generated by: LCOV version 1.10