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