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