Tag: cws_dev300_dba30d User: fs Date: 2008-06-09 13:44:36+0000 Modified: dba/dbaccess/source/ui/control/tabletree.cxx
Log: #i80943# +describeObject File Changes: Directory: /dba/dbaccess/source/ui/control/ =========================================== File [changed]: tabletree.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/control/tabletree.cxx?r1=1.37&r2=1.37.10.1 Delta lines: +106 -20 ---------------------- --- tabletree.cxx 2008-05-05 15:55:34+0000 1.37 +++ tabletree.cxx 2008-06-09 13:44:33+0000 1.37.10.1 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: tabletree.cxx,v $ - * $Revision: 1.37 $ + * $Revision: 1.37.10.1 $ * * This file is part of OpenOffice.org. * @@ -61,6 +61,9 @@ #ifndef _COM_SUN_STAR_SDB_APPLICATION_DATABASEOBJECT_HPP_ #include <com/sun/star/sdb/application/DatabaseObject.hpp> #endif +#ifndef _COM_SUN_STAR_SDB_APPLICATION_DATABASEOBJECTFOLDER_HPP_ +#include <com/sun/star/sdb/application/DatabaseObjectFolder.hpp> +#endif #ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_ #include <com/sun/star/sdbc/XDriverAccess.hpp> #endif @@ -91,6 +94,9 @@ #ifndef TOOLS_DIAGNOSE_EX_H #include <tools/diagnose_ex.h> #endif +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif #include <algorithm> //......................................................................... @@ -105,11 +111,13 @@ using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; +using namespace ::com::sun::star::sdb::application; using namespace ::dbtools; using namespace ::comphelper; namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; +namespace DatabaseObjectFolder = ::com::sun::star::sdb::application::DatabaseObjectFolder; //======================================================================== //= OTableTreeListBox @@ -148,7 +156,13 @@ // ----------------------------------------------------------------------------- bool OTableTreeListBox::isFolderEntry( const SvLBoxEntry* _pEntry ) const { - return _pEntry->GetUserData() == reinterpret_cast< void* >(FOLDER_INDICATOR); + sal_Int32 nEntryType = reinterpret_cast< sal_IntPtr >( _pEntry->GetUserData() ); + if ( ( nEntryType == DatabaseObjectFolder::ALL_TABLES ) + || ( nEntryType == DatabaseObjectFolder::CATALOG ) + || ( nEntryType == DatabaseObjectFolder::SCHEMA ) + ) + return true; + return false; } // ----------------------------------------------------------------------------- @@ -314,7 +328,7 @@ sRootEntryText = String(ModuleRes(STR_ALL_VIEWS)); else sRootEntryText = String(ModuleRes(STR_ALL_TABLES_AND_VIEWS)); - pAllObjects = InsertEntry( sRootEntryText, NULL, FALSE, LIST_APPEND, reinterpret_cast< void* >( FOLDER_INDICATOR ) ); + pAllObjects = InsertEntry( sRootEntryText, NULL, FALSE, LIST_APPEND, reinterpret_cast< void* >( DatabaseObjectFolder::ALL_TABLES ) ); } if ( _rTables.empty() ) @@ -451,22 +465,34 @@ SvLBoxEntry* pParentEntry = getAllObjectsEntry(); - SvLBoxEntry* pCat = NULL; - SvLBoxEntry* pSchema = NULL; - if (sCatalog.getLength()) - { - pCat = GetEntryPosByName(sCatalog, pParentEntry); - if (!pCat) - pCat = InsertEntry( sCatalog, pParentEntry, FALSE, LIST_APPEND, reinterpret_cast< void* >( FOLDER_INDICATOR ) ); - pParentEntry = pCat; - } - - if (sSchema.getLength()) - { - pSchema = GetEntryPosByName(sSchema, pParentEntry); - if (!pSchema) - pSchema = InsertEntry( sSchema, pParentEntry, FALSE, LIST_APPEND, reinterpret_cast< void* >( FOLDER_INDICATOR ) ); - pParentEntry = pSchema; + // if the DB uses catalog at the start of identifiers, then our hierarchy is + // catalog + // +- schema + // +- table + // else it is + // schema + // +- catalog + // +- table + sal_Bool bCatalogAtStart = _rxMeta->isCatalogAtStart(); + ::rtl::OUString& nFirstName = bCatalogAtStart ? sCatalog : sSchema; + sal_Int32 nFirstFolderType = bCatalogAtStart ? DatabaseObjectFolder::CATALOG : DatabaseObjectFolder::SCHEMA; + ::rtl::OUString& nSecondName = bCatalogAtStart ? sSchema : sCatalog; + sal_Int32 nSecondFolderType = bCatalogAtStart ? DatabaseObjectFolder::SCHEMA : DatabaseObjectFolder::CATALOG; + + if ( nFirstName.getLength() ) + { + SvLBoxEntry* pFolder = GetEntryPosByName( nFirstName, pParentEntry ); + if ( !pFolder ) + pFolder = InsertEntry( nFirstName, pParentEntry, FALSE, LIST_APPEND, reinterpret_cast< void* >( nFirstFolderType ) ); + pParentEntry = pFolder; + } + + if ( nSecondName.getLength() ) + { + SvLBoxEntry* pFolder = GetEntryPosByName( nSecondName, pParentEntry ); + if ( !pFolder ) + pFolder = InsertEntry( nSecondName, pParentEntry, FALSE, LIST_APPEND, reinterpret_cast< void* >( nSecondFolderType ) ); + pParentEntry = pFolder; } SvLBoxEntry* pRet = NULL; @@ -486,6 +512,66 @@ } //------------------------------------------------------------------------ +NamedDatabaseObject OTableTreeListBox::describeObject( SvLBoxEntry* _pEntry ) +{ + NamedDatabaseObject aObject; + + sal_Int32 nEntryType = reinterpret_cast< sal_IntPtr >( _pEntry->GetUserData() ); + + if ( nEntryType == DatabaseObjectFolder::ALL_TABLES ) + { + aObject.Type = DatabaseObjectFolder::ALL_TABLES; + } + else if ( ( nEntryType == DatabaseObjectFolder::CATALOG ) + || ( nEntryType == DatabaseObjectFolder::SCHEMA ) + ) + { + ::rtl::OUString sCatalogSeparator; + try + { + Reference< XConnection > xConnection( m_xConnection, UNO_SET_THROW ); + Reference< XDatabaseMetaData > xMeta( xConnection->getMetaData(), UNO_SET_THROW ); + + sCatalogSeparator = xMeta->getCatalogSeparator(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + SvLBoxEntry* pParent = GetParent( _pEntry ); + sal_Int32 nParentEntryType = pParent ? reinterpret_cast< sal_IntPtr >( pParent->GetUserData() ) : -1; + + ::rtl::OUStringBuffer buffer; + if ( nEntryType == DatabaseObjectFolder::CATALOG ) + { + if ( nParentEntryType == DatabaseObjectFolder::SCHEMA ) + { + buffer.append( GetEntryText( pParent ) ); + buffer.append( sCatalogSeparator ); + } + buffer.append( GetEntryText( _pEntry ) ); + } + else if ( nEntryType == DatabaseObjectFolder::SCHEMA ) + { + if ( nParentEntryType == DatabaseObjectFolder::CATALOG ) + { + buffer.append( GetEntryText( pParent ) ); + buffer.append( sCatalogSeparator ); + } + buffer.append( GetEntryText( _pEntry ) ); + } + } + else + { + aObject.Type = DatabaseObject::TABLE; + aObject.Name = getQualifiedTableName( _pEntry ); + } + + return aObject; +} + +//------------------------------------------------------------------------ SvLBoxEntry* OTableTreeListBox::addedTable( const ::rtl::OUString& _rName ) { try --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
