diff options
author | Ocke Janssen <oj@openoffice.org> | 2002-06-27 07:23:50 +0000 |
---|---|---|
committer | Ocke Janssen <oj@openoffice.org> | 2002-06-27 07:23:50 +0000 |
commit | 6ad8d456a90179e8cc5351f52822c9a5e9a3e70c (patch) | |
tree | 5fe868240499362c8098d8f82eb072bfc6694a89 /dbaccess/source | |
parent | #96325# remove all convertAlias calls (diff) | |
download | core-6ad8d456a90179e8cc5351f52822c9a5e9a3e70c.tar.gz core-6ad8d456a90179e8cc5351f52822c9a5e9a3e70c.zip |
#96325# new methods to handle userdata correctly
Diffstat (limited to 'dbaccess/source')
-rw-r--r-- | dbaccess/source/ui/inc/TableWindow.hxx | 35 | ||||
-rw-r--r-- | dbaccess/source/ui/querydesign/JoinTableView.cxx | 11 | ||||
-rw-r--r-- | dbaccess/source/ui/querydesign/QTableWindow.cxx | 108 | ||||
-rw-r--r-- | dbaccess/source/ui/querydesign/QTableWindow.hxx | 29 | ||||
-rw-r--r-- | dbaccess/source/ui/querydesign/QueryTabWinUndoAct.cxx | 6 | ||||
-rw-r--r-- | dbaccess/source/ui/querydesign/QueryTableView.cxx | 39 | ||||
-rw-r--r-- | dbaccess/source/ui/querydesign/TableWindow.cxx | 41 | ||||
-rw-r--r-- | dbaccess/source/ui/relationdesign/RelationTableView.cxx | 6 |
8 files changed, 119 insertions, 156 deletions
diff --git a/dbaccess/source/ui/inc/TableWindow.hxx b/dbaccess/source/ui/inc/TableWindow.hxx index c554f3447477..3a012069bf32 100644 --- a/dbaccess/source/ui/inc/TableWindow.hxx +++ b/dbaccess/source/ui/inc/TableWindow.hxx @@ -2,9 +2,9 @@ * * $RCSfile: TableWindow.hxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: oj $ $Date: 2002-06-24 07:49:59 $ + * last change: $Author: oj $ $Date: 2002-06-27 08:19:42 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -76,9 +76,7 @@ #ifndef DBAUI_TABLEWINDOWDATA_HXX #include "TableWindowData.hxx" #endif -#ifndef _VECTOR_ #include <vector> -#endif #ifndef _SV_WINDOW_HXX #include <vcl/window.hxx> #endif @@ -114,6 +112,7 @@ namespace dbaui OTableWindowTitle m_aTitle; OTableWindowListBox* m_pListBox; IAccessibleHelper* m_pAccessible; + private: // the columns of the table ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xTable; @@ -137,12 +136,9 @@ namespace dbaui virtual OTableWindowListBox* CreateListBox(); // wird im ERSTEN Init aufgerufen - virtual BOOL FillListBox(); + BOOL FillListBox(); // wird in JEDEM Init aufgerufen - virtual void EmptyListBox(); - // Liste wird geleert, damit haben abgeleitete Klassen die Moeglichkeit, eventuell gesetzte UserData zu loeschen - virtual void OnEntryDoubleClicked(SvLBoxEntry* pEntry) { } // wird aus dem DoubleClickHdl der ListBox heraus aufgerufen @@ -153,6 +149,25 @@ namespace dbaui <TRUE/> when the table could handle the keyevent. */ BOOL HandleKeyInput( const KeyEvent& rEvt ); + + /** delete the user data with the equal type as created within createUserData + @param _pUserData + The user data store in the listbox entries. Created with a call to createUserData. + _pUserData may be <NULL/>. _pUserData will be set to <NULL/> after call. + */ + virtual void deleteUserData(void*& _pUserData); + + /** creates user information that will be append at the ListBoxentry + @param _xColumn + The corresponding column, can be <NULL/>. + @param _bPrimaryKey + <TRUE/> when the column belongs to the primary key + @return + the user data which will be append at the listbox entry, may be <NULL/> + */ + virtual void* createUserData(const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet>& _xColumn, + bool _bPrimaryKey); public: TYPEINFO(); OTableWindow( Window* pParent, OTableWindowData* pTabWinData); @@ -216,6 +231,10 @@ namespace dbaui // OEventListenerAdapter virtual void _disposing( const ::com::sun::star::lang::EventObject& _rSource ); + + /** clears the listbox inside. Must be called be the dtor is called. + */ + void clearListBox(); }; } #endif //DBAUI_TABLEWINDOW_HXX diff --git a/dbaccess/source/ui/querydesign/JoinTableView.cxx b/dbaccess/source/ui/querydesign/JoinTableView.cxx index 2b23fc4c20ea..b36a4ae650e7 100644 --- a/dbaccess/source/ui/querydesign/JoinTableView.cxx +++ b/dbaccess/source/ui/querydesign/JoinTableView.cxx @@ -2,9 +2,9 @@ * * $RCSfile: JoinTableView.cxx,v $ * - * $Revision: 1.38 $ + * $Revision: 1.39 $ * - * last change: $Author: oj $ $Date: 2002-06-24 07:56:02 $ + * last change: $Author: oj $ $Date: 2002-06-27 08:21:02 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -400,6 +400,7 @@ void OJoinTableView::AddTabWin(const ::rtl::OUString& _rComposedName, const ::rt else { delete pNewTabWinData; + pNewTabWin->clearListBox(); delete pNewTabWin; } } @@ -448,6 +449,8 @@ void OJoinTableView::RemoveTabWin( OTableWindow* pTabWin ) if (pTabWin == m_pLastFocusTabWin) m_pLastFocusTabWin = NULL; + + pTabWin->clearListBox(); delete pTabWin; } @@ -1649,7 +1652,11 @@ void OJoinTableView::clearLayoutInformation() // Listen loeschen OTableWindowMapIterator aIter = m_aTableMap.begin(); for(;aIter != m_aTableMap.end();++aIter) + { + if ( aIter->second ) + aIter->second->clearListBox(); delete aIter->second; + } m_aTableMap.clear(); diff --git a/dbaccess/source/ui/querydesign/QTableWindow.cxx b/dbaccess/source/ui/querydesign/QTableWindow.cxx index aa85276d9c23..02994765bcc9 100644 --- a/dbaccess/source/ui/querydesign/QTableWindow.cxx +++ b/dbaccess/source/ui/querydesign/QTableWindow.cxx @@ -2,9 +2,9 @@ * * $RCSfile: QTableWindow.cxx,v $ * - * $Revision: 1.11 $ + * $Revision: 1.12 $ * - * last change: $Author: oj $ $Date: 2002-05-10 08:23:32 $ + * last change: $Author: oj $ $Date: 2002-06-27 08:21:02 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -222,7 +222,7 @@ sal_Bool OQueryTableWindow::Init() m_aTitle.SetText(GetAliasName()); m_aTitle.Show(); - EmptyListBox(); + clearListBox(); // neu zu fuellen brauche ich die nicht, da ich ja keine Tabelle habe m_pListBox->Show(); } @@ -230,101 +230,21 @@ sal_Bool OQueryTableWindow::Init() getTableView()->getDesignView()->getController()->InvalidateFeature(ID_BROWSER_QUERY_EXECUTE); return bSuccess; } -//------------------------------------------------------------------------------ -sal_Bool OQueryTableWindow::FillListBox() +// ----------------------------------------------------------------------------- +void* OQueryTableWindow::createUserData(const Reference< XPropertySet>& _xColumn,bool _bPrimaryKey) { - ModuleRes TmpRes(isHiContrast(m_pListBox) ? IMG_JOINS_H : IMG_JOINS); - ImageList aImageList(TmpRes); - Image aPrimKeyImage = aImageList.GetImage(IMG_PRIMARY_KEY); - - - - // first we need the keys from the table - Reference<XKeysSupplier> xKeys(GetTable(),UNO_QUERY); - Reference<XNameAccess> xPKeyColumns; - if(xKeys.is()) - { - Reference< XIndexAccess> xKeyIndex = xKeys->getKeys(); - Reference<XColumnsSupplier> xColumnsSupplier; - // search the one and only primary key - for(sal_Int32 i=0;i< xKeyIndex->getCount();++i) - { - Reference<XPropertySet> xProp; - ::cppu::extractInterface(xProp,xKeyIndex->getByIndex(i)); - OSL_ENSURE(xProp.is(),"OQueryTableWindow::FillListBox Key isn't a XPropertySet!"); - if(xProp.is()) - { - sal_Int32 nKeyType = 0; - xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType; - if(KeyType::PRIMARY == nKeyType) - { - xColumnsSupplier = Reference<XColumnsSupplier>(xProp,UNO_QUERY); - break; - } - } - } - if(xColumnsSupplier.is()) - xPKeyColumns = xColumnsSupplier->getColumns(); - } - - // first we need a * - SvLBoxEntry* pEntry = NULL; - if (GetData()->IsShowAll()) - { - pEntry = m_pListBox->InsertEntry( ::rtl::OUString::createFromAscii("*") ); - pEntry->SetUserData( new OTableFieldInfo() ); - } - - if(GetOriginalColumns().is()) - { - Sequence< ::rtl::OUString> aColumns = GetOriginalColumns()->getElementNames(); - const ::rtl::OUString* pBegin = aColumns.getConstArray(); - const ::rtl::OUString* pEnd = pBegin + aColumns.getLength(); - - for (; pBegin != pEnd; ++pBegin) - { - OTableFieldInfo* pInfo = new OTableFieldInfo(); - // is this column in the primary key - if (xPKeyColumns.is() && xPKeyColumns->hasByName(*pBegin)) - { - pEntry = m_pListBox->InsertEntry(*pBegin, aPrimKeyImage, aPrimKeyImage); - pInfo->SetKey(TAB_PRIMARY_FIELD); - } - else - { - pEntry = m_pListBox->InsertEntry(*pBegin); - pInfo->SetKey(TAB_NORMAL_FIELD); - } - Reference<XPropertySet> xColumn; - ::cppu::extractInterface(xColumn,GetOriginalColumns()->getByName(*pBegin)); - OSL_ENSURE(xColumn.is(),"No column!"); - if(xColumn.is()) - pInfo->SetDataType(::comphelper::getINT32(xColumn->getPropertyValue(PROPERTY_TYPE))); - pEntry->SetUserData( pInfo ); - } - } - return sal_True; + OTableFieldInfo* pInfo = new OTableFieldInfo(); + pInfo->SetKey(_bPrimaryKey ? TAB_PRIMARY_FIELD : TAB_NORMAL_FIELD); + if ( _xColumn.is() ) + pInfo->SetDataType(::comphelper::getINT32(_xColumn->getPropertyValue(PROPERTY_TYPE))); + return pInfo; } - -//------------------------------------------------------------------------------ -void OQueryTableWindow::EmptyListBox() +// ----------------------------------------------------------------------------- +void OQueryTableWindow::deleteUserData(void*& _pUserData) { - if(m_pListBox) - { - SvLBoxEntry* pEntry = m_pListBox->First(); - - while(pEntry) - { - OTableFieldInfo* pInf = (OTableFieldInfo*)pEntry->GetUserData(); - delete pInf; - - SvLBoxEntry* pNextEntry = m_pListBox->Next(pEntry); - m_pListBox->GetModel()->Remove(pEntry); - pEntry = pNextEntry; - } - } + delete static_cast<OTableFieldInfo*>(_pUserData); + _pUserData = NULL; } - //------------------------------------------------------------------------------ void OQueryTableWindow::OnEntryDoubleClicked(SvLBoxEntry* pEntry) { diff --git a/dbaccess/source/ui/querydesign/QTableWindow.hxx b/dbaccess/source/ui/querydesign/QTableWindow.hxx index 8cb7aba8a731..97555cd61e15 100644 --- a/dbaccess/source/ui/querydesign/QTableWindow.hxx +++ b/dbaccess/source/ui/querydesign/QTableWindow.hxx @@ -2,9 +2,9 @@ * * $RCSfile: QTableWindow.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: oj $ $Date: 2001-10-05 06:49:18 $ + * last change: $Author: oj $ $Date: 2002-06-27 08:21:02 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -106,14 +106,27 @@ namespace dbaui protected: virtual void KeyInput( const KeyEvent& rEvt ); - // wird im ERSTEN Init aufgerufen - virtual BOOL FillListBox(); - // wird in JEDEM Init aufgerufen - virtual void EmptyListBox(); - // ListBox definiert leeren - virtual void OnEntryDoubleClicked(SvLBoxEntry* pEntry); // wird aus dem DoubleClickHdl der ListBox heraus aufgerufen + /** delete the user data with the equal type as created within createUserData + @param _pUserData + The user data store in the listbox entries. Created with a call to createUserData. + _pUserData may be <NULL/>. + */ + virtual void deleteUserData(void*& _pUserData); + + /** creates user information that will be append at the ListBoxentry + @param _xColumn + The corresponding column, can be <NULL/>. + @param _bPrimaryKey + <TRUE/> when the column belongs to the primary key + @return + the user data which will be append at the listbox entry, may be <NULL/> + */ + virtual void* createUserData(const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet>& _xColumn, + bool _bPrimaryKey); + }; } #endif // DBAUI_QUERY_TABLEWINDOW_HXX diff --git a/dbaccess/source/ui/querydesign/QueryTabWinUndoAct.cxx b/dbaccess/source/ui/querydesign/QueryTabWinUndoAct.cxx index 54310322a6d3..bab154b571b5 100644 --- a/dbaccess/source/ui/querydesign/QueryTabWinUndoAct.cxx +++ b/dbaccess/source/ui/querydesign/QueryTabWinUndoAct.cxx @@ -2,9 +2,9 @@ * * $RCSfile: QueryTabWinUndoAct.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: oj $ $Date: 2002-02-06 08:15:30 $ + * last change: $Author: oj $ $Date: 2002-06-27 08:22:08 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -103,6 +103,8 @@ OQueryTabWinUndoAct::~OQueryTabWinUndoAct() OSL_ENSURE(!m_pTabWin->IsVisible(), "OQueryTabWinUndoAct::~OQueryTabWinUndoAct() : *m_pTabWin sollte nicht sichtbar sein"); delete m_pTabWin->GetData(); + if ( m_pTabWin ) + m_pTabWin->clearListBox(); delete m_pTabWin; // und natuerlich auch die entsprechenden Connections diff --git a/dbaccess/source/ui/querydesign/QueryTableView.cxx b/dbaccess/source/ui/querydesign/QueryTableView.cxx index 673c3bdc8560..3af4fbc03f6a 100644 --- a/dbaccess/source/ui/querydesign/QueryTableView.cxx +++ b/dbaccess/source/ui/querydesign/QueryTableView.cxx @@ -2,9 +2,9 @@ * * $RCSfile: QueryTableView.cxx,v $ * - * $Revision: 1.22 $ + * $Revision: 1.23 $ * - * last change: $Author: oj $ $Date: 2002-05-22 10:43:25 $ + * last change: $Author: oj $ $Date: 2002-06-27 08:21:02 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -157,32 +157,6 @@ using namespace ::com::sun::star::container; TYPEINIT1(OQueryTableView, OJoinTableView); //------------------------------------------------------------------------------ -::rtl::OUString ConvertAlias(const ::rtl::OUString& _rName) -{ - if (!_rName.getLength()) - return _rName; - - String rName(_rName); - - const sal_Unicode* pStr = rName.GetBuffer(); - sal_Bool bValid(!((*pStr >= 48) && (*pStr <= 57))); // keine Zahl am Anfang - - String aTmp; - if (bValid) - aTmp = rName; - - for (sal_Int32 i=0; i < rName.Len() && *pStr;i++, pStr++ ){ - if ( ((*pStr >= 97) && (*pStr <= 122)) ||((*pStr >= 65) && (*pStr <= 90)) || - ((*pStr >= 48) && (*pStr <= 57)) || *pStr == '_' ) - ; - else - aTmp.SearchAndReplace(*pStr,'_'); - - } - - return aTmp; -} - namespace { // ----------------------------------------------------------------------------- @@ -413,6 +387,7 @@ void OQueryTableView::ReSync() { // das Initialisieren ging schief, dass heisst, dieses TabWin steht nicht zur Verfuegung, also muss ich es inklusive // seiner Daten am Dokument aufraeumen + pTabWin->clearListBox(); delete pTabWin; arrInvalidTables.push_back(pData->GetAliasName()); @@ -522,8 +497,9 @@ void OQueryTableView::AddTabWin(const ::rtl::OUString& strDatabase, const ::rtl: return; try { + Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData(); ::rtl::OUString sCatalog, sSchema, sTable; - ::dbtools::qualifiedNameComponents(xConnection->getMetaData(), + ::dbtools::qualifiedNameComponents(xMetaData, strDatabase, sCatalog, sSchema, @@ -533,7 +509,7 @@ void OQueryTableView::AddTabWin(const ::rtl::OUString& strDatabase, const ::rtl: sRealName+= ::rtl::OUString('.'); sRealName += sTable; - AddTabWin(strDatabase, sRealName, ConvertAlias(strTableName), bNewTable); + AddTabWin(strDatabase, sRealName, strTableName, bNewTable); } catch(SQLException&) { @@ -1060,10 +1036,13 @@ sal_Bool OQueryTableView::ShowTabWin( OQueryTableWindow* pTabWin, OQueryTabWinUn bSuccess = sal_True; } else + { ////////////////////////////////////////////////////////////////// // Initialisierung fehlgeschlagen // (z.B. wenn Verbindung zur Datenbank in diesem Augenblick unterbrochen worden ist) + pTabWin->clearListBox(); delete pTabWin; + } } // damit habe ich das Doc natuerlich modifiziert diff --git a/dbaccess/source/ui/querydesign/TableWindow.cxx b/dbaccess/source/ui/querydesign/TableWindow.cxx index 2c80b3f8de9e..dc0267f67d32 100644 --- a/dbaccess/source/ui/querydesign/TableWindow.cxx +++ b/dbaccess/source/ui/querydesign/TableWindow.cxx @@ -2,9 +2,9 @@ * * $RCSfile: TableWindow.cxx,v $ * - * $Revision: 1.21 $ + * $Revision: 1.22 $ * - * last change: $Author: oj $ $Date: 2002-06-24 07:49:06 $ + * last change: $Author: oj $ $Date: 2002-06-27 08:21:01 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -188,7 +188,7 @@ OTableWindow::~OTableWindow() stopComponentListening(xComponent); if (m_pListBox) { - EmptyListBox(); + OSL_ENSURE(m_pListBox->GetEntryCount()==0,"Forgot to call EmptyListbox()!"); ::std::auto_ptr<Window> aTemp(m_pListBox); m_pListBox = NULL; } @@ -255,7 +255,10 @@ BOOL OTableWindow::FillListBox() Image aPrimKeyImage = aImageList.GetImage(IMG_PRIMARY_KEY); if (GetData()->IsShowAll()) - m_pListBox->InsertEntry( ::rtl::OUString::createFromAscii("*") ); + { + SvLBoxEntry* pEntry = m_pListBox->InsertEntry( ::rtl::OUString::createFromAscii("*") ); + pEntry->SetUserData( createUserData(NULL,false) ); + } ::osl::MutexGuard aGuard( m_aMutex ); // first we need the keys from the table @@ -287,21 +290,37 @@ BOOL OTableWindow::FillListBox() const ::rtl::OUString* pBegin = aColumns.getConstArray(); const ::rtl::OUString* pEnd = pBegin + aColumns.getLength(); + SvLBoxEntry* pEntry = NULL; for (; pBegin != pEnd; ++pBegin) { + bool bPrimaryKeyColumn; // is this column in the primary key - if (xPKeyColumns.is() && xPKeyColumns->hasByName(*pBegin)) - m_pListBox->InsertEntry(*pBegin, aPrimKeyImage, aPrimKeyImage); + if ( bPrimaryKeyColumn = (xPKeyColumns.is() && xPKeyColumns->hasByName(*pBegin)) ) + pEntry = m_pListBox->InsertEntry(*pBegin, aPrimKeyImage, aPrimKeyImage); else - m_pListBox->InsertEntry(*pBegin); + pEntry = m_pListBox->InsertEntry(*pBegin); + + Reference<XPropertySet> xColumn; + m_xColumns->getByName(*pBegin) >>= xColumn; + pEntry->SetUserData( createUserData(xColumn,bPrimaryKeyColumn) ); } } return TRUE; } - +// ----------------------------------------------------------------------------- +void* OTableWindow::createUserData(const Reference< XPropertySet>& _xColumn,bool _bPrimaryKey) +{ + return NULL; +} +// ----------------------------------------------------------------------------- +void OTableWindow::deleteUserData(void*& _pUserData) +{ + OSL_ENSURE(!_pUserData,"INVALID call. Need to delete the userclass!"); + _pUserData = NULL; +} //------------------------------------------------------------------------------ -void OTableWindow::EmptyListBox() +void OTableWindow::clearListBox() { // da ich defaultmaessig keine USerData an die Items haenge, kann ich hier einfach loeschen if ( m_pListBox ) @@ -310,6 +329,8 @@ void OTableWindow::EmptyListBox() while(pEntry) { + void* pUserData = pEntry->GetUserData(); + deleteUserData(pUserData); SvLBoxEntry* pNextEntry = m_pListBox->Next(pEntry); m_pListBox->GetModel()->Remove(pEntry); pEntry = pNextEntry; @@ -385,7 +406,7 @@ BOOL OTableWindow::Init() m_pListBox->Show(); // die Felder in die ListBox eintragen - EmptyListBox(); + clearListBox(); if (bInit = FillListBox()) m_pListBox->SelectAll(FALSE); } diff --git a/dbaccess/source/ui/relationdesign/RelationTableView.cxx b/dbaccess/source/ui/relationdesign/RelationTableView.cxx index c9e080eea832..82a1c61b2a42 100644 --- a/dbaccess/source/ui/relationdesign/RelationTableView.cxx +++ b/dbaccess/source/ui/relationdesign/RelationTableView.cxx @@ -2,9 +2,9 @@ * * $RCSfile: RelationTableView.cxx,v $ * - * $Revision: 1.11 $ + * $Revision: 1.12 $ * - * last change: $Author: oj $ $Date: 2002-05-22 11:16:34 $ + * last change: $Author: oj $ $Date: 2002-06-27 08:23:50 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -195,6 +195,7 @@ void ORelationTableView::ReSync() { // das Initialisieren ging schief, dass heisst, dieses TabWin steht nicht zur Verfuegung, also muss ich es inklusive // seiner Daten am Dokument aufraeumen + pTabWin->clearListBox(); delete pTabWin; arrInvalidTables.push_back(pData->GetTableName()); @@ -478,6 +479,7 @@ void ORelationTableView::AddTabWin(const ::rtl::OUString& _rComposedName, const else { delete pNewTabWinData; + pNewTabWin->clearListBox(); delete pNewTabWin; } } |