merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / browser / unodatbr.cxx
bloba889b2d15ffca637c41bcb8281fc74838ceed3b5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unodatbr.cxx,v $
10 * $Revision: 1.203.8.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "browserids.hxx"
35 #include "dbaccess_helpid.hrc"
36 #include "dbexchange.hxx"
37 #include "dbtreelistbox.hxx"
38 #include "dbtreemodel.hxx"
39 #include "dbtreeview.hxx"
40 #include "dbu_brw.hrc"
41 #include "dbu_reghelper.hxx"
42 #include "dbustrings.hrc"
43 #include "dlgsave.hxx"
44 #include "HtmlReader.hxx"
45 #include "imageprovider.hxx"
46 #include "listviewitems.hxx"
47 #include "QEnumTypes.hxx"
48 #include "RtfReader.hxx"
49 #include "sbagrid.hrc"
50 #include "sbagrid.hxx"
51 #include "sqlmessage.hxx"
52 #include "TokenWriter.hxx"
53 #include "UITools.hxx"
54 #include "unodatbr.hxx"
55 #include "WColumnSelect.hxx"
56 #include "WCopyTable.hxx"
57 #include "WCPage.hxx"
58 #include "WExtendPages.hxx"
59 #include "WNameMatch.hxx"
61 /** === begin UNO includes === **/
62 #include <com/sun/star/awt/LineEndFormat.hpp>
63 #include <com/sun/star/awt/LineEndFormat.hpp>
64 #include <com/sun/star/awt/MouseWheelBehavior.hpp>
65 #include <com/sun/star/awt/TextAlign.hpp>
66 #include <com/sun/star/awt/VisualEffect.hpp>
67 #include <com/sun/star/beans/NamedValue.hpp>
68 #include <com/sun/star/beans/PropertyValue.hpp>
69 #include <com/sun/star/container/XNameContainer.hpp>
70 #include <com/sun/star/form/XForm.hpp>
71 #include <com/sun/star/form/XGridColumnFactory.hpp>
72 #include <com/sun/star/form/XLoadable.hpp>
73 #include <com/sun/star/frame/FrameSearchFlag.hpp>
74 #include <com/sun/star/frame/XLayoutManager.hpp>
75 #include <com/sun/star/lang/DisposedException.hpp>
76 #include <com/sun/star/sdb/CommandType.hpp>
77 #include <com/sun/star/sdb/SQLContext.hpp>
78 #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
79 #include <com/sun/star/sdb/XCompletedConnection.hpp>
80 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
81 #include <com/sun/star/sdb/XParametersSupplier.hpp>
82 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
83 #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
84 #include <com/sun/star/sdb/XResultSetAccess.hpp>
85 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
86 #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp>
87 #include <com/sun/star/sdbc/ColumnValue.hpp>
88 #include <com/sun/star/sdbc/DataType.hpp>
89 #include <com/sun/star/sdbc/FetchDirection.hpp>
90 #include <com/sun/star/sdbc/SQLWarning.hpp>
91 #include <com/sun/star/sdbc/XDataSource.hpp>
92 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
93 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
94 #include <com/sun/star/sdbcx/Privilege.hpp>
95 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
96 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
97 #include <com/sun/star/sdbcx/XDrop.hpp>
98 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
99 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
100 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
101 #include <com/sun/star/util/XFlushable.hpp>
102 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
103 #include <com/sun/star/document/MacroExecMode.hpp>
104 #include <com/sun/star/frame/XComponentLoader.hpp>
105 #include <com/sun/star/ui/XContextMenuInterceptor.hpp>
106 /** === end UNO includes === **/
108 #include <comphelper/extract.hxx>
109 #include <comphelper/sequence.hxx>
110 #include <comphelper/types.hxx>
111 #include <connectivity/dbexception.hxx>
112 #include <cppuhelper/implbase2.hxx>
113 #include <cppuhelper/typeprovider.hxx>
114 #include <sfx2/app.hxx>
115 #include <sfx2/dispatch.hxx>
116 #include <sot/storage.hxx>
117 #include <svtools/filenotation.hxx>
118 #include <svtools/intitem.hxx>
119 #include <svtools/moduleoptions.hxx>
120 #include <svtools/svlbitm.hxx>
121 #include <svtools/svtreebx.hxx>
122 #include <svx/algitem.hxx>
123 #include <svx/dataaccessdescriptor.hxx>
124 #include <svx/databaseregistrationui.hxx>
125 #include <svx/gridctrl.hxx>
126 #include <toolkit/unohlp.hxx>
127 #include <tools/diagnose_ex.h>
128 #include <tools/multisel.hxx>
129 #include <tools/urlobj.hxx>
130 #include <unotools/confignode.hxx>
131 #include <vcl/msgbox.hxx>
132 #include <vcl/split.hxx>
133 #include <vcl/stdtext.hxx>
134 #include <vcl/svapp.hxx>
135 #include <vcl/toolbox.hxx>
136 #include <vcl/waitobj.hxx>
137 #include <vcl/wrkwin.hxx>
138 #include <rtl/logfile.hxx>
140 #include <memory>
142 using namespace ::com::sun::star::uno;
143 using namespace ::com::sun::star::awt;
144 using namespace ::com::sun::star::sdb;
145 using namespace ::com::sun::star::sdb::application;
146 using namespace ::com::sun::star::sdbc;
147 using namespace ::com::sun::star::sdbcx;
148 using namespace ::com::sun::star::beans;
149 using namespace ::com::sun::star::util;
150 using namespace ::com::sun::star::frame;
151 using namespace ::com::sun::star::container;
152 using namespace ::com::sun::star::lang;
153 using namespace ::com::sun::star::ui::dialogs;
154 using namespace ::com::sun::star::task;
155 using namespace ::com::sun::star::form;
156 using namespace ::com::sun::star::io;
157 using namespace ::com::sun::star::i18n;
158 using namespace ::com::sun::star::view;
159 using namespace ::com::sun::star::datatransfer;
160 using namespace ::com::sun::star::document;
161 using namespace ::com::sun::star::ui;
162 using namespace ::dbtools;
163 using namespace ::comphelper;
164 using namespace ::svx;
166 // .........................................................................
167 namespace dbaui
169 // .........................................................................
171 namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
172 namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
174 //==================================================================
175 //= SbaTableQueryBrowser
176 //==================================================================
177 // -------------------------------------------------------------------------
178 extern "C" void SAL_CALL createRegistryInfo_OBrowser()
180 static OMultiInstanceAutoRegistration< SbaTableQueryBrowser > aAutoRegistration;
182 // -------------------------------------------------------------------------
183 void SafeAddPropertyListener(const Reference< XPropertySet > & xSet, const ::rtl::OUString& rPropName, XPropertyChangeListener* pListener)
185 Reference< XPropertySetInfo > xInfo = xSet->getPropertySetInfo();
186 if (xInfo->hasPropertyByName(rPropName))
187 xSet->addPropertyChangeListener(rPropName, pListener);
190 // -------------------------------------------------------------------------
191 void SafeRemovePropertyListener(const Reference< XPropertySet > & xSet, const ::rtl::OUString& rPropName, XPropertyChangeListener* pListener)
193 Reference< XPropertySetInfo > xInfo = xSet->getPropertySetInfo();
194 if (xInfo->hasPropertyByName(rPropName))
195 xSet->removePropertyChangeListener(rPropName, pListener);
197 //-------------------------------------------------------------------------
198 ::rtl::OUString SAL_CALL SbaTableQueryBrowser::getImplementationName() throw(RuntimeException)
200 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getImplementationName" );
201 return getImplementationName_Static();
203 //-------------------------------------------------------------------------
204 ::comphelper::StringSequence SAL_CALL SbaTableQueryBrowser::getSupportedServiceNames() throw(RuntimeException)
206 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getSupportedServiceNames" );
207 return getSupportedServiceNames_Static();
209 // -------------------------------------------------------------------------
210 ::rtl::OUString SbaTableQueryBrowser::getImplementationName_Static() throw(RuntimeException)
212 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getImplementationName_Static" );
213 return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.ODatasourceBrowser");
215 //-------------------------------------------------------------------------
216 ::comphelper::StringSequence SbaTableQueryBrowser::getSupportedServiceNames_Static() throw(RuntimeException)
218 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getSupportedServiceNames_Static" );
219 ::comphelper::StringSequence aSupported(1);
220 aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.DataSourceBrowser");
221 return aSupported;
223 //-------------------------------------------------------------------------
224 Reference< XInterface > SAL_CALL SbaTableQueryBrowser::Create(const Reference<XMultiServiceFactory >& _rxFactory)
226 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::Create" );
227 ::vos::OGuard aGuard(Application::GetSolarMutex());
228 return *(new SbaTableQueryBrowser(_rxFactory));
231 DBG_NAME(SbaTableQueryBrowser);
232 //------------------------------------------------------------------------------
233 SbaTableQueryBrowser::SbaTableQueryBrowser(const Reference< XMultiServiceFactory >& _rM)
234 :SbaXDataBrowserController(_rM)
235 ,m_aSelectionListeners( getMutex() )
236 ,m_aContextMenuInterceptors( getMutex() )
237 ,m_aTableCopyHelper(this)
238 ,m_pTreeView(NULL)
239 ,m_pSplitter(NULL)
240 ,m_pTreeModel(NULL)
241 ,m_pCurrentlyDisplayed(NULL)
242 ,m_nAsyncDrop(0)
243 ,m_nBorder(1)
244 ,m_bQueryEscapeProcessing( sal_False )
245 ,m_bShowMenu(sal_False)
246 ,m_bInSuspend(sal_False)
247 ,m_bEnableBrowser(sal_True)
249 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::SbaTableQueryBrowser" );
250 DBG_CTOR(SbaTableQueryBrowser,NULL);
253 //------------------------------------------------------------------------------
254 SbaTableQueryBrowser::~SbaTableQueryBrowser()
256 DBG_DTOR(SbaTableQueryBrowser,NULL);
257 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
259 OSL_ENSURE(0,"Please check who doesn't dispose this component!");
260 // increment ref count to prevent double call of Dtor
261 osl_incrementInterlockedCount( &m_refCount );
262 dispose();
266 //------------------------------------------------------------------------------
267 Any SAL_CALL SbaTableQueryBrowser::queryInterface(const Type& _rType) throw (RuntimeException)
269 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::queryInterface" );
270 if ( _rType.equals( XScriptInvocationContext::static_type() ) )
272 OSL_PRECOND( !!m_aDocScriptSupport, "SbaTableQueryBrowser::queryInterface: did not initialize this, yet!" );
273 if ( !!m_aDocScriptSupport && *m_aDocScriptSupport )
274 return makeAny( Reference< XScriptInvocationContext >( this ) );
275 return Any();
278 Any aReturn = SbaXDataBrowserController::queryInterface(_rType);
279 if (!aReturn.hasValue())
280 aReturn = SbaTableQueryBrowser_Base::queryInterface(_rType);
281 return aReturn;
284 //------------------------------------------------------------------------------
285 Sequence< Type > SAL_CALL SbaTableQueryBrowser::getTypes( ) throw (RuntimeException)
287 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getTypes" );
288 Sequence< Type > aTypes( ::comphelper::concatSequences(
289 SbaXDataBrowserController::getTypes(),
290 SbaTableQueryBrowser_Base::getTypes()
291 ) );
293 OSL_PRECOND( !!m_aDocScriptSupport, "SbaTableQueryBrowser::getTypes: did not initialize this, yet!" );
294 if ( !m_aDocScriptSupport || !*m_aDocScriptSupport )
296 Sequence< Type > aStrippedTypes( aTypes.getLength() - 1 );
297 ::std::remove_copy_if(
298 aTypes.getConstArray(),
299 aTypes.getConstArray() + aTypes.getLength(),
300 aStrippedTypes.getArray(),
301 ::std::bind2nd( ::std::equal_to< Type >(), XScriptInvocationContext::static_type() )
303 aTypes = aStrippedTypes;
305 return aTypes;
308 //------------------------------------------------------------------------------
309 Sequence< sal_Int8 > SAL_CALL SbaTableQueryBrowser::getImplementationId( ) throw (RuntimeException)
311 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getImplementationId" );
312 static ::cppu::OImplementationId * pId = 0;
313 if (! pId)
315 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
316 if (! pId)
318 static ::cppu::OImplementationId aId;
319 pId = &aId;
322 return pId->getImplementationId();
325 //------------------------------------------------------------------------------
326 void SAL_CALL SbaTableQueryBrowser::disposing()
328 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::disposing" );
329 ::vos::OGuard aGuard(Application::GetSolarMutex());
330 // doin' a lot of VCL stuff here -> lock the SolarMutex
332 // kiss our listeners goodbye
333 EventObject aEvt(*this);
334 m_aSelectionListeners.disposeAndClear(aEvt);
335 m_aContextMenuInterceptors.disposeAndClear(aEvt);
337 // reset the content's tree view: it holds a reference to our model which is to be deleted immediately,
338 // and it will live longer than we do.
339 if (getBrowserView())
340 getBrowserView()->setTreeView(NULL);
342 clearTreeModel();
343 // clear the tree model
345 ::std::auto_ptr<SvLBoxTreeList> aTemp(m_pTreeModel);
346 m_pTreeModel = NULL;
349 // remove ourself as status listener
350 implRemoveStatusListeners();
352 // remove the container listener from the database context
353 Reference< XContainer > xDatasourceContainer(m_xDatabaseContext, UNO_QUERY);
354 if (xDatasourceContainer.is())
355 xDatasourceContainer->removeContainerListener(this);
357 // check out from all the objects we are listening
358 // the frame
359 if (m_xCurrentFrameParent.is())
360 m_xCurrentFrameParent->removeFrameActionListener((::com::sun::star::frame::XFrameActionListener*)this);
361 SbaXDataBrowserController::disposing();
364 //------------------------------------------------------------------------------
365 sal_Bool SbaTableQueryBrowser::Construct(Window* pParent)
367 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::Construct" );
368 if (!SbaXDataBrowserController::Construct(pParent))
369 return sal_False;
373 Reference< XContainer > xDatasourceContainer(m_xDatabaseContext, UNO_QUERY);
374 if (xDatasourceContainer.is())
375 xDatasourceContainer->addContainerListener(this);
376 else {
377 DBG_ERROR("SbaTableQueryBrowser::Construct: the DatabaseContext should allow us to be a listener!");
380 // the collator for the string compares
381 m_xCollator = Reference< XCollator >(getORB()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.i18n.Collator")), UNO_QUERY);
382 if (m_xCollator.is())
383 m_xCollator->loadDefaultCollator(Application::GetSettings().GetLocale(), 0);
385 catch(Exception&)
387 DBG_ERROR("SbaTableQueryBrowser::Construct: could not create (or start listening at) the database context!");
389 // some help ids
390 if (getBrowserView() && getBrowserView()->getVclControl())
393 // create controls and set sizes
394 const long nFrameWidth = getBrowserView()->LogicToPixel( ::Size( 3, 0 ), MAP_APPFONT ).Width();
396 m_pSplitter = new Splitter(getBrowserView(),WB_HSCROLL);
397 m_pSplitter->SetPosSizePixel( ::Point(0,0), ::Size(nFrameWidth,0) );
398 m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) );
400 m_pTreeView = new DBTreeView(getBrowserView(),getORB(), WB_TABSTOP | WB_BORDER);
401 m_pTreeView->SetPreExpandHandler(LINK(this, SbaTableQueryBrowser, OnExpandEntry));
403 m_pTreeView->setCopyHandler(LINK(this, SbaTableQueryBrowser, OnCopyEntry));
405 m_pTreeView->getListBox().setContextMenuProvider( this );
406 m_pTreeView->getListBox().setControlActionListener( this );
407 m_pTreeView->SetHelpId(HID_CTL_TREEVIEW);
409 // a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide
410 m_pSplitter->SetSplitPosPixel( getBrowserView()->LogicToPixel( ::Size( 80, 0 ), MAP_APPFONT ).Width() );
412 getBrowserView()->setSplitter(m_pSplitter);
413 getBrowserView()->setTreeView(m_pTreeView);
415 // fill view with data
416 m_pTreeModel = new SvLBoxTreeList;
417 m_pTreeModel->SetSortMode(SortAscending);
418 m_pTreeModel->SetCompareHdl(LINK(this, SbaTableQueryBrowser, OnTreeEntryCompare));
419 m_pTreeView->setModel(m_pTreeModel);
420 m_pTreeView->setSelChangeHdl( LINK( this, SbaTableQueryBrowser, OnSelectionChange ) );
422 // TODO
423 getBrowserView()->getVclControl()->GetDataWindow().SetUniqueId(UID_DATABROWSE_DATAWINDOW);
424 getBrowserView()->getVclControl()->SetHelpId(HID_CTL_TABBROWSER);
425 getBrowserView()->SetUniqueId(UID_CTL_CONTENT);
426 if (getBrowserView()->getVclControl()->GetHeaderBar())
427 getBrowserView()->getVclControl()->GetHeaderBar()->SetHelpId(HID_DATABROWSE_HEADER);
428 InvalidateFeature(ID_BROWSER_EXPLORER);
431 return sal_True;
433 // -------------------------------------------------------------------------
434 sal_Bool SbaTableQueryBrowser::InitializeForm(const Reference< ::com::sun::star::sdbc::XRowSet > & _rxForm)
436 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::InitializeForm" );
437 if(!m_pCurrentlyDisplayed)
438 return sal_True;
440 // this method set all format settings from the orignal table or query
443 // we send all properties at once, maybe the implementation is clever enough to handle one big PropertiesChanged
444 // more effective than many small PropertyChanged ;)
445 Sequence< ::rtl::OUString> aProperties(3);
446 Sequence< Any> aValues(3);
448 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
449 OSL_ENSURE( pData, "SbaTableQueryBrowser::InitializeForm: No user data set at the currently displayed entry!" );
450 OSL_ENSURE( pData->xObjectProperties.is(), "SbaTableQueryBrowser::InitializeForm: No table available!" );
452 if ( pData->xObjectProperties.is() )
454 sal_Int32 nPos = 0;
455 // is the filter intially applied ?
456 aProperties.getArray()[nPos] = PROPERTY_APPLYFILTER;
457 aValues.getArray()[nPos++] = pData->xObjectProperties->getPropertyValue(PROPERTY_APPLYFILTER);
459 // the initial filter
460 aProperties.getArray()[nPos] = PROPERTY_FILTER;
461 aValues.getArray()[nPos++] = pData->xObjectProperties->getPropertyValue(PROPERTY_FILTER);
463 if ( pData->xObjectProperties->getPropertySetInfo()->hasPropertyByName(PROPERTY_HAVING_CLAUSE) )
465 aProperties.realloc(aProperties.getLength()+1);
466 aValues.realloc(aValues.getLength()+1);
467 // the initial having clause
468 aProperties.getArray()[nPos] = PROPERTY_HAVING_CLAUSE;
469 aValues.getArray()[nPos++] = pData->xObjectProperties->getPropertyValue(PROPERTY_HAVING_CLAUSE);
472 // the initial ordering
473 aProperties.getArray()[nPos] = PROPERTY_ORDER;
474 aValues.getArray()[nPos++] = pData->xObjectProperties->getPropertyValue(PROPERTY_ORDER);
476 Reference< XMultiPropertySet > xFormMultiSet(_rxForm, UNO_QUERY);
477 xFormMultiSet->setPropertyValues(aProperties, aValues);
480 catch(Exception&)
482 DBG_ERROR("SbaTableQueryBrowser::InitializeForm : something went wrong !");
483 return sal_False;
487 return sal_True;
490 //------------------------------------------------------------------------------
491 void SbaTableQueryBrowser::initializePreviewMode()
493 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::initializePreviewMode" );
494 if ( getBrowserView() && getBrowserView()->getVclControl() )
496 getBrowserView()->getVclControl()->AlwaysEnableInput( FALSE );
497 getBrowserView()->getVclControl()->EnableInput( FALSE );
498 getBrowserView()->getVclControl()->ForceHideScrollbars( sal_True );
500 Reference< XPropertySet > xDataSourceSet(getRowSet(), UNO_QUERY);
501 if ( xDataSourceSet.is() )
503 xDataSourceSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowInserts")),makeAny(sal_False));
504 xDataSourceSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowUpdates")),makeAny(sal_False));
505 xDataSourceSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowDeletes")),makeAny(sal_False));
509 //------------------------------------------------------------------------------
510 sal_Bool SbaTableQueryBrowser::InitializeGridModel(const Reference< ::com::sun::star::form::XFormComponent > & xGrid)
512 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::InitializeGridModel" );
515 Reference< ::com::sun::star::form::XGridColumnFactory > xColFactory(xGrid, UNO_QUERY);
516 Reference< XNameContainer > xColContainer(xGrid, UNO_QUERY);
517 clearGridColumns( xColContainer );
519 Reference< XChild > xGridAsChild(xGrid, UNO_QUERY);
520 Reference< XLoadable > xFormAsLoadable;
521 if (xGridAsChild.is())
522 xFormAsLoadable = xFormAsLoadable.query(xGridAsChild->getParent());
523 if (xFormAsLoadable.is() && xFormAsLoadable->isLoaded())
525 // set the formats from the table
526 if(m_pCurrentlyDisplayed)
528 Sequence< ::rtl::OUString> aProperties(6 + ( m_bPreview ? 5 : 0 ));
529 Sequence< Any> aValues(7 + ( m_bPreview ? 5 : 0 ));
531 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
532 OSL_ENSURE( pData->xObjectProperties.is(), "SbaTableQueryBrowser::InitializeGridModel: No table available!" );
534 ::rtl::OUString* pStringIter = aProperties.getArray();
535 Any* pValueIter = aValues.getArray();
536 if ( m_bPreview )
538 *pStringIter++ = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AlwaysShowCursor"));
539 *pValueIter++ <<= sal_False;
540 *pStringIter++ = PROPERTY_BORDER;
541 *pValueIter++ <<= sal_Int16(0);
544 *pStringIter++ = PROPERTY_FONT;
545 *pValueIter++ = pData->xObjectProperties->getPropertyValue(PROPERTY_FONT);
546 *pStringIter++ = PROPERTY_TEXTEMPHASIS;
547 *pValueIter++ = pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTEMPHASIS);
548 *pStringIter++ = PROPERTY_TEXTRELIEF;
549 *pValueIter++ = pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTRELIEF);
550 if ( m_bPreview )
552 *pStringIter++ = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasNavigationBar"));
553 *pValueIter++ <<= sal_False;
554 *pStringIter++ = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasRecordMarker"));
555 *pValueIter++ <<= sal_False;
557 *pStringIter++ = PROPERTY_ROW_HEIGHT;
558 *pValueIter++ = pData->xObjectProperties->getPropertyValue(PROPERTY_ROW_HEIGHT);
559 if ( m_bPreview )
561 *pStringIter++ = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tabstop"));
562 *pValueIter++ <<= sal_False;
564 *pStringIter++ = PROPERTY_TEXTCOLOR;
565 *pValueIter++ = pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTCOLOR);
566 *pStringIter++ = PROPERTY_TEXTLINECOLOR;
567 *pValueIter++ = pData->xObjectProperties->getPropertyValue(PROPERTY_TEXTLINECOLOR);
569 Reference< XMultiPropertySet > xFormMultiSet(xGrid, UNO_QUERY);
570 xFormMultiSet->setPropertyValues(aProperties, aValues);
574 // get the formats supplier of the database we're working with
575 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier = getNumberFormatter()->getNumberFormatsSupplier();
577 Reference<XConnection> xConnection;
578 Reference<XPropertySet> xRowSetProps(getRowSet(),UNO_QUERY);
579 xRowSetProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xConnection;
580 OSL_ENSURE(xConnection.is(),"A ActiveConnection should normaly exists!");
582 Reference<XChild> xChild(xConnection,UNO_QUERY);
583 Reference<XPropertySet> xDataSourceProp(xChild->getParent(),UNO_QUERY);
584 sal_Bool bSuppressVersionCol = sal_False;
585 OSL_VERIFY( xDataSourceProp->getPropertyValue( PROPERTY_SUPPRESSVERSIONCL ) >>= bSuppressVersionCol );
587 // insert the column into the gridcontrol so that we see something :-)
588 ::rtl::OUString aCurrentModelType;
589 Reference<XColumnsSupplier> xSupCols(getRowSet(),UNO_QUERY);
590 Reference<XNameAccess> xColumns = xSupCols->getColumns();
591 Sequence< ::rtl::OUString> aNames = xColumns->getElementNames();
592 const ::rtl::OUString* pIter = aNames.getConstArray();
593 const ::rtl::OUString* pEnd = pIter + aNames.getLength();
595 ::rtl::OUString sDefaultProperty;
596 Reference< XPropertySet > xColumn;
597 Reference< XPropertySetInfo > xColPSI;
598 for (sal_uInt16 i=0; pIter != pEnd; ++i,++pIter)
600 xColumn.set( xColumns->getByName( *pIter ), UNO_QUERY_THROW );
601 xColPSI.set( xColumn->getPropertySetInfo(), UNO_SET_THROW );
603 // ignore the column when it is a rowversion one
604 if ( bSuppressVersionCol
605 && xColPSI->hasPropertyByName( PROPERTY_ISROWVERSION )
606 && ::cppu::any2bool( xColumn->getPropertyValue( PROPERTY_ISROWVERSION ) )
608 continue;
610 // use the result set column's type to determine the type of grid column to create
611 sal_Bool bFormattedIsNumeric = sal_True;
612 sal_Int32 nType = ::comphelper::getINT32( xColumn->getPropertyValue( PROPERTY_TYPE ) );
614 ::std::vector< NamedValue > aInitialValues;
615 ::std::vector< ::rtl::OUString > aCopyProperties;
617 switch(nType)
619 case DataType::BIT:
620 case DataType::BOOLEAN:
622 aCurrentModelType = ::rtl::OUString::createFromAscii("CheckBox");
623 aInitialValues.push_back( NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VisualEffect" ) ), makeAny( VisualEffect::FLAT ) ) );
624 sDefaultProperty = PROPERTY_DEFAULTSTATE;
626 sal_Int32 nNullable = ColumnValue::NULLABLE_UNKNOWN;
627 OSL_VERIFY( xColumn->getPropertyValue( PROPERTY_ISNULLABLE ) >>= nNullable );
628 aInitialValues.push_back( NamedValue(
629 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TriState" ) ),
630 makeAny( sal_Bool( ColumnValue::NO_NULLS != nNullable ) )
631 ) );
633 break;
635 case DataType::LONGVARCHAR:
636 aInitialValues.push_back( NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ), makeAny( (sal_Bool)sal_True ) ) );
637 // NO break!
638 case DataType::BINARY:
639 case DataType::VARBINARY:
640 case DataType::LONGVARBINARY:
641 aCurrentModelType = ::rtl::OUString::createFromAscii("TextField");
642 sDefaultProperty = PROPERTY_DEFAULTTEXT;
643 break;
645 case DataType::VARCHAR:
646 case DataType::CHAR:
647 bFormattedIsNumeric = sal_False;
648 // NO break!
649 default:
650 aCurrentModelType = ::rtl::OUString::createFromAscii("FormattedField");
651 sDefaultProperty = PROPERTY_EFFECTIVEDEFAULT;
653 if ( xSupplier.is() )
654 aInitialValues.push_back( NamedValue( ::rtl::OUString::createFromAscii( "FormatsSupplier" ), makeAny( xSupplier ) ) );
655 aInitialValues.push_back( NamedValue( ::rtl::OUString::createFromAscii( "TreatAsNumber" ), makeAny( (sal_Bool)bFormattedIsNumeric ) ) );
656 aCopyProperties.push_back( PROPERTY_FORMATKEY );
657 break;
660 aInitialValues.push_back( NamedValue( PROPERTY_CONTROLSOURCE, makeAny( *pIter ) ) );
661 aInitialValues.push_back( NamedValue( PROPERTY_LABEL, makeAny( *pIter ) ) );
663 Reference< XPropertySet > xGridCol( xColFactory->createColumn( aCurrentModelType ), UNO_SET_THROW );
664 Reference< XPropertySetInfo > xGridColPSI( xGridCol->getPropertySetInfo(), UNO_SET_THROW );
666 // calculate the default
667 Any aDefault;
668 if ( xGridColPSI->hasPropertyByName( PROPERTY_CONTROLDEFAULT ) )
669 aDefault = xColumn->getPropertyValue( PROPERTY_CONTROLDEFAULT );
671 // default value
672 if ( nType == DataType::BIT || nType == DataType::BOOLEAN )
674 if ( aDefault.hasValue() )
675 aDefault <<= (comphelper::getString(aDefault).toInt32() == 0) ? (sal_Int16)STATE_NOCHECK : (sal_Int16)STATE_CHECK;
676 else
677 aDefault <<= ((sal_Int16)STATE_DONTKNOW);
681 if ( aDefault.hasValue() )
682 aInitialValues.push_back( NamedValue( sDefaultProperty, aDefault ) );
684 // transfer properties from the definition to the UNO-model :
685 aCopyProperties.push_back( PROPERTY_HIDDEN );
686 aCopyProperties.push_back( PROPERTY_WIDTH );
688 // help text to display for the column
689 Any aDescription;
690 if ( xColPSI->hasPropertyByName( PROPERTY_HELPTEXT ) )
691 aDescription = xColumn->getPropertyValue( PROPERTY_HELPTEXT );
692 if ( !aDescription.hasValue() )
693 aDescription <<= ::rtl::OUString();
694 aInitialValues.push_back( NamedValue( PROPERTY_HELPTEXT, aDescription ) );
696 // ... horizontal justify
697 Any aAlign; aAlign <<= sal_Int16( 0 );
698 Any aColAlign( xColumn->getPropertyValue( PROPERTY_ALIGN ) );
699 if ( aColAlign.hasValue() )
700 aAlign <<= sal_Int16( ::comphelper::getINT32( aColAlign ) );
701 aInitialValues.push_back( NamedValue( PROPERTY_ALIGN, aAlign ) );
703 // don't allow the mouse to scroll in the cells
704 if ( xGridColPSI->hasPropertyByName( PROPERTY_MOUSE_WHEEL_BEHAVIOR ) )
705 aInitialValues.push_back( NamedValue( PROPERTY_MOUSE_WHEEL_BEHAVIOR, makeAny( MouseWheelBehavior::SCROLL_DISABLED ) ) );
707 // now set all those values
708 for ( ::std::vector< NamedValue >::const_iterator property = aInitialValues.begin();
709 property != aInitialValues.end();
710 ++property
713 xGridCol->setPropertyValue( property->Name, property->Value );
715 for ( ::std::vector< ::rtl::OUString >::const_iterator copyPropertyName = aCopyProperties.begin();
716 copyPropertyName != aCopyProperties.end();
717 ++copyPropertyName
719 xGridCol->setPropertyValue( *copyPropertyName, xColumn->getPropertyValue( *copyPropertyName ) );
721 xColContainer->insertByName(*pIter, makeAny(xGridCol));
725 catch(Exception&)
727 DBG_UNHANDLED_EXCEPTION();
728 return sal_False;
731 return sal_True;
733 // -----------------------------------------------------------------------------
734 Reference<XPropertySet> getColumnHelper(SvLBoxEntry* _pCurrentlyDisplayed,const Reference<XPropertySet>& _rxSource)
736 Reference<XPropertySet> xRet;
737 if(_pCurrentlyDisplayed)
739 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pCurrentlyDisplayed->GetUserData());
740 Reference<XColumnsSupplier> xColumnsSup(pData->xObjectProperties,UNO_QUERY);
741 Reference<XNameAccess> xNames = xColumnsSup->getColumns();
742 ::rtl::OUString aName;
743 _rxSource->getPropertyValue(PROPERTY_NAME) >>= aName;
744 if(xNames.is() && xNames->hasByName(aName))
745 ::cppu::extractInterface(xRet,xNames->getByName(aName));
747 return xRet;
750 // -----------------------------------------------------------------------
751 void SbaTableQueryBrowser::transferChangedControlProperty(const ::rtl::OUString& _rProperty, const Any& _rNewValue)
753 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::transferChangedControlProperty" );
754 if(m_pCurrentlyDisplayed)
756 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
757 Reference< XPropertySet > xObjectProps(pData->xObjectProperties, UNO_QUERY);
758 OSL_ENSURE(xObjectProps.is(),"SbaTableQueryBrowser::transferChangedControlProperty: no table/query object!");
759 if (xObjectProps.is())
760 xObjectProps->setPropertyValue(_rProperty, _rNewValue);
764 // -----------------------------------------------------------------------
765 void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException)
767 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::propertyChange" );
768 SbaXDataBrowserController::propertyChange(evt);
772 Reference< XPropertySet > xSource(evt.Source, UNO_QUERY);
773 if (!xSource.is())
774 return;
776 // one of the many properties which require us to update the definition ?
777 // a column's width ?
778 else if (evt.PropertyName.equals(PROPERTY_WIDTH))
779 { // a column width has changed -> update the model
780 // (the update of the view is done elsewhere)
781 Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
782 if(xProp.is())
784 if(!evt.NewValue.hasValue())
785 xProp->setPropertyValue(PROPERTY_WIDTH,makeAny((sal_Int32)227));
786 else
787 xProp->setPropertyValue(PROPERTY_WIDTH,evt.NewValue);
791 // a column's 'visible' state ?
792 else if (evt.PropertyName.equals(PROPERTY_HIDDEN))
794 Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
795 if(xProp.is())
796 xProp->setPropertyValue(PROPERTY_HIDDEN,evt.NewValue);
799 // a columns alignment ?
800 else if (evt.PropertyName.equals(PROPERTY_ALIGN))
802 Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
805 if(xProp.is())
807 if(evt.NewValue.hasValue())
809 sal_Int16 nAlign = 0;
810 if(evt.NewValue >>= nAlign)
811 xProp->setPropertyValue(PROPERTY_ALIGN,makeAny(sal_Int32(nAlign)));
812 else
813 xProp->setPropertyValue(PROPERTY_ALIGN,evt.NewValue);
815 else
816 xProp->setPropertyValue(PROPERTY_ALIGN,makeAny(::com::sun::star::awt::TextAlign::LEFT));
819 catch( const Exception& )
821 DBG_UNHANDLED_EXCEPTION();
825 // a column's format ?
826 else if ( (evt.PropertyName.equals(PROPERTY_FORMATKEY))
827 && (TypeClass_LONG == evt.NewValue.getValueTypeClass())
830 // update the model (means the definition object)
831 Reference<XPropertySet> xProp = getColumnHelper(m_pCurrentlyDisplayed,xSource);
832 if(xProp.is())
833 xProp->setPropertyValue(PROPERTY_FORMATKEY,evt.NewValue);
836 // some table definition properties ?
837 // the height of the rows in the grid ?
838 else if (evt.PropertyName.equals(PROPERTY_ROW_HEIGHT))
840 if(m_pCurrentlyDisplayed)
842 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(m_pCurrentlyDisplayed->GetUserData());
843 OSL_ENSURE( pData->xObjectProperties.is(), "No table available!" );
845 sal_Bool bDefault = !evt.NewValue.hasValue();
846 if (bDefault)
847 pData->xObjectProperties->setPropertyValue(PROPERTY_ROW_HEIGHT,makeAny((sal_Int32)45));
848 else
849 pData->xObjectProperties->setPropertyValue(PROPERTY_ROW_HEIGHT,evt.NewValue);
853 else if ( evt.PropertyName.equals(PROPERTY_FONT) // the font ?
854 || evt.PropertyName.equals(PROPERTY_TEXTCOLOR) // the text color ?
855 || evt.PropertyName.equals(PROPERTY_FILTER) // the filter ?
856 || evt.PropertyName.equals(PROPERTY_HAVING_CLAUSE) // the having clause ?
857 || evt.PropertyName.equals(PROPERTY_ORDER) // the sort ?
858 || evt.PropertyName.equals(PROPERTY_APPLYFILTER) // the appliance of the filter ?
859 || evt.PropertyName.equals(PROPERTY_TEXTLINECOLOR) // the text line color ?
860 || evt.PropertyName.equals(PROPERTY_TEXTEMPHASIS) // the text emphasis ?
861 || evt.PropertyName.equals(PROPERTY_TEXTRELIEF) // the text relief ?
864 transferChangedControlProperty(evt.PropertyName, evt.NewValue);
867 catch( const Exception& )
869 DBG_UNHANDLED_EXCEPTION();
873 // -----------------------------------------------------------------------
874 sal_Bool SbaTableQueryBrowser::suspend(sal_Bool bSuspend) throw( RuntimeException )
876 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::suspend" );
877 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
878 ::osl::MutexGuard aGuard( getMutex() );
879 if ( getView() && getView()->IsInModalMode() )
880 return sal_False;
881 sal_Bool bRet = sal_False;
882 if ( !m_bInSuspend )
884 m_bInSuspend = sal_True;
885 if ( rBHelper.bDisposed )
886 throw DisposedException( ::rtl::OUString(), *this );
888 bRet = SbaXDataBrowserController::suspend(bSuspend);
889 if ( bRet && getView() )
890 getView()->Hide();
892 m_bInSuspend = sal_False;
895 return bRet;
898 // -------------------------------------------------------------------------
899 void SAL_CALL SbaTableQueryBrowser::statusChanged( const FeatureStateEvent& _rEvent ) throw(RuntimeException)
901 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::statusChanged" );
902 // search the external dispatcher causing this call
903 Reference< XDispatch > xSource(_rEvent.Source, UNO_QUERY);
904 ExternalFeaturesMap::iterator aLoop;
905 for ( aLoop = m_aExternalFeatures.begin();
906 aLoop != m_aExternalFeatures.end();
907 ++aLoop
910 if ( _rEvent.FeatureURL.Complete == aLoop->second.aURL.Complete)
912 DBG_ASSERT( xSource.get() == aLoop->second.xDispatcher.get(), "SbaTableQueryBrowser::statusChanged: inconsistent!" );
913 // update the enabled state
914 aLoop->second.bEnabled = _rEvent.IsEnabled;
916 switch ( aLoop->first )
918 case ID_BROWSER_DOCUMENT_DATASOURCE:
920 // if it's the slot for the document data source, remember the state
921 Sequence< PropertyValue > aDescriptor;
922 #if OSL_DEBUG_LEVEL > 0
923 sal_Bool bProperFormat =
924 #endif
925 _rEvent.State >>= aDescriptor;
926 OSL_ENSURE(bProperFormat, "SbaTableQueryBrowser::statusChanged: need a data access descriptor here!");
927 m_aDocumentDataSource.initializeFrom(aDescriptor);
929 OSL_ENSURE( ( m_aDocumentDataSource.has(daDataSource)
930 || m_aDocumentDataSource.has(daDatabaseLocation)
932 && m_aDocumentDataSource.has(daCommand)
933 && m_aDocumentDataSource.has(daCommandType),
934 "SbaTableQueryBrowser::statusChanged: incomplete descriptor!");
936 // check if we know the object which is set as document data source
937 checkDocumentDataSource();
939 break;
941 default:
942 // update the toolbox
943 implCheckExternalSlot( aLoop->first );
944 break;
946 break;
950 DBG_ASSERT(aLoop != m_aExternalFeatures.end(), "SbaTableQueryBrowser::statusChanged: don't know who sent this!");
953 // -------------------------------------------------------------------------
954 void SbaTableQueryBrowser::checkDocumentDataSource()
956 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::checkDocumentDataSource" );
957 SvLBoxEntry* pDataSourceEntry = NULL;
958 SvLBoxEntry* pContainerEntry = NULL;
959 SvLBoxEntry* pObjectEntry = getObjectEntry( m_aDocumentDataSource, &pDataSourceEntry, &pContainerEntry, sal_False );
960 sal_Bool bKnownDocDataSource = (NULL != pObjectEntry);
961 if (!bKnownDocDataSource)
963 if (NULL != pDataSourceEntry)
964 { // at least the data source is know
965 if (NULL != pContainerEntry)
966 bKnownDocDataSource = sal_True; // assume we know it.
967 // TODO: should we expand the object container? This may be too expensive just for checking ....
968 else
970 if ((NULL == pObjectEntry) && m_aDocumentDataSource.has(daCommandType) && m_aDocumentDataSource.has(daCommand))
971 { // maybe we have a command to be displayed ?
972 sal_Int32 nCommandType = CommandType::TABLE;
973 m_aDocumentDataSource[daCommandType] >>= nCommandType;
975 ::rtl::OUString sCommand;
976 m_aDocumentDataSource[daCommand] >>= sCommand;
978 bKnownDocDataSource = (CommandType::COMMAND == nCommandType) && (0 != sCommand.getLength());
984 if ( !bKnownDocDataSource )
985 m_aExternalFeatures[ ID_BROWSER_DOCUMENT_DATASOURCE ].bEnabled = sal_False;
987 // update the toolbox
988 implCheckExternalSlot(ID_BROWSER_DOCUMENT_DATASOURCE);
991 // -------------------------------------------------------------------------
992 void SbaTableQueryBrowser::extractDescriptorProps(const ::svx::ODataAccessDescriptor& _rDescriptor, ::rtl::OUString& _rDataSource, ::rtl::OUString& _rCommand, sal_Int32& _rCommandType, sal_Bool& _rEscapeProcessing)
994 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::extractDescriptorProps" );
995 _rDataSource = _rDescriptor.getDataSource();
996 if ( _rDescriptor.has(daCommand) )
997 _rDescriptor[daCommand] >>= _rCommand;
998 if ( _rDescriptor.has(daCommandType) )
999 _rDescriptor[daCommandType] >>= _rCommandType;
1001 // escape processing is the only one allowed not to be present
1002 _rEscapeProcessing = sal_True;
1003 if (_rDescriptor.has(daEscapeProcessing))
1004 _rEscapeProcessing = ::cppu::any2bool(_rDescriptor[daEscapeProcessing]);
1007 // -------------------------------------------------------------------------
1008 namespace
1010 bool getDataSourceDisplayName_isURL( const String& _rDS, String& _rDisplayName, String& _rUniqueId )
1012 INetURLObject aURL( _rDS );
1013 if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1015 _rDisplayName = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_WITH_CHARSET);
1016 // _rDisplayName = aURL.getName(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_WITH_CHARSET);
1017 _rUniqueId = aURL.GetMainURL( INetURLObject::NO_DECODE );
1018 return true;
1020 _rDisplayName = _rDS;
1021 _rUniqueId = String();
1022 return false;
1025 // .....................................................................
1026 struct FilterByEntryDataId : public IEntryFilter
1028 String sId;
1029 FilterByEntryDataId( const String& _rId ) : sId( _rId ) { }
1031 virtual ~FilterByEntryDataId() {}
1033 virtual bool includeEntry( SvLBoxEntry* _pEntry ) const;
1036 bool FilterByEntryDataId::includeEntry( SvLBoxEntry* _pEntry ) const
1038 DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( _pEntry->GetUserData() );
1039 return ( !pData || ( pData->sAccessor == sId ) );
1043 // -------------------------------------------------------------------------
1044 String SbaTableQueryBrowser::getDataSourceAcessor( SvLBoxEntry* _pDataSourceEntry ) const
1046 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getDataSourceAcessor" );
1047 DBG_ASSERT( _pDataSourceEntry, "SbaTableQueryBrowser::getDataSourceAcessor: invalid entry!" );
1049 DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( _pDataSourceEntry->GetUserData() );
1050 DBG_ASSERT( pData, "SbaTableQueryBrowser::getDataSourceAcessor: invalid entry data!" );
1051 DBG_ASSERT( pData->eType == etDatasource, "SbaTableQueryBrowser::getDataSourceAcessor: entry does not denote a data source!" );
1052 return pData->sAccessor.Len() ? pData->sAccessor : GetEntryText( _pDataSourceEntry );
1055 // -------------------------------------------------------------------------
1056 SvLBoxEntry* SbaTableQueryBrowser::getObjectEntry(const ::rtl::OUString& _rDataSource, const ::rtl::OUString& _rCommand, sal_Int32 _nCommandType,
1057 SvLBoxEntry** _ppDataSourceEntry, SvLBoxEntry** _ppContainerEntry, sal_Bool _bExpandAncestors,
1058 const SharedConnection& _rxConnection )
1060 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getObjectEntry" );
1061 if (_ppDataSourceEntry)
1062 *_ppDataSourceEntry = NULL;
1063 if (_ppContainerEntry)
1064 *_ppContainerEntry = NULL;
1066 SvLBoxEntry* pObject = NULL;
1067 if ( m_pTreeView )
1069 // look for the data source entry
1070 String sDisplayName, sDataSourceId;
1071 bool bIsDataSourceURL = getDataSourceDisplayName_isURL( _rDataSource, sDisplayName, sDataSourceId );
1072 // the display name may differ from the URL for readability reasons
1073 // #i33699# - 2004-09-24 - fs@openoffice.org
1075 FilterByEntryDataId aFilter( sDataSourceId );
1076 SvLBoxEntry* pDataSource = m_pTreeView->getListBox().GetEntryPosByName( sDisplayName, NULL, &aFilter );
1077 if ( !pDataSource ) // check if the data source name is a file location
1079 if ( bIsDataSourceURL )
1081 // special case, the data source is a URL
1082 // add new entries to the list box model
1083 Image a, b, c; // not interested in reusing them
1084 String e, f;
1085 implAddDatasource( _rDataSource, a, e, b, f, c, _rxConnection );
1086 pDataSource = m_pTreeView->getListBox().GetEntryPosByName( sDisplayName, NULL, &aFilter );
1087 DBG_ASSERT( pDataSource, "SbaTableQueryBrowser::getObjectEntry: hmm - did not find it again!" );
1090 if (_ppDataSourceEntry)
1091 // (caller wants to have it ...)
1092 *_ppDataSourceEntry = pDataSource;
1094 if (pDataSource)
1096 // expand if required so
1097 if (_bExpandAncestors)
1098 m_pTreeView->getListBox().Expand(pDataSource);
1100 // look for the object container
1101 SvLBoxEntry* pCommandType = NULL;
1102 switch (_nCommandType)
1104 case CommandType::TABLE:
1105 pCommandType = m_pTreeView->getListBox().GetModel()->GetEntry(pDataSource, CONTAINER_TABLES);
1106 break;
1108 case CommandType::QUERY:
1109 pCommandType = m_pTreeView->getListBox().GetModel()->GetEntry(pDataSource, CONTAINER_QUERIES);
1110 break;
1113 if (_ppContainerEntry)
1114 *_ppContainerEntry = pCommandType;
1116 if (pCommandType)
1118 // expand if required so
1119 if (_bExpandAncestors)
1120 m_pTreeView->getListBox().Expand(pCommandType);
1122 // look for the object
1123 pObject = m_pTreeView->getListBox().GetEntryPosByName(_rCommand, pCommandType);
1127 return pObject;
1130 // -------------------------------------------------------------------------
1131 SvLBoxEntry* SbaTableQueryBrowser::getObjectEntry(const ::svx::ODataAccessDescriptor& _rDescriptor,
1132 SvLBoxEntry** _ppDataSourceEntry, SvLBoxEntry** _ppContainerEntry,
1133 sal_Bool _bExpandAncestors)
1135 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getObjectEntry" );
1136 // extract the props from the descriptor
1137 ::rtl::OUString sDataSource;
1138 ::rtl::OUString sCommand;
1139 sal_Int32 nCommandType = CommandType::COMMAND;
1140 sal_Bool bEscapeProcessing = sal_True;
1141 extractDescriptorProps(_rDescriptor, sDataSource, sCommand, nCommandType, bEscapeProcessing);
1143 return getObjectEntry( sDataSource, sCommand, nCommandType, _ppDataSourceEntry, _ppContainerEntry, _bExpandAncestors, SharedConnection() );
1146 // -------------------------------------------------------------------------
1147 void SbaTableQueryBrowser::connectExternalDispatches()
1149 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::connectExternalDispatches" );
1150 Reference< XDispatchProvider > xProvider( getFrame(), UNO_QUERY );
1151 DBG_ASSERT(xProvider.is(), "SbaTableQueryBrowser::connectExternalDispatches: no DispatchProvider !");
1152 if (xProvider.is())
1154 if ( m_aExternalFeatures.empty() )
1156 const sal_Char* pURLs[] = {
1157 ".uno:DataSourceBrowser/DocumentDataSource",
1158 ".uno:DataSourceBrowser/FormLetter",
1159 ".uno:DataSourceBrowser/InsertColumns",
1160 ".uno:DataSourceBrowser/InsertContent",
1162 const sal_uInt16 nIds[] = {
1163 ID_BROWSER_DOCUMENT_DATASOURCE,
1164 ID_BROWSER_FORMLETTER,
1165 ID_BROWSER_INSERTCOLUMNS,
1166 ID_BROWSER_INSERTCONTENT
1169 for ( size_t i=0; i < sizeof( pURLs ) / sizeof( pURLs[0] ); ++i )
1171 URL aURL;
1172 aURL.Complete = ::rtl::OUString::createFromAscii( pURLs[i] );
1173 if ( m_xUrlTransformer.is() )
1174 m_xUrlTransformer->parseStrict( aURL );
1175 m_aExternalFeatures[ nIds[ i ] ] = ExternalFeature( aURL );
1179 for ( ExternalFeaturesMap::iterator feature = m_aExternalFeatures.begin();
1180 feature != m_aExternalFeatures.end();
1181 ++feature
1184 feature->second.xDispatcher = xProvider->queryDispatch(
1185 feature->second.aURL, ::rtl::OUString::createFromAscii("_parent"), FrameSearchFlag::PARENT
1188 if ( feature->second.xDispatcher.get() == static_cast< XDispatch* >( this ) )
1190 OSL_ENSURE( sal_False, "SbaTableQueryBrowser::connectExternalDispatches: this should not happen anymore!" );
1191 // (nowadays, the URLs aren't in our SupportedFeatures list anymore, so we should
1192 // not supply a dispatcher for this)
1193 feature->second.xDispatcher.clear();
1196 if ( feature->second.xDispatcher.is() )
1200 feature->second.xDispatcher->addStatusListener( this, feature->second.aURL );
1202 catch( const Exception& )
1204 DBG_UNHANDLED_EXCEPTION();
1208 implCheckExternalSlot( feature->first );
1213 // -------------------------------------------------------------------------
1214 void SbaTableQueryBrowser::implCheckExternalSlot( sal_uInt16 _nId )
1216 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::implCheckExternalSlot" );
1217 if ( !m_xMainToolbar.is() )
1218 return;
1220 Window* pToolboxWindow = VCLUnoHelper::GetWindow( m_xMainToolbar );
1221 ToolBox* pToolbox = dynamic_cast< ToolBox* >( pToolboxWindow );
1222 OSL_ENSURE( pToolbox, "SbaTableQueryBrowser::implCheckExternalSlot: cannot obtain the toolbox window!" );
1224 // check if we have to hide this item from the toolbox
1225 if ( pToolbox )
1227 sal_Bool bHaveDispatcher = m_aExternalFeatures[ _nId ].xDispatcher.is();
1228 if ( bHaveDispatcher != pToolbox->IsItemVisible( _nId ) )
1229 bHaveDispatcher ? pToolbox->ShowItem( _nId ) : pToolbox->HideItem( _nId );
1232 // and invalidate this feature in general
1233 InvalidateFeature( _nId );
1236 // -------------------------------------------------------------------------
1237 void SAL_CALL SbaTableQueryBrowser::disposing( const EventObject& _rSource ) throw(RuntimeException)
1239 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::disposing" );
1240 // our frame ?
1241 Reference< ::com::sun::star::frame::XFrame > xSourceFrame(_rSource.Source, UNO_QUERY);
1242 if (m_xCurrentFrameParent.is() && (xSourceFrame == m_xCurrentFrameParent))
1243 m_xCurrentFrameParent->removeFrameActionListener((::com::sun::star::frame::XFrameActionListener*)this);
1244 else
1246 // search the external dispatcher causing this call in our map
1247 Reference< XDispatch > xSource(_rSource.Source, UNO_QUERY);
1248 if(xSource.is())
1250 for ( ExternalFeaturesMap::iterator aLoop = m_aExternalFeatures.begin();
1251 aLoop != m_aExternalFeatures.end();
1252 ++aLoop
1255 if ( aLoop->second.xDispatcher.get() == xSource.get() )
1257 ExternalFeaturesMap::iterator aPrevious = aLoop;
1258 --aPrevious;
1260 // remove it
1261 m_aExternalFeatures.erase( aLoop );
1263 // maybe update the UI
1264 implCheckExternalSlot(aLoop->first);
1266 // continue, the same XDispatch may be resposible for more than one URL
1267 aLoop = aPrevious;
1271 else
1273 Reference<XConnection> xCon(_rSource.Source, UNO_QUERY);
1274 if ( xCon.is() && m_pTreeView )
1275 { // our connection is in dispose so we have to find the entry equal with this connection
1276 // and close it what means to collapse the entry
1277 // get the top-level representing the removed data source
1278 SvLBoxEntry* pDSLoop = m_pTreeView->getListBox().FirstChild(NULL);
1279 while (pDSLoop)
1281 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pDSLoop->GetUserData());
1282 if ( pData && pData->xConnection == xCon )
1284 // we set the conenction to null to avoid a second disposing of the connection
1285 pData->xConnection.clear();
1286 closeConnection(pDSLoop,sal_False);
1287 break;
1290 pDSLoop = m_pTreeView->getListBox().NextSibling(pDSLoop);
1293 else
1294 SbaXDataBrowserController::disposing(_rSource);
1299 // -------------------------------------------------------------------------
1300 void SbaTableQueryBrowser::implRemoveStatusListeners()
1302 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::implRemoveStatusListeners" );
1303 // clear all old dispatches
1304 for ( ExternalFeaturesMap::const_iterator aLoop = m_aExternalFeatures.begin();
1305 aLoop != m_aExternalFeatures.end();
1306 ++aLoop
1309 if ( aLoop->second.xDispatcher.is() )
1313 aLoop->second.xDispatcher->removeStatusListener( this, aLoop->second.aURL );
1315 catch (Exception&)
1317 DBG_ERROR("SbaTableQueryBrowser::implRemoveStatusListeners: could not remove a status listener!");
1321 m_aExternalFeatures.clear();
1324 // -------------------------------------------------------------------------
1325 sal_Bool SAL_CALL SbaTableQueryBrowser::select( const Any& _rSelection ) throw (IllegalArgumentException, RuntimeException)
1327 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::select" );
1328 ::vos::OGuard aGuard(Application::GetSolarMutex());
1329 // doin' a lot of VCL stuff here -> lock the SolarMutex
1331 Sequence< PropertyValue > aDescriptorSequence;
1332 if (!(_rSelection >>= aDescriptorSequence))
1333 throw IllegalArgumentException(::rtl::OUString(), *this, 1);
1334 // TODO: error message
1336 ODataAccessDescriptor aDescriptor;
1339 aDescriptor = ODataAccessDescriptor(aDescriptorSequence);
1341 catch(const Exception&)
1343 OSL_ENSURE(sal_False, "SbaTableQueryBrowser::select: could not extract the descriptor!");
1346 // check the precense of the props we need
1347 if ( !(aDescriptor.has(daDataSource) || aDescriptor.has(daDatabaseLocation)) || !aDescriptor.has(daCommand) || !aDescriptor.has(daCommandType))
1348 throw IllegalArgumentException(::rtl::OUString(), *this, 1);
1349 // TODO: error message
1351 return implSelect(aDescriptor,sal_True);
1354 // -------------------------------------------------------------------------
1355 Any SAL_CALL SbaTableQueryBrowser::getSelection( ) throw (RuntimeException)
1357 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getSelection" );
1358 Any aReturn;
1362 Reference< XLoadable > xLoadable(getRowSet(), UNO_QUERY);
1363 if (xLoadable.is() && xLoadable->isLoaded())
1365 Reference< XPropertySet > aFormProps(getRowSet(), UNO_QUERY);
1366 ODataAccessDescriptor aDescriptor(aFormProps);
1367 // remove properties which are not part of our "selection"
1368 aDescriptor.erase(daConnection);
1369 aDescriptor.erase(daCursor);
1371 aReturn <<= aDescriptor.createPropertyValueSequence();
1374 catch( const Exception& )
1376 DBG_UNHANDLED_EXCEPTION();
1379 return aReturn;
1382 // -------------------------------------------------------------------------
1383 void SAL_CALL SbaTableQueryBrowser::addSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException)
1385 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::addSelectionChangeListener" );
1386 m_aSelectionListeners.addInterface(_rxListener);
1389 // -------------------------------------------------------------------------
1390 void SAL_CALL SbaTableQueryBrowser::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) throw (RuntimeException)
1392 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::removeSelectionChangeListener" );
1393 m_aSelectionListeners.removeInterface(_rxListener);
1396 // -------------------------------------------------------------------------
1397 void SbaTableQueryBrowser::attachFrame(const Reference< ::com::sun::star::frame::XFrame > & _xFrame) throw( RuntimeException )
1399 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::attachFrame" );
1400 implRemoveStatusListeners();
1402 if (m_xCurrentFrameParent.is())
1403 m_xCurrentFrameParent->removeFrameActionListener((::com::sun::star::frame::XFrameActionListener*)this);
1405 SbaXDataBrowserController::attachFrame(_xFrame);
1407 Reference< XFrame > xCurrentFrame( getFrame() );
1408 if ( xCurrentFrame.is() )
1410 m_xCurrentFrameParent = xCurrentFrame->findFrame(::rtl::OUString::createFromAscii("_parent"),FrameSearchFlag::PARENT);
1411 if ( m_xCurrentFrameParent.is() )
1412 m_xCurrentFrameParent->addFrameActionListener((::com::sun::star::frame::XFrameActionListener*)this);
1414 // obtain our toolbox
1417 Reference< XPropertySet > xFrameProps( m_aCurrentFrame.getFrame(), UNO_QUERY_THROW );
1418 Reference< XLayoutManager > xLayouter(
1419 xFrameProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ) ),
1420 UNO_QUERY );
1422 if ( xLayouter.is() )
1424 Reference< XUIElement > xUI(
1425 xLayouter->getElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/toolbar" ) ) ),
1426 UNO_SET_THROW );
1427 m_xMainToolbar = m_xMainToolbar.query( xUI->getRealInterface() );
1428 OSL_ENSURE( m_xMainToolbar.is(), "SbaTableQueryBrowser::attachFrame: where's my toolbox?" );
1431 catch( const Exception& )
1433 DBG_UNHANDLED_EXCEPTION();
1437 // get the dispatchers for the external slots
1438 connectExternalDispatches();
1441 // -------------------------------------------------------------------------
1442 void SbaTableQueryBrowser::addModelListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
1444 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::addModelListeners" );
1445 SbaXDataBrowserController::addModelListeners(_xGridControlModel);
1446 Reference< XPropertySet > xSourceSet(_xGridControlModel, UNO_QUERY);
1447 if (xSourceSet.is())
1449 xSourceSet->addPropertyChangeListener(PROPERTY_ROW_HEIGHT, static_cast<XPropertyChangeListener*>(this));
1450 xSourceSet->addPropertyChangeListener(PROPERTY_FONT, static_cast<XPropertyChangeListener*>(this));
1451 xSourceSet->addPropertyChangeListener(PROPERTY_TEXTCOLOR, static_cast<XPropertyChangeListener*>(this));
1452 xSourceSet->addPropertyChangeListener(PROPERTY_TEXTLINECOLOR, static_cast<XPropertyChangeListener*>(this));
1453 xSourceSet->addPropertyChangeListener(PROPERTY_TEXTEMPHASIS, static_cast<XPropertyChangeListener*>(this));
1454 xSourceSet->addPropertyChangeListener(PROPERTY_TEXTRELIEF, static_cast<XPropertyChangeListener*>(this));
1459 // -------------------------------------------------------------------------
1460 void SbaTableQueryBrowser::removeModelListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
1462 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::removeModelListeners" );
1463 SbaXDataBrowserController::removeModelListeners(_xGridControlModel);
1464 Reference< XPropertySet > xSourceSet(_xGridControlModel, UNO_QUERY);
1465 if (xSourceSet.is())
1467 xSourceSet->removePropertyChangeListener(PROPERTY_ROW_HEIGHT, static_cast<XPropertyChangeListener*>(this));
1468 xSourceSet->removePropertyChangeListener(PROPERTY_FONT, static_cast<XPropertyChangeListener*>(this));
1469 xSourceSet->removePropertyChangeListener(PROPERTY_TEXTCOLOR, static_cast<XPropertyChangeListener*>(this));
1470 xSourceSet->removePropertyChangeListener(PROPERTY_TEXTLINECOLOR, static_cast<XPropertyChangeListener*>(this));
1471 xSourceSet->removePropertyChangeListener(PROPERTY_TEXTEMPHASIS, static_cast<XPropertyChangeListener*>(this));
1472 xSourceSet->removePropertyChangeListener(PROPERTY_TEXTRELIEF, static_cast<XPropertyChangeListener*>(this));
1475 // -------------------------------------------------------------------------
1476 void SbaTableQueryBrowser::RowChanged()
1478 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::RowChanged" );
1479 if(getBrowserView())
1481 SbaGridControl* pControl = getBrowserView()->getVclControl();
1482 if (!pControl->IsEditing())
1483 InvalidateFeature(ID_BROWSER_COPY);
1485 SbaXDataBrowserController::RowChanged();
1488 // -------------------------------------------------------------------------
1489 void SbaTableQueryBrowser::ColumnChanged()
1491 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::ColumnChanged" );
1492 if(getBrowserView())
1494 SbaGridControl* pControl = getBrowserView()->getVclControl();
1495 if (!pControl->IsEditing())
1496 InvalidateFeature(ID_BROWSER_COPY);
1498 SbaXDataBrowserController::ColumnChanged();
1500 //------------------------------------------------------------------------------
1501 void SbaTableQueryBrowser::AddColumnListener(const Reference< XPropertySet > & xCol)
1503 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::AddColumnListener" );
1504 SbaXDataBrowserController::AddColumnListener(xCol);
1505 SafeAddPropertyListener(xCol, PROPERTY_WIDTH, static_cast<XPropertyChangeListener*>(this));
1506 SafeAddPropertyListener(xCol, PROPERTY_HIDDEN, static_cast<XPropertyChangeListener*>(this));
1507 SafeAddPropertyListener(xCol, PROPERTY_ALIGN, static_cast<XPropertyChangeListener*>(this));
1508 SafeAddPropertyListener(xCol, PROPERTY_FORMATKEY, static_cast<XPropertyChangeListener*>(this));
1511 //------------------------------------------------------------------------------
1512 void SbaTableQueryBrowser::RemoveColumnListener(const Reference< XPropertySet > & xCol)
1514 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::RemoveColumnListener" );
1515 SbaXDataBrowserController::RemoveColumnListener(xCol);
1516 SafeRemovePropertyListener(xCol, PROPERTY_WIDTH, static_cast<XPropertyChangeListener*>(this));
1517 SafeRemovePropertyListener(xCol, PROPERTY_HIDDEN, static_cast<XPropertyChangeListener*>(this));
1518 SafeRemovePropertyListener(xCol, PROPERTY_ALIGN, static_cast<XPropertyChangeListener*>(this));
1519 SafeRemovePropertyListener(xCol, PROPERTY_FORMATKEY, static_cast<XPropertyChangeListener*>(this));
1522 //------------------------------------------------------------------------------
1523 void SbaTableQueryBrowser::criticalFail()
1525 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::criticalFail" );
1526 SbaXDataBrowserController::criticalFail();
1527 unloadAndCleanup( sal_False );
1530 //------------------------------------------------------------------------------
1531 void SbaTableQueryBrowser::LoadFinished(sal_Bool _bWasSynch)
1533 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::LoadFinished" );
1534 SbaXDataBrowserController::LoadFinished(_bWasSynch);
1536 m_sQueryCommand = ::rtl::OUString();
1537 m_bQueryEscapeProcessing = sal_False;
1539 if (isValid() && !loadingCancelled())
1541 // did we load a query?
1542 sal_Bool bTemporary; // needed because we m_bQueryEscapeProcessing is only one bit wide (and we want to pass it by reference)
1543 if ( implGetQuerySignature( m_sQueryCommand, bTemporary ) )
1544 m_bQueryEscapeProcessing = bTemporary;
1547 // if the form has been loaded, this means that our "selection" has changed
1548 EventObject aEvent( *this );
1549 m_aSelectionListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aEvent );
1552 //------------------------------------------------------------------------------
1553 sal_Bool SbaTableQueryBrowser::getExternalSlotState( sal_uInt16 _nId ) const
1555 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getExternalSlotState" );
1556 sal_Bool bEnabled = sal_False;
1557 ExternalFeaturesMap::const_iterator aPos = m_aExternalFeatures.find( _nId );
1558 if ( ( m_aExternalFeatures.end() != aPos ) && aPos->second.xDispatcher.is() )
1559 bEnabled = aPos->second.bEnabled;
1560 return bEnabled;
1563 //------------------------------------------------------------------------------
1564 FeatureState SbaTableQueryBrowser::GetState(sal_uInt16 nId) const
1566 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::GetState" );
1567 FeatureState aReturn;
1568 // (disabled automatically)
1570 // no chance without a view
1571 if (!getBrowserView() || !getBrowserView()->getVclControl())
1572 return aReturn;
1574 switch ( nId )
1576 case ID_TREE_ADMINISTRATE:
1577 aReturn.bEnabled = true;
1578 return aReturn;
1580 case ID_BROWSER_CLOSE:
1581 // the close button should always be enabled
1582 aReturn.bEnabled = !m_bEnableBrowser;
1583 return aReturn;
1585 // "toggle explorer" is always enabled (if we have a explorer)
1586 case ID_BROWSER_EXPLORER:
1587 aReturn.bEnabled = m_bEnableBrowser;
1588 aReturn.bChecked = haveExplorer();
1589 return aReturn;
1591 case ID_BROWSER_REMOVEFILTER:
1592 return SbaXDataBrowserController::GetState( nId );
1594 case ID_BROWSER_COPY:
1595 if ( !m_pTreeView->HasChildPathFocus() )
1596 // handled below
1597 break;
1598 // NO break!
1599 case ID_TREE_CLOSE_CONN:
1600 case ID_TREE_EDIT_DATABASE:
1602 SvLBoxEntry* pCurrentEntry( m_pTreeView->getListBox().GetCurEntry() );
1603 EntryType eType = getEntryType( pCurrentEntry );
1604 if ( eType == etUnknown )
1605 return aReturn;
1607 SvLBoxEntry* pDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent( pCurrentEntry );
1608 DBTreeListUserData* pDSData
1609 = pDataSourceEntry
1610 ? static_cast< DBTreeListUserData* >( pDataSourceEntry->GetUserData() )
1611 : NULL;
1613 if ( nId == ID_TREE_CLOSE_CONN )
1615 aReturn.bEnabled = ( pDSData != NULL ) && pDSData->xConnection.is();
1617 else if ( nId == ID_TREE_EDIT_DATABASE )
1619 ::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithServiceFactory( getORB(),
1620 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.DataAccess/Policies/Features/Common" ) ) ) );
1621 sal_Bool bHaveEditDatabase( sal_True );
1622 OSL_VERIFY( aConfig.getNodeValue( "EditDatabaseFromDataSourceView" ) >>= bHaveEditDatabase );
1623 aReturn.bEnabled = getORB().is() && ( pDataSourceEntry != NULL ) && bHaveEditDatabase;
1625 else if ( nId == ID_BROWSER_COPY )
1627 aReturn.bEnabled = isEntryCopyAllowed( pCurrentEntry );
1630 return aReturn;
1634 // all slots not handled above are not available if no form is loaded
1635 if (!isLoaded())
1636 return aReturn;
1640 sal_Bool bHandled = sal_False;
1641 switch (nId)
1643 case ID_BROWSER_DOCUMENT_DATASOURCE:
1644 // the slot is enabled if we have an external dispatcher able to handle it,
1645 // and the dispatcher must have enabled the slot in general
1646 aReturn.bEnabled = getExternalSlotState( ID_BROWSER_DOCUMENT_DATASOURCE );
1647 bHandled = sal_True;
1648 break;
1649 case ID_BROWSER_REFRESH:
1650 aReturn.bEnabled = sal_True;
1651 bHandled = sal_True;
1652 break;
1655 if (bHandled)
1656 return aReturn;
1658 // no chance without valid models
1659 if (isValid() && !isValidCursor() && nId != ID_BROWSER_CLOSE)
1660 return aReturn;
1662 // no chance while loading the form
1663 if (PendingLoad())
1664 return aReturn;
1666 switch (nId)
1668 case ID_BROWSER_INSERTCOLUMNS:
1669 case ID_BROWSER_INSERTCONTENT:
1670 case ID_BROWSER_FORMLETTER:
1672 // the slot is enabled if we have an external dispatcher able to handle it,
1673 // and the dispatcher must have enabled the slot in general
1674 aReturn.bEnabled = getExternalSlotState( nId );
1676 // for the Insert* slots, we need at least one selected row
1677 if (ID_BROWSER_FORMLETTER != nId)
1678 aReturn.bEnabled = aReturn.bEnabled && getBrowserView()->getVclControl()->GetSelectRowCount();
1680 // disabled for native queries which are not saved within the database
1681 // 67706 - 23.08.99 - FS
1682 Reference< XPropertySet > xDataSource(getRowSet(), UNO_QUERY);
1685 aReturn.bEnabled = aReturn.bEnabled && xDataSource.is();
1687 if (xDataSource.is())
1689 sal_Int32 nType = ::comphelper::getINT32(xDataSource->getPropertyValue(PROPERTY_COMMAND_TYPE));
1690 aReturn.bEnabled = aReturn.bEnabled && ((::comphelper::getBOOL(xDataSource->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || (nType == ::com::sun::star::sdb::CommandType::QUERY)));
1693 catch(DisposedException&)
1695 OSL_ENSURE(sal_False, "SbaTableQueryBrowser::GetState: object already disposed!");
1697 catch( const Exception& )
1699 DBG_UNHANDLED_EXCEPTION();
1702 break;
1704 case ID_BROWSER_TITLE:
1706 Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
1707 sal_Int32 nCommandType = CommandType::TABLE;
1708 xProp->getPropertyValue(PROPERTY_COMMAND_TYPE) >>= nCommandType;
1709 String sTitle;
1710 switch (nCommandType)
1712 case CommandType::TABLE:
1713 sTitle = String(ModuleRes(STR_TBL_TITLE)); break;
1714 case CommandType::QUERY:
1715 case CommandType::COMMAND:
1716 sTitle = String(ModuleRes(STR_QRY_TITLE)); break;
1717 default:
1718 DBG_ASSERT(sal_False, "SbaTableQueryBrowser::GetState: unknown command type!");
1720 ::rtl::OUString aName;
1721 xProp->getPropertyValue(PROPERTY_COMMAND) >>= aName;
1722 String sObject(aName.getStr());
1724 sTitle.SearchAndReplace('#',sObject);
1725 aReturn.sTitle = sTitle;
1726 aReturn.bEnabled = sal_True;
1728 break;
1729 case ID_BROWSER_TABLEATTR:
1730 case ID_BROWSER_ROWHEIGHT:
1731 case ID_BROWSER_COLATTRSET:
1732 case ID_BROWSER_COLWIDTH:
1733 aReturn.bEnabled = getBrowserView() && getBrowserView()->getVclControl() && isValid() && isValidCursor();
1734 // aReturn.bEnabled &= getDefinition() && !getDefinition()->GetDatabase()->IsReadOnly();
1735 break;
1737 case ID_BROWSER_COPY:
1738 OSL_ENSURE( !m_pTreeView->HasChildPathFocus(), "SbaTableQueryBrowser::GetState( ID_BROWSER_COPY ): this should have been handled above!" );
1739 if (getBrowserView() && getBrowserView()->getVclControl() && !getBrowserView()->getVclControl()->IsEditing())
1741 SbaGridControl* pControl = getBrowserView()->getVclControl();
1742 if ( pControl->GetSelectRowCount() )
1744 aReturn.bEnabled = m_aCurrentFrame.isActive();
1745 break;
1746 } // if ( getBrowserView()->getVclControl()->GetSelectRowCount() )
1747 else
1748 aReturn.bEnabled = pControl->canCopyCellText(pControl->GetCurRow(), pControl->GetCurColumnId());
1749 break;
1751 // NO break here
1752 default:
1753 return SbaXDataBrowserController::GetState(nId);
1756 catch(const Exception&)
1758 DBG_UNHANDLED_EXCEPTION();
1761 return aReturn;
1765 //------------------------------------------------------------------------------
1766 void SbaTableQueryBrowser::Execute(sal_uInt16 nId, const Sequence< PropertyValue >& aArgs)
1768 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::Execute" );
1769 switch (nId)
1771 default:
1772 SbaXDataBrowserController::Execute(nId,aArgs);
1773 break;
1775 case ID_TREE_EDIT_DATABASE:
1776 implAdministrate( m_pTreeView->getListBox().GetCurEntry() );
1777 break;
1779 case ID_TREE_CLOSE_CONN:
1780 openHelpAgent( HID_DSBROWSER_DISCONNECTING );
1781 closeConnection( m_pTreeView->getListBox().GetRootLevelParent( m_pTreeView->getListBox().GetCurEntry() ) );
1782 break;
1784 case ID_TREE_ADMINISTRATE:
1785 ::svx::administrateDatabaseRegistration( getView() );
1786 break;
1788 case ID_BROWSER_REFRESH:
1790 if ( !SaveModified( ) )
1791 // nothing to do
1792 break;
1794 sal_Bool bFullReinit = sal_False;
1795 // check if the query signature (if the form is based on a query) has changed
1796 if ( m_sQueryCommand.getLength() )
1798 ::rtl::OUString sNewQueryCommand;
1799 sal_Bool bNewQueryEP;
1801 #if OSL_DEBUG_LEVEL > 0
1802 sal_Bool bIsQuery =
1803 #endif
1804 implGetQuerySignature( sNewQueryCommand, bNewQueryEP );
1805 OSL_ENSURE( bIsQuery, "SbaTableQueryBrowser::Execute: was a query before, but is not anymore?" );
1807 bFullReinit = ( sNewQueryCommand != m_sQueryCommand ) || ( m_bQueryEscapeProcessing != bNewQueryEP );
1809 if ( !bFullReinit )
1811 // let the base class do a simple reload
1812 SbaXDataBrowserController::Execute(nId,aArgs);
1813 break;
1815 // NO break here!
1818 case ID_BROWSER_REFRESH_REBUILD:
1820 if ( !SaveModified() )
1821 // nothing to do
1822 break;
1824 SvLBoxEntry* pSelected = m_pCurrentlyDisplayed;
1825 // unload
1826 unloadAndCleanup( sal_False );
1828 // reselect the entry
1829 if ( pSelected )
1831 implSelect( pSelected );
1833 else
1835 Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
1836 implSelect(::svx::ODataAccessDescriptor(xProp));
1839 break;
1841 case ID_BROWSER_EXPLORER:
1842 toggleExplorer();
1843 break;
1845 case ID_BROWSER_DOCUMENT_DATASOURCE:
1846 implSelect(m_aDocumentDataSource);
1847 break;
1849 case ID_BROWSER_INSERTCOLUMNS:
1850 case ID_BROWSER_INSERTCONTENT:
1851 case ID_BROWSER_FORMLETTER:
1852 if (getBrowserView() && isValidCursor())
1854 // the URL the slot id is assigned to
1855 OSL_ENSURE( m_aExternalFeatures.find( nId ) != m_aExternalFeatures.end(),
1856 "SbaTableQueryBrowser::Execute( ID_BROWSER_?): how could this ever be enabled?" );
1857 URL aParentUrl = m_aExternalFeatures[ nId ].aURL;
1859 // let the dispatcher execute the slot
1860 Reference< XDispatch > xDispatch( m_aExternalFeatures[ nId ].xDispatcher );
1861 if (xDispatch.is())
1863 // set the properties for the dispatch
1865 // first fill the selection
1866 SbaGridControl* pGrid = getBrowserView()->getVclControl();
1867 MultiSelection* pSelection = (MultiSelection*)pGrid->GetSelection();
1868 Sequence< Any > aSelection;
1869 if ( !pGrid->IsAllSelected() )
1870 { // transfer the selected rows only if not all rows are selected
1871 // (all rows means the whole table)
1872 // i3832 - 03.04.2002 - fs@openoffice.org
1873 if (pSelection != NULL)
1875 aSelection.realloc(pSelection->GetSelectCount());
1876 long nIdx = pSelection->FirstSelected();
1877 Any* pSelectionNos = aSelection.getArray();
1878 while (nIdx >= 0)
1880 *pSelectionNos++ <<= (sal_Int32)(nIdx + 1);
1881 nIdx = pSelection->NextSelected();
1886 Reference< XResultSet > xCursorClone;
1889 Reference< XResultSetAccess > xResultSetAccess(getRowSet(),UNO_QUERY);
1890 if (xResultSetAccess.is())
1891 xCursorClone = xResultSetAccess->createResultSet();
1893 catch(DisposedException&)
1895 OSL_ENSURE(0,"Object already disposed!");
1897 catch(Exception&)
1899 DBG_ERROR("SbaTableQueryBrowser::Execute(ID_BROWSER_?): could not clone the cursor!");
1902 Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
1906 ODataAccessDescriptor aDescriptor;
1907 ::rtl::OUString sDataSourceName;
1908 xProp->getPropertyValue(PROPERTY_DATASOURCENAME) >>= sDataSourceName;
1910 aDescriptor.setDataSource(sDataSourceName);
1911 aDescriptor[daCommand] = xProp->getPropertyValue(PROPERTY_COMMAND);
1912 aDescriptor[daCommandType] = xProp->getPropertyValue(PROPERTY_COMMAND_TYPE);
1913 aDescriptor[daConnection] = xProp->getPropertyValue(PROPERTY_ACTIVE_CONNECTION);
1914 aDescriptor[daCursor] <<= xCursorClone;
1915 if ( aSelection.getLength() )
1917 aDescriptor[daSelection] <<= aSelection;
1918 aDescriptor[daBookmarkSelection] <<= sal_False;
1919 // these are selection indicies
1920 // before we change this, all clients have to be adjusted
1921 // so that they recognize the new BookmarkSelection property!
1924 xDispatch->dispatch(aParentUrl, aDescriptor.createPropertyValueSequence());
1926 catch( const Exception& )
1928 DBG_UNHANDLED_EXCEPTION();
1932 break;
1934 case ID_BROWSER_CLOSE:
1935 closeTask();
1936 // if it's not 0, such a async close is already pending
1937 break;
1939 case ID_BROWSER_COPY:
1940 if(m_pTreeView->HasChildPathFocus())
1942 copyEntry(m_pTreeView->getListBox().GetCurEntry());
1944 else if (getBrowserView() && getBrowserView()->getVclControl() && !getBrowserView()->getVclControl()->IsEditing() && getBrowserView()->getVclControl()->GetSelectRowCount() < 1)
1946 SbaGridControl* pControl = getBrowserView()->getVclControl();
1947 pControl->copyCellText(pControl->GetCurRow(), pControl->GetCurColumnId());
1949 else
1950 SbaXDataBrowserController::Execute(nId,aArgs);
1951 break;
1954 // -------------------------------------------------------------------------
1955 void SbaTableQueryBrowser::implAddDatasource(const String& _rDbName, Image& _rDbImage,
1956 String& _rQueryName, Image& _rQueryImage, String& _rTableName, Image& _rTableImage,
1957 const SharedConnection& _rxConnection)
1959 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::implAddDatasource" );
1960 vos::OGuard aGuard( Application::GetSolarMutex() );
1961 // initialize the names/images if necessary
1962 if (!_rQueryName.Len())
1963 _rQueryName = String(ModuleRes(RID_STR_QUERIES_CONTAINER));
1964 if (!_rTableName.Len())
1965 _rTableName = String(ModuleRes(RID_STR_TABLES_CONTAINER));
1967 ImageProvider aImageProvider;
1968 if (!_rQueryImage)
1969 _rQueryImage = aImageProvider.getFolderImage( DatabaseObject::QUERY, isHiContrast() );
1970 if (!_rTableImage)
1971 _rTableImage = aImageProvider.getFolderImage( DatabaseObject::TABLE, isHiContrast() );
1973 if (!_rDbImage)
1974 _rDbImage = aImageProvider.getDatabaseImage( isHiContrast() );
1976 // add the entry for the data source
1977 // special handling for data sources denoted by URLs - we do not want to display this ugly URL, do we?
1978 // #i33699# - 2004-09-24 - fs@openoffice.org
1979 String sDSDisplayName, sDataSourceId;
1980 getDataSourceDisplayName_isURL( _rDbName, sDSDisplayName, sDataSourceId );
1982 SvLBoxEntry* pDatasourceEntry = m_pTreeView->getListBox().InsertEntry( sDSDisplayName, _rDbImage, _rDbImage, NULL, sal_False );
1983 DBTreeListUserData* pDSData = new DBTreeListUserData;
1984 pDSData->eType = etDatasource;
1985 pDSData->sAccessor = sDataSourceId;
1986 pDSData->xConnection = _rxConnection;
1987 pDatasourceEntry->SetUserData(pDSData);
1989 // the child for the queries container
1991 DBTreeListUserData* pQueriesData = new DBTreeListUserData;
1992 pQueriesData->eType = etQueryContainer;
1994 m_pTreeView->getListBox().InsertEntry(
1995 _rQueryName, _rQueryImage, _rQueryImage, pDatasourceEntry,
1996 TRUE /*ChildsOnDemand*/, LIST_APPEND, pQueriesData );
1999 // the child for the tables container
2001 DBTreeListUserData* pTablesData = new DBTreeListUserData;
2002 pTablesData->eType = etTableContainer;
2004 m_pTreeView->getListBox().InsertEntry(
2005 _rTableName, _rTableImage, _rTableImage, pDatasourceEntry,
2006 TRUE /*ChildsOnDemand*/, LIST_APPEND, pTablesData );
2010 // -------------------------------------------------------------------------
2011 void SbaTableQueryBrowser::initializeTreeModel()
2013 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::initializeTreeModel" );
2014 if (m_xDatabaseContext.is())
2016 Image aDBImage, aQueriesImage, aTablesImage;
2017 String sQueriesName, sTablesName;
2019 // fill the model with the names of the registered datasources
2020 Sequence< ::rtl::OUString > aDatasources = m_xDatabaseContext->getElementNames();
2021 const ::rtl::OUString* pIter = aDatasources.getConstArray();
2022 const ::rtl::OUString* pEnd = pIter + aDatasources.getLength();
2023 for (; pIter != pEnd; ++pIter)
2024 implAddDatasource( *pIter, aDBImage, sQueriesName, aQueriesImage, sTablesName, aTablesImage, SharedConnection() );
2027 // -------------------------------------------------------------------------
2028 sal_Bool SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAccess,
2029 SvLBoxEntry* _pParent,
2030 EntryType _eEntryType)
2032 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::populateTree" );
2033 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pParent->GetUserData());
2034 if(pData) // don't ask if the nameaccess is already set see OnExpandEntry views and tables
2035 pData->xContainer = _xNameAccess;
2039 Sequence< ::rtl::OUString > aNames = _xNameAccess->getElementNames();
2040 const ::rtl::OUString* pIter = aNames.getConstArray();
2041 const ::rtl::OUString* pEnd = pIter + aNames.getLength();
2042 for (; pIter != pEnd; ++pIter)
2044 if(!m_pTreeView->getListBox().GetEntryPosByName(*pIter,_pParent))
2046 DBTreeListUserData* pEntryData = new DBTreeListUserData;
2047 pEntryData->eType = _eEntryType;
2048 implAppendEntry( _pParent, *pIter, pEntryData, _eEntryType );
2052 catch(Exception&)
2054 DBG_ERROR("SbaTableQueryBrowser::populateTree: could not fill the tree");
2055 return sal_False;
2057 return sal_True;
2060 //------------------------------------------------------------------------------
2061 void SbaTableQueryBrowser::implAppendEntry( SvLBoxEntry* _pParent, const String& _rName, void* _pUserData, EntryType _eEntryType )
2063 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::implAppendEntry" );
2064 ::std::auto_ptr< ImageProvider > pImageProvider( getImageProviderFor( _pParent ) );
2066 Image aImage, aImageHC;
2067 pImageProvider->getImages( _rName, getDatabaseObjectType( _eEntryType ), aImage, aImageHC );
2069 SvLBoxEntry* pNewEntry = m_pTreeView->getListBox().InsertEntry( _rName, _pParent, sal_False, LIST_APPEND, _pUserData );
2071 m_pTreeView->getListBox().SetExpandedEntryBmp( pNewEntry, aImage, BMP_COLOR_NORMAL );
2072 m_pTreeView->getListBox().SetCollapsedEntryBmp( pNewEntry, aImage, BMP_COLOR_NORMAL );
2073 m_pTreeView->getListBox().SetExpandedEntryBmp( pNewEntry, aImageHC, BMP_COLOR_HIGHCONTRAST );
2074 m_pTreeView->getListBox().SetCollapsedEntryBmp( pNewEntry, aImageHC, BMP_COLOR_HIGHCONTRAST );
2077 //------------------------------------------------------------------------------
2078 IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, SvLBoxEntry*, _pParent)
2080 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::OnExpandEntry" );
2081 if (_pParent->HasChilds())
2082 // nothing to to ...
2083 return 1L;
2085 SvLBoxEntry* pFirstParent = m_pTreeView->getListBox().GetRootLevelParent(_pParent);
2086 OSL_ENSURE(pFirstParent,"SbaTableQueryBrowser::OnExpandEntry: No rootlevelparent!");
2088 DBTreeListUserData* pData = static_cast< DBTreeListUserData* >(_pParent->GetUserData());
2089 OSL_ENSURE(pData,"SbaTableQueryBrowser::OnExpandEntry: No user data!");
2090 #if OSL_DEBUG_LEVEL > 0
2091 SvLBoxString* pString = static_cast<SvLBoxString*>(pFirstParent->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING));
2092 OSL_ENSURE(pString,"SbaTableQueryBrowser::OnExpandEntry: No string item!");
2093 #endif
2095 if (etTableContainer == pData->eType)
2097 WaitObject aWaitCursor(getBrowserView());
2099 // it could be that we already have a connection
2100 SharedConnection xConnection;
2101 ensureConnection( pFirstParent, xConnection );
2103 if ( xConnection.is() )
2105 SQLExceptionInfo aInfo;
2108 Reference< XWarningsSupplier > xWarnings(xConnection, UNO_QUERY);
2109 if (xWarnings.is())
2110 xWarnings->clearWarnings();
2112 // first insert the views because the tables can also include
2113 // views but that time the bitmap is the wrong one
2114 // the nameaccess will be overwriten in populateTree
2115 Reference<XViewsSupplier> xViewSup(xConnection,UNO_QUERY);
2116 if(xViewSup.is())
2117 populateTree( xViewSup->getViews(), _pParent, etTableOrView );
2119 Reference<XTablesSupplier> xTabSup(xConnection,UNO_QUERY);
2120 if(xTabSup.is())
2122 populateTree( xTabSup->getTables(), _pParent, etTableOrView );
2123 Reference<XContainer> xCont(xTabSup->getTables(),UNO_QUERY);
2124 if(xCont.is())
2125 // add as listener to know when elements are inserted or removed
2126 xCont->addContainerListener(this);
2129 if (xWarnings.is())
2131 SQLExceptionInfo aWarnings(xWarnings->getWarnings());
2132 if (aWarnings.isValid() && sal_False)
2134 SQLContext aContext;
2135 aContext.Message = String(ModuleRes(STR_OPENTABLES_WARNINGS));
2136 aContext.Details = String(ModuleRes(STR_OPENTABLES_WARNINGS_DETAILS));
2137 aContext.NextException = aWarnings.get();
2138 aWarnings = aContext;
2139 showError(aWarnings);
2141 // TODO: we need a better concept for these warnings:
2142 // something like "don't show any warnings for this datasource, again" would be nice
2143 // But this requires an extension of the InteractionHandler and an additional property on the data source
2146 catch(const SQLContext& e) { aInfo = e; }
2147 catch(const SQLWarning& e) { aInfo = e; }
2148 catch(const SQLException& e) { aInfo = e; }
2149 catch(const WrappedTargetException& e)
2151 SQLException aSql;
2152 if(e.TargetException >>= aSql)
2153 aInfo = aSql;
2154 else
2155 OSL_ENSURE(sal_False, "SbaTableQueryBrowser::OnExpandEntry: something strange happended!");
2157 catch( const Exception& )
2159 DBG_UNHANDLED_EXCEPTION();
2161 if (aInfo.isValid())
2162 showError(aInfo);
2164 else
2165 return 0L;
2166 // 0 indicates that an error occured
2168 else
2169 { // we have to expand the queries or bookmarks
2170 if (ensureEntryObject(_pParent))
2172 DBTreeListUserData* pParentData = static_cast< DBTreeListUserData* >( _pParent->GetUserData() );
2173 Reference< XNameAccess > xCollection( pParentData->xContainer, UNO_QUERY );
2174 populateTree( xCollection, _pParent, etQuery );
2177 return 1L;
2180 //------------------------------------------------------------------------------
2181 sal_Bool SbaTableQueryBrowser::ensureEntryObject( SvLBoxEntry* _pEntry )
2183 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::ensureEntryObject" );
2184 DBG_ASSERT(_pEntry, "SbaTableQueryBrowser::ensureEntryObject: invalid argument!");
2185 if (!_pEntry)
2186 return sal_False;
2188 EntryType eType = getEntryType( _pEntry );
2190 // the user data of the entry
2191 DBTreeListUserData* pEntryData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData());
2192 OSL_ENSURE(pEntryData,"ensureEntryObject: user data should already be set!");
2194 SvLBoxEntry* pDataSourceEntry = m_pTreeView->getListBox().GetRootLevelParent(_pEntry);
2196 sal_Bool bSuccess = sal_False;
2197 switch (eType)
2199 case etQueryContainer:
2200 if ( pEntryData->xContainer.is() )
2202 // nothing to do
2203 bSuccess = sal_True;
2204 break;
2209 Reference< XQueryDefinitionsSupplier > xQuerySup;
2210 m_xDatabaseContext->getByName( getDataSourceAcessor( pDataSourceEntry ) ) >>= xQuerySup;
2211 if (xQuerySup.is())
2213 Reference< XNameAccess > xQueryDefs = xQuerySup->getQueryDefinitions();
2214 Reference< XContainer > xCont(xQueryDefs, UNO_QUERY);
2215 if (xCont.is())
2216 // add as listener to get notified if elements are inserted or removed
2217 xCont->addContainerListener(this);
2219 pEntryData->xContainer = xQueryDefs;
2220 bSuccess = pEntryData->xContainer.is();
2222 else {
2223 DBG_ERROR("SbaTableQueryBrowser::ensureEntryObject: no XQueryDefinitionsSupplier interface!");
2226 catch( const Exception& )
2228 DBG_UNHANDLED_EXCEPTION();
2230 break;
2232 default:
2233 DBG_ERROR("SbaTableQueryBrowser::ensureEntryObject: ooops ... missing some implementation here!");
2234 // TODO ...
2235 break;
2238 return bSuccess;
2240 //------------------------------------------------------------------------------
2241 sal_Bool SbaTableQueryBrowser::implSelect(const ::svx::ODataAccessDescriptor& _rDescriptor,sal_Bool _bSelectDirect)
2243 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::implSelect(_rDescriptor,_bSelectDirect)" );
2244 // extract the props
2245 ::rtl::OUString sDataSource;
2246 ::rtl::OUString sCommand;
2247 sal_Int32 nCommandType = CommandType::COMMAND;
2248 sal_Bool bEscapeProcessing = sal_True;
2249 extractDescriptorProps(_rDescriptor, sDataSource, sCommand, nCommandType, bEscapeProcessing);
2251 // select it
2252 return implSelect( sDataSource, sCommand, nCommandType, bEscapeProcessing, SharedConnection(), _bSelectDirect );
2255 //------------------------------------------------------------------------------
2256 sal_Bool SbaTableQueryBrowser::implLoadAnything(const ::rtl::OUString& _rDataSourceName, const ::rtl::OUString& _rCommand,
2257 const sal_Int32 _nCommandType, const sal_Bool _bEscapeProcessing, const SharedConnection& _rxConnection)
2259 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::implLoadAnything" );
2260 Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
2261 if(xProp.is())
2263 Reference< ::com::sun::star::form::XLoadable > xLoadable(xProp,UNO_QUERY);
2266 // the values allowing the RowSet to re-execute
2267 xProp->setPropertyValue(PROPERTY_DATASOURCENAME, makeAny(_rDataSourceName));
2268 if(_rxConnection.is())
2269 xProp->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( _rxConnection.getTyped() ) );
2271 // set this _before_ setting the connection, else the rowset would rebuild it ...
2272 xProp->setPropertyValue(PROPERTY_COMMAND_TYPE, makeAny(_nCommandType));
2273 xProp->setPropertyValue(PROPERTY_COMMAND, makeAny(_rCommand));
2274 xProp->setPropertyValue(PROPERTY_ESCAPE_PROCESSING, ::cppu::bool2any(_bEscapeProcessing));
2275 if ( m_bPreview )
2277 // this be undone by the grid control in DbGridControl::RecalcRows
2278 // xProp->setPropertyValue(PROPERTY_FETCHSIZE, makeAny(sal_Int32(20)));
2279 xProp->setPropertyValue(PROPERTY_FETCHDIRECTION, makeAny(FetchDirection::FORWARD));
2282 // the formatter depends on the data source we're working on, so rebuild it here ...
2283 initFormatter();
2285 // switch the grid to design mode while loading
2286 getBrowserView()->getGridControl()->setDesignMode(sal_True);
2287 InitializeForm(getRowSet());
2289 sal_Bool bSuccess = sal_True;
2293 Reference< XNameContainer > xColContainer(getFormComponent(), UNO_QUERY);
2294 // first we have to clear the grid
2295 clearGridColumns(xColContainer);
2297 FormErrorHelper aHelper(this);
2298 // load the form
2299 bSuccess = reloadForm(xLoadable);
2301 // initialize the model
2302 InitializeGridModel(getFormComponent());
2304 if ( m_bPreview )
2305 initializePreviewMode();
2307 LoadFinished(sal_True);
2310 InvalidateAll();
2311 return bSuccess;
2313 catch(SQLException& e)
2315 showError(SQLExceptionInfo(e));
2317 catch(WrappedTargetException& e)
2319 SQLException aSql;
2320 if(e.TargetException >>= aSql)
2321 showError(SQLExceptionInfo(aSql));
2322 else
2323 OSL_ENSURE(sal_False, "SbaTableQueryBrowser::implLoadAnything: something strange happended!");
2325 catch(Exception&)
2327 OSL_ENSURE(sal_False, "SbaTableQueryBrowser::implLoadAnything: something strange happended!");
2331 InvalidateAll();
2332 return sal_False;
2335 //------------------------------------------------------------------------------
2336 sal_Bool SbaTableQueryBrowser::implSelect(const ::rtl::OUString& _rDataSourceName, const ::rtl::OUString& _rCommand,
2337 const sal_Int32 _nCommandType, const sal_Bool _bEscapeProcessing,
2338 const SharedConnection& _rxConnection
2339 ,sal_Bool _bSelectDirect)
2341 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::implSelect(_rDataSourceName,_rCommand,...)" );
2342 if (_rDataSourceName.getLength() && _rCommand.getLength() && (-1 != _nCommandType))
2344 SvLBoxEntry* pDataSource = NULL;
2345 SvLBoxEntry* pCommandType = NULL;
2346 SvLBoxEntry* pCommand = getObjectEntry( _rDataSourceName, _rCommand, _nCommandType, &pDataSource, &pCommandType, sal_True, _rxConnection );
2348 if (pCommand)
2350 bool bSuccess = true;
2351 if ( _bSelectDirect )
2353 bSuccess = implSelect( pCommand );
2355 else
2357 m_pTreeView->getListBox().Select( pCommand );
2360 if ( bSuccess )
2362 m_pTreeView->getListBox().MakeVisible(pCommand);
2363 m_pTreeView->getListBox().SetCursor(pCommand);
2366 else if (!pCommandType)
2368 if ( m_pCurrentlyDisplayed )
2369 { // tell the old entry (if any) it has been deselected
2370 selectPath(m_pCurrentlyDisplayed, sal_False);
2371 m_pCurrentlyDisplayed = NULL;
2374 // we have a command and need to display this in the rowset
2375 return implLoadAnything(_rDataSourceName, _rCommand, _nCommandType, _bEscapeProcessing, _rxConnection);
2378 return sal_False;
2381 //------------------------------------------------------------------------------
2382 IMPL_LINK(SbaTableQueryBrowser, OnSelectionChange, void*, /*NOINTERESTEDIN*/)
2384 return implSelect( m_pTreeView->getListBox().FirstSelected() ) ? 1L : 0L;
2387 //------------------------------------------------------------------------------
2388 bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry )
2390 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::implSelect(_pEntry)" );
2391 if ( !_pEntry )
2392 return false;
2394 DBTreeListUserData* pEntryData = static_cast< DBTreeListUserData* >( _pEntry->GetUserData() );
2395 switch (pEntryData->eType)
2397 case etTableOrView:
2398 case etQuery:
2399 break;
2400 default:
2401 // nothing to do
2402 return false;
2405 OSL_ENSURE(m_pTreeModel->HasParent(_pEntry), "SbaTableQueryBrowser::implSelect: invalid entry (1)!");
2406 OSL_ENSURE(m_pTreeModel->HasParent(m_pTreeModel->GetParent(_pEntry)), "SbaTableQueryBrowser::implSelect: invalid entry (2)!");
2408 // get the entry for the tables or queries
2409 SvLBoxEntry* pContainer = m_pTreeModel->GetParent(_pEntry);
2410 DBTreeListUserData* pContainerData = static_cast<DBTreeListUserData*>(pContainer->GetUserData());
2412 // get the entry for the datasource
2413 SvLBoxEntry* pConnection = m_pTreeModel->GetParent(pContainer);
2414 DBTreeListUserData* pConData = static_cast<DBTreeListUserData*>(pConnection->GetUserData());
2416 // reinitialize the rowset
2417 // but first check if it is necessary
2418 // get all old properties
2419 Reference<XPropertySet> xRowSetProps(getRowSet(),UNO_QUERY);
2420 ::rtl::OUString aOldName;
2421 xRowSetProps->getPropertyValue(PROPERTY_COMMAND) >>= aOldName;
2422 sal_Int32 nOldType = 0;
2423 xRowSetProps->getPropertyValue(PROPERTY_COMMAND_TYPE) >>= nOldType;
2424 Reference<XConnection> xOldConnection;
2425 ::cppu::extractInterface(xOldConnection,xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION));
2426 // the name of the table or query
2427 SvLBoxString* pString = (SvLBoxString*)_pEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
2428 OSL_ENSURE(pString,"There must be a string item!");
2429 ::rtl::OUString aName(pString->GetText().GetBuffer());
2431 sal_Int32 nCommandType = ( etTableContainer == pContainerData->eType)
2432 ? CommandType::TABLE
2433 : CommandType::QUERY;
2435 // check if need to rebuild the rowset
2436 sal_Bool bRebuild = ( xOldConnection != pConData->xConnection )
2437 || ( nOldType != nCommandType )
2438 || ( aName != aOldName );
2440 Reference< ::com::sun::star::form::XLoadable > xLoadable = getLoadable();
2441 bRebuild |= !xLoadable->isLoaded();
2442 bool bSuccess = true;
2443 if ( bRebuild )
2447 WaitObject aWaitCursor(getBrowserView());
2449 // tell the old entry it has been deselected
2450 selectPath(m_pCurrentlyDisplayed, sal_False);
2451 m_pCurrentlyDisplayed = NULL;
2453 // not really loaded
2454 m_pCurrentlyDisplayed = _pEntry;
2455 // tell the new entry it has been selected
2456 selectPath(m_pCurrentlyDisplayed, sal_True);
2458 // get the name of the data source currently selected
2459 ensureConnection( m_pCurrentlyDisplayed, pConData->xConnection );
2461 if ( !pConData->xConnection.is() )
2463 unloadAndCleanup( sal_False );
2464 return false;
2467 Reference<XNameAccess> xNameAccess;
2468 switch(nCommandType)
2470 case CommandType::TABLE:
2472 // only for tables
2473 if ( !pContainerData->xContainer.is() )
2475 Reference<XTablesSupplier> xSup( pConData->xConnection, UNO_QUERY );
2476 if(xSup.is())
2477 xNameAccess = xSup->getTables();
2479 pContainerData->xContainer = xNameAccess;
2481 else
2482 xNameAccess.set( pContainerData->xContainer, UNO_QUERY );
2484 break;
2485 case CommandType::QUERY:
2487 Reference<XQueriesSupplier> xSup( pConData->xConnection, UNO_QUERY );
2488 if(xSup.is())
2489 xNameAccess = xSup->getQueries();
2491 break;
2493 String sStatus(ModuleRes( CommandType::TABLE == nCommandType ? STR_LOADING_TABLE : STR_LOADING_QUERY ));
2494 sStatus.SearchAndReplaceAscii("$name$", aName);
2495 BrowserViewStatusDisplay aShowStatus(static_cast<UnoDataBrowserView*>(getView()), sStatus);
2497 if(xNameAccess.is() && xNameAccess->hasByName(aName))
2499 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData());
2500 if ( !pData->xObjectProperties.is() )
2502 Reference<XInterface> xObject;
2503 if(xNameAccess->getByName(aName) >>= xObject) // remember the table or query object
2505 pData->xObjectProperties = pData->xObjectProperties.query( xObject );
2506 // if the query contains a parameterized statement and preview is enabled we won't get any data.
2507 if ( m_bPreview && nCommandType == CommandType::QUERY && xObject.is() )
2509 ::rtl::OUString sSql;
2510 Reference<XPropertySet> xObjectProps(xObject,UNO_QUERY);
2511 xObjectProps->getPropertyValue(PROPERTY_COMMAND) >>= sSql;
2512 Reference< XMultiServiceFactory > xFactory( pConData->xConnection, UNO_QUERY );
2513 if (xFactory.is())
2517 Reference<XSingleSelectQueryAnalyzer> xAnalyzer(xFactory->createInstance(SERVICE_NAME_SINGLESELECTQUERYCOMPOSER),UNO_QUERY);
2518 if ( xAnalyzer.is() )
2520 xAnalyzer->setQuery(sSql);
2521 Reference<XParametersSupplier> xParSup(xAnalyzer,UNO_QUERY);
2522 if ( xParSup->getParameters()->getCount() > 0 )
2524 String sFilter = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" WHERE "));
2525 sFilter = sFilter + xAnalyzer->getFilter();
2526 String sReplace(sSql);
2527 sReplace.SearchAndReplace(sFilter,String());
2528 xAnalyzer->setQuery(sReplace);
2529 Reference<XSingleSelectQueryComposer> xComposer(xAnalyzer,UNO_QUERY);
2530 xComposer->setFilter(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0=1")));
2531 aName = xAnalyzer->getQuery();
2532 nCommandType = CommandType::COMMAND;
2536 catch (Exception&)
2538 DBG_UNHANDLED_EXCEPTION();
2546 String sDataSourceName( getDataSourceAcessor( pConnection ) );
2547 bSuccess = implLoadAnything( sDataSourceName, aName, nCommandType, sal_True, pConData->xConnection );
2548 if ( !bSuccess )
2549 { // clean up
2550 criticalFail();
2553 catch(const SQLException& e)
2555 showError(SQLExceptionInfo(e));
2556 // reset the values
2557 xRowSetProps->setPropertyValue(PROPERTY_DATASOURCENAME,Any());
2558 xRowSetProps->setPropertyValue(PROPERTY_ACTIVE_CONNECTION,Any());
2560 catch(WrappedTargetException& e)
2562 SQLException aSql;
2563 if(e.TargetException >>= aSql)
2564 showError(SQLExceptionInfo(aSql));
2565 else
2566 OSL_ENSURE(sal_False, "SbaTableQueryBrowser::implSelect: something strange happended!");
2567 // reset the values
2568 xRowSetProps->setPropertyValue(PROPERTY_DATASOURCENAME,Any());
2569 xRowSetProps->setPropertyValue(PROPERTY_ACTIVE_CONNECTION,Any());
2571 catch(Exception&)
2573 // reset the values
2574 xRowSetProps->setPropertyValue(PROPERTY_DATASOURCENAME,Any());
2575 xRowSetProps->setPropertyValue(PROPERTY_ACTIVE_CONNECTION,Any());
2578 return bSuccess;
2581 // -----------------------------------------------------------------------------
2582 SvLBoxEntry* SbaTableQueryBrowser::getEntryFromContainer(const Reference<XNameAccess>& _rxNameAccess)
2584 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getEntryFromContainer" );
2585 DBTreeListBox& rListBox = m_pTreeView->getListBox();
2586 SvLBoxEntry* pContainer = NULL;
2587 SvLBoxEntry* pDSLoop = rListBox.FirstChild(NULL);
2588 while (pDSLoop)
2590 pContainer = rListBox.GetEntry(pDSLoop, CONTAINER_QUERIES);
2591 DBTreeListUserData* pQueriesData = static_cast<DBTreeListUserData*>(pContainer->GetUserData());
2592 if ( pQueriesData && pQueriesData->xContainer == _rxNameAccess )
2593 break;
2595 pContainer = rListBox.GetEntry(pDSLoop, CONTAINER_TABLES);
2596 DBTreeListUserData* pTablesData = static_cast<DBTreeListUserData*>(pContainer->GetUserData());
2597 if ( pTablesData && pTablesData->xContainer == _rxNameAccess )
2598 break;
2600 pDSLoop = rListBox.NextSibling(pDSLoop);
2601 pContainer = NULL;
2603 return pContainer;
2606 // -------------------------------------------------------------------------
2607 void SAL_CALL SbaTableQueryBrowser::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
2609 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::elementInserted" );
2610 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
2612 Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
2613 // first search for a definition container where we can insert this element
2615 SvLBoxEntry* pEntry = getEntryFromContainer(xNames);
2616 if(pEntry) // found one
2618 // insert the new entry into the tree
2619 DBTreeListUserData* pContainerData = static_cast<DBTreeListUserData*>(pEntry->GetUserData());
2620 OSL_ENSURE(pContainerData, "elementInserted: There must be user data for this type!");
2622 DBTreeListUserData* pNewData = new DBTreeListUserData;
2623 sal_Bool bIsTable = etTableContainer == pContainerData->eType;
2624 if ( bIsTable )
2626 _rEvent.Element >>= pNewData->xObjectProperties;// remember the new element
2627 pNewData->eType = etTableOrView;
2629 else
2631 if ((sal_Int32)m_pTreeView->getListBox().GetChildCount(pEntry) < ( xNames->getElementNames().getLength() - 1 ) )
2633 // the item inserts its children on demand, but it has not been expanded yet. So ensure here and
2634 // now that it has all items
2635 populateTree(xNames, pEntry, etQuery );
2637 pNewData->eType = etQuery;
2639 implAppendEntry( pEntry, ::comphelper::getString( _rEvent.Accessor ), pNewData, pNewData->eType );
2641 else if (xNames.get() == m_xDatabaseContext.get())
2642 { // a new datasource has been added to the context
2643 // the name of the new ds
2644 ::rtl::OUString sNewDS;
2645 _rEvent.Accessor >>= sNewDS;
2647 // add new entries to the list box model
2648 Image a, b, c; // not interested in reusing them
2649 String e, f;
2650 implAddDatasource( sNewDS, a, e, b, f, c, SharedConnection() );
2652 else
2653 SbaXDataBrowserController::elementInserted(_rEvent);
2655 // -------------------------------------------------------------------------
2656 sal_Bool SbaTableQueryBrowser::isCurrentlyDisplayedChanged(const String& _sName,SvLBoxEntry* _pContainer)
2658 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::isCurrentlyDisplayedChanged" );
2659 return m_pCurrentlyDisplayed
2660 && getEntryType(m_pCurrentlyDisplayed) == getChildType(_pContainer)
2661 && m_pTreeView->getListBox().GetParent(m_pCurrentlyDisplayed) == _pContainer
2662 && m_pTreeView->getListBox().GetEntryText(m_pCurrentlyDisplayed) == _sName;
2664 // -------------------------------------------------------------------------
2665 void SAL_CALL SbaTableQueryBrowser::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
2667 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::elementRemoved" );
2668 ::vos::OGuard aSolarGuard(Application::GetSolarMutex());
2670 Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
2671 // get the top-level representing the removed data source
2672 // and search for the queries and tables
2673 SvLBoxEntry* pContainer = getEntryFromContainer(xNames);
2674 if ( pContainer )
2675 { // a query or table has been removed
2676 String aName = ::comphelper::getString(_rEvent.Accessor).getStr();
2678 if ( isCurrentlyDisplayedChanged( aName, pContainer) )
2679 { // the element displayed currently has been replaced
2681 // we need to remember the old value
2682 SvLBoxEntry* pTemp = m_pCurrentlyDisplayed;
2684 // unload
2685 unloadAndCleanup( sal_False ); // don't dispose the connection
2687 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pTemp->GetUserData());
2688 pTemp->SetUserData(NULL);
2689 delete pData;
2690 // the data could be null because we have a table which isn't correct
2691 m_pTreeModel->Remove(pTemp);
2693 else
2695 // remove the entry from the model
2696 SvLBoxEntry* pChild = m_pTreeModel->FirstChild(pContainer);
2697 while(pChild)
2699 if (m_pTreeView->getListBox().GetEntryText(pChild) == aName)
2701 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pChild->GetUserData());
2702 pChild->SetUserData(NULL);
2703 delete pData;
2704 m_pTreeModel->Remove(pChild);
2705 break;
2707 pChild = m_pTreeModel->NextSibling(pChild);
2711 // maybe the object which is part of the document data source has been removed
2712 checkDocumentDataSource();
2714 else if (xNames.get() == m_xDatabaseContext.get())
2715 { // a datasource has been removed from the context
2717 // the name
2718 ::rtl::OUString sNewDS;
2719 _rEvent.Accessor >>= sNewDS;
2720 String sNewDatasource = sNewDS;
2722 // get the top-level representing the removed data source
2723 SvLBoxEntry* pDSLoop = m_pTreeView->getListBox().FirstChild(NULL);
2724 while (pDSLoop)
2726 if (m_pTreeView->getListBox().GetEntryText(pDSLoop) == sNewDatasource)
2727 break;
2729 pDSLoop = m_pTreeView->getListBox().NextSibling(pDSLoop);
2732 if (pDSLoop)
2734 if (isSelected(pDSLoop))
2735 { // a table or query belonging to the deleted data source is currently beeing displayed.
2736 OSL_ENSURE(m_pTreeView->getListBox().GetRootLevelParent(m_pCurrentlyDisplayed) == pDSLoop, "SbaTableQueryBrowser::elementRemoved: inconsistence (1)!");
2737 unloadAndCleanup( sal_True );
2739 else
2740 OSL_ENSURE(
2741 (NULL == m_pCurrentlyDisplayed)
2742 || (m_pTreeView->getListBox().GetRootLevelParent(m_pCurrentlyDisplayed) != pDSLoop), "SbaTableQueryBrowser::elementRemoved: inconsistence (2)!");
2744 // look for user data to delete
2745 SvTreeEntryList* pList = m_pTreeModel->GetChildList(pDSLoop);
2746 if(pList)
2748 SvLBoxEntry* pEntryLoop = static_cast<SvLBoxEntry*>(pList->First());
2749 while (pEntryLoop)
2751 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pEntryLoop->GetUserData());
2752 pEntryLoop->SetUserData(NULL);
2753 delete pData;
2754 pEntryLoop = static_cast<SvLBoxEntry*>(pList->Next());
2757 // remove the entry. This should remove all children, too.
2758 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pDSLoop->GetUserData());
2759 pDSLoop->SetUserData(NULL);
2760 delete pData;
2761 m_pTreeModel->Remove(pDSLoop);
2763 else {
2764 DBG_ERROR("SbaTableQueryBrowser::elementRemoved: unknown datasource name!");
2767 // maybe the object which is part of the document data source has been removed
2768 checkDocumentDataSource();
2770 else
2771 SbaXDataBrowserController::elementRemoved(_rEvent);
2774 // -------------------------------------------------------------------------
2775 void SAL_CALL SbaTableQueryBrowser::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
2777 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::elementReplaced" );
2778 ::vos::OGuard aSolarGuard(Application::GetSolarMutex());
2780 Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
2781 SvLBoxEntry* pContainer = getEntryFromContainer(xNames);
2782 if ( pContainer )
2783 { // a table or query as been replaced
2784 String aName = ::comphelper::getString(_rEvent.Accessor).getStr();
2786 if ( isCurrentlyDisplayedChanged( aName, pContainer) )
2787 { // the element displayed currently has been replaced
2789 // we need to remember the old value
2790 SvLBoxEntry* pTemp = m_pCurrentlyDisplayed;
2791 unloadAndCleanup( sal_False ); // don't dispose the connection
2793 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pTemp->GetUserData());
2794 if (pData)
2796 if ( etTableOrView == pData->eType )
2797 { // only insert userdata when we have a table because the query is only a commanddefinition object and not a query
2798 _rEvent.Element >>= pData->xObjectProperties; // remember the new element
2800 else
2802 pTemp->SetUserData(NULL);
2803 delete pData;
2807 else
2809 // find the entry for this name
2810 SvLBoxEntry* pChild = m_pTreeModel->FirstChild(pContainer);
2811 while(pChild)
2813 if (m_pTreeView->getListBox().GetEntryText(pChild) == aName)
2815 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pChild->GetUserData());
2816 if (pData)
2818 if ( etTableOrView == pData->eType )
2819 { // only insert userdata when we have a table because the query is only a commanddefinition object and not a query
2820 _rEvent.Element >>= pData->xObjectProperties; // remember the new element
2822 else
2824 pChild->SetUserData(NULL);
2825 delete pData;
2828 break;
2830 pChild = m_pTreeModel->NextSibling(pChild);
2834 // maybe the object which is part of the document data source has been removed
2835 checkDocumentDataSource();
2837 else if (xNames.get() == m_xDatabaseContext.get())
2838 { // a datasource has been replaced in the context
2839 DBG_ERROR("SbaTableQueryBrowser::elementReplaced: no support for replaced data sources!");
2840 // very suspicious: the database context should not allow to replace data source, only to register
2841 // and revoke them
2843 else
2844 SbaXDataBrowserController::elementReplaced(_rEvent);
2847 // -------------------------------------------------------------------------
2848 void SbaTableQueryBrowser::impl_releaseConnection( SharedConnection& _rxConnection )
2850 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::impl_releaseConnection" );
2851 // remove as event listener
2852 Reference< XComponent > xComponent( _rxConnection, UNO_QUERY );
2853 if ( xComponent.is() )
2855 Reference< XEventListener > xListener( static_cast< ::cppu::OWeakObject* >( this ), UNO_QUERY );
2856 xComponent->removeEventListener( xListener );
2861 // temporary (hopefully!) hack for #i55274#
2862 Reference< XFlushable > xFlush( _rxConnection, UNO_QUERY );
2863 if ( xFlush.is() )
2864 xFlush->flush();
2866 catch( const Exception& )
2868 DBG_UNHANDLED_EXCEPTION();
2871 // clear
2872 _rxConnection.clear();
2873 // will implicitly dispose if we have the ownership, since xConnection is a SharedConnection
2876 // -------------------------------------------------------------------------
2877 void SbaTableQueryBrowser::disposeConnection( SvLBoxEntry* _pDSEntry )
2879 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::disposeConnection" );
2880 DBG_ASSERT( _pDSEntry, "SbaTableQueryBrowser::disposeConnection: invalid entry (NULL)!" );
2881 DBG_ASSERT( impl_isDataSourceEntry( _pDSEntry ), "SbaTableQueryBrowser::disposeConnection: invalid entry (not top-level)!" );
2883 if ( _pDSEntry )
2885 DBTreeListUserData* pTreeListData = static_cast< DBTreeListUserData* >( _pDSEntry->GetUserData() );
2886 if ( pTreeListData )
2887 impl_releaseConnection( pTreeListData->xConnection );
2891 // -------------------------------------------------------------------------
2892 void SbaTableQueryBrowser::closeConnection(SvLBoxEntry* _pDSEntry,sal_Bool _bDisposeConnection)
2894 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::closeConnection" );
2895 DBG_ASSERT(_pDSEntry, "SbaTableQueryBrowser::closeConnection: invalid entry (NULL)!");
2896 DBG_ASSERT( impl_isDataSourceEntry( _pDSEntry ), "SbaTableQueryBrowser::closeConnection: invalid entry (not top-level)!");
2898 // if one of the entries of the given DS is displayed currently, unload the form
2899 if (m_pCurrentlyDisplayed && (m_pTreeView->getListBox().GetRootLevelParent(m_pCurrentlyDisplayed) == _pDSEntry))
2900 unloadAndCleanup(_bDisposeConnection);
2902 // collapse the query/table container
2903 for (SvLBoxEntry* pContainers = m_pTreeModel->FirstChild(_pDSEntry); pContainers; pContainers= m_pTreeModel->NextSibling(pContainers))
2905 SvLBoxEntry* pElements = m_pTreeModel->FirstChild(pContainers);
2906 if ( pElements )
2907 m_pTreeView->getListBox().Collapse(pContainers);
2908 m_pTreeView->getListBox().EnableExpandHandler(pContainers);
2909 // and delete their children (they are connection-relative)
2910 for (; pElements; )
2912 SvLBoxEntry* pRemove = pElements;
2913 pElements= m_pTreeModel->NextSibling(pElements);
2914 DBTreeListUserData* pData = static_cast<DBTreeListUserData*>(pRemove->GetUserData());
2915 pRemove->SetUserData(NULL);
2916 delete pData;
2917 m_pTreeModel->Remove(pRemove);
2920 // collapse the entry itself
2921 m_pTreeView->getListBox().Collapse(_pDSEntry);
2923 // dispose/reset the connection
2924 if ( _bDisposeConnection )
2925 disposeConnection( _pDSEntry );
2928 // -------------------------------------------------------------------------
2929 void SbaTableQueryBrowser::unloadAndCleanup( sal_Bool _bDisposeConnection )
2931 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::unloadAndCleanup" );
2932 if (!m_pCurrentlyDisplayed)
2933 // nothing to do
2934 return;
2936 SvLBoxEntry* pDSEntry = m_pTreeView->getListBox().GetRootLevelParent(m_pCurrentlyDisplayed);
2938 // de-select the path for the currently displayed table/query
2939 if (m_pCurrentlyDisplayed)
2941 selectPath(m_pCurrentlyDisplayed, sal_False);
2943 m_pCurrentlyDisplayed = NULL;
2947 // get the active connection. We need to dispose it.
2948 Reference< XPropertySet > xRowSetProps(getRowSet(),UNO_QUERY);
2949 Reference< XConnection > xConn;
2950 xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION) >>= xConn;
2951 #if OSL_DEBUG_LEVEL > 1
2953 Reference< XComponent > xComp;
2954 ::cppu::extractInterface(xComp, xRowSetProps->getPropertyValue(PROPERTY_ACTIVE_CONNECTION));
2956 #endif
2958 // unload the form
2959 Reference< XLoadable > xLoadable = getLoadable();
2960 if (xLoadable->isLoaded())
2961 xLoadable->unload();
2963 // clear the grid control
2964 Reference< XNameContainer > xConta(getControlModel(),UNO_QUERY);
2965 clearGridColumns(xConta);
2967 // dispose the connection
2968 if(_bDisposeConnection)
2969 disposeConnection( pDSEntry );
2971 catch(SQLException& e)
2973 showError(SQLExceptionInfo(e));
2975 catch(WrappedTargetException& e)
2977 SQLException aSql;
2978 if(e.TargetException >>= aSql)
2979 showError(SQLExceptionInfo(aSql));
2980 else
2981 OSL_ENSURE(sal_False, "SbaTableQueryBrowser::unloadAndCleanup: something strange happended!");
2983 catch(Exception&)
2985 OSL_ENSURE(sal_False, "SbaTableQueryBrowser::unloadAndCleanup: could not reset the form");
2989 // -------------------------------------------------------------------------
2990 namespace
2992 Reference< XInterface > lcl_getDataSource( const Reference< XNameAccess >& _rxDatabaseContext,
2993 const ::rtl::OUString& _rDataSourceName, const Reference< XConnection >& _rxConnection )
2995 Reference< XDataSource > xDataSource;
2998 if ( _rDataSourceName.getLength() && _rxDatabaseContext->hasByName( _rDataSourceName ) )
2999 xDataSource.set( _rxDatabaseContext->getByName( _rDataSourceName ), UNO_QUERY_THROW );
3001 if ( !xDataSource.is() )
3003 Reference< XChild > xConnAsChild( _rxConnection, UNO_QUERY );
3004 if ( xConnAsChild.is() )
3005 xDataSource.set( xConnAsChild->getParent(), UNO_QUERY_THROW );
3008 catch( const Exception& )
3010 DBG_UNHANDLED_EXCEPTION();
3012 return xDataSource.get();
3016 // -------------------------------------------------------------------------
3017 void SbaTableQueryBrowser::impl_initialize()
3019 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::impl_initialize" );
3020 ::vos::OGuard aGuard(Application::GetSolarMutex());
3021 // doin' a lot of VCL stuff here -> lock the SolarMutex
3023 // first initialize the parent
3024 SbaXDataBrowserController::impl_initialize();
3026 Reference<XConnection> xForeignConnection;
3027 Reference< XFrame > xFrame;
3029 ::rtl::OUString aTableName, aCatalogName, aSchemaName;
3031 sal_Bool bEsacpeProcessing = sal_True;
3032 sal_Int32 nInitialDisplayCommandType = CommandType::COMMAND;
3033 ::rtl::OUString sInitialDataSourceName;
3034 ::rtl::OUString sInitialCommand;
3036 const NamedValueCollection& rArguments( getInitParams() );
3038 rArguments.get_ensureType( (::rtl::OUString)PROPERTY_DATASOURCENAME, sInitialDataSourceName );
3039 rArguments.get_ensureType( (::rtl::OUString)PROPERTY_COMMAND_TYPE, nInitialDisplayCommandType );
3040 rArguments.get_ensureType( (::rtl::OUString)PROPERTY_COMMAND, sInitialCommand );
3041 rArguments.get_ensureType( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, xForeignConnection );
3042 rArguments.get_ensureType( (::rtl::OUString)PROPERTY_UPDATE_CATALOGNAME, aCatalogName );
3043 rArguments.get_ensureType( (::rtl::OUString)PROPERTY_UPDATE_SCHEMANAME, aSchemaName );
3044 rArguments.get_ensureType( (::rtl::OUString)PROPERTY_UPDATE_TABLENAME, aTableName );
3045 rArguments.get_ensureType( (::rtl::OUString)PROPERTY_ESCAPE_PROCESSING, bEsacpeProcessing );
3046 rArguments.get_ensureType( "Frame", xFrame );
3047 rArguments.get_ensureType( (::rtl::OUString)PROPERTY_SHOWMENU, m_bShowMenu );
3049 // disable the browser if either of ShowTreeViewButton (compatibility name) or EnableBrowser
3050 // is present and set to FALSE
3051 sal_Bool bDisableBrowser = ( sal_False == rArguments.getOrDefault( "ShowTreeViewButton", sal_True ) ) // compatibility name
3052 || ( sal_False == rArguments.getOrDefault( (::rtl::OUString)PROPERTY_ENABLE_BROWSER, sal_True ) );
3053 OSL_ENSURE( !rArguments.has( "ShowTreeViewButton" ),
3054 "SbaTableQueryBrowser::impl_initialize: ShowTreeViewButton is superseded by EnableBrowser!" );
3055 m_bEnableBrowser = !bDisableBrowser;
3057 // hide the tree view it is disabled in general, or if the settings tell to hide it initially
3058 sal_Bool bHideTreeView = ( !m_bEnableBrowser )
3059 || ( sal_False == rArguments.getOrDefault( "ShowTreeView", sal_True ) ) // compatibility name
3060 || ( sal_False == rArguments.getOrDefault( (::rtl::OUString)PROPERTY_SHOW_BROWSER, sal_True ) );
3061 OSL_ENSURE( !rArguments.has( "ShowTreeView" ),
3062 "SbaTableQueryBrowser::impl_initialize: ShowTreeView is superseded by ShowBrowser!" );
3064 if ( bHideTreeView )
3065 hideExplorer();
3066 else
3067 showExplorer();
3069 if ( m_bPreview )
3073 Sequence< ::rtl::OUString> aProperties(5);
3074 Sequence< Any> aValues(5);
3076 ::rtl::OUString* pStringIter = aProperties.getArray();
3077 Any* pValueIter = aValues.getArray();
3078 *pStringIter++ = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AlwaysShowCursor"));
3079 *pValueIter++ <<= sal_False;
3080 *pStringIter++ = PROPERTY_BORDER;
3081 *pValueIter++ <<= sal_Int16(0);
3083 *pStringIter++ = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasNavigationBar"));
3084 *pValueIter++ <<= sal_False;
3085 *pStringIter++ = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasRecordMarker"));
3086 *pValueIter++ <<= sal_False;
3088 *pStringIter++ = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tabstop"));
3089 *pValueIter++ <<= sal_False;
3091 Reference< XMultiPropertySet > xFormMultiSet(getFormComponent(), UNO_QUERY);
3092 if ( xFormMultiSet.is() )
3093 xFormMultiSet->setPropertyValues(aProperties, aValues);
3095 catch(Exception)
3097 DBG_UNHANDLED_EXCEPTION();
3101 // are we loaded into a (sub)frame of an embedded document (i.e. a form belonging to a database
3102 // document)?
3103 sal_Bool bSubFrameOfEmbeddedDocument = sal_False;
3104 if ( xFrame.is() )
3106 Reference<XFramesSupplier> xSup = xFrame->getCreator();
3107 Reference<XController> xCont = xSup.is() ? xSup->getController() : Reference<XController>();
3109 bSubFrameOfEmbeddedDocument = xCont.is() && ::dbtools::isEmbeddedInDatabase( xCont->getModel(), xForeignConnection );
3112 // if we have a connection at this point, it was either passed from outside, our
3113 // determined from a outer DB document. In both cases, do not dispose it later on.
3114 SharedConnection xConnection( xForeignConnection, SharedConnection::NoTakeOwnership );
3116 // should we display all registered databases in the left hand side tree?
3117 // or only *one* special?
3118 sal_Bool bLimitedTreeEntries = sal_False;
3119 // if we're part of a frame which is a secondary frame of a database document, then only
3120 // display the database for this document, not all registered ones
3121 bLimitedTreeEntries |= bSubFrameOfEmbeddedDocument;
3122 // if the tree view is not to be displayed at all, then only display the data source
3123 // which was given as initial selection
3124 bLimitedTreeEntries |= ( m_bEnableBrowser != sal_True );
3126 if ( bLimitedTreeEntries )
3128 if ( xConnection.is() )
3130 startConnectionListening( xConnection );
3132 // if no initial name was given, try to obtain one from the data source
3133 if ( !sInitialDataSourceName.getLength() )
3135 Reference< XChild > xChild( xConnection, UNO_QUERY );
3136 Reference< XPropertySet > xDataSourceProperties;
3137 if ( xChild.is() )
3138 xDataSourceProperties = xDataSourceProperties.query( xChild->getParent() );
3139 if ( xDataSourceProperties.is() )
3143 OSL_VERIFY( xDataSourceProperties->getPropertyValue( PROPERTY_NAME ) >>= sInitialDataSourceName );
3145 catch( const Exception& )
3147 OSL_ENSURE( sal_False, "SbaTableQueryBrowser::impl_initialize: a connection parent which does not have a 'Name'!??" );
3153 Image aDBImage, aQueriesImage, aTablesImage;
3154 String sQueriesName, sTablesName;
3156 implAddDatasource( sInitialDataSourceName,
3157 aDBImage, sQueriesName, aQueriesImage, sTablesName, aTablesImage, xConnection
3159 m_pTreeView->getListBox().Expand( m_pTreeView->getListBox().First() );
3161 else
3162 initializeTreeModel();
3164 if ( m_bEnableBrowser )
3166 m_aDocScriptSupport = ::boost::optional< bool >( false );
3168 else
3170 // we are not used as "browser", but as mere view for a single table/query/command. In particular,
3171 // there is a specific database document which we belong to.
3172 Reference< XOfficeDatabaseDocument > xDocument( getDataSourceOrModel(
3173 lcl_getDataSource( m_xDatabaseContext, sInitialDataSourceName, xConnection ) ), UNO_QUERY );
3174 m_aDocScriptSupport = ::boost::optional< bool >( Reference< XEmbeddedScripts >( xDocument, UNO_QUERY ).is() );
3177 if ( implSelect( sInitialDataSourceName, sInitialCommand, nInitialDisplayCommandType, bEsacpeProcessing, xConnection, sal_True ) )
3181 Reference< XPropertySet > xRowSetProps(getRowSet(), UNO_QUERY);
3182 xRowSetProps->setPropertyValue(PROPERTY_UPDATE_CATALOGNAME,makeAny(aCatalogName));
3183 xRowSetProps->setPropertyValue(PROPERTY_UPDATE_SCHEMANAME,makeAny(aSchemaName));
3184 xRowSetProps->setPropertyValue(PROPERTY_UPDATE_TABLENAME,makeAny(aTableName));
3187 catch(const Exception&)
3189 OSL_ENSURE(sal_False, "SbaTableQueryBrowser::impl_initialize: could not set the update related names!");
3193 InvalidateAll();
3196 // -------------------------------------------------------------------------
3197 sal_Bool SbaTableQueryBrowser::haveExplorer() const
3199 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::haveExplorer" );
3200 return m_pTreeView && m_pTreeView->IsVisible();
3203 // -------------------------------------------------------------------------
3204 void SbaTableQueryBrowser::hideExplorer()
3206 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::hideExplorer" );
3207 if (!haveExplorer())
3208 return;
3209 if (!getBrowserView())
3210 return;
3212 m_pTreeView->Hide();
3213 m_pSplitter->Hide();
3214 getBrowserView()->Resize();
3216 InvalidateFeature(ID_BROWSER_EXPLORER);
3219 // -------------------------------------------------------------------------
3220 void SbaTableQueryBrowser::showExplorer()
3222 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::showExplorer" );
3223 if (haveExplorer())
3224 return;
3226 if (!getBrowserView())
3227 return;
3229 m_pTreeView->Show();
3230 m_pSplitter->Show();
3231 getBrowserView()->Resize();
3233 InvalidateFeature(ID_BROWSER_EXPLORER);
3236 // -----------------------------------------------------------------------------
3237 sal_Bool SbaTableQueryBrowser::ensureConnection(SvLBoxEntry* _pAnyEntry, SharedConnection& _rConnection)
3239 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::ensureConnection" );
3240 SvLBoxEntry* pDSEntry = m_pTreeView->getListBox().GetRootLevelParent(_pAnyEntry);
3241 DBTreeListUserData* pDSData =
3242 pDSEntry
3243 ? static_cast<DBTreeListUserData*>(pDSEntry->GetUserData())
3244 : NULL;
3246 return ensureConnection( pDSEntry, pDSData, _rConnection );
3249 // -----------------------------------------------------------------------------
3250 ::std::auto_ptr< ImageProvider > SbaTableQueryBrowser::getImageProviderFor( SvLBoxEntry* _pAnyEntry )
3252 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getImageProviderFor" );
3253 ::std::auto_ptr< ImageProvider > pImageProvider( new ImageProvider );
3254 SharedConnection xConnection;
3255 if ( getExistentConnectionFor( _pAnyEntry, xConnection ) )
3256 pImageProvider.reset( new ImageProvider( xConnection ) );
3257 return pImageProvider;
3260 // -----------------------------------------------------------------------------
3261 sal_Bool SbaTableQueryBrowser::getExistentConnectionFor( SvLBoxEntry* _pAnyEntry, SharedConnection& _rConnection )
3263 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getExistentConnectionFor" );
3264 SvLBoxEntry* pDSEntry = m_pTreeView->getListBox().GetRootLevelParent( _pAnyEntry );
3265 DBTreeListUserData* pDSData =
3266 pDSEntry
3267 ? static_cast< DBTreeListUserData* >( pDSEntry->GetUserData() )
3268 : NULL;
3269 if ( pDSData )
3270 _rConnection = pDSData->xConnection;
3271 return _rConnection.is();
3274 #ifdef DBG_UTIL
3275 // -----------------------------------------------------------------------------
3276 bool SbaTableQueryBrowser::impl_isDataSourceEntry( SvLBoxEntry* _pEntry ) const
3278 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::impl_isDataSourceEntry" );
3279 return m_pTreeModel->GetRootLevelParent( _pEntry ) == _pEntry;
3281 #endif
3283 // -----------------------------------------------------------------------------
3284 sal_Bool SbaTableQueryBrowser::ensureConnection( SvLBoxEntry* _pDSEntry, void* pDSData, SharedConnection& _rConnection )
3286 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::ensureConnection" );
3287 DBG_ASSERT( impl_isDataSourceEntry( _pDSEntry ), "SbaTableQueryBrowser::ensureConnection: this entry does not denote a data source!" );
3288 if(_pDSEntry)
3290 DBTreeListUserData* pTreeListData = static_cast<DBTreeListUserData*>(pDSData);
3291 ::rtl::OUString aDSName = GetEntryText(_pDSEntry);
3293 if ( pTreeListData )
3294 _rConnection = pTreeListData->xConnection;
3296 if ( !_rConnection.is() && pTreeListData )
3298 // show the "connecting to ..." status
3299 String sConnecting(ModuleRes(STR_CONNECTING_DATASOURCE));
3300 sConnecting.SearchAndReplaceAscii("$name$", aDSName);
3301 BrowserViewStatusDisplay aShowStatus(static_cast<UnoDataBrowserView*>(getView()), sConnecting);
3303 // build a string showing context information in case of error
3304 String sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE ) );
3305 sConnectingContext.SearchAndReplaceAscii("$name$", aDSName);
3307 // connect
3308 _rConnection.reset(
3309 connect( getDataSourceAcessor( _pDSEntry ), sConnectingContext, NULL ),
3310 SharedConnection::TakeOwnership
3313 // remember the connection
3314 pTreeListData->xConnection = _rConnection;
3318 return _rConnection.is();
3321 // -----------------------------------------------------------------------------
3322 IMPL_LINK( SbaTableQueryBrowser, OnTreeEntryCompare, const SvSortData*, _pSortData )
3324 SvLBoxEntry* pLHS = static_cast<SvLBoxEntry*>(_pSortData->pLeft);
3325 SvLBoxEntry* pRHS = static_cast<SvLBoxEntry*>(_pSortData->pRight);
3326 DBG_ASSERT(pLHS && pRHS, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid tree entries!");
3327 // we want the table entry and the end so we have to do a check
3329 if (isContainer(pRHS))
3331 // don't use getEntryType (directly or indirecly) for the LHS:
3332 // LHS is currently beeing inserted, so it is not "completely valid" at the moment
3334 const EntryType eRight = getEntryType(pRHS);
3335 if (etTableContainer == eRight)
3336 // every other container should be placed _before_ the bookmark container
3337 return -1;
3339 const String sLeft = m_pTreeView->getListBox().GetEntryText(pLHS);
3341 EntryType eLeft = etTableContainer;
3342 if (String(ModuleRes(RID_STR_TABLES_CONTAINER)) == sLeft)
3343 eLeft = etTableContainer;
3344 else if (String(ModuleRes(RID_STR_QUERIES_CONTAINER)) == sLeft)
3345 eLeft = etQueryContainer;
3347 if ( eLeft == eRight )
3348 return COMPARE_EQUAL;
3350 if ( ( eLeft == etTableContainer ) && ( eRight == etQueryContainer ) )
3351 return COMPARE_GREATER;
3353 if ( ( eLeft == etQueryContainer ) && ( eRight == etTableContainer ) )
3354 return COMPARE_LESS;
3356 OSL_ENSURE( false, "SbaTableQueryBrowser::OnTreeEntryCompare: unexpected case!" );
3357 return COMPARE_EQUAL;
3360 SvLBoxString* pLeftTextItem = static_cast<SvLBoxString*>(pLHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
3361 SvLBoxString* pRightTextItem = static_cast<SvLBoxString*>(pRHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
3362 DBG_ASSERT(pLeftTextItem && pRightTextItem, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid text items!");
3364 String sLeftText = pLeftTextItem->GetText();
3365 String sRightText = pRightTextItem->GetText();
3367 sal_Int32 nCompareResult = 0; // equal by default
3369 if (m_xCollator.is())
3373 nCompareResult = m_xCollator->compareString(sLeftText, sRightText);
3375 catch(Exception&)
3379 else
3380 // default behaviour if we do not have a collator -> do the simple string compare
3381 nCompareResult = sLeftText.CompareTo(sRightText);
3383 return nCompareResult;
3386 // -----------------------------------------------------------------------------
3387 void SbaTableQueryBrowser::implAdministrate( SvLBoxEntry* _pApplyTo )
3389 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::implAdministrate" );
3390 OSL_PRECOND( _pApplyTo, "SbaTableQueryBrowser::implAdministrate: illegal entry!" );
3391 if ( !_pApplyTo )
3392 return;
3396 // get the desktop object
3397 sal_Int32 nFrameSearchFlag = FrameSearchFlag::ALL | FrameSearchFlag::GLOBAL ;
3398 Reference< XComponentLoader > xFrameLoader(getORB()->createInstance(SERVICE_FRAME_DESKTOP),UNO_QUERY);
3400 if ( xFrameLoader.is() )
3402 // the initial selection
3403 SvLBoxEntry* pTopLevelSelected = _pApplyTo;
3404 while (pTopLevelSelected && m_pTreeView->getListBox().GetParent(pTopLevelSelected))
3405 pTopLevelSelected = m_pTreeView->getListBox().GetParent(pTopLevelSelected);
3406 ::rtl::OUString sInitialSelection;
3407 if (pTopLevelSelected)
3408 sInitialSelection = getDataSourceAcessor( pTopLevelSelected );
3410 Reference< XDataSource > xDataSource( getDataSourceByName( sInitialSelection, getView(), getORB(), NULL ) );
3411 Reference< XModel > xDocumentModel( getDataSourceOrModel( xDataSource ), UNO_QUERY );
3413 if ( xDocumentModel.is() )
3415 Reference< XInteractionHandler > xInteractionHandler(
3416 getORB()->createInstance(
3417 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.InteractionHandler" ) ) ),
3418 UNO_QUERY );
3419 OSL_ENSURE( xInteractionHandler.is(), "SbaTableQueryBrowser::implAdministrate: no interaction handler available!" );
3421 ::comphelper::NamedValueCollection aLoadArgs;
3422 aLoadArgs.put( "Model", xDocumentModel );
3423 aLoadArgs.put( "InteractionHandler", xInteractionHandler );
3424 aLoadArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
3426 Sequence< PropertyValue > aLoadArgPV;
3427 aLoadArgs >>= aLoadArgPV;
3429 xFrameLoader->loadComponentFromURL(
3430 xDocumentModel->getURL(),
3431 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_default")),
3432 nFrameSearchFlag,
3433 aLoadArgPV
3438 catch( const Exception& )
3440 DBG_UNHANDLED_EXCEPTION();
3444 // -----------------------------------------------------------------------------
3445 sal_Bool SbaTableQueryBrowser::requestQuickHelp( const SvLBoxEntry* _pEntry, String& _rText ) const
3447 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::requestQuickHelp" );
3448 const DBTreeListUserData* pData = static_cast< const DBTreeListUserData* >( _pEntry->GetUserData() );
3449 if ( ( pData->eType == etDatasource ) && pData->sAccessor.Len() )
3451 _rText = ::svt::OFileNotation( pData->sAccessor ).get( ::svt::OFileNotation::N_SYSTEM );
3452 return sal_True;
3454 return sal_False;
3457 // -----------------------------------------------------------------------------
3458 PopupMenu* SbaTableQueryBrowser::getContextMenu( Control& _rControl ) const
3460 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getContextMenu" );
3461 OSL_PRECOND( &m_pTreeView->getListBox() == &_rControl,
3462 "SbaTableQueryBrowser::getContextMenu: where does this come from?" );
3463 if ( &m_pTreeView->getListBox() != &_rControl )
3464 return NULL;
3466 return new PopupMenu( ModuleRes( MENU_BROWSER_DEFAULTCONTEXT ) );
3469 // -----------------------------------------------------------------------------
3470 IController& SbaTableQueryBrowser::getCommandController()
3472 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getCommandController" );
3473 return *this;
3476 // -----------------------------------------------------------------------------
3477 ::cppu::OInterfaceContainerHelper* SbaTableQueryBrowser::getContextMenuInterceptors()
3479 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getContextMenuInterceptors" );
3480 return &m_aContextMenuInterceptors;
3483 // -----------------------------------------------------------------------------
3484 Any SbaTableQueryBrowser::getCurrentSelection( Control& _rControl ) const
3486 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getCurrentSelection" );
3487 OSL_PRECOND( &m_pTreeView->getListBox() == &_rControl,
3488 "SbaTableQueryBrowser::getCurrentSelection: where does this come from?" );
3490 if ( &m_pTreeView->getListBox() != &_rControl )
3491 return Any();
3493 SvLBoxEntry* pSelected = m_pTreeView->getListBox().FirstSelected();
3494 if ( !pSelected )
3495 return Any();
3497 OSL_ENSURE( m_pTreeView->getListBox().NextSelected( pSelected ) == NULL,
3498 "SbaTableQueryBrowser::getCurrentSelection: single-selection is expected here!" );
3500 NamedDatabaseObject aSelectedObject;
3501 DBTreeListUserData* pData = static_cast< DBTreeListUserData* >( pSelected->GetUserData() );
3502 aSelectedObject.Type = static_cast< sal_Int32 >( pData->eType );
3504 switch ( aSelectedObject.Type )
3506 case DatabaseObject::QUERY:
3507 case DatabaseObject::TABLE:
3508 aSelectedObject.Name = m_pTreeView->getListBox().GetEntryText( pSelected );
3509 break;
3511 case DatabaseObjectContainer::DATA_SOURCE:
3512 case DatabaseObjectContainer::QUERIES:
3513 case DatabaseObjectContainer::TABLES:
3514 aSelectedObject.Name = getDataSourceAcessor( pSelected );
3515 break;
3517 default:
3518 OSL_ENSURE( false, "SbaTableQueryBrowser::getCurrentSelection: invalid (unexpected) object type!" );
3519 break;
3522 return makeAny( aSelectedObject );
3525 // -----------------------------------------------------------------------------
3526 sal_Bool SbaTableQueryBrowser::implGetQuerySignature( ::rtl::OUString& _rCommand, sal_Bool& _bEscapeProcessing )
3528 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::implGetQuerySignature" );
3529 _rCommand = ::rtl::OUString();
3530 _bEscapeProcessing = sal_False;
3534 // ontain the dss (data source signature) of the form
3535 ::rtl::OUString sDataSourceName;
3536 ::rtl::OUString sCommand;
3537 sal_Int32 nCommandType = CommandType::COMMAND;
3538 Reference< XPropertySet > xRowsetProps( getRowSet(), UNO_QUERY );
3539 ODataAccessDescriptor aDesc( xRowsetProps );
3540 sDataSourceName = aDesc.getDataSource();
3541 aDesc[ daCommand ] >>= sCommand;
3542 aDesc[ daCommandType ] >>= nCommandType;
3544 // do we need to do anything?
3545 if ( CommandType::QUERY != nCommandType )
3546 return sal_False;
3548 // get the query object
3549 Reference< XQueryDefinitionsSupplier > xSuppQueries;
3550 Reference< XNameAccess > xQueries;
3551 Reference< XPropertySet > xQuery;
3552 m_xDatabaseContext->getByName( sDataSourceName ) >>= xSuppQueries;
3553 if ( xSuppQueries.is() )
3554 xQueries = xSuppQueries->getQueryDefinitions();
3555 if ( xQueries.is() )
3556 xQueries->getByName( sCommand ) >>= xQuery;
3557 OSL_ENSURE( xQuery.is(), "SbaTableQueryBrowser::implGetQuerySignature: could not retrieve the query object!" );
3559 // get the two properties we need
3560 if ( xQuery.is() )
3562 xQuery->getPropertyValue( PROPERTY_COMMAND ) >>= _rCommand;
3563 _bEscapeProcessing = ::cppu::any2bool( xQuery->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) );
3564 return sal_True;
3567 catch( const Exception& )
3569 DBG_UNHANDLED_EXCEPTION();
3572 return sal_False;
3574 //------------------------------------------------------------------------------
3575 void SbaTableQueryBrowser::frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( RuntimeException )
3577 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::frameAction" );
3578 if (aEvent.Frame == m_xCurrentFrameParent)
3580 if(aEvent.Action == FrameAction_COMPONENT_DETACHING)
3581 implRemoveStatusListeners();
3582 else if (aEvent.Action == FrameAction_COMPONENT_REATTACHED)
3583 connectExternalDispatches();
3585 else
3586 SbaXDataBrowserController::frameAction(aEvent);
3589 // -----------------------------------------------------------------------------
3590 void SbaTableQueryBrowser::clearGridColumns(const Reference< XNameContainer >& _xColContainer)
3592 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::clearGridColumns" );
3593 // first we have to clear the grid
3594 Sequence< ::rtl::OUString > aNames = _xColContainer->getElementNames();
3595 const ::rtl::OUString* pIter = aNames.getConstArray();
3596 const ::rtl::OUString* pEnd = pIter + aNames.getLength();
3597 Reference< XInterface > xColumn;
3598 for (; pIter != pEnd;++pIter)
3600 _xColContainer->getByName(*pIter) >>= xColumn;
3601 _xColContainer->removeByName(*pIter);
3602 ::comphelper::disposeComponent(xColumn);
3605 // -----------------------------------------------------------------------------
3606 sal_Bool SbaTableQueryBrowser::isHiContrast() const
3608 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::isHiContrast" );
3609 sal_Bool bRet = sal_False;
3610 if ( m_pTreeView )
3611 bRet = m_pTreeView->getListBox().GetBackground().GetColor().IsDark();
3612 return bRet;
3614 // -----------------------------------------------------------------------------
3615 void SbaTableQueryBrowser::loadMenu(const Reference< XFrame >& _xFrame)
3617 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::loadMenu" );
3618 if ( m_bShowMenu )
3620 OGenericUnoController::loadMenu(_xFrame);
3622 else if ( !m_bPreview )
3624 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager = getLayoutManager(_xFrame);
3626 if ( xLayoutManager.is() )
3628 xLayoutManager->lock();
3629 xLayoutManager->createElement( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/toolbar" )));
3630 xLayoutManager->unlock();
3631 xLayoutManager->doLayout();
3633 onLoadedMenu( xLayoutManager );
3636 // -----------------------------------------------------------------------------
3637 ::rtl::OUString SbaTableQueryBrowser::getPrivateTitle() const
3639 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getPrivateTitle" );
3640 ::rtl::OUString sTitle;
3641 if ( m_pCurrentlyDisplayed )
3643 SvLBoxEntry* pContainer = m_pTreeModel->GetParent(m_pCurrentlyDisplayed);
3644 // get the entry for the datasource
3645 SvLBoxEntry* pConnection = m_pTreeModel->GetParent(pContainer);
3646 ::rtl::OUString sName = m_pTreeView->getListBox().GetEntryText(m_pCurrentlyDisplayed);
3647 sTitle = GetEntryText( pConnection );
3648 INetURLObject aURL(sTitle);
3649 if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
3650 sTitle = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_WITH_CHARSET);
3651 if ( sName.getLength() )
3653 sName += ::rtl::OUString::createFromAscii(" - ");
3654 sName += sTitle;
3655 sTitle = sName;
3659 return sTitle;
3661 // -----------------------------------------------------------------------------
3662 sal_Bool SbaTableQueryBrowser::preReloadForm()
3664 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::preReloadForm" );
3665 sal_Bool bIni = sal_False;
3666 if ( !m_pCurrentlyDisplayed )
3668 // switch the grid to design mode while loading
3669 getBrowserView()->getGridControl()->setDesignMode(sal_True);
3670 // we had an invalid statement so we need to connect the column models
3671 Reference<XPropertySet> xRowSetProps(getRowSet(),UNO_QUERY);
3672 ::svx::ODataAccessDescriptor aDesc(xRowSetProps);
3673 // extract the props
3674 ::rtl::OUString sDataSource;
3675 ::rtl::OUString sCommand;
3676 sal_Int32 nCommandType = CommandType::COMMAND;
3677 sal_Bool bEscapeProcessing = sal_True;
3678 extractDescriptorProps(aDesc, sDataSource, sCommand, nCommandType, bEscapeProcessing);
3679 if ( sDataSource.getLength() && sCommand.getLength() && (-1 != nCommandType) )
3681 SvLBoxEntry* pDataSource = NULL;
3682 SvLBoxEntry* pCommandType = NULL;
3683 m_pCurrentlyDisplayed = getObjectEntry( sDataSource, sCommand, nCommandType, &pDataSource, &pCommandType, sal_True, SharedConnection() );
3684 bIni = sal_True;
3687 return bIni;
3690 // -----------------------------------------------------------------------------
3691 void SbaTableQueryBrowser::postReloadForm()
3693 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::postReloadForm" );
3694 InitializeGridModel(getFormComponent());
3695 LoadFinished(sal_True);
3696 //updateTitle();
3699 //------------------------------------------------------------------------------
3700 Reference< XEmbeddedScripts > SAL_CALL SbaTableQueryBrowser::getScriptContainer() throw (RuntimeException)
3702 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::getScriptContainer" );
3703 // update our database document
3704 Reference< XModel > xDocument;
3707 Reference< XPropertySet > xCursorProps( getRowSet(), UNO_QUERY_THROW );
3708 Reference< XConnection > xConnection( xCursorProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ), UNO_QUERY );
3709 if ( xConnection.is() )
3711 Reference< XChild > xChild( xConnection, UNO_QUERY_THROW );
3712 Reference< XDocumentDataSource > xDataSource( xChild->getParent(), UNO_QUERY_THROW );
3713 xDocument.set( xDataSource->getDatabaseDocument(), UNO_QUERY_THROW );
3716 catch( const Exception& )
3718 DBG_UNHANDLED_EXCEPTION();
3720 Reference< XEmbeddedScripts > xScripts( xDocument, UNO_QUERY );
3721 OSL_ENSURE( xScripts.is() || !xDocument.is(),
3722 "SbaTableQueryBrowser::getScriptContainer: invalid database document!" );
3723 return xScripts;
3726 //------------------------------------------------------------------------------
3727 void SAL_CALL SbaTableQueryBrowser::registerContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException)
3729 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::registerContextMenuInterceptor" );
3730 if ( _Interceptor.is() )
3731 m_aContextMenuInterceptors.addInterface( _Interceptor );
3734 //------------------------------------------------------------------------------
3735 void SAL_CALL SbaTableQueryBrowser::releaseContextMenuInterceptor( const Reference< XContextMenuInterceptor >& _Interceptor ) throw (RuntimeException)
3737 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaTableQueryBrowser::releaseContextMenuInterceptor" );
3738 m_aContextMenuInterceptors.removeInterface( _Interceptor );
3741 // .........................................................................
3742 } // namespace dbaui
3743 // .........................................................................