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