2000-10-05 09:09:48 +00:00
/*************************************************************************
*
* $ RCSfile : tabletree . cxx , v $
*
2004-08-02 14:37:10 +00:00
* $ Revision : 1.24 $
2000-10-05 09:09:48 +00:00
*
2004-08-02 14:37:10 +00:00
* last change : $ Author : hr $ $ Date : 2004 - 08 - 02 15 : 37 : 10 $
2000-10-05 09:09:48 +00:00
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc . , October , 2000
*
* GNU Lesser General Public License Version 2.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* Copyright 2000 by Sun Microsystems , Inc .
* 901 San Antonio Road , Palo Alto , CA 94303 , USA
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 , as published by the Free Software Foundation .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston ,
* MA 02111 - 1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 ( the " License " ) ; You may not use this file
* except in compliance with the License . You may obtain a copy of the
* License at http : //www.openoffice.org/license.html.
*
* Software provided under this License is provided on an " AS IS " basis ,
* WITHOUT WARRANTY OF ANY KIND , EITHER EXPRESS OR IMPLIED , INCLUDING ,
* WITHOUT LIMITATION , WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS ,
* MERCHANTABLE , FIT FOR A PARTICULAR PURPOSE , OR NON - INFRINGING .
* See the License for the specific provisions governing your rights and
* obligations concerning the Software .
*
* The Initial Developer of the Original Code is : Sun Microsystems , Inc . .
*
* Copyright : 2000 by Sun Microsystems , Inc .
*
* All Rights Reserved .
*
* Contributor ( s ) : _______________________________________
*
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# ifndef _DBAUI_TABLETREE_HXX_
# include "tabletree.hxx"
# endif
# ifndef _DBAUI_TABLETREE_HRC_
# include "tabletree.hrc"
# endif
# ifndef _DBAUI_MODULE_DBU_HXX_
# include "moduledbu.hxx"
# endif
2002-08-19 07:01:32 +00:00
# ifndef _DBU_CONTROL_HRC_
# include "dbu_control.hrc"
2000-10-05 09:09:48 +00:00
# endif
# ifndef _SV_MENU_HXX
# include <vcl/menu.hxx>
# endif
# ifndef _CONNECTIVITY_DBTOOLS_HXX_
# include <connectivity/dbtools.hxx>
# endif
2000-10-30 14:37:48 +00:00
# ifndef _COMPHELPER_TYPES_HXX_
# include <comphelper/types.hxx>
# endif
2000-10-26 13:55:04 +00:00
# ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
# include "dbustrings.hrc"
2000-10-05 09:09:48 +00:00
# endif
# ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_
# include <com/sun/star/sdbc/XDriverAccess.hpp>
# endif
# ifndef _COM_SUN_STAR_SDBCX_XDATADEFINITIONSUPPLIER_HPP_
# include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
# endif
# ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
# include <com/sun/star/sdbcx/XViewsSupplier.hpp>
# endif
# ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
# include <com/sun/star/sdbcx/XTablesSupplier.hpp>
# endif
2000-10-26 13:55:04 +00:00
# ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
# include <com/sun/star/sdb/SQLContext.hpp>
# endif
2000-10-30 14:37:48 +00:00
# ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
# include <com/sun/star/sdbc/XRow.hpp>
# endif
# ifndef _DBAUI_COMMON_TYPES_HXX_
# include "commontypes.hxx"
# endif
2001-01-30 07:29:43 +00:00
# ifndef _DBAUI_LISTVIEWITEMS_HXX_
# include "listviewitems.hxx"
# endif
2000-10-05 09:09:48 +00:00
//.........................................................................
namespace dbaui
{
//.........................................................................
using namespace : : com : : sun : : star : : uno ;
using namespace : : com : : sun : : star : : sdb ;
using namespace : : com : : sun : : star : : lang ;
using namespace : : com : : sun : : star : : sdbc ;
using namespace : : com : : sun : : star : : sdbcx ;
using namespace : : com : : sun : : star : : beans ;
using namespace : : com : : sun : : star : : container ;
using namespace : : dbtools ;
2000-10-30 14:37:48 +00:00
using namespace : : comphelper ;
2000-10-05 09:09:48 +00:00
//========================================================================
//= OTableTreeListBox
//========================================================================
2004-08-02 14:37:10 +00:00
OTableTreeListBox : : OTableTreeListBox ( Window * pParent , const Reference < XMultiServiceFactory > & _rxORB , sal_Bool _bHiContrast , WinBits nWinStyle , sal_Bool _bVirtualRoot )
: OMarkableTreeListBox ( pParent , _rxORB , nWinStyle )
2001-08-14 11:13:53 +00:00
, m_bVirtualRoot ( _bVirtualRoot )
2000-10-05 09:09:48 +00:00
{
2002-04-29 07:49:48 +00:00
notifyHiContrastChanged ( ) ;
2000-10-05 09:09:48 +00:00
}
//------------------------------------------------------------------------
2004-08-02 14:37:10 +00:00
OTableTreeListBox : : OTableTreeListBox ( Window * pParent , const Reference < XMultiServiceFactory > & _rxORB , const ResId & rResId , sal_Bool _bHiContrast , sal_Bool _bVirtualRoot )
: OMarkableTreeListBox ( pParent , _rxORB , rResId )
2001-08-14 11:13:53 +00:00
, m_bVirtualRoot ( _bVirtualRoot )
2000-10-05 09:09:48 +00:00
{
2002-04-29 07:49:48 +00:00
notifyHiContrastChanged ( ) ;
}
// -----------------------------------------------------------------------------
void OTableTreeListBox : : notifyHiContrastChanged ( )
{
sal_Bool bHiContrast = GetBackground ( ) . GetColor ( ) . IsDark ( ) ;
m_aTableImage = Image ( ModuleRes ( bHiContrast ? TABLE_TREE_ICON_SCH : TABLE_TREE_ICON ) ) ;
m_aViewImage = Image ( ModuleRes ( bHiContrast ? VIEW_TREE_ICON_SCH : VIEW_TREE_ICON ) ) ;
SetDefaultExpandedEntryBmp ( Image ( ModuleRes ( bHiContrast ? TABLEFOLDER_TREE_ICON_SCH : TABLEFOLDER_TREE_ICON ) ) ) ;
SetDefaultCollapsedEntryBmp ( Image ( ModuleRes ( bHiContrast ? TABLEFOLDER_TREE_ICON_SCH : TABLEFOLDER_TREE_ICON ) ) ) ;
SvLBoxEntry * pEntryLoop = First ( ) ;
while ( pEntryLoop )
{
sal_Int32 nType = reinterpret_cast < sal_Int32 > ( pEntryLoop - > GetUserData ( ) ) ;
if ( nType )
{
USHORT nCount = pEntryLoop - > ItemCount ( ) ;
for ( USHORT i = 0 ; i < nCount ; + + i )
{
SvLBoxItem * pItem = pEntryLoop - > GetItem ( i ) ;
if ( pItem & & pItem - > IsA ( ) = = SV_ITEM_ID_LBOXCONTEXTBMP )
{
Image aImage ;
switch ( nType )
{
case TABLE_TYPE : aImage = m_aTableImage ; break ;
case VIEW_TYPE : aImage = m_aViewImage ; break ;
default : aImage = Image ( ModuleRes ( bHiContrast ? TABLEFOLDER_TREE_ICON_SCH : TABLEFOLDER_TREE_ICON ) ) ;
}
static_cast < SvLBoxContextBmp * > ( pItem ) - > SetBitmap1 ( pEntryLoop , aImage ) ;
static_cast < SvLBoxContextBmp * > ( pItem ) - > SetBitmap2 ( pEntryLoop , aImage ) ;
break ;
}
}
}
pEntryLoop = Next ( pEntryLoop ) ;
}
2000-10-05 09:09:48 +00:00
}
//------------------------------------------------------------------------
2001-08-28 07:21:51 +00:00
Reference < XConnection > OTableTreeListBox : : UpdateTableList ( const : : rtl : : OUString & _rConnectionURL ,
const Sequence < PropertyValue > _rProperties , Reference < XDriver > & _rxCreator ) throw ( SQLException )
2000-10-05 09:09:48 +00:00
{
Reference < XDatabaseMetaData > xMetaData ;
Reference < XConnection > xConnection ;
2001-08-28 07:21:51 +00:00
_rxCreator . clear ( ) ;
2000-10-05 09:09:48 +00:00
2000-10-30 14:37:48 +00:00
Sequence < : : rtl : : OUString > sTables , sViews ;
2000-10-05 09:09:48 +00:00
DBG_ASSERT ( m_xORB . is ( ) , " OTableTreeListBox::UpdateTableList : please use setServiceFactory to give me a service factory ! " ) ;
String sCurrentActionError ;
2000-10-09 11:36:50 +00:00
String sCurrentActionDetails ;
2000-10-05 09:09:48 +00:00
try
{
if ( m_xORB . is ( ) )
{
// get the global DriverManager
Reference < XDriverAccess > xDriverManager ;
sCurrentActionError = String ( ModuleRes ( STR_COULDNOTCREATE_DRIVERMANAGER ) ) ;
// in case an error occures
2001-05-15 10:25:48 +00:00
sCurrentActionError . SearchAndReplaceAscii ( " #servicename# " , ( : : rtl : : OUString ) SERVICE_SDBC_CONNECTIONPOOL ) ;
2000-10-05 09:09:48 +00:00
try
{
2001-05-15 10:25:48 +00:00
xDriverManager = Reference < XDriverAccess > ( m_xORB - > createInstance ( SERVICE_SDBC_CONNECTIONPOOL ) , UNO_QUERY ) ;
2000-10-05 09:09:48 +00:00
DBG_ASSERT ( xDriverManager . is ( ) , " OTableTreeListBox::UpdateTableList : could not instantiate the driver manager, or it does not provide the necessary interface! " ) ;
}
catch ( Exception & e )
{
// wrap the exception into an SQLException
SQLException aSQLWrapper ( e . Message , m_xORB , : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " S1000 " ) ) , 0 , Any ( ) ) ;
throw aSQLWrapper ;
}
if ( ! xDriverManager . is ( ) )
throw Exception ( ) ;
sCurrentActionError = String ( ModuleRes ( STR_NOREGISTEREDDRIVER ) ) ;
2001-08-28 07:21:51 +00:00
_rxCreator = xDriverManager - > getDriverByURL ( _rConnectionURL ) ;
if ( ! _rxCreator . is ( ) )
2000-10-05 09:09:48 +00:00
// will be caught and translated into an SQLContext exception
throw Exception ( ) ;
2000-10-09 11:36:50 +00:00
sCurrentActionError = String ( ModuleRes ( STR_COULDNOTCONNECT ) ) ;
sCurrentActionDetails = String ( ModuleRes ( STR_COULDNOTCONNECT_PLEASECHECK ) ) ;
2001-08-28 07:21:51 +00:00
xConnection = _rxCreator - > connect ( _rConnectionURL , _rProperties ) ;
2000-10-09 11:36:50 +00:00
// exceptions thrown by connect will be caught and re-routed
DBG_ASSERT ( xConnection . is ( ) , " OTableTreeListBox::UpdateTableList : got an invalid connection! " ) ;
// if no exception was thrown, the connection should be no-NULL)
if ( ! xConnection . is ( ) )
throw Exception ( ) ;
sCurrentActionDetails = String ( ) ;
xMetaData = xConnection - > getMetaData ( ) ;
2000-10-30 14:37:48 +00:00
// get the (very necessary) interface XDataDefinitionSupplier
2001-08-28 07:21:51 +00:00
Reference < XDataDefinitionSupplier > xDefinitionAccess ( _rxCreator , UNO_QUERY ) ;
2000-10-30 14:37:48 +00:00
if ( ! xDefinitionAccess . is ( ) )
{
// okay, the driver's programmer was lazy :)
// let's do it on foot .... (ask the meta data for a result set describing the tables)
Reference < XResultSet > xTables ;
2000-10-09 11:36:50 +00:00
2000-10-30 14:37:48 +00:00
static const : : rtl : : OUString s_sTableTypeView ( RTL_CONSTASCII_USTRINGPARAM ( " VIEW " ) ) ;
2001-06-05 11:39:45 +00:00
static const : : rtl : : OUString s_sTableTypeTable ( RTL_CONSTASCII_USTRINGPARAM ( " TABLE " ) ) ;
2000-10-09 11:36:50 +00:00
2000-10-30 14:37:48 +00:00
if ( xMetaData . is ( ) )
{
// we want all catalogues, all schemas, all tables
2001-06-05 11:39:45 +00:00
Sequence < : : rtl : : OUString > sTableTypes ( 3 ) ;
static const : : rtl : : OUString sWildcard = : : rtl : : OUString : : createFromAscii ( " % " ) ;
sTableTypes [ 0 ] = s_sTableTypeView ;
sTableTypes [ 1 ] = s_sTableTypeTable ;
sTableTypes [ 2 ] = sWildcard ; // just to be sure to include anything else ....
2001-05-22 05:31:30 +00:00
2001-06-05 11:39:45 +00:00
xTables = xMetaData - > getTables ( Any ( ) , sWildcard , sWildcard , sTableTypes ) ;
2000-10-30 14:37:48 +00:00
}
Reference < XRow > xCurrentRow ( xTables , UNO_QUERY ) ;
if ( xCurrentRow . is ( ) )
{
StringBag aTableNames , aViewNames ;
: : rtl : : OUString sCatalog , sSchema , sName , sType , sComposedName ;
while ( xTables - > next ( ) )
{
// after creation the set is positioned before the first record, per definitionem
sCatalog = xCurrentRow - > getString ( 1 ) ;
sSchema = xCurrentRow - > getString ( 2 ) ;
sName = xCurrentRow - > getString ( 3 ) ;
sType = xCurrentRow - > getString ( 4 ) ;
2002-10-07 12:09:48 +00:00
: : dbtools : : composeTableName ( xMetaData , sCatalog , sSchema , sName , sComposedName , sal_False , : : dbtools : : eInDataManipulation ) ;
2000-10-30 14:37:48 +00:00
if ( s_sTableTypeView . equals ( sType ) )
aViewNames . insert ( sComposedName ) ;
else
aTableNames . insert ( sComposedName ) ;
}
// copy the names into the sequence
// tables
sTables . realloc ( aTableNames . size ( ) ) ;
: : rtl : : OUString * pTables = sTables . getArray ( ) ;
ConstStringBagIterator aCopy = aTableNames . begin ( ) ;
for ( ; aCopy ! = aTableNames . end ( ) ; + + aCopy , + + pTables )
* pTables = * aCopy ;
// views
sViews . realloc ( aViewNames . size ( ) ) ;
pTables = sViews . getArray ( ) ;
for ( aCopy = aViewNames . begin ( ) ; aCopy ! = aViewNames . end ( ) ; + + aCopy , + + pTables )
* pTables = * aCopy ;
}
disposeComponent ( xTables ) ;
}
else
{
Reference < XTablesSupplier > xTableSupp ;
Reference < XViewsSupplier > xViewSupp ;
sCurrentActionError = String ( ModuleRes ( STR_NOTABLEINFO ) ) ;
// get the table supplier and the tables
xTableSupp = xDefinitionAccess - > getDataDefinitionByConnection ( xConnection ) ;
if ( ! xTableSupp . is ( ) )
throw Exception ( ) ;
Reference < XNameAccess > xTables , xViews ;
xTables = xTableSupp - > getTables ( ) ;
// get the views supplier and the views
2004-08-02 14:37:10 +00:00
xViewSupp . set ( xTableSupp , UNO_QUERY ) ;
2000-10-30 14:37:48 +00:00
if ( xViewSupp . is ( ) )
xViews = xViewSupp - > getViews ( ) ;
if ( xTables . is ( ) )
sTables = xTables - > getElementNames ( ) ;
if ( xViews . is ( ) )
sViews = xViews - > getElementNames ( ) ;
}
2000-10-05 09:09:48 +00:00
}
}
catch ( RuntimeException & )
{
DBG_ERROR ( " OTableTreeListBox::UpdateTableList : caught an RuntimeException! " ) ;
}
catch ( SQLException & e )
{
sCurrentActionError . SearchAndReplaceAscii ( " #connurl# " , _rConnectionURL ) ;
// prepend a string stating what we were doing and throw again
2000-10-09 11:36:50 +00:00
SQLContext aExtendedInfo = prependContextInfo ( e , NULL , sCurrentActionError . GetBuffer ( ) , sCurrentActionDetails . GetBuffer ( ) ) ;
2000-10-05 09:09:48 +00:00
throw aExtendedInfo ;
}
catch ( Exception & )
{
sCurrentActionError . SearchAndReplaceAscii ( " #connurl# " , _rConnectionURL ) ;
// a non-SQLException exception occured ... simply throw an SQLContext
SQLContext aExtendedInfo ;
aExtendedInfo . Message = sCurrentActionError . GetBuffer ( ) ;
throw aExtendedInfo ;
}
2000-10-30 14:37:48 +00:00
UpdateTableList ( xMetaData , sTables , sViews ) ;
2000-10-05 09:09:48 +00:00
return xConnection ;
}
//------------------------------------------------------------------------
2000-10-30 14:37:48 +00:00
void OTableTreeListBox : : UpdateTableList ( const Reference < XDatabaseMetaData > & _rxConnMetaData , const Sequence < : : rtl : : OUString > & _rTables , const Sequence < : : rtl : : OUString > & _rViews )
2000-10-05 09:09:48 +00:00
{
// throw away all the old stuff
Clear ( ) ;
try
{
2001-01-30 07:29:43 +00:00
// the root entry saying "all objects"
2001-02-05 13:45:04 +00:00
SvLBoxEntry * pAllObjects = NULL ;
2001-08-14 11:13:53 +00:00
if ( haveVirtualRoot ( ) )
2001-02-05 13:45:04 +00:00
{
String sRootEntryText ;
if ( ! _rViews . getLength ( ) )
2004-08-02 14:37:10 +00:00
sRootEntryText = String ( ModuleRes ( STR_ALL_TABLES ) ) ;
2001-02-05 13:45:04 +00:00
else if ( ! _rTables . getLength ( ) )
2004-08-02 14:37:10 +00:00
sRootEntryText = String ( ModuleRes ( STR_ALL_VIEWS ) ) ;
2001-02-05 13:45:04 +00:00
else
2004-08-02 14:37:10 +00:00
sRootEntryText = String ( ModuleRes ( STR_ALL_TABLES_AND_VIEWS ) ) ;
2002-04-29 07:49:48 +00:00
pAllObjects = InsertEntry ( sRootEntryText , NULL , FALSE , LIST_APPEND , reinterpret_cast < void * > ( FOLDER_TYPE ) ) ;
2001-02-05 13:45:04 +00:00
}
2001-01-30 07:29:43 +00:00
2001-06-25 08:05:56 +00:00
if ( ! _rTables . getLength ( ) & & ! _rViews . getLength ( ) )
// nothing to do (besides inserting the root entry)
return ;
2000-10-05 09:09:48 +00:00
// get the table/view names
const : : rtl : : OUString * pTables = NULL ;
const : : rtl : : OUString * pViews = NULL ;
2001-03-29 07:06:35 +00:00
if ( _rTables . getLength ( ) )
pTables = _rTables . getConstArray ( ) ;
if ( _rViews . getLength ( ) )
pViews = _rViews . getConstArray ( ) ;
2000-10-05 09:09:48 +00:00
2001-03-29 06:09:53 +00:00
// loop through both sequences first the vies and than the tables
const : : rtl : : OUString * pSwitchSequences = ( pTables & & pViews ) ? pViews + _rViews . getLength ( ) - 1 : NULL ;
2000-10-05 09:09:48 +00:00
2000-10-30 14:37:48 +00:00
sal_Int32 nOverallLen = _rTables . getLength ( ) + _rViews . getLength ( ) ;
2001-03-29 06:09:53 +00:00
const : : rtl : : OUString * pCurrentTable = pViews ? pViews : pTables ; // currently handled view or table name
sal_Bool bIsView = pViews ? sal_True : sal_False ; // pCurrentTable points to a view name ?
2000-10-05 09:09:48 +00:00
for ( sal_Int32 i = 0 ;
i < nOverallLen ;
+ + i // inc the counter
, ( pSwitchSequences = = pCurrentTable // did we reached the last table ?
2001-03-29 06:09:53 +00:00
? bIsView = ! ( ( pCurrentTable = pTables ) ! = NULL ) // yes -> continue with the views, and set bIsView to sal_True
2000-10-05 09:09:48 +00:00
: + + pCurrentTable ! = NULL // no -> next table
) // (!= NULL is to make this a boolean expression, so it should work under SUNPRO5, too)
)
{
2001-08-14 11:13:53 +00:00
// add the entry
implAddEntry (
_rxConnMetaData ,
* pCurrentTable ,
bIsView ? m_aViewImage : m_aTableImage ,
2002-04-29 07:49:48 +00:00
pAllObjects ,
2004-08-02 14:37:10 +00:00
bIsView ? VIEW_TYPE : TABLE_TYPE ,
sal_False
2001-08-14 11:13:53 +00:00
) ;
2000-10-05 09:09:48 +00:00
}
}
catch ( RuntimeException & )
{
DBG_ERROR ( " OTableTreeListBox::UpdateTableList : caught a RuntimeException! " ) ;
}
}
2001-01-30 07:29:43 +00:00
//------------------------------------------------------------------------
sal_Bool OTableTreeListBox : : isWildcardChecked ( SvLBoxEntry * _pEntry ) const
{
if ( _pEntry )
{
OBoldListboxString * pTextItem = static_cast < OBoldListboxString * > ( _pEntry - > GetFirstItem ( SV_ITEM_ID_BOLDLBSTRING ) ) ;
if ( pTextItem )
return pTextItem - > isEmphasized ( ) ;
}
return sal_False ;
}
//------------------------------------------------------------------------
void OTableTreeListBox : : checkWildcard ( SvLBoxEntry * _pEntry )
{
SetCheckButtonState ( _pEntry , SV_BUTTON_CHECKED ) ;
checkedButton_noBroadcast ( _pEntry ) ;
}
//------------------------------------------------------------------------
SvLBoxEntry * OTableTreeListBox : : getAllObjectsEntry ( ) const
{
2001-08-14 11:13:53 +00:00
return haveVirtualRoot ( ) ? First ( ) : NULL ;
2001-01-30 07:29:43 +00:00
}
//------------------------------------------------------------------------
void OTableTreeListBox : : checkedButton_noBroadcast ( SvLBoxEntry * _pEntry )
{
OMarkableTreeListBox : : checkedButton_noBroadcast ( _pEntry ) ;
// if an entry has children, it makes a difference if the entry is checked because alls children are checked
// or if the user checked it explicitly.
// So we track explicit (un)checking
SvButtonState eState = GetCheckButtonState ( _pEntry ) ;
DBG_ASSERT ( SV_BUTTON_TRISTATE ! = eState , " OTableTreeListBox::CheckButtonHdl: user action which lead to TRISTATE? " ) ;
implEmphasize ( _pEntry , SV_BUTTON_CHECKED = = eState ) ;
}
//------------------------------------------------------------------------
2001-06-05 11:39:45 +00:00
void OTableTreeListBox : : implEmphasize ( SvLBoxEntry * _pEntry , sal_Bool _bChecked , sal_Bool _bUpdateDescendants , sal_Bool _bUpdateAncestors )
2001-01-30 07:29:43 +00:00
{
DBG_ASSERT ( _pEntry , " OTableTreeListBox::implEmphasize: invalid entry (NULL)! " ) ;
2001-07-16 14:43:24 +00:00
// special emphasizing handling for the "all objects" entry
// 89709 - 16.07.2001 - frank.schoenheit@sun.com
2001-08-14 11:13:53 +00:00
sal_Bool bAllObjectsEntryAffected = haveVirtualRoot ( ) & & ( getAllObjectsEntry ( ) = = _pEntry ) ;
2001-07-16 14:43:24 +00:00
if ( GetModel ( ) - > HasChilds ( _pEntry ) // the entry has children
| | bAllObjectsEntryAffected // or it is the "all objects" entry
)
2001-01-30 07:29:43 +00:00
{
OBoldListboxString * pTextItem = static_cast < OBoldListboxString * > ( _pEntry - > GetFirstItem ( SV_ITEM_ID_BOLDLBSTRING ) ) ;
if ( pTextItem )
pTextItem - > emphasize ( _bChecked ) ;
2001-07-16 14:43:24 +00:00
if ( bAllObjectsEntryAffected )
InvalidateEntry ( _pEntry ) ;
2001-01-30 07:29:43 +00:00
}
2001-06-05 11:39:45 +00:00
if ( _bUpdateDescendants )
2001-01-30 07:29:43 +00:00
{
// remove the mark for all children of the checked entry
SvLBoxEntry * pChildLoop = FirstChild ( _pEntry ) ;
while ( pChildLoop )
{
if ( GetModel ( ) - > HasChilds ( pChildLoop ) )
2001-06-05 11:39:45 +00:00
implEmphasize ( pChildLoop , sal_False , sal_True , sal_False ) ;
2001-01-30 07:29:43 +00:00
pChildLoop = NextSibling ( pChildLoop ) ;
}
2001-06-05 11:39:45 +00:00
}
if ( _bUpdateAncestors )
{
2001-01-30 07:29:43 +00:00
// remove the mark for all ancestors of the entry
if ( GetModel ( ) - > HasParent ( _pEntry ) )
2001-06-05 11:39:45 +00:00
implEmphasize ( GetParent ( _pEntry ) , sal_False , sal_False , sal_True ) ;
2001-01-30 07:29:43 +00:00
}
}
//------------------------------------------------------------------------
void OTableTreeListBox : : InitEntry ( SvLBoxEntry * _pEntry , const XubString & _rString , const Image & _rCollapsedBitmap , const Image & _rExpandedBitmap )
{
OMarkableTreeListBox : : InitEntry ( _pEntry , _rString , _rCollapsedBitmap , _rExpandedBitmap ) ;
// replace the text item with our own one
SvLBoxItem * pTextItem = _pEntry - > GetFirstItem ( SV_ITEM_ID_LBOXSTRING ) ;
DBG_ASSERT ( pTextItem , " OTableTreeListBox::InitEntry: no text item!? " ) ;
sal_uInt16 nTextPos = _pEntry - > GetPos ( pTextItem ) ;
DBG_ASSERT ( ( ( sal_uInt16 ) - 1 ) ! = nTextPos , " OTableTreeListBox::InitEntry: no text item pos! " ) ;
_pEntry - > ReplaceItem ( new OBoldListboxString ( _pEntry , 0 , _rString ) , nTextPos ) ;
}
2001-08-14 11:13:53 +00:00
//------------------------------------------------------------------------
2004-08-02 14:37:10 +00:00
SvLBoxEntry * OTableTreeListBox : : implAddEntry (
2001-08-14 11:13:53 +00:00
const Reference < XDatabaseMetaData > & _rxConnMetaData ,
const : : rtl : : OUString & _rTableName ,
const Image & _rImage ,
2002-04-29 07:49:48 +00:00
SvLBoxEntry * _pParentEntry ,
2004-08-02 14:37:10 +00:00
sal_Int32 _nType ,
sal_Bool _bCheckName
2001-08-14 11:13:53 +00:00
)
{
// split the complete name into it's components
: : rtl : : OUString sCatalog , sSchema , sName ;
2002-10-07 12:09:48 +00:00
qualifiedNameComponents ( _rxConnMetaData , _rTableName , sCatalog , sSchema , sName , : : dbtools : : eInDataManipulation ) ;
2001-08-14 11:13:53 +00:00
SvLBoxEntry * pCat = NULL ;
SvLBoxEntry * pSchema = NULL ;
if ( sCatalog . getLength ( ) )
{
pCat = GetEntryPosByName ( sCatalog , _pParentEntry ) ;
if ( ! pCat )
2002-04-29 07:49:48 +00:00
pCat = InsertEntry ( sCatalog , _pParentEntry , FALSE , LIST_APPEND , reinterpret_cast < void * > ( FOLDER_TYPE ) ) ;
2001-08-14 11:13:53 +00:00
_pParentEntry = pCat ;
}
if ( sSchema . getLength ( ) )
{
pSchema = GetEntryPosByName ( sSchema , _pParentEntry ) ;
if ( ! pSchema )
2002-04-29 07:49:48 +00:00
pSchema = InsertEntry ( sSchema , _pParentEntry , FALSE , LIST_APPEND , reinterpret_cast < void * > ( FOLDER_TYPE ) ) ;
2001-08-14 11:13:53 +00:00
_pParentEntry = pSchema ;
}
2004-08-02 14:37:10 +00:00
SvLBoxEntry * pRet = NULL ;
if ( ! _bCheckName | | ! GetEntryPosByName ( sName , _pParentEntry ) )
pRet = InsertEntry ( sName , _rImage , _rImage , _pParentEntry , FALSE , LIST_APPEND , reinterpret_cast < void * > ( _nType ) ) ;
return pRet ;
2001-08-14 11:13:53 +00:00
}
//------------------------------------------------------------------------
2004-08-02 14:37:10 +00:00
SvLBoxEntry * OTableTreeListBox : : addedTable ( const Reference < XConnection > & _rxConn , const : : rtl : : OUString & _rName , const Any & _rObject )
2001-08-14 11:13:53 +00:00
{
try
{
// get the connection meta data
Reference < XDatabaseMetaData > xMeta ;
if ( _rxConn . is ( ) ) xMeta = _rxConn - > getMetaData ( ) ;
if ( ! xMeta . is ( ) )
{
DBG_ERROR ( " OTableTreeListBox::addedTable: invalid connection! " ) ;
2004-08-02 14:37:10 +00:00
return NULL ;
2001-08-14 11:13:53 +00:00
}
// add the entry
2004-08-02 14:37:10 +00:00
return implAddEntry ( xMeta , _rName , m_aTableImage , getAllObjectsEntry ( ) , TABLE_TYPE ) ;
2001-08-14 11:13:53 +00:00
// TODO: the image
}
catch ( const Exception & )
{
DBG_ERROR ( " OTableTreeListBox::addedTable: caught an exception! " ) ;
}
2004-08-02 14:37:10 +00:00
return NULL ;
2001-08-14 11:13:53 +00:00
}
//------------------------------------------------------------------------
2004-08-02 14:37:10 +00:00
SvLBoxEntry * OTableTreeListBox : : getEntryByQualifiedName ( const Reference < XConnection > & _rxConn , const : : rtl : : OUString & _rName )
2001-08-14 11:13:53 +00:00
{
try
{
// get the connection meta data
Reference < XDatabaseMetaData > xMeta ;
if ( _rxConn . is ( ) ) xMeta = _rxConn - > getMetaData ( ) ;
if ( ! xMeta . is ( ) )
{
DBG_ERROR ( " OTableTreeListBox::removedTable: invalid connection! " ) ;
2004-08-02 14:37:10 +00:00
return NULL ;
}
// split the complete name into it's components
: : rtl : : OUString sCatalog , sSchema , sName ;
qualifiedNameComponents ( xMeta , _rName , sCatalog , sSchema , sName , : : dbtools : : eInDataManipulation ) ;
SvLBoxEntry * pParent = getAllObjectsEntry ( ) ;
SvLBoxEntry * pCat = NULL ;
SvLBoxEntry * pSchema = NULL ;
if ( sCatalog . getLength ( ) )
{
pCat = GetEntryPosByName ( sCatalog , pParent ) ;
if ( pCat )
pParent = pCat ;
}
if ( sSchema . getLength ( ) )
{
pSchema = GetEntryPosByName ( sSchema , pParent ) ;
if ( pSchema )
pParent = pSchema ;
2001-08-14 11:13:53 +00:00
}
2004-08-02 14:37:10 +00:00
return GetEntryPosByName ( sName , pParent ) ;
}
catch ( const Exception & )
{
DBG_ERROR ( " OTableTreeListBox::removedTable: caught an exception! " ) ;
}
return NULL ;
}
//------------------------------------------------------------------------
void OTableTreeListBox : : removedTable ( const Reference < XConnection > & _rxConn , const : : rtl : : OUString & _rName )
{
try
{
SvLBoxEntry * pEntry = getEntryByQualifiedName ( _rxConn , _rName ) ;
if ( pEntry )
GetModel ( ) - > Remove ( pEntry ) ;
2001-08-14 11:13:53 +00:00
}
catch ( const Exception & )
{
DBG_ERROR ( " OTableTreeListBox::removedTable: caught an exception! " ) ;
}
}
2000-10-05 09:09:48 +00:00
//.........................................................................
} // namespace dbaui
//.........................................................................