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