fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / browser / brwctrlr.cxx
blob8bbc094747045cda7d43dcdef4c07c137a288a88
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
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>
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>
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;
106 #define HANDLE_SQL_ERRORS( action, successflag, context, message ) \
107 try \
109 successflag = false; \
110 action; \
111 successflag = true; \
113 catch(SQLException& e) \
115 SQLException aError = ::dbtools::prependErrorInfo(e, *this, context); \
116 ::com::sun::star::sdb::SQLErrorEvent aEvent; \
117 aEvent.Reason <<= aError; \
118 errorOccured(aEvent); \
120 catch(Exception&) \
122 DBG_UNHANDLED_EXCEPTION(); \
125 #define DO_SAFE( action, message ) try { action; } catch(Exception&) { SAL_WARN("dbaccess.ui",message); } ;
127 namespace dbaui
130 // OParameterContinuation
131 class OParameterContinuation : public OInteraction< XInteractionSupplyParameters >
133 Sequence< PropertyValue > m_aValues;
135 public:
136 OParameterContinuation() { }
138 Sequence< PropertyValue > getValues() const { return m_aValues; }
140 // XInteractionSupplyParameters
141 virtual void SAL_CALL setParameters( const Sequence< PropertyValue >& _rValues ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
144 void SAL_CALL OParameterContinuation::setParameters( const Sequence< PropertyValue >& _rValues ) throw(RuntimeException, std::exception)
146 m_aValues = _rValues;
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 >
156 friend class SbaXDataBrowserController;
157 ::cppu::OInterfaceContainerHelper m_aActivateListeners;
158 SbaXDataBrowserController* m_pOwner;
160 public:
161 FormControllerImpl(SbaXDataBrowserController* pOwner);
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
241 protected:
242 virtual ~FormControllerImpl();
245 SbaXDataBrowserController::FormControllerImpl::FormControllerImpl(SbaXDataBrowserController* _pOwner)
246 :m_aActivateListeners(_pOwner->getMutex())
247 ,m_pOwner(_pOwner)
250 OSL_ENSURE(m_pOwner, "SbaXDataBrowserController::FormControllerImpl::FormControllerImpl : invalid Owner !");
253 SbaXDataBrowserController::FormControllerImpl::~FormControllerImpl()
258 Reference< runtime::XFormOperations > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getFormOperations() throw (RuntimeException, std::exception)
260 return FormOperations::createWithFormController( m_pOwner->m_xContext, this );
263 Reference< ::com::sun::star::awt::XControl > SbaXDataBrowserController::FormControllerImpl::getCurrentControl() throw( RuntimeException, std::exception )
265 return m_pOwner->getBrowserView() ? m_pOwner->getBrowserView()->getGridControl() : Reference< ::com::sun::star::awt::XControl > ();
268 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addActivateListener(const Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( RuntimeException, std::exception )
270 m_aActivateListeners.addInterface(l);
273 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeActivateListener(const Reference< ::com::sun::star::form::XFormControllerListener > & l) throw( RuntimeException, std::exception )
275 m_aActivateListeners.removeInterface(l);
278 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addChildController( const Reference< runtime::XFormController >& /*_ChildController*/ ) throw( RuntimeException, IllegalArgumentException, std::exception )
280 // not supported
281 throw IllegalArgumentException( OUString(), *this, 1 );
284 Reference< runtime::XFormControllerContext > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getContext() throw (RuntimeException, std::exception)
286 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::getContext: no support!!" );
287 return NULL;
290 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setContext( const Reference< runtime::XFormControllerContext >& /*_context*/ ) throw (RuntimeException, std::exception)
292 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::setContext: no support!!" );
295 Reference< XInteractionHandler > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getInteractionHandler() throw (RuntimeException, std::exception)
297 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::getInteractionHandler: no support!!" );
298 return NULL;
301 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setInteractionHandler( const Reference< XInteractionHandler >& /*_interactionHandler*/ ) throw (RuntimeException, std::exception)
303 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::setInteractionHandler: no support!!" );
306 Reference< XInterface > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getParent( ) throw (RuntimeException, std::exception)
308 // don't have any parent form controllers
309 return NULL;
312 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setParent( const Reference< XInterface >& /*Parent*/ ) throw (NoSupportException, RuntimeException, std::exception)
314 throw NoSupportException( OUString(), *this );
317 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::dispose( ) throw (RuntimeException, std::exception)
319 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::dispose: no, you do *not* want to do this!" );
322 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addEventListener( const Reference< XEventListener >& /*xListener*/ ) throw (RuntimeException, std::exception)
324 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addEventListener: no support!!" );
327 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeEventListener( const Reference< XEventListener >& /*aListener*/ ) throw (RuntimeException, std::exception)
329 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeEventListener: no support!!" );
332 ::sal_Int32 SAL_CALL SbaXDataBrowserController::FormControllerImpl::getCount( ) throw (RuntimeException, std::exception)
334 // no sub controllers, never
335 return 0;
338 Any SAL_CALL SbaXDataBrowserController::FormControllerImpl::getByIndex( ::sal_Int32 /*Index*/ ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException, std::exception)
340 // no sub controllers, never
341 throw IndexOutOfBoundsException( OUString(), *this );
344 Type SAL_CALL SbaXDataBrowserController::FormControllerImpl::getElementType( ) throw (RuntimeException, std::exception)
346 return ::cppu::UnoType< runtime::XFormController >::get();
349 sal_Bool SAL_CALL SbaXDataBrowserController::FormControllerImpl::hasElements( ) throw (RuntimeException, std::exception)
351 // no sub controllers, never
352 return false;
355 Reference< XEnumeration > SAL_CALL SbaXDataBrowserController::FormControllerImpl::createEnumeration( ) throw (RuntimeException, std::exception)
357 return new ::comphelper::OEnumerationByIndex( this );
360 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addModifyListener( const Reference< XModifyListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
362 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addModifyListener: no support!" );
365 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeModifyListener( const Reference< XModifyListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
367 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeModifyListener: no support!" );
370 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addConfirmDeleteListener( const Reference< XConfirmDeleteListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
372 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addConfirmDeleteListener: no support!" );
375 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeConfirmDeleteListener( const Reference< XConfirmDeleteListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
377 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeConfirmDeleteListener: no support!" );
380 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addSQLErrorListener( const Reference< XSQLErrorListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
382 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addSQLErrorListener: no support!" );
385 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeSQLErrorListener( const Reference< XSQLErrorListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
387 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeSQLErrorListener: no support!" );
390 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addRowSetApproveListener( const Reference< XRowSetApproveListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
392 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addRowSetApproveListener: no support!" );
395 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeRowSetApproveListener( const Reference< XRowSetApproveListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
397 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeRowSetApproveListener: no support!" );
400 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addDatabaseParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
402 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addDatabaseParameterListener: no support!" );
405 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeDatabaseParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
407 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeDatabaseParameterListener: no support!" );
410 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::addParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
412 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::addParameterListener: no support!" );
415 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::removeParameterListener( const Reference< XDatabaseParameterListener >& /*_Listener*/ ) throw (RuntimeException, std::exception)
417 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::FormControllerImpl::removeParameterListener: no support!" );
420 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setMode( const OUString& _rMode ) throw (NoSupportException, RuntimeException, std::exception)
422 if ( !supportsMode( _rMode ) )
423 throw NoSupportException();
426 OUString SAL_CALL SbaXDataBrowserController::FormControllerImpl::getMode( ) throw (RuntimeException, std::exception)
428 return OUString( "DataMode" );
431 Sequence< OUString > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getSupportedModes( ) throw (RuntimeException, std::exception)
433 Sequence< OUString > aModes(1);
434 aModes[1] = "DataMode";
435 return aModes;
438 sal_Bool SAL_CALL SbaXDataBrowserController::FormControllerImpl::supportsMode( const OUString& aMode ) throw (RuntimeException, std::exception)
440 return aMode == "DataMode";
443 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setModel(const Reference< ::com::sun::star::awt::XTabControllerModel > & /*Model*/) throw( RuntimeException, std::exception )
445 SAL_WARN("dbaccess.ui","SbaXDataBrowserController::FormControllerImpl::setModel : invalid call, can't change my model !");
448 Reference< ::com::sun::star::awt::XTabControllerModel > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getModel() throw( RuntimeException, std::exception )
450 return Reference< XTabControllerModel >(m_pOwner->getRowSet(), UNO_QUERY);
453 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setContainer(const Reference< ::com::sun::star::awt::XControlContainer > & /*_Container*/) throw( RuntimeException, std::exception )
455 SAL_WARN("dbaccess.ui","SbaXDataBrowserController::FormControllerImpl::setContainer : invalid call, can't change my container !");
458 Reference< ::com::sun::star::awt::XControlContainer > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getContainer() throw( RuntimeException, std::exception )
460 if (m_pOwner->getBrowserView())
461 return m_pOwner->getBrowserView()->getContainer();
462 return Reference< ::com::sun::star::awt::XControlContainer > ();
465 Sequence< Reference< ::com::sun::star::awt::XControl > > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getControls() throw( RuntimeException, std::exception )
467 if (m_pOwner->getBrowserView())
469 Reference< ::com::sun::star::awt::XControl > xGrid = m_pOwner->getBrowserView()->getGridControl();
470 return Sequence< Reference< ::com::sun::star::awt::XControl > >(&xGrid, 1);
472 return Sequence< Reference< ::com::sun::star::awt::XControl > >();
475 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::autoTabOrder() throw( RuntimeException, std::exception )
477 SAL_WARN("dbaccess.ui","SbaXDataBrowserController::FormControllerImpl::autoTabOrder : nothing to do (always have only one control) !");
480 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::activateTabOrder() throw( RuntimeException, std::exception )
482 SAL_WARN("dbaccess.ui","SbaXDataBrowserController::FormControllerImpl::activateTabOrder : nothing to do (always have only one control) !");
485 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::activateFirst() throw( RuntimeException, std::exception )
487 if (m_pOwner->getBrowserView())
488 m_pOwner->getBrowserView()->getVclControl()->ActivateCell();
491 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::activateLast() throw( RuntimeException, std::exception )
493 if (m_pOwner->getBrowserView())
494 m_pOwner->getBrowserView()->getVclControl()->ActivateCell();
497 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::frameAction(const ::com::sun::star::frame::FrameActionEvent& /*aEvent*/) throw( RuntimeException, std::exception )
501 void SAL_CALL SbaXDataBrowserController::FormControllerImpl::disposing(const ::com::sun::star::lang::EventObject& /*Source*/) throw( RuntimeException, std::exception )
503 // nothing to do
504 // we don't add ourself as listener to any broadcasters, so we are not resposible for removing us
507 // SbaXDataBrowserController
508 Sequence< Type > SAL_CALL SbaXDataBrowserController::getTypes( ) throw (RuntimeException, std::exception)
510 return ::comphelper::concatSequences(
511 SbaXDataBrowserController_Base::getTypes(),
512 m_pFormControllerImpl->getTypes()
516 Sequence< sal_Int8 > SAL_CALL SbaXDataBrowserController::getImplementationId( ) throw (RuntimeException, std::exception)
518 return css::uno::Sequence<sal_Int8>();
521 Any SAL_CALL SbaXDataBrowserController::queryInterface(const Type& _rType) throw (RuntimeException, std::exception)
523 // check for our additional interfaces
524 Any aRet = SbaXDataBrowserController_Base::queryInterface(_rType);
526 // check for our aggregate (implementing the XFormController)
527 if (!aRet.hasValue())
528 aRet = m_xFormControllerImpl->queryAggregation(_rType);
530 // no more to offer
531 return aRet;
534 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 ,m_bCannotSelectUnfiltered( true )
548 // create the form controller aggregate
549 osl_atomic_increment(&m_refCount);
551 m_pFormControllerImpl = new FormControllerImpl(this);
552 m_xFormControllerImpl = m_pFormControllerImpl;
553 m_xFormControllerImpl->setDelegator(*this);
555 osl_atomic_decrement(&m_refCount);
557 m_aInvalidateClipboard.SetTimeoutHdl(LINK(this, SbaXDataBrowserController, OnInvalidateClipboard));
558 m_aInvalidateClipboard.SetTimeout(300);
561 SbaXDataBrowserController::~SbaXDataBrowserController()
563 // deleteView();
564 // release the aggregated form controller
565 if (m_xFormControllerImpl.is())
567 Reference< XInterface > xEmpty;
568 m_xFormControllerImpl->setDelegator(xEmpty);
573 void SbaXDataBrowserController::startFrameListening( const Reference< XFrame >& _rxFrame )
575 SbaXDataBrowserController_Base::startFrameListening( _rxFrame );
577 Reference< XFrameActionListener > xAggListener;
578 if ( m_xFormControllerImpl.is() )
579 m_xFormControllerImpl->queryAggregation( cppu::UnoType<XFrameActionListener>::get() ) >>= xAggListener;
581 if ( _rxFrame.is() && xAggListener.is() )
582 _rxFrame->addFrameActionListener( xAggListener );
585 void SbaXDataBrowserController::stopFrameListening( const Reference< XFrame >& _rxFrame )
587 SbaXDataBrowserController_Base::stopFrameListening( _rxFrame );
589 Reference< XFrameActionListener > xAggListener;
590 if ( m_xFormControllerImpl.is() )
591 m_xFormControllerImpl->queryAggregation( cppu::UnoType<XFrameActionListener>::get() ) >>= xAggListener;
593 if ( _rxFrame.is() && xAggListener.is() )
594 _rxFrame->removeFrameActionListener( xAggListener );
597 void SbaXDataBrowserController::onStartLoading( const Reference< XLoadable >& _rxLoadable )
599 m_bLoadCanceled = false;
600 m_bCannotSelectUnfiltered = false;
602 Reference< XWarningsSupplier > xWarnings( _rxLoadable, UNO_QUERY );
603 if ( xWarnings.is() )
607 xWarnings->clearWarnings();
609 catch(const SQLException& )
611 DBG_UNHANDLED_EXCEPTION();
616 void SbaXDataBrowserController::impl_checkForCannotSelectUnfiltered( const SQLExceptionInfo& _rError )
618 ::connectivity::SQLError aError( getORB() );
619 ::connectivity::ErrorCode nErrorCode( connectivity::SQLError::getErrorCode( sdb::ErrorCondition::DATA_CANNOT_SELECT_UNFILTERED ) );
620 if ( ((const SQLException*)_rError)->ErrorCode == nErrorCode )
622 m_bCannotSelectUnfiltered = true;
623 InvalidateFeature( ID_BROWSER_FILTERCRIT );
627 bool SbaXDataBrowserController::reloadForm( const Reference< XLoadable >& _rxLoadable )
629 WaitObject aWO(getBrowserView());
631 onStartLoading( _rxLoadable );
633 FormErrorHelper aReportError(this);
634 if (_rxLoadable->isLoaded())
635 _rxLoadable->reload();
636 else
637 _rxLoadable->load();
639 m_xParser.clear();
640 const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
641 if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)))
642 xFormSet->getPropertyValue(PROPERTY_SINGLESELECTQUERYCOMPOSER) >>= m_xParser;
643 #if 0
645 const Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY );
646 const Reference< XSingleSelectQueryAnalyzer > xAnalyzer( xRowSetProps->getPropertyValue( PROPERTY_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY );
647 if ( xAnalyzer.is() )
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 )
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;
663 #endif
665 Reference< XWarningsSupplier > xWarnings( _rxLoadable, UNO_QUERY );
666 if ( xWarnings.is() )
670 SQLExceptionInfo aInfo( xWarnings->getWarnings() );
671 if ( aInfo.isValid() )
673 showError( aInfo );
674 impl_checkForCannotSelectUnfiltered( aInfo );
677 catch(const SQLException& )
679 DBG_UNHANDLED_EXCEPTION();
683 return _rxLoadable->isLoaded();
686 void SbaXDataBrowserController::initFormatter()
688 // create a formatter working with the connections format supplier
689 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(::dbtools::getConnection(m_xRowSet), true, getORB()));
691 if(xSupplier.is())
693 // create a new formatter
694 m_xFormatter = Reference< util::XNumberFormatter > (
695 util::NumberFormatter::create(getORB()), UNO_QUERY_THROW);
696 m_xFormatter->attachNumberFormatsSupplier(xSupplier);
698 else // clear the formatter
699 m_xFormatter = NULL;
702 void SbaXDataBrowserController::describeSupportedFeatures()
704 SbaXDataBrowserController_Base::describeSupportedFeatures();
705 implDescribeSupportedFeature( ".uno:FormSlots/undoRecord", ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS );
706 implDescribeSupportedFeature( ".uno:FormController/undoRecord", ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS );
707 implDescribeSupportedFeature( ".uno:RecUndo", ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS );
708 implDescribeSupportedFeature( ".uno:FormSlots/saveRecord", ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS );
709 implDescribeSupportedFeature( ".uno:FormController/saveRecord", ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS );
710 implDescribeSupportedFeature( ".uno:RecSave", ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS );
711 implDescribeSupportedFeature( ".uno:Save", ID_BROWSER_SAVERECORD, CommandGroup::DOCUMENT );
712 implDescribeSupportedFeature( ".uno:RecSearch", SID_FM_SEARCH, CommandGroup::CONTROLS );
713 implDescribeSupportedFeature( ".uno:AutoFilter", SID_FM_AUTOFILTER, CommandGroup::CONTROLS );
714 implDescribeSupportedFeature( ".uno:Refresh", SID_FM_REFRESH, CommandGroup::CONTROLS );
715 implDescribeSupportedFeature( ".uno:OrderCrit", SID_FM_ORDERCRIT, CommandGroup::CONTROLS );
716 implDescribeSupportedFeature( ".uno:RemoveFilterSort", SID_FM_REMOVE_FILTER_SORT,CommandGroup::CONTROLS );
717 implDescribeSupportedFeature( ".uno:FormFiltered", SID_FM_FORM_FILTERED, CommandGroup::CONTROLS );
718 implDescribeSupportedFeature( ".uno:FilterCrit", SID_FM_FILTERCRIT, CommandGroup::CONTROLS );
719 implDescribeSupportedFeature( ".uno:Sortup", ID_BROWSER_SORTUP, CommandGroup::CONTROLS );
720 implDescribeSupportedFeature( ".uno:SortDown", ID_BROWSER_SORTDOWN, CommandGroup::CONTROLS );
721 implDescribeSupportedFeature( ".uno:FormSlots/deleteRecord", SID_FM_DELETEROWS, CommandGroup::EDIT );
722 implDescribeSupportedFeature( ".uno:FormSlots/insertRecord", ID_BROWSER_INSERT_ROW, CommandGroup::INSERT );
725 bool SbaXDataBrowserController::Construct(vcl::Window* pParent)
727 // create/initialize the form and the grid model
728 m_xRowSet = CreateForm();
729 if (!m_xRowSet.is())
730 return false;
732 m_xColumnsSupplier.set(m_xRowSet,UNO_QUERY);
733 m_xLoadable.set(m_xRowSet,UNO_QUERY);
735 Reference< XPropertySet > xFormProperties( m_xRowSet, UNO_QUERY );
736 if ( !InitializeForm( xFormProperties ) )
737 return false;
739 m_xGridModel = CreateGridModel();
740 if (!m_xGridModel.is())
741 return false;
743 // set the formatter if available
744 initFormatter();
746 // we want to have a grid with a "flat" border
747 Reference< XPropertySet > xGridSet(m_xGridModel, UNO_QUERY);
748 if ( xGridSet.is() )
749 xGridSet->setPropertyValue(PROPERTY_BORDER, makeAny((sal_Int16)2));
752 // marry them
753 Reference< ::com::sun::star::container::XNameContainer > xNameCont(m_xRowSet, UNO_QUERY);
755 OUString sText(ModuleRes(STR_DATASOURCE_GRIDCONTROL_NAME));
756 xNameCont->insertByName(OUString(sText), makeAny(m_xGridModel));
759 // create the view
760 setView( VclPtr<UnoDataBrowserView>::Create( pParent, *this, getORB() ) );
761 if (!getBrowserView())
762 return false;
764 // late construction
765 bool bSuccess = false;
768 getBrowserView()->Construct(getControlModel());
769 bSuccess = true;
771 catch(SQLException&)
774 catch(Exception&)
776 SAL_WARN("dbaccess.ui","SbaXDataBrowserController::Construct : the construction of UnoDataBrowserView failed !");
779 if (!bSuccess)
781 // deleteView();
782 return false;
785 // now that we have a view we can create the clipboard listener
786 m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( getView() );
787 m_aSystemClipboard.StartClipboardListening( );
789 m_pClipbordNotifier = new TransferableClipboardListener( LINK( this, SbaXDataBrowserController, OnClipboardChanged ) );
790 m_pClipbordNotifier->acquire();
791 m_pClipbordNotifier->AddRemoveListener( getView(), true );
793 // this call create the toolbox
794 SbaXDataBrowserController_Base::Construct(pParent);
796 getBrowserView()->Show();
798 // set the callbacks for the grid control
799 SbaGridControl* pVclGrid = getBrowserView()->getVclControl();
800 OSL_ENSURE(pVclGrid, "SbaXDataBrowserController::Construct : have no VCL control !");
801 pVclGrid->SetMasterListener(this);
803 // add listeners ...
805 // ... to the form model
806 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
807 if (xFormSet.is())
809 xFormSet->addPropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this));
810 xFormSet->addPropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this));
811 xFormSet->addPropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this));
812 xFormSet->addPropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this));
813 xFormSet->addPropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this));
814 xFormSet->addPropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this));
815 xFormSet->addPropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this));
816 xFormSet->addPropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this));
818 Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY);
819 if (xFormError.is())
820 xFormError->addSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
822 if (m_xLoadable.is())
823 m_xLoadable->addLoadListener(this);
825 Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(getRowSet(), UNO_QUERY);
826 if (xFormParameter.is())
827 xFormParameter->addParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this);
829 addModelListeners(getControlModel());
830 addControlListeners(getBrowserView()->getGridControl());
832 // load the form
833 return LoadForm();
836 bool SbaXDataBrowserController::LoadForm()
838 reloadForm( m_xLoadable );
839 return true;
842 void SbaXDataBrowserController::AddColumnListener(const Reference< XPropertySet > & /*xCol*/)
844 // we're not interested in any column properties ...
847 void SbaXDataBrowserController::RemoveColumnListener(const Reference< XPropertySet > & /*xCol*/)
851 Reference< XRowSet > SbaXDataBrowserController::CreateForm()
853 return Reference< XRowSet > (
854 getORB()->getServiceManager()->createInstanceWithContext("com.sun.star.form.component.Form", getORB()),
855 UNO_QUERY);
858 Reference< ::com::sun::star::form::XFormComponent > SbaXDataBrowserController::CreateGridModel()
860 return Reference< ::com::sun::star::form::XFormComponent > (
861 getORB()->getServiceManager()->createInstanceWithContext("com.sun.star.form.component.GridControl", getORB()),
862 UNO_QUERY);
865 void SbaXDataBrowserController::addModelListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
867 // ... all the grid columns
868 addColumnListeners(_xGridControlModel);
870 // (we are interested in all columns the grid has (and only in these) so we have to listen to the container, too)
871 Reference< ::com::sun::star::container::XContainer > xColContainer(_xGridControlModel, UNO_QUERY);
872 if (xColContainer.is())
873 xColContainer->addContainerListener((::com::sun::star::container::XContainerListener*)this);
875 Reference< ::com::sun::star::form::XReset > xReset(_xGridControlModel, UNO_QUERY);
876 if (xReset.is())
877 xReset->addResetListener((::com::sun::star::form::XResetListener*)this);
880 void SbaXDataBrowserController::removeModelListeners(const Reference< XControlModel > & _xGridControlModel)
882 // every single column model
883 Reference< XIndexContainer > xColumns(_xGridControlModel, UNO_QUERY);
884 if (xColumns.is())
886 sal_Int32 nCount = xColumns->getCount();
887 for (sal_uInt16 i=0; i < nCount; ++i)
889 Reference< XPropertySet > xCol(xColumns->getByIndex(i),UNO_QUERY);
890 RemoveColumnListener(xCol);
894 Reference< XContainer > xColContainer(_xGridControlModel, UNO_QUERY);
895 if (xColContainer.is())
896 xColContainer->removeContainerListener( this );
898 Reference< XReset > xReset(_xGridControlModel, UNO_QUERY);
899 if (xReset.is())
900 xReset->removeResetListener( this );
903 void SbaXDataBrowserController::addControlListeners(const Reference< ::com::sun::star::awt::XControl > & _xGridControl)
905 // to ge the 'modified' for the current cell
906 Reference< XModifyBroadcaster > xBroadcaster(getBrowserView()->getGridControl(), UNO_QUERY);
907 if (xBroadcaster.is())
908 xBroadcaster->addModifyListener(static_cast<XModifyListener*>(this));
910 // introduce ourself as dispatch provider for the grid
911 Reference< XDispatchProviderInterception > xInterception(getBrowserView()->getGridControl(), UNO_QUERY);
912 if (xInterception.is())
913 xInterception->registerDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
915 // add as focus listener to the control (needed for the form controller functionality)
916 Reference< XWindow > xWindow(_xGridControl, UNO_QUERY);
917 if (xWindow.is())
918 xWindow->addFocusListener(this);
921 void SbaXDataBrowserController::removeControlListeners(const Reference< ::com::sun::star::awt::XControl > & _xGridControl)
923 Reference< XModifyBroadcaster > xBroadcaster(_xGridControl, UNO_QUERY);
924 if (xBroadcaster.is())
925 xBroadcaster->removeModifyListener(static_cast<XModifyListener*>(this));
927 Reference< XDispatchProviderInterception > xInterception(_xGridControl, UNO_QUERY);
928 if (xInterception.is())
929 xInterception->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
931 Reference< XWindow > xWindow(_xGridControl, UNO_QUERY);
932 if (xWindow.is())
933 xWindow->removeFocusListener(this);
936 void SAL_CALL SbaXDataBrowserController::focusGained(const FocusEvent& /*e*/) throw( RuntimeException, std::exception )
938 // notify our activate listeners (registered on the form controller aggregate)
939 EventObject aEvt(*this);
940 ::cppu::OInterfaceIteratorHelper aIter(m_pFormControllerImpl->m_aActivateListeners);
941 while (aIter.hasMoreElements())
942 static_cast<XFormControllerListener*>(aIter.next())->formActivated(aEvt);
945 void SAL_CALL SbaXDataBrowserController::focusLost(const FocusEvent& e) throw( RuntimeException, std::exception )
947 // some general checks
948 if (!getBrowserView() || !getBrowserView()->getGridControl().is())
949 return;
950 Reference< XVclWindowPeer > xMyGridPeer(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY);
951 if (!xMyGridPeer.is())
952 return;
953 Reference< XWindowPeer > xNextControlPeer(e.NextFocus, UNO_QUERY);
954 if (!xNextControlPeer.is())
955 return;
957 // don't do a notification if it remains in the family (i.e. a child of the grid control gets the focus)
958 if (xMyGridPeer->isChild(xNextControlPeer))
959 return;
961 if (xMyGridPeer == xNextControlPeer)
962 return;
964 // notify the listeners that the "form" we represent has been deactivated
965 EventObject aEvt(*this);
966 ::cppu::OInterfaceIteratorHelper aIter(m_pFormControllerImpl->m_aActivateListeners);
967 while (aIter.hasMoreElements())
968 static_cast<XFormControllerListener*>(aIter.next())->formDeactivated(aEvt);
970 // commit the changes of the grid control (as we're deactivated)
971 Reference< XBoundComponent > xCommitable(getBrowserView()->getGridControl(), UNO_QUERY);
972 if (xCommitable.is())
973 xCommitable->commit();
974 else
975 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::focusLost : why is my control not commitable ?");
978 void SbaXDataBrowserController::disposingGridControl(const ::com::sun::star::lang::EventObject& /*Source*/)
980 removeControlListeners(getBrowserView()->getGridControl());
983 void SbaXDataBrowserController::disposingGridModel(const ::com::sun::star::lang::EventObject& /*Source*/)
985 removeModelListeners(getControlModel());
988 void SbaXDataBrowserController::disposingFormModel(const ::com::sun::star::lang::EventObject& Source)
990 Reference< XPropertySet > xSourceSet(Source.Source, UNO_QUERY);
991 if (xSourceSet.is())
993 xSourceSet->removePropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this));
994 xSourceSet->removePropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this));
995 xSourceSet->removePropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this));
996 xSourceSet->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this));
997 xSourceSet->removePropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this));
998 xSourceSet->removePropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this));
999 xSourceSet->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this));
1000 xSourceSet->removePropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this));
1003 Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(Source.Source, UNO_QUERY);
1004 if (xFormError.is())
1005 xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
1007 if (m_xLoadable.is())
1008 m_xLoadable->removeLoadListener(this);
1010 Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(Source.Source, UNO_QUERY);
1011 if (xFormParameter.is())
1012 xFormParameter->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this);
1015 void SbaXDataBrowserController::disposingColumnModel(const ::com::sun::star::lang::EventObject& Source)
1017 RemoveColumnListener(Reference< XPropertySet > (Source.Source, UNO_QUERY));
1020 void SbaXDataBrowserController::disposing(const EventObject& Source) throw( RuntimeException, std::exception )
1022 // if it's a component other than our aggregate, forward it to the aggregate
1023 if ( m_xFormControllerImpl != Source.Source )
1025 Reference< XEventListener > xAggListener;
1026 m_xFormControllerImpl->queryAggregation( cppu::UnoType<decltype(xAggListener)>::get() ) >>= xAggListener;
1027 if ( xAggListener.is( ))
1028 xAggListener->disposing( Source );
1031 // is it the grid control ?
1032 if (getBrowserView())
1034 Reference< ::com::sun::star::awt::XControl > xSourceControl(Source.Source, UNO_QUERY);
1035 if (xSourceControl == getBrowserView()->getGridControl())
1036 disposingGridControl(Source);
1039 // its model (the container of the columns) ?
1040 if (getControlModel() == Source.Source)
1041 disposingGridModel(Source);
1043 // the form's model ?
1044 if ((getRowSet() == Source.Source))
1045 disposingFormModel(Source);
1047 // from a single column model ?
1048 Reference< XPropertySet > xSourceSet(Source.Source, UNO_QUERY);
1049 if (xSourceSet.is())
1051 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 if (xInfo->hasPropertyByName(PROPERTY_WIDTH))
1054 disposingColumnModel(Source);
1056 SbaXDataBrowserController_Base::OGenericUnoController::disposing( Source );
1059 void SAL_CALL SbaXDataBrowserController::setIdentifier( const OUString& _Identifier ) throw (RuntimeException, std::exception)
1061 ::osl::MutexGuard aGuard( getMutex() );
1062 m_sModuleIdentifier = _Identifier;
1065 OUString SAL_CALL SbaXDataBrowserController::getIdentifier( ) throw (RuntimeException, std::exception)
1067 ::osl::MutexGuard aGuard( getMutex() );
1068 return m_sModuleIdentifier;
1071 void SbaXDataBrowserController::propertyChange(const PropertyChangeEvent& evt) throw ( RuntimeException, std::exception )
1073 Reference< XPropertySet > xSource(evt.Source, UNO_QUERY);
1074 if (!xSource.is())
1075 return;
1077 SolarMutexGuard aGuard;
1078 // the IsModified changed to sal_False ?
1079 if ( evt.PropertyName == PROPERTY_ISMODIFIED
1080 && !::comphelper::getBOOL(evt.NewValue)
1082 { // -> the current field isn't modified anymore, too
1083 setCurrentModified( false );
1086 // switching to a new record ?
1087 if ( evt.PropertyName == PROPERTY_ISNEW
1088 && ::comphelper::getBOOL(evt.NewValue)
1091 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 InvalidateAll();
1097 if (evt.PropertyName == PROPERTY_FILTER)
1099 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1101 else if (evt.PropertyName == PROPERTY_HAVING_CLAUSE)
1103 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1105 else if (evt.PropertyName == PROPERTY_ORDER)
1107 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1110 // a new record count ? -> may be our search availability has changed
1111 if (evt.PropertyName == PROPERTY_ROWCOUNT)
1113 sal_Int32 nNewValue = 0, nOldValue = 0;
1114 evt.NewValue >>= nNewValue;
1115 evt.OldValue >>= nOldValue;
1116 if((nOldValue == 0 && nNewValue != 0) || (nOldValue != 0 && nNewValue == 0))
1117 InvalidateAll();
1121 void SbaXDataBrowserController::modified(const ::com::sun::star::lang::EventObject& /*aEvent*/) throw( RuntimeException, std::exception )
1123 setCurrentModified( true );
1126 void SbaXDataBrowserController::elementInserted(const ::com::sun::star::container::ContainerEvent& evt) throw( RuntimeException, std::exception )
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 Reference< XPropertySet > xNewColumn(evt.Element,UNO_QUERY);
1131 if ( xNewColumn.is() )
1132 AddColumnListener(xNewColumn);
1135 void SbaXDataBrowserController::elementRemoved(const ::com::sun::star::container::ContainerEvent& evt) throw( RuntimeException, std::exception )
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 Reference< XPropertySet > xOldColumn(evt.Element,UNO_QUERY);
1140 if ( xOldColumn.is() )
1141 RemoveColumnListener(xOldColumn);
1144 void SbaXDataBrowserController::elementReplaced(const ::com::sun::star::container::ContainerEvent& evt) throw( RuntimeException, std::exception )
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 Reference< XPropertySet > xOldColumn(evt.ReplacedElement,UNO_QUERY);
1149 if ( xOldColumn.is() )
1150 RemoveColumnListener(xOldColumn);
1152 Reference< XPropertySet > xNewColumn(evt.Element,UNO_QUERY);
1153 if ( xNewColumn.is() )
1154 AddColumnListener(xNewColumn);
1157 sal_Bool SbaXDataBrowserController::suspend(sal_Bool /*bSuspend*/) throw( RuntimeException, std::exception )
1159 m_aAsyncGetCellFocus.CancelCall();
1160 m_aAsyncDisplayError.CancelCall();
1161 m_aAsyncInvalidateAll.CancelCall();
1163 bool bSuccess = SaveModified();
1164 return bSuccess;
1167 void SbaXDataBrowserController::disposing()
1169 // the base class
1170 SbaXDataBrowserController_Base::OGenericUnoController::disposing();
1172 // the data source
1173 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1174 if (xFormSet.is())
1176 xFormSet->removePropertyChangeListener(PROPERTY_ISNEW, static_cast<XPropertyChangeListener*>(this));
1177 xFormSet->removePropertyChangeListener(PROPERTY_ISMODIFIED, static_cast<XPropertyChangeListener*>(this));
1178 xFormSet->removePropertyChangeListener(PROPERTY_ROWCOUNT, static_cast<XPropertyChangeListener*>(this));
1179 xFormSet->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND, static_cast<XPropertyChangeListener*>(this));
1180 xFormSet->removePropertyChangeListener(PROPERTY_ORDER, static_cast<XPropertyChangeListener*>(this));
1181 xFormSet->removePropertyChangeListener(PROPERTY_FILTER, static_cast<XPropertyChangeListener*>(this));
1182 xFormSet->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE, static_cast<XPropertyChangeListener*>(this));
1183 xFormSet->removePropertyChangeListener(PROPERTY_APPLYFILTER, static_cast<XPropertyChangeListener*>(this));
1186 Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY);
1187 if (xFormError.is())
1188 xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
1190 if (m_xLoadable.is())
1191 m_xLoadable->removeLoadListener(this);
1193 Reference< ::com::sun::star::form::XDatabaseParameterBroadcaster > xFormParameter(getRowSet(), UNO_QUERY);
1194 if (xFormParameter.is())
1195 xFormParameter->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener*)this);
1197 removeModelListeners(getControlModel());
1199 if ( getView() && m_pClipbordNotifier )
1201 m_pClipbordNotifier->ClearCallbackLink();
1202 m_pClipbordNotifier->AddRemoveListener( getView(), false );
1203 m_pClipbordNotifier->release();
1204 m_pClipbordNotifier = NULL;
1207 if (getBrowserView())
1209 removeControlListeners(getBrowserView()->getGridControl());
1210 // don't delete explicitly, this is done by the owner (and user) of this controller (me hopes ...)
1211 clearView();
1214 if(m_aInvalidateClipboard.IsActive())
1215 m_aInvalidateClipboard.Stop();
1217 // dispose the row set
1220 ::comphelper::disposeComponent(m_xRowSet);
1222 m_xRowSet = NULL;
1223 m_xColumnsSupplier = NULL;
1224 m_xLoadable = NULL;
1226 catch(Exception&)
1228 DBG_UNHANDLED_EXCEPTION();
1230 m_xParser.clear();
1231 // don't dispose, just reset - it's owned by the RowSet
1234 void SbaXDataBrowserController::frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( RuntimeException, std::exception )
1236 ::osl::MutexGuard aGuard( getMutex() );
1238 SbaXDataBrowserController_Base::frameAction( aEvent );
1240 if ( aEvent.Source == getFrame() )
1241 switch ( aEvent.Action )
1243 case FrameAction_FRAME_ACTIVATED:
1244 case FrameAction_FRAME_UI_ACTIVATED:
1245 // ensure that the active cell (if any) has the focus
1246 m_aAsyncGetCellFocus.Call();
1247 // start the clipboard timer
1248 if (getBrowserView() && getBrowserView()->getVclControl() && !m_aInvalidateClipboard.IsActive())
1250 m_aInvalidateClipboard.Start();
1251 OnInvalidateClipboard( NULL );
1253 break;
1254 case FrameAction_FRAME_DEACTIVATING:
1255 case FrameAction_FRAME_UI_DEACTIVATING:
1256 // stop the clipboard invalidator
1257 if (getBrowserView() && getBrowserView()->getVclControl() && m_aInvalidateClipboard.IsActive())
1259 m_aInvalidateClipboard.Stop();
1260 OnInvalidateClipboard( NULL );
1262 // remove the "get cell focus"-event
1263 m_aAsyncGetCellFocus.CancelCall();
1264 break;
1265 default:
1266 break;
1270 IMPL_LINK_NOARG( SbaXDataBrowserController, OnAsyncDisplayError )
1272 if ( m_aCurrentError.isValid() )
1274 ScopedVclPtrInstance< OSQLMessageBox > aDlg( getBrowserView(), m_aCurrentError );
1275 aDlg->Execute();
1277 return 0L;
1280 void SbaXDataBrowserController::errorOccured(const ::com::sun::star::sdb::SQLErrorEvent& aEvent) throw( RuntimeException, std::exception )
1282 ::osl::MutexGuard aGuard( getMutex() );
1284 SQLExceptionInfo aInfo( aEvent.Reason );
1285 if ( !aInfo.isValid() )
1286 return;
1288 if ( m_nFormActionNestingLevel )
1290 OSL_ENSURE( !m_aCurrentError.isValid(), "SbaXDataBrowserController::errorOccurred: can handle one error per transaction only!" );
1291 m_aCurrentError = aInfo;
1293 else
1295 m_aCurrentError = aInfo;
1296 m_aAsyncDisplayError.Call();
1300 sal_Bool SbaXDataBrowserController::approveParameter(const ::com::sun::star::form::DatabaseParameterEvent& aEvent) throw( RuntimeException, std::exception )
1302 if (aEvent.Source != getRowSet())
1304 // not my data source -> allow anything
1305 SAL_WARN("dbaccess.ui","SbaXDataBrowserController::approveParameter : invalid event source !");
1306 return sal_True;
1309 Reference< ::com::sun::star::container::XIndexAccess > xParameters = aEvent.Parameters;
1310 SolarMutexGuard aSolarGuard;
1312 // default handling: instantiate an interaction handler and let it handle the parameter request
1315 // two continuations allowed: OK and Cancel
1316 OParameterContinuation* pParamValues = new OParameterContinuation;
1317 OInteractionAbort* pAbort = new OInteractionAbort;
1318 // the request
1319 ParametersRequest aRequest;
1320 aRequest.Parameters = xParameters;
1321 aRequest.Connection = getConnection(Reference< XRowSet >(aEvent.Source, UNO_QUERY));
1322 OInteractionRequest* pParamRequest = new OInteractionRequest(makeAny(aRequest));
1323 Reference< XInteractionRequest > xParamRequest(pParamRequest);
1324 // some knittings
1325 pParamRequest->addContinuation(pParamValues);
1326 pParamRequest->addContinuation(pAbort);
1328 // create the handler, let it handle the request
1329 Reference< XInteractionHandler2 > xHandler( InteractionHandler::createWithParent(getORB(), 0) );
1330 xHandler->handle(xParamRequest);
1332 if (!pParamValues->wasSelected())
1333 { // canceled
1334 setLoadingCancelled();
1335 return sal_False;
1338 // transfer the values into the parameter supplier
1339 Sequence< PropertyValue > aFinalValues = pParamValues->getValues();
1340 if (aFinalValues.getLength() != aRequest.Parameters->getCount())
1342 SAL_WARN("dbaccess.ui","SbaXDataBrowserController::approveParameter: the InteractionHandler returned nonsense!");
1343 setLoadingCancelled();
1344 return sal_False;
1346 const PropertyValue* pFinalValues = aFinalValues.getConstArray();
1347 for (sal_Int32 i=0; i<aFinalValues.getLength(); ++i, ++pFinalValues)
1349 Reference< XPropertySet > xParam(
1350 aRequest.Parameters->getByIndex(i), css::uno::UNO_QUERY);
1351 OSL_ENSURE(xParam.is(), "SbaXDataBrowserController::approveParameter: one of the parameters is no property set!");
1352 if (xParam.is())
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 try { xParam->setPropertyValue(PROPERTY_VALUE, pFinalValues->Value); }
1360 catch(Exception&)
1362 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::approveParameter: setting one of the properties failed!");
1367 catch( const Exception& )
1369 DBG_UNHANDLED_EXCEPTION();
1372 return sal_True;
1375 sal_Bool SbaXDataBrowserController::approveReset(const ::com::sun::star::lang::EventObject& /*rEvent*/) throw( RuntimeException, std::exception )
1377 return sal_True;
1380 void SbaXDataBrowserController::resetted(const ::com::sun::star::lang::EventObject& rEvent) throw( RuntimeException, std::exception )
1382 OSL_ENSURE(rEvent.Source == getControlModel(), "SbaXDataBrowserController::resetted : where did this come from ?");
1383 (void)rEvent;
1384 setCurrentModified( false );
1387 sal_Bool SbaXDataBrowserController::confirmDelete(const ::com::sun::star::sdb::RowChangeEvent& /*aEvent*/) throw( RuntimeException, std::exception )
1389 if (ScopedVclPtrInstance<MessageDialog>::Create(getBrowserView(), ModuleRes(STR_QUERY_BRW_DELETE_ROWS), VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO)->Execute() != RET_YES)
1390 return sal_False;
1392 return sal_True;
1395 FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const
1397 FeatureState aReturn;
1398 // (disabled automatically)
1402 // no chance without a view
1403 if (!getBrowserView() || !getBrowserView()->getVclControl())
1404 return aReturn;
1406 switch (nId)
1408 case ID_BROWSER_REMOVEFILTER:
1409 if (!m_xParser.is())
1411 aReturn.bEnabled = false;
1412 return aReturn;
1414 // any filter or sort order set ?
1415 aReturn.bEnabled = m_xParser->getFilter().getLength() || m_xParser->getHavingClause().getLength() || m_xParser->getOrder().getLength();
1416 return aReturn;
1418 // no chance without valid models
1419 if (isValid() && !isValidCursor())
1420 return aReturn;
1422 switch (nId)
1424 case ID_BROWSER_SEARCH:
1426 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1427 sal_Int32 nCount = ::comphelper::getINT32(xFormSet->getPropertyValue(PROPERTY_ROWCOUNT));
1428 aReturn.bEnabled = nCount != 0;
1430 break;
1431 case ID_BROWSER_INSERT_ROW:
1433 // check if it is available
1434 bool bInsertPrivilege = ( m_nRowSetPrivileges & Privilege::INSERT) != 0;
1435 bool bAllowInsertions = true;
1438 Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
1439 OSL_VERIFY( xRowSetProps->getPropertyValue("AllowInserts") >>= bAllowInsertions );
1441 catch( const Exception& )
1443 DBG_UNHANDLED_EXCEPTION();
1445 aReturn.bEnabled = bInsertPrivilege && bAllowInsertions;
1447 break;
1448 case SID_FM_DELETEROWS:
1450 // check if it is available
1451 bool bDeletePrivilege = ( m_nRowSetPrivileges & Privilege::INSERT) != 0;
1452 bool bAllowDeletions = true;
1453 sal_Int32 nRowCount = 0;
1454 bool bInsertionRow = false;
1457 Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
1458 OSL_VERIFY( xRowSetProps->getPropertyValue("AllowDeletes") >>= bAllowDeletions );
1459 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ROWCOUNT ) >>= nRowCount );
1460 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ISNEW ) >>= bInsertionRow );
1462 catch( const Exception& )
1464 DBG_UNHANDLED_EXCEPTION();
1466 aReturn.bEnabled = bDeletePrivilege && bAllowDeletions && ( nRowCount != 0 ) && !bInsertionRow;
1468 break;
1470 case ID_BROWSER_COPY:
1471 if ( getBrowserView()->getVclControl()->GetSelectRowCount() )
1473 aReturn.bEnabled = m_aCurrentFrame.isActive();
1474 break;
1476 // run through
1477 case ID_BROWSER_PASTE:
1478 case ID_BROWSER_CUT:
1480 CellControllerRef xCurrentController = getBrowserView()->getVclControl()->Controller();
1481 if (xCurrentController.Is() && xCurrentController->ISA(EditCellController))
1483 Edit& rEdit = static_cast<Edit&>(xCurrentController->GetWindow());
1484 bool bHasLen = (rEdit.GetSelection().Len() != 0);
1485 bool bIsReadOnly = rEdit.IsReadOnly();
1486 switch (nId)
1488 case ID_BROWSER_CUT: aReturn.bEnabled = m_aCurrentFrame.isActive() && bHasLen && !bIsReadOnly; break;
1489 case SID_COPY : aReturn.bEnabled = m_aCurrentFrame.isActive() && bHasLen; break;
1490 case ID_BROWSER_PASTE:
1491 aReturn.bEnabled = m_aCurrentFrame.isActive() && !bIsReadOnly;
1492 if(aReturn.bEnabled)
1494 aReturn.bEnabled = aReturn.bEnabled && IsFormatSupported( m_aSystemClipboard.GetDataFlavorExVector(), SotClipboardFormatId::STRING );
1496 break;
1500 break;
1502 case ID_BROWSER_SORTUP:
1503 case ID_BROWSER_SORTDOWN:
1504 case ID_BROWSER_AUTOFILTER:
1506 // a native statement can't be filtered or sorted
1507 const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1508 if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || !m_xParser.is() )
1509 break;
1511 Reference< XPropertySet > xCurrentField = getBoundField();
1512 if (!xCurrentField.is())
1513 break;
1515 aReturn.bEnabled = ::comphelper::getBOOL(xCurrentField->getPropertyValue(PROPERTY_ISSEARCHABLE));
1516 const Reference< XRowSet > xRow = getRowSet();
1517 aReturn.bEnabled = aReturn.bEnabled
1518 && xRow.is()
1519 && !xRow->isBeforeFirst()
1520 && !xRow->isAfterLast()
1521 && !xRow->rowDeleted()
1522 && ( ::comphelper::getINT32( xFormSet->getPropertyValue( PROPERTY_ROWCOUNT ) ) != 0 );
1524 break;
1526 case ID_BROWSER_FILTERCRIT:
1527 if ( m_bCannotSelectUnfiltered && m_xParser.is() )
1529 aReturn.bEnabled = true;
1530 break;
1532 // no break
1533 case ID_BROWSER_ORDERCRIT:
1535 const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1536 if ( !::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) || !m_xParser.is() )
1537 break;
1539 aReturn.bEnabled = getRowSet().is()
1540 && ( ::comphelper::getINT32( xFormSet->getPropertyValue( PROPERTY_ROWCOUNT ) ) != 0 );
1542 break;
1544 case ID_BROWSER_REFRESH:
1545 aReturn.bEnabled = true;
1546 break;
1548 case ID_BROWSER_REDO:
1549 aReturn.bEnabled = false; // simply forget it ;). no redo possible.
1550 break;
1552 case ID_BROWSER_UNDORECORD:
1553 case ID_BROWSER_SAVERECORD:
1555 if (!m_bCurrentlyModified)
1557 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1558 if (xFormSet.is())
1559 aReturn.bEnabled = ::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ISMODIFIED));
1561 else
1562 aReturn.bEnabled = true;
1564 aReturn.sTitle = (ID_BROWSER_UNDORECORD == nId) ? m_sStateUndoRecord : m_sStateSaveRecord;
1566 break;
1567 case ID_BROWSER_EDITDOC:
1569 // check if it is available
1570 Reference< XPropertySet > xDataSourceSet(getRowSet(), UNO_QUERY);
1571 if (!xDataSourceSet.is())
1572 break; // no datasource -> no edit mode
1574 sal_Int32 nDataSourcePrivileges = ::comphelper::getINT32(xDataSourceSet->getPropertyValue(PROPERTY_PRIVILEGES));
1575 bool bInsertAllowedAndPossible = ((nDataSourcePrivileges & ::com::sun::star::sdbcx::Privilege::INSERT) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue("AllowInserts"));
1576 bool bUpdateAllowedAndPossible = ((nDataSourcePrivileges & ::com::sun::star::sdbcx::Privilege::UPDATE) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue("AllowUpdates"));
1577 bool bDeleteAllowedAndPossible = ((nDataSourcePrivileges & ::com::sun::star::sdbcx::Privilege::DELETE) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue("AllowDeletes"));
1578 if (!bInsertAllowedAndPossible && !bUpdateAllowedAndPossible && !bDeleteAllowedAndPossible)
1579 break; // no insert/update/delete -> no edit mode
1581 if (!isValidCursor() || !isLoaded())
1582 break; // no cursor -> no edit mode
1584 aReturn.bEnabled = true;
1586 sal_Int16 nGridMode = getBrowserView()->getVclControl()->GetOptions();
1587 aReturn.bChecked = nGridMode > DbGridControl::OPT_READONLY;
1589 break;
1590 case ID_BROWSER_FILTERED:
1592 aReturn.bEnabled = false;
1593 Reference< XPropertySet > xActiveSet(getRowSet(), UNO_QUERY);
1594 OUString aFilter = ::comphelper::getString(xActiveSet->getPropertyValue(PROPERTY_FILTER));
1595 OUString aHaving = ::comphelper::getString(xActiveSet->getPropertyValue(PROPERTY_HAVING_CLAUSE));
1596 if ( !(aFilter.isEmpty() && aHaving.isEmpty()) )
1598 xActiveSet->getPropertyValue( PROPERTY_APPLYFILTER ) >>= aReturn.bChecked;
1599 aReturn.bEnabled = true;
1601 else
1603 aReturn.bChecked = false;
1604 aReturn.bEnabled = false;
1607 break;
1608 default:
1609 return SbaXDataBrowserController_Base::GetState(nId);
1612 catch(const Exception& )
1614 DBG_UNHANDLED_EXCEPTION();
1617 return aReturn;
1620 void SbaXDataBrowserController::applyParserOrder(const OUString& _rOldOrder,const Reference< XSingleSelectQueryComposer >& _xParser)
1622 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1623 if (!m_xLoadable.is())
1625 SAL_WARN("dbaccess.ui","SbaXDataBrowserController::applyParserOrder: invalid row set!");
1626 return;
1629 sal_uInt16 nPos = getCurrentColumnPosition();
1630 bool bSuccess = false;
1633 xFormSet->setPropertyValue(PROPERTY_ORDER, makeAny(_xParser->getOrder()));
1634 bSuccess = reloadForm(m_xLoadable);
1636 catch(Exception&)
1640 if (!bSuccess)
1642 xFormSet->setPropertyValue(PROPERTY_ORDER, makeAny(_rOldOrder));
1646 if (loadingCancelled() || !reloadForm(m_xLoadable))
1647 criticalFail();
1649 catch(Exception&)
1651 criticalFail();
1653 InvalidateAll();
1655 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1657 setCurrentColumnPosition(nPos);
1660 void SbaXDataBrowserController::applyParserFilter(const OUString& _rOldFilter, bool _bOldFilterApplied,const ::OUString& _sOldHaving,const Reference< XSingleSelectQueryComposer >& _xParser)
1662 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1663 if (!m_xLoadable.is())
1665 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::applyParserFilter: invalid row set!");
1666 return;
1669 sal_uInt16 nPos = getCurrentColumnPosition();
1671 bool bSuccess = false;
1674 FormErrorHelper aError(this);
1675 xFormSet->setPropertyValue(PROPERTY_FILTER, makeAny(_xParser->getFilter()));
1676 xFormSet->setPropertyValue(PROPERTY_HAVING_CLAUSE, makeAny(_xParser->getHavingClause()));
1677 xFormSet->setPropertyValue(PROPERTY_APPLYFILTER, ::comphelper::makeBoolAny(true));
1679 bSuccess = reloadForm(m_xLoadable);
1681 catch(Exception&)
1685 if (!bSuccess)
1687 xFormSet->setPropertyValue(PROPERTY_FILTER, makeAny(_rOldFilter));
1688 xFormSet->setPropertyValue(PROPERTY_HAVING_CLAUSE, makeAny(_sOldHaving));
1689 xFormSet->setPropertyValue(PROPERTY_APPLYFILTER, ::comphelper::makeBoolAny(_bOldFilterApplied));
1693 if (loadingCancelled() || !reloadForm(m_xLoadable))
1694 criticalFail();
1696 catch(Exception&)
1698 criticalFail();
1700 InvalidateAll();
1702 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
1704 setCurrentColumnPosition(nPos);
1707 Reference< XSingleSelectQueryComposer > SbaXDataBrowserController::createParser_nothrow()
1709 Reference< XSingleSelectQueryComposer > xComposer;
1712 const Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
1713 const Reference< XMultiServiceFactory > xFactory(
1714 xRowSetProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ), UNO_QUERY_THROW );
1715 xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
1717 OUString sActiveCommand;
1718 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ACTIVECOMMAND ) >>= sActiveCommand );
1719 if ( !sActiveCommand.isEmpty() )
1721 xComposer->setElementaryQuery( sActiveCommand );
1723 else
1725 OUString sCommand;
1726 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
1727 sal_Int32 nCommandType = CommandType::COMMAND;
1728 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_COMMAND_TYPE ) >>= nCommandType );
1729 xComposer->setCommand( sCommand, nCommandType );
1732 OUString sFilter;
1733 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_FILTER ) >>= sFilter );
1734 xComposer->setFilter( sFilter );
1736 OUString sHavingClause;
1737 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_HAVING_CLAUSE ) >>= sHavingClause );
1738 xComposer->setHavingClause( sHavingClause );
1740 OUString sOrder;
1741 OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ORDER ) >>= sOrder );
1742 xComposer->setOrder( sOrder );
1744 catch ( const Exception& )
1746 DBG_UNHANDLED_EXCEPTION();
1748 return xComposer;
1751 void SbaXDataBrowserController::ExecuteFilterSortCrit(bool bFilter)
1753 if (!SaveModified())
1754 return;
1756 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
1758 const OUString sOldVal = bFilter ? m_xParser->getFilter() : m_xParser->getOrder();
1759 const OUString sOldHaving = m_xParser->getHavingClause();
1760 Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow();
1763 Reference< ::com::sun::star::sdbcx::XColumnsSupplier> xSup = getColumnsSupplier();
1764 Reference< XConnection> xCon(xFormSet->getPropertyValue(PROPERTY_ACTIVE_CONNECTION),UNO_QUERY);
1765 if(bFilter)
1767 ScopedVclPtrInstance< DlgFilterCrit > aDlg( getBrowserView(), getORB(), xCon, xParser, xSup->getColumns() );
1768 if ( !aDlg->Execute() )
1769 return; // if so we don't need to update the grid
1770 aDlg->BuildWherePart();
1772 else
1774 ScopedVclPtrInstance< DlgOrderCrit > aDlg( getBrowserView(),xCon,xParser,xSup->getColumns() );
1775 if(!aDlg->Execute())
1777 return; // if so we don't need to actualize the grid
1779 aDlg->BuildOrderPart();
1782 catch(const SQLException& )
1784 SQLExceptionInfo aError( ::cppu::getCaughtException() );
1785 showError( aError );
1786 return;
1788 catch(Exception&)
1790 return;
1793 OUString sNewVal = bFilter ? xParser->getFilter() : xParser->getOrder();
1794 bool bOldFilterApplied(false);
1795 if (bFilter)
1797 try { bOldFilterApplied = ::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_APPLYFILTER)); } catch(Exception&) { } ;
1800 OUString sNewHaving = xParser->getHavingClause();
1801 if ( sOldVal.equals(sNewVal) && (!bFilter || sOldHaving.equals(sNewHaving)) )
1802 // nothing to be done
1803 return;
1805 if (bFilter)
1806 applyParserFilter(sOldVal, bOldFilterApplied,sOldHaving,xParser);
1807 else
1808 applyParserOrder(sOldVal,xParser);
1810 ::comphelper::disposeComponent(xParser);
1813 void SbaXDataBrowserController::ExecuteSearch()
1815 // calculate the control source of the active field
1816 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 !");
1819 Reference< ::com::sun::star::form::XGridPeer > xGridPeer(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY);
1820 Reference< ::com::sun::star::container::XIndexContainer > xColumns = xGridPeer->getColumns();
1821 OSL_ENSURE(xGridPeer.is() && xColumns.is(), "SbaXDataBrowserController::ExecuteSearch : invalid peer !");
1823 sal_Int16 nViewCol = xGrid->getCurrentColumnPosition();
1824 sal_Int16 nModelCol = getBrowserView()->View2ModelPos(nViewCol);
1826 Reference< XPropertySet > xCurrentCol(xColumns->getByIndex(nModelCol),UNO_QUERY);
1827 OUString sActiveField = ::comphelper::getString(xCurrentCol->getPropertyValue(PROPERTY_CONTROLSOURCE));
1829 // the text within the current cell
1830 OUString sInitialText;
1831 Reference< ::com::sun::star::container::XIndexAccess > xColControls(xGridPeer, UNO_QUERY);
1832 Reference< XInterface > xCurControl(xColControls->getByIndex(nViewCol),UNO_QUERY);
1833 OUString aInitialText;
1834 if (IsSearchableControl(xCurControl, &aInitialText))
1835 sInitialText = aInitialText;
1837 // prohibit the synchronization of the grid's display with the cursor's position
1838 Reference< XPropertySet > xModelSet(getControlModel(), UNO_QUERY);
1839 OSL_ENSURE(xModelSet.is(), "SbaXDataBrowserController::ExecuteSearch : no model set ?!");
1840 xModelSet->setPropertyValue("DisplayIsSynchron", ::comphelper::makeBoolAny(false));
1841 xModelSet->setPropertyValue("AlwaysShowCursor", ::comphelper::makeBoolAny(true));
1842 xModelSet->setPropertyValue("CursorColor", makeAny(sal_Int32(COL_LIGHTRED)));
1844 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xNFS(::dbtools::getNumberFormats(::dbtools::getConnection(m_xRowSet), true, getORB()));
1846 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1847 AbstractFmSearchDialog* pDialog = NULL;
1848 if ( pFact )
1850 ::std::vector< OUString > aContextNames;
1851 aContextNames.push_back( OUString("Standard") );
1852 pDialog = pFact->CreateFmSearchDialog(getBrowserView(), sInitialText, aContextNames, 0, LINK(this, SbaXDataBrowserController, OnSearchContextRequest));
1854 OSL_ENSURE( pDialog, "SbaXDataBrowserController::ExecuteSearch: could not get the search dialog!" );
1855 if ( pDialog )
1857 pDialog->SetActiveField( sActiveField );
1858 pDialog->SetFoundHandler( LINK( this, SbaXDataBrowserController, OnFoundData ) );
1859 pDialog->SetCanceledNotFoundHdl( LINK( this, SbaXDataBrowserController, OnCanceledNotFound ) );
1860 pDialog->Execute();
1861 delete pDialog;
1864 // restore the grid's normal operating state
1865 xModelSet->setPropertyValue("DisplayIsSynchron", ::comphelper::makeBoolAny(true));
1866 xModelSet->setPropertyValue("AlwaysShowCursor", ::comphelper::makeBoolAny(false));
1867 xModelSet->setPropertyValue("CursorColor", Any());
1870 void SbaXDataBrowserController::Execute(sal_uInt16 nId, const Sequence< PropertyValue >& _rArgs)
1872 bool bSortUp = true;
1874 switch (nId)
1876 default:
1877 SbaXDataBrowserController_Base::Execute( nId, _rArgs );
1878 return;
1880 case ID_BROWSER_INSERT_ROW:
1883 if (SaveModified())
1885 getRowSet()->afterLast();
1886 // check if it is available
1887 Reference< XResultSetUpdate > xUpdateCursor(getRowSet(), UNO_QUERY_THROW);
1888 xUpdateCursor->moveToInsertRow();
1891 catch(Exception&)
1893 SAL_WARN("dbaccess.ui", "Exception caught!");
1895 break;
1896 case SID_FM_DELETEROWS:
1898 if (SaveModified())
1900 SbaGridControl* pVclGrid = getBrowserView()->getVclControl();
1901 if ( pVclGrid )
1903 if( !pVclGrid->GetSelectRowCount() )
1905 pVclGrid->DeactivateCell();
1906 pVclGrid->SelectRow(pVclGrid->GetCurRow());
1908 pVclGrid->DeleteSelectedRows();
1911 break;
1913 case ID_BROWSER_FILTERED:
1914 if (SaveModified())
1916 Reference< XPropertySet > xActiveSet(getRowSet(), UNO_QUERY);
1917 bool bApplied = ::comphelper::getBOOL(xActiveSet->getPropertyValue(PROPERTY_APPLYFILTER));
1918 xActiveSet->setPropertyValue(PROPERTY_APPLYFILTER, ::comphelper::makeBoolAny(!bApplied));
1919 reloadForm(m_xLoadable);
1921 InvalidateFeature(ID_BROWSER_FILTERED);
1922 break;
1923 case ID_BROWSER_EDITDOC:
1925 sal_Int16 nGridMode = getBrowserView()->getVclControl()->GetOptions();
1926 if (nGridMode == DbGridControl::OPT_READONLY)
1927 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
1931 if ( !SaveModified( ) )
1932 // give the user a chance to save the current record (if necessary)
1933 break;
1935 // maybe the user wanted to reject the modified record ?
1936 if (GetState(ID_BROWSER_UNDORECORD).bEnabled)
1937 Execute(ID_BROWSER_UNDORECORD,Sequence<PropertyValue>());
1939 getBrowserView()->getVclControl()->SetOptions(DbGridControl::OPT_READONLY);
1941 InvalidateFeature(ID_BROWSER_EDITDOC);
1943 break;
1945 case ID_BROWSER_SEARCH:
1946 if ( SaveModified( ) )
1947 ExecuteSearch();
1948 break;
1950 case ID_BROWSER_COPY:
1951 if ( getBrowserView()->getVclControl()->GetSelectRowCount() > 0 )
1953 getBrowserView()->getVclControl()->CopySelectedRowsToClipboard();
1954 break;
1956 // run through
1957 case ID_BROWSER_CUT:
1958 case ID_BROWSER_PASTE:
1960 CellControllerRef xCurrentController = getBrowserView()->getVclControl()->Controller();
1961 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 return;
1967 Edit& rEdit = static_cast<Edit&>(xCurrentController->GetWindow());
1968 switch (nId)
1970 case ID_BROWSER_CUT : rEdit.Cut(); break;
1971 case SID_COPY : rEdit.Copy(); break;
1972 case ID_BROWSER_PASTE : rEdit.Paste(); break;
1974 if (ID_BROWSER_CUT == nId || ID_BROWSER_PASTE == nId)
1976 xCurrentController->SetModified();
1977 rEdit.Modify();
1980 break;
1982 case ID_BROWSER_SORTDOWN:
1983 bSortUp = false;
1984 // DON'T break
1985 case ID_BROWSER_SORTUP:
1987 if (!SaveModified())
1988 break;
1990 if (!isValidCursor())
1991 break;
1993 // only one sort order
1994 Reference< XPropertySet > xField(getBoundField(), UNO_QUERY);
1995 if (!xField.is())
1996 break;
1998 Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow();
1999 const OUString sOldSort = xParser->getOrder();
2000 bool bParserSuccess = false;
2001 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 !"
2008 if (bParserSuccess)
2009 applyParserOrder(sOldSort,xParser);
2011 break;
2013 case ID_BROWSER_AUTOFILTER:
2015 if (!SaveModified())
2016 break;
2018 if (!isValidCursor())
2019 break;
2021 Reference< XPropertySet > xField(getBoundField(), UNO_QUERY);
2022 if (!xField.is())
2023 break;
2025 // check if the column is a aggregate function
2026 bool bHaving = false;
2027 OUString sName;
2028 xField->getPropertyValue(PROPERTY_NAME) >>= sName;
2029 Reference< XColumnsSupplier > xColumnsSupplier(m_xParser, UNO_QUERY);
2030 Reference< ::com::sun::star::container::XNameAccess > xCols = xColumnsSupplier.is() ? xColumnsSupplier->getColumns() : Reference< ::com::sun::star::container::XNameAccess > ();
2031 if ( xCols.is() && xCols->hasByName(sName) )
2033 Reference<XPropertySet> xProp(xCols->getByName(sName),UNO_QUERY);
2034 static const char sAgg[] = "AggregateFunction";
2035 if ( xProp->getPropertySetInfo()->hasPropertyByName(sAgg) )
2036 xProp->getPropertyValue(sAgg) >>= bHaving;
2039 Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow();
2040 const OUString sOldFilter = xParser->getFilter();
2041 const OUString sOldHaving = xParser->getHavingClause();
2043 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
2044 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 if (!bApplied)
2049 DO_SAFE( (bHaving ? xParser->setHavingClause(OUString()) : xParser->setFilter(::OUString())), "SbaXDataBrowserController::Execute : caught an exception while resetting the new filter !" );
2052 bool bParserSuccess = false;
2054 const sal_Int32 nOp = SQLFilterOperator::EQUAL;
2056 if ( bHaving )
2058 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 !"
2065 else
2067 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 !"
2075 if (bParserSuccess)
2076 applyParserFilter(sOldFilter, bApplied,sOldHaving,xParser);
2078 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
2079 InvalidateFeature(ID_BROWSER_FILTERED);
2081 break;
2083 case ID_BROWSER_ORDERCRIT:
2084 ExecuteFilterSortCrit(false);
2085 break;
2087 case ID_BROWSER_FILTERCRIT:
2088 ExecuteFilterSortCrit(true);
2089 InvalidateFeature(ID_BROWSER_FILTERED);
2090 break;
2092 case ID_BROWSER_REMOVEFILTER:
2094 if (!SaveModified())
2095 break;
2097 bool bNeedPostReload = preReloadForm();
2098 // reset the filter and the sort property simutaneously so only _one_ new statement has to be
2099 // sent
2100 Reference< XPropertySet > xSet(getRowSet(), UNO_QUERY);
2101 if ( xSet.is() )
2103 xSet->setPropertyValue(PROPERTY_FILTER,makeAny(OUString()));
2104 xSet->setPropertyValue(PROPERTY_HAVING_CLAUSE,makeAny(OUString()));
2105 xSet->setPropertyValue(PROPERTY_ORDER,makeAny(OUString()));
2109 reloadForm(m_xLoadable);
2110 if ( bNeedPostReload )
2111 postReloadForm();
2113 catch(Exception&)
2116 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
2117 InvalidateFeature(ID_BROWSER_FILTERED);
2119 break;
2121 case ID_BROWSER_REFRESH:
2122 if ( SaveModified( ) )
2124 if (!reloadForm(m_xLoadable))
2125 criticalFail();
2127 break;
2129 case ID_BROWSER_SAVERECORD:
2130 if ( SaveModified( false ) )
2131 setCurrentModified( false );
2132 break;
2134 case ID_BROWSER_UNDORECORD:
2138 // restore the cursor state
2139 Reference< XResultSetUpdate > xCursor(getRowSet(), UNO_QUERY);
2140 Reference< XPropertySet > xSet(xCursor, UNO_QUERY);
2141 Any aVal = xSet->getPropertyValue(PROPERTY_ISNEW);
2142 if (aVal.hasValue() && ::comphelper::getBOOL(aVal))
2144 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 ....)
2150 else
2152 xCursor->cancelRowUpdates();
2154 // restore the grids state
2155 Reference< ::com::sun::star::form::XReset > xReset(getControlModel(), UNO_QUERY);
2156 if (xReset.is())
2157 xReset->reset();
2160 catch(SQLException&)
2164 setCurrentModified( false );
2169 bool SbaXDataBrowserController::SaveModified(bool bAskFor)
2171 if ( bAskFor && GetState(ID_BROWSER_SAVERECORD).bEnabled )
2173 getBrowserView()->getVclControl()->GrabFocus();
2175 ScopedVclPtrInstance<MessageDialog> aQry( getBrowserView()->getVclControl(),
2176 "SaveModifiedDialog",
2177 "dbaccess/ui/savemodifieddialog.ui" );
2179 switch (aQry->Execute())
2181 case RET_NO:
2182 Execute(ID_BROWSER_UNDORECORD,Sequence<PropertyValue>());
2183 return true;
2184 case RET_CANCEL:
2185 return false;
2189 if ( !CommitCurrent() ) // das aktuelle Control committen lassen
2190 return false;
2192 Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
2193 bool bResult = false;
2196 if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ISMODIFIED)))
2198 Reference< XResultSetUpdate > xCursor(getRowSet(), UNO_QUERY);
2199 if (::comphelper::getBOOL(xFormSet->getPropertyValue(PROPERTY_ISNEW)))
2200 xCursor->insertRow();
2201 else
2202 xCursor->updateRow();
2204 bResult = true;
2206 catch(SQLException&)
2209 catch(Exception&)
2211 SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::SaveModified : could not save the current record !");
2212 bResult = false;
2215 InvalidateFeature(ID_BROWSER_SAVERECORD);
2216 InvalidateFeature(ID_BROWSER_UNDORECORD);
2217 return bResult;
2220 bool SbaXDataBrowserController::CommitCurrent()
2222 if (!getBrowserView())
2223 return true;
2225 Reference< ::com::sun::star::awt::XControl > xActiveControl(getBrowserView()->getGridControl());
2226 Reference< ::com::sun::star::form::XBoundControl > xLockingTest(xActiveControl, UNO_QUERY);
2227 bool bControlIsLocked = xLockingTest.is() && xLockingTest->getLock();
2228 if (xActiveControl.is() && !bControlIsLocked)
2230 // zunaechst das Control fragen ob es das IFace unterstuetzt
2231 Reference< ::com::sun::star::form::XBoundComponent > xBoundControl(xActiveControl, UNO_QUERY);
2232 if (!xBoundControl.is())
2233 xBoundControl = Reference< ::com::sun::star::form::XBoundComponent > (xActiveControl->getModel(), UNO_QUERY);
2234 if (xBoundControl.is() && !xBoundControl->commit())
2235 return false;
2237 return true;
2240 void SbaXDataBrowserController::setCurrentModified( bool _bSet )
2242 m_bCurrentlyModified = _bSet;
2243 InvalidateFeature( ID_BROWSER_SAVERECORD );
2244 InvalidateFeature( ID_BROWSER_UNDORECORD );
2247 void SbaXDataBrowserController::RowChanged()
2249 setCurrentModified( false );
2252 void SbaXDataBrowserController::ColumnChanged()
2254 InvalidateFeature(ID_BROWSER_SORTUP);
2255 InvalidateFeature(ID_BROWSER_SORTDOWN);
2256 InvalidateFeature(ID_BROWSER_ORDERCRIT);
2257 InvalidateFeature(ID_BROWSER_FILTERCRIT);
2258 InvalidateFeature(ID_BROWSER_AUTOFILTER);
2259 InvalidateFeature(ID_BROWSER_REMOVEFILTER);
2261 setCurrentModified( false );
2264 void SbaXDataBrowserController::SelectionChanged()
2266 // not interested in
2269 void SbaXDataBrowserController::CellActivated()
2271 m_aInvalidateClipboard.Start();
2272 OnInvalidateClipboard( NULL );
2275 void SbaXDataBrowserController::CellDeactivated()
2277 m_aInvalidateClipboard.Stop();
2278 OnInvalidateClipboard( NULL );
2281 IMPL_LINK_NOARG(SbaXDataBrowserController, OnClipboardChanged)
2283 SolarMutexGuard aGuard;
2284 OnInvalidateClipboard( NULL );
2285 return 0;
2288 IMPL_LINK_TYPED(SbaXDataBrowserController, OnInvalidateClipboard, Timer*, _pTimer, void)
2290 InvalidateFeature(ID_BROWSER_CUT);
2291 InvalidateFeature(ID_BROWSER_COPY);
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 if ( _pTimer != &m_aInvalidateClipboard )
2299 InvalidateFeature(ID_BROWSER_PASTE);
2302 Reference< XPropertySet > SbaXDataBrowserController::getBoundField(sal_uInt16 nViewPos) const
2304 Reference< XPropertySet > xEmptyReturn;
2306 // get the current column from the grid
2307 if (nViewPos == (sal_uInt16)-1)
2309 Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
2310 if (!xGrid.is())
2311 return xEmptyReturn;
2312 nViewPos = xGrid->getCurrentColumnPosition();
2314 sal_uInt16 nCurrentCol = getBrowserView()->View2ModelPos(nViewPos);
2315 if (nCurrentCol == (sal_uInt16)-1)
2316 return xEmptyReturn;
2318 // get the according column from the model
2319 Reference< ::com::sun::star::container::XIndexContainer > xCols(getControlModel(), UNO_QUERY);
2320 Reference< XPropertySet > xCurrentCol(xCols->getByIndex(nCurrentCol),UNO_QUERY);
2321 if (!xCurrentCol.is())
2322 return xEmptyReturn;
2324 xEmptyReturn.set(xCurrentCol->getPropertyValue(PROPERTY_BOUNDFIELD) ,UNO_QUERY);
2325 return xEmptyReturn;
2328 IMPL_LINK(SbaXDataBrowserController, OnSearchContextRequest, FmSearchContext*, pContext)
2330 Reference< ::com::sun::star::container::XIndexAccess > xPeerContainer(getBrowserView()->getGridControl(), UNO_QUERY);
2332 // check all grid columns for their control source
2333 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 !");
2338 OUString sFieldList;
2339 for (sal_Int32 nViewPos=0; nViewPos<xPeerContainer->getCount(); ++nViewPos)
2341 Reference< XInterface > xCurrentColumn(xPeerContainer->getByIndex(nViewPos),UNO_QUERY);
2342 if (!xCurrentColumn.is())
2343 continue;
2345 // can we use this column control for searching ?
2346 if (!IsSearchableControl(xCurrentColumn))
2347 continue;
2349 sal_uInt16 nModelPos = getBrowserView()->View2ModelPos((sal_uInt16)nViewPos);
2350 Reference< XPropertySet > xCurrentColModel(xModelColumns->getByIndex(nModelPos),UNO_QUERY);
2351 OUString aName = ::comphelper::getString(xCurrentColModel->getPropertyValue(PROPERTY_CONTROLSOURCE));
2353 sFieldList += aName + ";";
2355 pContext->arrFields.push_back(xCurrentColumn);
2357 sFieldList = comphelper::string::stripEnd(sFieldList, ';');
2359 pContext->xCursor.set(getRowSet(),UNO_QUERY);
2360 pContext->strUsedFields = sFieldList;
2362 // if the cursor is in a mode other than STANDARD -> reset
2363 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 if (xCursorSet.is() && ::comphelper::getBOOL(xCursorSet->getPropertyValue(PROPERTY_ISNEW)))
2368 Reference< XResultSetUpdate > xUpdateCursor(pContext->xCursor, UNO_QUERY);
2369 xUpdateCursor->moveToCurrentRow();
2371 return pContext->arrFields.size();
2374 IMPL_LINK(SbaXDataBrowserController, OnFoundData, FmFoundRecordInformation*, pInfo)
2376 Reference< ::com::sun::star::sdbcx::XRowLocate > xCursor(getRowSet(), UNO_QUERY);
2377 OSL_ENSURE(xCursor.is(), "SbaXDataBrowserController::OnFoundData : xCursor is empty");
2379 // move the cursor
2380 xCursor->moveToBookmark(pInfo->aPosition);
2382 // let the grid snyc it's display with the cursor
2383 Reference< XPropertySet > xModelSet(getControlModel(), UNO_QUERY);
2384 OSL_ENSURE(xModelSet.is(), "SbaXDataBrowserController::OnFoundData : no model set ?!");
2385 Any aOld = xModelSet->getPropertyValue("DisplayIsSynchron");
2386 xModelSet->setPropertyValue("DisplayIsSynchron", ::comphelper::makeBoolAny(true));
2387 xModelSet->setPropertyValue("DisplayIsSynchron", aOld);
2389 // and move to the field
2390 Reference< ::com::sun::star::container::XIndexAccess > aColumnControls(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY);
2391 sal_uInt16 nViewPos;
2393 for ( nViewPos = 0; nViewPos < aColumnControls->getCount(); ++nViewPos )
2395 Reference< XInterface > xCurrent(aColumnControls->getByIndex(nViewPos),UNO_QUERY);
2396 if (IsSearchableControl(xCurrent))
2398 if (pInfo->nFieldPos)
2399 --pInfo->nFieldPos;
2400 else
2401 break;
2405 Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
2406 xGrid->setCurrentColumnPosition(nViewPos);
2408 return 0;
2411 IMPL_LINK(SbaXDataBrowserController, OnCanceledNotFound, FmFoundRecordInformation*, pInfo)
2413 Reference< ::com::sun::star::sdbcx::XRowLocate > xCursor(getRowSet(), UNO_QUERY);
2417 OSL_ENSURE(xCursor.is(), "SbaXDataBrowserController::OnCanceledNotFound : xCursor is empty");
2418 // move the cursor
2419 xCursor->moveToBookmark(pInfo->aPosition);
2421 catch( const Exception& )
2423 DBG_UNHANDLED_EXCEPTION();
2428 // let the grid snyc its display with the cursor
2429 Reference< XPropertySet > xModelSet(getControlModel(), UNO_QUERY);
2430 OSL_ENSURE(xModelSet.is(), "SbaXDataBrowserController::OnCanceledNotFound : no model set ?!");
2431 Any aOld = xModelSet->getPropertyValue("DisplayIsSynchron");
2432 xModelSet->setPropertyValue("DisplayIsSynchron", ::comphelper::makeBoolAny(true));
2433 xModelSet->setPropertyValue("DisplayIsSynchron", aOld);
2435 catch( const Exception& )
2437 DBG_UNHANDLED_EXCEPTION();
2440 return 0L;
2443 IMPL_LINK_NOARG(SbaXDataBrowserController, OnAsyncGetCellFocus)
2445 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 if(pVclGrid)
2449 if (!pVclGrid->IsEditing())
2450 return 0L;
2452 if (pVclGrid->HasChildPathFocus())
2453 pVclGrid->Controller()->GetWindow().GrabFocus();
2456 return 0L;
2459 void SbaXDataBrowserController::criticalFail()
2461 InvalidateAll();
2462 m_nRowSetPrivileges = 0;
2465 void SbaXDataBrowserController::LoadFinished(bool /*bWasSynch*/)
2467 m_nRowSetPrivileges = 0;
2469 if (isValid() && !loadingCancelled())
2471 // obtain cached values
2474 Reference< XPropertySet > xFormProps( m_xLoadable, UNO_QUERY_THROW );
2475 OSL_VERIFY( xFormProps->getPropertyValue( PROPERTY_PRIVILEGES ) >>= m_nRowSetPrivileges );
2477 catch( const Exception& )
2479 DBG_UNHANDLED_EXCEPTION();
2482 // switch the control to alive mode
2483 getBrowserView()->getGridControl()->setDesignMode(sal_False);
2485 initializeParser();
2487 InvalidateAll();
2489 m_aAsyncGetCellFocus.Call();
2493 void SbaXDataBrowserController::initializeParser() const
2495 if ( !m_xParser.is() )
2497 // create a parser (needed for filtering/sorting)
2500 const Reference< XPropertySet > xFormSet(getRowSet(), UNO_QUERY);
2501 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 xFormSet->getPropertyValue(PROPERTY_SINGLESELECTQUERYCOMPOSER) >>= m_xParser;
2507 catch(Exception&)
2509 DBG_UNHANDLED_EXCEPTION();
2510 m_xParser = NULL;
2511 // no further handling, we ignore the error
2516 void SbaXDataBrowserController::loaded(const EventObject& /*aEvent*/) throw( RuntimeException, std::exception )
2518 // not interested in
2519 // we're loading within an separate thread and have a handling for it's "finished event"
2522 void SbaXDataBrowserController::unloading(const EventObject& /*aEvent*/) throw( RuntimeException, std::exception )
2524 // not interested in
2527 void SbaXDataBrowserController::unloaded(const EventObject& /*aEvent*/) throw( RuntimeException, std::exception )
2529 m_xParser.clear();
2530 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 ....
2538 void SbaXDataBrowserController::reloading(const EventObject& /*aEvent*/) throw( RuntimeException, std::exception )
2540 // not interested in
2543 void SbaXDataBrowserController::reloaded(const EventObject& /*aEvent*/) throw( RuntimeException, std::exception )
2545 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 ....
2553 void SbaXDataBrowserController::enterFormAction()
2555 if ( !m_nFormActionNestingLevel )
2556 // first action -> reset
2557 m_aCurrentError.clear();
2559 ++m_nFormActionNestingLevel;
2562 void SbaXDataBrowserController::leaveFormAction()
2564 OSL_ENSURE( m_nFormActionNestingLevel > 0, "SbaXDataBrowserController::leaveFormAction : invalid call !" );
2565 if ( --m_nFormActionNestingLevel > 0 )
2566 return;
2568 if ( !m_aCurrentError.isValid() )
2569 return;
2571 m_aAsyncDisplayError.Call();
2574 bool SbaXDataBrowserController::isLoaded() const
2576 return m_xLoadable.is() && m_xLoadable->isLoaded();
2579 bool SbaXDataBrowserController::isValidCursor() const
2581 if (!m_xColumnsSupplier.is())
2582 return false;
2583 Reference< ::com::sun::star::container::XNameAccess > xCols = m_xColumnsSupplier->getColumns();
2584 if (!xCols.is() || !xCols->hasElements())
2585 return false;
2587 bool bIsValid = !(m_xRowSet->isBeforeFirst() || m_xRowSet->isAfterLast());
2588 if ( !bIsValid )
2590 Reference<XPropertySet> xProp(m_xRowSet,UNO_QUERY);
2591 bIsValid = ::cppu::any2bool(xProp->getPropertyValue(PROPERTY_ISNEW));
2592 if ( !bIsValid )
2594 bIsValid = m_xParser.is();
2597 return bIsValid;
2600 sal_Int16 SbaXDataBrowserController::getCurrentColumnPosition()
2602 Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
2603 sal_Int16 nViewPos = -1;
2606 if ( xGrid.is() )
2607 nViewPos = xGrid->getCurrentColumnPosition();
2609 catch(Exception&) {}
2610 return nViewPos;
2613 void SbaXDataBrowserController::setCurrentColumnPosition( sal_Int16 _nPos )
2615 Reference< ::com::sun::star::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY);
2618 if ( -1 != _nPos )
2619 xGrid->setCurrentColumnPosition(_nPos);
2621 catch(Exception&) {}
2624 void SbaXDataBrowserController::BeforeDrop()
2626 Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY);
2627 if (xFormError.is())
2628 xFormError->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
2631 void SbaXDataBrowserController::AfterDrop()
2633 Reference< ::com::sun::star::sdb::XSQLErrorBroadcaster > xFormError(getRowSet(), UNO_QUERY);
2634 if (xFormError.is())
2635 xFormError->addSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener*)this);
2638 void SbaXDataBrowserController::addColumnListeners(const Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel)
2640 // ... all the grid columns
2641 Reference< ::com::sun::star::container::XIndexContainer > xColumns(_xGridControlModel, UNO_QUERY);
2642 if (xColumns.is())
2644 sal_Int32 nCount = xColumns->getCount();
2645 for (sal_uInt16 i=0; i < nCount; ++i)
2647 Reference< XPropertySet > xCol(xColumns->getByIndex(i),UNO_QUERY);
2648 AddColumnListener(xCol);
2653 bool SbaXDataBrowserController::InitializeGridModel(const Reference< ::com::sun::star::form::XFormComponent > & /*xGrid*/)
2655 return true;
2658 } // namespace dbaui
2660 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */