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
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
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.
19*96de5490SAndrew Rist  *
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 #include "browserids.hxx"
28cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
29cdf0e10cSrcweir #include "dbexchange.hxx"
30cdf0e10cSrcweir #include "dbtreelistbox.hxx"
31cdf0e10cSrcweir #include "dbtreemodel.hxx"
32cdf0e10cSrcweir #include "dbtreeview.hxx"
33cdf0e10cSrcweir #include "dbu_brw.hrc"
34cdf0e10cSrcweir #include "dbu_reghelper.hxx"
35cdf0e10cSrcweir #include "dbustrings.hrc"
36cdf0e10cSrcweir #include "dlgsave.hxx"
37cdf0e10cSrcweir #include "HtmlReader.hxx"
38cdf0e10cSrcweir #include "imageprovider.hxx"
39cdf0e10cSrcweir #include "listviewitems.hxx"
40cdf0e10cSrcweir #include "QEnumTypes.hxx"
41cdf0e10cSrcweir #include "RtfReader.hxx"
42cdf0e10cSrcweir #include "sbagrid.hrc"
43cdf0e10cSrcweir #include "sbagrid.hxx"
44cdf0e10cSrcweir #include "sqlmessage.hxx"
45cdf0e10cSrcweir #include "TokenWriter.hxx"
46cdf0e10cSrcweir #include "UITools.hxx"
47cdf0e10cSrcweir #include "unodatbr.hxx"
48cdf0e10cSrcweir #include "WColumnSelect.hxx"
49cdf0e10cSrcweir #include "WCopyTable.hxx"
50cdf0e10cSrcweir #include "WCPage.hxx"
51cdf0e10cSrcweir #include "WExtendPages.hxx"
52cdf0e10cSrcweir #include "WNameMatch.hxx"
53cdf0e10cSrcweir 
54cdf0e10cSrcweir /** === begin UNO includes === **/
55cdf0e10cSrcweir #include <com/sun/star/awt/LineEndFormat.hpp>
56cdf0e10cSrcweir #include <com/sun/star/awt/LineEndFormat.hpp>
57cdf0e10cSrcweir #include <com/sun/star/awt/MouseWheelBehavior.hpp>
58cdf0e10cSrcweir #include <com/sun/star/awt/TextAlign.hpp>
59cdf0e10cSrcweir #include <com/sun/star/awt/VisualEffect.hpp>
60cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
61cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
62cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
63cdf0e10cSrcweir #include <com/sun/star/form/XForm.hpp>
64cdf0e10cSrcweir #include <com/sun/star/form/XGridColumnFactory.hpp>
65cdf0e10cSrcweir #include <com/sun/star/form/XLoadable.hpp>
66cdf0e10cSrcweir #include <com/sun/star/form/XReset.hpp>
67cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
68cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp>
69cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
70cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
71cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
72cdf0e10cSrcweir #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
73cdf0e10cSrcweir #include <com/sun/star/sdb/XCompletedConnection.hpp>
74cdf0e10cSrcweir #include <com/sun/star/sdb/XDatabaseRegistrations.hpp>
75cdf0e10cSrcweir #include <com/sun/star/sdb/XDocumentDataSource.hpp>
76cdf0e10cSrcweir #include <com/sun/star/sdb/XParametersSupplier.hpp>
77cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
78cdf0e10cSrcweir #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
79cdf0e10cSrcweir #include <com/sun/star/sdb/XResultSetAccess.hpp>
80cdf0e10cSrcweir #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
81cdf0e10cSrcweir #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp>
82cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
83cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
84cdf0e10cSrcweir #include <com/sun/star/sdbc/FetchDirection.hpp>
85cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
86cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp>
87cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
88cdf0e10cSrcweir #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
89cdf0e10cSrcweir #include <com/sun/star/sdbcx/Privilege.hpp>
90cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
91cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
92cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDrop.hpp>
93cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
94cdf0e10cSrcweir #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
95cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
96cdf0e10cSrcweir #include <com/sun/star/util/XFlushable.hpp>
97cdf0e10cSrcweir #include <com/sun/star/sdb/XDocumentDataSource.hpp>
98cdf0e10cSrcweir #include <com/sun/star/document/MacroExecMode.hpp>
99cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
100cdf0e10cSrcweir #include <com/sun/star/ui/XContextMenuInterceptor.hpp>
101cdf0e10cSrcweir /** === end UNO includes === **/
102cdf0e10cSrcweir 
103cdf0e10cSrcweir #include <comphelper/extract.hxx>
104cdf0e10cSrcweir #include <comphelper/sequence.hxx>
105cdf0e10cSrcweir #include <comphelper/types.hxx>
106cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
107cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
108cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
109cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
110cdf0e10cSrcweir #include <sfx2/app.hxx>
111cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
112cdf0e10cSrcweir #include <sot/storage.hxx>
113cdf0e10cSrcweir #include <svl/filenotation.hxx>
114cdf0e10cSrcweir #include <svl/intitem.hxx>
115cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
116cdf0e10cSrcweir #include <svtools/svlbitm.hxx>
117cdf0e10cSrcweir #include <svtools/svtreebx.hxx>
118cdf0e10cSrcweir #include <svx/algitem.hxx>
119cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
120cdf0e10cSrcweir #include <svx/databaseregistrationui.hxx>
121cdf0e10cSrcweir #include <svx/gridctrl.hxx>
122cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
123cdf0e10cSrcweir #include <tools/diagnose_ex.h>
124cdf0e10cSrcweir #include <tools/multisel.hxx>
125cdf0e10cSrcweir #include <tools/urlobj.hxx>
126cdf0e10cSrcweir #include <unotools/confignode.hxx>
127cdf0e10cSrcweir #include <vcl/msgbox.hxx>
128cdf0e10cSrcweir #include <vcl/split.hxx>
129cdf0e10cSrcweir #include <vcl/stdtext.hxx>
130cdf0e10cSrcweir #include <vcl/svapp.hxx>
131cdf0e10cSrcweir #include <vcl/toolbox.hxx>
132cdf0e10cSrcweir #include <vcl/waitobj.hxx>
133cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
134cdf0e10cSrcweir #include <rtl/logfile.hxx>
135cdf0e10cSrcweir 
136cdf0e10cSrcweir #include <memory>
137cdf0e10cSrcweir 
138cdf0e10cSrcweir using namespace ::com::sun::star::uno;
139cdf0e10cSrcweir using namespace ::com::sun::star::awt;
140cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
141cdf0e10cSrcweir using namespace ::com::sun::star::sdb::application;
142cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
143cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
144cdf0e10cSrcweir using namespace ::com::sun::star::beans;
145cdf0e10cSrcweir using namespace ::com::sun::star::util;
146cdf0e10cSrcweir using namespace ::com::sun::star::frame;
147cdf0e10cSrcweir using namespace ::com::sun::star::container;
148cdf0e10cSrcweir using namespace ::com::sun::star::lang;
149cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
150cdf0e10cSrcweir using namespace ::com::sun::star::task;
151cdf0e10cSrcweir using namespace ::com::sun::star::form;
152cdf0e10cSrcweir using namespace ::com::sun::star::io;
153cdf0e10cSrcweir using namespace ::com::sun::star::i18n;
154cdf0e10cSrcweir using namespace ::com::sun::star::view;
155cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer;
156cdf0e10cSrcweir using namespace ::com::sun::star::document;
157cdf0e10cSrcweir using namespace ::com::sun::star::ui;
158cdf0e10cSrcweir using namespace ::dbtools;
159cdf0e10cSrcweir using namespace ::comphelper;
160cdf0e10cSrcweir using namespace ::svx;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir // .........................................................................
163cdf0e10cSrcweir namespace dbaui
164cdf0e10cSrcweir {
165cdf0e10cSrcweir // .........................................................................
166cdf0e10cSrcweir 
167cdf0e10cSrcweir namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
168cdf0e10cSrcweir namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir //==================================================================
171cdf0e10cSrcweir //= SbaTableQueryBrowser
172cdf0e10cSrcweir //==================================================================
173cdf0e10cSrcweir // -------------------------------------------------------------------------
174cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_OBrowser()
175cdf0e10cSrcweir {
176cdf0e10cSrcweir 	static OMultiInstanceAutoRegistration< SbaTableQueryBrowser > aAutoRegistration;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir // -------------------------------------------------------------------------
179cdf0e10cSrcweir void SafeAddPropertyListener(const Reference< XPropertySet > & xSet, const ::rtl::OUString& rPropName, XPropertyChangeListener* pListener)
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	Reference< XPropertySetInfo >  xInfo = xSet->getPropertySetInfo();
182cdf0e10cSrcweir 	if (xInfo->hasPropertyByName(rPropName))
183cdf0e10cSrcweir 		xSet->addPropertyChangeListener(rPropName, pListener);
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir // -------------------------------------------------------------------------
187cdf0e10cSrcweir void SafeRemovePropertyListener(const Reference< XPropertySet > & xSet, const ::rtl::OUString& rPropName, XPropertyChangeListener* pListener)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	Reference< XPropertySetInfo >  xInfo = xSet->getPropertySetInfo();
190cdf0e10cSrcweir 	if (xInfo->hasPropertyByName(rPropName))
191cdf0e10cSrcweir 		xSet->removePropertyChangeListener(rPropName, pListener);
192cdf0e10cSrcweir }
193cdf0e10cSrcweir //-------------------------------------------------------------------------
194cdf0e10cSrcweir ::rtl::OUString SAL_CALL SbaTableQueryBrowser::getImplementationName() throw(RuntimeException)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir 	return getImplementationName_Static();
197cdf0e10cSrcweir }
198cdf0e10cSrcweir //-------------------------------------------------------------------------
199cdf0e10cSrcweir ::comphelper::StringSequence SAL_CALL SbaTableQueryBrowser::getSupportedServiceNames() throw(RuntimeException)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	return getSupportedServiceNames_Static();
202cdf0e10cSrcweir }
203cdf0e10cSrcweir // -------------------------------------------------------------------------
204cdf0e10cSrcweir ::rtl::OUString SbaTableQueryBrowser::getImplementationName_Static() throw(RuntimeException)
205cdf0e10cSrcweir {
206cdf0e10cSrcweir 	return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.ODatasourceBrowser");
207cdf0e10cSrcweir }
208cdf0e10cSrcweir //-------------------------------------------------------------------------
209cdf0e10cSrcweir ::comphelper::StringSequence SbaTableQueryBrowser::getSupportedServiceNames_Static() throw(RuntimeException)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir 	::comphelper::StringSequence aSupported(1);
212cdf0e10cSrcweir 	aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.DataSourceBrowser");
213cdf0e10cSrcweir 	return aSupported;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir //-------------------------------------------------------------------------
216cdf0e10cSrcweir Reference< XInterface > SAL_CALL SbaTableQueryBrowser::Create(const Reference<XMultiServiceFactory >& _rxFactory)
217cdf0e10cSrcweir {
218cdf0e10cSrcweir 	::vos::OGuard aGuard(Application::GetSolarMutex());
219cdf0e10cSrcweir 	return *(new SbaTableQueryBrowser(_rxFactory));
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir DBG_NAME(SbaTableQueryBrowser);
223cdf0e10cSrcweir //------------------------------------------------------------------------------
224cdf0e10cSrcweir SbaTableQueryBrowser::SbaTableQueryBrowser(const Reference< XMultiServiceFactory >& _rM)
225cdf0e10cSrcweir 	:SbaXDataBrowserController(_rM)
226cdf0e10cSrcweir 	,m_aSelectionListeners( getMutex() )
227cdf0e10cSrcweir     ,m_aContextMenuInterceptors( getMutex() )
228cdf0e10cSrcweir     ,m_aTableCopyHelper(this)
229cdf0e10cSrcweir     ,m_pTreeView(NULL)
230cdf0e10cSrcweir     ,m_pSplitter(NULL)
231cdf0e10cSrcweir 	,m_pTreeModel(NULL)
232cdf0e10cSrcweir 	,m_pCurrentlyDisplayed(NULL)
233cdf0e10cSrcweir     ,m_nAsyncDrop(0)
234cdf0e10cSrcweir 	,m_nBorder(1)
235cdf0e10cSrcweir 	,m_bQueryEscapeProcessing( sal_False )
236cdf0e10cSrcweir 	,m_bShowMenu(sal_False)
237cdf0e10cSrcweir 	,m_bInSuspend(sal_False)
238cdf0e10cSrcweir 	,m_bEnableBrowser(sal_True)
239cdf0e10cSrcweir {
240cdf0e10cSrcweir 	DBG_CTOR(SbaTableQueryBrowser,NULL);
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir //------------------------------------------------------------------------------
244cdf0e10cSrcweir SbaTableQueryBrowser::~SbaTableQueryBrowser()
245cdf0e10cSrcweir {
246cdf0e10cSrcweir 	DBG_DTOR(SbaTableQueryBrowser,NULL);
247cdf0e10cSrcweir 	if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
248cdf0e10cSrcweir 	{
249cdf0e10cSrcweir 		OSL_ENSURE(0,"Please check who doesn't dispose this component!");
250cdf0e10cSrcweir         // increment ref count to prevent double call of Dtor
251cdf0e10cSrcweir         osl_incrementInterlockedCount( &m_refCount );
252cdf0e10cSrcweir         dispose();
253cdf0e10cSrcweir 	}
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir //------------------------------------------------------------------------------
257cdf0e10cSrcweir Any SAL_CALL SbaTableQueryBrowser::queryInterface(const Type& _rType) throw (RuntimeException)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir     if ( _rType.equals( XScriptInvocationContext::static_type() ) )
260cdf0e10cSrcweir     {
261cdf0e10cSrcweir         OSL_PRECOND( !!m_aDocScriptSupport, "SbaTableQueryBrowser::queryInterface: did not initialize this, yet!" );
262cdf0e10cSrcweir         if ( !!m_aDocScriptSupport && *m_aDocScriptSupport )
263cdf0e10cSrcweir             return makeAny( Reference< XScriptInvocationContext >( this ) );
264cdf0e10cSrcweir         return Any();
265cdf0e10cSrcweir     }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 	Any aReturn = SbaXDataBrowserController::queryInterface(_rType);
268cdf0e10cSrcweir 	if (!aReturn.hasValue())
269cdf0e10cSrcweir 		aReturn = SbaTableQueryBrowser_Base::queryInterface(_rType);
270cdf0e10cSrcweir 	return aReturn;
271cdf0e10cSrcweir }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir //------------------------------------------------------------------------------
274cdf0e10cSrcweir Sequence< Type > SAL_CALL SbaTableQueryBrowser::getTypes(  ) throw (RuntimeException)
275cdf0e10cSrcweir {
276cdf0e10cSrcweir     Sequence< Type > aTypes( ::comphelper::concatSequences(
277cdf0e10cSrcweir 		SbaXDataBrowserController::getTypes(),
278cdf0e10cSrcweir 		SbaTableQueryBrowser_Base::getTypes()
279cdf0e10cSrcweir 	) );
280cdf0e10cSrcweir 
281cdf0e10cSrcweir     OSL_PRECOND( !!m_aDocScriptSupport, "SbaTableQueryBrowser::getTypes: did not initialize this, yet!" );
282cdf0e10cSrcweir     if ( !m_aDocScriptSupport || !*m_aDocScriptSupport )
283cdf0e10cSrcweir     {
284cdf0e10cSrcweir         Sequence< Type > aStrippedTypes( aTypes.getLength() - 1 );
285cdf0e10cSrcweir         ::std::remove_copy_if(
286cdf0e10cSrcweir             aTypes.getConstArray(),
287cdf0e10cSrcweir             aTypes.getConstArray() + aTypes.getLength(),
288cdf0e10cSrcweir             aStrippedTypes.getArray(),
289cdf0e10cSrcweir             ::std::bind2nd( ::std::equal_to< Type >(), XScriptInvocationContext::static_type() )
290cdf0e10cSrcweir         );
291cdf0e10cSrcweir         aTypes = aStrippedTypes;
292cdf0e10cSrcweir     }
293cdf0e10cSrcweir     return aTypes;
294cdf0e10cSrcweir }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir //------------------------------------------------------------------------------
297cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL SbaTableQueryBrowser::getImplementationId(  ) throw (RuntimeException)
298cdf0e10cSrcweir {
299cdf0e10cSrcweir 	static ::cppu::OImplementationId * pId = 0;
300cdf0e10cSrcweir 	if (! pId)
301cdf0e10cSrcweir 	{
302cdf0e10cSrcweir 		::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
303cdf0e10cSrcweir 		if (! pId)
304cdf0e10cSrcweir 		{
305cdf0e10cSrcweir 			static ::cppu::OImplementationId aId;
306cdf0e10cSrcweir 			pId = &aId;
307cdf0e10cSrcweir 		}
308cdf0e10cSrcweir 	}
309cdf0e10cSrcweir 	return pId->getImplementationId();
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir //------------------------------------------------------------------------------
313cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::disposing()
314cdf0e10cSrcweir {
315cdf0e10cSrcweir 	::vos::OGuard aGuard(Application::GetSolarMutex());
316cdf0e10cSrcweir 		// doin' a lot of VCL stuff here -> lock the SolarMutex
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 	// kiss our listeners goodbye
319cdf0e10cSrcweir 	EventObject aEvt(*this);
320cdf0e10cSrcweir 	m_aSelectionListeners.disposeAndClear(aEvt);
321cdf0e10cSrcweir     m_aContextMenuInterceptors.disposeAndClear(aEvt);
322cdf0e10cSrcweir 
323cdf0e10cSrcweir 	// reset the content's tree view: it holds a reference to our model which is to be deleted immediately,
324cdf0e10cSrcweir 	// and it will live longer than we do.
325cdf0e10cSrcweir 	if (getBrowserView())
326cdf0e10cSrcweir 		getBrowserView()->setTreeView(NULL);
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 	clearTreeModel();
329cdf0e10cSrcweir 	// clear the tree model
330cdf0e10cSrcweir 	{
331cdf0e10cSrcweir 		::std::auto_ptr<SvLBoxTreeList> aTemp(m_pTreeModel);
332cdf0e10cSrcweir 		m_pTreeModel = NULL;
333cdf0e10cSrcweir 	}
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 	// remove ourself as status listener
336cdf0e10cSrcweir 	implRemoveStatusListeners();
337cdf0e10cSrcweir 
338cdf0e10cSrcweir 	// remove the container listener from the database context
339cdf0e10cSrcweir     try
340cdf0e10cSrcweir     {
341cdf0e10cSrcweir 	    Reference< XDatabaseRegistrations > xDatabaseRegistrations( m_xDatabaseContext, UNO_QUERY_THROW );
342cdf0e10cSrcweir         xDatabaseRegistrations->removeDatabaseRegistrationsListener( this );
343cdf0e10cSrcweir     }
344cdf0e10cSrcweir     catch( const Exception& )
345cdf0e10cSrcweir     {
346cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
347cdf0e10cSrcweir     }
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 	// check out from all the objects we are listening
350cdf0e10cSrcweir 	// the frame
351cdf0e10cSrcweir 	if (m_xCurrentFrameParent.is())
352cdf0e10cSrcweir 		m_xCurrentFrameParent->removeFrameActionListener((::com::sun::star::frame::XFrameActionListener*)this);
353cdf0e10cSrcweir 	SbaXDataBrowserController::disposing();
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir //------------------------------------------------------------------------------
357cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::Construct(Window* pParent)
358cdf0e10cSrcweir {
359cdf0e10cSrcweir 	if ( !SbaXDataBrowserController::Construct( pParent ) )
360cdf0e10cSrcweir 		return sal_False;
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 	try
363cdf0e10cSrcweir 	{
364cdf0e10cSrcweir 		Reference< XDatabaseRegistrations > xDatabaseRegistrations( m_xDatabaseContext, UNO_QUERY_THROW );
365cdf0e10cSrcweir         xDatabaseRegistrations->addDatabaseRegistrationsListener( this );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 		// the collator for the string compares
368cdf0e10cSrcweir 		m_xCollator = Reference< XCollator >( getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.i18n.Collator" ) ), UNO_QUERY_THROW );
369cdf0e10cSrcweir 		m_xCollator->loadDefaultCollator( Application::GetSettings().GetLocale(), 0 );
370cdf0e10cSrcweir 	}
371cdf0e10cSrcweir 	catch(Exception&)
372cdf0e10cSrcweir 	{
373cdf0e10cSrcweir 		DBG_ERROR("SbaTableQueryBrowser::Construct: could not create (or start listening at) the database context!");
374cdf0e10cSrcweir 	}
375cdf0e10cSrcweir 	// some help ids
376cdf0e10cSrcweir 	if (getBrowserView() && getBrowserView()->getVclControl())
377cdf0e10cSrcweir 	{
378cdf0e10cSrcweir 
379cdf0e10cSrcweir 		// create controls and set sizes
380cdf0e10cSrcweir         const long	nFrameWidth = getBrowserView()->LogicToPixel( ::Size( 3, 0 ), MAP_APPFONT ).Width();
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 		m_pSplitter = new Splitter(getBrowserView(),WB_HSCROLL);
383cdf0e10cSrcweir         m_pSplitter->SetPosSizePixel( ::Point(0,0), ::Size(nFrameWidth,0) );
384cdf0e10cSrcweir 		m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) );
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 		m_pTreeView = new DBTreeView(getBrowserView(),getORB(), WB_TABSTOP | WB_BORDER);
387cdf0e10cSrcweir 		m_pTreeView->SetPreExpandHandler(LINK(this, SbaTableQueryBrowser, OnExpandEntry));
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 		m_pTreeView->setCopyHandler(LINK(this, SbaTableQueryBrowser, OnCopyEntry));
390cdf0e10cSrcweir 
391cdf0e10cSrcweir         m_pTreeView->getListBox().setContextMenuProvider( this );
392cdf0e10cSrcweir 		m_pTreeView->getListBox().setControlActionListener( this );
393cdf0e10cSrcweir 		m_pTreeView->SetHelpId(HID_CTL_TREEVIEW);
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 		// a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide
396cdf0e10cSrcweir         m_pSplitter->SetSplitPosPixel( getBrowserView()->LogicToPixel( ::Size( 80, 0 ), MAP_APPFONT ).Width() );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 		getBrowserView()->setSplitter(m_pSplitter);
399cdf0e10cSrcweir 		getBrowserView()->setTreeView(m_pTreeView);
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 		// fill view with data
402cdf0e10cSrcweir 		m_pTreeModel = new SvLBoxTreeList;
403cdf0e10cSrcweir 		m_pTreeModel->SetSortMode(SortAscending);
404cdf0e10cSrcweir 		m_pTreeModel->SetCompareHdl(LINK(this, SbaTableQueryBrowser, OnTreeEntryCompare));
405cdf0e10cSrcweir 		m_pTreeView->setModel(m_pTreeModel);
406cdf0e10cSrcweir 		m_pTreeView->setSelChangeHdl( LINK( this, SbaTableQueryBrowser, OnSelectionChange ) );
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 		// TODO
409cdf0e10cSrcweir 		getBrowserView()->getVclControl()->GetDataWindow().SetUniqueId(UID_DATABROWSE_DATAWINDOW);
410cdf0e10cSrcweir 		getBrowserView()->getVclControl()->SetHelpId(HID_CTL_TABBROWSER);
411cdf0e10cSrcweir 		getBrowserView()->SetUniqueId(UID_CTL_CONTENT);
412cdf0e10cSrcweir 		if (getBrowserView()->getVclControl()->GetHeaderBar())
413cdf0e10cSrcweir 			getBrowserView()->getVclControl()->GetHeaderBar()->SetHelpId(HID_DATABROWSE_HEADER);
414cdf0e10cSrcweir 		InvalidateFeature(ID_BROWSER_EXPLORER);
415cdf0e10cSrcweir 	}
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 	return sal_True;
418cdf0e10cSrcweir }
419cdf0e10cSrcweir // ---------------------------------------------------------------------------------------------------------------------
420cdf0e10cSrcweir namespace
421cdf0e10cSrcweir {
422cdf0e10cSrcweir     // -----------------------------------------------------------------------------------------------------------------
423cdf0e10cSrcweir     struct SelectValueByName : public ::std::unary_function< ::rtl::OUString, Any >
424cdf0e10cSrcweir     {
425cdf0e10cSrcweir         const Any& operator()( ::rtl::OUString const& i_name ) const
426cdf0e10cSrcweir         {
427cdf0e10cSrcweir             return m_rCollection.get( i_name );
428cdf0e10cSrcweir         }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir         SelectValueByName( ::comphelper::NamedValueCollection const& i_collection )
431cdf0e10cSrcweir             :m_rCollection( i_collection )
432cdf0e10cSrcweir         {
433cdf0e10cSrcweir         }
434cdf0e10cSrcweir 
435cdf0e10cSrcweir         ::comphelper::NamedValueCollection const&   m_rCollection;
436cdf0e10cSrcweir     };
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir // ---------------------------------------------------------------------------------------------------------------------
440cdf0e10cSrcweir void SbaTableQueryBrowser::impl_sanitizeRowSetClauses_nothrow()
441cdf0e10cSrcweir {
442cdf0e10cSrcweir     try
443cdf0e10cSrcweir     {
444cdf0e10cSrcweir         Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
445cdf0e10cSrcweir         sal_Bool bEscapeProcessing = sal_False;
446cdf0e10cSrcweir         OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
447cdf0e10cSrcweir         if ( !bEscapeProcessing )
448cdf0e10cSrcweir             // don't touch or interpret anything if escape processing is disabled
449cdf0e10cSrcweir             return;
450cdf0e10cSrcweir 
451cdf0e10cSrcweir         Reference< XSingleSelectQueryComposer > xComposer( createParser_nothrow() );
452cdf0e10cSrcweir         if ( !xComposer.is() )
453cdf0e10cSrcweir             // can't do anything. Already reported via assertion in createParser_nothrow.
454cdf0e10cSrcweir             return;
455cdf0e10cSrcweir 
456cdf0e10cSrcweir         // the tables participating in the statement
457cdf0e10cSrcweir         const Reference< XTablesSupplier > xSuppTables( xComposer, UNO_QUERY_THROW );
458cdf0e10cSrcweir         const Reference< XNameAccess > xTableNames( xSuppTables->getTables(), UNO_QUERY_THROW );
459cdf0e10cSrcweir 
460cdf0e10cSrcweir         // the columns participating in the statement
461cdf0e10cSrcweir         const Reference< XColumnsSupplier > xSuppColumns( xComposer, UNO_QUERY_THROW );
462cdf0e10cSrcweir         const Reference< XNameAccess > xColumnNames( xSuppColumns->getColumns(), UNO_QUERY_THROW );
463cdf0e10cSrcweir 
464cdf0e10cSrcweir         // .............................................................................................................
465cdf0e10cSrcweir         // check if the order columns apply to tables which really exist in the statement
466cdf0e10cSrcweir         const Reference< XIndexAccess > xOrderColumns( xComposer->getOrderColumns(), UNO_SET_THROW );
467cdf0e10cSrcweir         const sal_Int32 nOrderColumns( xOrderColumns->getCount() );
468cdf0e10cSrcweir         bool invalidColumn = nOrderColumns == 0;
469cdf0e10cSrcweir         for ( sal_Int32 c=0; ( c < nOrderColumns ) && !invalidColumn; ++c )
470cdf0e10cSrcweir         {
471cdf0e10cSrcweir             const Reference< XPropertySet > xOrderColumn( xOrderColumns->getByIndex(c), UNO_QUERY_THROW );
472cdf0e10cSrcweir             ::rtl::OUString sTableName;
473cdf0e10cSrcweir             OSL_VERIFY( xOrderColumn->getPropertyValue( PROPERTY_TABLENAME ) >>= sTableName );
474cdf0e10cSrcweir             ::rtl::OUString sColumnName;
475cdf0e10cSrcweir             OSL_VERIFY( xOrderColumn->getPropertyValue( PROPERTY_NAME ) >>= sColumnName );
476cdf0e10cSrcweir 
477cdf0e10cSrcweir             if ( sTableName.getLength() == 0 )
478cdf0e10cSrcweir             {
479cdf0e10cSrcweir                 if ( !xColumnNames->hasByName( sColumnName ) )
480cdf0e10cSrcweir                 {
481cdf0e10cSrcweir                     invalidColumn = true;
482cdf0e10cSrcweir                     break;
483cdf0e10cSrcweir                 }
484cdf0e10cSrcweir             }
485cdf0e10cSrcweir             else
486cdf0e10cSrcweir             {
487cdf0e10cSrcweir                 if ( !xTableNames->hasByName( sTableName ) )
488cdf0e10cSrcweir                 {
489cdf0e10cSrcweir                     invalidColumn = true;
490cdf0e10cSrcweir                     break;
491cdf0e10cSrcweir                 }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir                 const Reference< XColumnsSupplier > xSuppTableColumns( xTableNames->getByName( sTableName ), UNO_QUERY_THROW );
494cdf0e10cSrcweir                 const Reference< XNameAccess > xTableColumnNames( xSuppTableColumns->getColumns(), UNO_QUERY_THROW );
495cdf0e10cSrcweir                 if ( !xTableColumnNames->hasByName( sColumnName ) )
496cdf0e10cSrcweir                 {
497cdf0e10cSrcweir                     invalidColumn = true;
498cdf0e10cSrcweir                     break;
499cdf0e10cSrcweir                 }
500cdf0e10cSrcweir             }
501cdf0e10cSrcweir         }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir         if ( invalidColumn )
504cdf0e10cSrcweir         {
505cdf0e10cSrcweir             // reset the complete order statement at both the row set and the parser
506cdf0e10cSrcweir             const ::rtl::OUString sEmptyOrder;
507cdf0e10cSrcweir             xRowSetProps->setPropertyValue( PROPERTY_ORDER, makeAny( sEmptyOrder ) );
508cdf0e10cSrcweir             xComposer->setOrder( sEmptyOrder );
509cdf0e10cSrcweir         }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir         // .............................................................................................................
512cdf0e10cSrcweir         // check if the columns participating in the filter refer to existing tables
513cdf0e10cSrcweir         // TODO: there's no API at all for this. The method which comes nearest to what we need is
514cdf0e10cSrcweir         // "getStructuredFilter", but it returns pure column names only. That is, for a statement like
515cdf0e10cSrcweir         // "SELECT * FROM <table> WHERE <other_table>.<column> = <value>", it will return "<column>". But
516cdf0e10cSrcweir         // there's no API at all to retrieve the information about  "<other_table>" - which is what would
517cdf0e10cSrcweir         // be needed here.
518cdf0e10cSrcweir         // That'd be a chance to replace getStructuredFilter with something more reasonable. This method
519cdf0e10cSrcweir         // has at least one other problem: For a clause like "<column> != <value>", it will return "<column>"
520cdf0e10cSrcweir         // as column name, "NOT_EQUAL" as operator, and "!= <value>" as value, effectively duplicating the
521cdf0e10cSrcweir         // information about the operator, and beding all clients to manually remove the "!=" from the value
522cdf0e10cSrcweir         // string.
523cdf0e10cSrcweir         // So, what really would be handy, is some
524cdf0e10cSrcweir         //   XNormalizedFilter getNormalizedFilter();
525cdf0e10cSrcweir         // with
526cdf0e10cSrcweir         //   interface XDisjunctiveFilterExpression
527cdf0e10cSrcweir         //   {
528cdf0e10cSrcweir         //     XConjunctiveFilterTerm getTerm( int index );
529cdf0e10cSrcweir         //   }
530cdf0e10cSrcweir         //   interface XConjunctiveFilterTerm
531cdf0e10cSrcweir         //   {
532cdf0e10cSrcweir         //     ComparisonPredicate getPredicate( int index );
533cdf0e10cSrcweir         //   }
534cdf0e10cSrcweir         //   struct ComparisonPredicate
535cdf0e10cSrcweir         //   {
536cdf0e10cSrcweir         //     XComparisonOperand   Lhs;
537cdf0e10cSrcweir         //     SQLFilterOperator    Operator;
538cdf0e10cSrcweir         //     XComparisonOperand   Rhs;
539cdf0e10cSrcweir         //   }
540cdf0e10cSrcweir         //   interface XComparisonOperand
541cdf0e10cSrcweir         //   {
542cdf0e10cSrcweir         //     SQLFilterOperand Type;
543cdf0e10cSrcweir         //     XPropertySet     getColumn();
544cdf0e10cSrcweir         //     string           getLiteral();
545cdf0e10cSrcweir         //     ...
546cdf0e10cSrcweir         //   }
547cdf0e10cSrcweir         //   enum SQLFilterOperand { Column, Literal, ... }
548cdf0e10cSrcweir         //
549cdf0e10cSrcweir         // ... or something like this ....
550cdf0e10cSrcweir     }
551cdf0e10cSrcweir     catch( const Exception& )
552cdf0e10cSrcweir     {
553cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
554cdf0e10cSrcweir     }
555cdf0e10cSrcweir }
556cdf0e10cSrcweir 
557cdf0e10cSrcweir // ---------------------------------------------------------------------------------------------------------------------
558cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::InitializeForm( const Reference< XPropertySet > & i_formProperties )
559cdf0e10cSrcweir {
560cdf0e10cSrcweir 	if(!m_pCurrentlyDisplayed)
561cdf0e10cSrcweir 		return sal_True;
562cdf0e10cSrcweir 
563cdf0e10cSrcweir 	// this method set all format settings from the orignal table or query
564cdf0e10cSrcweir 	try
565cdf0e10cSrcweir 	{
566cdf0e10cSrcweir 		DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
567cdf0e10cSrcweir         ENSURE_OR_RETURN_FALSE( pData, "SbaTableQueryBrowser::InitializeForm: No user data set at the currently displayed entry!" );
568cdf0e10cSrcweir         ENSURE_OR_RETURN_FALSE( pData->xObjectProperties.is(), "SbaTableQueryBrowser::InitializeForm: No table available!" );
569cdf0e10cSrcweir 
570cdf0e10cSrcweir         Reference< XPropertySetInfo > xPSI( pData->xObjectProperties->getPropertySetInfo(), UNO_SET_THROW );
571cdf0e10cSrcweir 
572cdf0e10cSrcweir         ::comphelper::NamedValueCollection aPropertyValues;
573cdf0e10cSrcweir 
574cdf0e10cSrcweir         const ::rtl::OUString aTransferProperties[] =
575cdf0e10cSrcweir         {
576cdf0e10cSrcweir             PROPERTY_APPLYFILTER,
577cdf0e10cSrcweir             PROPERTY_FILTER,
578cdf0e10cSrcweir             PROPERTY_HAVING_CLAUSE,
579cdf0e10cSrcweir             PROPERTY_ORDER
580cdf0e10cSrcweir         };
581cdf0e10cSrcweir         for ( size_t i=0; i < sizeof( aTransferProperties ) / sizeof( aTransferProperties[0] ); ++i )
582cdf0e10cSrcweir         {
583cdf0e10cSrcweir             if ( !xPSI->hasPropertyByName( aTransferProperties[i] ) )
584cdf0e10cSrcweir                 continue;
585cdf0e10cSrcweir             aPropertyValues.put( aTransferProperties[i], pData->xObjectProperties->getPropertyValue( aTransferProperties[i] ) );
586cdf0e10cSrcweir         }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir         const ::std::vector< ::rtl::OUString > aNames( aPropertyValues.getNames() );
589cdf0e10cSrcweir         Sequence< ::rtl::OUString > aPropNames( aNames.size() );
590cdf0e10cSrcweir         ::std::copy( aNames.begin(), aNames.end(), aPropNames.getArray() );
591cdf0e10cSrcweir 
592cdf0e10cSrcweir         Sequence< Any > aPropValues( aNames.size() );
593cdf0e10cSrcweir         ::std::transform( aNames.begin(), aNames.end(), aPropValues.getArray(), SelectValueByName( aPropertyValues ) );
594cdf0e10cSrcweir 
595cdf0e10cSrcweir 		Reference< XMultiPropertySet > xFormMultiSet( i_formProperties, UNO_QUERY_THROW );
596cdf0e10cSrcweir 		xFormMultiSet->setPropertyValues( aPropNames, aPropValues );
597cdf0e10cSrcweir 
598cdf0e10cSrcweir         impl_sanitizeRowSetClauses_nothrow();
599cdf0e10cSrcweir 	}
600cdf0e10cSrcweir 	catch ( const Exception& )
601cdf0e10cSrcweir 	{
602cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
603cdf0e10cSrcweir 		return sal_False;
604cdf0e10cSrcweir 	}
605cdf0e10cSrcweir 
606cdf0e10cSrcweir 	return sal_True;
607cdf0e10cSrcweir }
608cdf0e10cSrcweir 
609cdf0e10cSrcweir //------------------------------------------------------------------------------
610cdf0e10cSrcweir void SbaTableQueryBrowser::initializePreviewMode()
611cdf0e10cSrcweir {
612cdf0e10cSrcweir 	if ( getBrowserView() && getBrowserView()->getVclControl() )
613cdf0e10cSrcweir 	{
614cdf0e10cSrcweir 		getBrowserView()->getVclControl()->AlwaysEnableInput( sal_False );
615cdf0e10cSrcweir 		getBrowserView()->getVclControl()->EnableInput( sal_False );
616cdf0e10cSrcweir 		getBrowserView()->getVclControl()->ForceHideScrollbars( sal_True );
617cdf0e10cSrcweir 	}
618cdf0e10cSrcweir 	Reference< XPropertySet >  xDataSourceSet(getRowSet(), UNO_QUERY);
619cdf0e10cSrcweir 	if ( xDataSourceSet.is() )
620cdf0e10cSrcweir 	{
621cdf0e10cSrcweir 		xDataSourceSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowInserts")),makeAny(sal_False));
622cdf0e10cSrcweir 		xDataSourceSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowUpdates")),makeAny(sal_False));
623cdf0e10cSrcweir 		xDataSourceSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowDeletes")),makeAny(sal_False));
624cdf0e10cSrcweir 	}
625cdf0e10cSrcweir }
626cdf0e10cSrcweir 
627cdf0e10cSrcweir //------------------------------------------------------------------------------
628cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::InitializeGridModel(const Reference< ::com::sun::star::form::XFormComponent > & xGrid)
629cdf0e10cSrcweir {
630cdf0e10cSrcweir 	try
631cdf0e10cSrcweir 	{
632cdf0e10cSrcweir 		Reference< ::com::sun::star::form::XGridColumnFactory >  xColFactory(xGrid, UNO_QUERY);
633cdf0e10cSrcweir 		Reference< XNameContainer >  xColContainer(xGrid, UNO_QUERY);
634cdf0e10cSrcweir 		clearGridColumns( xColContainer );
635cdf0e10cSrcweir 
636cdf0e10cSrcweir 		Reference< XChild > xGridAsChild(xGrid, UNO_QUERY);
637cdf0e10cSrcweir 		Reference< XLoadable > xFormAsLoadable;
638cdf0e10cSrcweir 		if (xGridAsChild.is())
639cdf0e10cSrcweir 			xFormAsLoadable = xFormAsLoadable.query(xGridAsChild->getParent());
640cdf0e10cSrcweir 		if (xFormAsLoadable.is() && xFormAsLoadable->isLoaded())
641cdf0e10cSrcweir 		{
642cdf0e10cSrcweir 			// set the formats from the table
643cdf0e10cSrcweir 			if(m_pCurrentlyDisplayed)
644cdf0e10cSrcweir 			{
645cdf0e10cSrcweir 				Sequence< ::rtl::OUString> aProperties(6 + ( m_bPreview ? 5 : 0 ));
646cdf0e10cSrcweir 				Sequence< Any> aValues(7 + ( m_bPreview ? 5 : 0 ));
647cdf0e10cSrcweir 
648cdf0e10cSrcweir 				DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
649cdf0e10cSrcweir 				OSL_ENSURE( pData->xObjectProperties.is(), "SbaTableQueryBrowser::InitializeGridModel: No table available!" );
650cdf0e10cSrcweir                 if ( !pData->xObjectProperties.is() )
651cdf0e10cSrcweir                     return sal_False;
652cdf0e10cSrcweir 
653cdf0e10cSrcweir 				::rtl::OUString* pStringIter = aProperties.getArray();
654cdf0e10cSrcweir 				Any* pValueIter = aValues.getArray();
655cdf0e10cSrcweir 				if ( m_bPreview )
656cdf0e10cSrcweir 				{
657cdf0e10cSrcweir 					*pStringIter++	= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AlwaysShowCursor"));
658cdf0e10cSrcweir 					*pValueIter++	<<= sal_False;
659cdf0e10cSrcweir 					*pStringIter++	= PROPERTY_BORDER;
660cdf0e10cSrcweir 					*pValueIter++	<<= sal_Int16(0);
661cdf0e10cSrcweir 				}
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 				*pStringIter++	= PROPERTY_FONT;
664cdf0e10cSrcweir 				*pValueIter++	= pData->xObjectProperties->getPropertyValue(PROPERTY_FONT);
665cdf0e10cSrcweir 				*pStringIter++	= PROPERTY_TEXTEMPHASIS;
666cdf0e10cSrcweir 				*pValueIter++	= pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTEMPHASIS);
667cdf0e10cSrcweir 				*pStringIter++	= PROPERTY_TEXTRELIEF;
668cdf0e10cSrcweir 				*pValueIter++	= pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTRELIEF);
669cdf0e10cSrcweir 				if ( m_bPreview )
670cdf0e10cSrcweir 				{
671cdf0e10cSrcweir 					*pStringIter++	= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasNavigationBar"));
672cdf0e10cSrcweir 					*pValueIter++		<<= sal_False;
673cdf0e10cSrcweir 					*pStringIter++	= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasRecordMarker"));
674cdf0e10cSrcweir 					*pValueIter++		<<= sal_False;
675cdf0e10cSrcweir 				}
676cdf0e10cSrcweir 				*pStringIter++	= PROPERTY_ROW_HEIGHT;
677cdf0e10cSrcweir 				*pValueIter++	= pData->xObjectProperties->getPropertyValue(PROPERTY_ROW_HEIGHT);
678cdf0e10cSrcweir 				if ( m_bPreview )
679cdf0e10cSrcweir 				{
680cdf0e10cSrcweir 					*pStringIter++	= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tabstop"));
681cdf0e10cSrcweir 					*pValueIter++		<<= sal_False;
682cdf0e10cSrcweir 				}
683cdf0e10cSrcweir 				*pStringIter++	= PROPERTY_TEXTCOLOR;
684cdf0e10cSrcweir 				*pValueIter++	= pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTCOLOR);
685cdf0e10cSrcweir 				*pStringIter++	= PROPERTY_TEXTLINECOLOR;
686cdf0e10cSrcweir 				*pValueIter++	= pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTLINECOLOR);
687cdf0e10cSrcweir 
688cdf0e10cSrcweir 				Reference< XMultiPropertySet >	xFormMultiSet(xGrid, UNO_QUERY);
689cdf0e10cSrcweir 				xFormMultiSet->setPropertyValues(aProperties, aValues);
690cdf0e10cSrcweir 			}
691cdf0e10cSrcweir 
692cdf0e10cSrcweir 
693cdf0e10cSrcweir 			// get the formats supplier of the database we're working with
694cdf0e10cSrcweir 			Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xSupplier = getNumberFormatter()->getNumberFormatsSupplier();
695cdf0e10cSrcweir 
696cdf0e10cSrcweir 			Reference<XConnection> xConnection;
697cdf0e10cSrcweir 			Reference<XPropertySet> xRowSetProps(getRowSet(),UNO_QUERY);
698cdf0e10cSrcweir             xRowSetProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xConnection;
699cdf0e10cSrcweir 			OSL_ENSURE(xConnection.is(),"A ActiveConnection should normaly exists!");
700cdf0e10cSrcweir 
701cdf0e10cSrcweir 			Reference<XChild> xChild(xConnection,UNO_QUERY);
702cdf0e10cSrcweir 			Reference<XPropertySet> xDataSourceProp(xChild->getParent(),UNO_QUERY);
703cdf0e10cSrcweir 			sal_Bool bSuppressVersionCol = sal_False;
704cdf0e10cSrcweir             OSL_VERIFY( xDataSourceProp->getPropertyValue( PROPERTY_SUPPRESSVERSIONCL ) >>= bSuppressVersionCol );
705cdf0e10cSrcweir 
706cdf0e10cSrcweir 			// insert the column into the gridcontrol so that we see something :-)
707cdf0e10cSrcweir 			::rtl::OUString aCurrentModelType;
708cdf0e10cSrcweir 			Reference<XColumnsSupplier> xSupCols(getRowSet(),UNO_QUERY);
709cdf0e10cSrcweir 			Reference<XNameAccess> xColumns 	= xSupCols->getColumns();
710cdf0e10cSrcweir 			Sequence< ::rtl::OUString> aNames	= xColumns->getElementNames();
711cdf0e10cSrcweir 			const ::rtl::OUString* pIter		= aNames.getConstArray();
712cdf0e10cSrcweir 			const ::rtl::OUString* pEnd 		= pIter + aNames.getLength();
713cdf0e10cSrcweir 
714cdf0e10cSrcweir 			::rtl::OUString sDefaultProperty;
715cdf0e10cSrcweir 			Reference< XPropertySet > xColumn;
716cdf0e10cSrcweir             Reference< XPropertySetInfo > xColPSI;
717cdf0e10cSrcweir 			for (sal_uInt16 i=0; pIter != pEnd; ++i,++pIter)
718cdf0e10cSrcweir 			{
719cdf0e10cSrcweir                 xColumn.set( xColumns->getByName( *pIter ), UNO_QUERY_THROW );
720cdf0e10cSrcweir                 xColPSI.set( xColumn->getPropertySetInfo(), UNO_SET_THROW );
721cdf0e10cSrcweir 
722cdf0e10cSrcweir 				// ignore the column when it is a rowversion one
723cdf0e10cSrcweir 				if  (   bSuppressVersionCol
724cdf0e10cSrcweir                     &&  xColPSI->hasPropertyByName( PROPERTY_ISROWVERSION )
725cdf0e10cSrcweir                     &&  ::cppu::any2bool( xColumn->getPropertyValue( PROPERTY_ISROWVERSION ) )
726cdf0e10cSrcweir                     )
727cdf0e10cSrcweir 					continue;
728cdf0e10cSrcweir 
729cdf0e10cSrcweir 				// use the result set column's type to determine the type of grid column to create
730cdf0e10cSrcweir 				sal_Bool bFormattedIsNumeric	= sal_True;
731cdf0e10cSrcweir                 sal_Int32 nType = ::comphelper::getINT32( xColumn->getPropertyValue( PROPERTY_TYPE ) );
732cdf0e10cSrcweir 
733cdf0e10cSrcweir                 ::std::vector< NamedValue > aInitialValues;
734cdf0e10cSrcweir                 ::std::vector< ::rtl::OUString > aCopyProperties;
735cdf0e10cSrcweir                 Any aDefault;
736cdf0e10cSrcweir 
737cdf0e10cSrcweir                 switch(nType)
738cdf0e10cSrcweir 				{
739cdf0e10cSrcweir 					case DataType::BIT:
740cdf0e10cSrcweir                     case DataType::BOOLEAN:
741cdf0e10cSrcweir                     {
742cdf0e10cSrcweir 						aCurrentModelType = ::rtl::OUString::createFromAscii("CheckBox");
743cdf0e10cSrcweir                         aInitialValues.push_back( NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VisualEffect" ) ), makeAny( VisualEffect::FLAT ) ) );
744cdf0e10cSrcweir 						sDefaultProperty = PROPERTY_DEFAULTSTATE;
745cdf0e10cSrcweir 
746cdf0e10cSrcweir                         sal_Int32 nNullable = ColumnValue::NULLABLE_UNKNOWN;
747cdf0e10cSrcweir                         OSL_VERIFY( xColumn->getPropertyValue( PROPERTY_ISNULLABLE ) >>= nNullable );
748cdf0e10cSrcweir                         aInitialValues.push_back( NamedValue(
749cdf0e10cSrcweir                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TriState" ) ),
750cdf0e10cSrcweir                             makeAny( sal_Bool( ColumnValue::NO_NULLS != nNullable ) )
751cdf0e10cSrcweir                         ) );
752cdf0e10cSrcweir                         if ( ColumnValue::NO_NULLS == nNullable )
753cdf0e10cSrcweir                             aDefault <<= (sal_Int16)STATE_NOCHECK;
754cdf0e10cSrcweir                     }
755cdf0e10cSrcweir                     break;
756cdf0e10cSrcweir 
757cdf0e10cSrcweir 					case DataType::LONGVARCHAR:
758cdf0e10cSrcweir 					case DataType::CLOB:
759cdf0e10cSrcweir                         aInitialValues.push_back( NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ), makeAny( (sal_Bool)sal_True ) ) );
760cdf0e10cSrcweir                         // NO break!
761cdf0e10cSrcweir 					case DataType::BINARY:
762cdf0e10cSrcweir 					case DataType::VARBINARY:
763cdf0e10cSrcweir 					case DataType::LONGVARBINARY:
764cdf0e10cSrcweir 						aCurrentModelType = ::rtl::OUString::createFromAscii("TextField");
765cdf0e10cSrcweir 						sDefaultProperty = PROPERTY_DEFAULTTEXT;
766cdf0e10cSrcweir 						break;
767cdf0e10cSrcweir 
768cdf0e10cSrcweir 					case DataType::VARCHAR:
769cdf0e10cSrcweir 					case DataType::CHAR:
770cdf0e10cSrcweir 						bFormattedIsNumeric = sal_False;
771cdf0e10cSrcweir 						// NO break!
772cdf0e10cSrcweir 					default:
773cdf0e10cSrcweir 						aCurrentModelType = ::rtl::OUString::createFromAscii("FormattedField");
774cdf0e10cSrcweir 						sDefaultProperty = PROPERTY_EFFECTIVEDEFAULT;
775cdf0e10cSrcweir 
776cdf0e10cSrcweir                         if ( xSupplier.is() )
777cdf0e10cSrcweir                             aInitialValues.push_back( NamedValue( ::rtl::OUString::createFromAscii( "FormatsSupplier" ), makeAny( xSupplier ) ) );
778cdf0e10cSrcweir 					    aInitialValues.push_back( NamedValue( ::rtl::OUString::createFromAscii( "TreatAsNumber" ), makeAny( (sal_Bool)bFormattedIsNumeric ) ) );
779cdf0e10cSrcweir                         aCopyProperties.push_back( PROPERTY_FORMATKEY );
780cdf0e10cSrcweir 						break;
781cdf0e10cSrcweir 				}
782cdf0e10cSrcweir 
783cdf0e10cSrcweir                 aInitialValues.push_back( NamedValue( PROPERTY_CONTROLSOURCE, makeAny( *pIter ) ) );
784cdf0e10cSrcweir                 ::rtl::OUString sLabel;
785cdf0e10cSrcweir                 xColumn->getPropertyValue(PROPERTY_LABEL) >>= sLabel;
786cdf0e10cSrcweir                 if ( sLabel.getLength() )
787cdf0e10cSrcweir                     aInitialValues.push_back( NamedValue( PROPERTY_LABEL, makeAny( sLabel ) ) );
788cdf0e10cSrcweir                 else
789cdf0e10cSrcweir                     aInitialValues.push_back( NamedValue( PROPERTY_LABEL, makeAny( *pIter ) ) );
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 				Reference< XPropertySet > xGridCol( xColFactory->createColumn( aCurrentModelType ), UNO_SET_THROW );
792cdf0e10cSrcweir                 Reference< XPropertySetInfo > xGridColPSI( xGridCol->getPropertySetInfo(), UNO_SET_THROW );
793cdf0e10cSrcweir 
794cdf0e10cSrcweir                 // calculate the default
795cdf0e10cSrcweir 				if ( xGridColPSI->hasPropertyByName( PROPERTY_CONTROLDEFAULT ) )
796cdf0e10cSrcweir                 {
797cdf0e10cSrcweir 					aDefault = xColumn->getPropertyValue( PROPERTY_CONTROLDEFAULT );
798cdf0e10cSrcweir 				    // default value
799cdf0e10cSrcweir 				    if ( nType == DataType::BIT || nType == DataType::BOOLEAN )
800cdf0e10cSrcweir 				    {
801cdf0e10cSrcweir 					    if ( aDefault.hasValue() )
802cdf0e10cSrcweir 						    aDefault <<= (comphelper::getString(aDefault).toInt32() == 0) ? (sal_Int16)STATE_NOCHECK : (sal_Int16)STATE_CHECK;
803cdf0e10cSrcweir 					    else
804cdf0e10cSrcweir 						    aDefault <<= ((sal_Int16)STATE_DONTKNOW);
805cdf0e10cSrcweir 				    }
806cdf0e10cSrcweir                 }
807cdf0e10cSrcweir 
808cdf0e10cSrcweir 				if ( aDefault.hasValue() )
809cdf0e10cSrcweir                     aInitialValues.push_back( NamedValue( sDefaultProperty, aDefault ) );
810cdf0e10cSrcweir 
811cdf0e10cSrcweir 				// transfer properties from the definition to the UNO-model :
812cdf0e10cSrcweir                 aCopyProperties.push_back( PROPERTY_HIDDEN );
813cdf0e10cSrcweir                 aCopyProperties.push_back( PROPERTY_WIDTH );
814cdf0e10cSrcweir 
815cdf0e10cSrcweir                 // help text to display for the column
816cdf0e10cSrcweir                 Any aDescription;
817cdf0e10cSrcweir 				if ( xColPSI->hasPropertyByName( PROPERTY_HELPTEXT ) )
818cdf0e10cSrcweir                     aDescription = xColumn->getPropertyValue( PROPERTY_HELPTEXT );
819cdf0e10cSrcweir                 ::rtl::OUString sTemp;
820cdf0e10cSrcweir                 aDescription >>= sTemp;
821cdf0e10cSrcweir                 if ( !sTemp.getLength() )
822cdf0e10cSrcweir                     xColumn->getPropertyValue( PROPERTY_DESCRIPTION ) >>= sTemp;
823cdf0e10cSrcweir 
824cdf0e10cSrcweir                 aDescription <<= sTemp;
825cdf0e10cSrcweir                 aInitialValues.push_back( NamedValue( PROPERTY_HELPTEXT, aDescription ) );
826cdf0e10cSrcweir 
827cdf0e10cSrcweir 				// ... horizontal justify
828cdf0e10cSrcweir                 Any aAlign; aAlign <<= sal_Int16( 0 );
829cdf0e10cSrcweir                 Any aColAlign( xColumn->getPropertyValue( PROPERTY_ALIGN ) );
830cdf0e10cSrcweir                 if ( aColAlign.hasValue() )
831cdf0e10cSrcweir                     aAlign <<= sal_Int16( ::comphelper::getINT32( aColAlign ) );
832cdf0e10cSrcweir                 aInitialValues.push_back( NamedValue( PROPERTY_ALIGN, aAlign ) );
833cdf0e10cSrcweir 
834cdf0e10cSrcweir                 // don't allow the mouse to scroll in the cells
835cdf0e10cSrcweir 				if ( xGridColPSI->hasPropertyByName( PROPERTY_MOUSE_WHEEL_BEHAVIOR ) )
836cdf0e10cSrcweir                     aInitialValues.push_back( NamedValue( PROPERTY_MOUSE_WHEEL_BEHAVIOR, makeAny( MouseWheelBehavior::SCROLL_DISABLED ) ) );
837cdf0e10cSrcweir 
838cdf0e10cSrcweir                 // now set all those values
839cdf0e10cSrcweir                 for ( ::std::vector< NamedValue >::const_iterator property = aInitialValues.begin();
840cdf0e10cSrcweir                       property != aInitialValues.end();
841cdf0e10cSrcweir                       ++property
842cdf0e10cSrcweir                     )
843cdf0e10cSrcweir                 {
844cdf0e10cSrcweir 				    xGridCol->setPropertyValue( property->Name, property->Value );
845cdf0e10cSrcweir                 }
846cdf0e10cSrcweir                 for ( ::std::vector< ::rtl::OUString >::const_iterator copyPropertyName = aCopyProperties.begin();
847cdf0e10cSrcweir                       copyPropertyName != aCopyProperties.end();
848cdf0e10cSrcweir                       ++copyPropertyName
849cdf0e10cSrcweir                     )
850cdf0e10cSrcweir 				    xGridCol->setPropertyValue( *copyPropertyName, xColumn->getPropertyValue( *copyPropertyName ) );
851cdf0e10cSrcweir 
852cdf0e10cSrcweir 				xColContainer->insertByName(*pIter, makeAny(xGridCol));
853cdf0e10cSrcweir 			}
854cdf0e10cSrcweir 		}
855cdf0e10cSrcweir 	}
856cdf0e10cSrcweir 	catch(Exception&)
857cdf0e10cSrcweir 	{
858cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
859cdf0e10cSrcweir 		return sal_False;
860cdf0e10cSrcweir 	}
861cdf0e10cSrcweir 
862cdf0e10cSrcweir 	return sal_True;
863cdf0e10cSrcweir }
864cdf0e10cSrcweir // -----------------------------------------------------------------------------
865cdf0e10cSrcweir Reference<XPropertySet> getColumnHelper(SvLBoxEntry* _pCurrentlyDisplayed,const Reference<XPropertySet>& _rxSource)
866cdf0e10cSrcweir {
867cdf0e10cSrcweir 	Reference<XPropertySet> xRet;
868cdf0e10cSrcweir 	if(_pCurrentlyDisplayed)
869cdf0e10cSrcweir 	{
870cdf0e10cSrcweir 		DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pCurrentlyDisplayed->GetUserData());
871cdf0e10cSrcweir 		Reference<XColumnsSupplier> xColumnsSup(pData->xObjectProperties,UNO_QUERY);
872cdf0e10cSrcweir 		Reference<XNameAccess> xNames = xColumnsSup->getColumns();
873cdf0e10cSrcweir 		::rtl::OUString aName;
874cdf0e10cSrcweir 		_rxSource->getPropertyValue(PROPERTY_NAME) >>= aName;
875cdf0e10cSrcweir 		if(xNames.is() && xNames->hasByName(aName))
876cdf0e10cSrcweir 			xRet.set(xNames->getByName(aName),UNO_QUERY);
877cdf0e10cSrcweir 	}
878cdf0e10cSrcweir 	return xRet;
879cdf0e10cSrcweir }
880cdf0e10cSrcweir 
881cdf0e10cSrcweir // -----------------------------------------------------------------------
882cdf0e10cSrcweir void SbaTableQueryBrowser::transferChangedControlProperty(const ::rtl::OUString& _rProperty, const Any& _rNewValue)
883cdf0e10cSrcweir {
884cdf0e10cSrcweir 	if(m_pCurrentlyDisplayed)
885cdf0e10cSrcweir 	{
886cdf0e10cSrcweir 		DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
887cdf0e10cSrcweir 		Reference< XPropertySet > xObjectProps(pData->xObjectProperties, UNO_QUERY);
888cdf0e10cSrcweir 		OSL_ENSURE(xObjectProps.is(),"SbaTableQueryBrowser::transferChangedControlProperty: no table/query object!");
889cdf0e10cSrcweir 		if (xObjectProps.is())
890cdf0e10cSrcweir 			xObjectProps->setPropertyValue(_rProperty, _rNewValue);
891cdf0e10cSrcweir 	}
892cdf0e10cSrcweir }
893cdf0e10cSrcweir 
894cdf0e10cSrcweir // -----------------------------------------------------------------------
895cdf0e10cSrcweir void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException)
896cdf0e10cSrcweir {
897cdf0e10cSrcweir 	SbaXDataBrowserController::propertyChange(evt);
898cdf0e10cSrcweir 
899cdf0e10cSrcweir 	try
900cdf0e10cSrcweir 	{
901cdf0e10cSrcweir 		Reference< XPropertySet >  xSource(evt.Source, UNO_QUERY);
902cdf0e10cSrcweir 		if (!xSource.is())
903cdf0e10cSrcweir 			return;
904cdf0e10cSrcweir 
905cdf0e10cSrcweir 		// one of the many properties which require us to update the definition ?
906cdf0e10cSrcweir 		// a column's width ?
907cdf0e10cSrcweir 		else if (evt.PropertyName.equals(PROPERTY_WIDTH))
908cdf0e10cSrcweir 		{	// a column width has changed -> update the model
909cdf0e10cSrcweir 			// (the update of the view is done elsewhere)
910cdf0e10cSrcweir 			Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
911cdf0e10cSrcweir 			if(xProp.is())
912cdf0e10cSrcweir 			{
913cdf0e10cSrcweir 				if(!evt.NewValue.hasValue())
914cdf0e10cSrcweir 					xProp->setPropertyValue(PROPERTY_WIDTH,makeAny((sal_Int32)227));
915cdf0e10cSrcweir 				else
916cdf0e10cSrcweir 					xProp->setPropertyValue(PROPERTY_WIDTH,evt.NewValue);
917cdf0e10cSrcweir 			}
918cdf0e10cSrcweir 		}
919cdf0e10cSrcweir 
920cdf0e10cSrcweir 		// a column's 'visible' state ?
921cdf0e10cSrcweir 		else if (evt.PropertyName.equals(PROPERTY_HIDDEN))
922cdf0e10cSrcweir 		{
923cdf0e10cSrcweir 			Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
924cdf0e10cSrcweir 			if(xProp.is())
925cdf0e10cSrcweir 				xProp->setPropertyValue(PROPERTY_HIDDEN,evt.NewValue);
926cdf0e10cSrcweir 		}
927cdf0e10cSrcweir 
928cdf0e10cSrcweir 		// a columns alignment ?
929cdf0e10cSrcweir 		else if (evt.PropertyName.equals(PROPERTY_ALIGN))
930cdf0e10cSrcweir 		{
931cdf0e10cSrcweir 			Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
932cdf0e10cSrcweir 			try
933cdf0e10cSrcweir 			{
934cdf0e10cSrcweir 				if(xProp.is())
935cdf0e10cSrcweir 				{
936cdf0e10cSrcweir 					if(evt.NewValue.hasValue())
937cdf0e10cSrcweir 					{
938cdf0e10cSrcweir 						sal_Int16 nAlign = 0;
939cdf0e10cSrcweir 						if(evt.NewValue >>= nAlign)
940cdf0e10cSrcweir 							xProp->setPropertyValue(PROPERTY_ALIGN,makeAny(sal_Int32(nAlign)));
941cdf0e10cSrcweir 						else
942cdf0e10cSrcweir 							xProp->setPropertyValue(PROPERTY_ALIGN,evt.NewValue);
943cdf0e10cSrcweir 					}
944cdf0e10cSrcweir 					else
945cdf0e10cSrcweir 						xProp->setPropertyValue(PROPERTY_ALIGN,makeAny(::com::sun::star::awt::TextAlign::LEFT));
946cdf0e10cSrcweir 				}
947cdf0e10cSrcweir 			}
948cdf0e10cSrcweir             catch( const Exception& )
949cdf0e10cSrcweir             {
950cdf0e10cSrcweir                 DBG_UNHANDLED_EXCEPTION();
951cdf0e10cSrcweir             }
952cdf0e10cSrcweir 		}
953cdf0e10cSrcweir 
954cdf0e10cSrcweir 		// a column's format ?
955cdf0e10cSrcweir 		else if (	(evt.PropertyName.equals(PROPERTY_FORMATKEY))
956cdf0e10cSrcweir 			&&	(TypeClass_LONG == evt.NewValue.getValueTypeClass())
957cdf0e10cSrcweir 			)
958cdf0e10cSrcweir 		{
959cdf0e10cSrcweir 			// update the model (means the definition object)
960cdf0e10cSrcweir 			Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
961cdf0e10cSrcweir 			if(xProp.is())
962cdf0e10cSrcweir 				xProp->setPropertyValue(PROPERTY_FORMATKEY,evt.NewValue);
963cdf0e10cSrcweir 		}
964cdf0e10cSrcweir 
965cdf0e10cSrcweir 		// some table definition properties ?
966cdf0e10cSrcweir 		// the height of the rows in the grid ?
967cdf0e10cSrcweir 		else if (evt.PropertyName.equals(PROPERTY_ROW_HEIGHT))
968cdf0e10cSrcweir 		{
969cdf0e10cSrcweir 			if(m_pCurrentlyDisplayed)
970cdf0e10cSrcweir 			{
971cdf0e10cSrcweir 				DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
972cdf0e10cSrcweir 				OSL_ENSURE( pData->xObjectProperties.is(), "No table available!" );
973cdf0e10cSrcweir 
974cdf0e10cSrcweir 				sal_Bool bDefault = !evt.NewValue.hasValue();
975cdf0e10cSrcweir 				if (bDefault)
976cdf0e10cSrcweir 					pData->xObjectProperties->setPropertyValue(PROPERTY_ROW_HEIGHT,makeAny((sal_Int32)45));
977cdf0e10cSrcweir 				else
978cdf0e10cSrcweir 					pData->xObjectProperties->setPropertyValue(PROPERTY_ROW_HEIGHT,evt.NewValue);
979cdf0e10cSrcweir 			}
980cdf0e10cSrcweir 		}
981cdf0e10cSrcweir 
982cdf0e10cSrcweir 		else if (	evt.PropertyName.equals(PROPERTY_FONT)			// the font ?
983cdf0e10cSrcweir 				||	evt.PropertyName.equals(PROPERTY_TEXTCOLOR) 	// the text color ?
984cdf0e10cSrcweir 				||	evt.PropertyName.equals(PROPERTY_FILTER)		// the filter ?
985cdf0e10cSrcweir 				||	evt.PropertyName.equals(PROPERTY_HAVING_CLAUSE)	// the having clause ?
986cdf0e10cSrcweir 				||	evt.PropertyName.equals(PROPERTY_ORDER) 		// the sort ?
987cdf0e10cSrcweir 				||	evt.PropertyName.equals(PROPERTY_APPLYFILTER)	// the appliance of the filter ?
988cdf0e10cSrcweir 				||	evt.PropertyName.equals(PROPERTY_TEXTLINECOLOR) // the text line color ?
989cdf0e10cSrcweir 				||	evt.PropertyName.equals(PROPERTY_TEXTEMPHASIS)	// the text emphasis ?
990cdf0e10cSrcweir 				||	evt.PropertyName.equals(PROPERTY_TEXTRELIEF)	// the text relief ?
991cdf0e10cSrcweir 				)
992cdf0e10cSrcweir 		{
993cdf0e10cSrcweir 			transferChangedControlProperty(evt.PropertyName, evt.NewValue);
994cdf0e10cSrcweir 		}
995cdf0e10cSrcweir 	}
996cdf0e10cSrcweir     catch( const Exception& )
997cdf0e10cSrcweir     {
998cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
999cdf0e10cSrcweir     }
1000cdf0e10cSrcweir }
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir // -----------------------------------------------------------------------
1003cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::suspend(sal_Bool bSuspend) throw( RuntimeException )
1004cdf0e10cSrcweir {
1005cdf0e10cSrcweir     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1006cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
1007cdf0e10cSrcweir     if ( getView() && getView()->IsInModalMode() )
1008cdf0e10cSrcweir         return sal_False;
1009cdf0e10cSrcweir     sal_Bool bRet = sal_False;
1010cdf0e10cSrcweir 	if ( !m_bInSuspend )
1011cdf0e10cSrcweir 	{
1012cdf0e10cSrcweir 		m_bInSuspend = sal_True;
1013cdf0e10cSrcweir 		if ( rBHelper.bDisposed )
1014cdf0e10cSrcweir 			throw DisposedException( ::rtl::OUString(), *this );
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir         bRet = SbaXDataBrowserController::suspend(bSuspend);
1017cdf0e10cSrcweir         if ( bRet && getView() )
1018cdf0e10cSrcweir             getView()->Hide();
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir 		m_bInSuspend = sal_False;
1021cdf0e10cSrcweir 	}
1022cdf0e10cSrcweir 
1023cdf0e10cSrcweir 	return bRet;
1024cdf0e10cSrcweir }
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir // -------------------------------------------------------------------------
1027cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::statusChanged( const FeatureStateEvent& _rEvent ) throw(RuntimeException)
1028cdf0e10cSrcweir {
1029cdf0e10cSrcweir 	// search the external dispatcher causing this call
1030cdf0e10cSrcweir 	Reference< XDispatch > xSource(_rEvent.Source, UNO_QUERY);
1031cdf0e10cSrcweir     ExternalFeaturesMap::iterator aLoop;
1032cdf0e10cSrcweir 	for ( aLoop = m_aExternalFeatures.begin();
1033cdf0e10cSrcweir 		  aLoop != m_aExternalFeatures.end();
1034cdf0e10cSrcweir 		  ++aLoop
1035cdf0e10cSrcweir 		)
1036cdf0e10cSrcweir 	{
1037cdf0e10cSrcweir 		if ( _rEvent.FeatureURL.Complete == aLoop->second.aURL.Complete)
1038cdf0e10cSrcweir 		{
1039cdf0e10cSrcweir 			DBG_ASSERT( xSource.get() == aLoop->second.xDispatcher.get(), "SbaTableQueryBrowser::statusChanged: inconsistent!" );
1040cdf0e10cSrcweir 			// update the enabled state
1041cdf0e10cSrcweir 			aLoop->second.bEnabled = _rEvent.IsEnabled;
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir 			switch ( aLoop->first )
1044cdf0e10cSrcweir 			{
1045cdf0e10cSrcweir 				case ID_BROWSER_DOCUMENT_DATASOURCE:
1046cdf0e10cSrcweir 				{
1047cdf0e10cSrcweir 					// if it's the slot for the document data source, remember the state
1048cdf0e10cSrcweir 					Sequence< PropertyValue > aDescriptor;
1049cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 0
1050cdf0e10cSrcweir 					sal_Bool bProperFormat =
1051cdf0e10cSrcweir 	#endif
1052cdf0e10cSrcweir 					_rEvent.State >>= aDescriptor;
1053cdf0e10cSrcweir 					OSL_ENSURE(bProperFormat, "SbaTableQueryBrowser::statusChanged: need a data access descriptor here!");
1054cdf0e10cSrcweir 					m_aDocumentDataSource.initializeFrom(aDescriptor);
1055cdf0e10cSrcweir 
1056cdf0e10cSrcweir 					OSL_ENSURE( (   m_aDocumentDataSource.has(daDataSource)
1057cdf0e10cSrcweir                                 ||  m_aDocumentDataSource.has(daDatabaseLocation)
1058cdf0e10cSrcweir                                 )
1059cdf0e10cSrcweir                                 &&  m_aDocumentDataSource.has(daCommand)
1060cdf0e10cSrcweir                                 &&  m_aDocumentDataSource.has(daCommandType),
1061cdf0e10cSrcweir 						"SbaTableQueryBrowser::statusChanged: incomplete descriptor!");
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir 					// check if we know the object which is set as document data source
1064cdf0e10cSrcweir 					checkDocumentDataSource();
1065cdf0e10cSrcweir 				}
1066cdf0e10cSrcweir 				break;
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir 				default:
1069cdf0e10cSrcweir 					// update the toolbox
1070cdf0e10cSrcweir                     implCheckExternalSlot( aLoop->first );
1071cdf0e10cSrcweir 					break;
1072cdf0e10cSrcweir 			}
1073cdf0e10cSrcweir 			break;
1074cdf0e10cSrcweir 		}
1075cdf0e10cSrcweir 	}
1076cdf0e10cSrcweir 
1077cdf0e10cSrcweir 	DBG_ASSERT(aLoop != m_aExternalFeatures.end(), "SbaTableQueryBrowser::statusChanged: don't know who sent this!");
1078cdf0e10cSrcweir }
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir // -------------------------------------------------------------------------
1081cdf0e10cSrcweir void SbaTableQueryBrowser::checkDocumentDataSource()
1082cdf0e10cSrcweir {
1083cdf0e10cSrcweir 	SvLBoxEntry* pDataSourceEntry = NULL;
1084cdf0e10cSrcweir 	SvLBoxEntry* pContainerEntry = NULL;
1085cdf0e10cSrcweir 	SvLBoxEntry* pObjectEntry = getObjectEntry( m_aDocumentDataSource, &pDataSourceEntry, &pContainerEntry, sal_False );
1086cdf0e10cSrcweir 	sal_Bool bKnownDocDataSource = (NULL != pObjectEntry);
1087cdf0e10cSrcweir 	if (!bKnownDocDataSource)
1088cdf0e10cSrcweir 	{
1089cdf0e10cSrcweir 		if (NULL != pDataSourceEntry)
1090cdf0e10cSrcweir 		{	// at least the data source is know
1091cdf0e10cSrcweir 			if (NULL != pContainerEntry)
1092cdf0e10cSrcweir 				bKnownDocDataSource = sal_True; // assume we know it.
1093cdf0e10cSrcweir 				// TODO: should we expand the object container? This may be too expensive just for checking ....
1094cdf0e10cSrcweir 			else
1095cdf0e10cSrcweir 			{
1096cdf0e10cSrcweir 				if ((NULL == pObjectEntry) && m_aDocumentDataSource.has(daCommandType) && m_aDocumentDataSource.has(daCommand))
1097cdf0e10cSrcweir 				{	// maybe we have a command to be displayed ?
1098cdf0e10cSrcweir 					sal_Int32 nCommandType = CommandType::TABLE;
1099cdf0e10cSrcweir 					m_aDocumentDataSource[daCommandType] >>= nCommandType;
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir 					::rtl::OUString sCommand;
1102cdf0e10cSrcweir 					m_aDocumentDataSource[daCommand] >>= sCommand;
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir 					bKnownDocDataSource = (CommandType::COMMAND == nCommandType) && (0 != sCommand.getLength());
1105cdf0e10cSrcweir 				}
1106cdf0e10cSrcweir 			}
1107cdf0e10cSrcweir 		}
1108cdf0e10cSrcweir 	}
1109cdf0e10cSrcweir 
1110cdf0e10cSrcweir     if ( !bKnownDocDataSource )
1111cdf0e10cSrcweir 	    m_aExternalFeatures[ ID_BROWSER_DOCUMENT_DATASOURCE ].bEnabled = sal_False;
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir 	// update the toolbox
1114cdf0e10cSrcweir 	implCheckExternalSlot(ID_BROWSER_DOCUMENT_DATASOURCE);
1115cdf0e10cSrcweir }
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir // -------------------------------------------------------------------------
1118cdf0e10cSrcweir void SbaTableQueryBrowser::extractDescriptorProps(const ::svx::ODataAccessDescriptor& _rDescriptor, ::rtl::OUString& _rDataSource, ::rtl::OUString& _rCommand, sal_Int32& _rCommandType, sal_Bool& _rEscapeProcessing)
1119cdf0e10cSrcweir {
1120cdf0e10cSrcweir 	_rDataSource = _rDescriptor.getDataSource();
1121cdf0e10cSrcweir 	if ( _rDescriptor.has(daCommand) )
1122cdf0e10cSrcweir 		_rDescriptor[daCommand] >>= _rCommand;
1123cdf0e10cSrcweir 	if ( _rDescriptor.has(daCommandType) )
1124cdf0e10cSrcweir 		_rDescriptor[daCommandType] >>= _rCommandType;
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir 	// escape processing is the only one allowed not to be present
1127cdf0e10cSrcweir 	_rEscapeProcessing = sal_True;
1128cdf0e10cSrcweir 	if (_rDescriptor.has(daEscapeProcessing))
1129cdf0e10cSrcweir 		_rEscapeProcessing = ::cppu::any2bool(_rDescriptor[daEscapeProcessing]);
1130cdf0e10cSrcweir }
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir // -------------------------------------------------------------------------
1133cdf0e10cSrcweir namespace
1134cdf0e10cSrcweir {
1135cdf0e10cSrcweir     bool getDataSourceDisplayName_isURL( const String& _rDS, String& _rDisplayName, String& _rUniqueId )
1136cdf0e10cSrcweir     {
1137cdf0e10cSrcweir         INetURLObject aURL( _rDS );
1138cdf0e10cSrcweir 		if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1139cdf0e10cSrcweir         {
1140cdf0e10cSrcweir 			_rDisplayName = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_WITH_CHARSET);
1141cdf0e10cSrcweir             //	_rDisplayName = aURL.getName(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_WITH_CHARSET);
1142cdf0e10cSrcweir             _rUniqueId = aURL.GetMainURL( INetURLObject::NO_DECODE );
1143cdf0e10cSrcweir             return true;
1144cdf0e10cSrcweir         }
1145cdf0e10cSrcweir         _rDisplayName = _rDS;
1146cdf0e10cSrcweir         _rUniqueId = String();
1147cdf0e10cSrcweir         return false;
1148cdf0e10cSrcweir     }
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir     // .....................................................................
1151cdf0e10cSrcweir     struct FilterByEntryDataId : public IEntryFilter
1152cdf0e10cSrcweir     {
1153cdf0e10cSrcweir         String sId;
1154cdf0e10cSrcweir         FilterByEntryDataId( const String& _rId ) : sId( _rId ) { }
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir         virtual ~FilterByEntryDataId() {}
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir         virtual bool    includeEntry( SvLBoxEntry* _pEntry ) const;
1159cdf0e10cSrcweir     };
1160cdf0e10cSrcweir 
1161cdf0e10cSrcweir     bool FilterByEntryDataId::includeEntry( SvLBoxEntry* _pEntry ) const
1162cdf0e10cSrcweir     {
1163cdf0e10cSrcweir         DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( _pEntry->GetUserData() );
1164cdf0e10cSrcweir         return ( !pData || ( pData->sAccessor == sId ) );
1165cdf0e10cSrcweir     }
1166cdf0e10cSrcweir }
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir // -------------------------------------------------------------------------
1169cdf0e10cSrcweir String SbaTableQueryBrowser::getDataSourceAcessor( SvLBoxEntry* _pDataSourceEntry ) const
1170cdf0e10cSrcweir {
1171cdf0e10cSrcweir     DBG_ASSERT( _pDataSourceEntry, "SbaTableQueryBrowser::getDataSourceAcessor: invalid entry!" );
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir 	DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( _pDataSourceEntry->GetUserData() );
1174cdf0e10cSrcweir     DBG_ASSERT( pData, "SbaTableQueryBrowser::getDataSourceAcessor: invalid entry data!" );
1175cdf0e10cSrcweir     DBG_ASSERT( pData->eType == etDatasource, "SbaTableQueryBrowser::getDataSourceAcessor: entry does not denote a data source!" );
1176cdf0e10cSrcweir     return pData->sAccessor.Len() ? pData->sAccessor : GetEntryText( _pDataSourceEntry );
1177cdf0e10cSrcweir }
1178cdf0e10cSrcweir 
1179cdf0e10cSrcweir // -------------------------------------------------------------------------
1180cdf0e10cSrcweir SvLBoxEntry* SbaTableQueryBrowser::getObjectEntry(const ::rtl::OUString& _rDataSource, const ::rtl::OUString& _rCommand, sal_Int32 _nCommandType,
1181cdf0e10cSrcweir 		SvLBoxEntry** _ppDataSourceEntry, SvLBoxEntry** _ppContainerEntry, sal_Bool _bExpandAncestors,
1182cdf0e10cSrcweir         const SharedConnection& _rxConnection )
1183cdf0e10cSrcweir {
1184cdf0e10cSrcweir 	if (_ppDataSourceEntry)
1185cdf0e10cSrcweir 		*_ppDataSourceEntry = NULL;
1186cdf0e10cSrcweir 	if (_ppContainerEntry)
1187cdf0e10cSrcweir 		*_ppContainerEntry = NULL;
1188cdf0e10cSrcweir 
1189cdf0e10cSrcweir 	SvLBoxEntry* pObject = NULL;
1190cdf0e10cSrcweir 	if ( m_pTreeView )
1191cdf0e10cSrcweir 	{
1192cdf0e10cSrcweir 		// look for the data source entry
1193cdf0e10cSrcweir         String sDisplayName, sDataSourceId;
1194cdf0e10cSrcweir         bool bIsDataSourceURL = getDataSourceDisplayName_isURL( _rDataSource, sDisplayName, sDataSourceId );
1195cdf0e10cSrcweir             // the display name may differ from the URL for readability reasons
1196cdf0e10cSrcweir             // #i33699# - 2004-09-24 - fs@openoffice.org
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir         FilterByEntryDataId aFilter( sDataSourceId );
1199cdf0e10cSrcweir         SvLBoxEntry* pDataSource = m_pTreeView->getListBox().GetEntryPosByName( sDisplayName, NULL, &aFilter );
1200cdf0e10cSrcweir 		if ( !pDataSource ) // check if the data source name is a file location
1201cdf0e10cSrcweir 		{
1202cdf0e10cSrcweir 			if ( bIsDataSourceURL )
1203cdf0e10cSrcweir             {
1204cdf0e10cSrcweir                 // special case, the data source is a URL
1205cdf0e10cSrcweir 		        // add new entries to the list box model
1206cdf0e10cSrcweir 				implAddDatasource( _rDataSource, _rxConnection );
1207cdf0e10cSrcweir 				pDataSource = m_pTreeView->getListBox().GetEntryPosByName( sDisplayName, NULL, &aFilter );
1208cdf0e10cSrcweir                 DBG_ASSERT( pDataSource, "SbaTableQueryBrowser::getObjectEntry: hmm - did not find it again!" );
1209cdf0e10cSrcweir 			}
1210cdf0e10cSrcweir 		}
1211cdf0e10cSrcweir 		if (_ppDataSourceEntry)
1212cdf0e10cSrcweir 			// (caller wants to have it ...)
1213cdf0e10cSrcweir 			*_ppDataSourceEntry = pDataSource;
1214cdf0e10cSrcweir 
1215cdf0e10cSrcweir 		if (pDataSource)
1216cdf0e10cSrcweir 		{
1217cdf0e10cSrcweir 			// expand if required so
1218cdf0e10cSrcweir 			if (_bExpandAncestors)
1219cdf0e10cSrcweir 				m_pTreeView->getListBox().Expand(pDataSource);
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir 			// look for the object container
1222cdf0e10cSrcweir 			SvLBoxEntry* pCommandType = NULL;
1223cdf0e10cSrcweir 			switch (_nCommandType)
1224cdf0e10cSrcweir 			{
1225cdf0e10cSrcweir 				case CommandType::TABLE:
1226cdf0e10cSrcweir 					pCommandType = m_pTreeView->getListBox().GetModel()->GetEntry(pDataSource, CONTAINER_TABLES);
1227cdf0e10cSrcweir 					break;
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir 				case CommandType::QUERY:
1230cdf0e10cSrcweir 					pCommandType = m_pTreeView->getListBox().GetModel()->GetEntry(pDataSource, CONTAINER_QUERIES);
1231cdf0e10cSrcweir 					break;
1232cdf0e10cSrcweir 			}
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir 			if (_ppContainerEntry)
1235cdf0e10cSrcweir 				*_ppContainerEntry = pCommandType;
1236cdf0e10cSrcweir 
1237cdf0e10cSrcweir 			if (pCommandType)
1238cdf0e10cSrcweir 			{
1239cdf0e10cSrcweir 				// expand if required so
1240cdf0e10cSrcweir 				if (_bExpandAncestors)
1241cdf0e10cSrcweir                 {
1242cdf0e10cSrcweir 					m_pTreeView->getListBox().Expand(pCommandType);
1243cdf0e10cSrcweir                 }
1244cdf0e10cSrcweir 
1245cdf0e10cSrcweir 				// look for the object
1246cdf0e10cSrcweir                 ::rtl::OUString sCommand = _rCommand;
1247cdf0e10cSrcweir                 sal_Int32 nIndex = 0;
1248cdf0e10cSrcweir                 do
1249cdf0e10cSrcweir                 {
1250cdf0e10cSrcweir                     ::rtl::OUString sPath = sCommand.getToken( 0, '/', nIndex );
1251cdf0e10cSrcweir                     pObject = m_pTreeView->getListBox().GetEntryPosByName(sPath, pCommandType);
1252cdf0e10cSrcweir                     pCommandType = pObject;
1253cdf0e10cSrcweir                     if ( nIndex >= 0 )
1254cdf0e10cSrcweir                     {
1255cdf0e10cSrcweir                         if (ensureEntryObject(pObject))
1256cdf0e10cSrcweir                         {
1257cdf0e10cSrcweir                             DBTreeListUserData* pParentData = static_cast< DBTreeListUserData* >( pObject->GetUserData() );
1258cdf0e10cSrcweir 			                Reference< XNameAccess > xCollection( pParentData->xContainer, UNO_QUERY );
1259cdf0e10cSrcweir                             sal_Int32 nIndex2 = nIndex;
1260cdf0e10cSrcweir                             sPath = sCommand.getToken( 0, '/', nIndex2 );
1261cdf0e10cSrcweir                             try
1262cdf0e10cSrcweir 	                        {
1263cdf0e10cSrcweir 		                        if ( xCollection->hasByName(sPath) )
1264cdf0e10cSrcweir 		                        {
1265cdf0e10cSrcweir 			                        if(!m_pTreeView->getListBox().GetEntryPosByName(sPath,pObject))
1266cdf0e10cSrcweir 			                        {
1267cdf0e10cSrcweir                                         Reference<XNameAccess> xChild(xCollection->getByName(sPath),UNO_QUERY);
1268cdf0e10cSrcweir 				                        DBTreeListUserData* pEntryData = new DBTreeListUserData;
1269cdf0e10cSrcweir 				                        pEntryData->eType = etQuery;
1270cdf0e10cSrcweir                                         if ( xChild.is() )
1271cdf0e10cSrcweir                                         {
1272cdf0e10cSrcweir                                             pEntryData->eType = etQueryContainer;
1273cdf0e10cSrcweir                                         }
1274cdf0e10cSrcweir                                         implAppendEntry( pObject, sPath, pEntryData, pEntryData->eType );
1275cdf0e10cSrcweir 			                        }
1276cdf0e10cSrcweir 		                        }
1277cdf0e10cSrcweir 	                        }
1278cdf0e10cSrcweir 	                        catch(Exception&)
1279cdf0e10cSrcweir 	                        {
1280cdf0e10cSrcweir 		                        DBG_ERROR("SbaTableQueryBrowser::populateTree: could not fill the tree");
1281cdf0e10cSrcweir 	                        }
1282cdf0e10cSrcweir                         }
1283cdf0e10cSrcweir                     }
1284cdf0e10cSrcweir 					 //   m_pTreeView->getListBox().Expand(pCommandType);
1285cdf0e10cSrcweir                 }
1286cdf0e10cSrcweir                 while ( nIndex >= 0 );
1287cdf0e10cSrcweir 			}
1288cdf0e10cSrcweir 		}
1289cdf0e10cSrcweir 	}
1290cdf0e10cSrcweir 	return pObject;
1291cdf0e10cSrcweir }
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir // -------------------------------------------------------------------------
1294cdf0e10cSrcweir SvLBoxEntry* SbaTableQueryBrowser::getObjectEntry(const ::svx::ODataAccessDescriptor& _rDescriptor,
1295cdf0e10cSrcweir 		SvLBoxEntry** _ppDataSourceEntry, SvLBoxEntry** _ppContainerEntry,
1296cdf0e10cSrcweir 		sal_Bool _bExpandAncestors)
1297cdf0e10cSrcweir {
1298cdf0e10cSrcweir 	// extract the props from the descriptor
1299cdf0e10cSrcweir 	::rtl::OUString sDataSource;
1300cdf0e10cSrcweir 	::rtl::OUString sCommand;
1301cdf0e10cSrcweir 	sal_Int32 nCommandType = CommandType::COMMAND;
1302cdf0e10cSrcweir 	sal_Bool bEscapeProcessing = sal_True;
1303cdf0e10cSrcweir 	extractDescriptorProps(_rDescriptor, sDataSource, sCommand, nCommandType, bEscapeProcessing);
1304cdf0e10cSrcweir 
1305cdf0e10cSrcweir 	return getObjectEntry( sDataSource, sCommand, nCommandType, _ppDataSourceEntry, _ppContainerEntry, _bExpandAncestors, SharedConnection() );
1306cdf0e10cSrcweir }
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir // -------------------------------------------------------------------------
1309cdf0e10cSrcweir void SbaTableQueryBrowser::connectExternalDispatches()
1310cdf0e10cSrcweir {
1311cdf0e10cSrcweir 	Reference< XDispatchProvider >	xProvider( getFrame(), UNO_QUERY );
1312cdf0e10cSrcweir 	DBG_ASSERT(xProvider.is(), "SbaTableQueryBrowser::connectExternalDispatches: no DispatchProvider !");
1313cdf0e10cSrcweir 	if (xProvider.is())
1314cdf0e10cSrcweir 	{
1315cdf0e10cSrcweir         if ( m_aExternalFeatures.empty() )
1316cdf0e10cSrcweir         {
1317cdf0e10cSrcweir             const sal_Char* pURLs[] = {
1318cdf0e10cSrcweir                 ".uno:DataSourceBrowser/DocumentDataSource",
1319cdf0e10cSrcweir                 ".uno:DataSourceBrowser/FormLetter",
1320cdf0e10cSrcweir                 ".uno:DataSourceBrowser/InsertColumns",
1321cdf0e10cSrcweir                 ".uno:DataSourceBrowser/InsertContent",
1322cdf0e10cSrcweir             };
1323cdf0e10cSrcweir             const sal_uInt16 nIds[] = {
1324cdf0e10cSrcweir                 ID_BROWSER_DOCUMENT_DATASOURCE,
1325cdf0e10cSrcweir                 ID_BROWSER_FORMLETTER,
1326cdf0e10cSrcweir                 ID_BROWSER_INSERTCOLUMNS,
1327cdf0e10cSrcweir                 ID_BROWSER_INSERTCONTENT
1328cdf0e10cSrcweir             };
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir             for ( size_t i=0; i < sizeof( pURLs ) / sizeof( pURLs[0] ); ++i )
1331cdf0e10cSrcweir             {
1332cdf0e10cSrcweir 	            URL aURL;
1333cdf0e10cSrcweir                 aURL.Complete = ::rtl::OUString::createFromAscii( pURLs[i] );
1334cdf0e10cSrcweir                 if ( m_xUrlTransformer.is() )
1335cdf0e10cSrcweir 			        m_xUrlTransformer->parseStrict( aURL );
1336cdf0e10cSrcweir                 m_aExternalFeatures[ nIds[ i ] ] = ExternalFeature( aURL );
1337cdf0e10cSrcweir             }
1338cdf0e10cSrcweir         }
1339cdf0e10cSrcweir 
1340cdf0e10cSrcweir         for ( ExternalFeaturesMap::iterator feature = m_aExternalFeatures.begin();
1341cdf0e10cSrcweir               feature != m_aExternalFeatures.end();
1342cdf0e10cSrcweir               ++feature
1343cdf0e10cSrcweir             )
1344cdf0e10cSrcweir         {
1345cdf0e10cSrcweir             feature->second.xDispatcher = xProvider->queryDispatch(
1346cdf0e10cSrcweir                 feature->second.aURL, ::rtl::OUString::createFromAscii("_parent"), FrameSearchFlag::PARENT
1347cdf0e10cSrcweir             );
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir             if ( feature->second.xDispatcher.get() == static_cast< XDispatch* >( this ) )
1350cdf0e10cSrcweir             {
1351cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "SbaTableQueryBrowser::connectExternalDispatches: this should not happen anymore!" );
1352cdf0e10cSrcweir                     // (nowadays, the URLs aren't in our SupportedFeatures list anymore, so we should
1353cdf0e10cSrcweir                     // not supply a dispatcher for this)
1354cdf0e10cSrcweir                 feature->second.xDispatcher.clear();
1355cdf0e10cSrcweir             }
1356cdf0e10cSrcweir 
1357cdf0e10cSrcweir 			if ( feature->second.xDispatcher.is() )
1358cdf0e10cSrcweir 			{
1359cdf0e10cSrcweir 				try
1360cdf0e10cSrcweir 				{
1361cdf0e10cSrcweir 					feature->second.xDispatcher->addStatusListener( this, feature->second.aURL );
1362cdf0e10cSrcweir 				}
1363cdf0e10cSrcweir                 catch( const Exception& )
1364cdf0e10cSrcweir                 {
1365cdf0e10cSrcweir                     DBG_UNHANDLED_EXCEPTION();
1366cdf0e10cSrcweir                 }
1367cdf0e10cSrcweir 			}
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir 			implCheckExternalSlot( feature->first );
1370cdf0e10cSrcweir 		}
1371cdf0e10cSrcweir 	}
1372cdf0e10cSrcweir }
1373cdf0e10cSrcweir 
1374cdf0e10cSrcweir // -------------------------------------------------------------------------
1375cdf0e10cSrcweir void SbaTableQueryBrowser::implCheckExternalSlot( sal_uInt16 _nId )
1376cdf0e10cSrcweir {
1377cdf0e10cSrcweir     if ( !m_xMainToolbar.is() )
1378cdf0e10cSrcweir         return;
1379cdf0e10cSrcweir 
1380cdf0e10cSrcweir     Window* pToolboxWindow = VCLUnoHelper::GetWindow( m_xMainToolbar );
1381cdf0e10cSrcweir     ToolBox* pToolbox = dynamic_cast< ToolBox* >( pToolboxWindow );
1382cdf0e10cSrcweir     OSL_ENSURE( pToolbox, "SbaTableQueryBrowser::implCheckExternalSlot: cannot obtain the toolbox window!" );
1383cdf0e10cSrcweir 
1384cdf0e10cSrcweir     // check if we have to hide this item from the toolbox
1385cdf0e10cSrcweir 	if ( pToolbox )
1386cdf0e10cSrcweir 	{
1387cdf0e10cSrcweir 		sal_Bool bHaveDispatcher = m_aExternalFeatures[ _nId ].xDispatcher.is();
1388cdf0e10cSrcweir 		if ( bHaveDispatcher != pToolbox->IsItemVisible( _nId ) )
1389cdf0e10cSrcweir 			bHaveDispatcher ? pToolbox->ShowItem( _nId ) : pToolbox->HideItem( _nId );
1390cdf0e10cSrcweir 	}
1391cdf0e10cSrcweir 
1392cdf0e10cSrcweir     // and invalidate this feature in general
1393cdf0e10cSrcweir 	InvalidateFeature( _nId );
1394cdf0e10cSrcweir }
1395cdf0e10cSrcweir 
1396cdf0e10cSrcweir // -------------------------------------------------------------------------
1397cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::disposing( const EventObject& _rSource ) throw(RuntimeException)
1398cdf0e10cSrcweir {
1399cdf0e10cSrcweir 	// our frame ?
1400cdf0e10cSrcweir 	Reference< ::com::sun::star::frame::XFrame >  xSourceFrame(_rSource.Source, UNO_QUERY);
1401cdf0e10cSrcweir 	if (m_xCurrentFrameParent.is() && (xSourceFrame == m_xCurrentFrameParent))
1402cdf0e10cSrcweir 		m_xCurrentFrameParent->removeFrameActionListener((::com::sun::star::frame::XFrameActionListener*)this);
1403cdf0e10cSrcweir 	else
1404cdf0e10cSrcweir 	{
1405cdf0e10cSrcweir 		// search the external dispatcher causing this call in our map
1406cdf0e10cSrcweir 		Reference< XDispatch > xSource(_rSource.Source, UNO_QUERY);
1407cdf0e10cSrcweir 		if(xSource.is())
1408cdf0e10cSrcweir 		{
1409cdf0e10cSrcweir             for (  ExternalFeaturesMap::iterator aLoop = m_aExternalFeatures.begin();
1410cdf0e10cSrcweir 				  aLoop != m_aExternalFeatures.end();
1411cdf0e10cSrcweir 				  ++aLoop
1412cdf0e10cSrcweir 				)
1413cdf0e10cSrcweir 			{
1414cdf0e10cSrcweir 				if ( aLoop->second.xDispatcher.get() == xSource.get() )
1415cdf0e10cSrcweir 				{
1416cdf0e10cSrcweir                     ExternalFeaturesMap::iterator aPrevious = aLoop;
1417cdf0e10cSrcweir 					--aPrevious;
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir 					// remove it
1420cdf0e10cSrcweir 					m_aExternalFeatures.erase( aLoop );
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir 					// maybe update the UI
1423cdf0e10cSrcweir 					implCheckExternalSlot(aLoop->first);
1424cdf0e10cSrcweir 
1425cdf0e10cSrcweir 					// continue, the same XDispatch may be resposible for more than one URL
1426cdf0e10cSrcweir 					aLoop = aPrevious;
1427cdf0e10cSrcweir 				}
1428cdf0e10cSrcweir 			}
1429cdf0e10cSrcweir 		}
1430cdf0e10cSrcweir 		else
1431cdf0e10cSrcweir 		{
1432cdf0e10cSrcweir 			Reference<XConnection> xCon(_rSource.Source, UNO_QUERY);
1433cdf0e10cSrcweir 			if ( xCon.is() && m_pTreeView )
1434cdf0e10cSrcweir 			{	// our connection is in dispose so we have to find the entry equal with this connection
1435cdf0e10cSrcweir 				// and close it what means to collapse the entry
1436cdf0e10cSrcweir 				// get the top-level representing the removed data source
1437cdf0e10cSrcweir 				SvLBoxEntry* pDSLoop = m_pTreeView->getListBox().FirstChild(NULL);
1438cdf0e10cSrcweir 				while (pDSLoop)
1439cdf0e10cSrcweir 				{
1440cdf0e10cSrcweir 					DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pDSLoop->GetUserData());
1441cdf0e10cSrcweir 					if ( pData && pData->xConnection == xCon )
1442cdf0e10cSrcweir 					{
1443cdf0e10cSrcweir 						// we set the conenction to null to avoid a second disposing of the connection
1444cdf0e10cSrcweir 						pData->xConnection.clear();
1445cdf0e10cSrcweir 						closeConnection(pDSLoop,sal_False);
1446cdf0e10cSrcweir 						break;
1447cdf0e10cSrcweir 					}
1448cdf0e10cSrcweir 
1449cdf0e10cSrcweir 					pDSLoop = m_pTreeView->getListBox().NextSibling(pDSLoop);
1450cdf0e10cSrcweir 				}
1451cdf0e10cSrcweir 			}
1452cdf0e10cSrcweir 			else
1453cdf0e10cSrcweir 				SbaXDataBrowserController::disposing(_rSource);
1454cdf0e10cSrcweir 		}
1455cdf0e10cSrcweir 	}
1456cdf0e10cSrcweir }
1457cdf0e10cSrcweir 
1458cdf0e10cSrcweir // -------------------------------------------------------------------------
1459cdf0e10cSrcweir void SbaTableQueryBrowser::implRemoveStatusListeners()
1460cdf0e10cSrcweir {
1461cdf0e10cSrcweir 	// clear all old dispatches
1462cdf0e10cSrcweir     for ( ExternalFeaturesMap::const_iterator aLoop = m_aExternalFeatures.begin();
1463cdf0e10cSrcweir 		  aLoop != m_aExternalFeatures.end();
1464cdf0e10cSrcweir 		  ++aLoop
1465cdf0e10cSrcweir 		)
1466cdf0e10cSrcweir 	{
1467cdf0e10cSrcweir 		if ( aLoop->second.xDispatcher.is() )
1468cdf0e10cSrcweir 		{
1469cdf0e10cSrcweir 			try
1470cdf0e10cSrcweir 			{
1471cdf0e10cSrcweir 				aLoop->second.xDispatcher->removeStatusListener( this, aLoop->second.aURL );
1472cdf0e10cSrcweir 			}
1473cdf0e10cSrcweir 			catch (Exception&)
1474cdf0e10cSrcweir 			{
1475cdf0e10cSrcweir 				DBG_ERROR("SbaTableQueryBrowser::implRemoveStatusListeners: could not remove a status listener!");
1476cdf0e10cSrcweir 			}
1477cdf0e10cSrcweir 		}
1478cdf0e10cSrcweir 	}
1479cdf0e10cSrcweir 	m_aExternalFeatures.clear();
1480cdf0e10cSrcweir }
1481cdf0e10cSrcweir 
1482cdf0e10cSrcweir // -------------------------------------------------------------------------
1483cdf0e10cSrcweir sal_Bool SAL_CALL SbaTableQueryBrowser::select( const Any& _rSelection ) throw (IllegalArgumentException, RuntimeException)
1484cdf0e10cSrcweir {
1485cdf0e10cSrcweir 	::vos::OGuard aGuard(Application::GetSolarMutex());
1486cdf0e10cSrcweir 		// doin' a lot of VCL stuff here -> lock the SolarMutex
1487cdf0e10cSrcweir 
1488cdf0e10cSrcweir 	Sequence< PropertyValue > aDescriptorSequence;
1489cdf0e10cSrcweir 	if (!(_rSelection >>= aDescriptorSequence))
1490cdf0e10cSrcweir 		throw IllegalArgumentException(::rtl::OUString(), *this, 1);
1491cdf0e10cSrcweir 		// TODO: error message
1492cdf0e10cSrcweir 
1493cdf0e10cSrcweir 	ODataAccessDescriptor aDescriptor;
1494cdf0e10cSrcweir 	try
1495cdf0e10cSrcweir 	{
1496cdf0e10cSrcweir 		aDescriptor = ODataAccessDescriptor(aDescriptorSequence);
1497cdf0e10cSrcweir 	}
1498cdf0e10cSrcweir 	catch(const Exception&)
1499cdf0e10cSrcweir 	{
1500cdf0e10cSrcweir 		OSL_ENSURE(sal_False, "SbaTableQueryBrowser::select: could not extract the descriptor!");
1501cdf0e10cSrcweir 	}
1502cdf0e10cSrcweir 
1503cdf0e10cSrcweir 	// check the precense of the props we need
1504cdf0e10cSrcweir 	if ( !(aDescriptor.has(daDataSource) || aDescriptor.has(daDatabaseLocation)) || !aDescriptor.has(daCommand) || !aDescriptor.has(daCommandType))
1505cdf0e10cSrcweir 		throw IllegalArgumentException(::rtl::OUString(), *this, 1);
1506cdf0e10cSrcweir 		// TODO: error message
1507cdf0e10cSrcweir 
1508cdf0e10cSrcweir 	return implSelect(aDescriptor,sal_True);
1509cdf0e10cSrcweir }
1510cdf0e10cSrcweir 
1511cdf0e10cSrcweir // -------------------------------------------------------------------------
1512cdf0e10cSrcweir Any SAL_CALL SbaTableQueryBrowser::getSelection(  ) throw (RuntimeException)
1513cdf0e10cSrcweir {
1514cdf0e10cSrcweir 	Any aReturn;
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir 	try
1517cdf0e10cSrcweir 	{
1518cdf0e10cSrcweir 		Reference< XLoadable > xLoadable(getRowSet(), UNO_QUERY);
1519cdf0e10cSrcweir 		if (xLoadable.is() && xLoadable->isLoaded())
1520cdf0e10cSrcweir 		{
1521cdf0e10cSrcweir 			Reference< XPropertySet > aFormProps(getRowSet(), UNO_QUERY);
1522cdf0e10cSrcweir 			ODataAccessDescriptor aDescriptor(aFormProps);
1523cdf0e10cSrcweir 			// remove properties which are not part of our "selection"
1524cdf0e10cSrcweir 			aDescriptor.erase(daConnection);
1525cdf0e10cSrcweir 			aDescriptor.erase(daCursor);
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir 			aReturn <<= aDescriptor.createPropertyValueSequence();
1528cdf0e10cSrcweir 		}
1529cdf0e10cSrcweir 	}
1530cdf0e10cSrcweir     catch( const Exception& )
1531cdf0e10cSrcweir     {
1532cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
1533cdf0e10cSrcweir     }
1534cdf0e10cSrcweir 
1535cdf0e10cSrcweir 	return aReturn;
1536cdf0e10cSrcweir }
1537cdf0e10cSrcweir 
1538cdf0e10cSrcweir // -------------------------------------------------------------------------
1539cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::addSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException)
1540cdf0e10cSrcweir {
1541cdf0e10cSrcweir 	m_aSelectionListeners.addInterface(_rxListener);
1542cdf0e10cSrcweir }
1543cdf0e10cSrcweir 
1544cdf0e10cSrcweir // -------------------------------------------------------------------------
1545cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException)
1546cdf0e10cSrcweir {
1547cdf0e10cSrcweir 	m_aSelectionListeners.removeInterface(_rxListener);
1548cdf0e10cSrcweir }
1549cdf0e10cSrcweir 
1550cdf0e10cSrcweir // -------------------------------------------------------------------------
1551cdf0e10cSrcweir void SbaTableQueryBrowser::attachFrame(const Reference< ::com::sun::star::frame::XFrame > & _xFrame) throw( RuntimeException )
1552cdf0e10cSrcweir {
1553cdf0e10cSrcweir 	implRemoveStatusListeners();
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir 	if (m_xCurrentFrameParent.is())
1556cdf0e10cSrcweir 		m_xCurrentFrameParent->removeFrameActionListener((::com::sun::star::frame::XFrameActionListener*)this);
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir 	SbaXDataBrowserController::attachFrame(_xFrame);
1559cdf0e10cSrcweir 
1560cdf0e10cSrcweir     Reference< XFrame > xCurrentFrame( getFrame() );
1561cdf0e10cSrcweir 	if ( xCurrentFrame.is() )
1562cdf0e10cSrcweir 	{
1563cdf0e10cSrcweir 		m_xCurrentFrameParent = xCurrentFrame->findFrame(::rtl::OUString::createFromAscii("_parent"),FrameSearchFlag::PARENT);
1564cdf0e10cSrcweir 		if ( m_xCurrentFrameParent.is() )
1565cdf0e10cSrcweir 			m_xCurrentFrameParent->addFrameActionListener((::com::sun::star::frame::XFrameActionListener*)this);
1566cdf0e10cSrcweir 
1567cdf0e10cSrcweir         // obtain our toolbox
1568cdf0e10cSrcweir         try
1569cdf0e10cSrcweir         {
1570cdf0e10cSrcweir             Reference< XPropertySet > xFrameProps( m_aCurrentFrame.getFrame(), UNO_QUERY_THROW );
1571cdf0e10cSrcweir             Reference< XLayoutManager > xLayouter(
1572cdf0e10cSrcweir                 xFrameProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ) ),
1573cdf0e10cSrcweir                 UNO_QUERY );
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir             if ( xLayouter.is() )
1576cdf0e10cSrcweir             {
1577cdf0e10cSrcweir 			    Reference< XUIElement > xUI(
1578cdf0e10cSrcweir                     xLayouter->getElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/toolbar" ) ) ),
1579cdf0e10cSrcweir                     UNO_SET_THROW );
1580cdf0e10cSrcweir                 m_xMainToolbar = m_xMainToolbar.query( xUI->getRealInterface() );
1581cdf0e10cSrcweir                 OSL_ENSURE( m_xMainToolbar.is(), "SbaTableQueryBrowser::attachFrame: where's my toolbox?" );
1582cdf0e10cSrcweir             }
1583cdf0e10cSrcweir         }
1584cdf0e10cSrcweir         catch( const Exception& )
1585cdf0e10cSrcweir         {
1586cdf0e10cSrcweir     	    DBG_UNHANDLED_EXCEPTION();
1587cdf0e10cSrcweir         }
1588cdf0e10cSrcweir 	}
1589cdf0e10cSrcweir 
1590cdf0e10cSrcweir 	// get the dispatchers for the external slots
1591cdf0e10cSrcweir 	connectExternalDispatches();
1592cdf0e10cSrcweir }
1593cdf0e10cSrcweir 
1594cdf0e10cSrcweir // -------------------------------------------------------------------------
1595cdf0e10cSrcweir void SbaTableQueryBrowser::addModelListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
1596cdf0e10cSrcweir {
1597cdf0e10cSrcweir 	SbaXDataBrowserController::addModelListeners(_xGridControlModel);
1598cdf0e10cSrcweir 	Reference< XPropertySet >  xSourceSet(_xGridControlModel, UNO_QUERY);
1599cdf0e10cSrcweir 	if (xSourceSet.is())
1600cdf0e10cSrcweir 	{
1601cdf0e10cSrcweir 		xSourceSet->addPropertyChangeListener(PROPERTY_ROW_HEIGHT, static_cast<XPropertyChangeListener*>(this));
1602cdf0e10cSrcweir 		xSourceSet->addPropertyChangeListener(PROPERTY_FONT, static_cast<XPropertyChangeListener*>(this));
1603cdf0e10cSrcweir 		xSourceSet->addPropertyChangeListener(PROPERTY_TEXTCOLOR, static_cast<XPropertyChangeListener*>(this));
1604cdf0e10cSrcweir 		xSourceSet->addPropertyChangeListener(PROPERTY_TEXTLINECOLOR, static_cast<XPropertyChangeListener*>(this));
1605cdf0e10cSrcweir 		xSourceSet->addPropertyChangeListener(PROPERTY_TEXTEMPHASIS, static_cast<XPropertyChangeListener*>(this));
1606cdf0e10cSrcweir 		xSourceSet->addPropertyChangeListener(PROPERTY_TEXTRELIEF, static_cast<XPropertyChangeListener*>(this));
1607cdf0e10cSrcweir 	}
1608cdf0e10cSrcweir 
1609cdf0e10cSrcweir }
1610cdf0e10cSrcweir 
1611cdf0e10cSrcweir // -------------------------------------------------------------------------
1612cdf0e10cSrcweir void SbaTableQueryBrowser::removeModelListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
1613cdf0e10cSrcweir {
1614cdf0e10cSrcweir 	SbaXDataBrowserController::removeModelListeners(_xGridControlModel);
1615cdf0e10cSrcweir 	Reference< XPropertySet >  xSourceSet(_xGridControlModel, UNO_QUERY);
1616cdf0e10cSrcweir 	if (xSourceSet.is())
1617cdf0e10cSrcweir 	{
1618cdf0e10cSrcweir 		xSourceSet->removePropertyChangeListener(PROPERTY_ROW_HEIGHT, static_cast<XPropertyChangeListener*>(this));
1619cdf0e10cSrcweir 		xSourceSet->removePropertyChangeListener(PROPERTY_FONT, static_cast<XPropertyChangeListener*>(this));
1620cdf0e10cSrcweir 		xSourceSet->removePropertyChangeListener(PROPERTY_TEXTCOLOR, static_cast<XPropertyChangeListener*>(this));
1621cdf0e10cSrcweir 		xSourceSet->removePropertyChangeListener(PROPERTY_TEXTLINECOLOR, static_cast<XPropertyChangeListener*>(this));
1622cdf0e10cSrcweir 		xSourceSet->removePropertyChangeListener(PROPERTY_TEXTEMPHASIS, static_cast<XPropertyChangeListener*>(this));
1623cdf0e10cSrcweir 		xSourceSet->removePropertyChangeListener(PROPERTY_TEXTRELIEF, static_cast<XPropertyChangeListener*>(this));
1624cdf0e10cSrcweir 	}
1625cdf0e10cSrcweir }
1626cdf0e10cSrcweir // -------------------------------------------------------------------------
1627cdf0e10cSrcweir void SbaTableQueryBrowser::RowChanged()
1628cdf0e10cSrcweir {
1629cdf0e10cSrcweir 	if(getBrowserView())
1630cdf0e10cSrcweir 	{
1631cdf0e10cSrcweir 		SbaGridControl* pControl = getBrowserView()->getVclControl();
1632cdf0e10cSrcweir 		if (!pControl->IsEditing())
1633cdf0e10cSrcweir 			InvalidateFeature(ID_BROWSER_COPY);
1634cdf0e10cSrcweir 	}
1635cdf0e10cSrcweir 	SbaXDataBrowserController::RowChanged();
1636cdf0e10cSrcweir }
1637cdf0e10cSrcweir 
1638cdf0e10cSrcweir // -------------------------------------------------------------------------
1639cdf0e10cSrcweir void SbaTableQueryBrowser::ColumnChanged()
1640cdf0e10cSrcweir {
1641cdf0e10cSrcweir 	if(getBrowserView())
1642cdf0e10cSrcweir 	{
1643cdf0e10cSrcweir 		SbaGridControl* pControl = getBrowserView()->getVclControl();
1644cdf0e10cSrcweir 		if (!pControl->IsEditing())
1645cdf0e10cSrcweir 			InvalidateFeature(ID_BROWSER_COPY);
1646cdf0e10cSrcweir 	}
1647cdf0e10cSrcweir 	SbaXDataBrowserController::ColumnChanged();
1648cdf0e10cSrcweir }
1649cdf0e10cSrcweir //------------------------------------------------------------------------------
1650cdf0e10cSrcweir void SbaTableQueryBrowser::AddColumnListener(const Reference< XPropertySet > & xCol)
1651cdf0e10cSrcweir {
1652cdf0e10cSrcweir 	SbaXDataBrowserController::AddColumnListener(xCol);
1653cdf0e10cSrcweir 	SafeAddPropertyListener(xCol, PROPERTY_WIDTH, static_cast<XPropertyChangeListener*>(this));
1654cdf0e10cSrcweir 	SafeAddPropertyListener(xCol, PROPERTY_HIDDEN, static_cast<XPropertyChangeListener*>(this));
1655cdf0e10cSrcweir 	SafeAddPropertyListener(xCol, PROPERTY_ALIGN, static_cast<XPropertyChangeListener*>(this));
1656cdf0e10cSrcweir 	SafeAddPropertyListener(xCol, PROPERTY_FORMATKEY, static_cast<XPropertyChangeListener*>(this));
1657cdf0e10cSrcweir }
1658cdf0e10cSrcweir 
1659cdf0e10cSrcweir //------------------------------------------------------------------------------
1660cdf0e10cSrcweir void SbaTableQueryBrowser::RemoveColumnListener(const Reference< XPropertySet > & xCol)
1661cdf0e10cSrcweir {
1662cdf0e10cSrcweir 	SbaXDataBrowserController::RemoveColumnListener(xCol);
1663cdf0e10cSrcweir 	SafeRemovePropertyListener(xCol, PROPERTY_WIDTH, static_cast<XPropertyChangeListener*>(this));
1664cdf0e10cSrcweir 	SafeRemovePropertyListener(xCol, PROPERTY_HIDDEN, static_cast<XPropertyChangeListener*>(this));
1665cdf0e10cSrcweir 	SafeRemovePropertyListener(xCol, PROPERTY_ALIGN, static_cast<XPropertyChangeListener*>(this));
1666cdf0e10cSrcweir 	SafeRemovePropertyListener(xCol, PROPERTY_FORMATKEY, static_cast<XPropertyChangeListener*>(this));
1667cdf0e10cSrcweir }
1668cdf0e10cSrcweir 
1669cdf0e10cSrcweir //------------------------------------------------------------------------------
1670cdf0e10cSrcweir void SbaTableQueryBrowser::criticalFail()
1671cdf0e10cSrcweir {
1672cdf0e10cSrcweir 	SbaXDataBrowserController::criticalFail();
1673cdf0e10cSrcweir 	unloadAndCleanup( sal_False );
1674cdf0e10cSrcweir }
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir //------------------------------------------------------------------------------
1677cdf0e10cSrcweir void SbaTableQueryBrowser::LoadFinished(sal_Bool _bWasSynch)
1678cdf0e10cSrcweir {
1679cdf0e10cSrcweir 	SbaXDataBrowserController::LoadFinished(_bWasSynch);
1680cdf0e10cSrcweir 
1681cdf0e10cSrcweir 	m_sQueryCommand = ::rtl::OUString();
1682cdf0e10cSrcweir 	m_bQueryEscapeProcessing = sal_False;
1683cdf0e10cSrcweir 
1684cdf0e10cSrcweir 	if (isValid() && !loadingCancelled())
1685cdf0e10cSrcweir 	{
1686cdf0e10cSrcweir 		// did we load a query?
1687cdf0e10cSrcweir 		sal_Bool bTemporary;	// needed because we m_bQueryEscapeProcessing is only one bit wide (and we want to pass it by reference)
1688cdf0e10cSrcweir 		if ( implGetQuerySignature( m_sQueryCommand, bTemporary ) )
1689cdf0e10cSrcweir 			m_bQueryEscapeProcessing = bTemporary;
1690cdf0e10cSrcweir 	}
1691cdf0e10cSrcweir 
1692cdf0e10cSrcweir 	// if the form has been loaded, this means that our "selection" has changed
1693cdf0e10cSrcweir 	EventObject aEvent( *this );
1694cdf0e10cSrcweir     m_aSelectionListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aEvent );
1695cdf0e10cSrcweir }
1696cdf0e10cSrcweir 
1697cdf0e10cSrcweir //------------------------------------------------------------------------------
1698cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::getExternalSlotState( sal_uInt16 _nId ) const
1699cdf0e10cSrcweir {
1700cdf0e10cSrcweir 	sal_Bool bEnabled = sal_False;
1701cdf0e10cSrcweir 	ExternalFeaturesMap::const_iterator aPos = m_aExternalFeatures.find( _nId );
1702cdf0e10cSrcweir 	if ( ( m_aExternalFeatures.end() != aPos ) && aPos->second.xDispatcher.is() )
1703cdf0e10cSrcweir 		bEnabled = aPos->second.bEnabled;
1704cdf0e10cSrcweir 	return bEnabled;
1705cdf0e10cSrcweir }
1706cdf0e10cSrcweir 
1707cdf0e10cSrcweir //------------------------------------------------------------------------------
1708cdf0e10cSrcweir FeatureState SbaTableQueryBrowser::GetState(sal_uInt16 nId) const
1709cdf0e10cSrcweir {
1710cdf0e10cSrcweir 	FeatureState aReturn;
1711cdf0e10cSrcweir 		// (disabled automatically)
1712cdf0e10cSrcweir 
1713cdf0e10cSrcweir 	// no chance without a view
1714cdf0e10cSrcweir 	if (!getBrowserView() || !getBrowserView()->getVclControl())
1715cdf0e10cSrcweir 		return aReturn;
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir 	switch ( nId )
1718cdf0e10cSrcweir 	{
1719cdf0e10cSrcweir         case ID_TREE_ADMINISTRATE:
1720cdf0e10cSrcweir 			aReturn.bEnabled = true;
1721cdf0e10cSrcweir 			return aReturn;
1722cdf0e10cSrcweir 
1723cdf0e10cSrcweir 		case ID_BROWSER_CLOSE:
1724cdf0e10cSrcweir 			// the close button should always be enabled
1725cdf0e10cSrcweir 			aReturn.bEnabled = !m_bEnableBrowser;
1726cdf0e10cSrcweir 			return aReturn;
1727cdf0e10cSrcweir 
1728cdf0e10cSrcweir             // "toggle explorer" is always enabled (if we have a explorer)
1729cdf0e10cSrcweir 		case ID_BROWSER_EXPLORER:
1730cdf0e10cSrcweir 			aReturn.bEnabled = m_bEnableBrowser;
1731cdf0e10cSrcweir 			aReturn.bChecked = haveExplorer();
1732cdf0e10cSrcweir 			return aReturn;
1733cdf0e10cSrcweir 
1734cdf0e10cSrcweir 		case ID_BROWSER_REMOVEFILTER:
1735cdf0e10cSrcweir 			return SbaXDataBrowserController::GetState( nId );
1736cdf0e10cSrcweir 
1737cdf0e10cSrcweir         case ID_BROWSER_COPY:
1738cdf0e10cSrcweir             if ( !m_pTreeView->HasChildPathFocus() )
1739cdf0e10cSrcweir                 // handled below
1740cdf0e10cSrcweir                 break;
1741cdf0e10cSrcweir             // NO break!
1742cdf0e10cSrcweir         case ID_TREE_CLOSE_CONN:
1743cdf0e10cSrcweir         case ID_TREE_EDIT_DATABASE:
1744cdf0e10cSrcweir         {
1745cdf0e10cSrcweir             SvLBoxEntry* pCurrentEntry( m_pTreeView->getListBox().GetCurEntry() );
1746cdf0e10cSrcweir             EntryType eType = getEntryType( pCurrentEntry );
1747cdf0e10cSrcweir             if ( eType == etUnknown )
1748cdf0e10cSrcweir                 return aReturn;
1749cdf0e10cSrcweir 
1750cdf0e10cSrcweir             SvLBoxEntry* pDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent( pCurrentEntry );
1751cdf0e10cSrcweir             DBTreeListUserData* pDSData
1752cdf0e10cSrcweir                 =   pDataSourceEntry
1753cdf0e10cSrcweir                 ?	static_cast< DBTreeListUserData* >( pDataSourceEntry->GetUserData() )
1754cdf0e10cSrcweir                 :	NULL;
1755cdf0e10cSrcweir 
1756cdf0e10cSrcweir             if ( nId == ID_TREE_CLOSE_CONN )
1757cdf0e10cSrcweir             {
1758cdf0e10cSrcweir                 aReturn.bEnabled = ( pDSData != NULL ) && pDSData->xConnection.is();
1759cdf0e10cSrcweir             }
1760cdf0e10cSrcweir             else if ( nId == ID_TREE_EDIT_DATABASE )
1761cdf0e10cSrcweir             {
1762cdf0e10cSrcweir                 ::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithServiceFactory( getORB(),
1763cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.DataAccess/Policies/Features/Common" ) ) ) );
1764cdf0e10cSrcweir                 sal_Bool bHaveEditDatabase( sal_True );
1765cdf0e10cSrcweir                 OSL_VERIFY( aConfig.getNodeValue( "EditDatabaseFromDataSourceView" ) >>= bHaveEditDatabase );
1766cdf0e10cSrcweir                 aReturn.bEnabled = getORB().is() && ( pDataSourceEntry != NULL ) && bHaveEditDatabase;
1767cdf0e10cSrcweir             }
1768cdf0e10cSrcweir             else if ( nId == ID_BROWSER_COPY )
1769cdf0e10cSrcweir             {
1770cdf0e10cSrcweir                 aReturn.bEnabled = isEntryCopyAllowed( pCurrentEntry );
1771cdf0e10cSrcweir             }
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir             return aReturn;
1774cdf0e10cSrcweir         }
1775cdf0e10cSrcweir 	}
1776cdf0e10cSrcweir 
1777cdf0e10cSrcweir     // all slots not handled above are not available if no form is loaded
1778cdf0e10cSrcweir 	if (!isLoaded())
1779cdf0e10cSrcweir 		return aReturn;
1780cdf0e10cSrcweir 
1781cdf0e10cSrcweir 	try
1782cdf0e10cSrcweir 	{
1783cdf0e10cSrcweir 		sal_Bool bHandled = sal_False;
1784cdf0e10cSrcweir 		switch (nId)
1785cdf0e10cSrcweir 		{
1786cdf0e10cSrcweir 			case ID_BROWSER_DOCUMENT_DATASOURCE:
1787cdf0e10cSrcweir 				// the slot is enabled if we have an external dispatcher able to handle it,
1788cdf0e10cSrcweir 				// and the dispatcher must have enabled the slot in general
1789cdf0e10cSrcweir 				aReturn.bEnabled = getExternalSlotState( ID_BROWSER_DOCUMENT_DATASOURCE );
1790cdf0e10cSrcweir 				bHandled = sal_True;
1791cdf0e10cSrcweir 				break;
1792cdf0e10cSrcweir 			case ID_BROWSER_REFRESH:
1793cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
1794cdf0e10cSrcweir 				bHandled = sal_True;
1795cdf0e10cSrcweir 				break;
1796cdf0e10cSrcweir 		}
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir 		if (bHandled)
1799cdf0e10cSrcweir 			return aReturn;
1800cdf0e10cSrcweir 
1801cdf0e10cSrcweir 		// no chance without valid models
1802cdf0e10cSrcweir 		if (isValid() && !isValidCursor() && nId != ID_BROWSER_CLOSE)
1803cdf0e10cSrcweir 			return aReturn;
1804cdf0e10cSrcweir 
1805cdf0e10cSrcweir 		switch (nId)
1806cdf0e10cSrcweir 		{
1807cdf0e10cSrcweir 			case ID_BROWSER_INSERTCOLUMNS:
1808cdf0e10cSrcweir 			case ID_BROWSER_INSERTCONTENT:
1809cdf0e10cSrcweir 			case ID_BROWSER_FORMLETTER:
1810cdf0e10cSrcweir 			{
1811cdf0e10cSrcweir 				// the slot is enabled if we have an external dispatcher able to handle it,
1812cdf0e10cSrcweir 				// and the dispatcher must have enabled the slot in general
1813cdf0e10cSrcweir 				aReturn.bEnabled = getExternalSlotState( nId );
1814cdf0e10cSrcweir 
1815cdf0e10cSrcweir 				// for the Insert* slots, we need at least one selected row
1816cdf0e10cSrcweir 				if (ID_BROWSER_FORMLETTER != nId)
1817cdf0e10cSrcweir 					aReturn.bEnabled = aReturn.bEnabled && getBrowserView()->getVclControl()->GetSelectRowCount();
1818cdf0e10cSrcweir 
1819cdf0e10cSrcweir 				// disabled for native queries which are not saved within the database
1820cdf0e10cSrcweir 				// 67706 - 23.08.99 - FS
1821cdf0e10cSrcweir 				Reference< XPropertySet >  xDataSource(getRowSet(), UNO_QUERY);
1822cdf0e10cSrcweir 				try
1823cdf0e10cSrcweir 				{
1824cdf0e10cSrcweir 					aReturn.bEnabled = aReturn.bEnabled && xDataSource.is();
1825cdf0e10cSrcweir 
1826cdf0e10cSrcweir 					if (xDataSource.is())
1827cdf0e10cSrcweir 					{
1828cdf0e10cSrcweir 						sal_Int32 nType = ::comphelper::getINT32(xDataSource->getPropertyValue(PROPERTY_COMMAND_TYPE));
1829cdf0e10cSrcweir 						aReturn.bEnabled = aReturn.bEnabled && ((::comphelper::getBOOL(xDataSource->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || (nType == ::com::sun::star::sdb::CommandType::QUERY)));
1830cdf0e10cSrcweir 					}
1831cdf0e10cSrcweir 				}
1832cdf0e10cSrcweir 				catch(DisposedException&)
1833cdf0e10cSrcweir 				{
1834cdf0e10cSrcweir 					OSL_ENSURE(sal_False, "SbaTableQueryBrowser::GetState: object already disposed!");
1835cdf0e10cSrcweir 				}
1836cdf0e10cSrcweir                 catch( const Exception& )
1837cdf0e10cSrcweir                 {
1838cdf0e10cSrcweir                     DBG_UNHANDLED_EXCEPTION();
1839cdf0e10cSrcweir                 }
1840cdf0e10cSrcweir 			}
1841cdf0e10cSrcweir 			break;
1842cdf0e10cSrcweir 
1843cdf0e10cSrcweir             case ID_BROWSER_TITLE:
1844cdf0e10cSrcweir 				{
1845cdf0e10cSrcweir 					Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
1846cdf0e10cSrcweir 					sal_Int32 nCommandType = CommandType::TABLE;
1847cdf0e10cSrcweir 					xProp->getPropertyValue(PROPERTY_COMMAND_TYPE) >>= nCommandType;
1848cdf0e10cSrcweir 					String sTitle;
1849cdf0e10cSrcweir 					switch (nCommandType)
1850cdf0e10cSrcweir 					{
1851cdf0e10cSrcweir 						case CommandType::TABLE:
1852cdf0e10cSrcweir 							sTitle = String(ModuleRes(STR_TBL_TITLE)); break;
1853cdf0e10cSrcweir 						case CommandType::QUERY:
1854cdf0e10cSrcweir 						case CommandType::COMMAND:
1855cdf0e10cSrcweir 							sTitle = String(ModuleRes(STR_QRY_TITLE)); break;
1856cdf0e10cSrcweir 						default:
1857cdf0e10cSrcweir 							DBG_ASSERT(sal_False, "SbaTableQueryBrowser::GetState: unknown command type!");
1858cdf0e10cSrcweir 					}
1859cdf0e10cSrcweir 					::rtl::OUString aName;
1860cdf0e10cSrcweir 					xProp->getPropertyValue(PROPERTY_COMMAND) >>= aName;
1861cdf0e10cSrcweir 					String sObject(aName.getStr());
1862cdf0e10cSrcweir 
1863cdf0e10cSrcweir 					sTitle.SearchAndReplace('#',sObject);
1864cdf0e10cSrcweir 					aReturn.sTitle = sTitle;
1865cdf0e10cSrcweir 					aReturn.bEnabled = sal_True;
1866cdf0e10cSrcweir 				}
1867cdf0e10cSrcweir 				break;
1868cdf0e10cSrcweir 			case ID_BROWSER_TABLEATTR:
1869cdf0e10cSrcweir 			case ID_BROWSER_ROWHEIGHT:
1870cdf0e10cSrcweir 			case ID_BROWSER_COLATTRSET:
1871cdf0e10cSrcweir 			case ID_BROWSER_COLWIDTH:
1872cdf0e10cSrcweir 				aReturn.bEnabled = getBrowserView() && getBrowserView()->getVclControl() && isValid() && isValidCursor();
1873cdf0e10cSrcweir 				//	aReturn.bEnabled &= getDefinition() && !getDefinition()->GetDatabase()->IsReadOnly();
1874cdf0e10cSrcweir 				break;
1875cdf0e10cSrcweir 
1876cdf0e10cSrcweir 			case ID_BROWSER_COPY:
1877cdf0e10cSrcweir                 OSL_ENSURE( !m_pTreeView->HasChildPathFocus(), "SbaTableQueryBrowser::GetState( ID_BROWSER_COPY ): this should have been handled above!" );
1878cdf0e10cSrcweir 				if (getBrowserView() && getBrowserView()->getVclControl() && !getBrowserView()->getVclControl()->IsEditing())
1879cdf0e10cSrcweir 				{
1880cdf0e10cSrcweir                     SbaGridControl* pControl = getBrowserView()->getVclControl();
1881cdf0e10cSrcweir                     if ( pControl->GetSelectRowCount() )
1882cdf0e10cSrcweir                     {
1883cdf0e10cSrcweir                         aReturn.bEnabled = m_aCurrentFrame.isActive();
1884cdf0e10cSrcweir                         break;
1885cdf0e10cSrcweir                     } // if ( getBrowserView()->getVclControl()->GetSelectRowCount() )
1886cdf0e10cSrcweir                     else
1887cdf0e10cSrcweir 					    aReturn.bEnabled = pControl->canCopyCellText(pControl->GetCurRow(), pControl->GetCurColumnId());
1888cdf0e10cSrcweir                     break;
1889cdf0e10cSrcweir 				}
1890cdf0e10cSrcweir                 // NO break here
1891cdf0e10cSrcweir 			default:
1892cdf0e10cSrcweir 				return SbaXDataBrowserController::GetState(nId);
1893cdf0e10cSrcweir 		}
1894cdf0e10cSrcweir 	}
1895cdf0e10cSrcweir 	catch(const Exception&)
1896cdf0e10cSrcweir 	{
1897cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
1898cdf0e10cSrcweir 	}
1899cdf0e10cSrcweir 
1900cdf0e10cSrcweir 	return aReturn;
1901cdf0e10cSrcweir 
1902cdf0e10cSrcweir }
1903cdf0e10cSrcweir 
1904cdf0e10cSrcweir //------------------------------------------------------------------------------
1905cdf0e10cSrcweir void SbaTableQueryBrowser::Execute(sal_uInt16 nId, const Sequence< PropertyValue >& aArgs)
1906cdf0e10cSrcweir {
1907cdf0e10cSrcweir 	switch (nId)
1908cdf0e10cSrcweir 	{
1909cdf0e10cSrcweir 		default:
1910cdf0e10cSrcweir 			SbaXDataBrowserController::Execute(nId,aArgs);
1911cdf0e10cSrcweir 			break;
1912cdf0e10cSrcweir 
1913cdf0e10cSrcweir 		case ID_TREE_EDIT_DATABASE:
1914cdf0e10cSrcweir             implAdministrate( m_pTreeView->getListBox().GetCurEntry() );
1915cdf0e10cSrcweir 			break;
1916cdf0e10cSrcweir 
1917cdf0e10cSrcweir         case ID_TREE_CLOSE_CONN:
1918cdf0e10cSrcweir             openHelpAgent( HID_DSBROWSER_DISCONNECTING );
1919cdf0e10cSrcweir             closeConnection( m_pTreeView->getListBox().GetRootLevelParent( m_pTreeView->getListBox().GetCurEntry() ) );
1920cdf0e10cSrcweir             break;
1921cdf0e10cSrcweir 
1922cdf0e10cSrcweir         case ID_TREE_ADMINISTRATE:
1923cdf0e10cSrcweir             ::svx::administrateDatabaseRegistration( getView() );
1924cdf0e10cSrcweir             break;
1925cdf0e10cSrcweir 
1926cdf0e10cSrcweir         case ID_BROWSER_REFRESH:
1927cdf0e10cSrcweir 		{
1928cdf0e10cSrcweir 			if ( !SaveModified( ) )
1929cdf0e10cSrcweir 				// nothing to do
1930cdf0e10cSrcweir 				break;
1931cdf0e10cSrcweir 
1932cdf0e10cSrcweir 			sal_Bool bFullReinit = sal_False;
1933cdf0e10cSrcweir 			// check if the query signature (if the form is based on a query) has changed
1934cdf0e10cSrcweir 			if ( m_sQueryCommand.getLength() )
1935cdf0e10cSrcweir 			{
1936cdf0e10cSrcweir 				::rtl::OUString sNewQueryCommand;
1937cdf0e10cSrcweir 				sal_Bool bNewQueryEP;
1938cdf0e10cSrcweir 
1939cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1940cdf0e10cSrcweir 				sal_Bool bIsQuery =
1941cdf0e10cSrcweir #endif
1942cdf0e10cSrcweir 				implGetQuerySignature( sNewQueryCommand, bNewQueryEP );
1943cdf0e10cSrcweir 				OSL_ENSURE( bIsQuery, "SbaTableQueryBrowser::Execute: was a query before, but is not anymore?" );
1944cdf0e10cSrcweir 
1945cdf0e10cSrcweir 				bFullReinit = ( sNewQueryCommand != m_sQueryCommand ) || ( m_bQueryEscapeProcessing != bNewQueryEP );
1946cdf0e10cSrcweir 			}
1947cdf0e10cSrcweir 			if ( !bFullReinit )
1948cdf0e10cSrcweir 			{
1949cdf0e10cSrcweir 				// let the base class do a simple reload
1950cdf0e10cSrcweir 				SbaXDataBrowserController::Execute(nId,aArgs);
1951cdf0e10cSrcweir 				break;
1952cdf0e10cSrcweir 			}
1953cdf0e10cSrcweir 			// NO break here!
1954cdf0e10cSrcweir 		}
1955cdf0e10cSrcweir 
1956cdf0e10cSrcweir 		case ID_BROWSER_REFRESH_REBUILD:
1957cdf0e10cSrcweir 		{
1958cdf0e10cSrcweir 			if ( !SaveModified() )
1959cdf0e10cSrcweir 				// nothing to do
1960cdf0e10cSrcweir 				break;
1961cdf0e10cSrcweir 
1962cdf0e10cSrcweir 			SvLBoxEntry* pSelected = m_pCurrentlyDisplayed;
1963cdf0e10cSrcweir 			// unload
1964cdf0e10cSrcweir 			unloadAndCleanup( sal_False );
1965cdf0e10cSrcweir 
1966cdf0e10cSrcweir 			// reselect the entry
1967cdf0e10cSrcweir 			if ( pSelected )
1968cdf0e10cSrcweir             {
1969cdf0e10cSrcweir 				implSelect( pSelected );
1970cdf0e10cSrcweir             }
1971cdf0e10cSrcweir 			else
1972cdf0e10cSrcweir 			{
1973cdf0e10cSrcweir 				Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
1974cdf0e10cSrcweir 				implSelect(::svx::ODataAccessDescriptor(xProp));
1975cdf0e10cSrcweir 			}
1976cdf0e10cSrcweir 		}
1977cdf0e10cSrcweir 		break;
1978cdf0e10cSrcweir 
1979cdf0e10cSrcweir 		case ID_BROWSER_EXPLORER:
1980cdf0e10cSrcweir 			toggleExplorer();
1981cdf0e10cSrcweir 			break;
1982cdf0e10cSrcweir 
1983cdf0e10cSrcweir 		case ID_BROWSER_DOCUMENT_DATASOURCE:
1984cdf0e10cSrcweir 			implSelect(m_aDocumentDataSource);
1985cdf0e10cSrcweir 			break;
1986cdf0e10cSrcweir 
1987cdf0e10cSrcweir 		case ID_BROWSER_INSERTCOLUMNS:
1988cdf0e10cSrcweir 		case ID_BROWSER_INSERTCONTENT:
1989cdf0e10cSrcweir 		case ID_BROWSER_FORMLETTER:
1990cdf0e10cSrcweir 			if (getBrowserView() && isValidCursor())
1991cdf0e10cSrcweir 			{
1992cdf0e10cSrcweir 				// the URL the slot id is assigned to
1993cdf0e10cSrcweir                 OSL_ENSURE( m_aExternalFeatures.find( nId ) != m_aExternalFeatures.end(),
1994cdf0e10cSrcweir                     "SbaTableQueryBrowser::Execute( ID_BROWSER_?): how could this ever be enabled?" );
1995cdf0e10cSrcweir 				URL aParentUrl = m_aExternalFeatures[ nId ].aURL;
1996cdf0e10cSrcweir 
1997cdf0e10cSrcweir 				// let the dispatcher execute the slot
1998cdf0e10cSrcweir 				Reference< XDispatch > xDispatch( m_aExternalFeatures[ nId ].xDispatcher );
1999cdf0e10cSrcweir 				if (xDispatch.is())
2000cdf0e10cSrcweir 				{
2001cdf0e10cSrcweir 					// set the properties for the dispatch
2002cdf0e10cSrcweir 
2003cdf0e10cSrcweir 					// first fill the selection
2004cdf0e10cSrcweir 					SbaGridControl* pGrid = getBrowserView()->getVclControl();
2005cdf0e10cSrcweir 					MultiSelection* pSelection = (MultiSelection*)pGrid->GetSelection();
2006cdf0e10cSrcweir 					Sequence< Any > aSelection;
2007cdf0e10cSrcweir 					if ( !pGrid->IsAllSelected() )
2008cdf0e10cSrcweir 					{	// transfer the selected rows only if not all rows are selected
2009cdf0e10cSrcweir 						// (all rows means the whole table)
2010cdf0e10cSrcweir 						// i3832 - 03.04.2002 - fs@openoffice.org
2011cdf0e10cSrcweir 						if (pSelection != NULL)
2012cdf0e10cSrcweir 						{
2013cdf0e10cSrcweir 							aSelection.realloc(pSelection->GetSelectCount());
2014cdf0e10cSrcweir 							long nIdx = pSelection->FirstSelected();
2015cdf0e10cSrcweir 							Any* pSelectionNos = aSelection.getArray();
2016cdf0e10cSrcweir 							while (nIdx >= 0)
2017cdf0e10cSrcweir 							{
2018cdf0e10cSrcweir 								*pSelectionNos++ <<= (sal_Int32)(nIdx + 1);
2019cdf0e10cSrcweir 								nIdx = pSelection->NextSelected();
2020cdf0e10cSrcweir 							}
2021cdf0e10cSrcweir 						}
2022cdf0e10cSrcweir 					}
2023cdf0e10cSrcweir 
2024cdf0e10cSrcweir 					Reference< XResultSet > xCursorClone;
2025cdf0e10cSrcweir 					try
2026cdf0e10cSrcweir 					{
2027cdf0e10cSrcweir 						Reference< XResultSetAccess > xResultSetAccess(getRowSet(),UNO_QUERY);
2028cdf0e10cSrcweir 						if (xResultSetAccess.is())
2029cdf0e10cSrcweir 							xCursorClone = xResultSetAccess->createResultSet();
2030cdf0e10cSrcweir 					}
2031cdf0e10cSrcweir 					catch(DisposedException&)
2032cdf0e10cSrcweir 					{
2033cdf0e10cSrcweir 						OSL_ENSURE(0,"Object already disposed!");
2034cdf0e10cSrcweir 					}
2035cdf0e10cSrcweir 					catch(Exception&)
2036cdf0e10cSrcweir 					{
2037cdf0e10cSrcweir 						DBG_ERROR("SbaTableQueryBrowser::Execute(ID_BROWSER_?): could not clone the cursor!");
2038cdf0e10cSrcweir 					}
2039cdf0e10cSrcweir 
2040cdf0e10cSrcweir 					Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
2041cdf0e10cSrcweir 
2042cdf0e10cSrcweir 					try
2043cdf0e10cSrcweir 					{
2044cdf0e10cSrcweir 						ODataAccessDescriptor aDescriptor;
2045cdf0e10cSrcweir 						::rtl::OUString sDataSourceName;
2046cdf0e10cSrcweir 						xProp->getPropertyValue(PROPERTY_DATASOURCENAME) >>= sDataSourceName;
2047cdf0e10cSrcweir 
2048cdf0e10cSrcweir 						aDescriptor.setDataSource(sDataSourceName);
2049cdf0e10cSrcweir 						aDescriptor[daCommand]		=	xProp->getPropertyValue(PROPERTY_COMMAND);
2050cdf0e10cSrcweir 						aDescriptor[daCommandType]	=	xProp->getPropertyValue(PROPERTY_COMMAND_TYPE);
2051cdf0e10cSrcweir 						aDescriptor[daConnection]	=	xProp->getPropertyValue(PROPERTY_ACTIVE_CONNECTION);
2052cdf0e10cSrcweir 						aDescriptor[daCursor]		<<= xCursorClone;
2053cdf0e10cSrcweir 						if ( aSelection.getLength() )
2054cdf0e10cSrcweir 						{
2055cdf0e10cSrcweir 							aDescriptor[daSelection]			<<= aSelection;
2056cdf0e10cSrcweir 							aDescriptor[daBookmarkSelection]	<<= sal_False;
2057cdf0e10cSrcweir 								// these are selection indicies
2058cdf0e10cSrcweir 								// before we change this, all clients have to be adjusted
2059cdf0e10cSrcweir 								// so that they recognize the new BookmarkSelection property!
2060cdf0e10cSrcweir 						}
2061cdf0e10cSrcweir 
2062cdf0e10cSrcweir 						xDispatch->dispatch(aParentUrl, aDescriptor.createPropertyValueSequence());
2063cdf0e10cSrcweir 					}
2064cdf0e10cSrcweir                     catch( const Exception& )
2065cdf0e10cSrcweir                     {
2066cdf0e10cSrcweir                         DBG_UNHANDLED_EXCEPTION();
2067cdf0e10cSrcweir                     }
2068cdf0e10cSrcweir 				}
2069cdf0e10cSrcweir 			}
2070cdf0e10cSrcweir 			break;
2071cdf0e10cSrcweir 
2072cdf0e10cSrcweir 		case ID_BROWSER_CLOSE:
2073cdf0e10cSrcweir 			closeTask();
2074cdf0e10cSrcweir 			// if it's not 0, such a async close is already pending
2075cdf0e10cSrcweir 			break;
2076cdf0e10cSrcweir 
2077cdf0e10cSrcweir 		case ID_BROWSER_COPY:
2078cdf0e10cSrcweir 			if(m_pTreeView->HasChildPathFocus())
2079cdf0e10cSrcweir 			{
2080cdf0e10cSrcweir 				copyEntry(m_pTreeView->getListBox().GetCurEntry());
2081cdf0e10cSrcweir 			}
2082cdf0e10cSrcweir 			else if (getBrowserView() && getBrowserView()->getVclControl() && !getBrowserView()->getVclControl()->IsEditing() && getBrowserView()->getVclControl()->GetSelectRowCount() < 1)
2083cdf0e10cSrcweir 			{
2084cdf0e10cSrcweir 				SbaGridControl* pControl = getBrowserView()->getVclControl();
2085cdf0e10cSrcweir 				pControl->copyCellText(pControl->GetCurRow(), pControl->GetCurColumnId());
2086cdf0e10cSrcweir 			}
2087cdf0e10cSrcweir 			else
2088cdf0e10cSrcweir 				SbaXDataBrowserController::Execute(nId,aArgs);
2089cdf0e10cSrcweir 			break;
2090cdf0e10cSrcweir 	}
2091cdf0e10cSrcweir }
2092cdf0e10cSrcweir 
2093cdf0e10cSrcweir // -------------------------------------------------------------------------
2094cdf0e10cSrcweir void SbaTableQueryBrowser::implAddDatasource( const String& _rDataSourceName, const SharedConnection& _rxConnection )
2095cdf0e10cSrcweir {
2096cdf0e10cSrcweir     Image a, b, c;
2097cdf0e10cSrcweir     String d, e;
2098cdf0e10cSrcweir     implAddDatasource( _rDataSourceName, a, d, b, e, c, _rxConnection );
2099cdf0e10cSrcweir }
2100cdf0e10cSrcweir 
2101cdf0e10cSrcweir // -------------------------------------------------------------------------
2102cdf0e10cSrcweir void SbaTableQueryBrowser::implAddDatasource(const String& _rDbName, Image& _rDbImage,
2103cdf0e10cSrcweir 		String& _rQueryName, Image& _rQueryImage, String& _rTableName, Image& _rTableImage,
2104cdf0e10cSrcweir         const SharedConnection& _rxConnection)
2105cdf0e10cSrcweir {
2106cdf0e10cSrcweir 	vos::OGuard aGuard( Application::GetSolarMutex() );
2107cdf0e10cSrcweir 	// initialize the names/images if necessary
2108cdf0e10cSrcweir 	if (!_rQueryName.Len())
2109cdf0e10cSrcweir 		_rQueryName = String(ModuleRes(RID_STR_QUERIES_CONTAINER));
2110cdf0e10cSrcweir 	if (!_rTableName.Len())
2111cdf0e10cSrcweir 		_rTableName = String(ModuleRes(RID_STR_TABLES_CONTAINER));
2112cdf0e10cSrcweir 
2113cdf0e10cSrcweir     ImageProvider aImageProvider;
2114cdf0e10cSrcweir 	if (!_rQueryImage)
2115cdf0e10cSrcweir         _rQueryImage = aImageProvider.getFolderImage( DatabaseObject::QUERY, isHiContrast() );
2116cdf0e10cSrcweir 	if (!_rTableImage)
2117cdf0e10cSrcweir         _rTableImage = aImageProvider.getFolderImage( DatabaseObject::TABLE, isHiContrast() );
2118cdf0e10cSrcweir 
2119cdf0e10cSrcweir 	if (!_rDbImage)
2120cdf0e10cSrcweir 		_rDbImage = aImageProvider.getDatabaseImage( isHiContrast() );
2121cdf0e10cSrcweir 
2122cdf0e10cSrcweir 	// add the entry for the data source
2123cdf0e10cSrcweir     // special handling for data sources denoted by URLs - we do not want to display this ugly URL, do we?
2124cdf0e10cSrcweir     // #i33699# - 2004-09-24 - fs@openoffice.org
2125cdf0e10cSrcweir     String sDSDisplayName, sDataSourceId;
2126cdf0e10cSrcweir     getDataSourceDisplayName_isURL( _rDbName, sDSDisplayName, sDataSourceId );
2127cdf0e10cSrcweir 
2128cdf0e10cSrcweir 	SvLBoxEntry* pDatasourceEntry = m_pTreeView->getListBox().InsertEntry( sDSDisplayName, _rDbImage, _rDbImage, NULL, sal_False );
2129cdf0e10cSrcweir 	DBTreeListUserData* pDSData = new DBTreeListUserData;
2130cdf0e10cSrcweir 	pDSData->eType = etDatasource;
2131cdf0e10cSrcweir     pDSData->sAccessor = sDataSourceId;
2132cdf0e10cSrcweir 	pDSData->xConnection = _rxConnection;
2133cdf0e10cSrcweir 	pDatasourceEntry->SetUserData(pDSData);
2134cdf0e10cSrcweir 
2135cdf0e10cSrcweir 	// the child for the queries container
2136cdf0e10cSrcweir 	{
2137cdf0e10cSrcweir 		DBTreeListUserData* pQueriesData = new DBTreeListUserData;
2138cdf0e10cSrcweir 		pQueriesData->eType = etQueryContainer;
2139cdf0e10cSrcweir 
2140cdf0e10cSrcweir         m_pTreeView->getListBox().InsertEntry(
2141cdf0e10cSrcweir             _rQueryName, _rQueryImage, _rQueryImage, pDatasourceEntry,
2142cdf0e10cSrcweir             sal_True /*ChildsOnDemand*/, LIST_APPEND, pQueriesData );
2143cdf0e10cSrcweir 	}
2144cdf0e10cSrcweir 
2145cdf0e10cSrcweir 	// the child for the tables container
2146cdf0e10cSrcweir 	{
2147cdf0e10cSrcweir 		DBTreeListUserData* pTablesData = new DBTreeListUserData;
2148cdf0e10cSrcweir 		pTablesData->eType = etTableContainer;
2149cdf0e10cSrcweir 
2150cdf0e10cSrcweir 		m_pTreeView->getListBox().InsertEntry(
2151cdf0e10cSrcweir             _rTableName, _rTableImage, _rTableImage, pDatasourceEntry,
2152cdf0e10cSrcweir             sal_True /*ChildsOnDemand*/, LIST_APPEND, pTablesData );
2153cdf0e10cSrcweir 	}
2154cdf0e10cSrcweir 
2155cdf0e10cSrcweir }
2156cdf0e10cSrcweir // -------------------------------------------------------------------------
2157cdf0e10cSrcweir void SbaTableQueryBrowser::initializeTreeModel()
2158cdf0e10cSrcweir {
2159cdf0e10cSrcweir 	if (m_xDatabaseContext.is())
2160cdf0e10cSrcweir 	{
2161cdf0e10cSrcweir 		Image aDBImage, aQueriesImage, aTablesImage;
2162cdf0e10cSrcweir 		String sQueriesName, sTablesName;
2163cdf0e10cSrcweir 
2164cdf0e10cSrcweir 		// fill the model with the names of the registered datasources
2165cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aDatasources = m_xDatabaseContext->getElementNames();
2166cdf0e10cSrcweir 		const ::rtl::OUString* pIter	= aDatasources.getConstArray();
2167cdf0e10cSrcweir 		const ::rtl::OUString* pEnd 	= pIter + aDatasources.getLength();
2168cdf0e10cSrcweir 		for (; pIter != pEnd; ++pIter)
2169cdf0e10cSrcweir 			implAddDatasource( *pIter, aDBImage, sQueriesName, aQueriesImage, sTablesName, aTablesImage, SharedConnection() );
2170cdf0e10cSrcweir 	}
2171cdf0e10cSrcweir }
2172cdf0e10cSrcweir // -------------------------------------------------------------------------
2173cdf0e10cSrcweir void SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAccess,
2174cdf0e10cSrcweir 											SvLBoxEntry* _pParent,
2175cdf0e10cSrcweir 											EntryType _eEntryType)
2176cdf0e10cSrcweir {
2177cdf0e10cSrcweir 	DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pParent->GetUserData());
2178cdf0e10cSrcweir 	if(pData) // don't ask if the nameaccess is already set see OnExpandEntry views and tables
2179cdf0e10cSrcweir 		pData->xContainer = _xNameAccess;
2180cdf0e10cSrcweir 
2181cdf0e10cSrcweir 	try
2182cdf0e10cSrcweir 	{
2183cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aNames = _xNameAccess->getElementNames();
2184cdf0e10cSrcweir 		const ::rtl::OUString* pIter	= aNames.getConstArray();
2185cdf0e10cSrcweir 		const ::rtl::OUString* pEnd 	= pIter + aNames.getLength();
2186cdf0e10cSrcweir 		for (; pIter != pEnd; ++pIter)
2187cdf0e10cSrcweir 		{
2188cdf0e10cSrcweir 			if( !m_pTreeView->getListBox().GetEntryPosByName(*pIter,_pParent))
2189cdf0e10cSrcweir 			{
2190cdf0e10cSrcweir 				DBTreeListUserData* pEntryData = new DBTreeListUserData;
2191cdf0e10cSrcweir 				pEntryData->eType = _eEntryType;
2192cdf0e10cSrcweir                 if ( _eEntryType == etQuery )
2193cdf0e10cSrcweir                 {
2194cdf0e10cSrcweir 					Reference<XNameAccess> xChild(_xNameAccess->getByName(*pIter),UNO_QUERY);
2195cdf0e10cSrcweir 					if ( xChild.is() )
2196cdf0e10cSrcweir 						pEntryData->eType = etQueryContainer;
2197cdf0e10cSrcweir                 }
2198cdf0e10cSrcweir                 implAppendEntry( _pParent, *pIter, pEntryData, pEntryData->eType );
2199cdf0e10cSrcweir 			}
2200cdf0e10cSrcweir 		}
2201cdf0e10cSrcweir 	}
2202cdf0e10cSrcweir 	catch(Exception&)
2203cdf0e10cSrcweir 	{
2204cdf0e10cSrcweir 		DBG_ERROR("SbaTableQueryBrowser::populateTree: could not fill the tree");
2205cdf0e10cSrcweir 	}
2206cdf0e10cSrcweir }
2207cdf0e10cSrcweir 
2208cdf0e10cSrcweir //------------------------------------------------------------------------------
2209cdf0e10cSrcweir SvLBoxEntry* SbaTableQueryBrowser::implAppendEntry( SvLBoxEntry* _pParent, const String& _rName, void* _pUserData, EntryType _eEntryType )
2210cdf0e10cSrcweir {
2211cdf0e10cSrcweir     ::std::auto_ptr< ImageProvider > pImageProvider( getImageProviderFor( _pParent ) );
2212cdf0e10cSrcweir 
2213cdf0e10cSrcweir     Image aImage, aImageHC;
2214cdf0e10cSrcweir     pImageProvider->getImages( _rName, getDatabaseObjectType( _eEntryType ), aImage, aImageHC );
2215cdf0e10cSrcweir 
2216cdf0e10cSrcweir     SvLBoxEntry* pNewEntry = m_pTreeView->getListBox().InsertEntry( _rName, _pParent, _eEntryType == etQueryContainer , LIST_APPEND, _pUserData );
2217cdf0e10cSrcweir 
2218cdf0e10cSrcweir     m_pTreeView->getListBox().SetExpandedEntryBmp( pNewEntry, aImage, BMP_COLOR_NORMAL );
2219cdf0e10cSrcweir     m_pTreeView->getListBox().SetCollapsedEntryBmp( pNewEntry, aImage, BMP_COLOR_NORMAL );
2220cdf0e10cSrcweir     m_pTreeView->getListBox().SetExpandedEntryBmp( pNewEntry, aImageHC, BMP_COLOR_HIGHCONTRAST );
2221cdf0e10cSrcweir     m_pTreeView->getListBox().SetCollapsedEntryBmp( pNewEntry, aImageHC, BMP_COLOR_HIGHCONTRAST );
2222cdf0e10cSrcweir 
2223cdf0e10cSrcweir     return pNewEntry;
2224cdf0e10cSrcweir }
2225cdf0e10cSrcweir 
2226cdf0e10cSrcweir //------------------------------------------------------------------------------
2227cdf0e10cSrcweir IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, SvLBoxEntry*, _pParent)
2228cdf0e10cSrcweir {
2229cdf0e10cSrcweir 	if (_pParent->HasChilds())
2230cdf0e10cSrcweir 		// nothing to to ...
2231cdf0e10cSrcweir 		return 1L;
2232cdf0e10cSrcweir 
2233cdf0e10cSrcweir 	SvLBoxEntry* pFirstParent = m_pTreeView->getListBox().GetRootLevelParent(_pParent);
2234cdf0e10cSrcweir 	OSL_ENSURE(pFirstParent,"SbaTableQueryBrowser::OnExpandEntry: No rootlevelparent!");
2235cdf0e10cSrcweir 
2236cdf0e10cSrcweir 	DBTreeListUserData* pData = static_cast< DBTreeListUserData* >(_pParent->GetUserData());
2237cdf0e10cSrcweir 	OSL_ENSURE(pData,"SbaTableQueryBrowser::OnExpandEntry: No user data!");
2238cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
2239cdf0e10cSrcweir 	SvLBoxString* pString = static_cast<SvLBoxString*>(pFirstParent->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING));
2240cdf0e10cSrcweir     OSL_ENSURE(pString,"SbaTableQueryBrowser::OnExpandEntry: No string item!");
2241cdf0e10cSrcweir #endif
2242cdf0e10cSrcweir 
2243cdf0e10cSrcweir 	if (etTableContainer == pData->eType)
2244cdf0e10cSrcweir 	{
2245cdf0e10cSrcweir 		WaitObject aWaitCursor(getBrowserView());
2246cdf0e10cSrcweir 
2247cdf0e10cSrcweir 		// it could be that we already have a connection
2248cdf0e10cSrcweir         SharedConnection xConnection;
2249cdf0e10cSrcweir 		ensureConnection( pFirstParent, xConnection );
2250cdf0e10cSrcweir 
2251cdf0e10cSrcweir 		if ( xConnection.is() )
2252cdf0e10cSrcweir 		{
2253cdf0e10cSrcweir 			SQLExceptionInfo aInfo;
2254cdf0e10cSrcweir 			try
2255cdf0e10cSrcweir 			{
2256cdf0e10cSrcweir 				Reference< XWarningsSupplier > xWarnings(xConnection, UNO_QUERY);
2257cdf0e10cSrcweir 				if (xWarnings.is())
2258cdf0e10cSrcweir 					xWarnings->clearWarnings();
2259cdf0e10cSrcweir 
2260cdf0e10cSrcweir 				// first insert the views because the tables can also include
2261cdf0e10cSrcweir 				// views but that time the bitmap is the wrong one
2262cdf0e10cSrcweir 				// the nameaccess will be overwriten in populateTree
2263cdf0e10cSrcweir 				Reference<XViewsSupplier> xViewSup(xConnection,UNO_QUERY);
2264cdf0e10cSrcweir 				if(xViewSup.is())
2265cdf0e10cSrcweir 					populateTree( xViewSup->getViews(), _pParent, etTableOrView );
2266cdf0e10cSrcweir 
2267cdf0e10cSrcweir 				Reference<XTablesSupplier> xTabSup(xConnection,UNO_QUERY);
2268cdf0e10cSrcweir 				if(xTabSup.is())
2269cdf0e10cSrcweir 				{
2270cdf0e10cSrcweir 					populateTree( xTabSup->getTables(), _pParent, etTableOrView );
2271cdf0e10cSrcweir 					Reference<XContainer> xCont(xTabSup->getTables(),UNO_QUERY);
2272cdf0e10cSrcweir 					if(xCont.is())
2273cdf0e10cSrcweir 						// add as listener to know when elements are inserted or removed
2274cdf0e10cSrcweir 						xCont->addContainerListener(this);
2275cdf0e10cSrcweir 				}
2276cdf0e10cSrcweir 
2277cdf0e10cSrcweir 				if (xWarnings.is())
2278cdf0e10cSrcweir 				{
2279cdf0e10cSrcweir 					SQLExceptionInfo aWarnings(xWarnings->getWarnings());
2280cdf0e10cSrcweir 					if (aWarnings.isValid() && sal_False)
2281cdf0e10cSrcweir 					{
2282cdf0e10cSrcweir 						SQLContext aContext;
2283cdf0e10cSrcweir 						aContext.Message = String(ModuleRes(STR_OPENTABLES_WARNINGS));
2284cdf0e10cSrcweir 						aContext.Details = String(ModuleRes(STR_OPENTABLES_WARNINGS_DETAILS));
2285cdf0e10cSrcweir 						aContext.NextException = aWarnings.get();
2286cdf0e10cSrcweir 						aWarnings = aContext;
2287cdf0e10cSrcweir 						showError(aWarnings);
2288cdf0e10cSrcweir 					}
2289cdf0e10cSrcweir 					// TODO: we need a better concept for these warnings:
2290cdf0e10cSrcweir 					// something like "don't show any warnings for this datasource, again" would be nice
2291cdf0e10cSrcweir 					// But this requires an extension of the InteractionHandler and an additional property on the data source
2292cdf0e10cSrcweir 				}
2293cdf0e10cSrcweir 			}
2294cdf0e10cSrcweir 			catch(const SQLContext& e) { aInfo = e; }
2295cdf0e10cSrcweir 			catch(const SQLWarning& e) { aInfo = e; }
2296cdf0e10cSrcweir 			catch(const SQLException& e) { aInfo = e; }
2297cdf0e10cSrcweir 			catch(const WrappedTargetException& e)
2298cdf0e10cSrcweir 			{
2299cdf0e10cSrcweir 				SQLException aSql;
2300cdf0e10cSrcweir 				if(e.TargetException >>= aSql)
2301cdf0e10cSrcweir 					aInfo = aSql;
2302cdf0e10cSrcweir 				else
2303cdf0e10cSrcweir 					OSL_ENSURE(sal_False, "SbaTableQueryBrowser::OnExpandEntry: something strange happended!");
2304cdf0e10cSrcweir 			}
2305cdf0e10cSrcweir             catch( const Exception& )
2306cdf0e10cSrcweir             {
2307cdf0e10cSrcweir                 DBG_UNHANDLED_EXCEPTION();
2308cdf0e10cSrcweir             }
2309cdf0e10cSrcweir 			if (aInfo.isValid())
2310cdf0e10cSrcweir 				showError(aInfo);
2311cdf0e10cSrcweir 		}
2312cdf0e10cSrcweir 		else
2313cdf0e10cSrcweir 			return 0L;
2314cdf0e10cSrcweir 				// 0 indicates that an error occured
2315cdf0e10cSrcweir 	}
2316cdf0e10cSrcweir 	else
2317cdf0e10cSrcweir 	{	// we have to expand the queries or bookmarks
2318cdf0e10cSrcweir 		if (ensureEntryObject(_pParent))
2319cdf0e10cSrcweir 		{
2320cdf0e10cSrcweir             DBTreeListUserData* pParentData = static_cast< DBTreeListUserData* >( _pParent->GetUserData() );
2321cdf0e10cSrcweir 			Reference< XNameAccess > xCollection( pParentData->xContainer, UNO_QUERY );
2322cdf0e10cSrcweir 			populateTree( xCollection, _pParent, etQuery );
2323cdf0e10cSrcweir 		}
2324cdf0e10cSrcweir 	}
2325cdf0e10cSrcweir 	return 1L;
2326cdf0e10cSrcweir }
2327cdf0e10cSrcweir 
2328cdf0e10cSrcweir //------------------------------------------------------------------------------
2329cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::ensureEntryObject( SvLBoxEntry* _pEntry )
2330cdf0e10cSrcweir {
2331cdf0e10cSrcweir 	DBG_ASSERT(_pEntry, "SbaTableQueryBrowser::ensureEntryObject: invalid argument!");
2332cdf0e10cSrcweir 	if (!_pEntry)
2333cdf0e10cSrcweir 		return sal_False;
2334cdf0e10cSrcweir 
2335cdf0e10cSrcweir 	EntryType eType = getEntryType( _pEntry );
2336cdf0e10cSrcweir 
2337cdf0e10cSrcweir 	// the user data of the entry
2338cdf0e10cSrcweir 	DBTreeListUserData* pEntryData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData());
2339cdf0e10cSrcweir 	OSL_ENSURE(pEntryData,"ensureEntryObject: user data should already be set!");
2340cdf0e10cSrcweir 
2341cdf0e10cSrcweir 	SvLBoxEntry* pDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent(_pEntry);
2342cdf0e10cSrcweir 
2343cdf0e10cSrcweir     sal_Bool bSuccess = sal_False;
2344cdf0e10cSrcweir 	switch (eType)
2345cdf0e10cSrcweir 	{
2346cdf0e10cSrcweir 		case etQueryContainer:
2347cdf0e10cSrcweir 	        if ( pEntryData->xContainer.is() )
2348cdf0e10cSrcweir             {
2349cdf0e10cSrcweir 		        // nothing to do
2350cdf0e10cSrcweir                 bSuccess = sal_True;
2351cdf0e10cSrcweir                 break;
2352cdf0e10cSrcweir             }
2353cdf0e10cSrcweir 
2354cdf0e10cSrcweir             {
2355cdf0e10cSrcweir                 SvLBoxEntry* pParent = m_pTreeView->getListBox().GetParent(_pEntry);
2356cdf0e10cSrcweir                 if ( pParent != pDataSourceEntry )
2357cdf0e10cSrcweir                 {
2358cdf0e10cSrcweir                     SvLBoxString* pString = (SvLBoxString*)_pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
2359cdf0e10cSrcweir 	                OSL_ENSURE(pString,"There must be a string item!");
2360cdf0e10cSrcweir 	                ::rtl::OUString aName(pString->GetText());
2361cdf0e10cSrcweir                     DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pParent->GetUserData());
2362cdf0e10cSrcweir                     try
2363cdf0e10cSrcweir                     {
2364cdf0e10cSrcweir                         Reference< XNameAccess > xNameAccess(pData->xContainer,UNO_QUERY);
2365cdf0e10cSrcweir                         if ( xNameAccess.is() )
2366cdf0e10cSrcweir 		                    pEntryData->xContainer.set(xNameAccess->getByName(aName),UNO_QUERY);
2367cdf0e10cSrcweir                     }
2368cdf0e10cSrcweir                     catch(const Exception& )
2369cdf0e10cSrcweir                     {
2370cdf0e10cSrcweir                         DBG_UNHANDLED_EXCEPTION();
2371cdf0e10cSrcweir                     }
2372cdf0e10cSrcweir 
2373cdf0e10cSrcweir                     bSuccess = pEntryData->xContainer.is();
2374cdf0e10cSrcweir                 }
2375cdf0e10cSrcweir                 else
2376cdf0e10cSrcweir                 {
2377cdf0e10cSrcweir                     try
2378cdf0e10cSrcweir 			        {
2379cdf0e10cSrcweir 				        Reference< XQueryDefinitionsSupplier > xQuerySup;
2380cdf0e10cSrcweir 				        m_xDatabaseContext->getByName( getDataSourceAcessor( pDataSourceEntry ) ) >>= xQuerySup;
2381cdf0e10cSrcweir 				        if (xQuerySup.is())
2382cdf0e10cSrcweir 				        {
2383cdf0e10cSrcweir 					        Reference< XNameAccess > xQueryDefs = xQuerySup->getQueryDefinitions();
2384cdf0e10cSrcweir 					        Reference< XContainer > xCont(xQueryDefs, UNO_QUERY);
2385cdf0e10cSrcweir 					        if (xCont.is())
2386cdf0e10cSrcweir 						        // add as listener to get notified if elements are inserted or removed
2387cdf0e10cSrcweir 						        xCont->addContainerListener(this);
2388cdf0e10cSrcweir 
2389cdf0e10cSrcweir 					        pEntryData->xContainer = xQueryDefs;
2390cdf0e10cSrcweir                             bSuccess = pEntryData->xContainer.is();
2391cdf0e10cSrcweir 				        }
2392cdf0e10cSrcweir 				        else {
2393cdf0e10cSrcweir 					        DBG_ERROR("SbaTableQueryBrowser::ensureEntryObject: no XQueryDefinitionsSupplier interface!");
2394cdf0e10cSrcweir                         }
2395cdf0e10cSrcweir 			        }
2396cdf0e10cSrcweir                     catch( const Exception& )
2397cdf0e10cSrcweir                     {
2398cdf0e10cSrcweir                         DBG_UNHANDLED_EXCEPTION();
2399cdf0e10cSrcweir                     }
2400cdf0e10cSrcweir                 }
2401cdf0e10cSrcweir             }
2402cdf0e10cSrcweir 		    break;
2403cdf0e10cSrcweir 
2404cdf0e10cSrcweir 		default:
2405cdf0e10cSrcweir 			DBG_ERROR("SbaTableQueryBrowser::ensureEntryObject: ooops ... missing some implementation here!");
2406cdf0e10cSrcweir 			// TODO ...
2407cdf0e10cSrcweir 			break;
2408cdf0e10cSrcweir 	}
2409cdf0e10cSrcweir 
2410cdf0e10cSrcweir 	return bSuccess;
2411cdf0e10cSrcweir }
2412cdf0e10cSrcweir //------------------------------------------------------------------------------
2413cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::implSelect(const ::svx::ODataAccessDescriptor& _rDescriptor,sal_Bool _bSelectDirect)
2414cdf0e10cSrcweir {
2415cdf0e10cSrcweir 	// extract the props
2416cdf0e10cSrcweir 	::rtl::OUString sDataSource;
2417cdf0e10cSrcweir 	::rtl::OUString sCommand;
2418cdf0e10cSrcweir 	sal_Int32 nCommandType = CommandType::COMMAND;
2419cdf0e10cSrcweir 	sal_Bool bEscapeProcessing = sal_True;
2420cdf0e10cSrcweir 	extractDescriptorProps(_rDescriptor, sDataSource, sCommand, nCommandType, bEscapeProcessing);
2421cdf0e10cSrcweir 
2422cdf0e10cSrcweir 	// select it
2423cdf0e10cSrcweir 	return implSelect( sDataSource, sCommand, nCommandType, bEscapeProcessing, SharedConnection(), _bSelectDirect );
2424cdf0e10cSrcweir }
2425cdf0e10cSrcweir 
2426cdf0e10cSrcweir //------------------------------------------------------------------------------
2427cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::implLoadAnything(const ::rtl::OUString& _rDataSourceName, const ::rtl::OUString& _rCommand,
2428cdf0e10cSrcweir 	const sal_Int32 _nCommandType, const sal_Bool _bEscapeProcessing, const SharedConnection& _rxConnection)
2429cdf0e10cSrcweir {
2430cdf0e10cSrcweir 	try
2431cdf0e10cSrcweir 	{
2432cdf0e10cSrcweir         Reference<XPropertySet> xProp( getRowSet(), UNO_QUERY_THROW );
2433cdf0e10cSrcweir         Reference< XLoadable >	xLoadable( xProp, UNO_QUERY_THROW );
2434cdf0e10cSrcweir 		// the values allowing the RowSet to re-execute
2435cdf0e10cSrcweir 		xProp->setPropertyValue(PROPERTY_DATASOURCENAME, makeAny(_rDataSourceName));
2436cdf0e10cSrcweir 		if(_rxConnection.is())
2437cdf0e10cSrcweir 			xProp->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( _rxConnection.getTyped() ) );
2438cdf0e10cSrcweir 
2439cdf0e10cSrcweir 			// set this _before_ setting the connection, else the rowset would rebuild it ...
2440cdf0e10cSrcweir 		xProp->setPropertyValue(PROPERTY_COMMAND_TYPE, makeAny(_nCommandType));
2441cdf0e10cSrcweir 		xProp->setPropertyValue(PROPERTY_COMMAND, makeAny(_rCommand));
2442cdf0e10cSrcweir 		xProp->setPropertyValue(PROPERTY_ESCAPE_PROCESSING, ::cppu::bool2any(_bEscapeProcessing));
2443cdf0e10cSrcweir 		if ( m_bPreview )
2444cdf0e10cSrcweir 		{
2445cdf0e10cSrcweir 			xProp->setPropertyValue(PROPERTY_FETCHDIRECTION, makeAny(FetchDirection::FORWARD));
2446cdf0e10cSrcweir 		}
2447cdf0e10cSrcweir 
2448cdf0e10cSrcweir 		// the formatter depends on the data source we're working on, so rebuild it here ...
2449cdf0e10cSrcweir 		initFormatter();
2450cdf0e10cSrcweir 
2451cdf0e10cSrcweir 		// switch the grid to design mode while loading
2452cdf0e10cSrcweir 		getBrowserView()->getGridControl()->setDesignMode(sal_True);
2453cdf0e10cSrcweir 		InitializeForm( xProp );
2454cdf0e10cSrcweir 
2455cdf0e10cSrcweir 		sal_Bool bSuccess = sal_True;
2456cdf0e10cSrcweir 
2457cdf0e10cSrcweir 		{
2458cdf0e10cSrcweir 			{
2459cdf0e10cSrcweir 				Reference< XNameContainer >  xColContainer(getFormComponent(), UNO_QUERY);
2460cdf0e10cSrcweir 				// first we have to clear the grid
2461cdf0e10cSrcweir 				clearGridColumns(xColContainer);
2462cdf0e10cSrcweir 			}
2463cdf0e10cSrcweir 			FormErrorHelper aHelper(this);
2464cdf0e10cSrcweir 			// load the form
2465cdf0e10cSrcweir 			bSuccess = reloadForm(xLoadable);
2466cdf0e10cSrcweir 
2467cdf0e10cSrcweir 			// initialize the model
2468cdf0e10cSrcweir 			InitializeGridModel(getFormComponent());
2469cdf0e10cSrcweir 
2470cdf0e10cSrcweir             Any aVal = xProp->getPropertyValue(PROPERTY_ISNEW);
2471cdf0e10cSrcweir 			if (aVal.hasValue() && ::comphelper::getBOOL(aVal))
2472cdf0e10cSrcweir             {
2473cdf0e10cSrcweir                 // then set the default values and the parameters given from the parent
2474cdf0e10cSrcweir                 Reference< XReset> xReset(xProp, UNO_QUERY);
2475cdf0e10cSrcweir 		        xReset->reset();
2476cdf0e10cSrcweir             }
2477cdf0e10cSrcweir 
2478cdf0e10cSrcweir 		    if ( m_bPreview )
2479cdf0e10cSrcweir                 initializePreviewMode();
2480cdf0e10cSrcweir 
2481cdf0e10cSrcweir 			LoadFinished(sal_True);
2482cdf0e10cSrcweir 		}
2483cdf0e10cSrcweir 
2484cdf0e10cSrcweir 		InvalidateAll();
2485cdf0e10cSrcweir 		return bSuccess;
2486cdf0e10cSrcweir 	}
2487cdf0e10cSrcweir 	catch( const SQLException& e )
2488cdf0e10cSrcweir 	{
2489cdf0e10cSrcweir         Any aException( ::cppu::getCaughtException() );
2490cdf0e10cSrcweir         showError( SQLExceptionInfo( aException ) );
2491cdf0e10cSrcweir 	}
2492cdf0e10cSrcweir 	catch( const WrappedTargetException& e )
2493cdf0e10cSrcweir 	{
2494cdf0e10cSrcweir 		SQLException aSql;
2495cdf0e10cSrcweir         if  ( e.TargetException.isExtractableTo( ::cppu::UnoType< SQLException >::get() ) )
2496cdf0e10cSrcweir 			showError( SQLExceptionInfo( e.TargetException ) );
2497cdf0e10cSrcweir 		else
2498cdf0e10cSrcweir         {
2499cdf0e10cSrcweir 			DBG_UNHANDLED_EXCEPTION();
2500cdf0e10cSrcweir         }
2501cdf0e10cSrcweir 	}
2502cdf0e10cSrcweir 	catch(Exception&)
2503cdf0e10cSrcweir 	{
2504cdf0e10cSrcweir 		DBG_UNHANDLED_EXCEPTION();
2505cdf0e10cSrcweir 	}
2506cdf0e10cSrcweir 
2507cdf0e10cSrcweir 	InvalidateAll();
2508cdf0e10cSrcweir 	return sal_False;
2509cdf0e10cSrcweir }
2510cdf0e10cSrcweir 
2511cdf0e10cSrcweir //------------------------------------------------------------------------------
2512cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::implSelect(const ::rtl::OUString& _rDataSourceName, const ::rtl::OUString& _rCommand,
2513cdf0e10cSrcweir 									  const sal_Int32 _nCommandType, const sal_Bool _bEscapeProcessing,
2514cdf0e10cSrcweir 									  const SharedConnection& _rxConnection
2515cdf0e10cSrcweir 									  ,sal_Bool _bSelectDirect)
2516cdf0e10cSrcweir {
2517cdf0e10cSrcweir 	if (_rDataSourceName.getLength() && _rCommand.getLength() && (-1 != _nCommandType))
2518cdf0e10cSrcweir 	{
2519cdf0e10cSrcweir 		SvLBoxEntry* pDataSource = NULL;
2520cdf0e10cSrcweir 		SvLBoxEntry* pCommandType = NULL;
2521cdf0e10cSrcweir 		SvLBoxEntry* pCommand = getObjectEntry( _rDataSourceName, _rCommand, _nCommandType, &pDataSource, &pCommandType, sal_True, _rxConnection );
2522cdf0e10cSrcweir 
2523cdf0e10cSrcweir 		if (pCommand)
2524cdf0e10cSrcweir 		{
2525cdf0e10cSrcweir             bool bSuccess = true;
2526cdf0e10cSrcweir 			if ( _bSelectDirect )
2527cdf0e10cSrcweir 			{
2528cdf0e10cSrcweir 				bSuccess = implSelect( pCommand );
2529cdf0e10cSrcweir 			}
2530cdf0e10cSrcweir 			else
2531cdf0e10cSrcweir             {
2532cdf0e10cSrcweir 				m_pTreeView->getListBox().Select( pCommand );
2533cdf0e10cSrcweir             }
2534cdf0e10cSrcweir 
2535cdf0e10cSrcweir             if ( bSuccess )
2536cdf0e10cSrcweir             {
2537cdf0e10cSrcweir                 m_pTreeView->getListBox().MakeVisible(pCommand);
2538cdf0e10cSrcweir                 m_pTreeView->getListBox().SetCursor(pCommand);
2539cdf0e10cSrcweir             }
2540cdf0e10cSrcweir 		}
2541cdf0e10cSrcweir 		else if (!pCommandType)
2542cdf0e10cSrcweir 		{
2543cdf0e10cSrcweir 			if ( m_pCurrentlyDisplayed )
2544cdf0e10cSrcweir 			{	// tell the old entry (if any) it has been deselected
2545cdf0e10cSrcweir 				selectPath(m_pCurrentlyDisplayed, sal_False);
2546cdf0e10cSrcweir 				m_pCurrentlyDisplayed = NULL;
2547cdf0e10cSrcweir 			}
2548cdf0e10cSrcweir 
2549cdf0e10cSrcweir 			// we have a command and need to display this in the rowset
2550cdf0e10cSrcweir 			return implLoadAnything(_rDataSourceName, _rCommand, _nCommandType, _bEscapeProcessing, _rxConnection);
2551cdf0e10cSrcweir 		}
2552cdf0e10cSrcweir 	}
2553cdf0e10cSrcweir 	return sal_False;
2554cdf0e10cSrcweir }
2555cdf0e10cSrcweir 
2556cdf0e10cSrcweir //------------------------------------------------------------------------------
2557cdf0e10cSrcweir IMPL_LINK(SbaTableQueryBrowser, OnSelectionChange, void*, /*NOINTERESTEDIN*/)
2558cdf0e10cSrcweir {
2559cdf0e10cSrcweir     return implSelect( m_pTreeView->getListBox().FirstSelected() ) ? 1L : 0L;
2560cdf0e10cSrcweir }
2561cdf0e10cSrcweir //------------------------------------------------------------------------------
2562cdf0e10cSrcweir SvLBoxEntry* SbaTableQueryBrowser::implGetConnectionEntry(SvLBoxEntry* _pEntry) const
2563cdf0e10cSrcweir {
2564cdf0e10cSrcweir     SvLBoxEntry* pCurrentEntry = _pEntry;
2565cdf0e10cSrcweir     DBTreeListUserData* pEntryData = static_cast< DBTreeListUserData* >( pCurrentEntry->GetUserData() );
2566cdf0e10cSrcweir     while(pEntryData->eType != etDatasource )
2567cdf0e10cSrcweir     {
2568cdf0e10cSrcweir         pCurrentEntry = m_pTreeModel->GetParent(pCurrentEntry);
2569cdf0e10cSrcweir         pEntryData = static_cast< DBTreeListUserData* >( pCurrentEntry->GetUserData() );
2570cdf0e10cSrcweir     }
2571cdf0e10cSrcweir     return pCurrentEntry;
2572cdf0e10cSrcweir }
2573cdf0e10cSrcweir //------------------------------------------------------------------------------
2574cdf0e10cSrcweir bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry )
2575cdf0e10cSrcweir {
2576cdf0e10cSrcweir     if ( !_pEntry )
2577cdf0e10cSrcweir         return false;
2578cdf0e10cSrcweir 
2579cdf0e10cSrcweir 	DBTreeListUserData* pEntryData = static_cast< DBTreeListUserData* >( _pEntry->GetUserData() );
2580cdf0e10cSrcweir 	switch (pEntryData->eType)
2581cdf0e10cSrcweir 	{
2582cdf0e10cSrcweir 		case etTableOrView:
2583cdf0e10cSrcweir 		case etQuery:
2584cdf0e10cSrcweir 			break;
2585cdf0e10cSrcweir 		default:
2586cdf0e10cSrcweir 			// nothing to do
2587cdf0e10cSrcweir 			return false;
2588cdf0e10cSrcweir 	}
2589cdf0e10cSrcweir 
2590cdf0e10cSrcweir 	OSL_ENSURE(m_pTreeModel->HasParent(_pEntry), "SbaTableQueryBrowser::implSelect: invalid entry (1)!");
2591cdf0e10cSrcweir 	OSL_ENSURE(m_pTreeModel->HasParent(m_pTreeModel->GetParent(_pEntry)), "SbaTableQueryBrowser::implSelect: invalid entry (2)!");
2592cdf0e10cSrcweir 
2593cdf0e10cSrcweir 	// get the entry for the tables or queries
2594cdf0e10cSrcweir 	SvLBoxEntry* pContainer = m_pTreeModel->GetParent(_pEntry);
2595cdf0e10cSrcweir 	DBTreeListUserData* pContainerData = static_cast<DBTreeListUserData*>(pContainer->GetUserData());
2596cdf0e10cSrcweir 
2597cdf0e10cSrcweir 	// get the entry for the datasource
2598cdf0e10cSrcweir 	SvLBoxEntry* pConnection = implGetConnectionEntry(pContainer);
2599cdf0e10cSrcweir 	DBTreeListUserData* pConData = static_cast<DBTreeListUserData*>(pConnection->GetUserData());
2600cdf0e10cSrcweir 
2601cdf0e10cSrcweir 	// reinitialize the rowset
2602cdf0e10cSrcweir 	// but first check if it is necessary
2603cdf0e10cSrcweir 	// get all old properties
2604cdf0e10cSrcweir 	Reference<XPropertySet> xRowSetProps(getRowSet(),UNO_QUERY);
2605cdf0e10cSrcweir 	::rtl::OUString aOldName;
2606cdf0e10cSrcweir 	xRowSetProps->getPropertyValue(PROPERTY_COMMAND) >>= aOldName;
2607cdf0e10cSrcweir 	sal_Int32 nOldType = 0;
2608cdf0e10cSrcweir 	xRowSetProps->getPropertyValue(PROPERTY_COMMAND_TYPE) >>= nOldType;
2609cdf0e10cSrcweir 	Reference<XConnection> xOldConnection(xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION),UNO_QUERY);
2610cdf0e10cSrcweir 
2611cdf0e10cSrcweir 	// the name of the table or query
2612cdf0e10cSrcweir 	SvLBoxString* pString = (SvLBoxString*)_pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
2613cdf0e10cSrcweir 	OSL_ENSURE(pString,"There must be a string item!");
2614cdf0e10cSrcweir     const ::rtl::OUString sSimpleName = pString->GetText();
2615cdf0e10cSrcweir 	::rtl::OUStringBuffer sNameBuffer(sSimpleName);
2616cdf0e10cSrcweir     if ( etQueryContainer == pContainerData->eType )
2617cdf0e10cSrcweir     {
2618cdf0e10cSrcweir         SvLBoxEntry* pTemp = pContainer;
2619cdf0e10cSrcweir         while( m_pTreeModel->GetParent(pTemp) != pConnection )
2620cdf0e10cSrcweir         {
2621cdf0e10cSrcweir             sNameBuffer.insert(0,sal_Unicode('/'));
2622cdf0e10cSrcweir             pString = (SvLBoxString*)pTemp->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
2623cdf0e10cSrcweir 	        OSL_ENSURE(pString,"There must be a string item!");
2624cdf0e10cSrcweir 	        sNameBuffer.insert(0,pString->GetText());
2625cdf0e10cSrcweir             pTemp = m_pTreeModel->GetParent(pTemp);
2626cdf0e10cSrcweir         }
2627cdf0e10cSrcweir     }
2628cdf0e10cSrcweir     ::rtl::OUString aName = sNameBuffer.makeStringAndClear();
2629cdf0e10cSrcweir 
2630cdf0e10cSrcweir 	sal_Int32 nCommandType =	( etTableContainer == pContainerData->eType)
2631cdf0e10cSrcweir 							?	CommandType::TABLE
2632cdf0e10cSrcweir 							:	CommandType::QUERY;
2633cdf0e10cSrcweir 
2634cdf0e10cSrcweir 	// check if need to rebuild the rowset
2635cdf0e10cSrcweir 	sal_Bool bRebuild = ( xOldConnection != pConData->xConnection )
2636cdf0e10cSrcweir                      || ( nOldType != nCommandType )
2637cdf0e10cSrcweir                      || ( aName != aOldName );
2638cdf0e10cSrcweir 
2639cdf0e10cSrcweir 	Reference< ::com::sun::star::form::XLoadable >	xLoadable = getLoadable();
2640cdf0e10cSrcweir 	bRebuild |= !xLoadable->isLoaded();
2641cdf0e10cSrcweir     bool bSuccess = true;
2642cdf0e10cSrcweir 	if ( bRebuild )
2643cdf0e10cSrcweir 	{
2644cdf0e10cSrcweir 		try
2645cdf0e10cSrcweir 		{
2646cdf0e10cSrcweir 			WaitObject aWaitCursor(getBrowserView());
2647cdf0e10cSrcweir 
2648cdf0e10cSrcweir 			// tell the old entry it has been deselected
2649cdf0e10cSrcweir 			selectPath(m_pCurrentlyDisplayed, sal_False);
2650cdf0e10cSrcweir 			m_pCurrentlyDisplayed = NULL;
2651cdf0e10cSrcweir 
2652cdf0e10cSrcweir 			// not really loaded
2653cdf0e10cSrcweir 			m_pCurrentlyDisplayed = _pEntry;
2654cdf0e10cSrcweir 			// tell the new entry it has been selected
2655cdf0e10cSrcweir 			selectPath(m_pCurrentlyDisplayed, sal_True);
2656cdf0e10cSrcweir 
2657cdf0e10cSrcweir 			// get the name of the data source currently selected
2658cdf0e10cSrcweir 			ensureConnection( m_pCurrentlyDisplayed, pConData->xConnection );
2659cdf0e10cSrcweir 
2660cdf0e10cSrcweir 			if ( !pConData->xConnection.is() )
2661cdf0e10cSrcweir 			{
2662cdf0e10cSrcweir 				unloadAndCleanup( sal_False );
2663cdf0e10cSrcweir 				return false;
2664cdf0e10cSrcweir 			}
2665cdf0e10cSrcweir 
2666cdf0e10cSrcweir 			Reference<XNameAccess> xNameAccess;
2667cdf0e10cSrcweir 			switch(nCommandType)
2668cdf0e10cSrcweir 			{
2669cdf0e10cSrcweir 				case CommandType::TABLE:
2670cdf0e10cSrcweir 					{
2671cdf0e10cSrcweir 						// only for tables
2672cdf0e10cSrcweir 						if ( !pContainerData->xContainer.is() )
2673cdf0e10cSrcweir 						{
2674cdf0e10cSrcweir 							Reference<XTablesSupplier> xSup( pConData->xConnection, UNO_QUERY );
2675cdf0e10cSrcweir 							if(xSup.is())
2676cdf0e10cSrcweir 								xNameAccess = xSup->getTables();
2677cdf0e10cSrcweir 
2678cdf0e10cSrcweir 							pContainerData->xContainer = xNameAccess;
2679cdf0e10cSrcweir 						}
2680cdf0e10cSrcweir 						else
2681cdf0e10cSrcweir 							xNameAccess.set( pContainerData->xContainer, UNO_QUERY );
2682cdf0e10cSrcweir 					}
2683cdf0e10cSrcweir 					break;
2684cdf0e10cSrcweir 				case CommandType::QUERY:
2685cdf0e10cSrcweir 					{
2686cdf0e10cSrcweir                         if ( pContainerData->xContainer.is() )
2687cdf0e10cSrcweir                             xNameAccess.set( pContainerData->xContainer, UNO_QUERY );
2688cdf0e10cSrcweir                         else
2689cdf0e10cSrcweir                         {
2690cdf0e10cSrcweir 						    Reference<XQueriesSupplier> xSup( pConData->xConnection, UNO_QUERY );
2691cdf0e10cSrcweir 						    if(xSup.is())
2692cdf0e10cSrcweir 							    xNameAccess = xSup->getQueries();
2693cdf0e10cSrcweir                         }
2694cdf0e10cSrcweir 					}
2695cdf0e10cSrcweir 					break;
2696cdf0e10cSrcweir 			}
2697cdf0e10cSrcweir 			String sStatus(ModuleRes( CommandType::TABLE == nCommandType ? STR_LOADING_TABLE : STR_LOADING_QUERY ));
2698cdf0e10cSrcweir 			sStatus.SearchAndReplaceAscii("$name$", aName);
2699cdf0e10cSrcweir 			BrowserViewStatusDisplay aShowStatus(static_cast<UnoDataBrowserView*>(getView()), sStatus);
2700cdf0e10cSrcweir 
2701cdf0e10cSrcweir 
2702cdf0e10cSrcweir             sal_Bool bEscapeProcessing = sal_True;
2703cdf0e10cSrcweir 			if(xNameAccess.is() && xNameAccess->hasByName(sSimpleName))
2704cdf0e10cSrcweir 			{
2705cdf0e10cSrcweir 				DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData());
2706cdf0e10cSrcweir 				if ( !pData->xObjectProperties.is() )
2707cdf0e10cSrcweir 				{
2708cdf0e10cSrcweir 					Reference<XInterface> xObject;
2709cdf0e10cSrcweir 					if(xNameAccess->getByName(sSimpleName) >>= xObject) // remember the table or query object
2710cdf0e10cSrcweir 					{
2711cdf0e10cSrcweir 						pData->xObjectProperties = pData->xObjectProperties.query( xObject );
2712cdf0e10cSrcweir 						// if the query contains a parameterized statement and preview is enabled we won't get any data.
2713cdf0e10cSrcweir 						if ( nCommandType == CommandType::QUERY && xObject.is() )
2714cdf0e10cSrcweir 						{
2715cdf0e10cSrcweir 							Reference<XPropertySet> xObjectProps(xObject,UNO_QUERY);
2716cdf0e10cSrcweir                             xObjectProps->getPropertyValue(PROPERTY_ESCAPE_PROCESSING) >>= bEscapeProcessing;
2717cdf0e10cSrcweir                             if ( m_bPreview )
2718cdf0e10cSrcweir                             {
2719cdf0e10cSrcweir                                 ::rtl::OUString sSql;
2720cdf0e10cSrcweir 							    xObjectProps->getPropertyValue(PROPERTY_COMMAND) >>= sSql;
2721cdf0e10cSrcweir 							    Reference< XMultiServiceFactory >  xFactory( pConData->xConnection, UNO_QUERY );
2722cdf0e10cSrcweir 							    if (xFactory.is())
2723cdf0e10cSrcweir 							    {
2724cdf0e10cSrcweir 								    try
2725cdf0e10cSrcweir 								    {
2726cdf0e10cSrcweir 									    Reference<XSingleSelectQueryAnalyzer> xAnalyzer(xFactory->createInstance(SERVICE_NAME_SINGLESELECTQUERYCOMPOSER),UNO_QUERY);
2727cdf0e10cSrcweir 									    if ( xAnalyzer.is() )
2728cdf0e10cSrcweir 									    {
2729cdf0e10cSrcweir 										    xAnalyzer->setQuery(sSql);
2730cdf0e10cSrcweir 										    Reference<XParametersSupplier> xParSup(xAnalyzer,UNO_QUERY);
2731cdf0e10cSrcweir 										    if ( xParSup->getParameters()->getCount() > 0 )
2732cdf0e10cSrcweir 										    {
2733cdf0e10cSrcweir 											    String sFilter = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" WHERE "));
2734cdf0e10cSrcweir 											    sFilter = sFilter + xAnalyzer->getFilter();
2735cdf0e10cSrcweir 											    String sReplace(sSql);
2736cdf0e10cSrcweir 											    sReplace.SearchAndReplace(sFilter,String());
2737cdf0e10cSrcweir 											    xAnalyzer->setQuery(sReplace);
2738cdf0e10cSrcweir 											    Reference<XSingleSelectQueryComposer> xComposer(xAnalyzer,UNO_QUERY);
2739cdf0e10cSrcweir 											    xComposer->setFilter(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0=1")));
2740cdf0e10cSrcweir 											    aName = xAnalyzer->getQuery();
2741cdf0e10cSrcweir 											    nCommandType = CommandType::COMMAND;
2742cdf0e10cSrcweir 										    }
2743cdf0e10cSrcweir 									    }
2744cdf0e10cSrcweir 								    }
2745cdf0e10cSrcweir 								    catch (Exception&)
2746cdf0e10cSrcweir 								    {
2747cdf0e10cSrcweir                                         DBG_UNHANDLED_EXCEPTION();
2748cdf0e10cSrcweir 								    }
2749cdf0e10cSrcweir 							    }
2750cdf0e10cSrcweir                             }
2751cdf0e10cSrcweir 						}
2752cdf0e10cSrcweir 					}
2753cdf0e10cSrcweir 				}
2754cdf0e10cSrcweir 			}
2755cdf0e10cSrcweir 
2756cdf0e10cSrcweir 			String sDataSourceName( getDataSourceAcessor( pConnection ) );
2757cdf0e10cSrcweir 			bSuccess = implLoadAnything( sDataSourceName, aName, nCommandType, bEscapeProcessing, pConData->xConnection );
2758cdf0e10cSrcweir             if ( !bSuccess )
2759cdf0e10cSrcweir 			{	// clean up
2760cdf0e10cSrcweir 				criticalFail();
2761cdf0e10cSrcweir 			}
2762cdf0e10cSrcweir 		}
2763cdf0e10cSrcweir 		catch(const SQLException& e)
2764cdf0e10cSrcweir 		{
2765cdf0e10cSrcweir 			showError(SQLExceptionInfo(e));
2766cdf0e10cSrcweir 			// reset the values
2767cdf0e10cSrcweir 			xRowSetProps->setPropertyValue(PROPERTY_DATASOURCENAME,Any());
2768cdf0e10cSrcweir 			xRowSetProps->setPropertyValue(PROPERTY_ACTIVE_CONNECTION,Any());
2769cdf0e10cSrcweir 		}
2770cdf0e10cSrcweir 		catch(WrappedTargetException& e)
2771cdf0e10cSrcweir 		{
2772cdf0e10cSrcweir 			SQLException aSql;
2773cdf0e10cSrcweir 			if(e.TargetException >>= aSql)
2774cdf0e10cSrcweir 				showError(SQLExceptionInfo(aSql));
2775cdf0e10cSrcweir 			else
2776cdf0e10cSrcweir 				OSL_ENSURE(sal_False, "SbaTableQueryBrowser::implSelect: something strange happended!");
2777cdf0e10cSrcweir 			// reset the values
2778cdf0e10cSrcweir 			xRowSetProps->setPropertyValue(PROPERTY_DATASOURCENAME,Any());
2779cdf0e10cSrcweir 			xRowSetProps->setPropertyValue(PROPERTY_ACTIVE_CONNECTION,Any());
2780cdf0e10cSrcweir 		}
2781cdf0e10cSrcweir 		catch(Exception&)
2782cdf0e10cSrcweir 		{
2783cdf0e10cSrcweir 			// reset the values
2784cdf0e10cSrcweir 			xRowSetProps->setPropertyValue(PROPERTY_DATASOURCENAME,Any());
2785cdf0e10cSrcweir 			xRowSetProps->setPropertyValue(PROPERTY_ACTIVE_CONNECTION,Any());
2786cdf0e10cSrcweir 		}
2787cdf0e10cSrcweir 	}
2788cdf0e10cSrcweir 	return bSuccess;
2789cdf0e10cSrcweir }
2790cdf0e10cSrcweir 
2791cdf0e10cSrcweir // -----------------------------------------------------------------------------
2792cdf0e10cSrcweir SvLBoxEntry* SbaTableQueryBrowser::getEntryFromContainer(const Reference<XNameAccess>& _rxNameAccess)
2793cdf0e10cSrcweir {
2794cdf0e10cSrcweir 	DBTreeListBox& rListBox = m_pTreeView->getListBox();
2795cdf0e10cSrcweir 	SvLBoxEntry* pContainer = NULL;
2796cdf0e10cSrcweir 	SvLBoxEntry* pDSLoop = rListBox.FirstChild(NULL);
2797cdf0e10cSrcweir 	while (pDSLoop)
2798cdf0e10cSrcweir 	{
2799cdf0e10cSrcweir 		pContainer	= rListBox.GetEntry(pDSLoop, CONTAINER_QUERIES);
2800cdf0e10cSrcweir 		DBTreeListUserData* pQueriesData = static_cast<DBTreeListUserData*>(pContainer->GetUserData());
2801cdf0e10cSrcweir 		if ( pQueriesData && pQueriesData->xContainer == _rxNameAccess )
2802cdf0e10cSrcweir 			break;
2803cdf0e10cSrcweir 
2804cdf0e10cSrcweir 		pContainer	= rListBox.GetEntry(pDSLoop, CONTAINER_TABLES);
2805cdf0e10cSrcweir 		DBTreeListUserData* pTablesData = static_cast<DBTreeListUserData*>(pContainer->GetUserData());
2806cdf0e10cSrcweir 		if ( pTablesData && pTablesData->xContainer == _rxNameAccess )
2807cdf0e10cSrcweir 			break;
2808cdf0e10cSrcweir 
2809cdf0e10cSrcweir 		pDSLoop 	= rListBox.NextSibling(pDSLoop);
2810cdf0e10cSrcweir 		pContainer	= NULL;
2811cdf0e10cSrcweir 	}
2812cdf0e10cSrcweir 	return pContainer;
2813cdf0e10cSrcweir }
2814cdf0e10cSrcweir 
2815cdf0e10cSrcweir // -------------------------------------------------------------------------
2816cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
2817cdf0e10cSrcweir {
2818cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
2819cdf0e10cSrcweir 
2820cdf0e10cSrcweir 	Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
2821cdf0e10cSrcweir 	// first search for a definition container where we can insert this element
2822cdf0e10cSrcweir 
2823cdf0e10cSrcweir 	SvLBoxEntry* pEntry = getEntryFromContainer(xNames);
2824cdf0e10cSrcweir 	if(pEntry)	// found one
2825cdf0e10cSrcweir 	{
2826cdf0e10cSrcweir 		// insert the new entry into the tree
2827cdf0e10cSrcweir 		DBTreeListUserData* pContainerData = static_cast<DBTreeListUserData*>(pEntry->GetUserData());
2828cdf0e10cSrcweir 		OSL_ENSURE(pContainerData, "elementInserted: There must be user data for this type!");
2829cdf0e10cSrcweir 
2830cdf0e10cSrcweir 		DBTreeListUserData* pNewData = new DBTreeListUserData;
2831cdf0e10cSrcweir 		sal_Bool bIsTable = etTableContainer == pContainerData->eType;
2832cdf0e10cSrcweir 		if ( bIsTable )
2833cdf0e10cSrcweir 		{
2834cdf0e10cSrcweir 			_rEvent.Element >>= pNewData->xObjectProperties;// remember the new element
2835cdf0e10cSrcweir 			pNewData->eType = etTableOrView;
2836cdf0e10cSrcweir 		}
2837cdf0e10cSrcweir 		else
2838cdf0e10cSrcweir 		{
2839cdf0e10cSrcweir 			if ((sal_Int32)m_pTreeView->getListBox().GetChildCount(pEntry) < ( xNames->getElementNames().getLength() - 1 ) )
2840cdf0e10cSrcweir 			{
2841cdf0e10cSrcweir 				// the item inserts its children on demand, but it has not been expanded yet. So ensure here and
2842cdf0e10cSrcweir 				// now that it has all items
2843cdf0e10cSrcweir 				populateTree(xNames, pEntry, etQuery );
2844cdf0e10cSrcweir 			}
2845cdf0e10cSrcweir             pNewData->eType = etQuery;
2846cdf0e10cSrcweir 		}
2847cdf0e10cSrcweir         implAppendEntry( pEntry, ::comphelper::getString( _rEvent.Accessor ), pNewData, pNewData->eType );
2848cdf0e10cSrcweir 	}
2849cdf0e10cSrcweir 	else
2850cdf0e10cSrcweir 		SbaXDataBrowserController::elementInserted(_rEvent);
2851cdf0e10cSrcweir }
2852cdf0e10cSrcweir // -------------------------------------------------------------------------
2853cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::isCurrentlyDisplayedChanged(const String& _sName,SvLBoxEntry* _pContainer)
2854cdf0e10cSrcweir {
2855cdf0e10cSrcweir 	return m_pCurrentlyDisplayed
2856cdf0e10cSrcweir 			&&	getEntryType(m_pCurrentlyDisplayed) == getChildType(_pContainer)
2857cdf0e10cSrcweir 			&&	m_pTreeView->getListBox().GetParent(m_pCurrentlyDisplayed) == _pContainer
2858cdf0e10cSrcweir 			&&	m_pTreeView->getListBox().GetEntryText(m_pCurrentlyDisplayed) == _sName;
2859cdf0e10cSrcweir }
2860cdf0e10cSrcweir // -------------------------------------------------------------------------
2861cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
2862cdf0e10cSrcweir {
2863cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
2864cdf0e10cSrcweir 
2865cdf0e10cSrcweir 	Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
2866cdf0e10cSrcweir 	// get the top-level representing the removed data source
2867cdf0e10cSrcweir 	// and search for the queries and tables
2868cdf0e10cSrcweir 	SvLBoxEntry* pContainer = getEntryFromContainer(xNames);
2869cdf0e10cSrcweir 	if ( pContainer )
2870cdf0e10cSrcweir 	{ // a query or table has been removed
2871cdf0e10cSrcweir 		String aName = ::comphelper::getString(_rEvent.Accessor).getStr();
2872cdf0e10cSrcweir 
2873cdf0e10cSrcweir 		if ( isCurrentlyDisplayedChanged( aName, pContainer) )
2874cdf0e10cSrcweir 		{	// the element displayed currently has been replaced
2875cdf0e10cSrcweir 
2876cdf0e10cSrcweir 			// we need to remember the old value
2877cdf0e10cSrcweir 			SvLBoxEntry* pTemp = m_pCurrentlyDisplayed;
2878cdf0e10cSrcweir 
2879cdf0e10cSrcweir 			// unload
2880cdf0e10cSrcweir 			unloadAndCleanup( sal_False ); // don't dispose the connection
2881cdf0e10cSrcweir 
2882cdf0e10cSrcweir 			DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pTemp->GetUserData());
2883cdf0e10cSrcweir 			pTemp->SetUserData(NULL);
2884cdf0e10cSrcweir 			delete pData;
2885cdf0e10cSrcweir 				// the data could be null because we have a table which isn't correct
2886cdf0e10cSrcweir 			m_pTreeModel->Remove(pTemp);
2887cdf0e10cSrcweir 		}
2888cdf0e10cSrcweir 		else
2889cdf0e10cSrcweir 		{
2890cdf0e10cSrcweir 			// remove the entry from the model
2891cdf0e10cSrcweir 			SvLBoxEntry* pChild = m_pTreeModel->FirstChild(pContainer);
2892cdf0e10cSrcweir 			while(pChild)
2893cdf0e10cSrcweir 			{
2894cdf0e10cSrcweir 				if (m_pTreeView->getListBox().GetEntryText(pChild) == aName)
2895cdf0e10cSrcweir 				{
2896cdf0e10cSrcweir 					DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pChild->GetUserData());
2897cdf0e10cSrcweir 					pChild->SetUserData(NULL);
2898cdf0e10cSrcweir 					delete pData;
2899cdf0e10cSrcweir 					m_pTreeModel->Remove(pChild);
2900cdf0e10cSrcweir 					break;
2901cdf0e10cSrcweir 				}
2902cdf0e10cSrcweir 				pChild = m_pTreeModel->NextSibling(pChild);
2903cdf0e10cSrcweir 			}
2904cdf0e10cSrcweir 		}
2905cdf0e10cSrcweir 
2906cdf0e10cSrcweir 		// maybe the object which is part of the document data source has been removed
2907cdf0e10cSrcweir 		checkDocumentDataSource();
2908cdf0e10cSrcweir 	}
2909cdf0e10cSrcweir 	else
2910cdf0e10cSrcweir 		SbaXDataBrowserController::elementRemoved(_rEvent);
2911cdf0e10cSrcweir }
2912cdf0e10cSrcweir 
2913cdf0e10cSrcweir // -------------------------------------------------------------------------
2914cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
2915cdf0e10cSrcweir {
2916cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
2917cdf0e10cSrcweir 
2918cdf0e10cSrcweir 	Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
2919cdf0e10cSrcweir 	SvLBoxEntry* pContainer = getEntryFromContainer(xNames);
2920cdf0e10cSrcweir 	if ( pContainer )
2921cdf0e10cSrcweir 	{	 // a table or query as been replaced
2922cdf0e10cSrcweir 		String aName = ::comphelper::getString(_rEvent.Accessor).getStr();
2923cdf0e10cSrcweir 
2924cdf0e10cSrcweir 		if ( isCurrentlyDisplayedChanged( aName, pContainer) )
2925cdf0e10cSrcweir 		{	// the element displayed currently has been replaced
2926cdf0e10cSrcweir 
2927cdf0e10cSrcweir 			// we need to remember the old value
2928cdf0e10cSrcweir 			SvLBoxEntry* pTemp = m_pCurrentlyDisplayed;
2929cdf0e10cSrcweir 			unloadAndCleanup( sal_False ); // don't dispose the connection
2930cdf0e10cSrcweir 
2931cdf0e10cSrcweir 			DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pTemp->GetUserData());
2932cdf0e10cSrcweir 			if (pData)
2933cdf0e10cSrcweir 			{
2934cdf0e10cSrcweir 				if ( etTableOrView == pData->eType )
2935cdf0e10cSrcweir 				{ // only insert userdata when we have a table because the query is only a commanddefinition object and not a query
2936cdf0e10cSrcweir 					 _rEvent.Element >>= pData->xObjectProperties;  // remember the new element
2937cdf0e10cSrcweir 				}
2938cdf0e10cSrcweir 				else
2939cdf0e10cSrcweir 				{
2940cdf0e10cSrcweir 					pTemp->SetUserData(NULL);
2941cdf0e10cSrcweir 					delete pData;
2942cdf0e10cSrcweir 				}
2943cdf0e10cSrcweir 			}
2944cdf0e10cSrcweir 		}
2945cdf0e10cSrcweir 		else
2946cdf0e10cSrcweir 		{
2947cdf0e10cSrcweir 			// find the entry for this name
2948cdf0e10cSrcweir 			SvLBoxEntry* pChild = m_pTreeModel->FirstChild(pContainer);
2949cdf0e10cSrcweir 			while(pChild)
2950cdf0e10cSrcweir 			{
2951cdf0e10cSrcweir 				if (m_pTreeView->getListBox().GetEntryText(pChild) == aName)
2952cdf0e10cSrcweir 				{
2953cdf0e10cSrcweir 					DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pChild->GetUserData());
2954cdf0e10cSrcweir 					if (pData)
2955cdf0e10cSrcweir 					{
2956cdf0e10cSrcweir 						if ( etTableOrView == pData->eType )
2957cdf0e10cSrcweir 						{ // only insert userdata when we have a table because the query is only a commanddefinition object and not a query
2958cdf0e10cSrcweir 							_rEvent.Element >>= pData->xObjectProperties;   // remember the new element
2959cdf0e10cSrcweir 						}
2960cdf0e10cSrcweir 						else
2961cdf0e10cSrcweir 						{
2962cdf0e10cSrcweir 							pChild->SetUserData(NULL);
2963cdf0e10cSrcweir 							delete pData;
2964cdf0e10cSrcweir 						}
2965cdf0e10cSrcweir 					}
2966cdf0e10cSrcweir 					break;
2967cdf0e10cSrcweir 				}
2968cdf0e10cSrcweir 				pChild = m_pTreeModel->NextSibling(pChild);
2969cdf0e10cSrcweir 			}
2970cdf0e10cSrcweir 		}
2971cdf0e10cSrcweir 
2972cdf0e10cSrcweir 		// maybe the object which is part of the document data source has been removed
2973cdf0e10cSrcweir 		checkDocumentDataSource();
2974cdf0e10cSrcweir 	}
2975cdf0e10cSrcweir 	else if (xNames.get() == m_xDatabaseContext.get())
2976cdf0e10cSrcweir 	{	// a datasource has been replaced in the context
2977cdf0e10cSrcweir 		DBG_ERROR("SbaTableQueryBrowser::elementReplaced: no support for replaced data sources!");
2978cdf0e10cSrcweir 			// very suspicious: the database context should not allow to replace data source, only to register
2979cdf0e10cSrcweir 			// and revoke them
2980cdf0e10cSrcweir 	}
2981cdf0e10cSrcweir 	else
2982cdf0e10cSrcweir 		SbaXDataBrowserController::elementReplaced(_rEvent);
2983cdf0e10cSrcweir }
2984cdf0e10cSrcweir 
2985cdf0e10cSrcweir // -------------------------------------------------------------------------
2986cdf0e10cSrcweir void SbaTableQueryBrowser::impl_releaseConnection( SharedConnection& _rxConnection )
2987cdf0e10cSrcweir {
2988cdf0e10cSrcweir 	// remove as event listener
2989cdf0e10cSrcweir 	Reference< XComponent > xComponent( _rxConnection, UNO_QUERY );
2990cdf0e10cSrcweir 	if ( xComponent.is() )
2991cdf0e10cSrcweir 	{
2992cdf0e10cSrcweir 		Reference< XEventListener > xListener( static_cast< ::cppu::OWeakObject* >( this ), UNO_QUERY );
2993cdf0e10cSrcweir 		xComponent->removeEventListener( xListener );
2994cdf0e10cSrcweir 	}
2995cdf0e10cSrcweir 
2996cdf0e10cSrcweir     try
2997cdf0e10cSrcweir     {
2998cdf0e10cSrcweir         // temporary (hopefully!) hack for #i55274#
2999cdf0e10cSrcweir         Reference< XFlushable > xFlush( _rxConnection, UNO_QUERY );
3000cdf0e10cSrcweir         if ( xFlush.is() )
3001cdf0e10cSrcweir             xFlush->flush();
3002cdf0e10cSrcweir     }
3003cdf0e10cSrcweir     catch( const Exception& )
3004cdf0e10cSrcweir     {
3005cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
3006cdf0e10cSrcweir     }
3007cdf0e10cSrcweir 
3008cdf0e10cSrcweir 	// clear
3009cdf0e10cSrcweir 	_rxConnection.clear();
3010cdf0e10cSrcweir         // will implicitly dispose if we have the ownership, since xConnection is a SharedConnection
3011cdf0e10cSrcweir }
3012cdf0e10cSrcweir 
3013cdf0e10cSrcweir // -------------------------------------------------------------------------
3014cdf0e10cSrcweir void SbaTableQueryBrowser::disposeConnection( SvLBoxEntry* _pDSEntry )
3015cdf0e10cSrcweir {
3016cdf0e10cSrcweir 	DBG_ASSERT( _pDSEntry, "SbaTableQueryBrowser::disposeConnection: invalid entry (NULL)!" );
3017cdf0e10cSrcweir 	DBG_ASSERT( impl_isDataSourceEntry( _pDSEntry ), "SbaTableQueryBrowser::disposeConnection: invalid entry (not top-level)!" );
3018cdf0e10cSrcweir 
3019cdf0e10cSrcweir 	if ( _pDSEntry )
3020cdf0e10cSrcweir 	{
3021cdf0e10cSrcweir 		DBTreeListUserData* pTreeListData = static_cast< DBTreeListUserData* >( _pDSEntry->GetUserData() );
3022cdf0e10cSrcweir 		if ( pTreeListData )
3023cdf0e10cSrcweir             impl_releaseConnection( pTreeListData->xConnection );
3024cdf0e10cSrcweir 	}
3025cdf0e10cSrcweir }
3026cdf0e10cSrcweir 
3027cdf0e10cSrcweir // -------------------------------------------------------------------------
3028cdf0e10cSrcweir void SbaTableQueryBrowser::closeConnection(SvLBoxEntry* _pDSEntry,sal_Bool _bDisposeConnection)
3029cdf0e10cSrcweir {
3030cdf0e10cSrcweir 	DBG_ASSERT(_pDSEntry, "SbaTableQueryBrowser::closeConnection: invalid entry (NULL)!");
3031cdf0e10cSrcweir 	DBG_ASSERT( impl_isDataSourceEntry( _pDSEntry ), "SbaTableQueryBrowser::closeConnection: invalid entry (not top-level)!");
3032cdf0e10cSrcweir 
3033cdf0e10cSrcweir 	// if one of the entries of the given DS is displayed currently, unload the form
3034cdf0e10cSrcweir 	if (m_pCurrentlyDisplayed && (m_pTreeView->getListBox().GetRootLevelParent(m_pCurrentlyDisplayed) == _pDSEntry))
3035cdf0e10cSrcweir 		unloadAndCleanup(_bDisposeConnection);
3036cdf0e10cSrcweir 
3037cdf0e10cSrcweir 	// collapse the query/table container
3038cdf0e10cSrcweir 	for (SvLBoxEntry* pContainers = m_pTreeModel->FirstChild(_pDSEntry); pContainers; pContainers= m_pTreeModel->NextSibling(pContainers))
3039cdf0e10cSrcweir 	{
3040cdf0e10cSrcweir 		SvLBoxEntry* pElements = m_pTreeModel->FirstChild(pContainers);
3041cdf0e10cSrcweir 		if ( pElements )
3042cdf0e10cSrcweir 			m_pTreeView->getListBox().Collapse(pContainers);
3043cdf0e10cSrcweir 		m_pTreeView->getListBox().EnableExpandHandler(pContainers);
3044cdf0e10cSrcweir 		// and delete their children (they are connection-relative)
3045cdf0e10cSrcweir 		for (; pElements; )
3046cdf0e10cSrcweir 		{
3047cdf0e10cSrcweir 			SvLBoxEntry* pRemove = pElements;
3048cdf0e10cSrcweir 			pElements= m_pTreeModel->NextSibling(pElements);
3049cdf0e10cSrcweir 			DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pRemove->GetUserData());
3050cdf0e10cSrcweir 			pRemove->SetUserData(NULL);
3051cdf0e10cSrcweir 			delete pData;
3052cdf0e10cSrcweir 			m_pTreeModel->Remove(pRemove);
3053cdf0e10cSrcweir 		}
3054cdf0e10cSrcweir 	}
3055cdf0e10cSrcweir 	// collapse the entry itself
3056cdf0e10cSrcweir 	m_pTreeView->getListBox().Collapse(_pDSEntry);
3057cdf0e10cSrcweir 
3058cdf0e10cSrcweir 	// dispose/reset the connection
3059cdf0e10cSrcweir 	if ( _bDisposeConnection )
3060cdf0e10cSrcweir 		disposeConnection( _pDSEntry );
3061cdf0e10cSrcweir }
3062cdf0e10cSrcweir 
3063cdf0e10cSrcweir // -------------------------------------------------------------------------
3064cdf0e10cSrcweir void SbaTableQueryBrowser::unloadAndCleanup( sal_Bool _bDisposeConnection )
3065cdf0e10cSrcweir {
3066cdf0e10cSrcweir 	if (!m_pCurrentlyDisplayed)
3067cdf0e10cSrcweir 		// nothing to do
3068cdf0e10cSrcweir 		return;
3069cdf0e10cSrcweir 
3070cdf0e10cSrcweir 	SvLBoxEntry* pDSEntry = m_pTreeView->getListBox().GetRootLevelParent(m_pCurrentlyDisplayed);
3071cdf0e10cSrcweir 
3072cdf0e10cSrcweir 	// de-select the path for the currently displayed table/query
3073cdf0e10cSrcweir 	if (m_pCurrentlyDisplayed)
3074cdf0e10cSrcweir 	{
3075cdf0e10cSrcweir 		selectPath(m_pCurrentlyDisplayed, sal_False);
3076cdf0e10cSrcweir 	}
3077cdf0e10cSrcweir 	m_pCurrentlyDisplayed = NULL;
3078cdf0e10cSrcweir 
3079cdf0e10cSrcweir 	try
3080cdf0e10cSrcweir 	{
3081cdf0e10cSrcweir 		// get the active connection. We need to dispose it.
3082cdf0e10cSrcweir 		Reference< XPropertySet > xRowSetProps(getRowSet(),UNO_QUERY);
3083cdf0e10cSrcweir 		Reference< XConnection > xConn;
3084cdf0e10cSrcweir 		xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION) >>= xConn;
3085cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
3086cdf0e10cSrcweir 		{
3087cdf0e10cSrcweir 			Reference< XComponent > xComp;
3088cdf0e10cSrcweir 			::cppu::extractInterface(xComp, xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION));
3089cdf0e10cSrcweir 		}
3090cdf0e10cSrcweir #endif
3091cdf0e10cSrcweir 
3092cdf0e10cSrcweir 		// unload the form
3093cdf0e10cSrcweir 		Reference< XLoadable > xLoadable = getLoadable();
3094cdf0e10cSrcweir 		if (xLoadable->isLoaded())
3095cdf0e10cSrcweir 			xLoadable->unload();
3096cdf0e10cSrcweir 
3097cdf0e10cSrcweir 		// clear the grid control
3098cdf0e10cSrcweir 		Reference< XNameContainer > xConta(getControlModel(),UNO_QUERY);
3099cdf0e10cSrcweir 		clearGridColumns(xConta);
3100cdf0e10cSrcweir 
3101cdf0e10cSrcweir 		// dispose the connection
3102cdf0e10cSrcweir 		if(_bDisposeConnection)
3103cdf0e10cSrcweir 			disposeConnection( pDSEntry );
3104cdf0e10cSrcweir 	}
3105cdf0e10cSrcweir 	catch(SQLException& e)
3106cdf0e10cSrcweir 	{
3107cdf0e10cSrcweir 		showError(SQLExceptionInfo(e));
3108cdf0e10cSrcweir 	}
3109cdf0e10cSrcweir 	catch(WrappedTargetException& e)
3110cdf0e10cSrcweir 	{
3111cdf0e10cSrcweir 		SQLException aSql;
3112cdf0e10cSrcweir 		if(e.TargetException >>= aSql)
3113cdf0e10cSrcweir 			showError(SQLExceptionInfo(aSql));
3114cdf0e10cSrcweir 		else
3115cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "SbaTableQueryBrowser::unloadAndCleanup: something strange happended!");
3116cdf0e10cSrcweir 	}
3117cdf0e10cSrcweir 	catch(Exception&)
3118cdf0e10cSrcweir 	{
3119cdf0e10cSrcweir 		OSL_ENSURE(sal_False, "SbaTableQueryBrowser::unloadAndCleanup: could not reset the form");
3120cdf0e10cSrcweir 	}
3121cdf0e10cSrcweir }
3122cdf0e10cSrcweir 
3123cdf0e10cSrcweir // -------------------------------------------------------------------------
3124cdf0e10cSrcweir namespace
3125cdf0e10cSrcweir {
3126cdf0e10cSrcweir     Reference< XInterface > lcl_getDataSource( const Reference< XNameAccess >& _rxDatabaseContext,
3127cdf0e10cSrcweir         const ::rtl::OUString& _rDataSourceName, const Reference< XConnection >& _rxConnection )
3128cdf0e10cSrcweir     {
3129cdf0e10cSrcweir         Reference< XDataSource > xDataSource;
3130cdf0e10cSrcweir         try
3131cdf0e10cSrcweir         {
3132cdf0e10cSrcweir             if ( _rDataSourceName.getLength() && _rxDatabaseContext->hasByName( _rDataSourceName ) )
3133cdf0e10cSrcweir                 xDataSource.set( _rxDatabaseContext->getByName( _rDataSourceName ), UNO_QUERY_THROW );
3134cdf0e10cSrcweir 
3135cdf0e10cSrcweir             if ( !xDataSource.is() )
3136cdf0e10cSrcweir             {
3137cdf0e10cSrcweir                 Reference< XChild > xConnAsChild( _rxConnection, UNO_QUERY );
3138cdf0e10cSrcweir                 if ( xConnAsChild.is() )
3139cdf0e10cSrcweir                     xDataSource.set( xConnAsChild->getParent(), UNO_QUERY_THROW );
3140cdf0e10cSrcweir             }
3141cdf0e10cSrcweir         }
3142cdf0e10cSrcweir         catch( const Exception& )
3143cdf0e10cSrcweir         {
3144cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
3145cdf0e10cSrcweir         }
3146cdf0e10cSrcweir         return xDataSource.get();
3147cdf0e10cSrcweir     }
3148cdf0e10cSrcweir }
3149cdf0e10cSrcweir 
3150cdf0e10cSrcweir // -------------------------------------------------------------------------
3151cdf0e10cSrcweir void SbaTableQueryBrowser::impl_initialize()
3152cdf0e10cSrcweir {
3153cdf0e10cSrcweir 	::vos::OGuard aGuard(Application::GetSolarMutex());
3154cdf0e10cSrcweir 		// doin' a lot of VCL stuff here -> lock the SolarMutex
3155cdf0e10cSrcweir 
3156cdf0e10cSrcweir 	// first initialize the parent
3157cdf0e10cSrcweir 	SbaXDataBrowserController::impl_initialize();
3158cdf0e10cSrcweir 
3159cdf0e10cSrcweir 	Reference<XConnection> xForeignConnection;
3160cdf0e10cSrcweir 	Reference< XFrame > xFrame;
3161cdf0e10cSrcweir 
3162cdf0e10cSrcweir 	::rtl::OUString aTableName, aCatalogName, aSchemaName;
3163cdf0e10cSrcweir 
3164cdf0e10cSrcweir 	sal_Bool bEsacpeProcessing = sal_True;
3165cdf0e10cSrcweir 	sal_Int32 nInitialDisplayCommandType = CommandType::COMMAND;
3166cdf0e10cSrcweir 	::rtl::OUString sInitialDataSourceName;
3167cdf0e10cSrcweir 	::rtl::OUString sInitialCommand;
3168cdf0e10cSrcweir 
3169cdf0e10cSrcweir     const NamedValueCollection& rArguments( getInitParams() );
3170cdf0e10cSrcweir 
3171cdf0e10cSrcweir     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_DATASOURCENAME, sInitialDataSourceName );
3172cdf0e10cSrcweir     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_COMMAND_TYPE, nInitialDisplayCommandType );
3173cdf0e10cSrcweir     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_COMMAND, sInitialCommand );
3174cdf0e10cSrcweir     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, xForeignConnection );
3175cdf0e10cSrcweir     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_UPDATE_CATALOGNAME, aCatalogName );
3176cdf0e10cSrcweir     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_UPDATE_SCHEMANAME, aSchemaName );
3177cdf0e10cSrcweir     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_UPDATE_TABLENAME, aTableName );
3178cdf0e10cSrcweir     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, bEsacpeProcessing );
3179cdf0e10cSrcweir     rArguments.get_ensureType( "Frame", xFrame );
3180cdf0e10cSrcweir     rArguments.get_ensureType( (::rtl::OUString)PROPERTY_SHOWMENU, m_bShowMenu );
3181cdf0e10cSrcweir 
3182cdf0e10cSrcweir     // disable the browser if either of ShowTreeViewButton (compatibility name) or EnableBrowser
3183cdf0e10cSrcweir     // is present and set to FALSE
3184cdf0e10cSrcweir     sal_Bool bDisableBrowser =  ( sal_False == rArguments.getOrDefault( "ShowTreeViewButton", sal_True ) )   // compatibility name
3185cdf0e10cSrcweir                             ||  ( sal_False == rArguments.getOrDefault( (::rtl::OUString)PROPERTY_ENABLE_BROWSER, sal_True ) );
3186cdf0e10cSrcweir     OSL_ENSURE( !rArguments.has( "ShowTreeViewButton" ),
3187cdf0e10cSrcweir         "SbaTableQueryBrowser::impl_initialize: ShowTreeViewButton is superseded by EnableBrowser!" );
3188cdf0e10cSrcweir     m_bEnableBrowser = !bDisableBrowser;
3189cdf0e10cSrcweir 
3190cdf0e10cSrcweir     // hide the tree view it is disabled in general, or if the settings tell to hide it initially
3191cdf0e10cSrcweir     sal_Bool bHideTreeView =    ( !m_bEnableBrowser )
3192cdf0e10cSrcweir                             ||  ( sal_False == rArguments.getOrDefault( "ShowTreeView", sal_True ) )  // compatibility name
3193cdf0e10cSrcweir                             ||  ( sal_False == rArguments.getOrDefault( (::rtl::OUString)PROPERTY_SHOW_BROWSER, sal_True ) );
3194cdf0e10cSrcweir     OSL_ENSURE( !rArguments.has( "ShowTreeView" ),
3195cdf0e10cSrcweir         "SbaTableQueryBrowser::impl_initialize: ShowTreeView is superseded by ShowBrowser!" );
3196cdf0e10cSrcweir 
3197cdf0e10cSrcweir     if ( bHideTreeView )
3198cdf0e10cSrcweir         hideExplorer();
3199cdf0e10cSrcweir     else
3200cdf0e10cSrcweir         showExplorer();
3201cdf0e10cSrcweir 
3202cdf0e10cSrcweir 	if ( m_bPreview )
3203cdf0e10cSrcweir 	{
3204cdf0e10cSrcweir 		try
3205cdf0e10cSrcweir 		{
3206cdf0e10cSrcweir 			Sequence< ::rtl::OUString> aProperties(5);
3207cdf0e10cSrcweir 			Sequence< Any> aValues(5);
3208cdf0e10cSrcweir 
3209cdf0e10cSrcweir 			::rtl::OUString* pStringIter = aProperties.getArray();
3210cdf0e10cSrcweir 			Any* pValueIter = aValues.getArray();
3211cdf0e10cSrcweir 			*pStringIter++	= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AlwaysShowCursor"));
3212cdf0e10cSrcweir 			*pValueIter++	<<= sal_False;
3213cdf0e10cSrcweir 			*pStringIter++	= PROPERTY_BORDER;
3214cdf0e10cSrcweir 			*pValueIter++	<<= sal_Int16(0);
3215cdf0e10cSrcweir 
3216cdf0e10cSrcweir 			*pStringIter++	= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasNavigationBar"));
3217cdf0e10cSrcweir 			*pValueIter++		<<= sal_False;
3218cdf0e10cSrcweir 			*pStringIter++	= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasRecordMarker"));
3219cdf0e10cSrcweir 			*pValueIter++		<<= sal_False;
3220cdf0e10cSrcweir 
3221cdf0e10cSrcweir 			*pStringIter++	= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tabstop"));
3222cdf0e10cSrcweir 			*pValueIter++		<<= sal_False;
3223cdf0e10cSrcweir 
3224cdf0e10cSrcweir 			Reference< XMultiPropertySet >	xFormMultiSet(getFormComponent(), UNO_QUERY);
3225cdf0e10cSrcweir 			if ( xFormMultiSet.is() )
3226cdf0e10cSrcweir 				xFormMultiSet->setPropertyValues(aProperties, aValues);
3227cdf0e10cSrcweir 		}
3228cdf0e10cSrcweir 		catch(Exception)
3229cdf0e10cSrcweir 		{
3230cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
3231cdf0e10cSrcweir 		}
3232cdf0e10cSrcweir 	}
3233cdf0e10cSrcweir 
3234cdf0e10cSrcweir     // are we loaded into a (sub)frame of an embedded document (i.e. a form belonging to a database
3235cdf0e10cSrcweir     // document)?
3236cdf0e10cSrcweir 	sal_Bool bSubFrameOfEmbeddedDocument = sal_False;
3237cdf0e10cSrcweir 	if ( xFrame.is() )
3238cdf0e10cSrcweir 	{
3239cdf0e10cSrcweir 		Reference<XFramesSupplier> xSup = xFrame->getCreator();
3240cdf0e10cSrcweir 		Reference<XController> xCont = xSup.is() ? xSup->getController() : Reference<XController>();
3241cdf0e10cSrcweir 
3242cdf0e10cSrcweir         bSubFrameOfEmbeddedDocument = xCont.is() && ::dbtools::isEmbeddedInDatabase( xCont->getModel(), xForeignConnection );
3243cdf0e10cSrcweir 	}
3244cdf0e10cSrcweir 
3245cdf0e10cSrcweir     // if we have a connection at this point, it was either passed from outside, our
3246cdf0e10cSrcweir     // determined from a outer DB document. In both cases, do not dispose it later on.
3247cdf0e10cSrcweir     SharedConnection xConnection( xForeignConnection, SharedConnection::NoTakeOwnership );
3248cdf0e10cSrcweir 
3249cdf0e10cSrcweir     // should we display all registered databases in the left hand side tree?
3250cdf0e10cSrcweir     // or only *one* special?
3251cdf0e10cSrcweir     sal_Bool bLimitedTreeEntries = sal_False;
3252cdf0e10cSrcweir     // if we're part of a frame which is a secondary frame of a database document, then only
3253cdf0e10cSrcweir     // display the database for this document, not all registered ones
3254cdf0e10cSrcweir     bLimitedTreeEntries |= bSubFrameOfEmbeddedDocument;
3255cdf0e10cSrcweir     // if the tree view is not to be displayed at all, then only display the data source
3256cdf0e10cSrcweir     // which was given as initial selection
3257cdf0e10cSrcweir     bLimitedTreeEntries |= ( m_bEnableBrowser != sal_True );
3258cdf0e10cSrcweir 
3259cdf0e10cSrcweir     if ( bLimitedTreeEntries )
3260cdf0e10cSrcweir     {
3261cdf0e10cSrcweir         if ( xConnection.is() )
3262cdf0e10cSrcweir         {
3263cdf0e10cSrcweir             startConnectionListening( xConnection );
3264cdf0e10cSrcweir 
3265cdf0e10cSrcweir             // if no initial name was given, try to obtain one from the data source
3266cdf0e10cSrcweir             if ( !sInitialDataSourceName.getLength() )
3267cdf0e10cSrcweir 	        {
3268cdf0e10cSrcweir 	            Reference< XChild > xChild( xConnection, UNO_QUERY );
3269cdf0e10cSrcweir 		        Reference< XPropertySet > xDataSourceProperties;
3270cdf0e10cSrcweir                 if ( xChild.is() )
3271cdf0e10cSrcweir                     xDataSourceProperties = xDataSourceProperties.query( xChild->getParent() );
3272cdf0e10cSrcweir 		        if ( xDataSourceProperties.is() )
3273cdf0e10cSrcweir                 {
3274cdf0e10cSrcweir                     try
3275cdf0e10cSrcweir                     {
3276cdf0e10cSrcweir                         OSL_VERIFY( xDataSourceProperties->getPropertyValue( PROPERTY_NAME ) >>= sInitialDataSourceName );
3277cdf0e10cSrcweir                     }
3278cdf0e10cSrcweir                     catch( const Exception& )
3279cdf0e10cSrcweir                     {
3280cdf0e10cSrcweir                 	    OSL_ENSURE( sal_False, "SbaTableQueryBrowser::impl_initialize: a connection parent which does not have a 'Name'!??" );
3281cdf0e10cSrcweir                     }
3282cdf0e10cSrcweir                 }
3283cdf0e10cSrcweir             }
3284cdf0e10cSrcweir         }
3285cdf0e10cSrcweir 
3286cdf0e10cSrcweir 		implAddDatasource( sInitialDataSourceName, xConnection );
3287cdf0e10cSrcweir 		m_pTreeView->getListBox().Expand( m_pTreeView->getListBox().First() );
3288cdf0e10cSrcweir     }
3289cdf0e10cSrcweir     else
3290cdf0e10cSrcweir 		initializeTreeModel();
3291cdf0e10cSrcweir 
3292cdf0e10cSrcweir     if ( m_bEnableBrowser )
3293cdf0e10cSrcweir     {
3294cdf0e10cSrcweir         m_aDocScriptSupport = ::boost::optional< bool >( false );
3295cdf0e10cSrcweir     }
3296cdf0e10cSrcweir     else
3297cdf0e10cSrcweir     {
3298cdf0e10cSrcweir         // we are not used as "browser", but as mere view for a single table/query/command. In particular,
3299cdf0e10cSrcweir         // there is a specific database document which we belong to.
3300cdf0e10cSrcweir         Reference< XOfficeDatabaseDocument > xDocument( getDataSourceOrModel(
3301cdf0e10cSrcweir             lcl_getDataSource( m_xDatabaseContext, sInitialDataSourceName, xConnection ) ), UNO_QUERY );
3302cdf0e10cSrcweir         m_aDocScriptSupport = ::boost::optional< bool >( Reference< XEmbeddedScripts >( xDocument, UNO_QUERY ).is() );
3303cdf0e10cSrcweir     }
3304cdf0e10cSrcweir 
3305cdf0e10cSrcweir     if ( implSelect( sInitialDataSourceName, sInitialCommand, nInitialDisplayCommandType, bEsacpeProcessing, xConnection, sal_True ) )
3306cdf0e10cSrcweir 	{
3307cdf0e10cSrcweir 		try
3308cdf0e10cSrcweir 		{
3309cdf0e10cSrcweir 			Reference< XPropertySet > xRowSetProps(getRowSet(), UNO_QUERY);
3310cdf0e10cSrcweir 			xRowSetProps->setPropertyValue(PROPERTY_UPDATE_CATALOGNAME,makeAny(aCatalogName));
3311cdf0e10cSrcweir 			xRowSetProps->setPropertyValue(PROPERTY_UPDATE_SCHEMANAME,makeAny(aSchemaName));
3312cdf0e10cSrcweir 			xRowSetProps->setPropertyValue(PROPERTY_UPDATE_TABLENAME,makeAny(aTableName));
3313cdf0e10cSrcweir 
3314cdf0e10cSrcweir 		}
3315cdf0e10cSrcweir 		catch(const Exception&)
3316cdf0e10cSrcweir 		{
3317cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "SbaTableQueryBrowser::impl_initialize: could not set the update related names!");
3318cdf0e10cSrcweir 		}
3319cdf0e10cSrcweir 	}
3320cdf0e10cSrcweir 
3321cdf0e10cSrcweir 	InvalidateAll();
3322cdf0e10cSrcweir }
3323cdf0e10cSrcweir 
3324cdf0e10cSrcweir // -------------------------------------------------------------------------
3325cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::haveExplorer() const
3326cdf0e10cSrcweir {
3327cdf0e10cSrcweir 	return m_pTreeView && m_pTreeView->IsVisible();
3328cdf0e10cSrcweir }
3329cdf0e10cSrcweir 
3330cdf0e10cSrcweir // -------------------------------------------------------------------------
3331cdf0e10cSrcweir void SbaTableQueryBrowser::hideExplorer()
3332cdf0e10cSrcweir {
3333cdf0e10cSrcweir 	if (!haveExplorer())
3334cdf0e10cSrcweir 		return;
3335cdf0e10cSrcweir 	if (!getBrowserView())
3336cdf0e10cSrcweir 		return;
3337cdf0e10cSrcweir 
3338cdf0e10cSrcweir 	m_pTreeView->Hide();
3339cdf0e10cSrcweir 	m_pSplitter->Hide();
3340cdf0e10cSrcweir 	getBrowserView()->Resize();
3341cdf0e10cSrcweir 
3342cdf0e10cSrcweir 	InvalidateFeature(ID_BROWSER_EXPLORER);
3343cdf0e10cSrcweir }
3344cdf0e10cSrcweir 
3345cdf0e10cSrcweir // -------------------------------------------------------------------------
3346cdf0e10cSrcweir void SbaTableQueryBrowser::showExplorer()
3347cdf0e10cSrcweir {
3348cdf0e10cSrcweir 	if (haveExplorer())
3349cdf0e10cSrcweir 		return;
3350cdf0e10cSrcweir 
3351cdf0e10cSrcweir 	if (!getBrowserView())
3352cdf0e10cSrcweir 		return;
3353cdf0e10cSrcweir 
3354cdf0e10cSrcweir 	m_pTreeView->Show();
3355cdf0e10cSrcweir 	m_pSplitter->Show();
3356cdf0e10cSrcweir 	getBrowserView()->Resize();
3357cdf0e10cSrcweir 
3358cdf0e10cSrcweir 	InvalidateFeature(ID_BROWSER_EXPLORER);
3359cdf0e10cSrcweir }
3360cdf0e10cSrcweir 
3361cdf0e10cSrcweir // -----------------------------------------------------------------------------
3362cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::ensureConnection(SvLBoxEntry* _pAnyEntry, SharedConnection& _rConnection)
3363cdf0e10cSrcweir {
3364cdf0e10cSrcweir 	SvLBoxEntry* pDSEntry = m_pTreeView->getListBox().GetRootLevelParent(_pAnyEntry);
3365cdf0e10cSrcweir 	DBTreeListUserData* pDSData =
3366cdf0e10cSrcweir 				pDSEntry
3367cdf0e10cSrcweir 			?	static_cast<DBTreeListUserData*>(pDSEntry->GetUserData())
3368cdf0e10cSrcweir 			:	NULL;
3369cdf0e10cSrcweir 
3370cdf0e10cSrcweir 	return ensureConnection( pDSEntry, pDSData, _rConnection );
3371cdf0e10cSrcweir }
3372cdf0e10cSrcweir 
3373cdf0e10cSrcweir // -----------------------------------------------------------------------------
3374cdf0e10cSrcweir ::std::auto_ptr< ImageProvider > SbaTableQueryBrowser::getImageProviderFor( SvLBoxEntry* _pAnyEntry )
3375cdf0e10cSrcweir {
3376cdf0e10cSrcweir     ::std::auto_ptr< ImageProvider > pImageProvider( new ImageProvider );
3377cdf0e10cSrcweir     SharedConnection xConnection;
3378cdf0e10cSrcweir     if ( getExistentConnectionFor( _pAnyEntry, xConnection ) )
3379cdf0e10cSrcweir         pImageProvider.reset( new ImageProvider( xConnection ) );
3380cdf0e10cSrcweir     return pImageProvider;
3381cdf0e10cSrcweir }
3382cdf0e10cSrcweir 
3383cdf0e10cSrcweir // -----------------------------------------------------------------------------
3384cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::getExistentConnectionFor( SvLBoxEntry* _pAnyEntry, SharedConnection& _rConnection )
3385cdf0e10cSrcweir {
3386cdf0e10cSrcweir 	SvLBoxEntry* pDSEntry = m_pTreeView->getListBox().GetRootLevelParent( _pAnyEntry );
3387cdf0e10cSrcweir 	DBTreeListUserData* pDSData =
3388cdf0e10cSrcweir 				pDSEntry
3389cdf0e10cSrcweir 			?	static_cast< DBTreeListUserData* >( pDSEntry->GetUserData() )
3390cdf0e10cSrcweir 			:	NULL;
3391cdf0e10cSrcweir 	if ( pDSData )
3392cdf0e10cSrcweir 		_rConnection = pDSData->xConnection;
3393cdf0e10cSrcweir     return _rConnection.is();
3394cdf0e10cSrcweir }
3395cdf0e10cSrcweir 
3396cdf0e10cSrcweir #ifdef DBG_UTIL
3397cdf0e10cSrcweir // -----------------------------------------------------------------------------
3398cdf0e10cSrcweir bool SbaTableQueryBrowser::impl_isDataSourceEntry( SvLBoxEntry* _pEntry ) const
3399cdf0e10cSrcweir {
3400cdf0e10cSrcweir     return m_pTreeModel->GetRootLevelParent( _pEntry ) == _pEntry;
3401cdf0e10cSrcweir }
3402cdf0e10cSrcweir #endif
3403cdf0e10cSrcweir 
3404cdf0e10cSrcweir // -----------------------------------------------------------------------------
3405cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::ensureConnection( SvLBoxEntry* _pDSEntry, void* pDSData, SharedConnection& _rConnection )
3406cdf0e10cSrcweir {
3407cdf0e10cSrcweir     DBG_ASSERT( impl_isDataSourceEntry( _pDSEntry ), "SbaTableQueryBrowser::ensureConnection: this entry does not denote a data source!" );
3408cdf0e10cSrcweir 	if(_pDSEntry)
3409cdf0e10cSrcweir 	{
3410cdf0e10cSrcweir 		DBTreeListUserData* pTreeListData = static_cast<DBTreeListUserData*>(pDSData);
3411cdf0e10cSrcweir 		::rtl::OUString aDSName = GetEntryText(_pDSEntry);
3412cdf0e10cSrcweir 
3413cdf0e10cSrcweir 		if ( pTreeListData )
3414cdf0e10cSrcweir 			_rConnection = pTreeListData->xConnection;
3415cdf0e10cSrcweir 
3416cdf0e10cSrcweir 		if ( !_rConnection.is() && pTreeListData )
3417cdf0e10cSrcweir 		{
3418cdf0e10cSrcweir 			// show the "connecting to ..." status
3419cdf0e10cSrcweir 			String sConnecting(ModuleRes(STR_CONNECTING_DATASOURCE));
3420cdf0e10cSrcweir 			sConnecting.SearchAndReplaceAscii("$name$", aDSName);
3421cdf0e10cSrcweir 			BrowserViewStatusDisplay aShowStatus(static_cast<UnoDataBrowserView*>(getView()), sConnecting);
3422cdf0e10cSrcweir 
3423cdf0e10cSrcweir 			// build a string showing context information in case of error
3424cdf0e10cSrcweir 			String sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE ) );
3425cdf0e10cSrcweir 			sConnectingContext.SearchAndReplaceAscii("$name$", aDSName);
3426cdf0e10cSrcweir 
3427cdf0e10cSrcweir 			// connect
3428cdf0e10cSrcweir             _rConnection.reset(
3429cdf0e10cSrcweir                 connect( getDataSourceAcessor( _pDSEntry ), sConnectingContext, NULL ),
3430cdf0e10cSrcweir                 SharedConnection::TakeOwnership
3431cdf0e10cSrcweir             );
3432cdf0e10cSrcweir 
3433cdf0e10cSrcweir 			// remember the connection
3434cdf0e10cSrcweir 			pTreeListData->xConnection = _rConnection;
3435cdf0e10cSrcweir 		}
3436cdf0e10cSrcweir 	}
3437cdf0e10cSrcweir 
3438cdf0e10cSrcweir 	return _rConnection.is();
3439cdf0e10cSrcweir }
3440cdf0e10cSrcweir 
3441cdf0e10cSrcweir // -----------------------------------------------------------------------------
3442cdf0e10cSrcweir IMPL_LINK( SbaTableQueryBrowser, OnTreeEntryCompare, const SvSortData*, _pSortData )
3443cdf0e10cSrcweir {
3444cdf0e10cSrcweir 	SvLBoxEntry* pLHS = static_cast<SvLBoxEntry*>(_pSortData->pLeft);
3445cdf0e10cSrcweir 	SvLBoxEntry* pRHS = static_cast<SvLBoxEntry*>(_pSortData->pRight);
3446cdf0e10cSrcweir 	DBG_ASSERT(pLHS && pRHS, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid tree entries!");
3447cdf0e10cSrcweir 	// we want the table entry and the end so we have to do a check
3448cdf0e10cSrcweir 
3449cdf0e10cSrcweir 	if (isContainer(pRHS))
3450cdf0e10cSrcweir 	{
3451cdf0e10cSrcweir 		// don't use getEntryType (directly or indirecly) for the LHS:
3452cdf0e10cSrcweir 		// LHS is currently beeing inserted, so it is not "completely valid" at the moment
3453cdf0e10cSrcweir 
3454cdf0e10cSrcweir 		const EntryType eRight = getEntryType(pRHS);
3455cdf0e10cSrcweir 		if (etTableContainer == eRight)
3456cdf0e10cSrcweir 			// every other container should be placed _before_ the bookmark container
3457cdf0e10cSrcweir 			return -1;
3458cdf0e10cSrcweir 
3459cdf0e10cSrcweir 		const String sLeft = m_pTreeView->getListBox().GetEntryText(pLHS);
3460cdf0e10cSrcweir 
3461cdf0e10cSrcweir 		EntryType eLeft = etTableContainer;
3462cdf0e10cSrcweir 		if (String(ModuleRes(RID_STR_TABLES_CONTAINER)) == sLeft)
3463cdf0e10cSrcweir 			eLeft = etTableContainer;
3464cdf0e10cSrcweir 		else if (String(ModuleRes(RID_STR_QUERIES_CONTAINER)) == sLeft)
3465cdf0e10cSrcweir 			eLeft = etQueryContainer;
3466cdf0e10cSrcweir 
3467cdf0e10cSrcweir         if ( eLeft == eRight )
3468cdf0e10cSrcweir             return COMPARE_EQUAL;
3469cdf0e10cSrcweir 
3470cdf0e10cSrcweir         if ( ( eLeft == etTableContainer ) && ( eRight == etQueryContainer ) )
3471cdf0e10cSrcweir             return COMPARE_GREATER;
3472cdf0e10cSrcweir 
3473cdf0e10cSrcweir         if ( ( eLeft == etQueryContainer ) && ( eRight == etTableContainer ) )
3474cdf0e10cSrcweir             return COMPARE_LESS;
3475cdf0e10cSrcweir 
3476cdf0e10cSrcweir         OSL_ENSURE( false, "SbaTableQueryBrowser::OnTreeEntryCompare: unexpected case!" );
3477cdf0e10cSrcweir         return COMPARE_EQUAL;
3478cdf0e10cSrcweir 	}
3479cdf0e10cSrcweir 
3480cdf0e10cSrcweir 	SvLBoxString* pLeftTextItem = static_cast<SvLBoxString*>(pLHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
3481cdf0e10cSrcweir 	SvLBoxString* pRightTextItem = static_cast<SvLBoxString*>(pRHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
3482cdf0e10cSrcweir 	DBG_ASSERT(pLeftTextItem && pRightTextItem, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid text items!");
3483cdf0e10cSrcweir 
3484cdf0e10cSrcweir 	String sLeftText = pLeftTextItem->GetText();
3485cdf0e10cSrcweir 	String sRightText = pRightTextItem->GetText();
3486cdf0e10cSrcweir 
3487cdf0e10cSrcweir 	sal_Int32 nCompareResult = 0;	// equal by default
3488cdf0e10cSrcweir 
3489cdf0e10cSrcweir 	if (m_xCollator.is())
3490cdf0e10cSrcweir 	{
3491cdf0e10cSrcweir 		try
3492cdf0e10cSrcweir 		{
3493cdf0e10cSrcweir 			nCompareResult = m_xCollator->compareString(sLeftText, sRightText);
3494cdf0e10cSrcweir 		}
3495cdf0e10cSrcweir 		catch(Exception&)
3496cdf0e10cSrcweir 		{
3497cdf0e10cSrcweir 		}
3498cdf0e10cSrcweir 	}
3499cdf0e10cSrcweir 	else
3500cdf0e10cSrcweir 		// default behaviour if we do not have a collator -> do the simple string compare
3501cdf0e10cSrcweir 		nCompareResult = sLeftText.CompareTo(sRightText);
3502cdf0e10cSrcweir 
3503cdf0e10cSrcweir 	return nCompareResult;
3504cdf0e10cSrcweir }
3505cdf0e10cSrcweir 
3506cdf0e10cSrcweir // -----------------------------------------------------------------------------
3507cdf0e10cSrcweir void SbaTableQueryBrowser::implAdministrate( SvLBoxEntry* _pApplyTo )
3508cdf0e10cSrcweir {
3509cdf0e10cSrcweir     OSL_PRECOND( _pApplyTo, "SbaTableQueryBrowser::implAdministrate: illegal entry!" );
3510cdf0e10cSrcweir     if ( !_pApplyTo )
3511cdf0e10cSrcweir         return;
3512cdf0e10cSrcweir 
3513cdf0e10cSrcweir 	try
3514cdf0e10cSrcweir 	{
3515cdf0e10cSrcweir 		// get the desktop object
3516cdf0e10cSrcweir 		sal_Int32 nFrameSearchFlag = FrameSearchFlag::ALL | FrameSearchFlag::GLOBAL ;
3517cdf0e10cSrcweir 		Reference< XComponentLoader > xFrameLoader(getORB()->createInstance(SERVICE_FRAME_DESKTOP),UNO_QUERY);
3518cdf0e10cSrcweir 
3519cdf0e10cSrcweir 		if ( xFrameLoader.is() )
3520cdf0e10cSrcweir 		{
3521cdf0e10cSrcweir 			// the initial selection
3522cdf0e10cSrcweir 			SvLBoxEntry* pTopLevelSelected = _pApplyTo;
3523cdf0e10cSrcweir 			while (pTopLevelSelected && m_pTreeView->getListBox().GetParent(pTopLevelSelected))
3524cdf0e10cSrcweir 				pTopLevelSelected = m_pTreeView->getListBox().GetParent(pTopLevelSelected);
3525cdf0e10cSrcweir 			::rtl::OUString sInitialSelection;
3526cdf0e10cSrcweir 			if (pTopLevelSelected)
3527cdf0e10cSrcweir 				sInitialSelection = getDataSourceAcessor( pTopLevelSelected );
3528cdf0e10cSrcweir 
3529cdf0e10cSrcweir             Reference< XDataSource > xDataSource( getDataSourceByName( sInitialSelection, getView(), getORB(), NULL ) );
3530cdf0e10cSrcweir 			Reference< XModel > xDocumentModel( getDataSourceOrModel( xDataSource ), UNO_QUERY );
3531cdf0e10cSrcweir 
3532cdf0e10cSrcweir             if ( xDocumentModel.is() )
3533cdf0e10cSrcweir 			{
3534cdf0e10cSrcweir                 Reference< XInteractionHandler > xInteractionHandler(
3535cdf0e10cSrcweir                     getORB()->createInstance(
3536cdf0e10cSrcweir                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ),
3537cdf0e10cSrcweir                         UNO_QUERY );
3538cdf0e10cSrcweir                 OSL_ENSURE( xInteractionHandler.is(), "SbaTableQueryBrowser::implAdministrate: no interaction handler available!" );
3539cdf0e10cSrcweir 
3540cdf0e10cSrcweir                 ::comphelper::NamedValueCollection aLoadArgs;
3541cdf0e10cSrcweir                 aLoadArgs.put( "Model", xDocumentModel );
3542cdf0e10cSrcweir                 aLoadArgs.put( "InteractionHandler", xInteractionHandler );
3543cdf0e10cSrcweir                 aLoadArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
3544cdf0e10cSrcweir 
3545cdf0e10cSrcweir                 Sequence< PropertyValue > aLoadArgPV;
3546cdf0e10cSrcweir                 aLoadArgs >>= aLoadArgPV;
3547cdf0e10cSrcweir 
3548cdf0e10cSrcweir                 xFrameLoader->loadComponentFromURL(
3549cdf0e10cSrcweir 					xDocumentModel->getURL(),
3550cdf0e10cSrcweir 					::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_default")),
3551cdf0e10cSrcweir 					nFrameSearchFlag,
3552cdf0e10cSrcweir                     aLoadArgPV
3553cdf0e10cSrcweir 				);
3554cdf0e10cSrcweir 			}
3555cdf0e10cSrcweir 		}
3556cdf0e10cSrcweir 	}
3557cdf0e10cSrcweir     catch( const Exception& )
3558cdf0e10cSrcweir     {
3559cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
3560cdf0e10cSrcweir     }
3561cdf0e10cSrcweir }
3562cdf0e10cSrcweir 
3563cdf0e10cSrcweir // -----------------------------------------------------------------------------
3564cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::requestQuickHelp( const SvLBoxEntry* _pEntry, String& _rText ) const
3565cdf0e10cSrcweir {
3566cdf0e10cSrcweir 	const DBTreeListUserData* pData = static_cast< const DBTreeListUserData* >( _pEntry->GetUserData() );
3567cdf0e10cSrcweir     if ( ( pData->eType == etDatasource ) && pData->sAccessor.Len() )
3568cdf0e10cSrcweir     {
3569cdf0e10cSrcweir         _rText = ::svt::OFileNotation( pData->sAccessor ).get( ::svt::OFileNotation::N_SYSTEM );
3570cdf0e10cSrcweir         return sal_True;
3571cdf0e10cSrcweir     }
3572cdf0e10cSrcweir     return sal_False;
3573cdf0e10cSrcweir }
3574cdf0e10cSrcweir 
3575cdf0e10cSrcweir // -----------------------------------------------------------------------------
3576cdf0e10cSrcweir PopupMenu* SbaTableQueryBrowser::getContextMenu( Control& _rControl ) const
3577cdf0e10cSrcweir {
3578cdf0e10cSrcweir     OSL_PRECOND( &m_pTreeView->getListBox() == &_rControl,
3579cdf0e10cSrcweir         "SbaTableQueryBrowser::getContextMenu: where does this come from?" );
3580cdf0e10cSrcweir     if ( &m_pTreeView->getListBox() != &_rControl )
3581cdf0e10cSrcweir         return NULL;
3582cdf0e10cSrcweir 
3583cdf0e10cSrcweir     return new PopupMenu( ModuleRes( MENU_BROWSER_DEFAULTCONTEXT ) );
3584cdf0e10cSrcweir }
3585cdf0e10cSrcweir 
3586cdf0e10cSrcweir // -----------------------------------------------------------------------------
3587cdf0e10cSrcweir IController& SbaTableQueryBrowser::getCommandController()
3588cdf0e10cSrcweir {
3589cdf0e10cSrcweir     return *this;
3590cdf0e10cSrcweir }
3591cdf0e10cSrcweir 
3592cdf0e10cSrcweir // -----------------------------------------------------------------------------
3593cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* SbaTableQueryBrowser::getContextMenuInterceptors()
3594cdf0e10cSrcweir {
3595cdf0e10cSrcweir     return &m_aContextMenuInterceptors;
3596cdf0e10cSrcweir }
3597cdf0e10cSrcweir 
3598cdf0e10cSrcweir // -----------------------------------------------------------------------------
3599cdf0e10cSrcweir Any SbaTableQueryBrowser::getCurrentSelection( Control& _rControl ) const
3600cdf0e10cSrcweir {
3601cdf0e10cSrcweir     OSL_PRECOND( &m_pTreeView->getListBox() == &_rControl,
3602cdf0e10cSrcweir         "SbaTableQueryBrowser::getCurrentSelection: where does this come from?" );
3603cdf0e10cSrcweir 
3604cdf0e10cSrcweir     if ( &m_pTreeView->getListBox() != &_rControl )
3605cdf0e10cSrcweir         return Any();
3606cdf0e10cSrcweir 
3607cdf0e10cSrcweir     SvLBoxEntry* pSelected = m_pTreeView->getListBox().FirstSelected();
3608cdf0e10cSrcweir     if ( !pSelected )
3609cdf0e10cSrcweir         return Any();
3610cdf0e10cSrcweir 
3611cdf0e10cSrcweir     OSL_ENSURE( m_pTreeView->getListBox().NextSelected( pSelected ) == NULL,
3612cdf0e10cSrcweir         "SbaTableQueryBrowser::getCurrentSelection: single-selection is expected here!" );
3613cdf0e10cSrcweir 
3614cdf0e10cSrcweir     NamedDatabaseObject aSelectedObject;
3615cdf0e10cSrcweir 	DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( pSelected->GetUserData() );
3616cdf0e10cSrcweir     aSelectedObject.Type = static_cast< sal_Int32 >( pData->eType );
3617cdf0e10cSrcweir 
3618cdf0e10cSrcweir     switch ( aSelectedObject.Type )
3619cdf0e10cSrcweir     {
3620cdf0e10cSrcweir     case DatabaseObject::QUERY:
3621cdf0e10cSrcweir     case DatabaseObject::TABLE:
3622cdf0e10cSrcweir         aSelectedObject.Name = m_pTreeView->getListBox().GetEntryText( pSelected );
3623cdf0e10cSrcweir         break;
3624cdf0e10cSrcweir 
3625cdf0e10cSrcweir     case DatabaseObjectContainer::DATA_SOURCE:
3626cdf0e10cSrcweir     case DatabaseObjectContainer::QUERIES:
3627cdf0e10cSrcweir     case DatabaseObjectContainer::TABLES:
3628cdf0e10cSrcweir         aSelectedObject.Name = getDataSourceAcessor( pSelected );
3629cdf0e10cSrcweir         break;
3630cdf0e10cSrcweir 
3631cdf0e10cSrcweir     default:
3632cdf0e10cSrcweir         OSL_ENSURE( false, "SbaTableQueryBrowser::getCurrentSelection: invalid (unexpected) object type!" );
3633cdf0e10cSrcweir         break;
3634cdf0e10cSrcweir     }
3635cdf0e10cSrcweir 
3636cdf0e10cSrcweir     return makeAny( aSelectedObject );
3637cdf0e10cSrcweir }
3638cdf0e10cSrcweir 
3639cdf0e10cSrcweir // -----------------------------------------------------------------------------
3640cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::implGetQuerySignature( ::rtl::OUString& _rCommand, sal_Bool& _bEscapeProcessing )
3641cdf0e10cSrcweir {
3642cdf0e10cSrcweir 	_rCommand = ::rtl::OUString();
3643cdf0e10cSrcweir 	_bEscapeProcessing = sal_False;
3644cdf0e10cSrcweir 
3645cdf0e10cSrcweir 	try
3646cdf0e10cSrcweir 	{
3647cdf0e10cSrcweir 		// ontain the dss (data source signature) of the form
3648cdf0e10cSrcweir 		::rtl::OUString sDataSourceName;
3649cdf0e10cSrcweir 		::rtl::OUString sCommand;
3650cdf0e10cSrcweir 		sal_Int32		nCommandType = CommandType::COMMAND;
3651cdf0e10cSrcweir 		Reference< XPropertySet > xRowsetProps( getRowSet(), UNO_QUERY );
3652cdf0e10cSrcweir 		ODataAccessDescriptor aDesc( xRowsetProps );
3653cdf0e10cSrcweir 		sDataSourceName = aDesc.getDataSource();
3654cdf0e10cSrcweir 		aDesc[ daCommand ]		>>= sCommand;
3655cdf0e10cSrcweir 		aDesc[ daCommandType ]	>>= nCommandType;
3656cdf0e10cSrcweir 
3657cdf0e10cSrcweir 		// do we need to do anything?
3658cdf0e10cSrcweir 		if ( CommandType::QUERY != nCommandType )
3659cdf0e10cSrcweir 			return sal_False;
3660cdf0e10cSrcweir 
3661cdf0e10cSrcweir 		// get the query object
3662cdf0e10cSrcweir 		Reference< XQueryDefinitionsSupplier > xSuppQueries;
3663cdf0e10cSrcweir 		Reference< XNameAccess > xQueries;
3664cdf0e10cSrcweir 		Reference< XPropertySet > xQuery;
3665cdf0e10cSrcweir 		m_xDatabaseContext->getByName( sDataSourceName ) >>= xSuppQueries;
3666cdf0e10cSrcweir 		if ( xSuppQueries.is() )
3667cdf0e10cSrcweir 			xQueries = xSuppQueries->getQueryDefinitions();
3668cdf0e10cSrcweir 		if ( xQueries.is() )
3669cdf0e10cSrcweir 			xQueries->getByName( sCommand ) >>= xQuery;
3670cdf0e10cSrcweir 		OSL_ENSURE( xQuery.is(), "SbaTableQueryBrowser::implGetQuerySignature: could not retrieve the query object!" );
3671cdf0e10cSrcweir 
3672cdf0e10cSrcweir 		// get the two properties we need
3673cdf0e10cSrcweir 		if ( xQuery.is() )
3674cdf0e10cSrcweir 		{
3675cdf0e10cSrcweir 			xQuery->getPropertyValue( PROPERTY_COMMAND ) >>= _rCommand;
3676cdf0e10cSrcweir 			_bEscapeProcessing = ::cppu::any2bool( xQuery->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) );
3677cdf0e10cSrcweir 			return sal_True;
3678cdf0e10cSrcweir 		}
3679cdf0e10cSrcweir 	}
3680cdf0e10cSrcweir     catch( const Exception& )
3681cdf0e10cSrcweir     {
3682cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
3683cdf0e10cSrcweir     }
3684cdf0e10cSrcweir 
3685cdf0e10cSrcweir 	return sal_False;
3686cdf0e10cSrcweir }
3687cdf0e10cSrcweir //------------------------------------------------------------------------------
3688cdf0e10cSrcweir void SbaTableQueryBrowser::frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( RuntimeException )
3689cdf0e10cSrcweir {
3690cdf0e10cSrcweir 	if (aEvent.Frame == m_xCurrentFrameParent)
3691cdf0e10cSrcweir 	{
3692cdf0e10cSrcweir 		if(aEvent.Action == FrameAction_COMPONENT_DETACHING)
3693cdf0e10cSrcweir 			implRemoveStatusListeners();
3694cdf0e10cSrcweir 		else if (aEvent.Action == FrameAction_COMPONENT_REATTACHED)
3695cdf0e10cSrcweir 			connectExternalDispatches();
3696cdf0e10cSrcweir 	}
3697cdf0e10cSrcweir 	else
3698cdf0e10cSrcweir 		SbaXDataBrowserController::frameAction(aEvent);
3699cdf0e10cSrcweir 
3700cdf0e10cSrcweir }
3701cdf0e10cSrcweir // -----------------------------------------------------------------------------
3702cdf0e10cSrcweir void SbaTableQueryBrowser::clearGridColumns(const Reference< XNameContainer >& _xColContainer)
3703cdf0e10cSrcweir {
3704cdf0e10cSrcweir 	// first we have to clear the grid
3705cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aNames = _xColContainer->getElementNames();
3706cdf0e10cSrcweir 	const ::rtl::OUString* pIter	= aNames.getConstArray();
3707cdf0e10cSrcweir 	const ::rtl::OUString* pEnd		= pIter + aNames.getLength();
3708cdf0e10cSrcweir 	Reference< XInterface > xColumn;
3709cdf0e10cSrcweir 	for (; pIter != pEnd;++pIter)
3710cdf0e10cSrcweir 	{
3711cdf0e10cSrcweir 		_xColContainer->getByName(*pIter) >>= xColumn;
3712cdf0e10cSrcweir 		_xColContainer->removeByName(*pIter);
3713cdf0e10cSrcweir 		::comphelper::disposeComponent(xColumn);
3714cdf0e10cSrcweir 	}
3715cdf0e10cSrcweir }
3716cdf0e10cSrcweir // -----------------------------------------------------------------------------
3717cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::isHiContrast() const
3718cdf0e10cSrcweir {
3719cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
3720cdf0e10cSrcweir 	if ( m_pTreeView )
3721cdf0e10cSrcweir 		bRet = m_pTreeView->getListBox().GetSettings().GetStyleSettings().GetHighContrastMode();
3722cdf0e10cSrcweir 	return bRet;
3723cdf0e10cSrcweir }
3724cdf0e10cSrcweir // -----------------------------------------------------------------------------
3725cdf0e10cSrcweir void SbaTableQueryBrowser::loadMenu(const Reference< XFrame >& _xFrame)
3726cdf0e10cSrcweir {
3727cdf0e10cSrcweir 	if ( m_bShowMenu )
3728cdf0e10cSrcweir 	{
3729cdf0e10cSrcweir 		OGenericUnoController::loadMenu(_xFrame);
3730cdf0e10cSrcweir 	}
3731cdf0e10cSrcweir 	else if ( !m_bPreview )
3732cdf0e10cSrcweir 	{
3733cdf0e10cSrcweir         Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager = getLayoutManager(_xFrame);
3734cdf0e10cSrcweir 
3735cdf0e10cSrcweir 		if ( xLayoutManager.is() )
3736cdf0e10cSrcweir 		{
3737cdf0e10cSrcweir 			xLayoutManager->lock();
3738cdf0e10cSrcweir 			xLayoutManager->createElement( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/toolbar" )));
3739cdf0e10cSrcweir 			xLayoutManager->unlock();
3740cdf0e10cSrcweir 			xLayoutManager->doLayout();
3741cdf0e10cSrcweir 		}
3742cdf0e10cSrcweir         onLoadedMenu( xLayoutManager );
3743cdf0e10cSrcweir 	}
3744cdf0e10cSrcweir }
3745cdf0e10cSrcweir // -----------------------------------------------------------------------------
3746cdf0e10cSrcweir ::rtl::OUString SbaTableQueryBrowser::getPrivateTitle() const
3747cdf0e10cSrcweir {
3748cdf0e10cSrcweir     ::rtl::OUString sTitle;
3749cdf0e10cSrcweir 	if ( m_pCurrentlyDisplayed )
3750cdf0e10cSrcweir 	{
3751cdf0e10cSrcweir 		SvLBoxEntry* pContainer = m_pTreeModel->GetParent(m_pCurrentlyDisplayed);
3752cdf0e10cSrcweir 		// get the entry for the datasource
3753cdf0e10cSrcweir         SvLBoxEntry* pConnection = implGetConnectionEntry(pContainer);
3754cdf0e10cSrcweir 		::rtl::OUString sName = m_pTreeView->getListBox().GetEntryText(m_pCurrentlyDisplayed);
3755cdf0e10cSrcweir 		sTitle = GetEntryText( pConnection );
3756cdf0e10cSrcweir 		INetURLObject aURL(sTitle);
3757cdf0e10cSrcweir 		if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
3758cdf0e10cSrcweir 			sTitle = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_WITH_CHARSET);
3759cdf0e10cSrcweir 		if ( sName.getLength() )
3760cdf0e10cSrcweir 		{
3761cdf0e10cSrcweir 			sName += ::rtl::OUString::createFromAscii(" - ");
3762cdf0e10cSrcweir 			sName += sTitle;
3763cdf0e10cSrcweir             sTitle = sName;
3764cdf0e10cSrcweir 		}
3765cdf0e10cSrcweir 	}
3766cdf0e10cSrcweir 
3767cdf0e10cSrcweir     return sTitle;
3768cdf0e10cSrcweir }
3769cdf0e10cSrcweir // -----------------------------------------------------------------------------
3770cdf0e10cSrcweir sal_Bool SbaTableQueryBrowser::preReloadForm()
3771cdf0e10cSrcweir {
3772cdf0e10cSrcweir 	sal_Bool bIni = sal_False;
3773cdf0e10cSrcweir 	if ( !m_pCurrentlyDisplayed )
3774cdf0e10cSrcweir 	{
3775cdf0e10cSrcweir 		// switch the grid to design mode while loading
3776cdf0e10cSrcweir 		getBrowserView()->getGridControl()->setDesignMode(sal_True);
3777cdf0e10cSrcweir 		// we had an invalid statement so we need to connect the column models
3778cdf0e10cSrcweir 		Reference<XPropertySet> xRowSetProps(getRowSet(),UNO_QUERY);
3779cdf0e10cSrcweir 		::svx::ODataAccessDescriptor aDesc(xRowSetProps);
3780cdf0e10cSrcweir 		// extract the props
3781cdf0e10cSrcweir 		::rtl::OUString sDataSource;
3782cdf0e10cSrcweir 		::rtl::OUString sCommand;
3783cdf0e10cSrcweir 		sal_Int32 nCommandType = CommandType::COMMAND;
3784cdf0e10cSrcweir 		sal_Bool bEscapeProcessing = sal_True;
3785cdf0e10cSrcweir 		extractDescriptorProps(aDesc, sDataSource, sCommand, nCommandType, bEscapeProcessing);
3786cdf0e10cSrcweir 		if ( sDataSource.getLength() && sCommand.getLength() && (-1 != nCommandType) )
3787cdf0e10cSrcweir 		{
3788cdf0e10cSrcweir 			SvLBoxEntry* pDataSource = NULL;
3789cdf0e10cSrcweir 			SvLBoxEntry* pCommandType = NULL;
3790cdf0e10cSrcweir 			m_pCurrentlyDisplayed = getObjectEntry( sDataSource, sCommand, nCommandType, &pDataSource, &pCommandType, sal_True, SharedConnection() );
3791cdf0e10cSrcweir 			bIni = sal_True;
3792cdf0e10cSrcweir 		}
3793cdf0e10cSrcweir 	}
3794cdf0e10cSrcweir 	return bIni;
3795cdf0e10cSrcweir }
3796cdf0e10cSrcweir 
3797cdf0e10cSrcweir // -----------------------------------------------------------------------------
3798cdf0e10cSrcweir void SbaTableQueryBrowser::postReloadForm()
3799cdf0e10cSrcweir {
3800cdf0e10cSrcweir 	InitializeGridModel(getFormComponent());
3801cdf0e10cSrcweir 	LoadFinished(sal_True);
3802cdf0e10cSrcweir 	//updateTitle();
3803cdf0e10cSrcweir }
3804cdf0e10cSrcweir 
3805cdf0e10cSrcweir //------------------------------------------------------------------------------
3806cdf0e10cSrcweir Reference< XEmbeddedScripts > SAL_CALL SbaTableQueryBrowser::getScriptContainer() throw (RuntimeException)
3807cdf0e10cSrcweir {
3808cdf0e10cSrcweir     // update our database document
3809cdf0e10cSrcweir     Reference< XModel > xDocument;
3810cdf0e10cSrcweir     try
3811cdf0e10cSrcweir     {
3812cdf0e10cSrcweir         Reference< XPropertySet > xCursorProps( getRowSet(), UNO_QUERY_THROW );
3813cdf0e10cSrcweir         Reference< XConnection > xConnection( xCursorProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ), UNO_QUERY );
3814cdf0e10cSrcweir         if ( xConnection.is() )
3815cdf0e10cSrcweir         {
3816cdf0e10cSrcweir             Reference< XChild > xChild( xConnection, UNO_QUERY_THROW );
3817cdf0e10cSrcweir             Reference< XDocumentDataSource > xDataSource( xChild->getParent(), UNO_QUERY_THROW );
3818cdf0e10cSrcweir             xDocument.set( xDataSource->getDatabaseDocument(), UNO_QUERY_THROW );
3819cdf0e10cSrcweir         }
3820cdf0e10cSrcweir     }
3821cdf0e10cSrcweir     catch( const Exception& )
3822cdf0e10cSrcweir     {
3823cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
3824cdf0e10cSrcweir     }
3825cdf0e10cSrcweir     Reference< XEmbeddedScripts > xScripts( xDocument, UNO_QUERY );
3826cdf0e10cSrcweir     OSL_ENSURE( xScripts.is() || !xDocument.is(),
3827cdf0e10cSrcweir         "SbaTableQueryBrowser::getScriptContainer: invalid database document!" );
3828cdf0e10cSrcweir     return xScripts;
3829cdf0e10cSrcweir }
3830cdf0e10cSrcweir 
3831cdf0e10cSrcweir //------------------------------------------------------------------------------
3832cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::registerContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException)
3833cdf0e10cSrcweir {
3834cdf0e10cSrcweir     if ( _Interceptor.is() )
3835cdf0e10cSrcweir         m_aContextMenuInterceptors.addInterface( _Interceptor );
3836cdf0e10cSrcweir }
3837cdf0e10cSrcweir 
3838cdf0e10cSrcweir //------------------------------------------------------------------------------
3839cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::releaseContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException)
3840cdf0e10cSrcweir {
3841cdf0e10cSrcweir     if ( _Interceptor.is() )
3842cdf0e10cSrcweir         m_aContextMenuInterceptors.removeInterface( _Interceptor );
3843cdf0e10cSrcweir }
3844cdf0e10cSrcweir 
3845cdf0e10cSrcweir //------------------------------------------------------------------------------
3846cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::registeredDatabaseLocation( const DatabaseRegistrationEvent& _Event ) throw (RuntimeException)
3847cdf0e10cSrcweir {
3848cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
3849cdf0e10cSrcweir 	implAddDatasource( _Event.Name, SharedConnection() );
3850cdf0e10cSrcweir }
3851cdf0e10cSrcweir 
3852cdf0e10cSrcweir //------------------------------------------------------------------------------
3853cdf0e10cSrcweir void SbaTableQueryBrowser::impl_cleanupDataSourceEntry( const String& _rDataSourceName )
3854cdf0e10cSrcweir {
3855cdf0e10cSrcweir 	// get the top-level representing the removed data source
3856cdf0e10cSrcweir 	SvLBoxEntry* pDataSourceEntry = m_pTreeView->getListBox().FirstChild( NULL );
3857cdf0e10cSrcweir 	while ( pDataSourceEntry )
3858cdf0e10cSrcweir 	{
3859cdf0e10cSrcweir 		if ( m_pTreeView->getListBox().GetEntryText( pDataSourceEntry ) == _rDataSourceName )
3860cdf0e10cSrcweir 			break;
3861cdf0e10cSrcweir 
3862cdf0e10cSrcweir 		pDataSourceEntry = m_pTreeView->getListBox().NextSibling( pDataSourceEntry );
3863cdf0e10cSrcweir 	}
3864cdf0e10cSrcweir 
3865cdf0e10cSrcweir     OSL_ENSURE( pDataSourceEntry, "SbaTableQueryBrowser::impl_cleanupDataSourceEntry: do not know this data source!" );
3866cdf0e10cSrcweir     if ( !pDataSourceEntry )
3867cdf0e10cSrcweir         return;
3868cdf0e10cSrcweir 
3869cdf0e10cSrcweir     if ( isSelected( pDataSourceEntry ) )
3870cdf0e10cSrcweir 	{	// a table or query belonging to the deleted data source is currently beeing displayed.
3871cdf0e10cSrcweir 		OSL_ENSURE( m_pTreeView->getListBox().GetRootLevelParent( m_pCurrentlyDisplayed ) == pDataSourceEntry,
3872cdf0e10cSrcweir             "SbaTableQueryBrowser::impl_cleanupDataSourceEntry: inconsistence (1)!" );
3873cdf0e10cSrcweir 		unloadAndCleanup( sal_True );
3874cdf0e10cSrcweir 	}
3875cdf0e10cSrcweir 	else
3876cdf0e10cSrcweir 		OSL_ENSURE(
3877cdf0e10cSrcweir 				( NULL == m_pCurrentlyDisplayed )
3878cdf0e10cSrcweir 			||	( m_pTreeView->getListBox().GetRootLevelParent( m_pCurrentlyDisplayed ) != pDataSourceEntry ),
3879cdf0e10cSrcweir             "SbaTableQueryBrowser::impl_cleanupDataSourceEntry: inconsistence (2)!");
3880cdf0e10cSrcweir 
3881cdf0e10cSrcweir     // delete any user data of the child entries of the to-be-removed entry
3882cdf0e10cSrcweir 	SvTreeEntryList* pList = m_pTreeModel->GetChildList( pDataSourceEntry );
3883cdf0e10cSrcweir 	if ( pList )
3884cdf0e10cSrcweir 	{
3885cdf0e10cSrcweir 		SvLBoxEntry* pEntryLoop = static_cast<SvLBoxEntry*>( pList->First() );
3886cdf0e10cSrcweir 		while ( pEntryLoop )
3887cdf0e10cSrcweir 		{
3888cdf0e10cSrcweir 			DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( pEntryLoop->GetUserData() );
3889cdf0e10cSrcweir 			pEntryLoop->SetUserData( NULL );
3890cdf0e10cSrcweir 			delete pData;
3891cdf0e10cSrcweir 			pEntryLoop = static_cast< SvLBoxEntry* >( pList->Next() );
3892cdf0e10cSrcweir 		}
3893cdf0e10cSrcweir 	}
3894cdf0e10cSrcweir 
3895cdf0e10cSrcweir 	// remove the entry
3896cdf0e10cSrcweir 	DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( pDataSourceEntry->GetUserData() );
3897cdf0e10cSrcweir 	pDataSourceEntry->SetUserData( NULL );
3898cdf0e10cSrcweir 	delete pData;
3899cdf0e10cSrcweir 	m_pTreeModel->Remove( pDataSourceEntry );
3900cdf0e10cSrcweir }
3901cdf0e10cSrcweir 
3902cdf0e10cSrcweir //------------------------------------------------------------------------------
3903cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::revokedDatabaseLocation( const DatabaseRegistrationEvent& _Event ) throw (RuntimeException)
3904cdf0e10cSrcweir {
3905cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
3906cdf0e10cSrcweir 
3907cdf0e10cSrcweir     impl_cleanupDataSourceEntry( _Event.Name );
3908cdf0e10cSrcweir 
3909cdf0e10cSrcweir 	// maybe the object which is part of the document data source has been removed
3910cdf0e10cSrcweir 	checkDocumentDataSource();
3911cdf0e10cSrcweir }
3912cdf0e10cSrcweir 
3913cdf0e10cSrcweir //------------------------------------------------------------------------------
3914cdf0e10cSrcweir void SAL_CALL SbaTableQueryBrowser::changedDatabaseLocation( const DatabaseRegistrationEvent& _Event ) throw (RuntimeException)
3915cdf0e10cSrcweir {
3916cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
3917cdf0e10cSrcweir 
3918cdf0e10cSrcweir     // in case the data source was expanded, and connected, we need to clean it up
3919cdf0e10cSrcweir     // for simplicity, just do as if the data source were completely removed and re-added
3920cdf0e10cSrcweir     impl_cleanupDataSourceEntry( _Event.Name );
3921cdf0e10cSrcweir     implAddDatasource( _Event.Name, SharedConnection() );
3922cdf0e10cSrcweir }
3923cdf0e10cSrcweir 
3924cdf0e10cSrcweir 
3925cdf0e10cSrcweir // .........................................................................
3926cdf0e10cSrcweir }	// namespace dbaui
3927cdf0e10cSrcweir // .........................................................................
3928cdf0e10cSrcweir 
3929cdf0e10cSrcweir 
3930