1*96de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*96de5490SAndrew Rist * distributed with this work for additional information 6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance 9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*96de5490SAndrew Rist * software distributed under the License is distributed on an 15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the 17*96de5490SAndrew Rist * specific language governing permissions and limitations 18*96de5490SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*96de5490SAndrew Rist *************************************************************/ 21*96de5490SAndrew Rist 22*96de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _DBAUI_TABLESPAGE_HXX_ 28cdf0e10cSrcweir #include "tablespage.hxx" 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir #ifndef _DBU_DLG_HRC_ 31cdf0e10cSrcweir #include "dbu_dlg.hrc" 32cdf0e10cSrcweir #endif 33cdf0e10cSrcweir #ifndef _DBAUI_DBADMIN_HRC_ 34cdf0e10cSrcweir #include "dbadmin.hrc" 35cdf0e10cSrcweir #endif 36cdf0e10cSrcweir #ifndef _DBAUI_DATASOURCEITEMS_HXX_ 37cdf0e10cSrcweir #include "dsitems.hxx" 38cdf0e10cSrcweir #endif 39cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX 40cdf0e10cSrcweir #include "browserids.hxx" 41cdf0e10cSrcweir #endif 42cdf0e10cSrcweir #ifndef _DBAUI_DATASOURCECONNECTOR_HXX_ 43cdf0e10cSrcweir #include "datasourceconnector.hxx" 44cdf0e10cSrcweir #endif 45cdf0e10cSrcweir #ifndef _COMPHELPER_TYPES_HXX_ 46cdf0e10cSrcweir #include <comphelper/types.hxx> 47cdf0e10cSrcweir #endif 48cdf0e10cSrcweir #ifndef _CONNECTIVITY_DBTOOLS_HXX_ 49cdf0e10cSrcweir #include <connectivity/dbtools.hxx> 50cdf0e10cSrcweir #endif 51cdf0e10cSrcweir #ifndef _DBHELPER_DBEXCEPTION_HXX_ 52cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 53cdf0e10cSrcweir #endif 54cdf0e10cSrcweir #ifndef _DBAUI_STRINGLISTITEM_HXX_ 55cdf0e10cSrcweir #include "stringlistitem.hxx" 56cdf0e10cSrcweir #endif 57cdf0e10cSrcweir #ifndef _SFXENUMITEM_HXX 58cdf0e10cSrcweir #include <svl/eitem.hxx> 59cdf0e10cSrcweir #endif 60cdf0e10cSrcweir #ifndef _SFXSTRITEM_HXX 61cdf0e10cSrcweir #include <svl/stritem.hxx> 62cdf0e10cSrcweir #endif 63cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC 64cdf0e10cSrcweir #include "dbustrings.hrc" 65cdf0e10cSrcweir #endif 66cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX 67cdf0e10cSrcweir #include <vcl/svapp.hxx> 68cdf0e10cSrcweir #endif 69cdf0e10cSrcweir #ifndef _SV_WAITOBJ_HXX 70cdf0e10cSrcweir #include <vcl/waitobj.hxx> 71cdf0e10cSrcweir #endif 72cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_ 73cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp> 74cdf0e10cSrcweir #endif 75cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_ 76cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp> 77cdf0e10cSrcweir #endif 78cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_ 79cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAppend.hpp> 80cdf0e10cSrcweir #endif 81cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_XMODIFIABLE_HPP_ 82cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 83cdf0e10cSrcweir #endif 84cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XDROP_HPP_ 85cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDrop.hpp> 86cdf0e10cSrcweir #endif 87cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XDATADEFINITIONSUPPLIER_HPP_ 88cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> 89cdf0e10cSrcweir #endif 90cdf0e10cSrcweir #ifndef _DBAUI_SQLMESSAGE_HXX_ 91cdf0e10cSrcweir #include "sqlmessage.hxx" 92cdf0e10cSrcweir #endif 93cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX 94cdf0e10cSrcweir #include <vcl/msgbox.hxx> 95cdf0e10cSrcweir #endif 96cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_ 97cdf0e10cSrcweir #include "dbaccess_helpid.hrc" 98cdf0e10cSrcweir #endif 99cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX 100cdf0e10cSrcweir #include "UITools.hxx" 101cdf0e10cSrcweir #endif 102cdf0e10cSrcweir #ifndef _VOS_MUTEX_HXX_ 103cdf0e10cSrcweir #include <vos/mutex.hxx> 104cdf0e10cSrcweir #endif 105cdf0e10cSrcweir #ifndef _SVTOOLS_IMGDEF_HXX 106cdf0e10cSrcweir #include <svtools/imgdef.hxx> 107cdf0e10cSrcweir #endif 108cdf0e10cSrcweir #ifndef _DBAUI_TABLESSINGLEDLG_HXX_ 109cdf0e10cSrcweir #include "TablesSingleDlg.hxx" 110cdf0e10cSrcweir #endif 111cdf0e10cSrcweir #ifndef TOOLS_DIAGNOSE_EX_H 112cdf0e10cSrcweir #include <tools/diagnose_ex.h> 113cdf0e10cSrcweir #endif 114cdf0e10cSrcweir #ifndef _CPPUHELPER_EXC_HLP_HXX_ 115cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 116cdf0e10cSrcweir #endif 117cdf0e10cSrcweir #ifndef _DBAUI_AUTOCONTROLS_HRC_ 118cdf0e10cSrcweir #include "AutoControls.hrc" 119cdf0e10cSrcweir #endif 120cdf0e10cSrcweir 121cdf0e10cSrcweir //......................................................................... 122cdf0e10cSrcweir namespace dbaui 123cdf0e10cSrcweir { 124cdf0e10cSrcweir //......................................................................... 125cdf0e10cSrcweir 126cdf0e10cSrcweir using namespace ::com::sun::star::uno; 127cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 128cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 129cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 130cdf0e10cSrcweir using namespace ::com::sun::star::beans; 131cdf0e10cSrcweir using namespace ::com::sun::star::lang; 132cdf0e10cSrcweir using namespace ::com::sun::star::i18n; 133cdf0e10cSrcweir using namespace ::com::sun::star::container; 134cdf0e10cSrcweir using namespace ::com::sun::star::frame; 135cdf0e10cSrcweir using namespace ::com::sun::star::util; 136cdf0e10cSrcweir using namespace ::dbtools; 137cdf0e10cSrcweir using namespace ::comphelper; 138cdf0e10cSrcweir 139cdf0e10cSrcweir //======================================================================== 140cdf0e10cSrcweir //= OTableSubscriptionPage 141cdf0e10cSrcweir //======================================================================== 142cdf0e10cSrcweir DBG_NAME(OTableSubscriptionPage) 143cdf0e10cSrcweir //------------------------------------------------------------------------ 144cdf0e10cSrcweir OTableSubscriptionPage::OTableSubscriptionPage( Window* pParent, const SfxItemSet& _rCoreAttrs,OTableSubscriptionDialog* _pTablesDlg ) 145cdf0e10cSrcweir :OGenericAdministrationPage( pParent, ModuleRes(PAGE_TABLESUBSCRIPTION), _rCoreAttrs ) 146cdf0e10cSrcweir ,m_aTables (this, ModuleRes(FL_SEPARATOR1)) 147cdf0e10cSrcweir ,m_aTablesList (this, NULL,ModuleRes(CTL_TABLESUBSCRIPTION),sal_True) 148cdf0e10cSrcweir ,m_aExplanation (this, ModuleRes(FT_FILTER_EXPLANATION)) 149cdf0e10cSrcweir ,m_bCheckedAll ( sal_False ) 150cdf0e10cSrcweir ,m_bCatalogAtStart ( sal_True ) 151cdf0e10cSrcweir ,m_pTablesDlg(_pTablesDlg) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir DBG_CTOR(OTableSubscriptionPage,NULL); 154cdf0e10cSrcweir 155cdf0e10cSrcweir m_aTablesList.SetCheckHandler(getControlModifiedLink()); 156cdf0e10cSrcweir 157cdf0e10cSrcweir // initialize the TabListBox 158cdf0e10cSrcweir m_aTablesList.SetSelectionMode( MULTIPLE_SELECTION ); 159cdf0e10cSrcweir m_aTablesList.SetDragDropMode( 0 ); 160cdf0e10cSrcweir m_aTablesList.EnableInplaceEditing( sal_False ); 161cdf0e10cSrcweir m_aTablesList.SetStyle(m_aTablesList.GetStyle() | WB_BORDER | WB_HASLINES | WB_HASLINESATROOT | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT); 162cdf0e10cSrcweir 163cdf0e10cSrcweir m_aTablesList.Clear(); 164cdf0e10cSrcweir 165cdf0e10cSrcweir FreeResource(); 166cdf0e10cSrcweir 167cdf0e10cSrcweir m_aTablesList.SetCheckButtonHdl(LINK(this, OTableSubscriptionPage, OnTreeEntryChecked)); 168cdf0e10cSrcweir m_aTablesList.SetCheckHandler(LINK(this, OTableSubscriptionPage, OnTreeEntryChecked)); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir //------------------------------------------------------------------------ 172cdf0e10cSrcweir OTableSubscriptionPage::~OTableSubscriptionPage() 173cdf0e10cSrcweir { 174cdf0e10cSrcweir // just to make sure that our connection will be removed 175cdf0e10cSrcweir try 176cdf0e10cSrcweir { 177cdf0e10cSrcweir ::comphelper::disposeComponent(m_xCurrentConnection); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir catch (RuntimeException&) { } 180cdf0e10cSrcweir 181cdf0e10cSrcweir DBG_DTOR(OTableSubscriptionPage,NULL); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir // ----------------------------------------------------------------------------- 185cdf0e10cSrcweir void OTableSubscriptionPage::StateChanged( StateChangedType nType ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir OGenericAdministrationPage::StateChanged( nType ); 188cdf0e10cSrcweir 189cdf0e10cSrcweir if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir // Check if we need to get new images for normal/high contrast mode 192cdf0e10cSrcweir m_aTablesList.notifyHiContrastChanged(); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir } 195cdf0e10cSrcweir // ----------------------------------------------------------------------------- 196cdf0e10cSrcweir void OTableSubscriptionPage::DataChanged( const DataChangedEvent& rDCEvt ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir OGenericAdministrationPage::DataChanged( rDCEvt ); 199cdf0e10cSrcweir 200cdf0e10cSrcweir if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS ) || 201cdf0e10cSrcweir ( rDCEvt.GetType() == DATACHANGED_DISPLAY )) && 202cdf0e10cSrcweir ( rDCEvt.GetFlags() & SETTINGS_STYLE )) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir // Check if we need to get new images for normal/high contrast mode 205cdf0e10cSrcweir m_aTablesList.notifyHiContrastChanged(); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir } 208cdf0e10cSrcweir //------------------------------------------------------------------ 209cdf0e10cSrcweir void OTableSubscriptionPage::resizeControls(const Size& _rDiff) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir if ( _rDiff.Height() ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir Size aOldSize = m_aTablesList.GetSizePixel(); 214cdf0e10cSrcweir aOldSize.Height() -= _rDiff.Height(); 215cdf0e10cSrcweir m_aTablesList.SetPosSizePixel( 216cdf0e10cSrcweir m_aTablesList.GetPosPixel()+Point(0,_rDiff.Height()), 217cdf0e10cSrcweir aOldSize 218cdf0e10cSrcweir ); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir } 221cdf0e10cSrcweir //------------------------------------------------------------------------ 222cdf0e10cSrcweir void OTableSubscriptionPage::implCheckTables(const Sequence< ::rtl::OUString >& _rTables) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir // the meta data for the current connection, used for splitting up table names 225cdf0e10cSrcweir Reference< XDatabaseMetaData > xMeta; 226cdf0e10cSrcweir try 227cdf0e10cSrcweir { 228cdf0e10cSrcweir if (m_xCurrentConnection.is()) 229cdf0e10cSrcweir xMeta = m_xCurrentConnection->getMetaData(); 230cdf0e10cSrcweir } 231cdf0e10cSrcweir catch(SQLException&) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir DBG_ERROR("OTableSubscriptionPage::implCheckTables : could not retrieve the current connection's meta data!"); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir // uncheck all 237cdf0e10cSrcweir CheckAll(sal_False); 238cdf0e10cSrcweir 239cdf0e10cSrcweir // check the ones which are in the list 240cdf0e10cSrcweir String aListBoxTable; 241cdf0e10cSrcweir ::rtl::OUString sCatalog, sSchema, sName; 242cdf0e10cSrcweir 243cdf0e10cSrcweir SvLBoxEntry* pRootEntry = m_aTablesList.getAllObjectsEntry(); 244cdf0e10cSrcweir sal_Bool bAllTables = sal_False; 245cdf0e10cSrcweir sal_Bool bAllSchemas = sal_False; 246cdf0e10cSrcweir 247cdf0e10cSrcweir const ::rtl::OUString* pIncludeTable = _rTables.getConstArray(); 248cdf0e10cSrcweir for (sal_Int32 i=0; i<_rTables.getLength(); ++i, ++pIncludeTable) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir if (xMeta.is()) 251cdf0e10cSrcweir qualifiedNameComponents(xMeta, pIncludeTable->getStr(), sCatalog, sSchema, sName,::dbtools::eInDataManipulation); 252cdf0e10cSrcweir else 253cdf0e10cSrcweir sName = pIncludeTable->getStr(); 254cdf0e10cSrcweir 255cdf0e10cSrcweir bAllTables = (1 == sName.getLength()) && ('%' == sName[0]); 256cdf0e10cSrcweir bAllSchemas = (1 == sSchema.getLength()) && ('%' == sSchema[0]); 257cdf0e10cSrcweir 258cdf0e10cSrcweir // the catalog entry 259cdf0e10cSrcweir SvLBoxEntry* pCatalog = m_aTablesList.GetEntryPosByName(sCatalog, pRootEntry); 260cdf0e10cSrcweir if (!pCatalog && sCatalog.getLength()) 261cdf0e10cSrcweir // the table (resp. its catalog) refered in this filter entry does not exist anymore 262cdf0e10cSrcweir continue; 263cdf0e10cSrcweir 264cdf0e10cSrcweir if (bAllSchemas && pCatalog) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir m_aTablesList.checkWildcard(pCatalog); 267cdf0e10cSrcweir continue; 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir // the schema entry 271cdf0e10cSrcweir SvLBoxEntry* pSchema = m_aTablesList.GetEntryPosByName(sSchema, (pCatalog ? pCatalog : pRootEntry)); 272cdf0e10cSrcweir if (!pSchema && sSchema.getLength()) 273cdf0e10cSrcweir // the table (resp. its schema) refered in this filter entry does not exist anymore 274cdf0e10cSrcweir continue; 275cdf0e10cSrcweir 276cdf0e10cSrcweir if (bAllTables && pSchema) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir m_aTablesList.checkWildcard(pSchema); 279cdf0e10cSrcweir continue; 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir SvLBoxEntry* pEntry = m_aTablesList.GetEntryPosByName(sName, pSchema ? pSchema : (pCatalog ? pCatalog : pRootEntry) ); 283cdf0e10cSrcweir if (pEntry) 284cdf0e10cSrcweir m_aTablesList.SetCheckButtonState(pEntry, SV_BUTTON_CHECKED); 285cdf0e10cSrcweir } 286cdf0e10cSrcweir m_aTablesList.CheckButtons(); 287cdf0e10cSrcweir } 288cdf0e10cSrcweir 289cdf0e10cSrcweir //------------------------------------------------------------------------ 290cdf0e10cSrcweir void OTableSubscriptionPage::implCompleteTablesCheck( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rTableFilter ) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir if (!_rTableFilter.getLength()) 293cdf0e10cSrcweir { // no tables visible 294cdf0e10cSrcweir CheckAll(sal_False); 295cdf0e10cSrcweir } 296cdf0e10cSrcweir else 297cdf0e10cSrcweir { 298cdf0e10cSrcweir if ((1 == _rTableFilter.getLength()) && _rTableFilter[0].equalsAsciiL("%", 1)) 299cdf0e10cSrcweir { // all tables visible 300cdf0e10cSrcweir CheckAll(sal_True); 301cdf0e10cSrcweir } 302cdf0e10cSrcweir else 303cdf0e10cSrcweir implCheckTables( _rTableFilter ); 304cdf0e10cSrcweir } 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir //------------------------------------------------------------------------- 308cdf0e10cSrcweir void OTableSubscriptionPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) 311cdf0e10cSrcweir sal_Bool bValid, bReadonly; 312cdf0e10cSrcweir getFlags(_rSet, bValid, bReadonly); 313cdf0e10cSrcweir 314cdf0e10cSrcweir // get the name of the data source we're working for 315cdf0e10cSrcweir SFX_ITEMSET_GET(_rSet, pNameItem, SfxStringItem, DSID_NAME, sal_True); 316cdf0e10cSrcweir DBG_ASSERT(pNameItem, "OTableSubscriptionPage::implInitControls: missing the name attribute!"); 317cdf0e10cSrcweir String sDSName = pNameItem->GetValue(); 318cdf0e10cSrcweir 319cdf0e10cSrcweir if (bValid && sDSName.Len() && !m_xCurrentConnection.is() ) 320cdf0e10cSrcweir { // get the current table list from the connection for the current settings 321cdf0e10cSrcweir 322cdf0e10cSrcweir // the PropertyValues for the current dialog settings 323cdf0e10cSrcweir Sequence< PropertyValue > aConnectionParams; 324cdf0e10cSrcweir DBG_ASSERT(m_pTablesDlg, "OTableSubscriptionPage::implInitControls: need a parent dialog doing the translation!"); 325cdf0e10cSrcweir if ( m_pTablesDlg ) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir if (!m_pTablesDlg->getCurrentSettings(aConnectionParams)) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir m_aTablesList.Clear(); 330cdf0e10cSrcweir m_pTablesDlg->endExecution(); 331cdf0e10cSrcweir return; 332cdf0e10cSrcweir } 333cdf0e10cSrcweir } 334cdf0e10cSrcweir 335cdf0e10cSrcweir if (!m_xCollator.is()) 336cdf0e10cSrcweir { 337cdf0e10cSrcweir // the collator for the string compares 338cdf0e10cSrcweir try 339cdf0e10cSrcweir { 340cdf0e10cSrcweir m_xCollator = Reference< XCollator >(m_xORB->createInstance(SERVICE_I18N_COLLATOR), UNO_QUERY); 341cdf0e10cSrcweir if (m_xCollator.is()) 342cdf0e10cSrcweir m_xCollator->loadDefaultCollator(Application::GetSettings().GetLocale(), 0); 343cdf0e10cSrcweir } 344cdf0e10cSrcweir catch(const Exception&) 345cdf0e10cSrcweir { 346cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 347cdf0e10cSrcweir } 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir // fill the table list with this connection information 351cdf0e10cSrcweir SQLExceptionInfo aErrorInfo; 352cdf0e10cSrcweir // the current DSN 353cdf0e10cSrcweir String sURL; 354cdf0e10cSrcweir if ( m_pTablesDlg ) 355cdf0e10cSrcweir sURL = m_pTablesDlg->getConnectionURL(); 356cdf0e10cSrcweir 357cdf0e10cSrcweir try 358cdf0e10cSrcweir { 359cdf0e10cSrcweir WaitObject aWaitCursor(this); 360cdf0e10cSrcweir m_aTablesList.GetModel()->SetSortMode(SortAscending); 361cdf0e10cSrcweir m_aTablesList.GetModel()->SetCompareHdl(LINK(this, OTableSubscriptionPage, OnTreeEntryCompare)); 362cdf0e10cSrcweir 363cdf0e10cSrcweir Reference< XDriver > xDriver; 364cdf0e10cSrcweir m_aTablesList.setORB(m_xORB); 365cdf0e10cSrcweir Reference<XPropertySet> xProp = m_pTablesDlg->getCurrentDataSource(); 366cdf0e10cSrcweir OSL_ENSURE(xProp.is(),"No data source set!"); 367cdf0e10cSrcweir if ( xProp.is() ) 368cdf0e10cSrcweir { 369cdf0e10cSrcweir Any aTableFilter = xProp->getPropertyValue(PROPERTY_TABLEFILTER); 370cdf0e10cSrcweir Any aTableTypeFilter = xProp->getPropertyValue(PROPERTY_TABLETYPEFILTER); 371cdf0e10cSrcweir 372cdf0e10cSrcweir Reference<XModifiable> xModi(getDataSourceOrModel(xProp),UNO_QUERY); 373cdf0e10cSrcweir sal_Bool bModified = ( xModi.is() && xModi->isModified() ); 374cdf0e10cSrcweir 375cdf0e10cSrcweir Sequence< ::rtl::OUString > aNewTableFilter(1); 376cdf0e10cSrcweir aNewTableFilter[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")); 377cdf0e10cSrcweir xProp->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(aNewTableFilter)); 378cdf0e10cSrcweir 379cdf0e10cSrcweir xProp->setPropertyValue( PROPERTY_TABLETYPEFILTER, makeAny( Sequence< ::rtl::OUString >() ) ); 380cdf0e10cSrcweir Reference< ::com::sun::star::lang::XEventListener> xEvt; 381cdf0e10cSrcweir aErrorInfo = ::dbaui::createConnection(xProp,m_xORB,xEvt,m_xCurrentConnection); 382cdf0e10cSrcweir 383cdf0e10cSrcweir xProp->setPropertyValue(PROPERTY_TABLEFILTER,aTableFilter); 384cdf0e10cSrcweir xProp->setPropertyValue(PROPERTY_TABLETYPEFILTER,aTableTypeFilter); 385cdf0e10cSrcweir 386cdf0e10cSrcweir if ( xModi.is() && !bModified ) 387cdf0e10cSrcweir xModi->setModified(sal_False); 388cdf0e10cSrcweir 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir if ( m_xCurrentConnection.is() ) 392cdf0e10cSrcweir { 393cdf0e10cSrcweir m_aTablesList.UpdateTableList( m_xCurrentConnection ); 394cdf0e10cSrcweir if (m_pTablesDlg) 395cdf0e10cSrcweir m_pTablesDlg->successfullyConnected(); 396cdf0e10cSrcweir } 397cdf0e10cSrcweir } 398cdf0e10cSrcweir catch (const SQLException&) 399cdf0e10cSrcweir { 400cdf0e10cSrcweir aErrorInfo = ::cppu::getCaughtException(); 401cdf0e10cSrcweir } 402cdf0e10cSrcweir 403cdf0e10cSrcweir if (aErrorInfo.isValid()) 404cdf0e10cSrcweir { 405cdf0e10cSrcweir // establishing the connection failed. Show an error window and exit. 406cdf0e10cSrcweir OSQLMessageBox aMessageBox( GetParent()->GetParent(), aErrorInfo ); 407cdf0e10cSrcweir aMessageBox.Execute(); 408cdf0e10cSrcweir m_aTables.Enable(sal_False); 409cdf0e10cSrcweir m_aTablesList.Enable(sal_False); 410cdf0e10cSrcweir m_aExplanation.Enable(sal_False); 411cdf0e10cSrcweir m_aTablesList.Clear(); 412cdf0e10cSrcweir 413cdf0e10cSrcweir if ( m_pTablesDlg ) 414cdf0e10cSrcweir { 415cdf0e10cSrcweir m_pTablesDlg->clearPassword(); 416cdf0e10cSrcweir m_pTablesDlg->endExecution(); 417cdf0e10cSrcweir } 418cdf0e10cSrcweir } 419cdf0e10cSrcweir else 420cdf0e10cSrcweir { 421cdf0e10cSrcweir // in addition, we need some infos about the connection used 422cdf0e10cSrcweir m_sCatalogSeparator = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".")); // (default) 423cdf0e10cSrcweir m_bCatalogAtStart = sal_True; // (default) 424cdf0e10cSrcweir try 425cdf0e10cSrcweir { 426cdf0e10cSrcweir Reference< XDatabaseMetaData > xMeta; 427cdf0e10cSrcweir if (m_xCurrentConnection.is()) 428cdf0e10cSrcweir xMeta = m_xCurrentConnection->getMetaData(); 429cdf0e10cSrcweir if (xMeta.is() && xMeta->supportsCatalogsInDataManipulation()) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir m_sCatalogSeparator = xMeta->getCatalogSeparator(); 432cdf0e10cSrcweir m_bCatalogAtStart = xMeta->isCatalogAtStart(); 433cdf0e10cSrcweir } 434cdf0e10cSrcweir } 435cdf0e10cSrcweir catch(Exception&) 436cdf0e10cSrcweir { 437cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 438cdf0e10cSrcweir } 439cdf0e10cSrcweir } 440cdf0e10cSrcweir } 441cdf0e10cSrcweir 442cdf0e10cSrcweir bValid = bValid && m_xCurrentConnection.is(); 443cdf0e10cSrcweir bReadonly = bReadonly || !bValid; 444cdf0e10cSrcweir 445cdf0e10cSrcweir // get the current table filter 446cdf0e10cSrcweir SFX_ITEMSET_GET(_rSet, pTableFilter, OStringListItem, DSID_TABLEFILTER, sal_True); 447cdf0e10cSrcweir SFX_ITEMSET_GET(_rSet, pSuppress, SfxBoolItem, DSID_SUPPRESSVERSIONCL, sal_True); 448cdf0e10cSrcweir Sequence< ::rtl::OUString > aTableFilter; 449cdf0e10cSrcweir sal_Bool bSuppressVersionColumns = sal_True; 450cdf0e10cSrcweir if (pTableFilter) 451cdf0e10cSrcweir aTableFilter = pTableFilter->getList(); 452cdf0e10cSrcweir if (pSuppress) 453cdf0e10cSrcweir bSuppressVersionColumns = pSuppress->GetValue(); 454cdf0e10cSrcweir 455cdf0e10cSrcweir implCompleteTablesCheck( aTableFilter ); 456cdf0e10cSrcweir 457cdf0e10cSrcweir // expand the first entry by default 458cdf0e10cSrcweir SvLBoxEntry* pExpand = m_aTablesList.getAllObjectsEntry(); 459cdf0e10cSrcweir while (pExpand) 460cdf0e10cSrcweir { 461cdf0e10cSrcweir m_aTablesList.Expand(pExpand); 462cdf0e10cSrcweir pExpand = m_aTablesList.FirstChild(pExpand); 463cdf0e10cSrcweir if (pExpand && m_aTablesList.NextSibling(pExpand)) 464cdf0e10cSrcweir pExpand = NULL; 465cdf0e10cSrcweir } 466cdf0e10cSrcweir 467cdf0e10cSrcweir // update the toolbox according the the current selection and check state 468cdf0e10cSrcweir OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue); 469cdf0e10cSrcweir } 470cdf0e10cSrcweir 471cdf0e10cSrcweir //------------------------------------------------------------------------ 472cdf0e10cSrcweir void OTableSubscriptionPage::CheckAll( sal_Bool _bCheck ) 473cdf0e10cSrcweir { 474cdf0e10cSrcweir SvButtonState eState = _bCheck ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED; 475cdf0e10cSrcweir SvLBoxEntry* pEntry = m_aTablesList.First(); 476cdf0e10cSrcweir while (pEntry) 477cdf0e10cSrcweir { 478cdf0e10cSrcweir m_aTablesList.SetCheckButtonState( pEntry, eState); 479cdf0e10cSrcweir pEntry = m_aTablesList.Next(pEntry); 480cdf0e10cSrcweir } 481cdf0e10cSrcweir 482cdf0e10cSrcweir if (_bCheck && m_aTablesList.getAllObjectsEntry()) 483cdf0e10cSrcweir m_aTablesList.checkWildcard(m_aTablesList.getAllObjectsEntry()); 484cdf0e10cSrcweir } 485cdf0e10cSrcweir 486cdf0e10cSrcweir //------------------------------------------------------------------------ 487cdf0e10cSrcweir int OTableSubscriptionPage::DeactivatePage(SfxItemSet* _pSet) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir int nResult = OGenericAdministrationPage::DeactivatePage(_pSet); 490cdf0e10cSrcweir 491cdf0e10cSrcweir // dispose the connection, we don't need it anymore, so we're not wasting resources 492cdf0e10cSrcweir try 493cdf0e10cSrcweir { 494cdf0e10cSrcweir ::comphelper::disposeComponent(m_xCurrentConnection); 495cdf0e10cSrcweir } 496cdf0e10cSrcweir catch (RuntimeException&) { } 497cdf0e10cSrcweir 498cdf0e10cSrcweir return nResult; 499cdf0e10cSrcweir } 500cdf0e10cSrcweir //------------------------------------------------------------------------ 501cdf0e10cSrcweir IMPL_LINK( OTableSubscriptionPage, OnTreeEntryChecked, Control*, _pControl ) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir return OnControlModified(_pControl); 504cdf0e10cSrcweir } 505cdf0e10cSrcweir //------------------------------------------------------------------------ 506cdf0e10cSrcweir IMPL_LINK( OTableSubscriptionPage, OnTreeEntryCompare, const SvSortData*, _pSortData ) 507cdf0e10cSrcweir { 508cdf0e10cSrcweir SvLBoxEntry* pLHS = static_cast<SvLBoxEntry*>(_pSortData->pLeft); 509cdf0e10cSrcweir SvLBoxEntry* pRHS = static_cast<SvLBoxEntry*>(_pSortData->pRight); 510cdf0e10cSrcweir DBG_ASSERT(pLHS && pRHS, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid tree entries!"); 511cdf0e10cSrcweir 512cdf0e10cSrcweir SvLBoxString* pLeftTextItem = static_cast<SvLBoxString*>(pLHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING)); 513cdf0e10cSrcweir SvLBoxString* pRightTextItem = static_cast<SvLBoxString*>(pRHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING)); 514cdf0e10cSrcweir DBG_ASSERT(pLeftTextItem && pRightTextItem, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid text items!"); 515cdf0e10cSrcweir 516cdf0e10cSrcweir String sLeftText = pLeftTextItem->GetText(); 517cdf0e10cSrcweir String sRightText = pRightTextItem->GetText(); 518cdf0e10cSrcweir 519cdf0e10cSrcweir sal_Int32 nCompareResult = 0; // equal by default 520cdf0e10cSrcweir 521cdf0e10cSrcweir if (m_xCollator.is()) 522cdf0e10cSrcweir { 523cdf0e10cSrcweir try 524cdf0e10cSrcweir { 525cdf0e10cSrcweir nCompareResult = m_xCollator->compareString(sLeftText, sRightText); 526cdf0e10cSrcweir } 527cdf0e10cSrcweir catch(Exception&) 528cdf0e10cSrcweir { 529cdf0e10cSrcweir } 530cdf0e10cSrcweir } 531cdf0e10cSrcweir else 532cdf0e10cSrcweir // default behaviour if we do not have a collator -> do the simple string compare 533cdf0e10cSrcweir nCompareResult = sLeftText.CompareTo(sRightText); 534cdf0e10cSrcweir 535cdf0e10cSrcweir return nCompareResult; 536cdf0e10cSrcweir } 537cdf0e10cSrcweir 538cdf0e10cSrcweir //------------------------------------------------------------------------ 539cdf0e10cSrcweir Sequence< ::rtl::OUString > OTableSubscriptionPage::collectDetailedSelection() const 540cdf0e10cSrcweir { 541cdf0e10cSrcweir Sequence< ::rtl::OUString > aTableFilter; 542cdf0e10cSrcweir static const ::rtl::OUString sDot(RTL_CONSTASCII_USTRINGPARAM(".")); 543cdf0e10cSrcweir static const ::rtl::OUString sWildcard(RTL_CONSTASCII_USTRINGPARAM("%")); 544cdf0e10cSrcweir 545cdf0e10cSrcweir ::rtl::OUString sComposedName; 546cdf0e10cSrcweir const SvLBoxEntry* pAllObjectsEntry = m_aTablesList.getAllObjectsEntry(); 547cdf0e10cSrcweir if (!pAllObjectsEntry) 548cdf0e10cSrcweir return aTableFilter; 549cdf0e10cSrcweir SvLBoxEntry* pEntry = m_aTablesList.GetModel()->Next(const_cast<SvLBoxEntry*>(pAllObjectsEntry)); 550cdf0e10cSrcweir while(pEntry) 551cdf0e10cSrcweir { 552cdf0e10cSrcweir sal_Bool bCatalogWildcard = sal_False; 553cdf0e10cSrcweir sal_Bool bSchemaWildcard = sal_False; 554cdf0e10cSrcweir SvLBoxEntry* pSchema = NULL; 555cdf0e10cSrcweir SvLBoxEntry* pCatalog = NULL; 556cdf0e10cSrcweir 557cdf0e10cSrcweir if (m_aTablesList.GetCheckButtonState(pEntry) == SV_BUTTON_CHECKED && !m_aTablesList.GetModel()->HasChilds(pEntry)) 558cdf0e10cSrcweir { // checked and a leaf, which means it's no catalog, no schema, but a real table 559cdf0e10cSrcweir ::rtl::OUString sCatalog; 560cdf0e10cSrcweir if(m_aTablesList.GetModel()->HasParent(pEntry)) 561cdf0e10cSrcweir { 562cdf0e10cSrcweir pSchema = m_aTablesList.GetModel()->GetParent(pEntry); 563cdf0e10cSrcweir if (pAllObjectsEntry == pSchema) 564cdf0e10cSrcweir // do not want to have the root entry 565cdf0e10cSrcweir pSchema = NULL; 566cdf0e10cSrcweir 567cdf0e10cSrcweir if (pSchema) 568cdf0e10cSrcweir { // it's a real schema entry, not the "all objects" root 569cdf0e10cSrcweir if(m_aTablesList.GetModel()->HasParent(pSchema)) 570cdf0e10cSrcweir { 571cdf0e10cSrcweir pCatalog = m_aTablesList.GetModel()->GetParent(pSchema); 572cdf0e10cSrcweir if (pAllObjectsEntry == pCatalog) 573cdf0e10cSrcweir // do not want to have the root entry 574cdf0e10cSrcweir pCatalog = NULL; 575cdf0e10cSrcweir 576cdf0e10cSrcweir if (pCatalog) 577cdf0e10cSrcweir { // it's a real catalog entry, not the "all objects" root 578cdf0e10cSrcweir bCatalogWildcard = m_aTablesList.isWildcardChecked(pCatalog); 579cdf0e10cSrcweir if (m_bCatalogAtStart) 580cdf0e10cSrcweir { 581cdf0e10cSrcweir sComposedName += m_aTablesList.GetEntryText( pCatalog ); 582cdf0e10cSrcweir sComposedName += m_sCatalogSeparator; 583cdf0e10cSrcweir if (bCatalogWildcard) 584cdf0e10cSrcweir sComposedName += sWildcard; 585cdf0e10cSrcweir } 586cdf0e10cSrcweir else 587cdf0e10cSrcweir { 588cdf0e10cSrcweir if (bCatalogWildcard) 589cdf0e10cSrcweir sCatalog = sWildcard; 590cdf0e10cSrcweir else 591cdf0e10cSrcweir sCatalog = ::rtl::OUString(); 592cdf0e10cSrcweir sCatalog += m_sCatalogSeparator; 593cdf0e10cSrcweir sCatalog += m_aTablesList.GetEntryText( pCatalog ); 594cdf0e10cSrcweir } 595cdf0e10cSrcweir } 596cdf0e10cSrcweir } 597cdf0e10cSrcweir bSchemaWildcard = m_aTablesList.isWildcardChecked(pSchema); 598cdf0e10cSrcweir sComposedName += m_aTablesList.GetEntryText( pSchema ); 599cdf0e10cSrcweir sComposedName += sDot; 600cdf0e10cSrcweir } 601cdf0e10cSrcweir 602cdf0e10cSrcweir if (bSchemaWildcard) 603cdf0e10cSrcweir sComposedName += sWildcard; 604cdf0e10cSrcweir } 605cdf0e10cSrcweir if (!bSchemaWildcard && !bCatalogWildcard) 606cdf0e10cSrcweir sComposedName += m_aTablesList.GetEntryText( pEntry ); 607cdf0e10cSrcweir 608cdf0e10cSrcweir if (!m_bCatalogAtStart && !bCatalogWildcard) 609cdf0e10cSrcweir sComposedName += sCatalog; 610cdf0e10cSrcweir 611cdf0e10cSrcweir // need some space 612cdf0e10cSrcweir sal_Int32 nOldLen = aTableFilter.getLength(); 613cdf0e10cSrcweir aTableFilter.realloc(nOldLen + 1); 614cdf0e10cSrcweir // add the new name 615cdf0e10cSrcweir aTableFilter[nOldLen] = sComposedName; 616cdf0e10cSrcweir 617cdf0e10cSrcweir // reset the composed name 618cdf0e10cSrcweir sComposedName = ::rtl::OUString(); 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir if (bCatalogWildcard) 622cdf0e10cSrcweir pEntry = implNextSibling(pCatalog); 623cdf0e10cSrcweir else if (bSchemaWildcard) 624cdf0e10cSrcweir pEntry = implNextSibling(pSchema); 625cdf0e10cSrcweir else 626cdf0e10cSrcweir pEntry = m_aTablesList.GetModel()->Next(pEntry); 627cdf0e10cSrcweir } 628cdf0e10cSrcweir 629cdf0e10cSrcweir return aTableFilter; 630cdf0e10cSrcweir } 631cdf0e10cSrcweir 632cdf0e10cSrcweir //------------------------------------------------------------------------ 633cdf0e10cSrcweir SvLBoxEntry* OTableSubscriptionPage::implNextSibling(SvLBoxEntry* _pEntry) const 634cdf0e10cSrcweir { 635cdf0e10cSrcweir SvLBoxEntry* pReturn = NULL; 636cdf0e10cSrcweir if (_pEntry) 637cdf0e10cSrcweir { 638cdf0e10cSrcweir pReturn = m_aTablesList.NextSibling(_pEntry); 639cdf0e10cSrcweir if (!pReturn) 640cdf0e10cSrcweir pReturn = implNextSibling(m_aTablesList.GetParent(_pEntry)); 641cdf0e10cSrcweir } 642cdf0e10cSrcweir return pReturn; 643cdf0e10cSrcweir } 644cdf0e10cSrcweir 645cdf0e10cSrcweir //------------------------------------------------------------------------ 646cdf0e10cSrcweir sal_Bool OTableSubscriptionPage::FillItemSet( SfxItemSet& _rCoreAttrs ) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir sal_Bool bValid, bReadonly; 649cdf0e10cSrcweir getFlags(_rCoreAttrs, bValid, bReadonly); 650cdf0e10cSrcweir 651cdf0e10cSrcweir if (!bValid || bReadonly) 652cdf0e10cSrcweir // don't store anything if the data we're working with is invalid or readonly 653cdf0e10cSrcweir return sal_True; 654cdf0e10cSrcweir 655cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 656cdf0e10cSrcweir // create the output string which contains all the table names 657cdf0e10cSrcweir if ( m_xCurrentConnection.is() ) 658cdf0e10cSrcweir { // collect the table filter data only if we have a connection - else no tables are displayed at all 659cdf0e10cSrcweir Sequence< ::rtl::OUString > aTableFilter; 660cdf0e10cSrcweir if (m_aTablesList.isWildcardChecked(m_aTablesList.getAllObjectsEntry())) 661cdf0e10cSrcweir { 662cdf0e10cSrcweir aTableFilter.realloc(1); 663cdf0e10cSrcweir aTableFilter[0] = ::rtl::OUString("%", 1, RTL_TEXTENCODING_ASCII_US); 664cdf0e10cSrcweir } 665cdf0e10cSrcweir else 666cdf0e10cSrcweir { 667cdf0e10cSrcweir aTableFilter = collectDetailedSelection(); 668cdf0e10cSrcweir } 669cdf0e10cSrcweir _rCoreAttrs.Put( OStringListItem(DSID_TABLEFILTER, aTableFilter) ); 670cdf0e10cSrcweir } 671cdf0e10cSrcweir 672cdf0e10cSrcweir return sal_True; 673cdf0e10cSrcweir } 674cdf0e10cSrcweir 675cdf0e10cSrcweir // ----------------------------------------------------------------------- 676cdf0e10cSrcweir void OTableSubscriptionPage::fillControls(::std::vector< ISaveValueWrapper* >& /*_rControlList*/) 677cdf0e10cSrcweir { 678cdf0e10cSrcweir } 679cdf0e10cSrcweir // ----------------------------------------------------------------------- 680cdf0e10cSrcweir void OTableSubscriptionPage::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList) 681cdf0e10cSrcweir { 682cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<OTableTreeListBox>(&m_aTablesList)); 683cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aTables)); 684cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aExplanation)); 685cdf0e10cSrcweir } 686cdf0e10cSrcweir // ----------------------------------------------------------------------- 687cdf0e10cSrcweir //......................................................................... 688cdf0e10cSrcweir } // namespace dbaui 689cdf0e10cSrcweir //......................................................................... 690cdf0e10cSrcweir 691