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