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 : #include "browserids.hxx"
21 : #include "brwctrlr.hxx"
22 : #include "brwview.hxx"
23 : #include "dbu_brw.hrc"
24 : #include "dbustrings.hrc"
25 : #include "queryfilter.hxx"
26 : #include "queryorder.hxx"
27 : #include "sqlmessage.hxx"
28 :
29 : #include <com/sun/star/beans/PropertyAttribute.hpp>
30 : #include <com/sun/star/container/XNameContainer.hpp>
31 : #include <com/sun/star/container/XNamed.hpp>
32 : #include <com/sun/star/form/FormButtonType.hpp>
33 : #include <com/sun/star/form/FormSubmitEncoding.hpp>
34 : #include <com/sun/star/form/FormSubmitMethod.hpp>
35 : #include <com/sun/star/form/XApproveActionBroadcaster.hpp>
36 : #include <com/sun/star/form/XBoundControl.hpp>
37 : #include <com/sun/star/form/XChangeBroadcaster.hpp>
38 : #include <com/sun/star/form/XChangeListener.hpp>
39 : #include <com/sun/star/form/XDatabaseParameterBroadcaster.hpp>
40 : #include <com/sun/star/form/XLoadable.hpp>
41 : #include <com/sun/star/form/XReset.hpp>
42 : #include <com/sun/star/form/XResetListener.hpp>
43 : #include <com/sun/star/form/XSubmit.hpp>
44 : #include <com/sun/star/form/XSubmitListener.hpp>
45 : #include <com/sun/star/form/runtime/XFormController.hpp>
46 : #include <com/sun/star/form/runtime/FormOperations.hpp>
47 : #include <com/sun/star/sdb/CommandType.hpp>
48 : #include <com/sun/star/sdb/ErrorCondition.hpp>
49 : #include <com/sun/star/sdb/ParametersRequest.hpp>
50 : #include <com/sun/star/sdb/SQLContext.hpp>
51 : #include <com/sun/star/sdb/XInteractionSupplyParameters.hpp>
52 : #include <com/sun/star/sdb/XSQLErrorBroadcaster.hpp>
53 : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
54 : #include <com/sun/star/sdb/SQLFilterOperator.hpp>
55 : #include <com/sun/star/sdbc/XConnection.hpp>
56 : #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
57 : #include <com/sun/star/sdbc/XRowSetListener.hpp>
58 : #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
59 : #include <com/sun/star/sdbcx/Privilege.hpp>
60 : #include <com/sun/star/sdbcx/XRowLocate.hpp>
61 : #include <com/sun/star/task/InteractionHandler.hpp>
62 : #include <com/sun/star/uno/TypeClass.hpp>
63 : #include <com/sun/star/util/NumberFormatter.hpp>
64 : #include <com/sun/star/util/XCancellable.hpp>
65 :
66 : #include <comphelper/enumhelper.hxx>
67 : #include <comphelper/extract.hxx>
68 : #include <comphelper/interaction.hxx>
69 : #include <comphelper/processfactory.hxx>
70 : #include <comphelper/sequence.hxx>
71 : #include <comphelper/string.hxx>
72 : #include <connectivity/dbexception.hxx>
73 : #include <connectivity/dbtools.hxx>
74 : #include <connectivity/sqlerror.hxx>
75 : #include <cppuhelper/exc_hlp.hxx>
76 : #include <cppuhelper/implbase2.hxx>
77 : #include <cppuhelper/typeprovider.hxx>
78 : #include <osl/mutex.hxx>
79 : #include <sfx2/app.hxx>
80 : #include <sfx2/sfx.hrc>
81 : #include <svx/fmsearch.hxx>
82 : #include <svx/svxdlg.hxx>
83 : #include <tools/diagnose_ex.h>
84 : #include <osl/diagnose.h>
85 : #include <vcl/layout.hxx>
86 : #include <vcl/waitobj.hxx>
87 :
88 : using namespace ::com::sun::star;
89 : using namespace ::com::sun::star::uno;
90 : using namespace ::com::sun::star::awt;
91 : using namespace ::com::sun::star::sdb;
92 : using namespace ::com::sun::star::sdbc;
93 : using namespace ::com::sun::star::sdbcx;
94 : using namespace ::com::sun::star::task;
95 : using namespace ::com::sun::star::beans;
96 : using namespace ::com::sun::star::frame;
97 : using namespace ::com::sun::star::form::runtime;
98 : using namespace ::com::sun::star::form;
99 : using namespace ::com::sun::star::util;
100 : using namespace ::com::sun::star::lang;
101 : using namespace ::com::sun::star::container;
102 : using namespace ::dbtools;
103 : using namespace ::comphelper;
104 : using namespace ::svt;
105 :
106 : #define HANDLE_SQL_ERRORS( action, successflag, context, message ) \
107 : try \
108 : { \
109 : successflag = false; \
110 : action; \
111 : successflag = true; \
112 : } \
113 : catch(SQLException& e) \
114 : { \
115 : SQLException aError = ::dbtools::prependErrorInfo(e, *this, context); \
116 : ::com::sun::star::sdb::SQLErrorEvent aEvent; \
117 : aEvent.Reason <<= aError; \
118 : errorOccured(aEvent); \
119 : } \
120 : catch(Exception&) \
121 : { \
122 : DBG_UNHANDLED_EXCEPTION(); \
123 : } \
124 :
125 : #define DO_SAFE( action, message ) try { action; } catch(Exception&) { SAL_WARN("dbaccess.ui",message); } ;
126 :
127 : namespace dbaui
128 : {
129 :
130 : // OParameterContinuation
131 0 : class OParameterContinuation : public OInteraction< XInteractionSupplyParameters >
132 : {
133 : Sequence< PropertyValue > m_aValues;
134 :
135 : public:
136 0 : OParameterContinuation() { }
137 :
138 0 : Sequence< PropertyValue > getValues() const { return m_aValues; }
139 :
140 : // XInteractionSupplyParameters
141 : virtual void SAL_CALL setParameters( const Sequence< PropertyValue >& _rValues ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
142 : };
143 :
144 0 : void SAL_CALL OParameterContinuation::setParameters( const Sequence< PropertyValue >& _rValues ) throw(RuntimeException, std::exception)
145 : {
146 0 : m_aValues = _rValues;
147 0 : }
148 :
149 : // a helper class implementing a runtime::XFormController, will be aggregated by SbaXDataBrowserController
150 : // (we can't derive from XFormController as it's base class is XTabController and the XTabController::getModel collides
151 : // with the XController::getModel implemented in our base class SbaXDataBrowserController)
152 : class SbaXDataBrowserController::FormControllerImpl
153 : : public ::cppu::WeakAggImplHelper2< ::com::sun::star::form::runtime::XFormController,
154 : ::com::sun::star::frame::XFrameActionListener >
155 : {
156 : friend class SbaXDataBrowserController;
157 : ::cppu::OInterfaceContainerHelper m_aActivateListeners;
158 : SbaXDataBrowserController* m_pOwner;
159 :
160 : public:
161 : FormControllerImpl(SbaXDataBrowserController* pOwner);
162 :
163 : // XFormController
164 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations > SAL_CALL getFormOperations() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
165 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > SAL_CALL getCurrentControl() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
166 : virtual void SAL_CALL addActivateListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
167 : virtual void SAL_CALL removeActivateListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
168 : virtual void SAL_CALL addChildController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _ChildController ) throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
169 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormControllerContext > SAL_CALL getContext() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
170 : virtual void SAL_CALL setContext( const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormControllerContext >& _context ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
171 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > SAL_CALL getInteractionHandler() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
172 : virtual void SAL_CALL setInteractionHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _interactionHandler ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
173 :
174 : // XChild, base of XFormController
175 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
176 : virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Parent ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
177 :
178 : // XComponent, base of XFormController
179 : virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
180 : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
181 : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
182 :
183 : // XIndexAccess, base of XFormController
184 : virtual ::sal_Int32 SAL_CALL getCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
185 : virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
186 :
187 : // XElementAccess, base of XIndexAccess
188 : virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
189 : virtual sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
190 :
191 : // XEnumerationAccess, base of XElementAccess
192 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
193 :
194 : // XModifyBroadcaster, base of XFormController
195 : virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
196 : virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
197 :
198 : // XConfirmDeleteBroadcaster, base of XFormController
199 : virtual void SAL_CALL addConfirmDeleteListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XConfirmDeleteListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
200 : virtual void SAL_CALL removeConfirmDeleteListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XConfirmDeleteListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
201 :
202 : // XSQLErrorBroadcaster, base of XFormController
203 : virtual void SAL_CALL addSQLErrorListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLErrorListener >& Listener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
204 : virtual void SAL_CALL removeSQLErrorListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLErrorListener >& Listener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
205 :
206 : // XRowSetApproveBroadcaster, base of XFormController
207 : virtual void SAL_CALL addRowSetApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XRowSetApproveListener >& listener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
208 : virtual void SAL_CALL removeRowSetApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XRowSetApproveListener >& listener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
209 :
210 : // XDatabaseParameterBroadcaster2, base of XFormController
211 : virtual void SAL_CALL addDatabaseParameterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XDatabaseParameterListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
212 : virtual void SAL_CALL removeDatabaseParameterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XDatabaseParameterListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
213 :
214 : // XDatabaseParameterBroadcaster, base of XDatabaseParameterBroadcaster2
215 : virtual void SAL_CALL addParameterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XDatabaseParameterListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
216 : virtual void SAL_CALL removeParameterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XDatabaseParameterListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
217 :
218 : // XModeSelector, base of XFormController
219 : virtual void SAL_CALL setMode( const OUString& aMode ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
220 : virtual OUString SAL_CALL getMode( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
221 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedModes( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
222 : virtual sal_Bool SAL_CALL supportsMode( const OUString& aMode ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
223 :
224 : // XTabController, base of XFormController
225 : virtual void SAL_CALL setModel(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabControllerModel > & Model) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
226 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabControllerModel > SAL_CALL getModel() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
227 : virtual void SAL_CALL setContainer(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > & _Container) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
228 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > SAL_CALL getContainer() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
229 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > > SAL_CALL getControls() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
230 : virtual void SAL_CALL autoTabOrder() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
231 : virtual void SAL_CALL activateTabOrder() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
232 : virtual void SAL_CALL activateFirst() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
233 : virtual void SAL_CALL activateLast() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
234 :
235 : // XFrameActionListener
236 : virtual void SAL_CALL frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
237 :
238 : // XEventListener
239 : virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
240 :
241 : protected:
242 : virtual ~FormControllerImpl();
243 : };
244 :
245 2 : SbaXDataBrowserController::FormControllerImpl::FormControllerImpl(SbaXDataBrowserController* _pOwner)
246 2 : :m_aActivateListeners(_pOwner->getMutex())
247 4 : ,m_pOwner(_pOwner)
248 : {
249 :
250 : OSL_ENSURE(m_pOwner, "SbaXDataBrowserController::FormControllerImpl::FormControllerImpl : invalid Owner !");
251 2 : }
252 :
253 4 : SbaXDataBrowserController::FormControllerImpl::~FormControllerImpl()
254 : {
255 :
256 4 : }
257 :
258 0 : Reference< runtime::XFormOperations > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getFormOperations() throw (RuntimeException, std::exception)
259 : {
260 0 : return FormOperations::createWithFormController( m_pOwner->m_xContext, this );
261 : }
262 :
263 0 : Reference< ::com::sun::star::awt::XControl > SbaXDataBrowserController::FormControllerImpl::getCurrentControl() throw( RuntimeException, std::exception )
264 : {
265 0 : return m_pOwner->getBrowserView() ? m_pOwner->getBrowserView()->getGridControl() : Reference< ::com::sun::star::awt::XControl > ();
266 : }
267 :
268 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addActivateListener(const Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( RuntimeException, std::exception )
269 : {
270 0 : m_aActivateListeners.addInterface(l);
271 0 : }
272 :
273 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeActivateListener(const Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( RuntimeException, std::exception )
274 : {
275 0 : m_aActivateListeners.removeInterface(l);
276 0 : }
277 :
278 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addChildController( const Reference< runtime::XFormController >& /*_ChildController*/ ) throw( RuntimeException, IllegalArgumentException, std::exception )
279 : {
280 : // not supported
281 0 : throw IllegalArgumentException( OUString(), *this, 1 );
282 : }
283 :
284 0 : Reference< runtime::XFormControllerContext > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getContext() throw (RuntimeException, std::exception)
285 : {
286 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::getContext: no support!!" );
287 0 : return NULL;
288 : }
289 :
290 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setContext( const Reference< runtime::XFormControllerContext >& /*_context*/ ) throw (RuntimeException, std::exception)
291 : {
292 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::setContext: no support!!" );
293 0 : }
294 :
295 0 : Reference< XInteractionHandler > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getInteractionHandler() throw (RuntimeException, std::exception)
296 : {
297 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::getInteractionHandler: no support!!" );
298 0 : return NULL;
299 : }
300 :
301 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setInteractionHandler( const Reference< XInteractionHandler >& /*_interactionHandler*/ ) throw (RuntimeException, std::exception)
302 : {
303 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::setInteractionHandler: no support!!" );
304 0 : }
305 :
306 0 : Reference< XInterface > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getParent( ) throw (RuntimeException, std::exception)
307 : {
308 : // don't have any parent form controllers
309 0 : return NULL;
310 : }
311 :
312 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setParent( const Reference< XInterface >& /*Parent*/ ) throw (NoSupportException, RuntimeException, std::exception)
313 : {
314 0 : throw NoSupportException( OUString(), *this );
315 : }
316 :
317 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::dispose( ) throw (RuntimeException, std::exception)
318 : {
319 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::dispose: no, you do *not* want to do this!" );
320 0 : }
321 :
322 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addEventListener( const Reference< XEventListener >& /*xListener*/ ) throw (RuntimeException, std::exception)
323 : {
324 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addEventListener: no support!!" );
325 0 : }
326 :
327 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeEventListener( const Reference< XEventListener >& /*aListener*/ ) throw (RuntimeException, std::exception)
328 : {
329 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeEventListener: no support!!" );
330 0 : }
331 :
332 0 : ::sal_Int32 SAL_CALL SbaXDataBrowserController::FormControllerImpl::getCount( ) throw (RuntimeException, std::exception)
333 : {
334 : // no sub controllers, never
335 0 : return 0;
336 : }
337 :
338 0 : Any SAL_CALL SbaXDataBrowserController::FormControllerImpl::getByIndex( ::sal_Int32 /*Index*/ ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
339 : {
340 : // no sub controllers, never
341 0 : throw IndexOutOfBoundsException( OUString(), *this );
342 : }
343 :
344 0 : Type SAL_CALL SbaXDataBrowserController::FormControllerImpl::getElementType( ) throw (RuntimeException, std::exception)
345 : {
346 0 : return ::cppu::UnoType< runtime::XFormController >::get();
347 : }
348 :
349 0 : sal_Bool SAL_CALL SbaXDataBrowserController::FormControllerImpl::hasElements( ) throw (RuntimeException, std::exception)
350 : {
351 : // no sub controllers, never
352 0 : return false;
353 : }
354 :
355 0 : Reference< XEnumeration > SAL_CALL SbaXDataBrowserController::FormControllerImpl::createEnumeration( ) throw (RuntimeException, std::exception)
356 : {
357 0 : return new ::comphelper::OEnumerationByIndex( this );
358 : }
359 :
360 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addModifyListener( const Reference< XModifyListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
361 : {
362 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addModifyListener: no support!" );
363 0 : }
364 :
365 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeModifyListener( const Reference< XModifyListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
366 : {
367 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeModifyListener: no support!" );
368 0 : }
369 :
370 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addConfirmDeleteListener( const Reference< XConfirmDeleteListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
371 : {
372 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addConfirmDeleteListener: no support!" );
373 0 : }
374 :
375 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeConfirmDeleteListener( const Reference< XConfirmDeleteListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
376 : {
377 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeConfirmDeleteListener: no support!" );
378 0 : }
379 :
380 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addSQLErrorListener( const Reference< XSQLErrorListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
381 : {
382 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addSQLErrorListener: no support!" );
383 0 : }
384 :
385 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeSQLErrorListener( const Reference< XSQLErrorListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
386 : {
387 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeSQLErrorListener: no support!" );
388 0 : }
389 :
390 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addRowSetApproveListener( const Reference< XRowSetApproveListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
391 : {
392 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addRowSetApproveListener: no support!" );
393 0 : }
394 :
395 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeRowSetApproveListener( const Reference< XRowSetApproveListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
396 : {
397 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeRowSetApproveListener: no support!" );
398 0 : }
399 :
400 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addDatabaseParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
401 : {
402 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addDatabaseParameterListener: no support!" );
403 0 : }
404 :
405 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeDatabaseParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
406 : {
407 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeDatabaseParameterListener: no support!" );
408 0 : }
409 :
410 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
411 : {
412 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addParameterListener: no support!" );
413 0 : }
414 :
415 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
416 : {
417 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeParameterListener: no support!" );
418 0 : }
419 :
420 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setMode( const OUString& _rMode ) throw (NoSupportException, RuntimeException, std::exception)
421 : {
422 0 : if ( !supportsMode( _rMode ) )
423 0 : throw NoSupportException();
424 0 : }
425 :
426 0 : OUString SAL_CALL SbaXDataBrowserController::FormControllerImpl::getMode( ) throw (RuntimeException, std::exception)
427 : {
428 0 : return OUString( "DataMode" );
429 : }
430 :
431 0 : Sequence< OUString > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getSupportedModes( ) throw (RuntimeException, std::exception)
432 : {
433 0 : Sequence< OUString > aModes(1);
434 0 : aModes[1] = "DataMode";
435 0 : return aModes;
436 : }
437 :
438 0 : sal_Bool SAL_CALL SbaXDataBrowserController::FormControllerImpl::supportsMode( const OUString& aMode ) throw (RuntimeException, std::exception)
439 : {
440 0 : return aMode == "DataMode";
441 : }
442 :
443 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setModel(const Reference< ::com::sun::star::awt::XTabControllerModel > & /*Model*/) throw( RuntimeException, std::exception )
444 : {
445 : SAL_WARN("dbaccess.ui","SbaXDataBrowserController::FormControllerImpl::setModel : invalid call, can't change my model !");
446 0 : }
447 :
448 0 : Reference< ::com::sun::star::awt::XTabControllerModel > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getModel() throw( RuntimeException, std::exception )
449 : {
450 0 : return Reference< XTabControllerModel >(m_pOwner->getRowSet(), UNO_QUERY);
451 : }
452 :
453 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setContainer(const Reference< ::com::sun::star::awt::XControlContainer > & /*_Container*/) throw( RuntimeException, std::exception )
454 : {
455 : SAL_WARN("dbaccess.ui","SbaXDataBrowserController::FormControllerImpl::setContainer : invalid call, can't change my container !");
456 0 : }
457 :
458 0 : Reference< ::com::sun::star::awt::XControlContainer > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getContainer() throw( RuntimeException, std::exception )
459 : {
460 0 : if (m_pOwner->getBrowserView())
461 0 : return m_pOwner->getBrowserView()->getContainer();
462 0 : return Reference< ::com::sun::star::awt::XControlContainer > ();
463 : }
464 :
465 0 : Sequence< Reference< ::com::sun::star::awt::XControl > > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getControls() throw( RuntimeException, std::exception )
466 : {
467 0 : if (m_pOwner->getBrowserView())
468 : {
469 0 : Reference< ::com::sun::star::awt::XControl > xGrid = m_pOwner->getBrowserView()->getGridControl();
470 0 : return Sequence< Reference< ::com::sun::star::awt::XControl > >(&xGrid, 1);
471 : }
472 0 : return Sequence< Reference< ::com::sun::star::awt::XControl > >();
473 : }
474 :
475 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::autoTabOrder() throw( RuntimeException, std::exception )
476 : {
477 : SAL_WARN("dbaccess.ui","SbaXDataBrowserController::FormControllerImpl::autoTabOrder : nothing to do (always have only one control) !");
478 0 : }
479 :
480 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::activateTabOrder() throw( RuntimeException, std::exception )
481 : {
482 : SAL_WARN("dbaccess.ui","SbaXDataBrowserController::FormControllerImpl::activateTabOrder : nothing to do (always have only one control) !");
483 0 : }
484 :
485 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::activateFirst() throw( RuntimeException, std::exception )
486 : {
487 0 : if (m_pOwner->getBrowserView())
488 0 : m_pOwner->getBrowserView()->getVclControl()->ActivateCell();
489 0 : }
490 :
491 0 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::activateLast() throw( RuntimeException, std::exception )
492 : {
493 0 : if (m_pOwner->getBrowserView())
494 0 : m_pOwner->getBrowserView()->getVclControl()->ActivateCell();
495 0 : }
496 :
497 1 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::frameAction(const ::com::sun::star::frame::FrameActionEvent& /*aEvent*/) throw( RuntimeException, std::exception )
498 : {
499 1 : }
500 :
501 1 : void SAL_CALL SbaXDataBrowserController::FormControllerImpl::disposing(const ::com::sun::star::lang::EventObject& /*Source*/) throw( RuntimeException, std::exception )
502 : {
503 : // nothing to do
504 : // we don't add ourself as listener to any broadcasters, so we are not resposible for removing us
505 1 : }
506 :
507 : // SbaXDataBrowserController
508 0 : Sequence< Type > SAL_CALL SbaXDataBrowserController::getTypes( ) throw (RuntimeException, std::exception)
509 : {
510 : return ::comphelper::concatSequences(
511 : SbaXDataBrowserController_Base::getTypes(),
512 0 : m_pFormControllerImpl->getTypes()
513 0 : );
514 : }
515 :
516 0 : Sequence< sal_Int8 > SAL_CALL SbaXDataBrowserController::getImplementationId( ) throw (RuntimeException, std::exception)
517 : {
518 0 : return css::uno::Sequence<sal_Int8>();
519 : }
520 :
521 116 : Any SAL_CALL SbaXDataBrowserController::queryInterface(const Type& _rType) throw (RuntimeException, std::exception)
522 : {
523 : // check for our additional interfaces
524 116 : Any aRet = SbaXDataBrowserController_Base::queryInterface(_rType);
525 :
526 : // check for our aggregate (implementing the XFormController)
527 116 : if (!aRet.hasValue())
528 10 : aRet = m_xFormControllerImpl->queryAggregation(_rType);
529 :
530 : // no more to offer
531 116 : return aRet;
532 : }
533 :
534 2 : SbaXDataBrowserController::SbaXDataBrowserController(const Reference< ::com::sun::star::uno::XComponentContext >& _rM)
535 : :SbaXDataBrowserController_Base(_rM)
536 : ,m_nRowSetPrivileges(0)
537 : ,m_pClipbordNotifier( NULL )
538 : ,m_aAsyncGetCellFocus(LINK(this, SbaXDataBrowserController, OnAsyncGetCellFocus))
539 : ,m_aAsyncDisplayError( LINK( this, SbaXDataBrowserController, OnAsyncDisplayError ) )
540 : ,m_sStateSaveRecord(ModuleRes(RID_STR_SAVE_CURRENT_RECORD))
541 : ,m_sStateUndoRecord(ModuleRes(RID_STR_UNDO_MODIFY_RECORD))
542 : ,m_sModuleIdentifier( OUString( "com.sun.star.sdb.DataSourceBrowser" ) )
543 : ,m_pFormControllerImpl(NULL)
544 : ,m_nFormActionNestingLevel(0)
545 : ,m_bLoadCanceled( false )
546 2 : ,m_bCannotSelectUnfiltered( true )
547 : {
548 : // create the form controller aggregate
549 2 : osl_atomic_increment(&m_refCount);
550 : {
551 2 : m_pFormControllerImpl = new FormControllerImpl(this);
552 2 : m_xFormControllerImpl = m_pFormControllerImpl;
553 2 : m_xFormControllerImpl->setDelegator(*this);
554 : }
555 2 : osl_atomic_decrement(&m_refCount);
556 :
557 2 : m_aInvalidateClipboard.SetTimeoutHdl(LINK(this, SbaXDataBrowserController, OnInvalidateClipboard));
558 2 : m_aInvalidateClipboard.SetTimeout(300);
559 2 : }
560 :
561 4 : SbaXDataBrowserController::~SbaXDataBrowserController()
562 : {
563 : // deleteView();
564 : // release the aggregated form controller
565 2 : if (m_xFormControllerImpl.is())
566 : {
567 2 : Reference< XInterface > xEmpty;
568 2 : m_xFormControllerImpl->setDelegator(xEmpty);
569 : }
570 :
571 2 : }
572 :
573 1 : void SbaXDataBrowserController::startFrameListening( const Reference< XFrame >& _rxFrame )
574 : {
575 1 : SbaXDataBrowserController_Base::startFrameListening( _rxFrame );
576 :
577 1 : Reference< XFrameActionListener > xAggListener;
578 1 : if ( m_xFormControllerImpl.is() )
579 1 : m_xFormControllerImpl->queryAggregation( cppu::UnoType<XFrameActionListener>::get() ) >>= xAggListener;
580 :
581 1 : if ( _rxFrame.is() && xAggListener.is() )
582 1 : _rxFrame->addFrameActionListener( xAggListener );
583 1 : }
584 :
585 3 : void SbaXDataBrowserController::stopFrameListening( const Reference< XFrame >& _rxFrame )
586 : {
587 3 : SbaXDataBrowserController_Base::stopFrameListening( _rxFrame );
588 :
589 3 : Reference< XFrameActionListener > xAggListener;
590 3 : if ( m_xFormControllerImpl.is() )
591 3 : m_xFormControllerImpl->queryAggregation( cppu::UnoType<XFrameActionListener>::get() ) >>= xAggListener;
592 :
593 3 : if ( _rxFrame.is() && xAggListener.is() )
594 1 : _rxFrame->removeFrameActionListener( xAggListener );
595 3 : }
596 :
597 2 : void SbaXDataBrowserController::onStartLoading( const Reference< XLoadable >& _rxLoadable )
598 : {
599 2 : m_bLoadCanceled = false;
600 2 : m_bCannotSelectUnfiltered = false;
601 :
602 2 : Reference< XWarningsSupplier > xWarnings( _rxLoadable, UNO_QUERY );
603 2 : if ( xWarnings.is() )
604 : {
605 : try
606 : {
607 2 : xWarnings->clearWarnings();
608 : }
609 0 : catch(const SQLException& )
610 : {
611 : DBG_UNHANDLED_EXCEPTION();
612 : }
613 2 : }
614 2 : }
615 :
616 0 : void SbaXDataBrowserController::impl_checkForCannotSelectUnfiltered( const SQLExceptionInfo& _rError )
617 : {
618 0 : ::connectivity::SQLError aError( getORB() );
619 0 : ::connectivity::ErrorCode nErrorCode( connectivity::SQLError::getErrorCode( sdb::ErrorCondition::DATA_CANNOT_SELECT_UNFILTERED ) );
620 0 : if ( static_cast<const SQLException*>(_rError)->ErrorCode == nErrorCode )
621 : {
622 0 : m_bCannotSelectUnfiltered = true;
623 0 : InvalidateFeature( ID_BROWSER_FILTERCRIT );
624 0 : }
625 0 : }
626 :
627 2 : bool SbaXDataBrowserController::reloadForm( const Reference< XLoadable >& _rxLoadable )
628 : {
629 2 : WaitObject aWO(getBrowserView());
630 :
631 2 : onStartLoading( _rxLoadable );
632 :
633 4 : FormErrorHelper aReportError(this);
634 2 : if (_rxLoadable->isLoaded())
635 0 : _rxLoadable->reload();
636 : else
637 2 : _rxLoadable->load();
638 :
639 2 : m_xParser.clear();
640 4 : const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
641 2 : if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)))
642 2 : xFormSet->getPropertyValue(PROPERTY_SINGLESELECTQUERYCOMPOSER) >>= m_xParser;
643 : #if 0
644 : {
645 : const Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY );
646 : const Reference< XSingleSelectQueryAnalyzer > xAnalyzer( xRowSetProps->getPropertyValue( PROPERTY_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY );
647 : if ( xAnalyzer.is() )
648 : {
649 : const Reference< XIndexAccess > xOrderColumns( xAnalyzer->getOrderColumns(), UNO_SET_THROW );
650 : const sal_Int32 nOrderColumns( xOrderColumns->getCount() );
651 : for ( sal_Int32 c=0; c<nOrderColumns; ++c )
652 : {
653 : const Reference< XPropertySet > xOrderColumn( xOrderColumns->getByIndex(c), UNO_QUERY_THROW );
654 : OUString sColumnName;
655 : OSL_VERIFY( xOrderColumn->getPropertyValue( PROPERTY_NAME ) >>= sColumnName);
656 : OUString sTableName;
657 : OSL_VERIFY( xOrderColumn->getPropertyValue( PROPERTY_TABLENAME ) >>= sTableName);
658 : (void)sColumnName;
659 : (void)sTableName;
660 : }
661 : }
662 : }
663 : #endif
664 :
665 4 : Reference< XWarningsSupplier > xWarnings( _rxLoadable, UNO_QUERY );
666 2 : if ( xWarnings.is() )
667 : {
668 : try
669 : {
670 2 : SQLExceptionInfo aInfo( xWarnings->getWarnings() );
671 2 : if ( aInfo.isValid() )
672 : {
673 0 : showError( aInfo );
674 0 : impl_checkForCannotSelectUnfiltered( aInfo );
675 2 : }
676 : }
677 0 : catch(const SQLException& )
678 : {
679 : DBG_UNHANDLED_EXCEPTION();
680 : }
681 : }
682 :
683 4 : return _rxLoadable->isLoaded();
684 : }
685 :
686 2 : void SbaXDataBrowserController::initFormatter()
687 : {
688 : // create a formatter working with the connections format supplier
689 2 : Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(::dbtools::getConnection(m_xRowSet), true, getORB()));
690 :
691 2 : if(xSupplier.is())
692 : {
693 : // create a new formatter
694 4 : m_xFormatter = Reference< util::XNumberFormatter > (
695 2 : util::NumberFormatter::create(getORB()), UNO_QUERY_THROW);
696 2 : m_xFormatter->attachNumberFormatsSupplier(xSupplier);
697 : }
698 : else // clear the formatter
699 0 : m_xFormatter = NULL;
700 2 : }
701 :
702 1 : void SbaXDataBrowserController::describeSupportedFeatures()
703 : {
704 1 : SbaXDataBrowserController_Base::describeSupportedFeatures();
705 1 : implDescribeSupportedFeature( ".uno:FormSlots/undoRecord", ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS );
706 1 : implDescribeSupportedFeature( ".uno:FormController/undoRecord", ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS );
707 1 : implDescribeSupportedFeature( ".uno:RecUndo", ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS );
708 1 : implDescribeSupportedFeature( ".uno:FormSlots/saveRecord", ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS );
709 1 : implDescribeSupportedFeature( ".uno:FormController/saveRecord", ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS );
710 1 : implDescribeSupportedFeature( ".uno:RecSave", ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS );
711 1 : implDescribeSupportedFeature( ".uno:Save", ID_BROWSER_SAVERECORD, CommandGroup::DOCUMENT );
712 1 : implDescribeSupportedFeature( ".uno:RecSearch", SID_FM_SEARCH, CommandGroup::CONTROLS );
713 1 : implDescribeSupportedFeature( ".uno:AutoFilter", SID_FM_AUTOFILTER, CommandGroup::CONTROLS );
714 1 : implDescribeSupportedFeature( ".uno:Refresh", SID_FM_REFRESH, CommandGroup::CONTROLS );
715 1 : implDescribeSupportedFeature( ".uno:OrderCrit", SID_FM_ORDERCRIT, CommandGroup::CONTROLS );
716 1 : implDescribeSupportedFeature( ".uno:RemoveFilterSort", SID_FM_REMOVE_FILTER_SORT,CommandGroup::CONTROLS );
717 1 : implDescribeSupportedFeature( ".uno:FormFiltered", SID_FM_FORM_FILTERED, CommandGroup::CONTROLS );
718 1 : implDescribeSupportedFeature( ".uno:FilterCrit", SID_FM_FILTERCRIT, CommandGroup::CONTROLS );
719 1 : implDescribeSupportedFeature( ".uno:Sortup", ID_BROWSER_SORTUP, CommandGroup::CONTROLS );
720 1 : implDescribeSupportedFeature( ".uno:SortDown", ID_BROWSER_SORTDOWN, CommandGroup::CONTROLS );
721 1 : implDescribeSupportedFeature( ".uno:FormSlots/deleteRecord", SID_FM_DELETEROWS, CommandGroup::EDIT );
722 1 : implDescribeSupportedFeature( ".uno:FormSlots/insertRecord", ID_BROWSER_INSERT_ROW, CommandGroup::INSERT );
723 1 : }
724 :
725 1 : bool SbaXDataBrowserController::Construct(vcl::Window* pParent)
726 : {
727 : // create/initialize the form and the grid model
728 1 : m_xRowSet = CreateForm();
729 1 : if (!m_xRowSet.is())
730 0 : return false;
731 :
732 1 : m_xColumnsSupplier.set(m_xRowSet,UNO_QUERY);
733 1 : m_xLoadable.set(m_xRowSet,UNO_QUERY);
734 :
735 1 : Reference< XPropertySet > xFormProperties( m_xRowSet, UNO_QUERY );
736 1 : if ( !InitializeForm( xFormProperties ) )
737 0 : return false;
738 :
739 1 : m_xGridModel = CreateGridModel();
740 1 : if (!m_xGridModel.is())
741 0 : return false;
742 :
743 : // set the formatter if available
744 1 : initFormatter();
745 :
746 : // we want to have a grid with a "flat" border
747 2 : Reference< XPropertySet > xGridSet(m_xGridModel, UNO_QUERY);
748 1 : if ( xGridSet.is() )
749 1 : xGridSet->setPropertyValue(PROPERTY_BORDER, makeAny((sal_Int16)2));
750 :
751 :
752 : // marry them
753 2 : Reference< ::com::sun::star::container::XNameContainer > xNameCont(m_xRowSet, UNO_QUERY);
754 : {
755 1 : OUString sText(ModuleRes(STR_DATASOURCE_GRIDCONTROL_NAME));
756 1 : xNameCont->insertByName(OUString(sText), makeAny(m_xGridModel));
757 : }
758 :
759 : // create the view
760 1 : setView( VclPtr<UnoDataBrowserView>::Create( pParent, *this, getORB() ) );
761 1 : if (!getBrowserView())
762 0 : return false;
763 :
764 : // late construction
765 1 : bool bSuccess = false;
766 : try
767 : {
768 1 : getBrowserView()->Construct(getControlModel());
769 1 : bSuccess = true;
770 : }
771 0 : catch(SQLException&)
772 : {
773 : }
774 0 : catch(Exception&)
775 : {
776 : SAL_WARN("dbaccess.ui","SbaXDataBrowserController::Construct : the construction of UnoDataBrowserView failed !");
777 : }
778 :
779 1 : if (!bSuccess)
780 : {
781 : // deleteView();
782 0 : return false;
783 : }
784 :
785 : // now that we have a view we can create the clipboard listener
786 1 : m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( getView() );
787 1 : m_aSystemClipboard.StartClipboardListening( );
788 :
789 1 : m_pClipbordNotifier = new TransferableClipboardListener( LINK( this, SbaXDataBrowserController, OnClipboardChanged ) );
790 1 : m_pClipbordNotifier->acquire();
791 1 : m_pClipbordNotifier->AddRemoveListener( getView(), true );
792 :
793 : // this call create the toolbox
794 1 : SbaXDataBrowserController_Base::Construct(pParent);
795 :
796 1 : getBrowserView()->Show();
797 :
798 : // set the callbacks for the grid control
799 1 : SbaGridControl* pVclGrid = getBrowserView()->getVclControl();
800 : OSL_ENSURE(pVclGrid, "SbaXDataBrowserController::Construct : have no VCL control !");
801 1 : pVclGrid->SetMasterListener(this);
802 :
803 : // add listeners ...
804 :
805 : // ... to the form model
806 2 : Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
807 1 : if (xFormSet.is())
808 : {
809 1 : xFormSet->addPropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this));
810 1 : xFormSet->addPropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this));
811 1 : xFormSet->addPropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this));
812 1 : xFormSet->addPropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this));
813 1 : xFormSet->addPropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this));
814 1 : xFormSet->addPropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this));
815 1 : xFormSet->addPropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this));
816 1 : xFormSet->addPropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this));
817 : }
818 2 : Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY);
819 1 : if (xFormError.is())
820 1 : xFormError->addSQLErrorListener(static_cast<com::sun::star::sdb::XSQLErrorListener*>(this));
821 :
822 1 : if (m_xLoadable.is())
823 1 : m_xLoadable->addLoadListener(this);
824 :
825 2 : Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(getRowSet(), UNO_QUERY);
826 1 : if (xFormParameter.is())
827 1 : xFormParameter->addParameterListener(static_cast<com::sun::star::form::XDatabaseParameterListener*>(this));
828 :
829 1 : addModelListeners(getControlModel());
830 1 : addControlListeners(getBrowserView()->getGridControl());
831 :
832 : // load the form
833 2 : return LoadForm();
834 : }
835 :
836 1 : bool SbaXDataBrowserController::LoadForm()
837 : {
838 1 : reloadForm( m_xLoadable );
839 1 : return true;
840 : }
841 :
842 31 : void SbaXDataBrowserController::AddColumnListener(const Reference< XPropertySet > & /*xCol*/)
843 : {
844 : // we're not interested in any column properties ...
845 31 : }
846 :
847 31 : void SbaXDataBrowserController::RemoveColumnListener(const Reference< XPropertySet > & /*xCol*/)
848 : {
849 31 : }
850 :
851 1 : Reference< XRowSet > SbaXDataBrowserController::CreateForm()
852 : {
853 : return Reference< XRowSet > (
854 2 : getORB()->getServiceManager()->createInstanceWithContext("com.sun.star.form.component.Form", getORB()),
855 2 : UNO_QUERY);
856 : }
857 :
858 1 : Reference< ::com::sun::star::form::XFormComponent > SbaXDataBrowserController::CreateGridModel()
859 : {
860 : return Reference< ::com::sun::star::form::XFormComponent > (
861 2 : getORB()->getServiceManager()->createInstanceWithContext("com.sun.star.form.component.GridControl", getORB()),
862 2 : UNO_QUERY);
863 : }
864 :
865 1 : void SbaXDataBrowserController::addModelListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
866 : {
867 : // ... all the grid columns
868 1 : addColumnListeners(_xGridControlModel);
869 :
870 : // (we are interested in all columns the grid has (and only in these) so we have to listen to the container, too)
871 1 : Reference< ::com::sun::star::container::XContainer > xColContainer(_xGridControlModel, UNO_QUERY);
872 1 : if (xColContainer.is())
873 1 : xColContainer->addContainerListener(static_cast<com::sun::star::container::XContainerListener*>(this));
874 :
875 2 : Reference< ::com::sun::star::form::XReset > xReset(_xGridControlModel, UNO_QUERY);
876 1 : if (xReset.is())
877 2 : xReset->addResetListener(static_cast<com::sun::star::form::XResetListener*>(this));
878 1 : }
879 :
880 2 : void SbaXDataBrowserController::removeModelListeners(const Reference< XControlModel > & _xGridControlModel)
881 : {
882 : // every single column model
883 2 : Reference< XIndexContainer > xColumns(_xGridControlModel, UNO_QUERY);
884 2 : if (xColumns.is())
885 : {
886 1 : sal_Int32 nCount = xColumns->getCount();
887 32 : for (sal_Int32 i=0; i < nCount; ++i)
888 : {
889 31 : Reference< XPropertySet > xCol(xColumns->getByIndex(i),UNO_QUERY);
890 31 : RemoveColumnListener(xCol);
891 31 : }
892 : }
893 :
894 4 : Reference< XContainer > xColContainer(_xGridControlModel, UNO_QUERY);
895 2 : if (xColContainer.is())
896 1 : xColContainer->removeContainerListener( this );
897 :
898 4 : Reference< XReset > xReset(_xGridControlModel, UNO_QUERY);
899 2 : if (xReset.is())
900 3 : xReset->removeResetListener( this );
901 2 : }
902 :
903 1 : void SbaXDataBrowserController::addControlListeners(const Reference< ::com::sun::star::awt::XControl > & _xGridControl)
904 : {
905 : // to ge the 'modified' for the current cell
906 1 : Reference< XModifyBroadcaster > xBroadcaster(getBrowserView()->getGridControl(), UNO_QUERY);
907 1 : if (xBroadcaster.is())
908 1 : xBroadcaster->addModifyListener(static_cast<XModifyListener*>(this));
909 :
910 : // introduce ourself as dispatch provider for the grid
911 2 : Reference< XDispatchProviderInterception > xInterception(getBrowserView()->getGridControl(), UNO_QUERY);
912 1 : if (xInterception.is())
913 1 : xInterception->registerDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
914 :
915 : // add as focus listener to the control (needed for the form controller functionality)
916 2 : Reference< XWindow > xWindow(_xGridControl, UNO_QUERY);
917 1 : if (xWindow.is())
918 2 : xWindow->addFocusListener(this);
919 1 : }
920 :
921 1 : void SbaXDataBrowserController::removeControlListeners(const Reference< ::com::sun::star::awt::XControl > & _xGridControl)
922 : {
923 1 : Reference< XModifyBroadcaster > xBroadcaster(_xGridControl, UNO_QUERY);
924 1 : if (xBroadcaster.is())
925 1 : xBroadcaster->removeModifyListener(static_cast<XModifyListener*>(this));
926 :
927 2 : Reference< XDispatchProviderInterception > xInterception(_xGridControl, UNO_QUERY);
928 1 : if (xInterception.is())
929 1 : xInterception->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
930 :
931 2 : Reference< XWindow > xWindow(_xGridControl, UNO_QUERY);
932 1 : if (xWindow.is())
933 2 : xWindow->removeFocusListener(this);
934 1 : }
935 :
936 0 : void SAL_CALL SbaXDataBrowserController::focusGained(const FocusEvent& /*e*/) throw( RuntimeException, std::exception )
937 : {
938 : // notify our activate listeners (registered on the form controller aggregate)
939 0 : EventObject aEvt(*this);
940 0 : ::cppu::OInterfaceIteratorHelper aIter(m_pFormControllerImpl->m_aActivateListeners);
941 0 : while (aIter.hasMoreElements())
942 0 : static_cast<XFormControllerListener*>(aIter.next())->formActivated(aEvt);
943 0 : }
944 :
945 0 : void SAL_CALL SbaXDataBrowserController::focusLost(const FocusEvent& e) throw( RuntimeException, std::exception )
946 : {
947 : // some general checks
948 0 : if (!getBrowserView() || !getBrowserView()->getGridControl().is())
949 0 : return;
950 0 : Reference< XVclWindowPeer > xMyGridPeer(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY);
951 0 : if (!xMyGridPeer.is())
952 0 : return;
953 0 : Reference< XWindowPeer > xNextControlPeer(e.NextFocus, UNO_QUERY);
954 0 : if (!xNextControlPeer.is())
955 0 : return;
956 :
957 : // don't do a notification if it remains in the family (i.e. a child of the grid control gets the focus)
958 0 : if (xMyGridPeer->isChild(xNextControlPeer))
959 0 : return;
960 :
961 0 : if (xMyGridPeer == xNextControlPeer)
962 0 : return;
963 :
964 : // notify the listeners that the "form" we represent has been deactivated
965 0 : EventObject aEvt(*this);
966 0 : ::cppu::OInterfaceIteratorHelper aIter(m_pFormControllerImpl->m_aActivateListeners);
967 0 : while (aIter.hasMoreElements())
968 0 : static_cast<XFormControllerListener*>(aIter.next())->formDeactivated(aEvt);
969 :
970 : // commit the changes of the grid control (as we're deactivated)
971 0 : Reference< XBoundComponent > xCommitable(getBrowserView()->getGridControl(), UNO_QUERY);
972 0 : if (xCommitable.is())
973 0 : xCommitable->commit();
974 : else
975 0 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::focusLost : why is my control not commitable ?");
976 : }
977 :
978 0 : void SbaXDataBrowserController::disposingGridControl(const ::com::sun::star::lang::EventObject& /*Source*/)
979 : {
980 0 : removeControlListeners(getBrowserView()->getGridControl());
981 0 : }
982 :
983 0 : void SbaXDataBrowserController::disposingGridModel(const ::com::sun::star::lang::EventObject& /*Source*/)
984 : {
985 0 : removeModelListeners(getControlModel());
986 0 : }
987 :
988 0 : void SbaXDataBrowserController::disposingFormModel(const ::com::sun::star::lang::EventObject& Source)
989 : {
990 0 : Reference< XPropertySet > xSourceSet(Source.Source, UNO_QUERY);
991 0 : if (xSourceSet.is())
992 : {
993 0 : xSourceSet->removePropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this));
994 0 : xSourceSet->removePropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this));
995 0 : xSourceSet->removePropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this));
996 0 : xSourceSet->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this));
997 0 : xSourceSet->removePropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this));
998 0 : xSourceSet->removePropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this));
999 0 : xSourceSet->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this));
1000 0 : xSourceSet->removePropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this));
1001 : }
1002 :
1003 0 : Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(Source.Source, UNO_QUERY);
1004 0 : if (xFormError.is())
1005 0 : xFormError->removeSQLErrorListener(static_cast<com::sun::star::sdb::XSQLErrorListener*>(this));
1006 :
1007 0 : if (m_xLoadable.is())
1008 0 : m_xLoadable->removeLoadListener(this);
1009 :
1010 0 : Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(Source.Source, UNO_QUERY);
1011 0 : if (xFormParameter.is())
1012 0 : xFormParameter->removeParameterListener(static_cast<com::sun::star::form::XDatabaseParameterListener*>(this));
1013 0 : }
1014 :
1015 0 : void SbaXDataBrowserController::disposingColumnModel(const ::com::sun::star::lang::EventObject& Source)
1016 : {
1017 0 : RemoveColumnListener(Reference< XPropertySet > (Source.Source, UNO_QUERY));
1018 0 : }
1019 :
1020 1 : void SbaXDataBrowserController::disposing(const EventObject& Source) throw( RuntimeException, std::exception )
1021 : {
1022 : // if it's a component other than our aggregate, forward it to the aggregate
1023 1 : if ( m_xFormControllerImpl != Source.Source )
1024 : {
1025 1 : Reference< XEventListener > xAggListener;
1026 1 : m_xFormControllerImpl->queryAggregation( cppu::UnoType<decltype(xAggListener)>::get() ) >>= xAggListener;
1027 1 : if ( xAggListener.is( ))
1028 1 : xAggListener->disposing( Source );
1029 : }
1030 :
1031 : // is it the grid control ?
1032 1 : if (getBrowserView())
1033 : {
1034 1 : Reference< ::com::sun::star::awt::XControl > xSourceControl(Source.Source, UNO_QUERY);
1035 1 : if (xSourceControl == getBrowserView()->getGridControl())
1036 0 : disposingGridControl(Source);
1037 : }
1038 :
1039 : // its model (the container of the columns) ?
1040 1 : if (getControlModel() == Source.Source)
1041 0 : disposingGridModel(Source);
1042 :
1043 : // the form's model ?
1044 1 : if ((getRowSet() == Source.Source))
1045 0 : disposingFormModel(Source);
1046 :
1047 : // from a single column model ?
1048 1 : Reference< XPropertySet > xSourceSet(Source.Source, UNO_QUERY);
1049 1 : if (xSourceSet.is())
1050 : {
1051 0 : Reference< XPropertySetInfo > xInfo = xSourceSet->getPropertySetInfo();
1052 : // we assume that columns have a Width property and all other sets we are listening to don't have
1053 0 : if (xInfo->hasPropertyByName(PROPERTY_WIDTH))
1054 0 : disposingColumnModel(Source);
1055 : }
1056 1 : SbaXDataBrowserController_Base::OGenericUnoController::disposing( Source );
1057 1 : }
1058 :
1059 0 : void SAL_CALL SbaXDataBrowserController::setIdentifier( const OUString& _Identifier ) throw (RuntimeException, std::exception)
1060 : {
1061 0 : ::osl::MutexGuard aGuard( getMutex() );
1062 0 : m_sModuleIdentifier = _Identifier;
1063 0 : }
1064 :
1065 8 : OUString SAL_CALL SbaXDataBrowserController::getIdentifier( ) throw (RuntimeException, std::exception)
1066 : {
1067 8 : ::osl::MutexGuard aGuard( getMutex() );
1068 8 : return m_sModuleIdentifier;
1069 : }
1070 :
1071 4 : void SbaXDataBrowserController::propertyChange(const PropertyChangeEvent& evt) throw ( RuntimeException, std::exception )
1072 : {
1073 4 : Reference< XPropertySet > xSource(evt.Source, UNO_QUERY);
1074 4 : if (!xSource.is())
1075 4 : return;
1076 :
1077 8 : SolarMutexGuard aGuard;
1078 : // the IsModified changed to sal_False ?
1079 8 : if ( evt.PropertyName == PROPERTY_ISMODIFIED
1080 4 : && !::comphelper::getBOOL(evt.NewValue)
1081 : )
1082 : { // -> the current field isn't modified anymore, too
1083 0 : setCurrentModified( false );
1084 : }
1085 :
1086 : // switching to a new record ?
1087 8 : if ( evt.PropertyName == PROPERTY_ISNEW
1088 4 : && ::comphelper::getBOOL(evt.NewValue)
1089 : )
1090 : {
1091 0 : if (::comphelper::getINT32(xSource->getPropertyValue(PROPERTY_ROWCOUNT)) == 0)
1092 : // if we're switching to a new record and didn't have any records before we need to invalidate
1093 : // all slots (as the cursor was invalid before the mode change and so the slots were disabled)
1094 0 : InvalidateAll();
1095 : }
1096 :
1097 4 : if (evt.PropertyName == PROPERTY_FILTER)
1098 : {
1099 0 : InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1100 : }
1101 4 : else if (evt.PropertyName == PROPERTY_HAVING_CLAUSE)
1102 : {
1103 0 : InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1104 : }
1105 4 : else if (evt.PropertyName == PROPERTY_ORDER)
1106 : {
1107 1 : InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1108 : }
1109 :
1110 : // a new record count ? -> may be our search availability has changed
1111 4 : if (evt.PropertyName == PROPERTY_ROWCOUNT)
1112 : {
1113 1 : sal_Int32 nNewValue = 0, nOldValue = 0;
1114 1 : evt.NewValue >>= nNewValue;
1115 1 : evt.OldValue >>= nOldValue;
1116 1 : if((nOldValue == 0 && nNewValue != 0) || (nOldValue != 0 && nNewValue == 0))
1117 1 : InvalidateAll();
1118 4 : }
1119 : }
1120 :
1121 0 : void SbaXDataBrowserController::modified(const ::com::sun::star::lang::EventObject& /*aEvent*/) throw( RuntimeException, std::exception )
1122 : {
1123 0 : setCurrentModified( true );
1124 0 : }
1125 :
1126 31 : void SbaXDataBrowserController::elementInserted(const ::com::sun::star::container::ContainerEvent& evt) throw( RuntimeException, std::exception )
1127 : {
1128 : OSL_ENSURE(Reference< XInterface >(evt.Source, UNO_QUERY).get() == Reference< XInterface >(getControlModel(), UNO_QUERY).get(),
1129 : "SbaXDataBrowserController::elementInserted: where did this come from (not from the grid model)?!");
1130 31 : Reference< XPropertySet > xNewColumn(evt.Element,UNO_QUERY);
1131 31 : if ( xNewColumn.is() )
1132 31 : AddColumnListener(xNewColumn);
1133 31 : }
1134 :
1135 0 : void SbaXDataBrowserController::elementRemoved(const ::com::sun::star::container::ContainerEvent& evt) throw( RuntimeException, std::exception )
1136 : {
1137 : OSL_ENSURE(Reference< XInterface >(evt.Source, UNO_QUERY).get() == Reference< XInterface >(getControlModel(), UNO_QUERY).get(),
1138 : "SbaXDataBrowserController::elementRemoved: where did this come from (not from the grid model)?!");
1139 0 : Reference< XPropertySet > xOldColumn(evt.Element,UNO_QUERY);
1140 0 : if ( xOldColumn.is() )
1141 0 : RemoveColumnListener(xOldColumn);
1142 0 : }
1143 :
1144 0 : void SbaXDataBrowserController::elementReplaced(const ::com::sun::star::container::ContainerEvent& evt) throw( RuntimeException, std::exception )
1145 : {
1146 : OSL_ENSURE(Reference< XInterface >(evt.Source, UNO_QUERY).get() == Reference< XInterface >(getControlModel(), UNO_QUERY).get(),
1147 : "SbaXDataBrowserController::elementReplaced: where did this come from (not from the grid model)?!");
1148 0 : Reference< XPropertySet > xOldColumn(evt.ReplacedElement,UNO_QUERY);
1149 0 : if ( xOldColumn.is() )
1150 0 : RemoveColumnListener(xOldColumn);
1151 :
1152 0 : Reference< XPropertySet > xNewColumn(evt.Element,UNO_QUERY);
1153 0 : if ( xNewColumn.is() )
1154 0 : AddColumnListener(xNewColumn);
1155 0 : }
1156 :
1157 0 : sal_Bool SbaXDataBrowserController::suspend(sal_Bool /*bSuspend*/) throw( RuntimeException, std::exception )
1158 : {
1159 0 : m_aAsyncGetCellFocus.CancelCall();
1160 0 : m_aAsyncDisplayError.CancelCall();
1161 0 : m_aAsyncInvalidateAll.CancelCall();
1162 :
1163 0 : bool bSuccess = SaveModified();
1164 0 : return bSuccess;
1165 : }
1166 :
1167 2 : void SbaXDataBrowserController::disposing()
1168 : {
1169 : // the base class
1170 2 : SbaXDataBrowserController_Base::OGenericUnoController::disposing();
1171 :
1172 : // the data source
1173 2 : Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1174 2 : if (xFormSet.is())
1175 : {
1176 1 : xFormSet->removePropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this));
1177 1 : xFormSet->removePropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this));
1178 1 : xFormSet->removePropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this));
1179 1 : xFormSet->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this));
1180 1 : xFormSet->removePropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this));
1181 1 : xFormSet->removePropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this));
1182 1 : xFormSet->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this));
1183 1 : xFormSet->removePropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this));
1184 : }
1185 :
1186 4 : Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY);
1187 2 : if (xFormError.is())
1188 1 : xFormError->removeSQLErrorListener(static_cast<com::sun::star::sdb::XSQLErrorListener*>(this));
1189 :
1190 2 : if (m_xLoadable.is())
1191 1 : m_xLoadable->removeLoadListener(this);
1192 :
1193 4 : Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(getRowSet(), UNO_QUERY);
1194 2 : if (xFormParameter.is())
1195 1 : xFormParameter->removeParameterListener(static_cast<com::sun::star::form::XDatabaseParameterListener*>(this));
1196 :
1197 2 : removeModelListeners(getControlModel());
1198 :
1199 2 : if ( getView() && m_pClipbordNotifier )
1200 : {
1201 1 : m_pClipbordNotifier->ClearCallbackLink();
1202 1 : m_pClipbordNotifier->AddRemoveListener( getView(), false );
1203 1 : m_pClipbordNotifier->release();
1204 1 : m_pClipbordNotifier = NULL;
1205 : }
1206 :
1207 2 : if (getBrowserView())
1208 : {
1209 1 : removeControlListeners(getBrowserView()->getGridControl());
1210 : // don't delete explicitly, this is done by the owner (and user) of this controller (me hopes ...)
1211 1 : clearView();
1212 : }
1213 :
1214 2 : if(m_aInvalidateClipboard.IsActive())
1215 1 : m_aInvalidateClipboard.Stop();
1216 :
1217 : // dispose the row set
1218 : try
1219 : {
1220 2 : ::comphelper::disposeComponent(m_xRowSet);
1221 :
1222 2 : m_xRowSet = NULL;
1223 2 : m_xColumnsSupplier = NULL;
1224 2 : m_xLoadable = NULL;
1225 : }
1226 0 : catch(Exception&)
1227 : {
1228 : DBG_UNHANDLED_EXCEPTION();
1229 : }
1230 4 : m_xParser.clear();
1231 : // don't dispose, just reset - it's owned by the RowSet
1232 2 : }
1233 :
1234 1 : void SbaXDataBrowserController::frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( RuntimeException, std::exception )
1235 : {
1236 1 : ::osl::MutexGuard aGuard( getMutex() );
1237 :
1238 1 : SbaXDataBrowserController_Base::frameAction( aEvent );
1239 :
1240 1 : if ( aEvent.Source == getFrame() )
1241 1 : switch ( aEvent.Action )
1242 : {
1243 : case FrameAction_FRAME_ACTIVATED:
1244 : case FrameAction_FRAME_UI_ACTIVATED:
1245 : // ensure that the active cell (if any) has the focus
1246 0 : m_aAsyncGetCellFocus.Call();
1247 : // start the clipboard timer
1248 0 : if (getBrowserView() && getBrowserView()->getVclControl() && !m_aInvalidateClipboard.IsActive())
1249 : {
1250 0 : m_aInvalidateClipboard.Start();
1251 0 : OnInvalidateClipboard( NULL );
1252 : }
1253 0 : break;
1254 : case FrameAction_FRAME_DEACTIVATING:
1255 : case FrameAction_FRAME_UI_DEACTIVATING:
1256 : // stop the clipboard invalidator
1257 0 : if (getBrowserView() && getBrowserView()->getVclControl() && m_aInvalidateClipboard.IsActive())
1258 : {
1259 0 : m_aInvalidateClipboard.Stop();
1260 0 : OnInvalidateClipboard( NULL );
1261 : }
1262 : // remove the "get cell focus"-event
1263 0 : m_aAsyncGetCellFocus.CancelCall();
1264 0 : break;
1265 : default:
1266 1 : break;
1267 1 : }
1268 1 : }
1269 :
1270 0 : IMPL_LINK_NOARG( SbaXDataBrowserController, OnAsyncDisplayError )
1271 : {
1272 0 : if ( m_aCurrentError.isValid() )
1273 : {
1274 0 : ScopedVclPtrInstance< OSQLMessageBox > aDlg( getBrowserView(), m_aCurrentError );
1275 0 : aDlg->Execute();
1276 : }
1277 0 : return 0L;
1278 : }
1279 :
1280 0 : void SbaXDataBrowserController::errorOccured(const ::com::sun::star::sdb::SQLErrorEvent& aEvent) throw( RuntimeException, std::exception )
1281 : {
1282 0 : ::osl::MutexGuard aGuard( getMutex() );
1283 :
1284 0 : SQLExceptionInfo aInfo( aEvent.Reason );
1285 0 : if ( !aInfo.isValid() )
1286 0 : return;
1287 :
1288 0 : if ( m_nFormActionNestingLevel )
1289 : {
1290 : OSL_ENSURE( !m_aCurrentError.isValid(), "SbaXDataBrowserController::errorOccurred: can handle one error per transaction only!" );
1291 0 : m_aCurrentError = aInfo;
1292 : }
1293 : else
1294 : {
1295 0 : m_aCurrentError = aInfo;
1296 0 : m_aAsyncDisplayError.Call();
1297 0 : }
1298 : }
1299 :
1300 0 : sal_Bool SbaXDataBrowserController::approveParameter(const ::com::sun::star::form::DatabaseParameterEvent& aEvent) throw( RuntimeException, std::exception )
1301 : {
1302 0 : if (aEvent.Source != getRowSet())
1303 : {
1304 : // not my data source -> allow anything
1305 : SAL_WARN("dbaccess.ui","SbaXDataBrowserController::approveParameter : invalid event source !");
1306 0 : return sal_True;
1307 : }
1308 :
1309 0 : Reference< ::com::sun::star::container::XIndexAccess > xParameters = aEvent.Parameters;
1310 0 : SolarMutexGuard aSolarGuard;
1311 :
1312 : // default handling: instantiate an interaction handler and let it handle the parameter request
1313 : try
1314 : {
1315 : // two continuations allowed: OK and Cancel
1316 0 : OParameterContinuation* pParamValues = new OParameterContinuation;
1317 0 : OInteractionAbort* pAbort = new OInteractionAbort;
1318 : // the request
1319 0 : ParametersRequest aRequest;
1320 0 : aRequest.Parameters = xParameters;
1321 0 : aRequest.Connection = getConnection(Reference< XRowSet >(aEvent.Source, UNO_QUERY));
1322 0 : OInteractionRequest* pParamRequest = new OInteractionRequest(makeAny(aRequest));
1323 0 : Reference< XInteractionRequest > xParamRequest(pParamRequest);
1324 : // some knittings
1325 0 : pParamRequest->addContinuation(pParamValues);
1326 0 : pParamRequest->addContinuation(pAbort);
1327 :
1328 : // create the handler, let it handle the request
1329 0 : Reference< XInteractionHandler2 > xHandler( InteractionHandler::createWithParent(getORB(), 0) );
1330 0 : xHandler->handle(xParamRequest);
1331 :
1332 0 : if (!pParamValues->wasSelected())
1333 : { // canceled
1334 0 : setLoadingCancelled();
1335 0 : return sal_False;
1336 : }
1337 :
1338 : // transfer the values into the parameter supplier
1339 0 : Sequence< PropertyValue > aFinalValues = pParamValues->getValues();
1340 0 : if (aFinalValues.getLength() != aRequest.Parameters->getCount())
1341 : {
1342 : SAL_WARN("dbaccess.ui","SbaXDataBrowserController::approveParameter: the InteractionHandler returned nonsense!");
1343 0 : setLoadingCancelled();
1344 0 : return sal_False;
1345 : }
1346 0 : const PropertyValue* pFinalValues = aFinalValues.getConstArray();
1347 0 : for (sal_Int32 i=0; i<aFinalValues.getLength(); ++i, ++pFinalValues)
1348 : {
1349 : Reference< XPropertySet > xParam(
1350 0 : aRequest.Parameters->getByIndex(i), css::uno::UNO_QUERY);
1351 : OSL_ENSURE(xParam.is(), "SbaXDataBrowserController::approveParameter: one of the parameters is no property set!");
1352 0 : if (xParam.is())
1353 : {
1354 : #ifdef DBG_UTIL
1355 : OUString sName;
1356 : xParam->getPropertyValue(PROPERTY_NAME) >>= sName;
1357 : OSL_ENSURE(sName.equals(pFinalValues->Name), "SbaXDataBrowserController::approveParameter: suspicious value names!");
1358 : #endif
1359 0 : try { xParam->setPropertyValue(PROPERTY_VALUE, pFinalValues->Value); }
1360 0 : catch(Exception&)
1361 : {
1362 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::approveParameter: setting one of the properties failed!");
1363 : }
1364 : }
1365 0 : }
1366 : }
1367 0 : catch( const Exception& )
1368 : {
1369 : DBG_UNHANDLED_EXCEPTION();
1370 : }
1371 :
1372 0 : return sal_True;
1373 : }
1374 :
1375 0 : sal_Bool SbaXDataBrowserController::approveReset(const ::com::sun::star::lang::EventObject& /*rEvent*/) throw( RuntimeException, std::exception )
1376 : {
1377 0 : return sal_True;
1378 : }
1379 :
1380 0 : void SbaXDataBrowserController::resetted(const ::com::sun::star::lang::EventObject& rEvent) throw( RuntimeException, std::exception )
1381 : {
1382 : OSL_ENSURE(rEvent.Source == getControlModel(), "SbaXDataBrowserController::resetted : where did this come from ?");
1383 : (void)rEvent;
1384 0 : setCurrentModified( false );
1385 0 : }
1386 :
1387 0 : sal_Bool SbaXDataBrowserController::confirmDelete(const ::com::sun::star::sdb::RowChangeEvent& /*aEvent*/) throw( RuntimeException, std::exception )
1388 : {
1389 0 : if (ScopedVclPtrInstance<MessageDialog>::Create(getBrowserView(), ModuleRes(STR_QUERY_BRW_DELETE_ROWS), VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO)->Execute() != RET_YES)
1390 0 : return sal_False;
1391 :
1392 0 : return sal_True;
1393 : }
1394 :
1395 120 : FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const
1396 : {
1397 120 : FeatureState aReturn;
1398 : // (disabled automatically)
1399 :
1400 : try
1401 : {
1402 : // no chance without a view
1403 120 : if (!getBrowserView() || !getBrowserView()->getVclControl())
1404 0 : return aReturn;
1405 :
1406 120 : switch (nId)
1407 : {
1408 : case ID_BROWSER_REMOVEFILTER:
1409 8 : if (!m_xParser.is())
1410 : {
1411 2 : aReturn.bEnabled = false;
1412 2 : return aReturn;
1413 : }
1414 : // any filter or sort order set ?
1415 6 : aReturn.bEnabled = m_xParser->getFilter().getLength() || m_xParser->getHavingClause().getLength() || m_xParser->getOrder().getLength();
1416 6 : return aReturn;
1417 : }
1418 : // no chance without valid models
1419 112 : if (isValid() && !isValidCursor())
1420 0 : return aReturn;
1421 :
1422 112 : switch (nId)
1423 : {
1424 : case ID_BROWSER_SEARCH:
1425 : {
1426 3 : Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1427 3 : sal_Int32 nCount = ::comphelper::getINT32(xFormSet->getPropertyValue(PROPERTY_ROWCOUNT));
1428 3 : aReturn.bEnabled = nCount != 0;
1429 : }
1430 3 : break;
1431 : case ID_BROWSER_INSERT_ROW:
1432 : {
1433 : // check if it is available
1434 3 : bool bInsertPrivilege = ( m_nRowSetPrivileges & Privilege::INSERT) != 0;
1435 3 : bool bAllowInsertions = true;
1436 : try
1437 : {
1438 3 : Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
1439 3 : OSL_VERIFY( xRowSetProps->getPropertyValue("AllowInserts") >>= bAllowInsertions );
1440 : }
1441 0 : catch( const Exception& )
1442 : {
1443 : DBG_UNHANDLED_EXCEPTION();
1444 : }
1445 3 : aReturn.bEnabled = bInsertPrivilege && bAllowInsertions;
1446 : }
1447 3 : break;
1448 : case SID_FM_DELETEROWS:
1449 : {
1450 : // check if it is available
1451 3 : bool bDeletePrivilege = ( m_nRowSetPrivileges & Privilege::INSERT) != 0;
1452 3 : bool bAllowDeletions = true;
1453 3 : sal_Int32 nRowCount = 0;
1454 3 : bool bInsertionRow = false;
1455 : try
1456 : {
1457 3 : Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
1458 3 : OSL_VERIFY( xRowSetProps->getPropertyValue("AllowDeletes") >>= bAllowDeletions );
1459 3 : OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ROWCOUNT ) >>= nRowCount );
1460 3 : OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ISNEW ) >>= bInsertionRow );
1461 : }
1462 0 : catch( const Exception& )
1463 : {
1464 : DBG_UNHANDLED_EXCEPTION();
1465 : }
1466 3 : aReturn.bEnabled = bDeletePrivilege && bAllowDeletions && ( nRowCount != 0 ) && !bInsertionRow;
1467 : }
1468 3 : break;
1469 :
1470 : case ID_BROWSER_COPY:
1471 14 : if ( getBrowserView()->getVclControl()->GetSelectRowCount() )
1472 : {
1473 0 : aReturn.bEnabled = m_aCurrentFrame.isActive();
1474 0 : break;
1475 : }
1476 : // run through
1477 : case ID_BROWSER_PASTE:
1478 : case ID_BROWSER_CUT:
1479 : {
1480 38 : CellControllerRef xCurrentController = getBrowserView()->getVclControl()->Controller();
1481 38 : if (xCurrentController.Is() && xCurrentController->ISA(EditCellController))
1482 : {
1483 38 : Edit& rEdit = static_cast<Edit&>(xCurrentController->GetWindow());
1484 38 : bool bHasLen = (rEdit.GetSelection().Len() != 0);
1485 38 : bool bIsReadOnly = rEdit.IsReadOnly();
1486 38 : switch (nId)
1487 : {
1488 12 : case ID_BROWSER_CUT: aReturn.bEnabled = m_aCurrentFrame.isActive() && bHasLen && !bIsReadOnly; break;
1489 14 : case SID_COPY : aReturn.bEnabled = m_aCurrentFrame.isActive() && bHasLen; break;
1490 : case ID_BROWSER_PASTE:
1491 12 : aReturn.bEnabled = m_aCurrentFrame.isActive() && !bIsReadOnly;
1492 12 : if(aReturn.bEnabled)
1493 : {
1494 0 : aReturn.bEnabled = aReturn.bEnabled && IsFormatSupported( m_aSystemClipboard.GetDataFlavorExVector(), SotClipboardFormatId::STRING );
1495 : }
1496 12 : break;
1497 : }
1498 38 : }
1499 : }
1500 38 : break;
1501 :
1502 : case ID_BROWSER_SORTUP:
1503 : case ID_BROWSER_SORTDOWN:
1504 : case ID_BROWSER_AUTOFILTER:
1505 : {
1506 : // a native statement can't be filtered or sorted
1507 15 : const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1508 15 : if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || !m_xParser.is() )
1509 0 : break;
1510 :
1511 30 : Reference< XPropertySet > xCurrentField = getBoundField();
1512 15 : if (!xCurrentField.is())
1513 0 : break;
1514 :
1515 15 : aReturn.bEnabled = ::comphelper::getBOOL(xCurrentField->getPropertyValue(PROPERTY_ISSEARCHABLE));
1516 30 : const Reference< XRowSet > xRow = getRowSet();
1517 : aReturn.bEnabled = aReturn.bEnabled
1518 15 : && xRow.is()
1519 15 : && !xRow->isBeforeFirst()
1520 15 : && !xRow->isAfterLast()
1521 15 : && !xRow->rowDeleted()
1522 45 : && ( ::comphelper::getINT32( xFormSet->getPropertyValue( PROPERTY_ROWCOUNT ) ) != 0 );
1523 : }
1524 15 : break;
1525 :
1526 : case ID_BROWSER_FILTERCRIT:
1527 5 : if ( m_bCannotSelectUnfiltered && m_xParser.is() )
1528 : {
1529 0 : aReturn.bEnabled = true;
1530 0 : break;
1531 : }
1532 : // no break
1533 : case ID_BROWSER_ORDERCRIT:
1534 : {
1535 10 : const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1536 10 : if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || !m_xParser.is() )
1537 0 : break;
1538 :
1539 40 : aReturn.bEnabled = getRowSet().is()
1540 40 : && ( ::comphelper::getINT32( xFormSet->getPropertyValue( PROPERTY_ROWCOUNT ) ) != 0 );
1541 : }
1542 10 : break;
1543 :
1544 : case ID_BROWSER_REFRESH:
1545 0 : aReturn.bEnabled = true;
1546 0 : break;
1547 :
1548 : case ID_BROWSER_REDO:
1549 0 : aReturn.bEnabled = false; // simply forget it ;). no redo possible.
1550 0 : break;
1551 :
1552 : case ID_BROWSER_UNDORECORD:
1553 : case ID_BROWSER_SAVERECORD:
1554 : {
1555 28 : if (!m_bCurrentlyModified)
1556 : {
1557 28 : Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1558 28 : if (xFormSet.is())
1559 28 : aReturn.bEnabled = ::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ISMODIFIED));
1560 : }
1561 : else
1562 0 : aReturn.bEnabled = true;
1563 :
1564 28 : aReturn.sTitle = (ID_BROWSER_UNDORECORD == nId) ? m_sStateUndoRecord : m_sStateSaveRecord;
1565 : }
1566 28 : break;
1567 : case ID_BROWSER_EDITDOC:
1568 : {
1569 : // check if it is available
1570 3 : Reference< XPropertySet > xDataSourceSet(getRowSet(), UNO_QUERY);
1571 3 : if (!xDataSourceSet.is())
1572 0 : break; // no datasource -> no edit mode
1573 :
1574 3 : sal_Int32 nDataSourcePrivileges = ::comphelper::getINT32(xDataSourceSet->getPropertyValue(PROPERTY_PRIVILEGES));
1575 3 : bool bInsertAllowedAndPossible = ((nDataSourcePrivileges & ::com::sun::star::sdbcx::Privilege::INSERT) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue("AllowInserts"));
1576 3 : bool bUpdateAllowedAndPossible = ((nDataSourcePrivileges & ::com::sun::star::sdbcx::Privilege::UPDATE) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue("AllowUpdates"));
1577 3 : bool bDeleteAllowedAndPossible = ((nDataSourcePrivileges & ::com::sun::star::sdbcx::Privilege::DELETE) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue("AllowDeletes"));
1578 3 : if (!bInsertAllowedAndPossible && !bUpdateAllowedAndPossible && !bDeleteAllowedAndPossible)
1579 0 : break; // no insert/update/delete -> no edit mode
1580 :
1581 3 : if (!isValidCursor() || !isLoaded())
1582 0 : break; // no cursor -> no edit mode
1583 :
1584 3 : aReturn.bEnabled = true;
1585 :
1586 3 : sal_Int16 nGridMode = getBrowserView()->getVclControl()->GetOptions();
1587 3 : aReturn.bChecked = nGridMode > DbGridControl::OPT_READONLY;
1588 : }
1589 3 : break;
1590 : case ID_BROWSER_FILTERED:
1591 : {
1592 3 : aReturn.bEnabled = false;
1593 3 : Reference< XPropertySet > xActiveSet(getRowSet(), UNO_QUERY);
1594 6 : OUString aFilter = ::comphelper::getString(xActiveSet->getPropertyValue(PROPERTY_FILTER));
1595 6 : OUString aHaving = ::comphelper::getString(xActiveSet->getPropertyValue(PROPERTY_HAVING_CLAUSE));
1596 3 : if ( !(aFilter.isEmpty() && aHaving.isEmpty()) )
1597 : {
1598 0 : xActiveSet->getPropertyValue( PROPERTY_APPLYFILTER ) >>= aReturn.bChecked;
1599 0 : aReturn.bEnabled = true;
1600 : }
1601 : else
1602 : {
1603 3 : aReturn.bChecked = false;
1604 3 : aReturn.bEnabled = false;
1605 3 : }
1606 : }
1607 3 : break;
1608 : default:
1609 6 : return SbaXDataBrowserController_Base::GetState(nId);
1610 : }
1611 : }
1612 0 : catch(const Exception& )
1613 : {
1614 : DBG_UNHANDLED_EXCEPTION();
1615 : }
1616 :
1617 106 : return aReturn;
1618 : }
1619 :
1620 0 : void SbaXDataBrowserController::applyParserOrder(const OUString& _rOldOrder,const Reference< XSingleSelectQueryComposer >& _xParser)
1621 : {
1622 0 : Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1623 0 : if (!m_xLoadable.is())
1624 : {
1625 : SAL_WARN("dbaccess.ui","SbaXDataBrowserController::applyParserOrder: invalid row set!");
1626 0 : return;
1627 : }
1628 :
1629 0 : sal_uInt16 nPos = getCurrentColumnPosition();
1630 0 : bool bSuccess = false;
1631 : try
1632 : {
1633 0 : xFormSet->setPropertyValue(PROPERTY_ORDER, makeAny(_xParser->getOrder()));
1634 0 : bSuccess = reloadForm(m_xLoadable);
1635 : }
1636 0 : catch(Exception&)
1637 : {
1638 : }
1639 :
1640 0 : if (!bSuccess)
1641 : {
1642 0 : xFormSet->setPropertyValue(PROPERTY_ORDER, makeAny(_rOldOrder));
1643 :
1644 : try
1645 : {
1646 0 : if (loadingCancelled() || !reloadForm(m_xLoadable))
1647 0 : criticalFail();
1648 : }
1649 0 : catch(Exception&)
1650 : {
1651 0 : criticalFail();
1652 : }
1653 0 : InvalidateAll();
1654 : }
1655 0 : InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1656 :
1657 0 : setCurrentColumnPosition(nPos);
1658 : }
1659 :
1660 0 : void SbaXDataBrowserController::applyParserFilter(const OUString& _rOldFilter, bool _bOldFilterApplied,const ::OUString& _sOldHaving,const Reference< XSingleSelectQueryComposer >& _xParser)
1661 : {
1662 0 : Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1663 0 : if (!m_xLoadable.is())
1664 : {
1665 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::applyParserFilter: invalid row set!");
1666 0 : return;
1667 : }
1668 :
1669 0 : sal_uInt16 nPos = getCurrentColumnPosition();
1670 :
1671 0 : bool bSuccess = false;
1672 : try
1673 : {
1674 0 : FormErrorHelper aError(this);
1675 0 : xFormSet->setPropertyValue(PROPERTY_FILTER, makeAny(_xParser->getFilter()));
1676 0 : xFormSet->setPropertyValue(PROPERTY_HAVING_CLAUSE, makeAny(_xParser->getHavingClause()));
1677 0 : xFormSet->setPropertyValue(PROPERTY_APPLYFILTER, ::comphelper::makeBoolAny(true));
1678 :
1679 0 : bSuccess = reloadForm(m_xLoadable);
1680 : }
1681 0 : catch(Exception&)
1682 : {
1683 : }
1684 :
1685 0 : if (!bSuccess)
1686 : {
1687 0 : xFormSet->setPropertyValue(PROPERTY_FILTER, makeAny(_rOldFilter));
1688 0 : xFormSet->setPropertyValue(PROPERTY_HAVING_CLAUSE, makeAny(_sOldHaving));
1689 0 : xFormSet->setPropertyValue(PROPERTY_APPLYFILTER, ::comphelper::makeBoolAny(_bOldFilterApplied));
1690 :
1691 : try
1692 : {
1693 0 : if (loadingCancelled() || !reloadForm(m_xLoadable))
1694 0 : criticalFail();
1695 : }
1696 0 : catch(Exception&)
1697 : {
1698 0 : criticalFail();
1699 : }
1700 0 : InvalidateAll();
1701 : }
1702 0 : InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1703 :
1704 0 : setCurrentColumnPosition(nPos);
1705 : }
1706 :
1707 1 : Reference< XSingleSelectQueryComposer > SbaXDataBrowserController::createParser_nothrow()
1708 : {
1709 1 : Reference< XSingleSelectQueryComposer > xComposer;
1710 : try
1711 : {
1712 1 : const Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
1713 : const Reference< XMultiServiceFactory > xFactory(
1714 2 : xRowSetProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ), UNO_QUERY_THROW );
1715 1 : xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
1716 :
1717 2 : OUString sActiveCommand;
1718 1 : OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ACTIVECOMMAND ) >>= sActiveCommand );
1719 1 : if ( !sActiveCommand.isEmpty() )
1720 : {
1721 0 : xComposer->setElementaryQuery( sActiveCommand );
1722 : }
1723 : else
1724 : {
1725 1 : OUString sCommand;
1726 1 : OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
1727 1 : sal_Int32 nCommandType = CommandType::COMMAND;
1728 1 : OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_COMMAND_TYPE ) >>= nCommandType );
1729 1 : xComposer->setCommand( sCommand, nCommandType );
1730 : }
1731 :
1732 2 : OUString sFilter;
1733 1 : OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_FILTER ) >>= sFilter );
1734 1 : xComposer->setFilter( sFilter );
1735 :
1736 2 : OUString sHavingClause;
1737 1 : OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_HAVING_CLAUSE ) >>= sHavingClause );
1738 1 : xComposer->setHavingClause( sHavingClause );
1739 :
1740 2 : OUString sOrder;
1741 1 : OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ORDER ) >>= sOrder );
1742 2 : xComposer->setOrder( sOrder );
1743 : }
1744 0 : catch ( const Exception& )
1745 : {
1746 : DBG_UNHANDLED_EXCEPTION();
1747 : }
1748 1 : return xComposer;
1749 : }
1750 :
1751 0 : void SbaXDataBrowserController::ExecuteFilterSortCrit(bool bFilter)
1752 : {
1753 0 : if (!SaveModified())
1754 0 : return;
1755 :
1756 0 : Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1757 :
1758 0 : const OUString sOldVal = bFilter ? m_xParser->getFilter() : m_xParser->getOrder();
1759 0 : const OUString sOldHaving = m_xParser->getHavingClause();
1760 0 : Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow();
1761 : try
1762 : {
1763 0 : Reference< ::com::sun::star::sdbcx::XColumnsSupplier> xSup = getColumnsSupplier();
1764 0 : Reference< XConnection> xCon(xFormSet->getPropertyValue(PROPERTY_ACTIVE_CONNECTION),UNO_QUERY);
1765 0 : if(bFilter)
1766 : {
1767 0 : ScopedVclPtrInstance< DlgFilterCrit > aDlg( getBrowserView(), getORB(), xCon, xParser, xSup->getColumns() );
1768 0 : if ( !aDlg->Execute() )
1769 0 : return; // if so we don't need to update the grid
1770 0 : aDlg->BuildWherePart();
1771 : }
1772 : else
1773 : {
1774 0 : ScopedVclPtrInstance< DlgOrderCrit > aDlg( getBrowserView(),xCon,xParser,xSup->getColumns() );
1775 0 : if(!aDlg->Execute())
1776 : {
1777 0 : return; // if so we don't need to actualize the grid
1778 : }
1779 0 : aDlg->BuildOrderPart();
1780 0 : }
1781 : }
1782 0 : catch(const SQLException& )
1783 : {
1784 0 : SQLExceptionInfo aError( ::cppu::getCaughtException() );
1785 0 : showError( aError );
1786 0 : return;
1787 : }
1788 0 : catch(Exception&)
1789 : {
1790 0 : return;
1791 : }
1792 :
1793 0 : OUString sNewVal = bFilter ? xParser->getFilter() : xParser->getOrder();
1794 0 : bool bOldFilterApplied(false);
1795 0 : if (bFilter)
1796 : {
1797 0 : try { bOldFilterApplied = ::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_APPLYFILTER)); } catch(Exception&) { } ;
1798 : }
1799 :
1800 0 : OUString sNewHaving = xParser->getHavingClause();
1801 0 : if ( sOldVal.equals(sNewVal) && (!bFilter || sOldHaving.equals(sNewHaving)) )
1802 : // nothing to be done
1803 0 : return;
1804 :
1805 0 : if (bFilter)
1806 0 : applyParserFilter(sOldVal, bOldFilterApplied,sOldHaving,xParser);
1807 : else
1808 0 : applyParserOrder(sOldVal,xParser);
1809 :
1810 0 : ::comphelper::disposeComponent(xParser);
1811 : }
1812 :
1813 0 : void SbaXDataBrowserController::ExecuteSearch()
1814 : {
1815 : // calculate the control source of the active field
1816 0 : Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
1817 : OSL_ENSURE(xGrid.is(), "SbaXDataBrowserController::ExecuteSearch : the control should have an ::com::sun::star::form::XGrid interface !");
1818 :
1819 0 : Reference< ::com::sun::star::form::XGridPeer > xGridPeer(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY);
1820 0 : Reference< ::com::sun::star::container::XIndexContainer > xColumns = xGridPeer->getColumns();
1821 : OSL_ENSURE(xGridPeer.is() && xColumns.is(), "SbaXDataBrowserController::ExecuteSearch : invalid peer !");
1822 :
1823 0 : sal_Int16 nViewCol = xGrid->getCurrentColumnPosition();
1824 0 : sal_Int16 nModelCol = getBrowserView()->View2ModelPos(nViewCol);
1825 :
1826 0 : Reference< XPropertySet > xCurrentCol(xColumns->getByIndex(nModelCol),UNO_QUERY);
1827 0 : OUString sActiveField = ::comphelper::getString(xCurrentCol->getPropertyValue(PROPERTY_CONTROLSOURCE));
1828 :
1829 : // the text within the current cell
1830 0 : OUString sInitialText;
1831 0 : Reference< ::com::sun::star::container::XIndexAccess > xColControls(xGridPeer, UNO_QUERY);
1832 0 : Reference< XInterface > xCurControl(xColControls->getByIndex(nViewCol),UNO_QUERY);
1833 0 : OUString aInitialText;
1834 0 : if (IsSearchableControl(xCurControl, &aInitialText))
1835 0 : sInitialText = aInitialText;
1836 :
1837 : // prohibit the synchronization of the grid's display with the cursor's position
1838 0 : Reference< XPropertySet > xModelSet(getControlModel(), UNO_QUERY);
1839 : OSL_ENSURE(xModelSet.is(), "SbaXDataBrowserController::ExecuteSearch : no model set ?!");
1840 0 : xModelSet->setPropertyValue("DisplayIsSynchron", ::comphelper::makeBoolAny(false));
1841 0 : xModelSet->setPropertyValue("AlwaysShowCursor", ::comphelper::makeBoolAny(true));
1842 0 : xModelSet->setPropertyValue("CursorColor", makeAny(sal_Int32(COL_LIGHTRED)));
1843 :
1844 0 : Reference< ::com::sun::star::util::XNumberFormatsSupplier > xNFS(::dbtools::getNumberFormats(::dbtools::getConnection(m_xRowSet), true, getORB()));
1845 :
1846 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1847 0 : AbstractFmSearchDialog* pDialog = NULL;
1848 0 : if ( pFact )
1849 : {
1850 0 : ::std::vector< OUString > aContextNames;
1851 0 : aContextNames.push_back( OUString("Standard") );
1852 0 : pDialog = pFact->CreateFmSearchDialog(getBrowserView(), sInitialText, aContextNames, 0, LINK(this, SbaXDataBrowserController, OnSearchContextRequest));
1853 : }
1854 : OSL_ENSURE( pDialog, "SbaXDataBrowserController::ExecuteSearch: could not get the search dialog!" );
1855 0 : if ( pDialog )
1856 : {
1857 0 : pDialog->SetActiveField( sActiveField );
1858 0 : pDialog->SetFoundHandler( LINK( this, SbaXDataBrowserController, OnFoundData ) );
1859 0 : pDialog->SetCanceledNotFoundHdl( LINK( this, SbaXDataBrowserController, OnCanceledNotFound ) );
1860 0 : pDialog->Execute();
1861 0 : delete pDialog;
1862 : }
1863 :
1864 : // restore the grid's normal operating state
1865 0 : xModelSet->setPropertyValue("DisplayIsSynchron", ::comphelper::makeBoolAny(true));
1866 0 : xModelSet->setPropertyValue("AlwaysShowCursor", ::comphelper::makeBoolAny(false));
1867 0 : xModelSet->setPropertyValue("CursorColor", Any());
1868 0 : }
1869 :
1870 0 : void SbaXDataBrowserController::Execute(sal_uInt16 nId, const Sequence< PropertyValue >& _rArgs)
1871 : {
1872 0 : bool bSortUp = true;
1873 :
1874 0 : switch (nId)
1875 : {
1876 : default:
1877 0 : SbaXDataBrowserController_Base::Execute( nId, _rArgs );
1878 0 : return;
1879 :
1880 : case ID_BROWSER_INSERT_ROW:
1881 : try
1882 : {
1883 0 : if (SaveModified())
1884 : {
1885 0 : getRowSet()->afterLast();
1886 : // check if it is available
1887 0 : Reference< XResultSetUpdate > xUpdateCursor(getRowSet(), UNO_QUERY_THROW);
1888 0 : xUpdateCursor->moveToInsertRow();
1889 : }
1890 : }
1891 0 : catch(Exception&)
1892 : {
1893 : SAL_WARN("dbaccess.ui", "Exception caught!");
1894 : }
1895 0 : break;
1896 : case SID_FM_DELETEROWS:
1897 :
1898 0 : if (SaveModified())
1899 : {
1900 0 : SbaGridControl* pVclGrid = getBrowserView()->getVclControl();
1901 0 : if ( pVclGrid )
1902 : {
1903 0 : if( !pVclGrid->GetSelectRowCount() )
1904 : {
1905 0 : pVclGrid->DeactivateCell();
1906 0 : pVclGrid->SelectRow(pVclGrid->GetCurRow());
1907 : }
1908 0 : pVclGrid->DeleteSelectedRows();
1909 : }
1910 : }
1911 0 : break;
1912 :
1913 : case ID_BROWSER_FILTERED:
1914 0 : if (SaveModified())
1915 : {
1916 0 : Reference< XPropertySet > xActiveSet(getRowSet(), UNO_QUERY);
1917 0 : bool bApplied = ::comphelper::getBOOL(xActiveSet->getPropertyValue(PROPERTY_APPLYFILTER));
1918 0 : xActiveSet->setPropertyValue(PROPERTY_APPLYFILTER, ::comphelper::makeBoolAny(!bApplied));
1919 0 : reloadForm(m_xLoadable);
1920 : }
1921 0 : InvalidateFeature(ID_BROWSER_FILTERED);
1922 0 : break;
1923 : case ID_BROWSER_EDITDOC:
1924 : {
1925 0 : sal_Int16 nGridMode = getBrowserView()->getVclControl()->GetOptions();
1926 0 : if (nGridMode == DbGridControl::OPT_READONLY)
1927 0 : getBrowserView()->getVclControl()->SetOptions(DbGridControl::OPT_UPDATE | DbGridControl::OPT_INSERT | DbGridControl::OPT_DELETE);
1928 : // the options not supported by the data source will be removed automatically
1929 : else
1930 : {
1931 0 : if ( !SaveModified( ) )
1932 : // give the user a chance to save the current record (if necessary)
1933 0 : break;
1934 :
1935 : // maybe the user wanted to reject the modified record ?
1936 0 : if (GetState(ID_BROWSER_UNDORECORD).bEnabled)
1937 0 : Execute(ID_BROWSER_UNDORECORD,Sequence<PropertyValue>());
1938 :
1939 0 : getBrowserView()->getVclControl()->SetOptions(DbGridControl::OPT_READONLY);
1940 : }
1941 0 : InvalidateFeature(ID_BROWSER_EDITDOC);
1942 : }
1943 0 : break;
1944 :
1945 : case ID_BROWSER_SEARCH:
1946 0 : if ( SaveModified( ) )
1947 0 : ExecuteSearch();
1948 0 : break;
1949 :
1950 : case ID_BROWSER_COPY:
1951 0 : if ( getBrowserView()->getVclControl()->GetSelectRowCount() > 0 )
1952 : {
1953 0 : getBrowserView()->getVclControl()->CopySelectedRowsToClipboard();
1954 0 : break;
1955 : }
1956 : // run through
1957 : case ID_BROWSER_CUT:
1958 : case ID_BROWSER_PASTE:
1959 : {
1960 0 : CellControllerRef xCurrentController = getBrowserView()->getVclControl()->Controller();
1961 0 : if (!xCurrentController.Is())
1962 : // should be intercepted by GetState. Normally.
1963 : // Unfortunately ID_BROWSER_PASTE is a 'fast call' slot, which means it may be executed without checking if it is
1964 : // enabled. This would be really deadly herein if the current cell has no controller ...
1965 0 : return;
1966 :
1967 0 : Edit& rEdit = static_cast<Edit&>(xCurrentController->GetWindow());
1968 0 : switch (nId)
1969 : {
1970 0 : case ID_BROWSER_CUT : rEdit.Cut(); break;
1971 0 : case SID_COPY : rEdit.Copy(); break;
1972 0 : case ID_BROWSER_PASTE : rEdit.Paste(); break;
1973 : }
1974 0 : if (ID_BROWSER_CUT == nId || ID_BROWSER_PASTE == nId)
1975 : {
1976 0 : xCurrentController->SetModified();
1977 0 : rEdit.Modify();
1978 0 : }
1979 : }
1980 0 : break;
1981 :
1982 : case ID_BROWSER_SORTDOWN:
1983 0 : bSortUp = false;
1984 : // DON'T break
1985 : case ID_BROWSER_SORTUP:
1986 : {
1987 0 : if (!SaveModified())
1988 0 : break;
1989 :
1990 0 : if (!isValidCursor())
1991 0 : break;
1992 :
1993 : // only one sort order
1994 0 : Reference< XPropertySet > xField(getBoundField(), UNO_QUERY);
1995 0 : if (!xField.is())
1996 0 : break;
1997 :
1998 0 : Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow();
1999 0 : const OUString sOldSort = xParser->getOrder();
2000 0 : bool bParserSuccess = false;
2001 0 : HANDLE_SQL_ERRORS(
2002 : xParser->setOrder(OUString()); xParser->appendOrderByColumn(xField, bSortUp),
2003 : bParserSuccess,
2004 : ModuleRes(SBA_BROWSER_SETTING_ORDER).toString(),
2005 : "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"
2006 : )
2007 :
2008 0 : if (bParserSuccess)
2009 0 : applyParserOrder(sOldSort,xParser);
2010 : }
2011 0 : break;
2012 :
2013 : case ID_BROWSER_AUTOFILTER:
2014 : {
2015 0 : if (!SaveModified())
2016 0 : break;
2017 :
2018 0 : if (!isValidCursor())
2019 0 : break;
2020 :
2021 0 : Reference< XPropertySet > xField(getBoundField(), UNO_QUERY);
2022 0 : if (!xField.is())
2023 0 : break;
2024 :
2025 : // check if the column is a aggregate function
2026 0 : bool bHaving = false;
2027 0 : OUString sName;
2028 0 : xField->getPropertyValue(PROPERTY_NAME) >>= sName;
2029 0 : Reference< XColumnsSupplier > xColumnsSupplier(m_xParser, UNO_QUERY);
2030 0 : Reference< ::com::sun::star::container::XNameAccess > xCols = xColumnsSupplier.is() ? xColumnsSupplier->getColumns() : Reference< ::com::sun::star::container::XNameAccess > ();
2031 0 : if ( xCols.is() && xCols->hasByName(sName) )
2032 : {
2033 0 : Reference<XPropertySet> xProp(xCols->getByName(sName),UNO_QUERY);
2034 : static const char sAgg[] = "AggregateFunction";
2035 0 : if ( xProp->getPropertySetInfo()->hasPropertyByName(sAgg) )
2036 0 : xProp->getPropertyValue(sAgg) >>= bHaving;
2037 : }
2038 :
2039 0 : Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow();
2040 0 : const OUString sOldFilter = xParser->getFilter();
2041 0 : const OUString sOldHaving = xParser->getHavingClause();
2042 :
2043 0 : Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
2044 0 : bool bApplied = ::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_APPLYFILTER));
2045 : // do we have a filter but it's not applied ?
2046 : // -> completely overwrite it, else append one
2047 0 : if (!bApplied)
2048 : {
2049 0 : DO_SAFE( (bHaving ? xParser->setHavingClause(OUString()) : xParser->setFilter(::OUString())), "SbaXDataBrowserController::Execute : caught an exception while resetting the new filter !" );
2050 : }
2051 :
2052 0 : bool bParserSuccess = false;
2053 :
2054 0 : const sal_Int32 nOp = SQLFilterOperator::EQUAL;
2055 :
2056 0 : if ( bHaving )
2057 : {
2058 0 : HANDLE_SQL_ERRORS(
2059 : xParser->appendHavingClauseByColumn(xField,sal_True,nOp),
2060 : bParserSuccess,
2061 : ModuleRes(SBA_BROWSER_SETTING_FILTER).toString(),
2062 : "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"
2063 : )
2064 : }
2065 : else
2066 : {
2067 0 : HANDLE_SQL_ERRORS(
2068 : xParser->appendFilterByColumn(xField,sal_True,nOp),
2069 : bParserSuccess,
2070 : ModuleRes(SBA_BROWSER_SETTING_FILTER).toString(),
2071 : "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"
2072 : )
2073 : }
2074 :
2075 0 : if (bParserSuccess)
2076 0 : applyParserFilter(sOldFilter, bApplied,sOldHaving,xParser);
2077 :
2078 0 : InvalidateFeature(ID_BROWSER_REMOVEFILTER);
2079 0 : InvalidateFeature(ID_BROWSER_FILTERED);
2080 : }
2081 0 : break;
2082 :
2083 : case ID_BROWSER_ORDERCRIT:
2084 0 : ExecuteFilterSortCrit(false);
2085 0 : break;
2086 :
2087 : case ID_BROWSER_FILTERCRIT:
2088 0 : ExecuteFilterSortCrit(true);
2089 0 : InvalidateFeature(ID_BROWSER_FILTERED);
2090 0 : break;
2091 :
2092 : case ID_BROWSER_REMOVEFILTER:
2093 : {
2094 0 : if (!SaveModified())
2095 0 : break;
2096 :
2097 0 : bool bNeedPostReload = preReloadForm();
2098 : // reset the filter and the sort property simutaneously so only _one_ new statement has to be
2099 : // sent
2100 0 : Reference< XPropertySet > xSet(getRowSet(), UNO_QUERY);
2101 0 : if ( xSet.is() )
2102 : {
2103 0 : xSet->setPropertyValue(PROPERTY_FILTER,makeAny(OUString()));
2104 0 : xSet->setPropertyValue(PROPERTY_HAVING_CLAUSE,makeAny(OUString()));
2105 0 : xSet->setPropertyValue(PROPERTY_ORDER,makeAny(OUString()));
2106 : }
2107 : try
2108 : {
2109 0 : reloadForm(m_xLoadable);
2110 0 : if ( bNeedPostReload )
2111 0 : postReloadForm();
2112 : }
2113 0 : catch(Exception&)
2114 : {
2115 : }
2116 0 : InvalidateFeature(ID_BROWSER_REMOVEFILTER);
2117 0 : InvalidateFeature(ID_BROWSER_FILTERED);
2118 : }
2119 0 : break;
2120 :
2121 : case ID_BROWSER_REFRESH:
2122 0 : if ( SaveModified( ) )
2123 : {
2124 0 : if (!reloadForm(m_xLoadable))
2125 0 : criticalFail();
2126 : }
2127 0 : break;
2128 :
2129 : case ID_BROWSER_SAVERECORD:
2130 0 : if ( SaveModified( false ) )
2131 0 : setCurrentModified( false );
2132 0 : break;
2133 :
2134 : case ID_BROWSER_UNDORECORD:
2135 : {
2136 : try
2137 : {
2138 : // restore the cursor state
2139 0 : Reference< XResultSetUpdate > xCursor(getRowSet(), UNO_QUERY);
2140 0 : Reference< XPropertySet > xSet(xCursor, UNO_QUERY);
2141 0 : Any aVal = xSet->getPropertyValue(PROPERTY_ISNEW);
2142 0 : if (aVal.hasValue() && ::comphelper::getBOOL(aVal))
2143 : {
2144 0 : xCursor->moveToInsertRow();
2145 : // no need to reset the grid model after we moved to the insert row, this is done implicitly by the
2146 : // form
2147 : // (and in some cases it may be deadly to do the reset explicitly after the form did it implicitly,
2148 : // cause the form's reset may be async, and this leads to some nice deadlock scenarios ....)
2149 : }
2150 : else
2151 : {
2152 0 : xCursor->cancelRowUpdates();
2153 :
2154 : // restore the grids state
2155 0 : Reference< ::com::sun::star::form::XReset > xReset(getControlModel(), UNO_QUERY);
2156 0 : if (xReset.is())
2157 0 : xReset->reset();
2158 0 : }
2159 : }
2160 0 : catch(SQLException&)
2161 : {
2162 : }
2163 :
2164 0 : setCurrentModified( false );
2165 : }
2166 : }
2167 : }
2168 :
2169 0 : bool SbaXDataBrowserController::SaveModified(bool bAskFor)
2170 : {
2171 0 : if ( bAskFor && GetState(ID_BROWSER_SAVERECORD).bEnabled )
2172 : {
2173 0 : getBrowserView()->getVclControl()->GrabFocus();
2174 :
2175 0 : ScopedVclPtrInstance<MessageDialog> aQry( getBrowserView()->getVclControl(),
2176 : "SaveModifiedDialog",
2177 0 : "dbaccess/ui/savemodifieddialog.ui" );
2178 :
2179 0 : switch (aQry->Execute())
2180 : {
2181 : case RET_NO:
2182 0 : Execute(ID_BROWSER_UNDORECORD,Sequence<PropertyValue>());
2183 0 : return true;
2184 : case RET_CANCEL:
2185 0 : return false;
2186 0 : }
2187 : }
2188 :
2189 0 : if ( !CommitCurrent() ) // das aktuelle Control committen lassen
2190 0 : return false;
2191 :
2192 0 : Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
2193 0 : bool bResult = false;
2194 : try
2195 : {
2196 0 : if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ISMODIFIED)))
2197 : {
2198 0 : Reference< XResultSetUpdate > xCursor(getRowSet(), UNO_QUERY);
2199 0 : if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ISNEW)))
2200 0 : xCursor->insertRow();
2201 : else
2202 0 : xCursor->updateRow();
2203 : }
2204 0 : bResult = true;
2205 : }
2206 0 : catch(SQLException&)
2207 : {
2208 : }
2209 0 : catch(Exception&)
2210 : {
2211 : SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::SaveModified : could not save the current record !");
2212 0 : bResult = false;
2213 : }
2214 :
2215 0 : InvalidateFeature(ID_BROWSER_SAVERECORD);
2216 0 : InvalidateFeature(ID_BROWSER_UNDORECORD);
2217 0 : return bResult;
2218 : }
2219 :
2220 0 : bool SbaXDataBrowserController::CommitCurrent()
2221 : {
2222 0 : if (!getBrowserView())
2223 0 : return true;
2224 :
2225 0 : Reference< ::com::sun::star::awt::XControl > xActiveControl(getBrowserView()->getGridControl());
2226 0 : Reference< ::com::sun::star::form::XBoundControl > xLockingTest(xActiveControl, UNO_QUERY);
2227 0 : bool bControlIsLocked = xLockingTest.is() && xLockingTest->getLock();
2228 0 : if (xActiveControl.is() && !bControlIsLocked)
2229 : {
2230 : // zunaechst das Control fragen ob es das IFace unterstuetzt
2231 0 : Reference< ::com::sun::star::form::XBoundComponent > xBoundControl(xActiveControl, UNO_QUERY);
2232 0 : if (!xBoundControl.is())
2233 0 : xBoundControl = Reference< ::com::sun::star::form::XBoundComponent > (xActiveControl->getModel(), UNO_QUERY);
2234 0 : if (xBoundControl.is() && !xBoundControl->commit())
2235 0 : return false;
2236 : }
2237 0 : return true;
2238 : }
2239 :
2240 5 : void SbaXDataBrowserController::setCurrentModified( bool _bSet )
2241 : {
2242 5 : m_bCurrentlyModified = _bSet;
2243 5 : InvalidateFeature( ID_BROWSER_SAVERECORD );
2244 5 : InvalidateFeature( ID_BROWSER_UNDORECORD );
2245 5 : }
2246 :
2247 2 : void SbaXDataBrowserController::RowChanged()
2248 : {
2249 2 : setCurrentModified( false );
2250 2 : }
2251 :
2252 3 : void SbaXDataBrowserController::ColumnChanged()
2253 : {
2254 3 : InvalidateFeature(ID_BROWSER_SORTUP);
2255 3 : InvalidateFeature(ID_BROWSER_SORTDOWN);
2256 3 : InvalidateFeature(ID_BROWSER_ORDERCRIT);
2257 3 : InvalidateFeature(ID_BROWSER_FILTERCRIT);
2258 3 : InvalidateFeature(ID_BROWSER_AUTOFILTER);
2259 3 : InvalidateFeature(ID_BROWSER_REMOVEFILTER);
2260 :
2261 3 : setCurrentModified( false );
2262 3 : }
2263 :
2264 0 : void SbaXDataBrowserController::SelectionChanged()
2265 : {
2266 : // not interested in
2267 0 : }
2268 :
2269 6 : void SbaXDataBrowserController::CellActivated()
2270 : {
2271 6 : m_aInvalidateClipboard.Start();
2272 6 : OnInvalidateClipboard( NULL );
2273 6 : }
2274 :
2275 5 : void SbaXDataBrowserController::CellDeactivated()
2276 : {
2277 5 : m_aInvalidateClipboard.Stop();
2278 5 : OnInvalidateClipboard( NULL );
2279 5 : }
2280 :
2281 0 : IMPL_LINK_NOARG(SbaXDataBrowserController, OnClipboardChanged)
2282 : {
2283 0 : SolarMutexGuard aGuard;
2284 0 : OnInvalidateClipboard( NULL );
2285 0 : return 0;
2286 : }
2287 :
2288 13 : IMPL_LINK_TYPED(SbaXDataBrowserController, OnInvalidateClipboard, Timer*, _pTimer, void)
2289 : {
2290 12 : InvalidateFeature(ID_BROWSER_CUT);
2291 12 : InvalidateFeature(ID_BROWSER_COPY);
2292 :
2293 : // if the invalidation was triggered by the timer, we do not need to invalidate PASTE.
2294 : // The timer is only for checking the CUT/COPY slots regulariry, which depend on the
2295 : // selection state of the active cell
2296 : // TODO: get a callback at the Edit which allows to be notified when the selection
2297 : // changes. This would be much better than this cycle-eating polling mechanism here ....
2298 12 : if ( _pTimer != &m_aInvalidateClipboard )
2299 11 : InvalidateFeature(ID_BROWSER_PASTE);
2300 12 : }
2301 :
2302 15 : Reference< XPropertySet > SbaXDataBrowserController::getBoundField(sal_uInt16 nViewPos) const
2303 : {
2304 15 : Reference< XPropertySet > xEmptyReturn;
2305 :
2306 : // get the current column from the grid
2307 15 : if (nViewPos == (sal_uInt16)-1)
2308 : {
2309 15 : Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
2310 15 : if (!xGrid.is())
2311 0 : return xEmptyReturn;
2312 15 : nViewPos = xGrid->getCurrentColumnPosition();
2313 : }
2314 15 : sal_uInt16 nCurrentCol = getBrowserView()->View2ModelPos(nViewPos);
2315 15 : if (nCurrentCol == (sal_uInt16)-1)
2316 0 : return xEmptyReturn;
2317 :
2318 : // get the according column from the model
2319 30 : Reference< ::com::sun::star::container::XIndexContainer > xCols(getControlModel(), UNO_QUERY);
2320 30 : Reference< XPropertySet > xCurrentCol(xCols->getByIndex(nCurrentCol),UNO_QUERY);
2321 15 : if (!xCurrentCol.is())
2322 0 : return xEmptyReturn;
2323 :
2324 15 : xEmptyReturn.set(xCurrentCol->getPropertyValue(PROPERTY_BOUNDFIELD) ,UNO_QUERY);
2325 15 : return xEmptyReturn;
2326 : }
2327 :
2328 0 : IMPL_LINK(SbaXDataBrowserController, OnSearchContextRequest, FmSearchContext*, pContext)
2329 : {
2330 0 : Reference< ::com::sun::star::container::XIndexAccess > xPeerContainer(getBrowserView()->getGridControl(), UNO_QUERY);
2331 :
2332 : // check all grid columns for their control source
2333 0 : Reference< ::com::sun::star::container::XIndexAccess > xModelColumns(getFormComponent(), UNO_QUERY);
2334 : OSL_ENSURE(xModelColumns.is(), "SbaXDataBrowserController::OnSearchContextRequest : there is a grid control without columns !");
2335 : // the case 'no columns' should be indicated with an empty container, I think ...
2336 : OSL_ENSURE(xModelColumns->getCount() >= xPeerContainer->getCount(), "SbaXDataBrowserController::OnSearchContextRequest : impossible : have more view than model columns !");
2337 :
2338 0 : OUString sFieldList;
2339 0 : for (sal_Int32 nViewPos=0; nViewPos<xPeerContainer->getCount(); ++nViewPos)
2340 : {
2341 0 : Reference< XInterface > xCurrentColumn(xPeerContainer->getByIndex(nViewPos),UNO_QUERY);
2342 0 : if (!xCurrentColumn.is())
2343 0 : continue;
2344 :
2345 : // can we use this column control for searching ?
2346 0 : if (!IsSearchableControl(xCurrentColumn))
2347 0 : continue;
2348 :
2349 0 : sal_uInt16 nModelPos = getBrowserView()->View2ModelPos((sal_uInt16)nViewPos);
2350 0 : Reference< XPropertySet > xCurrentColModel(xModelColumns->getByIndex(nModelPos),UNO_QUERY);
2351 0 : OUString aName = ::comphelper::getString(xCurrentColModel->getPropertyValue(PROPERTY_CONTROLSOURCE));
2352 :
2353 0 : sFieldList += aName + ";";
2354 :
2355 0 : pContext->arrFields.push_back(xCurrentColumn);
2356 0 : }
2357 0 : sFieldList = comphelper::string::stripEnd(sFieldList, ';');
2358 :
2359 0 : pContext->xCursor.set(getRowSet(),UNO_QUERY);
2360 0 : pContext->strUsedFields = sFieldList;
2361 :
2362 : // if the cursor is in a mode other than STANDARD -> reset
2363 0 : Reference< XPropertySet > xCursorSet(pContext->xCursor, UNO_QUERY);
2364 : OSL_ENSURE(xCursorSet.is() && !::comphelper::getBOOL(xCursorSet->getPropertyValue(PROPERTY_ISMODIFIED)),
2365 : "SbaXDataBrowserController::OnSearchContextRequest : please do not call for cursors with modified rows !");
2366 0 : if (xCursorSet.is() && ::comphelper::getBOOL(xCursorSet->getPropertyValue(PROPERTY_ISNEW)))
2367 : {
2368 0 : Reference< XResultSetUpdate > xUpdateCursor(pContext->xCursor, UNO_QUERY);
2369 0 : xUpdateCursor->moveToCurrentRow();
2370 : }
2371 0 : return pContext->arrFields.size();
2372 : }
2373 :
2374 0 : IMPL_LINK(SbaXDataBrowserController, OnFoundData, FmFoundRecordInformation*, pInfo)
2375 : {
2376 0 : Reference< ::com::sun::star::sdbcx::XRowLocate > xCursor(getRowSet(), UNO_QUERY);
2377 : OSL_ENSURE(xCursor.is(), "SbaXDataBrowserController::OnFoundData : xCursor is empty");
2378 :
2379 : // move the cursor
2380 0 : xCursor->moveToBookmark(pInfo->aPosition);
2381 :
2382 : // let the grid snyc it's display with the cursor
2383 0 : Reference< XPropertySet > xModelSet(getControlModel(), UNO_QUERY);
2384 : OSL_ENSURE(xModelSet.is(), "SbaXDataBrowserController::OnFoundData : no model set ?!");
2385 0 : Any aOld = xModelSet->getPropertyValue("DisplayIsSynchron");
2386 0 : xModelSet->setPropertyValue("DisplayIsSynchron", ::comphelper::makeBoolAny(true));
2387 0 : xModelSet->setPropertyValue("DisplayIsSynchron", aOld);
2388 :
2389 : // and move to the field
2390 0 : Reference< ::com::sun::star::container::XIndexAccess > aColumnControls(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY);
2391 : sal_uInt16 nViewPos;
2392 :
2393 0 : for ( nViewPos = 0; nViewPos < aColumnControls->getCount(); ++nViewPos )
2394 : {
2395 0 : Reference< XInterface > xCurrent(aColumnControls->getByIndex(nViewPos),UNO_QUERY);
2396 0 : if (IsSearchableControl(xCurrent))
2397 : {
2398 0 : if (pInfo->nFieldPos)
2399 0 : --pInfo->nFieldPos;
2400 : else
2401 0 : break;
2402 : }
2403 0 : }
2404 :
2405 0 : Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
2406 0 : xGrid->setCurrentColumnPosition(nViewPos);
2407 :
2408 0 : return 0;
2409 : }
2410 :
2411 0 : IMPL_LINK(SbaXDataBrowserController, OnCanceledNotFound, FmFoundRecordInformation*, pInfo)
2412 : {
2413 0 : Reference< ::com::sun::star::sdbcx::XRowLocate > xCursor(getRowSet(), UNO_QUERY);
2414 :
2415 : try
2416 : {
2417 : OSL_ENSURE(xCursor.is(), "SbaXDataBrowserController::OnCanceledNotFound : xCursor is empty");
2418 : // move the cursor
2419 0 : xCursor->moveToBookmark(pInfo->aPosition);
2420 : }
2421 0 : catch( const Exception& )
2422 : {
2423 : DBG_UNHANDLED_EXCEPTION();
2424 : }
2425 :
2426 : try
2427 : {
2428 : // let the grid snyc its display with the cursor
2429 0 : Reference< XPropertySet > xModelSet(getControlModel(), UNO_QUERY);
2430 : OSL_ENSURE(xModelSet.is(), "SbaXDataBrowserController::OnCanceledNotFound : no model set ?!");
2431 0 : Any aOld = xModelSet->getPropertyValue("DisplayIsSynchron");
2432 0 : xModelSet->setPropertyValue("DisplayIsSynchron", ::comphelper::makeBoolAny(true));
2433 0 : xModelSet->setPropertyValue("DisplayIsSynchron", aOld);
2434 : }
2435 0 : catch( const Exception& )
2436 : {
2437 : DBG_UNHANDLED_EXCEPTION();
2438 : }
2439 :
2440 0 : return 0L;
2441 : }
2442 :
2443 2 : IMPL_LINK_NOARG(SbaXDataBrowserController, OnAsyncGetCellFocus)
2444 : {
2445 1 : SbaGridControl* pVclGrid = getBrowserView() ? getBrowserView()->getVclControl() : NULL;
2446 : // if we have a controller, but the window for the controller doesn't have the focus, we correct this
2447 1 : if(pVclGrid)
2448 : {
2449 1 : if (!pVclGrid->IsEditing())
2450 0 : return 0L;
2451 :
2452 1 : if (pVclGrid->HasChildPathFocus())
2453 0 : pVclGrid->Controller()->GetWindow().GrabFocus();
2454 : }
2455 :
2456 1 : return 0L;
2457 : }
2458 :
2459 0 : void SbaXDataBrowserController::criticalFail()
2460 : {
2461 0 : InvalidateAll();
2462 0 : m_nRowSetPrivileges = 0;
2463 0 : }
2464 :
2465 1 : void SbaXDataBrowserController::LoadFinished(bool /*bWasSynch*/)
2466 : {
2467 1 : m_nRowSetPrivileges = 0;
2468 :
2469 1 : if (isValid() && !loadingCancelled())
2470 : {
2471 : // obtain cached values
2472 : try
2473 : {
2474 1 : Reference< XPropertySet > xFormProps( m_xLoadable, UNO_QUERY_THROW );
2475 1 : OSL_VERIFY( xFormProps->getPropertyValue( PROPERTY_PRIVILEGES ) >>= m_nRowSetPrivileges );
2476 : }
2477 0 : catch( const Exception& )
2478 : {
2479 : DBG_UNHANDLED_EXCEPTION();
2480 : }
2481 :
2482 : // switch the control to alive mode
2483 1 : getBrowserView()->getGridControl()->setDesignMode(sal_False);
2484 :
2485 1 : initializeParser();
2486 :
2487 1 : InvalidateAll();
2488 :
2489 1 : m_aAsyncGetCellFocus.Call();
2490 : }
2491 1 : }
2492 :
2493 1 : void SbaXDataBrowserController::initializeParser() const
2494 : {
2495 1 : if ( !m_xParser.is() )
2496 : {
2497 : // create a parser (needed for filtering/sorting)
2498 : try
2499 : {
2500 0 : const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
2501 0 : if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)))
2502 : { // (only if the statement isn't native)
2503 : // (it is allowed to use the PROPERTY_ISPASSTHROUGH : _after_ loading a form it is valid)
2504 0 : xFormSet->getPropertyValue(PROPERTY_SINGLESELECTQUERYCOMPOSER) >>= m_xParser;
2505 0 : }
2506 : }
2507 0 : catch(Exception&)
2508 : {
2509 : DBG_UNHANDLED_EXCEPTION();
2510 0 : m_xParser = NULL;
2511 : // no further handling, we ignore the error
2512 : }
2513 : }
2514 1 : }
2515 :
2516 1 : void SbaXDataBrowserController::loaded(const EventObject& /*aEvent*/) throw( RuntimeException, std::exception )
2517 : {
2518 : // not interested in
2519 : // we're loading within an separate thread and have a handling for it's "finished event"
2520 1 : }
2521 :
2522 0 : void SbaXDataBrowserController::unloading(const EventObject& /*aEvent*/) throw( RuntimeException, std::exception )
2523 : {
2524 : // not interested in
2525 0 : }
2526 :
2527 0 : void SbaXDataBrowserController::unloaded(const EventObject& /*aEvent*/) throw( RuntimeException, std::exception )
2528 : {
2529 0 : m_xParser.clear();
2530 0 : InvalidateAll();
2531 : // do this asynchronously, there are other listeners reacting on this message ...
2532 : // (it's a little hack : the grid columns are listening to this event, too, and their bound field may
2533 : // change as a reaction on that event. as we have no chance to be notified of this change (which is
2534 : // the one we're interested in) we give them time to do what they want to before invalidating our
2535 : // bound-field-dependent slots ....
2536 0 : }
2537 :
2538 0 : void SbaXDataBrowserController::reloading(const EventObject& /*aEvent*/) throw( RuntimeException, std::exception )
2539 : {
2540 : // not interested in
2541 0 : }
2542 :
2543 0 : void SbaXDataBrowserController::reloaded(const EventObject& /*aEvent*/) throw( RuntimeException, std::exception )
2544 : {
2545 0 : InvalidateAll();
2546 : // do this asynchronously, there are other listeners reacting on this message ...
2547 : // (it's a little hack : the grid columns are listening to this event, too, and their bound field may
2548 : // change as a reaction on that event. as we have no chance to be notified of this change (which is
2549 : // the one we're interested in) we give them time to do what they want to before invalidating our
2550 : // bound-field-dependent slots ....
2551 0 : }
2552 :
2553 3 : void SbaXDataBrowserController::enterFormAction()
2554 : {
2555 3 : if ( !m_nFormActionNestingLevel )
2556 : // first action -> reset
2557 2 : m_aCurrentError.clear();
2558 :
2559 3 : ++m_nFormActionNestingLevel;
2560 3 : }
2561 :
2562 3 : void SbaXDataBrowserController::leaveFormAction()
2563 : {
2564 : OSL_ENSURE( m_nFormActionNestingLevel > 0, "SbaXDataBrowserController::leaveFormAction : invalid call !" );
2565 3 : if ( --m_nFormActionNestingLevel > 0 )
2566 1 : return;
2567 :
2568 2 : if ( !m_aCurrentError.isValid() )
2569 2 : return;
2570 :
2571 0 : m_aAsyncDisplayError.Call();
2572 : }
2573 :
2574 203 : bool SbaXDataBrowserController::isLoaded() const
2575 : {
2576 203 : return m_xLoadable.is() && m_xLoadable->isLoaded();
2577 : }
2578 :
2579 248 : bool SbaXDataBrowserController::isValidCursor() const
2580 : {
2581 248 : if (!m_xColumnsSupplier.is())
2582 0 : return false;
2583 248 : Reference< ::com::sun::star::container::XNameAccess > xCols = m_xColumnsSupplier->getColumns();
2584 248 : if (!xCols.is() || !xCols->hasElements())
2585 0 : return false;
2586 :
2587 248 : bool bIsValid = !(m_xRowSet->isBeforeFirst() || m_xRowSet->isAfterLast());
2588 248 : if ( !bIsValid )
2589 : {
2590 0 : Reference<XPropertySet> xProp(m_xRowSet,UNO_QUERY);
2591 0 : bIsValid = ::cppu::any2bool(xProp->getPropertyValue(PROPERTY_ISNEW));
2592 0 : if ( !bIsValid )
2593 : {
2594 0 : bIsValid = m_xParser.is();
2595 0 : }
2596 : }
2597 248 : return bIsValid;
2598 : }
2599 :
2600 0 : sal_Int16 SbaXDataBrowserController::getCurrentColumnPosition()
2601 : {
2602 0 : Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
2603 0 : sal_Int16 nViewPos = -1;
2604 : try
2605 : {
2606 0 : if ( xGrid.is() )
2607 0 : nViewPos = xGrid->getCurrentColumnPosition();
2608 : }
2609 0 : catch(Exception&) {}
2610 0 : return nViewPos;
2611 : }
2612 :
2613 0 : void SbaXDataBrowserController::setCurrentColumnPosition( sal_Int16 _nPos )
2614 : {
2615 0 : Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
2616 : try
2617 : {
2618 0 : if ( -1 != _nPos )
2619 0 : xGrid->setCurrentColumnPosition(_nPos);
2620 : }
2621 0 : catch(Exception&) {}
2622 0 : }
2623 :
2624 0 : void SbaXDataBrowserController::BeforeDrop()
2625 : {
2626 0 : Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY);
2627 0 : if (xFormError.is())
2628 0 : xFormError->removeSQLErrorListener(static_cast<com::sun::star::sdb::XSQLErrorListener*>(this));
2629 0 : }
2630 :
2631 0 : void SbaXDataBrowserController::AfterDrop()
2632 : {
2633 0 : Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY);
2634 0 : if (xFormError.is())
2635 0 : xFormError->addSQLErrorListener(static_cast<com::sun::star::sdb::XSQLErrorListener*>(this));
2636 0 : }
2637 :
2638 1 : void SbaXDataBrowserController::addColumnListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
2639 : {
2640 : // ... all the grid columns
2641 1 : Reference< ::com::sun::star::container::XIndexContainer > xColumns(_xGridControlModel, UNO_QUERY);
2642 1 : if (xColumns.is())
2643 : {
2644 1 : sal_Int32 nCount = xColumns->getCount();
2645 1 : for (sal_Int32 i=0; i < nCount; ++i)
2646 : {
2647 0 : Reference< XPropertySet > xCol(xColumns->getByIndex(i),UNO_QUERY);
2648 0 : AddColumnListener(xCol);
2649 0 : }
2650 1 : }
2651 1 : }
2652 :
2653 0 : bool SbaXDataBrowserController::InitializeGridModel(const Reference< ::com::sun::star::form::XFormComponent > & /*xGrid*/)
2654 : {
2655 0 : return true;
2656 : }
2657 :
2658 36 : } // namespace dbaui
2659 :
2660 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|