Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "browserids.hxx"
22 : : #include "commontypes.hxx"
23 : : #include "dataview.hxx"
24 : : #include "dbu_misc.hrc"
25 : : #include "dbustrings.hrc"
26 : : #include "moduledbu.hxx"
27 : : #include "dbsubcomponentcontroller.hxx"
28 : :
29 : : #include <com/sun/star/frame/XUntitledNumbers.hpp>
30 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
31 : : #include <com/sun/star/container/XChild.hpp>
32 : : #include <com/sun/star/container/XNameAccess.hpp>
33 : : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
34 : : #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
35 : : #include <com/sun/star/sdbc/XDataSource.hpp>
36 : : #include <com/sun/star/lang/IllegalArgumentException.hpp>
37 : :
38 : : #include <comphelper/sequence.hxx>
39 : : #include <comphelper/types.hxx>
40 : : #include <connectivity/dbexception.hxx>
41 : : #include <connectivity/dbtools.hxx>
42 : : #include <cppuhelper/typeprovider.hxx>
43 : : #include <rtl/ustrbuf.hxx>
44 : : #include <toolkit/unohlp.hxx>
45 : : #include <tools/debug.hxx>
46 : : #include <tools/diagnose_ex.h>
47 : : #include <vcl/msgbox.hxx>
48 : :
49 : : //........................................................................
50 : : namespace dbaui
51 : : {
52 : : //........................................................................
53 : :
54 : : /** === begin UNO using === **/
55 : : using ::com::sun::star::uno::Any;
56 : : using ::com::sun::star::uno::Reference;
57 : : using ::com::sun::star::beans::XPropertySet;
58 : : using ::com::sun::star::util::XNumberFormatter;
59 : : using ::com::sun::star::lang::XMultiServiceFactory;
60 : : using ::com::sun::star::uno::RuntimeException;
61 : : using ::com::sun::star::uno::Sequence;
62 : : using ::com::sun::star::uno::Type;
63 : : using ::com::sun::star::sdbc::XConnection;
64 : : using ::com::sun::star::uno::UNO_QUERY;
65 : : using ::com::sun::star::container::XChild;
66 : : using ::com::sun::star::sdbc::XDataSource;
67 : : using ::com::sun::star::util::XNumberFormatter;
68 : : using ::com::sun::star::util::XNumberFormatsSupplier;
69 : : using ::com::sun::star::frame::XFrame;
70 : : using ::com::sun::star::uno::Exception;
71 : : using ::com::sun::star::sdbc::SQLException;
72 : : using ::com::sun::star::lang::EventObject;
73 : : using ::com::sun::star::beans::PropertyValue;
74 : : using ::com::sun::star::frame::XModel;
75 : : using ::com::sun::star::sdb::XOfficeDatabaseDocument;
76 : : using ::com::sun::star::awt::XWindow;
77 : : using ::com::sun::star::sdbc::XDatabaseMetaData;
78 : : using ::com::sun::star::sdb::XDocumentDataSource;
79 : : using ::com::sun::star::document::XEmbeddedScripts;
80 : : using ::com::sun::star::lang::IllegalArgumentException;
81 : : using ::com::sun::star::uno::UNO_SET_THROW;
82 : : using ::com::sun::star::uno::UNO_QUERY_THROW;
83 : : using ::com::sun::star::frame::XUntitledNumbers;
84 : : using ::com::sun::star::beans::PropertyVetoException;
85 : : /** === end UNO using === **/
86 : :
87 : 0 : class DataSourceHolder
88 : : {
89 : : public:
90 : 0 : DataSourceHolder()
91 : 0 : {
92 : 0 : }
93 : :
94 : 0 : DataSourceHolder( const Reference< XDataSource >& _rxDataSource )
95 : 0 : {
96 [ # # ]: 0 : m_xDataSource = _rxDataSource;
97 [ # # ]: 0 : Reference< XDocumentDataSource > xDocDS( m_xDataSource, UNO_QUERY );
98 [ # # ]: 0 : if ( xDocDS.is() )
99 [ # # ][ # # ]: 0 : m_xDocument = xDocDS->getDatabaseDocument();
[ # # ]
100 : :
101 [ # # ]: 0 : m_xDataSourceProps.set( m_xDataSource, UNO_QUERY );
102 : 0 : }
103 : :
104 : 0 : const Reference< XDataSource >& getDataSource() const { return m_xDataSource; }
105 : 0 : const Reference< XPropertySet >& getDataSourceProps() const { return m_xDataSourceProps; }
106 : 0 : const Reference< XOfficeDatabaseDocument > getDatabaseDocument() const { return m_xDocument; }
107 : :
108 : 0 : bool is() const { return m_xDataSource.is(); }
109 : :
110 : 0 : void clear()
111 : : {
112 : 0 : m_xDataSource.clear();
113 : 0 : m_xDocument.clear();
114 : 0 : }
115 : :
116 : : private:
117 : : Reference< XDataSource > m_xDataSource;
118 : : Reference< XPropertySet > m_xDataSourceProps;
119 : : Reference< XOfficeDatabaseDocument > m_xDocument;
120 : : };
121 : :
122 [ # # ][ # # ]: 0 : struct DBSubComponentController_Impl
[ # # ][ # # ]
[ # # ][ # # ]
123 : : {
124 : : private:
125 : : ::boost::optional< bool > m_aDocScriptSupport;
126 : :
127 : : public:
128 : : OModuleClient m_aModuleClient;
129 : : ::dbtools::SQLExceptionInfo m_aCurrentError;
130 : :
131 : : ::cppu::OInterfaceContainerHelper
132 : : m_aModifyListeners;
133 : :
134 : : // <properties>
135 : : SharedConnection m_xConnection;
136 : : ::dbtools::DatabaseMetaData m_aSdbMetaData;
137 : : // </properties>
138 : : ::rtl::OUString m_sDataSourceName; // the data source we're working for
139 : : DataSourceHolder m_aDataSource;
140 : : Reference< XModel > m_xDocument;
141 : : Reference< XNumberFormatter > m_xFormatter; // a number formatter working with the connection's NumberFormatsSupplier
142 : : sal_Int32 m_nDocStartNumber;
143 : : sal_Bool m_bSuspended; // is true when the controller was already suspended
144 : : sal_Bool m_bEditable; // is the control readonly or not
145 : : sal_Bool m_bModified; // is the data modified
146 : : bool m_bNotAttached;
147 : :
148 : 0 : DBSubComponentController_Impl( ::osl::Mutex& i_rMutex )
149 : : :m_aDocScriptSupport()
150 : : ,m_aModifyListeners( i_rMutex )
151 : : ,m_nDocStartNumber(0)
152 : : ,m_bSuspended( sal_False )
153 : : ,m_bEditable(sal_True)
154 : : ,m_bModified(sal_False)
155 [ # # ][ # # ]: 0 : ,m_bNotAttached(true)
[ # # ][ # # ]
[ # # ][ # # ]
156 : : {
157 : 0 : }
158 : :
159 : 0 : bool documentHasScriptSupport() const
160 : : {
161 : : OSL_PRECOND( !!m_aDocScriptSupport,
162 : : "DBSubComponentController_Impl::documentHasScriptSupport: not completely initialized, yet - don't know!?" );
163 [ # # ][ # # ]: 0 : return !!m_aDocScriptSupport && *m_aDocScriptSupport;
164 : : }
165 : :
166 : 0 : void setDocumentScriptSupport( const bool _bSupport )
167 : : {
168 : : OSL_PRECOND( !m_aDocScriptSupport,
169 : : "DBSubComponentController_Impl::setDocumentScriptSupport: already initialized!" );
170 [ # # ]: 0 : m_aDocScriptSupport = ::boost::optional< bool >( _bSupport );
171 : 0 : }
172 : : };
173 : :
174 : : //====================================================================
175 : : //= DBSubComponentController
176 : : //====================================================================
177 : : //--------------------------------------------------------------------
178 : 0 : DBSubComponentController::DBSubComponentController(const Reference< XMultiServiceFactory >& _rxORB)
179 : : :DBSubComponentController_Base( _rxORB )
180 [ # # ][ # # ]: 0 : ,m_pImpl( new DBSubComponentController_Impl( getMutex() ) )
[ # # ]
181 : : {
182 : 0 : }
183 : :
184 : : //--------------------------------------------------------------------
185 [ # # ]: 0 : DBSubComponentController::~DBSubComponentController()
186 : : {
187 [ # # ]: 0 : }
188 : :
189 : : //--------------------------------------------------------------------
190 : 0 : void DBSubComponentController::impl_initialize()
191 : : {
192 [ # # ]: 0 : OGenericUnoController::impl_initialize();
193 : :
194 : 0 : const ::comphelper::NamedValueCollection& rArguments( getInitParams() );
195 : :
196 : 0 : Reference< XConnection > xConnection;
197 [ # # ][ # # ]: 0 : xConnection = rArguments.getOrDefault( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, xConnection );
[ # # ]
198 : :
199 [ # # ]: 0 : if ( !xConnection.is() )
200 [ # # ][ # # ]: 0 : ::dbtools::isEmbeddedInDatabase( getModel(), xConnection );
201 : :
202 [ # # ]: 0 : if ( xConnection.is() )
203 [ # # ]: 0 : initializeConnection( xConnection );
204 : :
205 : 0 : bool bShowError = true;
206 [ # # ][ # # ]: 0 : if ( !isConnected() )
207 : : {
208 [ # # ]: 0 : reconnect( sal_False );
209 : 0 : bShowError = false;
210 : : }
211 [ # # ][ # # ]: 0 : if ( !isConnected() )
212 : : {
213 [ # # ]: 0 : if ( bShowError )
214 [ # # ]: 0 : connectionLostMessage();
215 [ # # ]: 0 : throw IllegalArgumentException();
216 : 0 : }
217 : 0 : }
218 : :
219 : : //--------------------------------------------------------------------
220 : 0 : Any SAL_CALL DBSubComponentController::queryInterface(const Type& _rType) throw (RuntimeException)
221 : : {
222 [ # # ]: 0 : if ( _rType.equals( XScriptInvocationContext::static_type() ) )
223 : : {
224 [ # # ]: 0 : if ( m_pImpl->documentHasScriptSupport() )
225 [ # # ]: 0 : return makeAny( Reference< XScriptInvocationContext >( this ) );
226 : 0 : return Any();
227 : : }
228 : :
229 : 0 : return DBSubComponentController_Base::queryInterface( _rType );
230 : : }
231 : :
232 : : //--------------------------------------------------------------------
233 : 0 : Sequence< Type > SAL_CALL DBSubComponentController::getTypes( ) throw (RuntimeException)
234 : : {
235 : 0 : Sequence< Type > aTypes( DBSubComponentController_Base::getTypes() );
236 [ # # ][ # # ]: 0 : if ( !m_pImpl->documentHasScriptSupport() )
237 : : {
238 [ # # ]: 0 : Sequence< Type > aStrippedTypes( aTypes.getLength() - 1 );
239 : : ::std::remove_copy_if(
240 : : aTypes.getConstArray(),
241 : 0 : aTypes.getConstArray() + aTypes.getLength(),
242 : : aStrippedTypes.getArray(),
243 [ # # ]: 0 : ::std::bind2nd( ::std::equal_to< Type >(), XScriptInvocationContext::static_type() )
244 [ # # ]: 0 : );
[ # # # # ]
245 [ # # ][ # # ]: 0 : aTypes = aStrippedTypes;
246 : : }
247 : 0 : return aTypes;
248 : : }
249 : :
250 : : //--------------------------------------------------------------------
251 : 0 : void DBSubComponentController::initializeConnection( const Reference< XConnection >& _rxForeignConn )
252 : : {
253 : : DBG_ASSERT( !isConnected(), "DBSubComponentController::initializeConnection: not to be called when already connected!" );
254 : : // usually this gets called from within initialize of derived classes ...
255 [ # # ]: 0 : if ( isConnected() )
256 : 0 : disconnect();
257 : :
258 : 0 : m_pImpl->m_xConnection.reset( _rxForeignConn, SharedConnection::NoTakeOwnership );
259 : 0 : m_pImpl->m_aSdbMetaData.reset( m_pImpl->m_xConnection );
260 : 0 : startConnectionListening( m_pImpl->m_xConnection );
261 : :
262 : : // get the data source the connection belongs to
263 : : try
264 : : {
265 : : // determine our data source
266 : : OSL_PRECOND( !m_pImpl->m_aDataSource.is(), "DBSubComponentController::initializeConnection: already a data source in this phase?" );
267 : : {
268 [ # # ]: 0 : Reference< XChild > xConnAsChild( m_pImpl->m_xConnection, UNO_QUERY );
269 : 0 : Reference< XDataSource > xDS;
270 [ # # ]: 0 : if ( xConnAsChild.is() )
271 [ # # ][ # # ]: 0 : xDS = Reference< XDataSource >( xConnAsChild->getParent(), UNO_QUERY );
[ # # ][ # # ]
272 : :
273 : : // (take the indirection through XDataSource to ensure we have a correct object ....)
274 [ # # ][ # # ]: 0 : m_pImpl->m_aDataSource = xDS;
[ # # ]
275 : : }
276 : : OSL_POSTCOND( m_pImpl->m_aDataSource.is(), "DBSubComponentController::initializeConnection: unable to obtain the data source object!" );
277 : :
278 [ # # ]: 0 : if ( m_pImpl->m_bNotAttached )
279 : : {
280 [ # # ][ # # ]: 0 : Reference< XUntitledNumbers > xUntitledProvider( getDatabaseDocument(), UNO_QUERY );
281 : 0 : m_pImpl->m_nDocStartNumber = 1;
282 [ # # ]: 0 : if ( xUntitledProvider.is() )
283 [ # # ][ # # ]: 0 : m_pImpl->m_nDocStartNumber = xUntitledProvider->leaseNumber( static_cast< XWeak* >( this ) );
[ # # ]
284 : : }
285 : :
286 : : // determine the availability of script support in our document. Our own XScriptInvocationContext
287 : : // interface depends on this
288 [ # # ][ # # ]: 0 : m_pImpl->setDocumentScriptSupport( Reference< XEmbeddedScripts >( getDatabaseDocument(), UNO_QUERY ).is() );
[ # # ]
289 : :
290 : : // get a number formatter
291 [ # # ]: 0 : Reference< XPropertySet > xDataSourceProps( m_pImpl->m_aDataSource.getDataSourceProps(), UNO_SET_THROW );
292 [ # # ][ # # ]: 0 : xDataSourceProps->getPropertyValue( PROPERTY_NAME ) >>= m_pImpl->m_sDataSourceName;
[ # # ]
293 : : DBG_ASSERT( !m_pImpl->m_sDataSourceName.isEmpty(), "DBSubComponentController::initializeConnection: invalid data source name!" );
294 [ # # ]: 0 : Reference< XNumberFormatsSupplier> xSupplier = ::dbtools::getNumberFormats(m_pImpl->m_xConnection);
295 [ # # ]: 0 : if(xSupplier.is())
296 : : {
297 : 0 : m_pImpl->m_xFormatter = Reference< XNumberFormatter >(getORB()
298 [ # # ][ # # ]: 0 : ->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatter"))), UNO_QUERY);
[ # # ][ # # ]
[ # # # # ]
299 [ # # ][ # # ]: 0 : m_pImpl->m_xFormatter->attachNumberFormatsSupplier(xSupplier);
300 : : }
301 [ # # ]: 0 : OSL_ENSURE(m_pImpl->m_xFormatter.is(),"No NumberFormatter!");
302 : : }
303 : 0 : catch( const Exception& )
304 : : {
305 : : DBG_UNHANDLED_EXCEPTION();
306 : : }
307 : 0 : }
308 : :
309 : : //--------------------------------------------------------------------
310 : 0 : void DBSubComponentController::reconnect( sal_Bool _bUI )
311 : : {
312 : : OSL_ENSURE(!m_pImpl->m_bSuspended, "Cannot reconnect while suspended!");
313 : :
314 : 0 : stopConnectionListening( m_pImpl->m_xConnection );
315 [ # # ]: 0 : m_pImpl->m_aSdbMetaData.reset( NULL );
316 : 0 : m_pImpl->m_xConnection.clear();
317 : :
318 : : // reconnect
319 : 0 : sal_Bool bReConnect = sal_True;
320 [ # # ]: 0 : if ( _bUI )
321 : : {
322 [ # # ][ # # ]: 0 : QueryBox aQuery( getView(), ModuleRes(QUERY_CONNECTION_LOST) );
323 [ # # ][ # # ]: 0 : bReConnect = ( RET_YES == aQuery.Execute() );
324 : : }
325 : :
326 : : // now really reconnect ...
327 [ # # ]: 0 : if ( bReConnect )
328 : : {
329 [ # # ]: 0 : m_pImpl->m_xConnection.reset( connect( m_pImpl->m_aDataSource.getDataSource(), NULL ), SharedConnection::TakeOwnership );
330 : 0 : m_pImpl->m_aSdbMetaData.reset( m_pImpl->m_xConnection );
331 : : }
332 : :
333 : : // invalidate all slots
334 : 0 : InvalidateAll();
335 : 0 : }
336 : :
337 : : //--------------------------------------------------------------------
338 : 0 : void DBSubComponentController::disconnect()
339 : : {
340 : 0 : stopConnectionListening(m_pImpl->m_xConnection);
341 [ # # ]: 0 : m_pImpl->m_aSdbMetaData.reset( NULL );
342 : 0 : m_pImpl->m_xConnection.clear();
343 : :
344 : 0 : InvalidateAll();
345 : 0 : }
346 : :
347 : : //--------------------------------------------------------------------
348 : 0 : void DBSubComponentController::losingConnection()
349 : : {
350 : : // our connection was disposed so we need a new one
351 : 0 : reconnect( sal_True );
352 : 0 : InvalidateAll();
353 : 0 : }
354 : :
355 : : //--------------------------------------------------------------------
356 : 0 : void SAL_CALL DBSubComponentController::disposing()
357 : : {
358 : 0 : DBSubComponentController_Base::disposing();
359 : :
360 : 0 : disconnect();
361 : :
362 [ # # ]: 0 : attachFrame( Reference < XFrame >() );
363 : :
364 : 0 : m_pImpl->m_aDataSource.clear();
365 : 0 : }
366 : :
367 : : //--------------------------------------------------------------------
368 : 0 : void SAL_CALL DBSubComponentController::disposing(const EventObject& _rSource) throw( RuntimeException )
369 : : {
370 [ # # ]: 0 : if ( _rSource.Source == getConnection() )
371 : : {
372 [ # # # # : 0 : if ( !m_pImpl->m_bSuspended // when already suspended then we don't have to reconnect
# # # # ]
[ # # ]
373 : 0 : && !getBroadcastHelper().bInDispose
374 : 0 : && !getBroadcastHelper().bDisposed
375 : 0 : && isConnected()
376 : : )
377 : : {
378 : 0 : losingConnection();
379 : : }
380 : : else
381 : : {
382 : 0 : m_pImpl->m_xConnection.reset( m_pImpl->m_xConnection, SharedConnection::NoTakeOwnership );
383 : : // this prevents the "disposeComponent" call in disconnect
384 : 0 : disconnect();
385 : : }
386 : : }
387 : : else
388 : 0 : DBSubComponentController_Base::disposing( _rSource );
389 : 0 : }
390 : :
391 : : //--------------------------------------------------------------------
392 : 0 : void DBSubComponentController::appendError( const ::rtl::OUString& _rErrorMessage, const ::dbtools::StandardSQLState _eSQLState,
393 : : const sal_Int32 _nErrorCode )
394 : : {
395 : 0 : m_pImpl->m_aCurrentError.append( ::dbtools::SQLExceptionInfo::SQL_EXCEPTION, _rErrorMessage, getStandardSQLStateAscii( _eSQLState ),
396 : 0 : _nErrorCode );
397 : 0 : }
398 : : //--------------------------------------------------------------------
399 : 0 : void DBSubComponentController::clearError()
400 : : {
401 [ # # ]: 0 : m_pImpl->m_aCurrentError = ::dbtools::SQLExceptionInfo();
402 : 0 : }
403 : :
404 : : //--------------------------------------------------------------------
405 : 0 : sal_Bool DBSubComponentController::hasError() const
406 : : {
407 : 0 : return m_pImpl->m_aCurrentError.isValid();
408 : : }
409 : :
410 : : //--------------------------------------------------------------------
411 : 0 : const ::dbtools::SQLExceptionInfo& DBSubComponentController::getError() const
412 : : {
413 : 0 : return m_pImpl->m_aCurrentError;
414 : : }
415 : :
416 : : //--------------------------------------------------------------------
417 : 0 : void DBSubComponentController::displayError()
418 : : {
419 : 0 : showError( m_pImpl->m_aCurrentError );
420 : 0 : }
421 : :
422 : : //--------------------------------------------------------------------
423 : 0 : sal_Bool SAL_CALL DBSubComponentController::suspend(sal_Bool bSuspend) throw( RuntimeException )
424 : : {
425 : 0 : m_pImpl->m_bSuspended = bSuspend;
426 [ # # ][ # # ]: 0 : if ( !bSuspend && !isConnected() )
[ # # ]
427 : 0 : reconnect(sal_True);
428 : :
429 : :
430 : 0 : return sal_True;
431 : : }
432 : :
433 : : // -----------------------------------------------------------------------------
434 : 0 : sal_Bool SAL_CALL DBSubComponentController::attachModel( const Reference< XModel > & _rxModel) throw( RuntimeException )
435 : : {
436 [ # # ]: 0 : if ( !_rxModel.is() )
437 : 0 : return sal_False;
438 [ # # ][ # # ]: 0 : if ( !DBSubComponentController_Base::attachModel( _rxModel ) )
439 : 0 : return sal_False;
440 : :
441 : 0 : m_pImpl->m_bNotAttached = false;
442 [ # # ]: 0 : if ( m_pImpl->m_nDocStartNumber == 1 )
443 [ # # ]: 0 : releaseNumberForComponent();
444 : :
445 [ # # ]: 0 : Reference< XUntitledNumbers > xUntitledProvider( _rxModel, UNO_QUERY );
446 : 0 : m_pImpl->m_nDocStartNumber = 1;
447 [ # # ]: 0 : if ( xUntitledProvider.is() )
448 [ # # ][ # # ]: 0 : m_pImpl->m_nDocStartNumber = xUntitledProvider->leaseNumber( static_cast< XWeak* >( this ) );
[ # # ]
449 : :
450 : 0 : return sal_True;
451 : : }
452 : :
453 : : // -----------------------------------------------------------------------------
454 : 0 : void DBSubComponentController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& _rArgs)
455 : : {
456 [ # # ]: 0 : if ( _nId == ID_BROWSER_CLOSE )
457 : : {
458 : 0 : closeTask();
459 : 0 : return;
460 : : }
461 : :
462 : 0 : DBSubComponentController_Base::Execute( _nId, _rArgs );
463 [ # # ]: 0 : InvalidateFeature( _nId );
464 : : }
465 : :
466 : : // -----------------------------------------------------------------------------
467 : 0 : ::rtl::OUString DBSubComponentController::getDataSourceName() const
468 : : {
469 : 0 : ::rtl::OUString sName;
470 : 0 : Reference< XPropertySet > xDataSourceProps( m_pImpl->m_aDataSource.getDataSourceProps() );
471 [ # # ]: 0 : if ( xDataSourceProps.is() )
472 [ # # ][ # # ]: 0 : xDataSourceProps->getPropertyValue(PROPERTY_NAME) >>= sName;
[ # # ]
473 : 0 : return sName;
474 : : }
475 : : // -----------------------------------------------------------------------------
476 : 0 : void DBSubComponentController::connectionLostMessage() const
477 : : {
478 [ # # ][ # # ]: 0 : String aMessage(ModuleRes(RID_STR_CONNECTION_LOST));
479 [ # # ]: 0 : Reference< XWindow > xWindow = getTopMostContainerWindow();
480 : 0 : Window* pWin = NULL;
481 [ # # ]: 0 : if ( xWindow.is() )
482 [ # # ]: 0 : pWin = VCLUnoHelper::GetWindow(xWindow);
483 [ # # ]: 0 : if ( !pWin )
484 [ # # ]: 0 : pWin = getView()->Window::GetParent();
485 : :
486 [ # # ][ # # ]: 0 : InfoBox(pWin, aMessage).Execute();
[ # # ][ # # ]
487 : 0 : }
488 : : // -----------------------------------------------------------------------------
489 : 0 : const Reference< XConnection >& DBSubComponentController::getConnection() const
490 : : {
491 : 0 : return m_pImpl->m_xConnection;
492 : : }
493 : :
494 : : // -----------------------------------------------------------------------------
495 : 0 : sal_Bool DBSubComponentController::isReadOnly() const
496 : : {
497 : 0 : return !m_pImpl->m_bEditable;
498 : : }
499 : :
500 : : // -----------------------------------------------------------------------------
501 : 0 : sal_Bool DBSubComponentController::isEditable() const
502 : : {
503 : 0 : return m_pImpl->m_bEditable;
504 : : }
505 : :
506 : : // -----------------------------------------------------------------------------
507 : 0 : void DBSubComponentController::setEditable(sal_Bool _bEditable)
508 : : {
509 : 0 : m_pImpl->m_bEditable = _bEditable;
510 : 0 : }
511 : :
512 : : // -----------------------------------------------------------------------------
513 : 0 : const ::dbtools::DatabaseMetaData& DBSubComponentController::getSdbMetaData() const
514 : : {
515 : 0 : return m_pImpl->m_aSdbMetaData;
516 : : }
517 : :
518 : : // -----------------------------------------------------------------------------
519 : 0 : sal_Bool DBSubComponentController::isConnected() const
520 : : {
521 : 0 : return m_pImpl->m_xConnection.is();
522 : : }
523 : :
524 : : // -----------------------------------------------------------------------------
525 : 0 : Reference< XDatabaseMetaData > DBSubComponentController::getMetaData( ) const
526 : : {
527 : 0 : Reference< XDatabaseMetaData > xMeta;
528 : : try
529 : : {
530 [ # # ][ # # ]: 0 : if ( isConnected() )
531 [ # # ][ # # ]: 0 : xMeta.set( m_pImpl->m_xConnection->getMetaData(), UNO_SET_THROW );
[ # # ][ # # ]
532 : : }
533 [ # # ]: 0 : catch( const Exception& )
534 : : {
535 : : DBG_UNHANDLED_EXCEPTION();
536 : : }
537 : 0 : return xMeta;
538 : : }
539 : :
540 : : // -----------------------------------------------------------------------------
541 : 0 : const Reference< XPropertySet >& DBSubComponentController::getDataSource() const
542 : : {
543 : 0 : return m_pImpl->m_aDataSource.getDataSourceProps();
544 : : }
545 : :
546 : : // -----------------------------------------------------------------------------
547 : 0 : sal_Bool DBSubComponentController::haveDataSource() const
548 : : {
549 : 0 : return m_pImpl->m_aDataSource.is();
550 : : }
551 : :
552 : : // -----------------------------------------------------------------------------
553 : 0 : Reference< XModel > DBSubComponentController::getDatabaseDocument() const
554 : : {
555 [ # # ]: 0 : return Reference< XModel >( m_pImpl->m_aDataSource.getDatabaseDocument(), UNO_QUERY );
556 : : }
557 : :
558 : : // -----------------------------------------------------------------------------
559 : 0 : Reference< XNumberFormatter > DBSubComponentController::getNumberFormatter() const
560 : : {
561 : 0 : return m_pImpl->m_xFormatter;
562 : : }
563 : :
564 : : // -----------------------------------------------------------------------------
565 : 0 : Reference< XModel > DBSubComponentController::getPrivateModel() const
566 : : {
567 : 0 : return getDatabaseDocument();
568 : : }
569 : : // -----------------------------------------------------------------------------
570 : : // XTitle
571 : 0 : ::rtl::OUString SAL_CALL DBSubComponentController::getTitle()
572 : : throw (RuntimeException)
573 : : {
574 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( getMutex() );
575 [ # # ]: 0 : if ( m_bExternalTitle )
576 [ # # ][ # # ]: 0 : return impl_getTitleHelper_throw()->getTitle ();
[ # # ]
577 : :
578 : 0 : ::rtl::OUStringBuffer sTitle;
579 [ # # ][ # # ]: 0 : Reference< XTitle > xTitle(getPrivateModel(),UNO_QUERY);
580 [ # # ]: 0 : if ( xTitle.is() )
581 : : {
582 [ # # ][ # # ]: 0 : sTitle.append( xTitle->getTitle() );
[ # # ]
583 [ # # ]: 0 : sTitle.appendAscii(" : ");
584 : : }
585 [ # # ][ # # ]: 0 : sTitle.append( getPrivateTitle() );
586 [ # # ][ # # ]: 0 : return sTitle.makeStringAndClear();
587 : : }
588 : :
589 : : // -----------------------------------------------------------------------------
590 : 0 : sal_Int32 DBSubComponentController::getCurrentStartNumber() const
591 : : {
592 : 0 : return m_pImpl->m_nDocStartNumber;
593 : : }
594 : :
595 : : // -----------------------------------------------------------------------------
596 : 0 : Reference< XEmbeddedScripts > SAL_CALL DBSubComponentController::getScriptContainer() throw (RuntimeException)
597 : : {
598 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( getMutex() );
599 [ # # ][ # # ]: 0 : if ( !m_pImpl->documentHasScriptSupport() )
600 [ # # ]: 0 : return NULL;
601 : :
602 [ # # ][ # # ]: 0 : return Reference< XEmbeddedScripts >( getDatabaseDocument(), UNO_QUERY_THROW );
[ # # ]
603 : : }
604 : :
605 : : // -----------------------------------------------------------------------------
606 : 0 : void SAL_CALL DBSubComponentController::addModifyListener( const Reference< XModifyListener >& i_Listener ) throw (RuntimeException)
607 : : {
608 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( getMutex() );
609 [ # # ][ # # ]: 0 : m_pImpl->m_aModifyListeners.addInterface( i_Listener );
610 : 0 : }
611 : :
612 : : // -----------------------------------------------------------------------------
613 : 0 : void SAL_CALL DBSubComponentController::removeModifyListener( const Reference< XModifyListener >& i_Listener ) throw (RuntimeException)
614 : : {
615 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( getMutex() );
616 [ # # ][ # # ]: 0 : m_pImpl->m_aModifyListeners.removeInterface( i_Listener );
617 : 0 : }
618 : :
619 : : // -----------------------------------------------------------------------------
620 : 0 : ::sal_Bool SAL_CALL DBSubComponentController::isModified( ) throw (RuntimeException)
621 : : {
622 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( getMutex() );
623 [ # # ][ # # ]: 0 : return impl_isModified();
624 : : }
625 : :
626 : : // -----------------------------------------------------------------------------
627 : 0 : void SAL_CALL DBSubComponentController::setModified( ::sal_Bool i_bModified ) throw (PropertyVetoException, RuntimeException)
628 : : {
629 [ # # ][ # # ]: 0 : ::osl::ClearableMutexGuard aGuard( getMutex() );
630 : :
631 [ # # ]: 0 : if ( m_pImpl->m_bModified == i_bModified )
632 : 0 : return;
633 : :
634 : 0 : m_pImpl->m_bModified = i_bModified;
635 [ # # ]: 0 : impl_onModifyChanged();
636 : :
637 [ # # ][ # # ]: 0 : EventObject aEvent( *this );
638 [ # # ]: 0 : aGuard.clear();
639 [ # # ][ # # ]: 0 : m_pImpl->m_aModifyListeners.notifyEach( &XModifyListener::modified, aEvent );
[ # # ][ # # ]
640 : : }
641 : :
642 : : // -----------------------------------------------------------------------------
643 : 0 : sal_Bool DBSubComponentController::impl_isModified() const
644 : : {
645 : 0 : return m_pImpl->m_bModified;
646 : : }
647 : :
648 : : // -----------------------------------------------------------------------------
649 : 0 : void DBSubComponentController::impl_onModifyChanged()
650 : : {
651 [ # # ]: 0 : InvalidateFeature( ID_BROWSER_SAVEDOC );
652 [ # # ]: 0 : if ( isFeatureSupported( ID_BROWSER_SAVEASDOC ) )
653 [ # # ]: 0 : InvalidateFeature( ID_BROWSER_SAVEASDOC );
654 : 0 : }
655 : :
656 : : //........................................................................
657 : : } // namespace dbaui
658 : : //........................................................................
659 : :
660 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|