diff options
author | RĂ¼diger Timm <rt@openoffice.org> | 2007-07-06 07:38:03 +0000 |
---|---|---|
committer | RĂ¼diger Timm <rt@openoffice.org> | 2007-07-06 07:38:03 +0000 |
commit | 86061e8e77f13742cb73d86e036fede712fe1be1 (patch) | |
tree | c68d8600f02b18c4085d83ba66c33079a9e4b2a1 /dbaccess/source/ui/misc/singledoccontroller.cxx | |
parent | c1c0281cee912c756bfab588ba31c7db64d8a899 (diff) |
INTEGRATION: CWS oj14 (1.16.4); FILE MERGED
2007/06/04 18:50:02 oj 1.16.4.9: RESYNC: (1.20-1.21); FILE MERGED
2006/12/21 12:30:02 oj 1.16.4.8: impl selectionSupplier
2006/11/13 13:23:56 oj 1.16.4.7: merge conflicts
2006/11/08 11:15:28 oj 1.16.4.6: merge conflicts resolved
2006/11/07 09:39:24 oj 1.16.4.5: RESYNC: (1.17-1.19); FILE MERGED
2006/07/04 08:15:49 oj 1.16.4.4: RESYNC: (1.16-1.17); FILE MERGED
2006/04/25 13:03:20 oj 1.16.4.3: new include
2006/03/20 07:48:50 oj 1.16.4.2: use of module client helper
2006/01/03 07:49:22 oj 1.16.4.1: changed module client
Diffstat (limited to 'dbaccess/source/ui/misc/singledoccontroller.cxx')
-rw-r--r-- | dbaccess/source/ui/misc/singledoccontroller.cxx | 226 |
1 files changed, 165 insertions, 61 deletions
diff --git a/dbaccess/source/ui/misc/singledoccontroller.cxx b/dbaccess/source/ui/misc/singledoccontroller.cxx index 64ba1ea9e4f5..fa2a0994ec06 100644 --- a/dbaccess/source/ui/misc/singledoccontroller.cxx +++ b/dbaccess/source/ui/misc/singledoccontroller.cxx @@ -4,9 +4,9 @@ * * $RCSfile: singledoccontroller.cxx,v $ * - * $Revision: 1.21 $ + * $Revision: 1.22 $ * - * last change: $Author: ihi $ $Date: 2007-04-16 16:29:08 $ + * last change: $Author: rt $ $Date: 2007-07-06 08:38:03 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -84,22 +84,62 @@ #ifndef _DBHELPER_DBEXCEPTION_HXX_ #include <connectivity/dbexception.hxx> #endif +#ifndef _CONNECTIVITY_DBTOOLS_HXX_ +#include <connectivity/dbtools.hxx> +#endif #ifndef DBACCESS_UI_BROWSER_ID_HXX #include "browserids.hxx" #endif - +#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ +#include <toolkit/unohlp.hxx> +#endif +#ifndef _DBAUI_MODULE_DBU_HXX_ +#include "moduledbu.hxx" +#endif +#ifndef _DBAUI_COMMON_TYPES_HXX_ +#include "commontypes.hxx" +#endif //........................................................................ namespace dbaui { //........................................................................ - - using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::beans; - using namespace ::com::sun::star::lang; - using namespace ::com::sun::star::container; - using namespace ::com::sun::star::sdbc; - using namespace ::com::sun::star::sdb; - using namespace ::com::sun::star::frame; + using namespace ::com::sun::star; + using namespace uno; + using namespace beans; + using namespace lang; + using namespace container; + using namespace sdbc; + using namespace sdb; + using namespace frame; + using namespace util; + + struct OSingleDocumentControllerImpl + { + OModuleClient m_aModuleClient; + uno::Any m_aCurrentError; // contains the current error which can be set through IEnvironment + + // <properties> + SharedConnection m_xConnection; + ::dbtools::DatabaseMetaData m_aSdbMetaData; + // </properties> + ::rtl::OUString m_sDataSourceName; // the data source we're working for + uno::Reference< beans::XPropertySet > + m_xDataSource; + uno::Reference< util::XNumberFormatter > + m_xFormatter; // a number formatter working with the connection's NumberFormatsSupplier + ModelControllerConnector + m_aModelConnector; + sal_Bool m_bSuspended : 1; // is true when the controller was already suspended + sal_Bool m_bEditable : 1; // is the control readonly or not + sal_Bool m_bModified : 1; // is the data modified + + OSingleDocumentControllerImpl() : + m_bSuspended( sal_False ) + ,m_bEditable(sal_True) + ,m_bModified(sal_False) + { + } + }; //==================================================================== //= OSingleDocumentController @@ -107,14 +147,35 @@ namespace dbaui //-------------------------------------------------------------------- OSingleDocumentController::OSingleDocumentController(const Reference< XMultiServiceFactory >& _rxORB) :OSingleDocumentController_CBASE( _rxORB ) - ,m_bSuspended( sal_False ) - ,m_bEditable(sal_True) - ,m_bModified(sal_False) - + ,m_pImpl(new OSingleDocumentControllerImpl()) { } + //-------------------------------------------------------------------- + OSingleDocumentController::~OSingleDocumentController() + { + } + //-------------------------------------------------------------------- + Sequence<sal_Int8> SAL_CALL OSingleDocumentController::getImplementationId( ) throw(RuntimeException) + { + static ::cppu::OImplementationId * pId = 0; + if (! pId) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if (! pId) + { + static ::cppu::OImplementationId aId; + pId = &aId; + } + } + return pId->getImplementationId(); + } //-------------------------------------------------------------------- + Sequence< Type > SAL_CALL OSingleDocumentController::getTypes( ) throw (RuntimeException) + { + return OSingleDocumentController_CBASE::getTypes(); + } + //-------------------------------------------------------------------- void OSingleDocumentController::initializeConnection( const Reference< XConnection >& _rxForeignConn ) { DBG_ASSERT( !isConnected(), "OSingleDocumentController::initializeConnection: not to be called when already connected!" ); @@ -122,45 +183,53 @@ namespace dbaui if ( isConnected() ) disconnect(); - m_xConnection.reset( _rxForeignConn, SharedConnection::NoTakeOwnership ); - m_aSdbMetaData.reset( m_xConnection ); - startConnectionListening( m_xConnection ); + m_pImpl->m_xConnection.reset( _rxForeignConn, SharedConnection::NoTakeOwnership ); + m_pImpl->m_aSdbMetaData.reset( m_pImpl->m_xConnection ); + startConnectionListening( m_pImpl->m_xConnection ); // get the data source the connection belongs to - if ( !m_xDataSource.is() ) + try { - try + if ( !m_pImpl->m_xDataSource.is() ) { - Reference< XChild > xConnAsChild( m_xConnection, UNO_QUERY ); + Reference< XChild > xConnAsChild( m_pImpl->m_xConnection, UNO_QUERY ); Reference< XDataSource > xDS; if ( xConnAsChild.is() ) xDS = Reference< XDataSource >( xConnAsChild->getParent(), UNO_QUERY ); // (take the indirection through XDataSource to ensure we have a correct object ....) - m_xDataSource.set(xDS,UNO_QUERY); - DBG_ASSERT( m_xDataSource.is(), "OSingleDocumentController::initializeConnection: could not retrieve the data source!" ); + m_pImpl->m_xDataSource.set(xDS,UNO_QUERY); + DBG_ASSERT( m_pImpl->m_xDataSource.is(), "OSingleDocumentController::initializeConnection: could not retrieve the data source!" ); + } - if ( m_xDataSource.is() ) + if ( m_pImpl->m_xDataSource.is() ) + { + m_pImpl->m_xDataSource->getPropertyValue( PROPERTY_NAME ) >>= m_pImpl->m_sDataSourceName; + DBG_ASSERT( m_pImpl->m_sDataSourceName.getLength(), "OSingleDocumentController::initializeConnection: invalid data source name!" ); + Reference< XNumberFormatsSupplier> xSupplier = ::dbtools::getNumberFormats(m_pImpl->m_xConnection); + if(xSupplier.is()) { - m_xDataSource->getPropertyValue( PROPERTY_NAME ) >>= m_sDataSourceName; - DBG_ASSERT( m_sDataSourceName.getLength(), "OSingleDocumentController::initializeConnection: invalid data source name!" ); + m_pImpl->m_xFormatter = Reference< util::XNumberFormatter >(getORB() + ->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.NumberFormatter")), UNO_QUERY); + m_pImpl->m_xFormatter->attachNumberFormatsSupplier(xSupplier); } - } - catch( const Exception& ) - { - DBG_ERROR( "OSingleDocumentController::initializeConnection: caught an exception!" ); + OSL_ENSURE(m_pImpl->m_xFormatter.is(),"No NumberFormatter!"); } } + catch( const Exception& ) + { + DBG_ERROR( "OSingleDocumentController::initializeConnection: caught an exception!" ); + } } //-------------------------------------------------------------------- void OSingleDocumentController::reconnect( sal_Bool _bUI ) { - OSL_ENSURE(!m_bSuspended, "Cannot reconnect while suspended!"); + OSL_ENSURE(!m_pImpl->m_bSuspended, "Cannot reconnect while suspended!"); - stopConnectionListening( m_xConnection ); - m_aSdbMetaData.reset( NULL ); - m_xConnection.clear(); + stopConnectionListening( m_pImpl->m_xConnection ); + m_pImpl->m_aSdbMetaData.reset( NULL ); + m_pImpl->m_xConnection.clear(); // reconnect sal_Bool bReConnect = sal_True; @@ -173,8 +242,8 @@ namespace dbaui // now really reconnect ... if ( bReConnect ) { - m_xConnection.reset( connect( Reference<XDataSource>(m_xDataSource,UNO_QUERY), sal_True ), SharedConnection::TakeOwnership ); - m_aSdbMetaData.reset( m_xConnection ); + m_pImpl->m_xConnection.reset( connect( Reference<XDataSource>(m_pImpl->m_xDataSource,UNO_QUERY), sal_True ), SharedConnection::TakeOwnership ); + m_pImpl->m_aSdbMetaData.reset( m_pImpl->m_xConnection ); } // invalidate all slots @@ -184,9 +253,9 @@ namespace dbaui //-------------------------------------------------------------------- void OSingleDocumentController::disconnect() { - stopConnectionListening(m_xConnection); - m_aSdbMetaData.reset( NULL ); - m_xConnection.clear(); + stopConnectionListening(m_pImpl->m_xConnection); + m_pImpl->m_aSdbMetaData.reset( NULL ); + m_pImpl->m_xConnection.clear(); InvalidateAll(); } @@ -208,7 +277,7 @@ namespace dbaui attachFrame( Reference < XFrame >() ); - m_xDataSource.clear(); + m_pImpl->m_xDataSource.clear(); } //-------------------------------------------------------------------- @@ -226,7 +295,7 @@ namespace dbaui { if ( _rSource.Source == getConnection() ) { - if ( !m_bSuspended // when already suspended then we don't have to reconnect + if ( !m_pImpl->m_bSuspended // when already suspended then we don't have to reconnect && !getBroadcastHelper().bInDispose && !getBroadcastHelper().bDisposed && isConnected() @@ -236,7 +305,7 @@ namespace dbaui } else { - m_xConnection.reset( m_xConnection, SharedConnection::NoTakeOwnership ); + m_pImpl->m_xConnection.reset( m_pImpl->m_xConnection, SharedConnection::NoTakeOwnership ); // this prevents the "disposeComponent" call in disconnect disconnect(); } @@ -274,35 +343,35 @@ namespace dbaui @param _aException contains a description of the error or the error directly */ - void OSingleDocumentController::appendError(const ::com::sun::star::sdbc::SQLException& _aException) + void OSingleDocumentController::appendError(const sdbc::SQLException& _aException) { - concatSQLExceptions(m_aCurrentError,makeAny(_aException)); + concatSQLExceptions(m_pImpl->m_aCurrentError,makeAny(_aException)); } //-------------------------------------------------------------------- /** clears the error state. */ void OSingleDocumentController::clearError() { - m_aCurrentError = Any(); + m_pImpl->m_aCurrentError = Any(); } //-------------------------------------------------------------------- /** set the current error in the given parameter. @param _rException will contain the current error */ - void OSingleDocumentController::getError(::com::sun::star::sdbc::SQLException& _rException ) const + void OSingleDocumentController::getError(sdbc::SQLException& _rException ) const { - m_aCurrentError >>= _rException; + m_pImpl->m_aCurrentError >>= _rException; } //-------------------------------------------------------------------- sal_Bool OSingleDocumentController::hasError() const { - return m_aCurrentError.hasValue(); + return m_pImpl->m_aCurrentError.hasValue(); } //-------------------------------------------------------------------- sal_Bool SAL_CALL OSingleDocumentController::suspend(sal_Bool bSuspend) throw( RuntimeException ) { - m_bSuspended = bSuspend; + m_pImpl->m_bSuspended = bSuspend; if ( !bSuspend && !isConnected() ) reconnect(sal_True); @@ -319,7 +388,7 @@ namespace dbaui switch (_nId) { case ID_BROWSER_UNDO: - aReturn.bEnabled = m_bEditable && m_aUndoManager.GetUndoActionCount() != 0; + aReturn.bEnabled = m_pImpl->m_bEditable && m_aUndoManager.GetUndoActionCount() != 0; if ( aReturn.bEnabled ) { String sUndo(ModuleRes(STR_UNDO_COLON)); @@ -329,7 +398,7 @@ namespace dbaui } break; case ID_BROWSER_REDO: - aReturn.bEnabled = m_bEditable && m_aUndoManager.GetRedoActionCount() != 0; + aReturn.bEnabled = m_pImpl->m_bEditable && m_aUndoManager.GetRedoActionCount() != 0; if ( aReturn.bEnabled ) { String sRedo(ModuleRes(STR_REDO_COLON)); @@ -381,7 +450,7 @@ namespace dbaui // ----------------------------------------------------------------------------- void OSingleDocumentController::setModified(sal_Bool _bModified) { - m_bModified = _bModified; + m_pImpl->m_bModified = _bModified; InvalidateFeature(ID_BROWSER_SAVEDOC); if ( isFeatureSupported( ID_BROWSER_SAVEASDOC ) ) @@ -390,7 +459,7 @@ namespace dbaui // ----------------------------------------------------------------------------- Reference< XModel > SAL_CALL OSingleDocumentController::getModel(void) throw( RuntimeException ) { - return NULL;//Reference< XModel >(m_xDataSource,UNO_QUERY); // OJ: i31891 + return NULL;//Reference< XModel >(m_pImpl->m_xDataSource,UNO_QUERY); // OJ: i31891 } // ----------------------------------------------------------------------------- sal_Bool SAL_CALL OSingleDocumentController::attachModel(const Reference< XModel > & _rxModel) throw( RuntimeException ) @@ -398,18 +467,53 @@ namespace dbaui ::osl::MutexGuard aGuard( m_aMutex ); Reference< XOfficeDatabaseDocument > xOfficeDoc( _rxModel, UNO_QUERY ); - m_xDataSource.set( xOfficeDoc.is() ? xOfficeDoc->getDataSource() : Reference<XDataSource>(), UNO_QUERY ); + m_pImpl->m_xDataSource.set( xOfficeDoc.is() ? xOfficeDoc->getDataSource() : Reference<XDataSource>(), UNO_QUERY ); return sal_True; } // ----------------------------------------------------------------------------- - ::rtl::OUString OSingleDocumentController::getDataSourceName() const - { - ::rtl::OUString sName; - if ( m_xDataSource.is() ) - m_xDataSource->getPropertyValue(PROPERTY_NAME) >>= sName; - return sName; - } + ::rtl::OUString OSingleDocumentController::getDataSourceName() const + { + ::rtl::OUString sName; + if ( m_pImpl->m_xDataSource.is() ) + m_pImpl->m_xDataSource->getPropertyValue(PROPERTY_NAME) >>= sName; + return sName; + } + // ----------------------------------------------------------------------------- + void OSingleDocumentController::connectionLostMessage() const + { + String aMessage(ModuleRes(RID_STR_CONNECTION_LOST)); + Reference< awt::XWindow> xWindow = getTopMostContainerWindow(); + Window* pWin = NULL; + if ( xWindow.is() ) + pWin = VCLUnoHelper::GetWindow(xWindow); + if ( !pWin ) + pWin = getView()->Window::GetParent(); + + InfoBox(pWin, aMessage).Execute(); + } + // ----------------------------------------------------------------------------- + const Reference< XConnection >& + OSingleDocumentController::getConnection() const + { + return m_pImpl->m_xConnection; + } + // ----------------------------------------------------------------------------- + sal_Bool OSingleDocumentController::isReadOnly() const { return !m_pImpl->m_bEditable; } + sal_Bool OSingleDocumentController::isEditable() const { return m_pImpl->m_bEditable; } + sal_Bool OSingleDocumentController::isModified() const { return m_pImpl->m_bModified; } + void OSingleDocumentController::setEditable(sal_Bool _bEditable) { m_pImpl->m_bEditable = _bEditable; } + const ::dbtools::DatabaseMetaData& OSingleDocumentController::getSdbMetaData() const { return m_pImpl->m_aSdbMetaData; } + sal_Bool OSingleDocumentController::isConnected() const { return m_pImpl->m_xConnection.is(); } + uno::Reference< sdbc::XDatabaseMetaData > + OSingleDocumentController::getMetaData( ) const + { + return isConnected() ? m_pImpl->m_xConnection->getMetaData() : uno::Reference< sdbc::XDatabaseMetaData >(); + } + const uno::Reference< beans::XPropertySet >& + OSingleDocumentController::getDataSource() const { return m_pImpl->m_xDataSource; } + sal_Bool OSingleDocumentController::haveDataSource() const { return m_pImpl->m_xDataSource.is(); } + uno::Reference< util::XNumberFormatter > OSingleDocumentController::getNumberFormatter() const { return m_pImpl->m_xFormatter; } //........................................................................ } // namespace dbaui //........................................................................ |