diff options
Diffstat (limited to 'dbaccess/source/ui/control/tabletree.cxx')
-rw-r--r-- | dbaccess/source/ui/control/tabletree.cxx | 472 |
1 files changed, 84 insertions, 388 deletions
diff --git a/dbaccess/source/ui/control/tabletree.cxx b/dbaccess/source/ui/control/tabletree.cxx index 2ec45c9b756a..d1090a9aae0f 100644 --- a/dbaccess/source/ui/control/tabletree.cxx +++ b/dbaccess/source/ui/control/tabletree.cxx @@ -28,12 +28,9 @@ #include <com/sun/star/sdbcx/XTablesSupplier.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <listviewitems.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <osl/diagnose.h> #include <connectivity/dbmetadata.hxx> -#include <vcl/treelistentry.hxx> #include <algorithm> @@ -42,10 +39,8 @@ 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 ::com::sun::star::sdb::application; @@ -56,84 +51,31 @@ namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer; // OTableTreeListBox -OTableTreeListBox::OTableTreeListBox(vcl::Window* pParent, WinBits nWinStyle) - :OMarkableTreeListBox(pParent, nWinStyle) - ,m_xImageProvider( new ImageProvider ) -{ - implSetDefaultImages(); -} - -TableTreeListBox::TableTreeListBox(std::unique_ptr<weld::TreeView> xTreeView) - : m_xImageProvider(new ImageProvider) +OTableTreeListBox::OTableTreeListBox(std::unique_ptr<weld::TreeView> xTreeView, bool bShowToggles) + : TreeListBox(std::move(xTreeView), true) + , m_xImageProvider(new ImageProvider) , m_bVirtualRoot(false) , m_bNoEmptyFolders(false) - , m_bShowToggles(true) - , m_xTreeView(std::move(xTreeView)) -{ - m_xTreeView->enable_toggle_buttons(weld::ColumnToggleType::Check); -} - -void OTableTreeListBox::implSetDefaultImages() + , m_bShowToggles(bShowToggles) { - SetDefaultExpandedEntryBmp( ImageProvider::getFolderImage( DatabaseObject::TABLE ) ); - SetDefaultCollapsedEntryBmp( ImageProvider::getFolderImage( DatabaseObject::TABLE ) ); + if (m_bShowToggles) + m_xTreeView->enable_toggle_buttons(weld::ColumnToggleType::Check); } -bool OTableTreeListBox::isFolderEntry( const SvTreeListEntry* _pEntry ) +bool OTableTreeListBox::isFolderEntry(const weld::TreeIter& rEntry) const { - sal_Int32 nEntryType = reinterpret_cast< sal_IntPtr >( _pEntry->GetUserData() ); + sal_Int32 nEntryType = m_xTreeView->get_id(rEntry).toInt32(); return ( nEntryType == DatabaseObjectContainer::TABLES ) || ( nEntryType == DatabaseObjectContainer::CATALOG ) || ( nEntryType == DatabaseObjectContainer::SCHEMA ); } -void OTableTreeListBox::notifyHiContrastChanged() -{ - implSetDefaultImages(); - - SvTreeListEntry* pEntryLoop = First(); - while (pEntryLoop) - { - size_t nCount = pEntryLoop->ItemCount(); - for (size_t i=0;i<nCount;++i) - { - SvLBoxItem& rItem = pEntryLoop->GetItem(i); - if (rItem.GetType() == SvLBoxItemType::ContextBmp) - { - SvLBoxContextBmp& rContextBitmapItem = static_cast< SvLBoxContextBmp& >( rItem ); - - Image aImage; - if ( isFolderEntry( pEntryLoop ) ) - { - aImage = ImageProvider::getFolderImage( DatabaseObject::TABLE ); - } - else - { - OUString sCompleteName( getQualifiedTableName( pEntryLoop ) ); - m_xImageProvider->getImages( sCompleteName, DatabaseObject::TABLE, aImage ); - } - - rContextBitmapItem.SetBitmap1( aImage ); - rContextBitmapItem.SetBitmap2( aImage ); - break; - } - } - pEntryLoop = Next(pEntryLoop); - } -} - void OTableTreeListBox::implOnNewConnection( const Reference< XConnection >& _rxConnection ) { m_xConnection = _rxConnection; m_xImageProvider.reset( new ImageProvider( m_xConnection ) ); } -void TableTreeListBox::implOnNewConnection( const Reference< XConnection >& _rxConnection ) -{ - m_xConnection = _rxConnection; - m_xImageProvider.reset( new ImageProvider( m_xConnection ) ); -} - void OTableTreeListBox::UpdateTableList( const Reference< XConnection >& _rxConnection ) { Sequence< OUString > sTables, sViews; @@ -160,49 +102,7 @@ void OTableTreeListBox::UpdateTableList( const Reference< XConnection >& _rxConn } catch(RuntimeException&) { - OSL_FAIL("OTableTreeListBox::UpdateTableList : caught a RuntimeException!"); - } - catch ( const SQLException& ) - { - throw; - } - catch(Exception&) - { - css::uno::Any anyEx = cppu::getCaughtException(); - // a non-SQLException exception occurred ... simply throw an SQLException - throw SQLException(sCurrentActionError, nullptr, "", 0, anyEx); - } - - UpdateTableList( _rxConnection, sTables, sViews ); -} - -void TableTreeListBox::UpdateTableList( const Reference< XConnection >& _rxConnection ) -{ - Sequence< OUString > sTables, sViews; - - OUString sCurrentActionError; - try - { - Reference< XTablesSupplier > xTableSupp( _rxConnection, UNO_QUERY_THROW ); - sCurrentActionError = DBA_RES(STR_NOTABLEINFO); - - Reference< XNameAccess > xTables,xViews; - - Reference< XViewsSupplier > xViewSupp( _rxConnection, UNO_QUERY ); - if ( xViewSupp.is() ) - { - xViews = xViewSupp->getViews(); - if (xViews.is()) - sViews = xViews->getElementNames(); - } - - xTables = xTableSupp->getTables(); - if (xTables.is()) - sTables = xTables->getElementNames(); - } - catch(RuntimeException&) - { - OSL_FAIL("OTableTreeListBox::UpdateTableList : caught a RuntimeException!"); + TOOLS_WARN_EXCEPTION( "dbaccess", "OTableTreeListBox::UpdateTableList"); } catch ( const SQLException& ) { @@ -212,7 +112,7 @@ void TableTreeListBox::UpdateTableList( const Reference< XConnection >& _rxConne { css::uno::Any anyEx = cppu::getCaughtException(); // a non-SQLException exception occurred ... simply throw an SQLException - throw SQLException(sCurrentActionError, nullptr, "", 0, anyEx); + throw SQLException(sCurrentActionError, nullptr, u""_ustr, 0, anyEx); } UpdateTableList( _rxConnection, sTables, sViews ); @@ -261,27 +161,6 @@ void OTableTreeListBox::UpdateTableList( UpdateTableList( _rxConnection, aTables ); } -void TableTreeListBox::UpdateTableList( - const Reference< XConnection >& _rxConnection, - const Sequence< OUString>& _rTables, - const Sequence< OUString>& _rViews - ) -{ - TNames aTables; - aTables.resize(_rTables.getLength()); - try - { - Reference< XDatabaseMetaData > xMeta( _rxConnection->getMetaData(), UNO_SET_THROW ); - std::transform( _rTables.begin(), _rTables.end(), - aTables.begin(), OViewSetter( _rViews, xMeta->supportsMixedCaseQuotedIdentifiers() ) ); - } - catch(Exception&) - { - DBG_UNHANDLED_EXCEPTION("dbaccess"); - } - UpdateTableList( _rxConnection, aTables ); -} - namespace { std::vector< OUString > lcl_getMetaDataStrings_throw( const Reference< XResultSet >& _rxMetaDataResult, sal_Int32 _nColumnIndex ) @@ -305,67 +184,6 @@ void OTableTreeListBox::UpdateTableList( const Reference< XConnection >& _rxConn implOnNewConnection( _rxConnection ); // throw away all the old stuff - Clear(); - - try - { - if ( _rTables.empty() ) - // nothing to do (besides inserting the root entry) - return; - - // get the table/view names - Reference< XDatabaseMetaData > xMeta( _rxConnection->getMetaData(), UNO_SET_THROW ); - for (auto const& table : _rTables) - { - // add the entry - implAddEntry( - xMeta, - table.first, - false - ); - } - - if ( lcl_shouldDisplayEmptySchemasAndCatalogs( _rxConnection ) ) - { - bool bSupportsCatalogs = xMeta->supportsCatalogsInDataManipulation(); - bool bSupportsSchemas = xMeta->supportsSchemasInDataManipulation(); - - if ( bSupportsCatalogs || bSupportsSchemas ) - { - // we display empty catalogs if the DB supports catalogs, and they're noted at the beginning of a - // composed name. Otherwise, we display empty schematas. (also see the tree structure explained in - // implAddEntry) - bool bCatalogs = bSupportsCatalogs && xMeta->isCatalogAtStart(); - - std::vector< OUString > aFolderNames( lcl_getMetaDataStrings_throw( - bCatalogs ? xMeta->getCatalogs() : xMeta->getSchemas(), 1 ) ); - sal_Int32 nFolderType = bCatalogs ? DatabaseObjectContainer::CATALOG : DatabaseObjectContainer::SCHEMA; - - for (auto const& folderName : aFolderNames) - { - SvTreeListEntry* pFolder = GetEntryPosByName( folderName, nullptr ); - if ( !pFolder ) - InsertEntry( folderName, nullptr, false, TREELIST_APPEND, reinterpret_cast< void* >( nFolderType ) ); - } - } - } - } - catch ( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("dbaccess"); - } -} - -void TableTreeListBox::DisableCheckButtons() -{ - m_bShowToggles = false; -} - -void TableTreeListBox::UpdateTableList( const Reference< XConnection >& _rxConnection, const TNames& _rTables ) -{ - implOnNewConnection( _rxConnection ); - - // throw away all the old stuff m_xTreeView->clear(); m_xTreeView->make_unsorted(); @@ -402,7 +220,7 @@ void TableTreeListBox::UpdateTableList( const Reference< XConnection >& _rxConne for (auto const& table : _rTables) { // add the entry - implAddEntry(xMeta, table.first); + implAddEntry(xMeta, table.first, false); } if ( !m_bNoEmptyFolders && lcl_shouldDisplayEmptySchemasAndCatalogs( _rxConnection ) ) @@ -450,12 +268,12 @@ void TableTreeListBox::UpdateTableList( const Reference< XConnection >& _rxConne m_xTreeView->make_sorted(); } -bool TableTreeListBox::isWildcardChecked(const weld::TreeIter& rEntry) +bool OTableTreeListBox::isWildcardChecked(const weld::TreeIter& rEntry) { return m_xTreeView->get_text_emphasis(rEntry, 0); } -void TableTreeListBox::checkWildcard(weld::TreeIter& rEntry) +void OTableTreeListBox::checkWildcard(const weld::TreeIter& rEntry) { if (!m_bShowToggles) return; @@ -463,7 +281,7 @@ void TableTreeListBox::checkWildcard(weld::TreeIter& rEntry) checkedButton_noBroadcast(rEntry); } -std::unique_ptr<weld::TreeIter> TableTreeListBox::getAllObjectsEntry() const +std::unique_ptr<weld::TreeIter> OTableTreeListBox::getAllObjectsEntry() const { if (!haveVirtualRoot()) return nullptr; @@ -473,20 +291,7 @@ std::unique_ptr<weld::TreeIter> TableTreeListBox::getAllObjectsEntry() const return xRet; } -void OTableTreeListBox::checkedButton_noBroadcast(SvTreeListEntry* _pEntry) -{ - OMarkableTreeListBox::checkedButton_noBroadcast(_pEntry); - - // if an entry has children, it makes a difference if the entry is checked - // because all children are checked or if the user checked it explicitly. - // So we track explicit (un)checking - - SvButtonState eState = GetCheckButtonState(_pEntry); - OSL_ENSURE(SvButtonState::Tristate != eState, "OTableTreeListBox::CheckButtonHdl: user action which lead to TRISTATE?"); - implEmphasize(_pEntry, SvButtonState::Checked == eState); -} - -void TableTreeListBox::checkedButton_noBroadcast(const weld::TreeIter& rEntry) +void OTableTreeListBox::checkedButton_noBroadcast(const weld::TreeIter& rEntry) { if (!m_bShowToggles) return; @@ -534,38 +339,7 @@ void TableTreeListBox::checkedButton_noBroadcast(const weld::TreeIter& rEntry) implEmphasize(rEntry, eState == TRISTATE_TRUE); } -void OTableTreeListBox::implEmphasize(SvTreeListEntry* _pEntry, bool _bChecked, bool _bUpdateDescendants, bool _bUpdateAncestors) -{ - OSL_ENSURE(_pEntry, "OTableTreeListBox::implEmphasize: invalid entry (NULL)!"); - - if ( GetModel()->HasChildren(_pEntry) ) // the entry has children - { - OBoldListboxString* pTextItem = static_cast<OBoldListboxString*>(_pEntry->GetFirstItem(SvLBoxItemType::String)); - if (pTextItem) - pTextItem->emphasize(_bChecked); - } - - if (_bUpdateDescendants) - { - // remove the mark for all children of the checked entry - SvTreeListEntry* pChildLoop = FirstChild(_pEntry); - while (pChildLoop) - { - if (GetModel()->HasChildren(pChildLoop)) - implEmphasize(pChildLoop, false, true, false); - pChildLoop = pChildLoop->NextSibling(); - } - } - - if (_bUpdateAncestors) - { - // remove the mark for all ancestors of the entry - if (GetModel()->HasParent(_pEntry)) - implEmphasize(GetParent(_pEntry), false, false); - } -} - -void TableTreeListBox::implEmphasize(const weld::TreeIter& rEntry, bool _bChecked, bool _bUpdateDescendants, bool _bUpdateAncestors) +void OTableTreeListBox::implEmphasize(const weld::TreeIter& rEntry, bool _bChecked, bool _bUpdateDescendants, bool _bUpdateAncestors) { // special emphasizing handling for the "all objects" entry bool bAllObjectsEntryAffected = haveVirtualRoot() && (getAllObjectsEntry()->equal(rEntry)); @@ -598,20 +372,7 @@ void TableTreeListBox::implEmphasize(const weld::TreeIter& rEntry, bool _bChecke } } -void OTableTreeListBox::InitEntry(SvTreeListEntry* _pEntry, const OUString& _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(SvLBoxItemType::String); - OSL_ENSURE(pTextItem, "OTableTreeListBox::InitEntry: no text item!?"); - size_t nTextPos = _pEntry->GetPos(pTextItem); - OSL_ENSURE(SvTreeListEntry::ITEM_NOT_FOUND != nTextPos, "OTableTreeListBox::InitEntry: no text item pos!"); - - _pEntry->ReplaceItem(std::make_unique<OBoldListboxString>(_rString), nTextPos); -} - -SvTreeListEntry* OTableTreeListBox::implAddEntry( +std::unique_ptr<weld::TreeIter> OTableTreeListBox::implAddEntry( const Reference< XDatabaseMetaData >& _rxMeta, const OUString& _rTableName, bool _bCheckName @@ -625,65 +386,6 @@ SvTreeListEntry* OTableTreeListBox::implAddEntry( OUString sCatalog, sSchema, sName; qualifiedNameComponents( _rxMeta, _rTableName, sCatalog, sSchema, sName, ::dbtools::EComposeRule::InDataManipulation ); - SvTreeListEntry* pParentEntry = nullptr; - - // if the DB uses catalog at the start of identifiers, then our hierarchy is - // catalog - // +- schema - // +- table - // else it is - // schema - // +- catalog - // +- table - bool bCatalogAtStart = _rxMeta->isCatalogAtStart(); - const OUString& rFirstName = bCatalogAtStart ? sCatalog : sSchema; - const sal_Int32 nFirstFolderType = bCatalogAtStart ? DatabaseObjectContainer::CATALOG : DatabaseObjectContainer::SCHEMA; - const OUString& rSecondName = bCatalogAtStart ? sSchema : sCatalog; - const sal_Int32 nSecondFolderType = bCatalogAtStart ? DatabaseObjectContainer::SCHEMA : DatabaseObjectContainer::CATALOG; - - if ( !rFirstName.isEmpty() ) - { - SvTreeListEntry* pFolder = GetEntryPosByName( rFirstName, pParentEntry ); - if ( !pFolder ) - pFolder = InsertEntry( rFirstName, pParentEntry, false, TREELIST_APPEND, reinterpret_cast< void* >( nFirstFolderType ) ); - pParentEntry = pFolder; - } - - if ( !rSecondName.isEmpty() ) - { - SvTreeListEntry* pFolder = GetEntryPosByName( rSecondName, pParentEntry ); - if ( !pFolder ) - pFolder = InsertEntry( rSecondName, pParentEntry, false, TREELIST_APPEND, reinterpret_cast< void* >( nSecondFolderType ) ); - pParentEntry = pFolder; - } - - SvTreeListEntry* pRet = nullptr; - if ( !_bCheckName || !GetEntryPosByName( sName, pParentEntry ) ) - { - pRet = InsertEntry( sName, pParentEntry ); - - Image aImage; - m_xImageProvider->getImages( _rTableName, DatabaseObject::TABLE, aImage ); - - SetExpandedEntryBmp( pRet, aImage ); - SetCollapsedEntryBmp( pRet, aImage ); - } - return pRet; -} - -void TableTreeListBox::implAddEntry( - const Reference< XDatabaseMetaData >& _rxMeta, - const OUString& _rTableName - ) -{ - OSL_PRECOND( _rxMeta.is(), "OTableTreeListBox::implAddEntry: invalid meta data!" ); - if ( !_rxMeta.is() ) - return; - - // split the complete name into its components - OUString sCatalog, sSchema, sName; - qualifiedNameComponents( _rxMeta, _rTableName, sCatalog, sSchema, sName, ::dbtools::EComposeRule::InDataManipulation ); - std::unique_ptr<weld::TreeIter> xParentEntry(getAllObjectsEntry()); // if the DB uses catalog at the start of identifiers, then our hierarchy is @@ -736,28 +438,35 @@ void TableTreeListBox::implAddEntry( xParentEntry = std::move(xFolder); } - std::unique_ptr<weld::TreeIter> xEntry = m_xTreeView->make_iterator(); - m_xTreeView->insert(xParentEntry.get(), -1, nullptr, nullptr, nullptr, nullptr, false, xEntry.get()); - - auto xGraphic = m_xImageProvider->getXGraphic(_rTableName, DatabaseObject::TABLE); - if (xGraphic.is()) - m_xTreeView->set_image(*xEntry, xGraphic, -1); - else + if (!_bCheckName || !GetEntryPosByName(sName, xParentEntry.get())) { - OUString sImageId(m_xImageProvider->getImageId(_rTableName, DatabaseObject::TABLE)); - m_xTreeView->set_image(*xEntry, sImageId, -1); + std::unique_ptr<weld::TreeIter> xEntry = m_xTreeView->make_iterator(); + m_xTreeView->insert(xParentEntry.get(), -1, nullptr, nullptr, nullptr, nullptr, false, xEntry.get()); + + auto xGraphic = m_xImageProvider->getXGraphic(_rTableName, DatabaseObject::TABLE); + if (xGraphic.is()) + m_xTreeView->set_image(*xEntry, xGraphic, -1); + else + { + OUString sImageId(m_xImageProvider->getImageId(_rTableName, DatabaseObject::TABLE)); + m_xTreeView->set_image(*xEntry, sImageId, -1); + } + if (m_bShowToggles) + m_xTreeView->set_toggle(*xEntry, TRISTATE_FALSE); + m_xTreeView->set_text(*xEntry, sName, 0); + m_xTreeView->set_text_emphasis(*xEntry, false, 0); + + return xEntry; } - if (m_bShowToggles) - m_xTreeView->set_toggle(*xEntry, TRISTATE_FALSE); - m_xTreeView->set_text(*xEntry, sName, 0); - m_xTreeView->set_text_emphasis(*xEntry, false, 0); + + return nullptr; } -NamedDatabaseObject OTableTreeListBox::describeObject( SvTreeListEntry* _pEntry ) +NamedDatabaseObject OTableTreeListBox::describeObject(const weld::TreeIter& rEntry) { NamedDatabaseObject aObject; - sal_Int32 nEntryType = reinterpret_cast< sal_IntPtr >( _pEntry->GetUserData() ); + sal_Int32 nEntryType = m_xTreeView->get_id(rEntry).toInt32(); if ( nEntryType == DatabaseObjectContainer::TABLES ) { @@ -772,19 +481,19 @@ NamedDatabaseObject OTableTreeListBox::describeObject( SvTreeListEntry* _pEntry else { aObject.Type = DatabaseObject::TABLE; - aObject.Name = getQualifiedTableName( _pEntry ); + aObject.Name = getQualifiedTableName(rEntry); } return aObject; } -SvTreeListEntry* OTableTreeListBox::addedTable( const OUString& _rName ) +std::unique_ptr<weld::TreeIter> OTableTreeListBox::addedTable(const OUString& rName) { try { Reference< XDatabaseMetaData > xMeta; if ( impl_getAndAssertMetaData( xMeta ) ) - return implAddEntry( xMeta, _rName ); + return implAddEntry( xMeta, rName ); } catch( const Exception& ) { @@ -801,9 +510,9 @@ bool OTableTreeListBox::impl_getAndAssertMetaData( Reference< XDatabaseMetaData return _out_rMetaData.is(); } -OUString OTableTreeListBox::getQualifiedTableName( SvTreeListEntry* _pEntry ) const +OUString OTableTreeListBox::getQualifiedTableName(const weld::TreeIter& rEntry) const { - OSL_PRECOND( !isFolderEntry( _pEntry ), "OTableTreeListBox::getQualifiedTableName: folder entries not allowed here!" ); + OSL_PRECOND( !isFolderEntry(rEntry), "OTableTreeListBox::getQualifiedTableName: folder entries not allowed here!" ); try { @@ -815,27 +524,29 @@ OUString OTableTreeListBox::getQualifiedTableName( SvTreeListEntry* _pEntry ) co OUString sSchema; OUString sTable; - SvTreeListEntry* pSchema = GetParent( _pEntry ); - if ( pSchema ) + std::unique_ptr<weld::TreeIter> xSchema(m_xTreeView->make_iterator(&rEntry)); + bool bSchema = m_xTreeView->iter_parent(*xSchema); + if (bSchema) { - SvTreeListEntry* pCatalog = GetParent( pSchema ); - if ( pCatalog + std::unique_ptr<weld::TreeIter> xCatalog(m_xTreeView->make_iterator(xSchema.get())); + bool bCatalog = m_xTreeView->iter_parent(*xCatalog); + if ( bCatalog || ( xMeta->supportsCatalogsInDataManipulation() && !xMeta->supportsSchemasInDataManipulation() ) // here we support catalog but no schema ) { - if ( pCatalog == nullptr ) + if (!bCatalog) { - pCatalog = pSchema; - pSchema = nullptr; + xCatalog = std::move(xSchema); + bSchema = false; } - sCatalog = GetEntryText( pCatalog ); + sCatalog = m_xTreeView->get_text(*xCatalog); } - if ( pSchema ) - sSchema = GetEntryText(pSchema); + if (bSchema) + sSchema = m_xTreeView->get_text(*xSchema); } - sTable = GetEntryText( _pEntry ); + sTable = m_xTreeView->get_text(rEntry); return ::dbtools::composeTableName( xMeta, sCatalog, sSchema, sTable, false, ::dbtools::EComposeRule::InDataManipulation ); } @@ -846,7 +557,7 @@ OUString OTableTreeListBox::getQualifiedTableName( SvTreeListEntry* _pEntry ) co return OUString(); } -SvTreeListEntry* OTableTreeListBox::getEntryByQualifiedName( const OUString& _rName ) +std::unique_ptr<weld::TreeIter> OTableTreeListBox::getEntryByQualifiedName(const OUString& rName) { try { @@ -856,26 +567,26 @@ SvTreeListEntry* OTableTreeListBox::getEntryByQualifiedName( const OUString& _rN // split the complete name into its components OUString sCatalog, sSchema, sName; - qualifiedNameComponents(xMeta, _rName, sCatalog, sSchema, sName,::dbtools::EComposeRule::InDataManipulation); + qualifiedNameComponents(xMeta, rName, sCatalog, sSchema, sName,::dbtools::EComposeRule::InDataManipulation); - SvTreeListEntry* pParent = nullptr; - SvTreeListEntry* pCat = nullptr; - SvTreeListEntry* pSchema = nullptr; - if ( !sCatalog.isEmpty() ) + std::unique_ptr<weld::TreeIter> xParent(getAllObjectsEntry()); + std::unique_ptr<weld::TreeIter> xCat; + std::unique_ptr<weld::TreeIter> xSchema; + if (!sCatalog.isEmpty()) { - pCat = GetEntryPosByName(sCatalog, pParent); - if ( pCat ) - pParent = pCat; + xCat = GetEntryPosByName(sCatalog); + if (xCat) + xParent = std::move(xCat); } - if ( !sSchema.isEmpty() ) + if (!sSchema.isEmpty()) { - pSchema = GetEntryPosByName(sSchema, pParent); - if ( pSchema ) - pParent = pSchema; + xSchema = GetEntryPosByName(sSchema, xParent.get()); + if (xSchema) + xParent = std::move(xSchema); } - return GetEntryPosByName(sName, pParent); + return GetEntryPosByName(sName, xParent.get()); } catch( const Exception& ) { @@ -884,13 +595,13 @@ SvTreeListEntry* OTableTreeListBox::getEntryByQualifiedName( const OUString& _rN return nullptr; } -void OTableTreeListBox::removedTable( const OUString& _rName ) +void OTableTreeListBox::removedTable(const OUString& rName) { try { - SvTreeListEntry* pEntry = getEntryByQualifiedName( _rName ); - if ( pEntry ) - GetModel()->Remove( pEntry ); + std::unique_ptr<weld::TreeIter> xEntry = getEntryByQualifiedName(rName); + if (xEntry) + m_xTreeView->remove(*xEntry); } catch( const Exception& ) { @@ -898,28 +609,7 @@ void OTableTreeListBox::removedTable( const OUString& _rName ) } } -std::unique_ptr<weld::TreeIter> TableTreeListBox::GetEntryPosByName(const OUString& aName, const weld::TreeIter* pStart, const IEntryFilter* _pFilter) const -{ - auto xEntry(m_xTreeView->make_iterator(pStart)); - if (!pStart && !m_xTreeView->get_iter_first(*xEntry)) - return nullptr; - - do - { - if (m_xTreeView->get_text(*xEntry) == aName) - { - if (!_pFilter || _pFilter->includeEntry(reinterpret_cast<void*>(m_xTreeView->get_id(*xEntry).toUInt64()))) - { - // found - return xEntry; - } - } - } while (m_xTreeView->iter_next(*xEntry)); - - return nullptr; -} - -void TableTreeListBox::CheckButtons() +void OTableTreeListBox::CheckButtons() { if (!m_bShowToggles) return; @@ -934,7 +624,7 @@ void TableTreeListBox::CheckButtons() } while (m_xTreeView->iter_next_sibling(*xEntry)); } -TriState TableTreeListBox::implDetermineState(weld::TreeIter& rEntry) +TriState OTableTreeListBox::implDetermineState(const weld::TreeIter& rEntry) { if (!m_bShowToggles) return TRISTATE_FALSE; @@ -1005,6 +695,12 @@ TriState TableTreeListBox::implDetermineState(weld::TreeIter& rEntry) return eState; } +DBTableTreeView::DBTableTreeView(weld::Container* pContainer) + : DBTreeViewBase(pContainer) +{ + m_xTreeListBox.reset(new OTableTreeListBox(m_xBuilder->weld_tree_view(u"treeview"_ustr), /*bShowToggles*/false)); +} + } // namespace dbaui /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |