1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "adtabdlg.hxx" 32*cdf0e10cSrcweir #include "adtabdlg.hrc" 33*cdf0e10cSrcweir #include "sqlmessage.hxx" 34*cdf0e10cSrcweir #include <tools/debug.hxx> 35*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 36*cdf0e10cSrcweir #include <svtools/localresaccess.hxx> 37*cdf0e10cSrcweir #include "dbaccess_helpid.hrc" 38*cdf0e10cSrcweir #include "dbu_resource.hrc" 39*cdf0e10cSrcweir #include "dbu_dlg.hrc" 40*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc> 41*cdf0e10cSrcweir #include "QueryTableView.hxx" 42*cdf0e10cSrcweir #include "QueryDesignView.hxx" 43*cdf0e10cSrcweir #include "querycontroller.hxx" 44*cdf0e10cSrcweir #include <connectivity/dbtools.hxx> 45*cdf0e10cSrcweir #include "browserids.hxx" 46*cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XViewsSupplier.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 50*cdf0e10cSrcweir #include "UITools.hxx" 51*cdf0e10cSrcweir #include "imageprovider.hxx" 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #include <comphelper/containermultiplexer.hxx> 54*cdf0e10cSrcweir #include "cppuhelper/basemutex.hxx" 55*cdf0e10cSrcweir #include <algorithm> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir // slot ids 58*cdf0e10cSrcweir using namespace dbaui; 59*cdf0e10cSrcweir using namespace ::com::sun::star; 60*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 61*cdf0e10cSrcweir using namespace ::com::sun::star::container; 62*cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 63*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 64*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 65*cdf0e10cSrcweir using namespace dbtools; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir //============================================================================== 68*cdf0e10cSrcweir //= TableObjectListFacade 69*cdf0e10cSrcweir //============================================================================== 70*cdf0e10cSrcweir TableObjectListFacade::~TableObjectListFacade() 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir //============================================================================== 75*cdf0e10cSrcweir //= TableListFacade 76*cdf0e10cSrcweir //============================================================================== 77*cdf0e10cSrcweir class TableListFacade : public ::cppu::BaseMutex 78*cdf0e10cSrcweir , public TableObjectListFacade 79*cdf0e10cSrcweir , public ::comphelper::OContainerListener 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir OTableTreeListBox& m_rTableList; 82*cdf0e10cSrcweir Reference< XConnection > m_xConnection; 83*cdf0e10cSrcweir ::rtl::Reference< comphelper::OContainerListenerAdapter> 84*cdf0e10cSrcweir m_pContainerListener; 85*cdf0e10cSrcweir bool m_bAllowViews; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir public: 88*cdf0e10cSrcweir TableListFacade( OTableTreeListBox& _rTableList, const Reference< XConnection >& _rxConnection ) 89*cdf0e10cSrcweir : ::comphelper::OContainerListener(m_aMutex) 90*cdf0e10cSrcweir ,m_rTableList( _rTableList ) 91*cdf0e10cSrcweir ,m_xConnection( _rxConnection ) 92*cdf0e10cSrcweir ,m_bAllowViews(true) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir virtual ~TableListFacade(); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir private: 99*cdf0e10cSrcweir virtual void updateTableObjectList( bool _bAllowViews ); 100*cdf0e10cSrcweir virtual String getSelectedName( String& _out_rAliasName ) const; 101*cdf0e10cSrcweir virtual bool isLeafSelected() const; 102*cdf0e10cSrcweir // OContainerListener 103*cdf0e10cSrcweir virtual void _elementInserted( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException); 104*cdf0e10cSrcweir virtual void _elementRemoved( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException); 105*cdf0e10cSrcweir virtual void _elementReplaced( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException); 106*cdf0e10cSrcweir }; 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir TableListFacade::~TableListFacade() 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir if ( m_pContainerListener.is() ) 111*cdf0e10cSrcweir m_pContainerListener->dispose(); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir //------------------------------------------------------------------------------ 114*cdf0e10cSrcweir String TableListFacade::getSelectedName( String& _out_rAliasName ) const 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir SvLBoxEntry* pEntry = m_rTableList.FirstSelected(); 117*cdf0e10cSrcweir if ( !pEntry ) 118*cdf0e10cSrcweir return String(); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir ::rtl::OUString aCatalog, aSchema, aTableName; 121*cdf0e10cSrcweir SvLBoxEntry* pSchema = m_rTableList.GetParent(pEntry); 122*cdf0e10cSrcweir if(pSchema && pSchema != m_rTableList.getAllObjectsEntry()) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir SvLBoxEntry* pCatalog = m_rTableList.GetParent(pSchema); 125*cdf0e10cSrcweir if(pCatalog && pCatalog != m_rTableList.getAllObjectsEntry()) 126*cdf0e10cSrcweir aCatalog = m_rTableList.GetEntryText(pCatalog); 127*cdf0e10cSrcweir aSchema = m_rTableList.GetEntryText(pSchema); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir aTableName = m_rTableList.GetEntryText(pEntry); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir ::rtl::OUString aComposedName; 132*cdf0e10cSrcweir try 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir Reference< XDatabaseMetaData > xMeta( m_xConnection->getMetaData(), UNO_QUERY_THROW ); 135*cdf0e10cSrcweir if ( !aCatalog.getLength() 136*cdf0e10cSrcweir && aSchema.getLength() 137*cdf0e10cSrcweir && xMeta->supportsCatalogsInDataManipulation() 138*cdf0e10cSrcweir && !xMeta->supportsSchemasInDataManipulation() ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir aCatalog = aSchema; 141*cdf0e10cSrcweir aSchema = ::rtl::OUString(); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir aComposedName = ::dbtools::composeTableName( 145*cdf0e10cSrcweir xMeta, aCatalog, aSchema, aTableName, sal_False, ::dbtools::eInDataManipulation ); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir catch ( const Exception& ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir _out_rAliasName = aTableName; 153*cdf0e10cSrcweir return aComposedName; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 156*cdf0e10cSrcweir void TableListFacade::_elementInserted( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir updateTableObjectList(m_bAllowViews); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 161*cdf0e10cSrcweir void TableListFacade::_elementRemoved( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir updateTableObjectList(m_bAllowViews); 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 166*cdf0e10cSrcweir void TableListFacade::_elementReplaced( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir //------------------------------------------------------------------------------ 170*cdf0e10cSrcweir void TableListFacade::updateTableObjectList( bool _bAllowViews ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir m_bAllowViews = _bAllowViews; 173*cdf0e10cSrcweir m_rTableList.Clear(); 174*cdf0e10cSrcweir try 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir Reference< XTablesSupplier > xTableSupp( m_xConnection, UNO_QUERY_THROW ); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir Reference< XViewsSupplier > xViewSupp; 179*cdf0e10cSrcweir Reference< XNameAccess > xTables, xViews; 180*cdf0e10cSrcweir Sequence< ::rtl::OUString > sTables, sViews; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir xTables = xTableSupp->getTables(); 183*cdf0e10cSrcweir if ( xTables.is() ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir if ( !m_pContainerListener.is() ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir Reference< XContainer> xContainer(xTables,uno::UNO_QUERY); 188*cdf0e10cSrcweir if ( xContainer.is() ) 189*cdf0e10cSrcweir m_pContainerListener = new ::comphelper::OContainerListenerAdapter(this,xContainer); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir sTables = xTables->getElementNames(); 192*cdf0e10cSrcweir } // if ( xTables.is() ) 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir xViewSupp.set( xTableSupp, UNO_QUERY ); 195*cdf0e10cSrcweir if ( xViewSupp.is() ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir xViews = xViewSupp->getViews(); 198*cdf0e10cSrcweir if ( xViews.is() ) 199*cdf0e10cSrcweir sViews = xViews->getElementNames(); 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir // if no views are allowed remove the views also out the table name filter 203*cdf0e10cSrcweir if ( !_bAllowViews ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir const ::rtl::OUString* pTableBegin = sTables.getConstArray(); 206*cdf0e10cSrcweir const ::rtl::OUString* pTableEnd = pTableBegin + sTables.getLength(); 207*cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aTables(pTableBegin,pTableEnd); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir const ::rtl::OUString* pViewBegin = sViews.getConstArray(); 210*cdf0e10cSrcweir const ::rtl::OUString* pViewEnd = pViewBegin + sViews.getLength(); 211*cdf0e10cSrcweir ::comphelper::TStringMixEqualFunctor aEqualFunctor; 212*cdf0e10cSrcweir for(;pViewBegin != pViewEnd;++pViewBegin) 213*cdf0e10cSrcweir aTables.erase(::std::remove_if(aTables.begin(),aTables.end(),::std::bind2nd(aEqualFunctor,*pViewBegin)),aTables.end()); 214*cdf0e10cSrcweir ::rtl::OUString* pTables = aTables.empty() ? 0 : &aTables[0]; 215*cdf0e10cSrcweir sTables = Sequence< ::rtl::OUString>(pTables, aTables.size()); 216*cdf0e10cSrcweir sViews = Sequence< ::rtl::OUString>(); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir m_rTableList.UpdateTableList( m_xConnection, sTables, sViews ); 220*cdf0e10cSrcweir SvLBoxEntry* pEntry = m_rTableList.First(); 221*cdf0e10cSrcweir while( pEntry && m_rTableList.GetModel()->HasChilds( pEntry ) ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir m_rTableList.Expand( pEntry ); 224*cdf0e10cSrcweir pEntry = m_rTableList.Next( pEntry ); 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir if ( pEntry ) 227*cdf0e10cSrcweir m_rTableList.Select(pEntry); 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir catch( const Exception& ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir //------------------------------------------------------------------------------ 236*cdf0e10cSrcweir bool TableListFacade::isLeafSelected() const 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir SvLBoxEntry* pEntry = m_rTableList.FirstSelected(); 239*cdf0e10cSrcweir return pEntry && !m_rTableList.GetModel()->HasChilds( pEntry ); 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir //============================================================================== 243*cdf0e10cSrcweir //= QueryListFacade 244*cdf0e10cSrcweir //============================================================================== 245*cdf0e10cSrcweir class QueryListFacade : public ::cppu::BaseMutex 246*cdf0e10cSrcweir , public TableObjectListFacade 247*cdf0e10cSrcweir , public ::comphelper::OContainerListener 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir SvTreeListBox& m_rQueryList; 250*cdf0e10cSrcweir Reference< XConnection > m_xConnection; 251*cdf0e10cSrcweir ::rtl::Reference< comphelper::OContainerListenerAdapter> 252*cdf0e10cSrcweir m_pContainerListener; 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir public: 255*cdf0e10cSrcweir QueryListFacade( SvTreeListBox& _rQueryList, const Reference< XConnection >& _rxConnection ) 256*cdf0e10cSrcweir : ::comphelper::OContainerListener(m_aMutex) 257*cdf0e10cSrcweir ,m_rQueryList( _rQueryList ) 258*cdf0e10cSrcweir ,m_xConnection( _rxConnection ) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir virtual ~QueryListFacade(); 262*cdf0e10cSrcweir private: 263*cdf0e10cSrcweir virtual void updateTableObjectList( bool _bAllowViews ); 264*cdf0e10cSrcweir virtual String getSelectedName( String& _out_rAliasName ) const; 265*cdf0e10cSrcweir virtual bool isLeafSelected() const; 266*cdf0e10cSrcweir // OContainerListener 267*cdf0e10cSrcweir virtual void _elementInserted( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException); 268*cdf0e10cSrcweir virtual void _elementRemoved( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException); 269*cdf0e10cSrcweir virtual void _elementReplaced( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException); 270*cdf0e10cSrcweir }; 271*cdf0e10cSrcweir QueryListFacade::~QueryListFacade() 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir if ( m_pContainerListener.is() ) 274*cdf0e10cSrcweir m_pContainerListener->dispose(); 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 277*cdf0e10cSrcweir void QueryListFacade::_elementInserted( const container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir ::rtl::OUString sName; 280*cdf0e10cSrcweir if ( _rEvent.Accessor >>= sName ) 281*cdf0e10cSrcweir m_rQueryList.InsertEntry( sName ); 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 284*cdf0e10cSrcweir void QueryListFacade::_elementRemoved( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir updateTableObjectList(true); 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 289*cdf0e10cSrcweir void QueryListFacade::_elementReplaced( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException) 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir //------------------------------------------------------------------------------ 294*cdf0e10cSrcweir void QueryListFacade::updateTableObjectList( bool /*_bAllowViews*/ ) 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir m_rQueryList.Clear(); 297*cdf0e10cSrcweir try 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir ImageProvider aImageProvider( m_xConnection ); 300*cdf0e10cSrcweir Image aQueryImage( aImageProvider.getDefaultImage( DatabaseObject::QUERY, false ) ); 301*cdf0e10cSrcweir Image aQueryImageHC( aImageProvider.getDefaultImage( DatabaseObject::QUERY, true ) ); 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir m_rQueryList.SetDefaultExpandedEntryBmp( aQueryImage, BMP_COLOR_NORMAL ); 304*cdf0e10cSrcweir m_rQueryList.SetDefaultCollapsedEntryBmp( aQueryImage, BMP_COLOR_NORMAL ); 305*cdf0e10cSrcweir m_rQueryList.SetDefaultExpandedEntryBmp( aQueryImageHC, BMP_COLOR_HIGHCONTRAST ); 306*cdf0e10cSrcweir m_rQueryList.SetDefaultCollapsedEntryBmp( aQueryImageHC, BMP_COLOR_HIGHCONTRAST ); 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir Reference< XQueriesSupplier > xSuppQueries( m_xConnection, UNO_QUERY_THROW ); 309*cdf0e10cSrcweir Reference< XNameAccess > xQueries( xSuppQueries->getQueries(), UNO_QUERY_THROW ); 310*cdf0e10cSrcweir if ( !m_pContainerListener.is() ) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir Reference< XContainer> xContainer(xQueries,UNO_QUERY_THROW); 313*cdf0e10cSrcweir m_pContainerListener = new ::comphelper::OContainerListenerAdapter(this,xContainer); 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir Sequence< ::rtl::OUString > aQueryNames = xQueries->getElementNames(); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir const ::rtl::OUString* pQuery = aQueryNames.getConstArray(); 318*cdf0e10cSrcweir const ::rtl::OUString* pQueryEnd = aQueryNames.getConstArray() + aQueryNames.getLength(); 319*cdf0e10cSrcweir while ( pQuery != pQueryEnd ) 320*cdf0e10cSrcweir m_rQueryList.InsertEntry( *pQuery++ ); 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir catch( const Exception& ) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir //------------------------------------------------------------------------------ 329*cdf0e10cSrcweir String QueryListFacade::getSelectedName( String& _out_rAliasName ) const 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir String sSelected; 332*cdf0e10cSrcweir SvLBoxEntry* pEntry = m_rQueryList.FirstSelected(); 333*cdf0e10cSrcweir if ( pEntry ) 334*cdf0e10cSrcweir sSelected = _out_rAliasName = m_rQueryList.GetEntryText( pEntry ); 335*cdf0e10cSrcweir return sSelected; 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir //------------------------------------------------------------------------------ 339*cdf0e10cSrcweir bool QueryListFacade::isLeafSelected() const 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir SvLBoxEntry* pEntry = m_rQueryList.FirstSelected(); 342*cdf0e10cSrcweir return pEntry && !m_rQueryList.GetModel()->HasChilds( pEntry ); 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir //============================================================================== 346*cdf0e10cSrcweir //= OAddTableDlg 347*cdf0e10cSrcweir //============================================================================== 348*cdf0e10cSrcweir //------------------------------------------------------------------------------ 349*cdf0e10cSrcweir OAddTableDlg::OAddTableDlg( Window* pParent, IAddTableDialogContext& _rContext ) 350*cdf0e10cSrcweir :ModelessDialog( pParent, ModuleRes(DLG_JOIN_TABADD) ) 351*cdf0e10cSrcweir ,m_aCaseTables( this, ModuleRes( RB_CASE_TABLES ) ) 352*cdf0e10cSrcweir ,m_aCaseQueries( this, ModuleRes( RB_CASE_QUERIES ) ) 353*cdf0e10cSrcweir ,m_aTableList( this, NULL, ModuleRes( LB_TABLE_OR_QUERY ), sal_False ) 354*cdf0e10cSrcweir ,m_aQueryList( this, ModuleRes( LB_TABLE_OR_QUERY ) ) 355*cdf0e10cSrcweir ,aAddButton( this, ModuleRes( PB_ADDTABLE ) ) 356*cdf0e10cSrcweir ,aCloseButton( this, ModuleRes( PB_CLOSE ) ) 357*cdf0e10cSrcweir ,aHelpButton( this, ModuleRes( PB_HELP ) ) 358*cdf0e10cSrcweir ,m_rContext( _rContext ) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir // der Close-Button hat schon einen Standard-Help-Text, den ich aber hier nicht haben moechte, also den Text ruecksetzen 361*cdf0e10cSrcweir // und eine neue ID verteilen 362*cdf0e10cSrcweir aCloseButton.SetHelpText(String()); 363*cdf0e10cSrcweir aCloseButton.SetHelpId(HID_JOINSH_ADDTAB_CLOSE); 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir m_aTableList.SetHelpId( HID_JOINSH_ADDTAB_TABLELIST ); 366*cdf0e10cSrcweir m_aQueryList.SetHelpId( HID_JOINSH_ADDTAB_QUERYLIST ); 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 369*cdf0e10cSrcweir m_aCaseTables.SetClickHdl( LINK( this, OAddTableDlg, OnTypeSelected ) ); 370*cdf0e10cSrcweir m_aCaseQueries.SetClickHdl( LINK( this, OAddTableDlg, OnTypeSelected ) ); 371*cdf0e10cSrcweir aAddButton.SetClickHdl( LINK( this, OAddTableDlg, AddClickHdl ) ); 372*cdf0e10cSrcweir aCloseButton.SetClickHdl( LINK( this, OAddTableDlg, CloseClickHdl ) ); 373*cdf0e10cSrcweir m_aTableList.SetDoubleClickHdl( LINK( this, OAddTableDlg, TableListDoubleClickHdl ) ); 374*cdf0e10cSrcweir m_aTableList.SetSelectHdl( LINK( this, OAddTableDlg, TableListSelectHdl ) ); 375*cdf0e10cSrcweir m_aQueryList.SetDoubleClickHdl( LINK( this, OAddTableDlg, TableListDoubleClickHdl ) ); 376*cdf0e10cSrcweir m_aQueryList.SetSelectHdl( LINK( this, OAddTableDlg, TableListSelectHdl ) ); 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 379*cdf0e10cSrcweir m_aTableList.EnableInplaceEditing( sal_False ); 380*cdf0e10cSrcweir m_aTableList.SetStyle(m_aTableList.GetStyle() | WB_BORDER | WB_HASLINES |WB_HASBUTTONS | WB_HASBUTTONSATROOT | WB_HASLINESATROOT | WB_SORT | WB_HSCROLL ); 381*cdf0e10cSrcweir m_aTableList.EnableCheckButton( NULL ); // do not show any buttons 382*cdf0e10cSrcweir m_aTableList.SetSelectionMode( SINGLE_SELECTION ); 383*cdf0e10cSrcweir m_aTableList.notifyHiContrastChanged(); 384*cdf0e10cSrcweir m_aTableList.suppressEmptyFolders(); 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 387*cdf0e10cSrcweir m_aQueryList.EnableInplaceEditing( sal_False ); 388*cdf0e10cSrcweir m_aQueryList.SetSelectionMode( SINGLE_SELECTION ); 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 391*cdf0e10cSrcweir if ( !m_rContext.allowQueries() ) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir m_aCaseTables.Hide(); 394*cdf0e10cSrcweir m_aCaseQueries.Hide(); 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir long nPixelDiff = m_aTableList.GetPosPixel().Y() - m_aCaseTables.GetPosPixel().Y(); 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir Point aListPos( m_aTableList.GetPosPixel() ); 399*cdf0e10cSrcweir aListPos.Y() -= nPixelDiff; 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir Size aListSize( m_aTableList.GetSizePixel() ); 402*cdf0e10cSrcweir aListSize.Height() += nPixelDiff; 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir m_aTableList.SetPosSizePixel( aListPos, aListSize ); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir FreeResource(); 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir SetText( getDialogTitleForContext( m_rContext ) ); 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir //------------------------------------------------------------------------------ 413*cdf0e10cSrcweir OAddTableDlg::~OAddTableDlg() 414*cdf0e10cSrcweir { 415*cdf0e10cSrcweir m_rContext.onWindowClosing( this ); 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir //------------------------------------------------------------------------------ 419*cdf0e10cSrcweir void OAddTableDlg::impl_switchTo( ObjectList _eList ) 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir switch ( _eList ) 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir case Tables: 424*cdf0e10cSrcweir m_aTableList.Show( sal_True ); m_aCaseTables.Check( sal_True ); 425*cdf0e10cSrcweir m_aQueryList.Show( sal_False ); m_aCaseQueries.Check( sal_False ); 426*cdf0e10cSrcweir m_pCurrentList.reset( new TableListFacade( m_aTableList, m_rContext.getConnection() ) ); 427*cdf0e10cSrcweir m_aTableList.GrabFocus(); 428*cdf0e10cSrcweir break; 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir case Queries: 431*cdf0e10cSrcweir m_aTableList.Show( sal_False ); m_aCaseTables.Check( sal_False ); 432*cdf0e10cSrcweir m_aQueryList.Show( sal_True ); m_aCaseQueries.Check( sal_True ); 433*cdf0e10cSrcweir m_pCurrentList.reset( new QueryListFacade( m_aQueryList, m_rContext.getConnection() ) ); 434*cdf0e10cSrcweir m_aQueryList.GrabFocus(); 435*cdf0e10cSrcweir break; 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir m_pCurrentList->updateTableObjectList( m_rContext.allowViews() ); 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir //------------------------------------------------------------------------------ 441*cdf0e10cSrcweir void OAddTableDlg::Update() 442*cdf0e10cSrcweir { 443*cdf0e10cSrcweir if ( !m_pCurrentList.get() ) 444*cdf0e10cSrcweir impl_switchTo( Tables ); 445*cdf0e10cSrcweir else 446*cdf0e10cSrcweir m_pCurrentList->updateTableObjectList( m_rContext.allowViews() ); 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir //------------------------------------------------------------------------------ 450*cdf0e10cSrcweir void OAddTableDlg::impl_addTable() 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir if ( m_pCurrentList->isLeafSelected() ) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir String sSelectedName, sAliasName; 455*cdf0e10cSrcweir sSelectedName = m_pCurrentList->getSelectedName( sAliasName ); 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir m_rContext.addTableWindow( sSelectedName, sAliasName ); 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir //------------------------------------------------------------------------------ 462*cdf0e10cSrcweir IMPL_LINK( OAddTableDlg, AddClickHdl, Button*, /*pButton*/ ) 463*cdf0e10cSrcweir { 464*cdf0e10cSrcweir TableListDoubleClickHdl(NULL); 465*cdf0e10cSrcweir return 0; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir //------------------------------------------------------------------------------ 469*cdf0e10cSrcweir IMPL_LINK( OAddTableDlg, TableListDoubleClickHdl, void*, /*EMPTY_ARG*/ ) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir if ( impl_isAddAllowed() ) 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir impl_addTable(); 474*cdf0e10cSrcweir if ( !impl_isAddAllowed() ) 475*cdf0e10cSrcweir Close(); 476*cdf0e10cSrcweir return 1L; // handled 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir return 0L; // not handled 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir //------------------------------------------------------------------------------ 483*cdf0e10cSrcweir IMPL_LINK( OAddTableDlg, TableListSelectHdl, void*, /*EMPTY_ARG*/ ) 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir aAddButton.Enable( m_pCurrentList->isLeafSelected() ); 486*cdf0e10cSrcweir return 0; 487*cdf0e10cSrcweir } 488*cdf0e10cSrcweir 489*cdf0e10cSrcweir //------------------------------------------------------------------------------ 490*cdf0e10cSrcweir IMPL_LINK( OAddTableDlg, CloseClickHdl, Button*, /*pButton*/ ) 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir return Close(); 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir //------------------------------------------------------------------------------ 496*cdf0e10cSrcweir IMPL_LINK( OAddTableDlg, OnTypeSelected, void*, /*EMPTY_ARG*/ ) 497*cdf0e10cSrcweir { 498*cdf0e10cSrcweir if ( m_aCaseTables.IsChecked() ) 499*cdf0e10cSrcweir impl_switchTo( Tables ); 500*cdf0e10cSrcweir else 501*cdf0e10cSrcweir impl_switchTo( Queries ); 502*cdf0e10cSrcweir return 0; 503*cdf0e10cSrcweir } 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir //------------------------------------------------------------------------------ 506*cdf0e10cSrcweir sal_Bool OAddTableDlg::Close() 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir m_rContext.onWindowClosing( this ); 509*cdf0e10cSrcweir return ModelessDialog::Close(); 510*cdf0e10cSrcweir } 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir //------------------------------------------------------------------------------ 513*cdf0e10cSrcweir bool OAddTableDlg::impl_isAddAllowed() 514*cdf0e10cSrcweir { 515*cdf0e10cSrcweir return m_rContext.allowAddition(); 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir //------------------------------------------------------------------------------ 519*cdf0e10cSrcweir String OAddTableDlg::getDialogTitleForContext( IAddTableDialogContext& _rContext ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir String sTitle; 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir ::svt::OLocalResourceAccess aLocalRes( ModuleRes( DLG_JOIN_TABADD ), RSC_MODELESSDIALOG ); 524*cdf0e10cSrcweir if ( _rContext.allowQueries() ) 525*cdf0e10cSrcweir sTitle = String( ModuleRes( STR_ADD_TABLE_OR_QUERY ) ); 526*cdf0e10cSrcweir else 527*cdf0e10cSrcweir sTitle = String( ModuleRes( STR_ADD_TABLES ) ); 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir return sTitle; 530*cdf0e10cSrcweir } 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 533*cdf0e10cSrcweir 534