merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / control / tabletree.cxx
blob7420c7073f5cfeb8f418ddd9688b9e9d9f41662e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabletree.cxx,v $
10 * $Revision: 1.35.78.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _DBAUI_TABLETREE_HXX_
35 #include "tabletree.hxx"
36 #endif
37 #ifndef _DBAUI_TABLETREE_HRC_
38 #include "tabletree.hrc"
39 #endif
40 #ifndef DBACCESS_IMAGEPROVIDER_HXX
41 #include "imageprovider.hxx"
42 #endif
43 #ifndef _DBAUI_MODULE_DBU_HXX_
44 #include "moduledbu.hxx"
45 #endif
46 #ifndef _DBU_CONTROL_HRC_
47 #include "dbu_control.hrc"
48 #endif
49 #ifndef _SV_MENU_HXX
50 #include <vcl/menu.hxx>
51 #endif
52 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
53 #include <connectivity/dbtools.hxx>
54 #endif
55 #ifndef _COMPHELPER_TYPES_HXX_
56 #include <comphelper/types.hxx>
57 #endif
58 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
59 #include "dbustrings.hrc"
60 #endif
61 #ifndef _COM_SUN_STAR_SDB_APPLICATION_DATABASEOBJECT_HPP_
62 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
63 #endif
64 #ifndef _COM_SUN_STAR_SDB_APPLICATION_DATABASEOBJECTFOLDER_HPP_
65 #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
66 #endif
67 #ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_
68 #include <com/sun/star/sdbc/XDriverAccess.hpp>
69 #endif
70 #ifndef _COM_SUN_STAR_SDBCX_XDATADEFINITIONSUPPLIER_HPP_
71 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
72 #endif
73 #ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
74 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
75 #endif
76 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
77 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
78 #endif
79 #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
80 #include <com/sun/star/sdb/SQLContext.hpp>
81 #endif
82 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
83 #include <com/sun/star/sdbc/XRow.hpp>
84 #endif
85 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
86 #include <com/sun/star/beans/XPropertySet.hpp>
87 #endif
88 #ifndef _DBAUI_COMMON_TYPES_HXX_
89 #include "commontypes.hxx"
90 #endif
91 #ifndef _DBAUI_LISTVIEWITEMS_HXX_
92 #include "listviewitems.hxx"
93 #endif
94 #ifndef TOOLS_DIAGNOSE_EX_H
95 #include <tools/diagnose_ex.h>
96 #endif
97 #ifndef _RTL_USTRBUF_HXX_
98 #include <rtl/ustrbuf.hxx>
99 #endif
100 #include <connectivity/dbmetadata.hxx>
102 #include <algorithm>
104 //.........................................................................
105 namespace dbaui
107 //.........................................................................
109 using namespace ::com::sun::star::uno;
110 using namespace ::com::sun::star::sdb;
111 using namespace ::com::sun::star::lang;
112 using namespace ::com::sun::star::sdbc;
113 using namespace ::com::sun::star::sdbcx;
114 using namespace ::com::sun::star::beans;
115 using namespace ::com::sun::star::container;
116 using namespace ::com::sun::star::sdb::application;
118 using namespace ::dbtools;
119 using namespace ::comphelper;
121 namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
122 namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
124 //========================================================================
125 //= OTableTreeListBox
126 //========================================================================
127 OTableTreeListBox::OTableTreeListBox( Window* pParent, const Reference< XMultiServiceFactory >& _rxORB, WinBits nWinStyle,sal_Bool _bVirtualRoot )
128 :OMarkableTreeListBox(pParent,_rxORB,nWinStyle)
129 ,m_pImageProvider( new ImageProvider )
130 ,m_bVirtualRoot(_bVirtualRoot)
131 ,m_bNoEmptyFolders( false )
133 implSetDefaultImages();
135 //------------------------------------------------------------------------
136 OTableTreeListBox::OTableTreeListBox( Window* pParent, const Reference< XMultiServiceFactory >& _rxORB, const ResId& rResId ,sal_Bool _bVirtualRoot)
137 :OMarkableTreeListBox(pParent,_rxORB,rResId)
138 ,m_pImageProvider( new ImageProvider )
139 ,m_bVirtualRoot(_bVirtualRoot)
140 ,m_bNoEmptyFolders( false )
142 implSetDefaultImages();
145 // -----------------------------------------------------------------------------
146 OTableTreeListBox::~OTableTreeListBox()
150 // -----------------------------------------------------------------------------
151 void OTableTreeListBox::implSetDefaultImages()
153 ImageProvider aImageProvider;
154 SetDefaultExpandedEntryBmp( aImageProvider.getFolderImage( DatabaseObject::TABLE, false ), BMP_COLOR_NORMAL );
155 SetDefaultExpandedEntryBmp( aImageProvider.getFolderImage( DatabaseObject::TABLE, true ), BMP_COLOR_HIGHCONTRAST );
156 SetDefaultCollapsedEntryBmp( aImageProvider.getFolderImage( DatabaseObject::TABLE, false ), BMP_COLOR_NORMAL );
157 SetDefaultCollapsedEntryBmp( aImageProvider.getFolderImage( DatabaseObject::TABLE, true ), BMP_COLOR_HIGHCONTRAST );
160 // -----------------------------------------------------------------------------
161 bool OTableTreeListBox::isFolderEntry( const SvLBoxEntry* _pEntry ) const
163 sal_Int32 nEntryType = reinterpret_cast< sal_IntPtr >( _pEntry->GetUserData() );
164 if ( ( nEntryType == DatabaseObjectContainer::TABLES )
165 || ( nEntryType == DatabaseObjectContainer::CATALOG )
166 || ( nEntryType == DatabaseObjectContainer::SCHEMA )
168 return true;
169 return false;
172 // -----------------------------------------------------------------------------
173 void OTableTreeListBox::notifyHiContrastChanged()
175 implSetDefaultImages();
177 SvLBoxEntry* pEntryLoop = First();
178 while (pEntryLoop)
180 USHORT nCount = pEntryLoop->ItemCount();
181 for (USHORT i=0;i<nCount;++i)
183 SvLBoxItem* pItem = pEntryLoop->GetItem(i);
184 if ( pItem && pItem->IsA() == SV_ITEM_ID_LBOXCONTEXTBMP)
186 SvLBoxContextBmp* pContextBitmapItem = static_cast< SvLBoxContextBmp* >( pItem );
188 Image aImage, aImageHC;
189 if ( isFolderEntry( pEntryLoop ) )
191 aImage = m_pImageProvider->getFolderImage( DatabaseObject::TABLE, false );
192 aImageHC = m_pImageProvider->getFolderImage( DatabaseObject::TABLE, true );
194 else
196 String sCompleteName( getQualifiedTableName( pEntryLoop ) );
197 m_pImageProvider->getImages( sCompleteName, DatabaseObject::TABLE, aImage, aImageHC );
200 pContextBitmapItem->SetBitmap1( aImage, BMP_COLOR_NORMAL );
201 pContextBitmapItem->SetBitmap2( aImage, BMP_COLOR_NORMAL );
202 pContextBitmapItem->SetBitmap1( aImageHC, BMP_COLOR_HIGHCONTRAST );
203 pContextBitmapItem->SetBitmap2( aImageHC, BMP_COLOR_HIGHCONTRAST );
204 // TODO: Now that we give both images to the entry item, it is not necessary anymore
205 // to do this anytime HC changes - the tree control will do this itself now.
206 // We would only need to properly initialize newly inserted entries.
207 break;
210 pEntryLoop = Next(pEntryLoop);
214 //------------------------------------------------------------------------
215 void OTableTreeListBox::implOnNewConnection( const Reference< XConnection >& _rxConnection )
217 m_xConnection = _rxConnection;
218 m_pImageProvider.reset( new ImageProvider( m_xConnection ) );
221 //------------------------------------------------------------------------
222 void OTableTreeListBox::UpdateTableList( const Reference< XConnection >& _rxConnection ) throw(SQLException)
224 Sequence< ::rtl::OUString > sTables, sViews;
226 String sCurrentActionError;
229 Reference< XTablesSupplier > xTableSupp( _rxConnection, UNO_QUERY_THROW );
230 sCurrentActionError = String(ModuleRes(STR_NOTABLEINFO));
232 Reference< XNameAccess > xTables,xViews;
234 Reference< XViewsSupplier > xViewSupp( _rxConnection, UNO_QUERY );
235 if ( xViewSupp.is() )
237 xViews = xViewSupp->getViews();
238 if (xViews.is())
239 sViews = xViews->getElementNames();
242 xTables = xTableSupp->getTables();
243 if (xTables.is())
244 sTables = xTables->getElementNames();
246 catch(RuntimeException&)
248 DBG_ERROR("OTableTreeListBox::UpdateTableList : caught an RuntimeException!");
250 catch ( const SQLException& )
252 throw;
254 catch(Exception&)
256 // a non-SQLException exception occured ... simply throw an SQLException
257 SQLException aInfo;
258 aInfo.Message = sCurrentActionError;
259 throw aInfo;
262 UpdateTableList( _rxConnection, sTables, sViews );
264 // -----------------------------------------------------------------------------
265 namespace
267 struct OViewSetter : public ::std::unary_function< OTableTreeListBox::TNames::value_type, bool>
269 const Sequence< ::rtl::OUString> m_aViews;
270 ::comphelper::TStringMixEqualFunctor m_aEqualFunctor;
272 OViewSetter(const Sequence< ::rtl::OUString>& _rViews,sal_Bool _bCase) : m_aViews(_rViews),m_aEqualFunctor(_bCase){}
273 OTableTreeListBox::TNames::value_type operator() (const ::rtl::OUString& lhs)
275 OTableTreeListBox::TNames::value_type aRet;
276 aRet.first = lhs;
277 const ::rtl::OUString* pIter = m_aViews.getConstArray();
278 const ::rtl::OUString* pEnd = m_aViews.getConstArray() + m_aViews.getLength();
279 aRet.second = (::std::find_if(pIter,pEnd,::std::bind2nd(m_aEqualFunctor,lhs)) != pEnd);
281 return aRet;
286 // -----------------------------------------------------------------------------
287 void OTableTreeListBox::UpdateTableList(
288 const Reference< XConnection >& _rxConnection,
289 const Sequence< ::rtl::OUString>& _rTables,
290 const Sequence< ::rtl::OUString>& _rViews
293 TNames aTables;
294 aTables.resize(_rTables.getLength());
295 const ::rtl::OUString* pIter = _rTables.getConstArray();
296 const ::rtl::OUString* pEnd = _rTables.getConstArray() + _rTables.getLength();
299 Reference< XDatabaseMetaData > xMeta( _rxConnection->getMetaData(), UNO_QUERY_THROW );
300 ::std::transform( pIter, pEnd,
301 aTables.begin(), OViewSetter( _rViews, xMeta->supportsMixedCaseQuotedIdentifiers() ) );
303 catch(Exception&)
305 DBG_UNHANDLED_EXCEPTION();
307 UpdateTableList( _rxConnection, aTables );
310 //------------------------------------------------------------------------
311 namespace
313 ::std::vector< ::rtl::OUString > lcl_getMetaDataStrings_throw( const Reference< XResultSet >& _rxMetaDataResult, sal_Int32 _nColumnIndex )
315 ::std::vector< ::rtl::OUString > aStrings;
316 Reference< XRow > xRow( _rxMetaDataResult, UNO_QUERY_THROW );
317 while ( _rxMetaDataResult->next() )
318 aStrings.push_back( xRow->getString( _nColumnIndex ) );
319 return aStrings;
322 bool lcl_shouldDisplayEmptySchemasAndCatalogs( const Reference< XConnection >& _rxConnection )
324 ::dbtools::DatabaseMetaData aMetaData( _rxConnection );
325 return aMetaData.displayEmptyTableFolders();
329 //------------------------------------------------------------------------
330 void OTableTreeListBox::UpdateTableList( const Reference< XConnection >& _rxConnection, const TNames& _rTables )
332 implOnNewConnection( _rxConnection );
334 // throw away all the old stuff
335 Clear();
339 // the root entry saying "all objects"
340 SvLBoxEntry* pAllObjects = NULL;
341 if (haveVirtualRoot())
343 String sRootEntryText;
344 TNames::const_iterator aViews = ::std::find_if(_rTables.begin(),_rTables.end(),
345 ::std::compose1(::std::bind2nd(::std::equal_to<sal_Bool>(),sal_False),::std::select2nd<TNames::value_type>()));
346 TNames::const_iterator aTables = ::std::find_if(_rTables.begin(),_rTables.end(),
347 ::std::compose1(::std::bind2nd(::std::equal_to<sal_Bool>(),sal_True),::std::select2nd<TNames::value_type>()));
349 if ( aViews == _rTables.end() )
350 sRootEntryText = String(ModuleRes(STR_ALL_TABLES));
351 else if ( aTables == _rTables.end() )
352 sRootEntryText = String(ModuleRes(STR_ALL_VIEWS));
353 else
354 sRootEntryText = String(ModuleRes(STR_ALL_TABLES_AND_VIEWS));
355 pAllObjects = InsertEntry( sRootEntryText, NULL, FALSE, LIST_APPEND, reinterpret_cast< void* >( DatabaseObjectContainer::TABLES ) );
358 if ( _rTables.empty() )
359 // nothing to do (besides inserting the root entry)
360 return;
362 // get the table/view names
363 TNames::const_iterator aIter = _rTables.begin();
364 TNames::const_iterator aEnd = _rTables.end();
366 Reference< XDatabaseMetaData > xMeta( _rxConnection->getMetaData(), UNO_QUERY_THROW );
367 for ( ; aIter != aEnd; ++aIter )
369 // add the entry
370 implAddEntry(
371 xMeta,
372 aIter->first,
373 sal_False
377 if ( !m_bNoEmptyFolders && lcl_shouldDisplayEmptySchemasAndCatalogs( _rxConnection ) )
379 sal_Bool bSupportsCatalogs = xMeta->supportsCatalogsInDataManipulation();
380 sal_Bool bSupportsSchemas = xMeta->supportsSchemasInDataManipulation();
382 if ( bSupportsCatalogs || bSupportsSchemas )
384 // we display empty catalogs if the DB supports catalogs, and they're noted at the beginning of a
385 // composed name. Otherwise, we display empty schematas. (also see the tree structure explained in
386 // implAddEntry)
387 bool bCatalogs = bSupportsCatalogs && xMeta->isCatalogAtStart();
389 ::std::vector< ::rtl::OUString > aFolderNames( lcl_getMetaDataStrings_throw(
390 bCatalogs ? xMeta->getCatalogs() : xMeta->getSchemas(), 1 ) );
391 sal_Int32 nFolderType = bCatalogs ? DatabaseObjectContainer::CATALOG : DatabaseObjectContainer::SCHEMA;
393 SvLBoxEntry* pRootEntry = getAllObjectsEntry();
394 for ( ::std::vector< ::rtl::OUString >::const_iterator folder = aFolderNames.begin();
395 folder != aFolderNames.end();
396 ++folder
399 SvLBoxEntry* pFolder = GetEntryPosByName( *folder, pRootEntry );
400 if ( !pFolder )
401 pFolder = InsertEntry( *folder, pRootEntry, FALSE, LIST_APPEND, reinterpret_cast< void* >( nFolderType ) );
406 catch ( const Exception& )
408 DBG_UNHANDLED_EXCEPTION();
411 //------------------------------------------------------------------------
412 sal_Bool OTableTreeListBox::isWildcardChecked(SvLBoxEntry* _pEntry) const
414 if (_pEntry)
416 OBoldListboxString* pTextItem = static_cast<OBoldListboxString*>(_pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING));
417 if (pTextItem)
418 return pTextItem->isEmphasized();
420 return sal_False;
423 //------------------------------------------------------------------------
424 void OTableTreeListBox::checkWildcard(SvLBoxEntry* _pEntry)
426 SetCheckButtonState(_pEntry, SV_BUTTON_CHECKED);
427 checkedButton_noBroadcast(_pEntry);
430 //------------------------------------------------------------------------
431 SvLBoxEntry* OTableTreeListBox::getAllObjectsEntry() const
433 return haveVirtualRoot() ? First() : NULL;
436 //------------------------------------------------------------------------
437 void OTableTreeListBox::checkedButton_noBroadcast(SvLBoxEntry* _pEntry)
439 OMarkableTreeListBox::checkedButton_noBroadcast(_pEntry);
441 // if an entry has children, it makes a difference if the entry is checked because alls children are checked
442 // or if the user checked it explicitly.
443 // So we track explicit (un)checking
445 SvButtonState eState = GetCheckButtonState(_pEntry);
446 DBG_ASSERT(SV_BUTTON_TRISTATE != eState, "OTableTreeListBox::CheckButtonHdl: user action which lead to TRISTATE?");
447 implEmphasize(_pEntry, SV_BUTTON_CHECKED == eState);
450 //------------------------------------------------------------------------
451 void OTableTreeListBox::implEmphasize(SvLBoxEntry* _pEntry, sal_Bool _bChecked, sal_Bool _bUpdateDescendants, sal_Bool _bUpdateAncestors)
453 DBG_ASSERT(_pEntry, "OTableTreeListBox::implEmphasize: invalid entry (NULL)!");
455 // special emphasizing handling for the "all objects" entry
456 // 89709 - 16.07.2001 - frank.schoenheit@sun.com
457 sal_Bool bAllObjectsEntryAffected = haveVirtualRoot() && (getAllObjectsEntry() == _pEntry);
458 if ( GetModel()->HasChilds(_pEntry) // the entry has children
459 || bAllObjectsEntryAffected // or it is the "all objects" entry
462 OBoldListboxString* pTextItem = static_cast<OBoldListboxString*>(_pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING));
463 if (pTextItem)
464 pTextItem->emphasize(_bChecked);
466 if (bAllObjectsEntryAffected)
467 InvalidateEntry(_pEntry);
470 if (_bUpdateDescendants)
472 // remove the mark for all children of the checked entry
473 SvLBoxEntry* pChildLoop = FirstChild(_pEntry);
474 while (pChildLoop)
476 if (GetModel()->HasChilds(pChildLoop))
477 implEmphasize(pChildLoop, sal_False, sal_True, sal_False);
478 pChildLoop = NextSibling(pChildLoop);
482 if (_bUpdateAncestors)
484 // remove the mark for all ancestors of the entry
485 if (GetModel()->HasParent(_pEntry))
486 implEmphasize(GetParent(_pEntry), sal_False, sal_False, sal_True);
490 //------------------------------------------------------------------------
491 void OTableTreeListBox::InitEntry(SvLBoxEntry* _pEntry, const XubString& _rString, const Image& _rCollapsedBitmap, const Image& _rExpandedBitmap, SvLBoxButtonKind _eButtonKind)
493 OMarkableTreeListBox::InitEntry(_pEntry, _rString, _rCollapsedBitmap, _rExpandedBitmap, _eButtonKind);
495 // replace the text item with our own one
496 SvLBoxItem* pTextItem = _pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING);
497 DBG_ASSERT(pTextItem, "OTableTreeListBox::InitEntry: no text item!?");
498 sal_uInt16 nTextPos = _pEntry->GetPos(pTextItem);
499 DBG_ASSERT(((sal_uInt16)-1) != nTextPos, "OTableTreeListBox::InitEntry: no text item pos!");
501 _pEntry->ReplaceItem(new OBoldListboxString(_pEntry, 0, _rString), nTextPos);
504 //------------------------------------------------------------------------
505 SvLBoxEntry* OTableTreeListBox::implAddEntry(
506 const Reference< XDatabaseMetaData >& _rxMeta,
507 const ::rtl::OUString& _rTableName,
508 sal_Bool _bCheckName
511 OSL_PRECOND( _rxMeta.is(), "OTableTreeListBox::implAddEntry: invalid meta data!" );
512 if ( !_rxMeta.is() )
513 return NULL;
515 // split the complete name into it's components
516 ::rtl::OUString sCatalog, sSchema, sName;
517 qualifiedNameComponents( _rxMeta, _rTableName, sCatalog, sSchema, sName, ::dbtools::eInDataManipulation );
519 SvLBoxEntry* pParentEntry = getAllObjectsEntry();
521 // if the DB uses catalog at the start of identifiers, then our hierarchy is
522 // catalog
523 // +- schema
524 // +- table
525 // else it is
526 // schema
527 // +- catalog
528 // +- table
529 sal_Bool bCatalogAtStart = _rxMeta->isCatalogAtStart();
530 const ::rtl::OUString& rFirstName = bCatalogAtStart ? sCatalog : sSchema;
531 const sal_Int32 nFirstFolderType = bCatalogAtStart ? DatabaseObjectContainer::CATALOG : DatabaseObjectContainer::SCHEMA;
532 const ::rtl::OUString& rSecondName = bCatalogAtStart ? sSchema : sCatalog;
533 const sal_Int32 nSecondFolderType = bCatalogAtStart ? DatabaseObjectContainer::SCHEMA : DatabaseObjectContainer::CATALOG;
535 if ( rFirstName.getLength() )
537 SvLBoxEntry* pFolder = GetEntryPosByName( rFirstName, pParentEntry );
538 if ( !pFolder )
539 pFolder = InsertEntry( rFirstName, pParentEntry, FALSE, LIST_APPEND, reinterpret_cast< void* >( nFirstFolderType ) );
540 pParentEntry = pFolder;
543 if ( rSecondName.getLength() )
545 SvLBoxEntry* pFolder = GetEntryPosByName( rSecondName, pParentEntry );
546 if ( !pFolder )
547 pFolder = InsertEntry( rSecondName, pParentEntry, FALSE, LIST_APPEND, reinterpret_cast< void* >( nSecondFolderType ) );
548 pParentEntry = pFolder;
551 SvLBoxEntry* pRet = NULL;
552 if ( !_bCheckName || !GetEntryPosByName( sName, pParentEntry ) )
554 pRet = InsertEntry( sName, pParentEntry, FALSE, LIST_APPEND );
556 Image aImage, aImageHC;
557 m_pImageProvider->getImages( _rTableName, DatabaseObject::TABLE, aImage, aImageHC );
559 SetExpandedEntryBmp( pRet, aImage, BMP_COLOR_NORMAL );
560 SetCollapsedEntryBmp( pRet, aImage, BMP_COLOR_NORMAL );
561 SetExpandedEntryBmp( pRet, aImageHC, BMP_COLOR_HIGHCONTRAST );
562 SetCollapsedEntryBmp( pRet, aImageHC, BMP_COLOR_HIGHCONTRAST );
564 return pRet;
567 //------------------------------------------------------------------------
568 NamedDatabaseObject OTableTreeListBox::describeObject( SvLBoxEntry* _pEntry )
570 NamedDatabaseObject aObject;
572 sal_Int32 nEntryType = reinterpret_cast< sal_IntPtr >( _pEntry->GetUserData() );
574 if ( nEntryType == DatabaseObjectContainer::TABLES )
576 aObject.Type = DatabaseObjectContainer::TABLES;
578 else if ( ( nEntryType == DatabaseObjectContainer::CATALOG )
579 || ( nEntryType == DatabaseObjectContainer::SCHEMA )
582 SvLBoxEntry* pParent = GetParent( _pEntry );
583 sal_Int32 nParentEntryType = pParent ? reinterpret_cast< sal_IntPtr >( pParent->GetUserData() ) : -1;
585 ::rtl::OUStringBuffer buffer;
586 if ( nEntryType == DatabaseObjectContainer::CATALOG )
588 if ( nParentEntryType == DatabaseObjectContainer::SCHEMA )
590 buffer.append( GetEntryText( pParent ) );
591 buffer.append( sal_Unicode( '.' ) );
593 buffer.append( GetEntryText( _pEntry ) );
595 else if ( nEntryType == DatabaseObjectContainer::SCHEMA )
597 if ( nParentEntryType == DatabaseObjectContainer::CATALOG )
599 buffer.append( GetEntryText( pParent ) );
600 buffer.append( sal_Unicode( '.' ) );
602 buffer.append( GetEntryText( _pEntry ) );
605 else
607 aObject.Type = DatabaseObject::TABLE;
608 aObject.Name = getQualifiedTableName( _pEntry );
611 return aObject;
614 //------------------------------------------------------------------------
615 SvLBoxEntry* OTableTreeListBox::addedTable( const ::rtl::OUString& _rName )
619 Reference< XDatabaseMetaData > xMeta;
620 if ( impl_getAndAssertMetaData( xMeta ) )
621 return implAddEntry( xMeta, _rName );
623 catch( const Exception& )
625 DBG_UNHANDLED_EXCEPTION();
627 return NULL;
630 //------------------------------------------------------------------------
631 bool OTableTreeListBox::impl_getAndAssertMetaData( Reference< XDatabaseMetaData >& _out_rMetaData ) const
633 if ( m_xConnection.is() )
634 _out_rMetaData = m_xConnection->getMetaData();
635 OSL_PRECOND( _out_rMetaData.is(), "OTableTreeListBox::impl_getAndAssertMetaData: invalid current connection!" );
636 return _out_rMetaData.is();
639 //------------------------------------------------------------------------
640 String OTableTreeListBox::getQualifiedTableName( SvLBoxEntry* _pEntry ) const
642 OSL_PRECOND( !isFolderEntry( _pEntry ), "OTableTreeListBox::getQualifiedTableName: folder entries not allowed here!" );
644 Reference< XDatabaseMetaData > xMeta;
645 if ( !impl_getAndAssertMetaData( xMeta ) )
646 return String();
648 ::rtl::OUString sCatalog;
649 ::rtl::OUString sSchema;
650 ::rtl::OUString sTable;
652 SvLBoxEntry* pSchema = GetParent( _pEntry );
653 if ( pSchema )
655 SvLBoxEntry* pCatalog = GetParent( pSchema );
656 if ( pCatalog
657 || ( xMeta->supportsCatalogsInDataManipulation()
658 && !xMeta->supportsSchemasInDataManipulation()
659 ) // here we support catalog but no schema
662 if ( pCatalog == NULL )
664 pCatalog = pSchema;
665 pSchema = NULL;
667 sCatalog = GetEntryText( pCatalog );
669 if ( pSchema )
670 sSchema = GetEntryText(pSchema);
672 sTable = GetEntryText( _pEntry );
674 return ::dbtools::composeTableName( xMeta, sCatalog, sSchema, sTable, sal_False, ::dbtools::eInDataManipulation );
677 //------------------------------------------------------------------------
678 SvLBoxEntry* OTableTreeListBox::getEntryByQualifiedName( const ::rtl::OUString& _rName )
682 Reference< XDatabaseMetaData > xMeta;
683 if ( !impl_getAndAssertMetaData( xMeta ) )
684 return NULL;
686 // split the complete name into it's components
687 ::rtl::OUString sCatalog, sSchema, sName;
688 qualifiedNameComponents(xMeta, _rName, sCatalog, sSchema, sName,::dbtools::eInDataManipulation);
690 SvLBoxEntry* pParent = getAllObjectsEntry();
691 SvLBoxEntry* pCat = NULL;
692 SvLBoxEntry* pSchema = NULL;
693 if ( sCatalog.getLength() )
695 pCat = GetEntryPosByName(sCatalog, pParent);
696 if ( pCat )
697 pParent = pCat;
700 if ( sSchema.getLength() )
702 pSchema = GetEntryPosByName(sSchema, pParent);
703 if ( pSchema )
704 pParent = pSchema;
707 return GetEntryPosByName(sName, pParent);
709 catch( const Exception& )
711 DBG_UNHANDLED_EXCEPTION();
713 return NULL;
715 //------------------------------------------------------------------------
716 void OTableTreeListBox::removedTable( const ::rtl::OUString& _rName )
720 SvLBoxEntry* pEntry = getEntryByQualifiedName( _rName );
721 if ( pEntry )
722 GetModel()->Remove( pEntry );
724 catch( const Exception& )
726 DBG_UNHANDLED_EXCEPTION();
730 //.........................................................................
731 } // namespace dbaui
732 //.........................................................................