LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - sqlcommanddesign.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 124 0.0 %
Date: 2014-04-14 Functions: 0 17 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 "sqlcommanddesign.hxx"
      21             : #include "formstrings.hxx"
      22             : #include "formresid.hrc"
      23             : #include "modulepcr.hxx"
      24             : #include "unourl.hxx"
      25             : 
      26             : #include <com/sun/star/awt/XWindow.hpp>
      27             : #include <com/sun/star/awt/XTopWindow.hpp>
      28             : #include <com/sun/star/uno/Sequence.hxx>
      29             : #include <com/sun/star/frame/Desktop.hpp>
      30             : #include <com/sun/star/frame/XTitle.hpp>
      31             : #include <com/sun/star/frame/XComponentLoader.hpp>
      32             : #include <com/sun/star/frame/XController.hpp>
      33             : #include <com/sun/star/lang/NullPointerException.hpp>
      34             : #include <com/sun/star/lang/DisposedException.hpp>
      35             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      36             : #include <com/sun/star/frame/XFramesSupplier.hpp>
      37             : #include <com/sun/star/sdbc/XConnection.hpp>
      38             : #include <com/sun/star/util/XCloseable.hpp>
      39             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      40             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      41             : #include <com/sun/star/sdb/CommandType.hpp>
      42             : 
      43             : #include <svtools/localresaccess.hxx>
      44             : #include <tools/diagnose_ex.h>
      45             : #include <osl/diagnose.h>
      46             : 
      47             : 
      48             : namespace pcr
      49             : {
      50             : 
      51             : 
      52             :     using ::com::sun::star::uno::Reference;
      53             :     using ::com::sun::star::lang::XMultiComponentFactory;
      54             :     using ::com::sun::star::beans::PropertyChangeEvent;
      55             :     using ::com::sun::star::uno::RuntimeException;
      56             :     using ::com::sun::star::frame::XFrame;
      57             :     using ::com::sun::star::awt::XTopWindow;
      58             :     using ::com::sun::star::awt::XWindow;
      59             :     using ::com::sun::star::uno::Exception;
      60             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      61             :     using ::com::sun::star::uno::UNO_QUERY;
      62             :     using ::com::sun::star::beans::PropertyValue;
      63             :     using ::com::sun::star::uno::Sequence;
      64             :     using ::com::sun::star::lang::XComponent;
      65             :     using ::com::sun::star::frame::XComponentLoader;
      66             :     using ::com::sun::star::beans::XPropertySet;
      67             :     using ::com::sun::star::beans::XPropertySetInfo;
      68             :     using ::com::sun::star::frame::XController;
      69             :     using ::com::sun::star::frame::XTitle;
      70             :     using ::com::sun::star::lang::EventObject;
      71             :     using ::com::sun::star::lang::NullPointerException;
      72             :     using ::com::sun::star::lang::DisposedException;
      73             :     using ::com::sun::star::uno::makeAny;
      74             :     using ::com::sun::star::uno::XComponentContext;
      75             :     using ::com::sun::star::frame::XFramesSupplier;
      76             :     using ::com::sun::star::frame::XFrames;
      77             :     using ::com::sun::star::util::XCloseable;
      78             :     using ::com::sun::star::uno::TypeClass_STRING;
      79             :     using ::com::sun::star::lang::XMultiServiceFactory;
      80             :     using ::com::sun::star::frame::XDispatchProvider;
      81             :     using ::com::sun::star::frame::XDispatch;
      82             :     using ::com::sun::star::frame::Desktop;
      83             :     using ::com::sun::star::frame::XDesktop2;
      84             :     using ::com::sun::star::uno::Any;
      85             : 
      86             :     namespace FrameSearchFlag = ::com::sun::star::frame::FrameSearchFlag;
      87             :     namespace CommandType = ::com::sun::star::sdb::CommandType;
      88             : 
      89             : 
      90             :     //= ISQLCommandAdapter
      91             : 
      92             : 
      93           0 :     ISQLCommandAdapter::~ISQLCommandAdapter()
      94             :     {
      95           0 :     }
      96             : 
      97             : 
      98             :     //= SQLCommandDesigner
      99             : 
     100             : 
     101           0 :     SQLCommandDesigner::SQLCommandDesigner( const Reference< XComponentContext >& _rxContext,
     102             :             const ::rtl::Reference< ISQLCommandAdapter >& _rxPropertyAdapter,
     103             :             const ::dbtools::SharedConnection& _rConnection, const Link& _rCloseLink )
     104             :         :m_xContext( _rxContext )
     105             :         ,m_xConnection( _rConnection )
     106             :         ,m_xObjectAdapter( _rxPropertyAdapter )
     107           0 :         ,m_aCloseLink( _rCloseLink )
     108             :     {
     109           0 :         if ( m_xContext.is() )
     110           0 :             m_xORB = m_xContext->getServiceManager();
     111           0 :         if ( !m_xORB.is() || !_rxPropertyAdapter.is() || !m_xConnection.is() )
     112           0 :             throw NullPointerException();
     113             : 
     114           0 :         impl_doOpenDesignerFrame_nothrow();
     115           0 :     }
     116             : 
     117             : 
     118           0 :     SQLCommandDesigner::~SQLCommandDesigner()
     119             :     {
     120           0 :     }
     121             : 
     122             : 
     123           0 :     void SAL_CALL SQLCommandDesigner::propertyChange( const PropertyChangeEvent& Event ) throw (RuntimeException, std::exception)
     124             :     {
     125             :         OSL_ENSURE( m_xDesigner.is() && ( Event.Source == m_xDesigner ), "SQLCommandDesigner::propertyChange: where did this come from?" );
     126             : 
     127           0 :         if ( m_xDesigner.is() && ( Event.Source == m_xDesigner ) )
     128             :         {
     129             :             try
     130             :             {
     131           0 :                 if ( PROPERTY_ACTIVECOMMAND == Event.PropertyName )
     132             :                 {
     133           0 :                     OUString sCommand;
     134           0 :                     OSL_VERIFY( Event.NewValue >>= sCommand );
     135           0 :                     m_xObjectAdapter->setSQLCommand( sCommand );
     136             :                 }
     137           0 :                 else if ( PROPERTY_ESCAPE_PROCESSING == Event.PropertyName )
     138             :                 {
     139           0 :                     sal_Bool bEscapeProcessing( sal_False );
     140           0 :                     OSL_VERIFY( Event.NewValue >>= bEscapeProcessing );
     141           0 :                     m_xObjectAdapter->setEscapeProcessing( bEscapeProcessing );
     142             :                 }
     143             :             }
     144           0 :             catch( const RuntimeException& ) { throw; }
     145           0 :             catch( const Exception& )
     146             :             {
     147             :                 // not allowed to leave, so silence it
     148             :                 DBG_UNHANDLED_EXCEPTION();
     149             :             }
     150             :         }
     151           0 :     }
     152             : 
     153             : 
     154           0 :     void SAL_CALL SQLCommandDesigner::disposing( const EventObject& Source ) throw (RuntimeException, std::exception)
     155             :     {
     156           0 :         if ( m_xDesigner.is() && ( Source.Source == m_xDesigner ) )
     157             :         {
     158           0 :             impl_designerClosed_nothrow();
     159           0 :             m_xDesigner.clear();
     160             :         }
     161           0 :     }
     162             : 
     163             : 
     164           0 :     void SQLCommandDesigner::dispose()
     165             :     {
     166           0 :         if ( impl_isDisposed() )
     167           0 :             return;
     168             : 
     169           0 :         if ( isActive() )
     170           0 :             impl_closeDesigner_nothrow();
     171             : 
     172           0 :         m_xConnection.clear();
     173           0 :         m_xContext.clear();
     174           0 :         m_xORB.clear();
     175             :     }
     176             : 
     177             : 
     178           0 :     void SQLCommandDesigner::impl_checkDisposed_throw() const
     179             :     {
     180           0 :         if ( impl_isDisposed() )
     181           0 :             throw DisposedException();
     182           0 :     }
     183             : 
     184             : 
     185           0 :     void SQLCommandDesigner::raise() const
     186             :     {
     187           0 :         impl_checkDisposed_throw();
     188           0 :         impl_raise_nothrow();
     189           0 :     }
     190             : 
     191             : 
     192           0 :     bool SQLCommandDesigner::suspend() const
     193             :     {
     194           0 :         impl_checkDisposed_throw();
     195           0 :         return impl_trySuspendDesigner_nothrow();
     196             :     }
     197             : 
     198             : 
     199           0 :     void SQLCommandDesigner::impl_raise_nothrow() const
     200             :     {
     201             :         OSL_PRECOND( isActive(), "SQLCommandDesigner::impl_raise_nothrow: not active!" );
     202           0 :         if ( !isActive() )
     203           0 :             return;
     204             : 
     205             :         try
     206             :         {
     207             :             // activate the frame for this component
     208           0 :             Reference< XFrame >     xFrame( m_xDesigner->getFrame(), UNO_QUERY_THROW );
     209           0 :             Reference< XWindow >    xWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
     210           0 :             Reference< XTopWindow > xTopWindow( xWindow, UNO_QUERY_THROW );
     211             : 
     212           0 :             xTopWindow->toFront();
     213           0 :             xWindow->setFocus();
     214             :         }
     215           0 :         catch( const Exception& )
     216             :         {
     217             :             DBG_UNHANDLED_EXCEPTION();
     218             :         }
     219             :     }
     220             : 
     221             : 
     222           0 :     void SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow()
     223             :     {
     224             :         OSL_PRECOND( !isActive(),
     225             :             "SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow: already active!" );
     226             :         OSL_PRECOND( m_xConnection.is(), "SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow: this will crash!" );
     227           0 :         osl_atomic_increment(&m_refCount);
     228             : 
     229             :         try
     230             :         {
     231             :             // for various reasons, we don't want the new frame to appear in the desktop's frame list
     232             :             // thus, we create a blank frame at the desktop, remove it from the desktop's frame list
     233             :             // immediately, and then load the component into this blank (and now parent-less) frame
     234           0 :             Reference< XComponentLoader > xLoader( impl_createEmptyParentlessTask_nothrow(), UNO_QUERY_THROW );
     235           0 :             Sequence< PropertyValue > aArgs( 5 );
     236           0 :             aArgs[0].Name = PROPERTY_ACTIVE_CONNECTION;
     237           0 :             aArgs[0].Value <<= m_xConnection.getTyped();
     238             : 
     239           0 :             aArgs[1].Name  = PROPERTY_COMMAND;
     240           0 :             aArgs[1].Value <<= m_xObjectAdapter->getSQLCommand();
     241           0 :             aArgs[2].Name  = PROPERTY_COMMANDTYPE;
     242           0 :             aArgs[2].Value <<= (sal_Int32)CommandType::COMMAND;
     243           0 :             aArgs[3].Name  = PROPERTY_ESCAPE_PROCESSING;
     244           0 :             aArgs[3].Value <<= m_xObjectAdapter->getEscapeProcessing();
     245             : 
     246           0 :             aArgs[4].Name  = "GraphicalDesign";
     247           0 :             aArgs[4].Value <<= m_xObjectAdapter->getEscapeProcessing();
     248             : 
     249           0 :             Reference< XComponent > xQueryDesign = xLoader->loadComponentFromURL(
     250             :                 OUString( ".component:DB/QueryDesign" ),
     251             :                 OUString( "_self" ),
     252             :                 FrameSearchFlag::TASKS | FrameSearchFlag::CREATE,
     253             :                 aArgs
     254           0 :             );
     255             : 
     256             :             // remember this newly loaded component - we need to care for it e.g. when we're suspended
     257           0 :             m_xDesigner = m_xDesigner.query( xQueryDesign );
     258             :             OSL_ENSURE( m_xDesigner.is() || !xQueryDesign.is(), "SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow: the component is expected to be a controller!" );
     259           0 :             if ( m_xDesigner.is() )
     260             :             {
     261           0 :                 Reference< XPropertySet > xQueryDesignProps( m_xDesigner, UNO_QUERY );
     262             :                 OSL_ENSURE( xQueryDesignProps.is(), "SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow: the controller should have properties!" );
     263           0 :                 if ( xQueryDesignProps.is() )
     264             :                 {
     265           0 :                     xQueryDesignProps->addPropertyChangeListener( PROPERTY_ACTIVECOMMAND, this );
     266           0 :                     xQueryDesignProps->addPropertyChangeListener( PROPERTY_ESCAPE_PROCESSING, this );
     267           0 :                 }
     268             :             }
     269             : 
     270             :             // get the frame which we just opened and set its title
     271           0 :             Reference< XTitle> xTitle(xQueryDesign,UNO_QUERY);
     272           0 :             if ( xTitle.is() )
     273             :             {
     274           0 :                 ::svt::OLocalResourceAccess aEnumStrings( PcrRes( RID_RSC_ENUM_COMMAND_TYPE ), RSC_RESOURCE );
     275           0 :                 OUString sDisplayName = PcrRes(CommandType::COMMAND + 1).toString();
     276           0 :                 xTitle->setTitle( sDisplayName );
     277           0 :             }
     278             :         }
     279           0 :         catch( const Exception& )
     280             :         {
     281             :             DBG_UNHANDLED_EXCEPTION();
     282           0 :             m_xDesigner.clear();
     283             :         }
     284           0 :         osl_atomic_decrement(&m_refCount);
     285           0 :     }
     286             : 
     287             : 
     288           0 :     Reference< XFrame > SQLCommandDesigner::impl_createEmptyParentlessTask_nothrow( ) const
     289             :     {
     290             :         OSL_PRECOND( m_xORB.is(), "SQLCommandDesigner::impl_createEmptyParentlessTask_nothrow: this will crash!" );
     291             : 
     292           0 :         Reference< XFrame > xFrame;
     293             :         try
     294             :         {
     295           0 :             Reference< XDesktop2 > xDesktop = Desktop::create(m_xContext);
     296             : 
     297           0 :             Reference< XFrames > xDesktopFramesCollection( xDesktop->getFrames(), UNO_QUERY_THROW );
     298           0 :             xFrame = xDesktop->findFrame( OUString( "_blank" ), FrameSearchFlag::CREATE );
     299             :             OSL_ENSURE( xFrame.is(), "SQLCommandDesigner::impl_createEmptyParentlessTask_nothrow: could not create an empty frame!" );
     300           0 :             xDesktopFramesCollection->remove( xFrame );
     301             :         }
     302           0 :         catch( const Exception& )
     303             :         {
     304             :             DBG_UNHANDLED_EXCEPTION();
     305             :         }
     306           0 :         return xFrame;
     307             :     }
     308             : 
     309             : 
     310           0 :     void SQLCommandDesigner::impl_designerClosed_nothrow()
     311             :     {
     312           0 :         if ( m_aCloseLink.IsSet() )
     313           0 :             m_aCloseLink.Call( this );
     314           0 :     }
     315             : 
     316             : 
     317           0 :     void SQLCommandDesigner::impl_closeDesigner_nothrow()
     318             :     {
     319             :         OSL_PRECOND( isActive(), "SQLCommandDesigner::impl_closeDesigner_nothrow: invalid calle!" );
     320             :         // close it
     321             :         try
     322             :         {
     323             :             // do not listen anymore ....
     324           0 :             Reference< XPropertySet > xProps( m_xDesigner, UNO_QUERY );
     325           0 :             if ( xProps.is() )
     326           0 :                 xProps->removePropertyChangeListener( PROPERTY_ACTIVECOMMAND, this );
     327             : 
     328             :             // we need to close the frame via the "user interface", by dispatching a close command,
     329             :             // instead of calling XCloseable::close directly. The latter method would also close
     330             :             // the frame, but not care for things like shutting down the office when the last
     331             :             // frame is gone ...
     332             :             const UnoURL aCloseURL( OUString( ".uno:CloseDoc" ),
     333           0 :                 Reference< XMultiServiceFactory >( m_xORB, UNO_QUERY ) );
     334             : 
     335           0 :             Reference< XDispatchProvider > xProvider( m_xDesigner->getFrame(), UNO_QUERY_THROW );
     336           0 :             Reference< XDispatch > xDispatch( xProvider->queryDispatch( aCloseURL, OUString( "_top" ), FrameSearchFlag::SELF ) );
     337             :             OSL_ENSURE( xDispatch.is(), "SQLCommandDesigner::impl_closeDesigner_nothrow: no dispatcher for the CloseDoc command!" );
     338           0 :             if ( xDispatch.is() )
     339             :             {
     340           0 :                 xDispatch->dispatch( aCloseURL, Sequence< PropertyValue >( ) );
     341             :             }
     342             :             else
     343             :             {
     344             :                 // fallback: use the XCloseable::close (with all possible disadvantages)
     345           0 :                 Reference< XCloseable > xClose( m_xDesigner->getFrame(), UNO_QUERY );
     346           0 :                 if ( xClose.is() )
     347           0 :                     xClose->close( sal_True );
     348           0 :             }
     349             :         }
     350           0 :         catch( const Exception& )
     351             :         {
     352             :             DBG_UNHANDLED_EXCEPTION();
     353             :         }
     354             : 
     355           0 :         m_xDesigner.clear();
     356           0 :     }
     357             : 
     358             : 
     359           0 :     bool SQLCommandDesigner::impl_trySuspendDesigner_nothrow() const
     360             :     {
     361             :         OSL_PRECOND( isActive(), "SQLCommandDesigner::impl_trySuspendDesigner_nothrow: no active designer, this will crash!" );
     362           0 :         sal_Bool bAllow = sal_True;
     363             :         try
     364             :         {
     365           0 :             bAllow = m_xDesigner->suspend( sal_True );
     366             :         }
     367           0 :         catch( const Exception& )
     368             :         {
     369             :             DBG_UNHANDLED_EXCEPTION();
     370             :         }
     371           0 :         return bAllow;
     372             :     }
     373             : 
     374             : 
     375             : } // namespace pcr
     376             : 
     377             : 
     378             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10