Tag: cws_src680_qiq User: fs Date: 06/05/10 04:08:41 Modified: /dba/dbaccess/source/ui/querydesign/ TableWindow.cxx
Log: #i51143# potentially allow to hold a query as well File Changes: Directory: /dba/dbaccess/source/ui/querydesign/ =============================================== File [changed]: TableWindow.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/querydesign/TableWindow.cxx?r1=1.30&r2=1.30.122.1 Delta lines: +104 -83 ---------------------- --- TableWindow.cxx 8 Sep 2005 16:30:11 -0000 1.30 +++ TableWindow.cxx 10 May 2006 11:08:39 -0000 1.30.122.1 @@ -4,9 +4,9 @@ * * $RCSfile: TableWindow.cxx,v $ * - * $Revision: 1.30 $ + * $Revision: 1.30.122.1 $ * - * last change: $Author: rt $ $Date: 2005/09/08 16:30:11 $ + * last change: $Author: fs $ $Date: 2006/05/10 11:08:39 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -50,12 +50,18 @@ #ifndef _TOOLS_DEBUG_HXX #include <tools/debug.hxx> #endif +#ifndef TOOLS_DIAGNOSE_EX_H +#include <tools/diagnose_ex.h> +#endif #ifndef _SV_SVAPP_HXX #include <vcl/svapp.hxx> #endif #ifndef _SV_WALL_HXX #include <vcl/wall.hxx> #endif +#ifndef _COM_SUN_STAR_SDB_XQUERIESSUPPLIER_HPP_ +#include <com/sun/star/sdb/XQueriesSupplier.hpp> +#endif #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_ #include <com/sun/star/sdbcx/XTablesSupplier.hpp> #endif @@ -107,6 +113,7 @@ using namespace dbaui; using namespace ::utl; +using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::uno; @@ -138,6 +145,7 @@ ,m_nMoveCount(0) ,m_nMoveIncrement(1) ,m_pAccessible(NULL) + ,m_bIsQuery( false ) { DBG_CTOR(OTableWindow,NULL); // ich uebernehme nicht die Verantwortung fuer die Daten, ich merke mir nur den Zeiger darauf @@ -164,9 +172,11 @@ OTableWindow::~OTableWindow() { DBG_DTOR(OTableWindow,NULL); - Reference<XComponent> xComponent(m_xTable,UNO_QUERY); - if(xComponent.is()) - stopComponentListening(xComponent); + + Reference<XComponent> xComponent( m_xTableOrQuery, UNO_QUERY ); + if ( xComponent.is() ) + stopComponentListening( xComponent ); + if (m_pListBox) { OSL_ENSURE(m_pListBox->GetEntryCount()==0,"Forgot to call EmptyListbox()!"); @@ -244,9 +254,8 @@ try { // first we need the keys from the table - Reference<XKeysSupplier> xKeys(m_xTable,UNO_QUERY); - - if(xKeys.is()) + Reference< XKeysSupplier > xKeys( m_xTableOrQuery, UNO_QUERY ); + if ( xKeys.is() ) { Reference< XIndexAccess> xKeyIndex = xKeys->getKeys(); Reference<XColumnsSupplier> xColumnsSupplier; @@ -342,62 +351,69 @@ //------------------------------------------------------------------------------ BOOL OTableWindow::Init() { + bool bSuccess = false; + // get the from the connection OJoinDesignView* pParent = getDesignView(); - Reference<XConnection > xConnection = pParent->getController()->getConnection(); - Reference<XTablesSupplier> xSups(xConnection,UNO_QUERY); - OSL_ENSURE(xSups.is(),"The connection isn't a tablessupplier!"); - sal_Bool bInit = sal_False; - if(xSups.is()) - { - Reference<XNameAccess> xTables = xSups->getTables(); - - ::rtl::OUString aName = GetComposedName(); - if(xTables->hasByName(aName)) - { - ::osl::MutexGuard aGuard( m_aMutex ); try { - ::cppu::extractInterface(m_xTable,xTables->getByName(aName)); - if(m_xTable.is()) - { - Reference<XComponent> xComponent(m_xTable,UNO_QUERY); - if(xComponent.is()) - startComponentListening(xComponent); - Reference<XColumnsSupplier> xColumnsSups(m_xTable,UNO_QUERY); - OSL_ENSURE(xColumnsSups.is(),"OTableWindow::Init Table isn't a XColumnsSupplier!"); - if(xColumnsSups.is()) - { + ::osl::MutexGuard aGuard( m_aMutex ); + + Reference< XConnection > xConnection = pParent->getController()->getConnection(); + ::rtl::OUString sObjectName = GetComposedName(); + + Reference< XQueriesSupplier > xSupQueries( xConnection, UNO_QUERY_THROW ); + Reference< XNameAccess > xQueries( xSupQueries->getQueries(), UNO_QUERY_THROW ); + bool bIsKnownQuery = allowQueries() && xQueries->hasByName( sObjectName ); + + Reference< XTablesSupplier > xSupTables( xConnection, UNO_QUERY_THROW ); + Reference< XNameAccess > xTables( xSupTables->getTables(), UNO_QUERY_THROW ); + bool bIsKnownTable = xTables->hasByName( sObjectName ); + + if ( bIsKnownQuery ) + m_xTableOrQuery = Reference< XPropertySet >( xQueries->getByName( sObjectName ), UNO_QUERY_THROW ); + else if ( bIsKnownTable ) + m_xTableOrQuery = Reference< XPropertySet >( xTables->getByName( sObjectName ), UNO_QUERY_THROW ); + else + DBG_ERROR( "OTableWindow::Init: this is neither a query (or no queries are allowed) nor a table!" ); + + // if we survived so far, we know whether it's a query + m_bIsQuery = bIsKnownQuery; + + // listen for the object being disposed + Reference<XComponent> xComponent( m_xTableOrQuery, UNO_QUERY ); + if ( xComponent.is() ) + startComponentListening( xComponent ); + + // obtain the columns + Reference< XColumnsSupplier > xColumnsSups( m_xTableOrQuery, UNO_QUERY_THROW ); m_xColumns = xColumnsSups->getColumns(); - bInit = sal_True; - } - } + + bSuccess = true; } - catch(SQLException& e) + catch ( SQLException& e ) { - ::dbaui::showError(::dbtools::SQLExceptionInfo(e),pParent,pParent->getController()->getORB()); - bInit = FALSE; + ::dbaui::showError( ::dbtools::SQLExceptionInfo( e ), pParent, pParent->getController()->getORB() ); } - catch(WrappedTargetException& e) + catch( const WrappedTargetException& e ) { SQLException aSql; - if(e.TargetException >>= aSql) - ::dbaui::showError(::dbtools::SQLExceptionInfo(aSql),pParent,pParent->getController()->getORB()); - bInit = FALSE; + if ( e.TargetException >>= aSql ) + ::dbaui::showError( ::dbtools::SQLExceptionInfo( aSql ), pParent, pParent->getController()->getORB() ); } - catch(Exception&) + catch( const Exception& ) { - bInit = FALSE; + DBG_UNHANDLED_EXCEPTION(); } - if(bInit) + if ( bSuccess ) { - // ListBox anlegen, wenn notwendig - if (!m_pListBox) + // create list box if necessary + if ( !m_pListBox ) { m_pListBox = CreateListBox(); - DBG_ASSERT(m_pListBox != NULL, "OTableWindow::Init() : CreateListBox hat NULL geliefert !"); - m_pListBox->SetSelectionMode(MULTIPLE_SELECTION); + DBG_ASSERT( m_pListBox != NULL, "OTableWindow::Init() : CreateListBox hat NULL geliefert !" ); + m_pListBox->SetSelectionMode( MULTIPLE_SELECTION ); } // Titel setzen @@ -408,13 +424,18 @@ // die Felder in die ListBox eintragen clearListBox(); - if (bInit = FillListBox()) - m_pListBox->SelectAll(FALSE); - } - } + if ( bSuccess = FillListBox() ) + m_pListBox->SelectAll( FALSE ); } - return bInit; + return bSuccess; +} + +//------------------------------------------------------------------------------ +Reference< XPropertySet > OTableWindow::GetTable() const +{ + DBG_ASSERT( !isQuery(), "OTableWindow::GetTable: you should only call this if you're *sure* this is a table!" ); + return m_xTableOrQuery; } //------------------------------------------------------------------------------ @@ -726,7 +747,7 @@ void OTableWindow::_disposing( const ::com::sun::star::lang::EventObject& _rSource ) { ::osl::MutexGuard aGuard( m_aMutex ); - m_xTable = NULL; + m_xTableOrQuery = NULL; m_xColumns = NULL; } // ----------------------------------------------------------------------------- --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
