1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
32 #include "browserids.hxx"
33 #include "brwctrlr.hxx"
34 #include "brwview.hxx"
35 #include "dbu_brw.hrc"
36 #include "dbustrings.hrc"
37 #include "queryfilter.hxx"
38 #include "queryorder.hxx"
39 #include "sqlmessage.hxx"
41 /** === begin UNO includes === **/
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 #include <com/sun/star/container/XNameContainer.hpp>
44 #include <com/sun/star/container/XNamed.hpp>
45 #include <com/sun/star/form/FormButtonType.hpp>
46 #include <com/sun/star/form/FormSubmitEncoding.hpp>
47 #include <com/sun/star/form/FormSubmitMethod.hpp>
48 #include <com/sun/star/form/XApproveActionBroadcaster.hpp>
49 #include <com/sun/star/form/XBoundControl.hpp>
50 #include <com/sun/star/form/XChangeBroadcaster.hpp>
51 #include <com/sun/star/form/XChangeListener.hpp>
52 #include <com/sun/star/form/XDatabaseParameterBroadcaster.hpp>
53 #include <com/sun/star/form/XLoadable.hpp>
54 #include <com/sun/star/form/XReset.hpp>
55 #include <com/sun/star/form/XResetListener.hpp>
56 #include <com/sun/star/form/XSubmit.hpp>
57 #include <com/sun/star/form/XSubmitListener.hpp>
58 #include <com/sun/star/form/runtime/XFormController.hpp>
59 #include <com/sun/star/sdb/CommandType.hpp>
60 #include <com/sun/star/sdb/ErrorCondition.hpp>
61 #include <com/sun/star/sdb/ParametersRequest.hpp>
62 #include <com/sun/star/sdb/SQLContext.hpp>
63 #include <com/sun/star/sdb/XInteractionSupplyParameters.hpp>
64 #include <com/sun/star/sdb/XSQLErrorBroadcaster.hpp>
65 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
66 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
67 #include <com/sun/star/sdbc/XConnection.hpp>
68 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
69 #include <com/sun/star/sdbc/XRowSetListener.hpp>
70 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
71 #include <com/sun/star/sdbcx/Privilege.hpp>
72 #include <com/sun/star/sdbcx/XRowLocate.hpp>
73 #include <com/sun/star/task/XInteractionHandler.hpp>
74 #include <com/sun/star/uno/TypeClass.hpp>
75 #include <com/sun/star/util/XCancellable.hpp>
76 /** === end UNO includes === **/
78 #include <comphelper/enumhelper.hxx>
79 #include <comphelper/extract.hxx>
80 #include <comphelper/interaction.hxx>
81 #include <comphelper/sequence.hxx>
82 #include <connectivity/dbexception.hxx>
83 #include <connectivity/dbtools.hxx>
84 #include <connectivity/sqlerror.hxx>
85 #include <cppuhelper/exc_hlp.hxx>
86 #include <cppuhelper/implbase2.hxx>
87 #include <cppuhelper/typeprovider.hxx>
88 #include <osl/mutex.hxx>
89 #include <rtl/logfile.hxx>
90 #include <sfx2/app.hxx>
91 #include <sfx2/sfx.hrc>
92 #include <svx/fmsearch.hxx>
93 #include <svx/svxdlg.hxx>
94 #include <tools/diagnose_ex.h>
95 #include <osl/diagnose.h>
96 #include <vcl/msgbox.hxx>
97 #include <vcl/waitobj.hxx>
99 using namespace ::com::sun::star::uno
;
100 using namespace ::com::sun::star::awt
;
101 using namespace ::com::sun::star::sdb
;
102 using namespace ::com::sun::star::sdbc
;
103 using namespace ::com::sun::star::sdbcx
;
104 using namespace ::com::sun::star::task
;
105 using namespace ::com::sun::star::beans
;
106 using namespace ::com::sun::star::frame
;
107 using namespace ::com::sun::star::form
;
108 using namespace ::com::sun::star::util
;
109 using namespace ::com::sun::star::lang
;
110 using namespace ::com::sun::star::container
;
111 using namespace ::dbtools
;
112 using namespace ::comphelper
;
113 using namespace ::svt
;
115 #define HANDLE_SQL_ERRORS( action, successflag, context, message ) \
118 successflag = sal_False; \
120 successflag = sal_True; \
122 catch(SQLException& e) \
124 SQLException aError = ::dbtools::prependErrorInfo(e, *this, context); \
125 ::com::sun::star::sdb::SQLErrorEvent aEvent; \
126 aEvent.Reason <<= aError; \
127 errorOccured(aEvent); \
131 DBG_UNHANDLED_EXCEPTION(); \
134 #define DO_SAFE( action, message ) try { action; } catch(Exception&) { OSL_FAIL(message); } ;
136 //..................................................................
139 //..................................................................
141 //==================================================================
142 // OParameterContinuation
143 //==================================================================
144 class OParameterContinuation
: public OInteraction
< XInteractionSupplyParameters
>
146 Sequence
< PropertyValue
> m_aValues
;
149 OParameterContinuation() { }
151 Sequence
< PropertyValue
> getValues() const { return m_aValues
; }
153 // XInteractionSupplyParameters
154 virtual void SAL_CALL
setParameters( const Sequence
< PropertyValue
>& _rValues
) throw(RuntimeException
);
157 //------------------------------------------------------------------
158 void SAL_CALL
OParameterContinuation::setParameters( const Sequence
< PropertyValue
>& _rValues
) throw(RuntimeException
)
160 m_aValues
= _rValues
;
164 //==============================================================================
165 // a helper class implementing a runtime::XFormController, will be aggregated by SbaXDataBrowserController
166 // (we can't derive from XFormController as it's base class is XTabController and the XTabController::getModel collides
167 // with the XController::getModel implemented in our base class SbaXDataBrowserController)
168 class SbaXDataBrowserController::FormControllerImpl
169 : public ::cppu::WeakAggImplHelper2
< ::com::sun::star::form::runtime::XFormController
,
170 ::com::sun::star::frame::XFrameActionListener
>
172 friend class SbaXDataBrowserController
;
173 ::cppu::OInterfaceContainerHelper m_aActivateListeners
;
174 SbaXDataBrowserController
* m_pOwner
;
177 FormControllerImpl(SbaXDataBrowserController
* pOwner
);
180 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormOperations
> SAL_CALL
getFormOperations() throw (::com::sun::star::uno::RuntimeException
);
181 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
> SAL_CALL
getCurrentControl(void) throw( ::com::sun::star::uno::RuntimeException
);
182 virtual void SAL_CALL
addActivateListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormControllerListener
> & l
) throw( ::com::sun::star::uno::RuntimeException
);
183 virtual void SAL_CALL
removeActivateListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XFormControllerListener
> & l
) throw( ::com::sun::star::uno::RuntimeException
);
184 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
);
185 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormControllerContext
> SAL_CALL
getContext() throw (::com::sun::star::uno::RuntimeException
);
186 virtual void SAL_CALL
setContext( const ::com::sun::star::uno::Reference
< ::com::sun::star::form::runtime::XFormControllerContext
>& _context
) throw (::com::sun::star::uno::RuntimeException
);
187 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionHandler
> SAL_CALL
getInteractionHandler() throw (::com::sun::star::uno::RuntimeException
);
188 virtual void SAL_CALL
setInteractionHandler( const ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionHandler
>& _interactionHandler
) throw (::com::sun::star::uno::RuntimeException
);
190 // XChild, base of XFormController
191 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
getParent( ) throw (::com::sun::star::uno::RuntimeException
);
192 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
);
194 // XComponent, base of XFormController
195 virtual void SAL_CALL
dispose( ) throw (::com::sun::star::uno::RuntimeException
);
196 virtual void SAL_CALL
addEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
197 virtual void SAL_CALL
removeEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
199 // XIndexAccess, base of XFormController
200 virtual ::sal_Int32 SAL_CALL
getCount( ) throw (::com::sun::star::uno::RuntimeException
);
201 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
);
203 // XElementAccess, base of XIndexAccess
204 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType( ) throw (::com::sun::star::uno::RuntimeException
);
205 virtual ::sal_Bool SAL_CALL
hasElements( ) throw (::com::sun::star::uno::RuntimeException
);
207 // XEnumerationAccess, base of XElementAccess
208 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumeration
> SAL_CALL
createEnumeration( ) throw (::com::sun::star::uno::RuntimeException
);
210 // XModifyBroadcaster, base of XFormController
211 virtual void SAL_CALL
addModifyListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::util::XModifyListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
212 virtual void SAL_CALL
removeModifyListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::util::XModifyListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
214 // XConfirmDeleteBroadcaster, base of XFormController
215 virtual void SAL_CALL
addConfirmDeleteListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XConfirmDeleteListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
216 virtual void SAL_CALL
removeConfirmDeleteListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XConfirmDeleteListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
218 // XSQLErrorBroadcaster, base of XFormController
219 virtual void SAL_CALL
addSQLErrorListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XSQLErrorListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
);
220 virtual void SAL_CALL
removeSQLErrorListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XSQLErrorListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
);
222 // XRowSetApproveBroadcaster, base of XFormController
223 virtual void SAL_CALL
addRowSetApproveListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XRowSetApproveListener
>& listener
) throw (::com::sun::star::uno::RuntimeException
);
224 virtual void SAL_CALL
removeRowSetApproveListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XRowSetApproveListener
>& listener
) throw (::com::sun::star::uno::RuntimeException
);
226 // XDatabaseParameterBroadcaster2, base of XFormController
227 virtual void SAL_CALL
addDatabaseParameterListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XDatabaseParameterListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
228 virtual void SAL_CALL
removeDatabaseParameterListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XDatabaseParameterListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
230 // XDatabaseParameterBroadcaster, base of XDatabaseParameterBroadcaster2
231 virtual void SAL_CALL
addParameterListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XDatabaseParameterListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
232 virtual void SAL_CALL
removeParameterListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::form::XDatabaseParameterListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
234 // XModeSelector, base of XFormController
235 virtual void SAL_CALL
setMode( const ::rtl::OUString
& aMode
) throw (::com::sun::star::lang::NoSupportException
, ::com::sun::star::uno::RuntimeException
);
236 virtual ::rtl::OUString SAL_CALL
getMode( ) throw (::com::sun::star::uno::RuntimeException
);
237 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedModes( ) throw (::com::sun::star::uno::RuntimeException
);
238 virtual ::sal_Bool SAL_CALL
supportsMode( const ::rtl::OUString
& aMode
) throw (::com::sun::star::uno::RuntimeException
);
240 // XTabController, base of XFormController
241 virtual void SAL_CALL
setModel(const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTabControllerModel
> & Model
) throw( ::com::sun::star::uno::RuntimeException
);
242 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTabControllerModel
> SAL_CALL
getModel(void) throw( ::com::sun::star::uno::RuntimeException
);
243 virtual void SAL_CALL
setContainer(const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlContainer
> & _Container
) throw( ::com::sun::star::uno::RuntimeException
);
244 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlContainer
> SAL_CALL
getContainer(void) throw( ::com::sun::star::uno::RuntimeException
);
245 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControl
> > SAL_CALL
getControls(void) throw( ::com::sun::star::uno::RuntimeException
);
246 virtual void SAL_CALL
autoTabOrder(void) throw( ::com::sun::star::uno::RuntimeException
);
247 virtual void SAL_CALL
activateTabOrder(void) throw( ::com::sun::star::uno::RuntimeException
);
248 virtual void SAL_CALL
activateFirst(void) throw( ::com::sun::star::uno::RuntimeException
);
249 virtual void SAL_CALL
activateLast(void) throw( ::com::sun::star::uno::RuntimeException
);
251 // XFrameActionListener
252 virtual void SAL_CALL
frameAction(const ::com::sun::star::frame::FrameActionEvent
& aEvent
) throw( ::com::sun::star::uno::RuntimeException
);
255 virtual void SAL_CALL
disposing(const ::com::sun::star::lang::EventObject
& Source
) throw( ::com::sun::star::uno::RuntimeException
);
258 ~FormControllerImpl();
262 DBG_NAME(FormControllerImpl
)
263 //------------------------------------------------------------------
264 SbaXDataBrowserController::FormControllerImpl::FormControllerImpl(SbaXDataBrowserController
* _pOwner
)
265 :m_aActivateListeners(_pOwner
->getMutex())
268 DBG_CTOR(FormControllerImpl
,NULL
);
270 OSL_ENSURE(m_pOwner
, "SbaXDataBrowserController::FormControllerImpl::FormControllerImpl : invalid Owner !");
273 //------------------------------------------------------------------
274 SbaXDataBrowserController::FormControllerImpl::~FormControllerImpl()
277 DBG_DTOR(FormControllerImpl
,NULL
);
280 //------------------------------------------------------------------
281 Reference
< runtime::XFormOperations
> SAL_CALL
SbaXDataBrowserController::FormControllerImpl::getFormOperations() throw (RuntimeException
)
283 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::getFormOperations: not supported!" );
287 //------------------------------------------------------------------
288 Reference
< ::com::sun::star::awt::XControl
> SbaXDataBrowserController::FormControllerImpl::getCurrentControl(void) throw( RuntimeException
)
290 return m_pOwner
->getBrowserView() ? m_pOwner
->getBrowserView()->getGridControl() : Reference
< ::com::sun::star::awt::XControl
> ();
293 //------------------------------------------------------------------
294 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::addActivateListener(const Reference
< ::com::sun::star::form::XFormControllerListener
> & l
) throw( RuntimeException
)
296 m_aActivateListeners
.addInterface(l
);
299 //------------------------------------------------------------------
300 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::removeActivateListener(const Reference
< ::com::sun::star::form::XFormControllerListener
> & l
) throw( RuntimeException
)
302 m_aActivateListeners
.removeInterface(l
);
305 //------------------------------------------------------------------
306 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::addChildController( const Reference
< runtime::XFormController
>& /*_ChildController*/ ) throw( RuntimeException
, IllegalArgumentException
)
309 throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
312 //------------------------------------------------------------------
313 Reference
< runtime::XFormControllerContext
> SAL_CALL
SbaXDataBrowserController::FormControllerImpl::getContext() throw (RuntimeException
)
315 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::getContext: no support!!" );
319 //------------------------------------------------------------------
320 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::setContext( const Reference
< runtime::XFormControllerContext
>& /*_context*/ ) throw (RuntimeException
)
322 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::setContext: no support!!" );
325 //------------------------------------------------------------------
326 Reference
< XInteractionHandler
> SAL_CALL
SbaXDataBrowserController::FormControllerImpl::getInteractionHandler() throw (RuntimeException
)
328 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::getInteractionHandler: no support!!" );
332 //------------------------------------------------------------------
333 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::setInteractionHandler( const Reference
< XInteractionHandler
>& /*_interactionHandler*/ ) throw (RuntimeException
)
335 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::setInteractionHandler: no support!!" );
338 //------------------------------------------------------------------
339 Reference
< XInterface
> SAL_CALL
SbaXDataBrowserController::FormControllerImpl::getParent( ) throw (RuntimeException
)
341 // don't have any parent form controllers
345 //------------------------------------------------------------------
346 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::setParent( const Reference
< XInterface
>& /*Parent*/ ) throw (NoSupportException
, RuntimeException
)
348 throw NoSupportException( ::rtl::OUString(), *this );
351 //------------------------------------------------------------------
352 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::dispose( ) throw (RuntimeException
)
354 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::dispose: no, you do *not* want to do this!" );
357 //------------------------------------------------------------------
358 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::addEventListener( const Reference
< XEventListener
>& /*xListener*/ ) throw (RuntimeException
)
360 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::addEventListener: no support!!" );
363 //------------------------------------------------------------------
364 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::removeEventListener( const Reference
< XEventListener
>& /*aListener*/ ) throw (RuntimeException
)
366 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::removeEventListener: no support!!" );
369 //------------------------------------------------------------------
370 ::sal_Int32 SAL_CALL
SbaXDataBrowserController::FormControllerImpl::getCount( ) throw (RuntimeException
)
372 // no sub controllers, never
376 //------------------------------------------------------------------
377 Any SAL_CALL
SbaXDataBrowserController::FormControllerImpl::getByIndex( ::sal_Int32
/*Index*/ ) throw (IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
379 // no sub controllers, never
380 throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
383 //------------------------------------------------------------------
384 Type SAL_CALL
SbaXDataBrowserController::FormControllerImpl::getElementType( ) throw (RuntimeException
)
386 return ::cppu::UnoType
< runtime::XFormController
>::get();
389 //------------------------------------------------------------------
390 ::sal_Bool SAL_CALL
SbaXDataBrowserController::FormControllerImpl::hasElements( ) throw (RuntimeException
)
392 // no sub controllers, never
396 //------------------------------------------------------------------
397 Reference
< XEnumeration
> SAL_CALL
SbaXDataBrowserController::FormControllerImpl::createEnumeration( ) throw (RuntimeException
)
399 return new ::comphelper::OEnumerationByIndex( this );
402 //------------------------------------------------------------------
403 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::addModifyListener( const Reference
< XModifyListener
>& /*_Listener*/ ) throw (RuntimeException
)
405 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::addModifyListener: no support!" );
408 //------------------------------------------------------------------
409 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::removeModifyListener( const Reference
< XModifyListener
>& /*_Listener*/ ) throw (RuntimeException
)
411 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::removeModifyListener: no support!" );
414 //------------------------------------------------------------------
415 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::addConfirmDeleteListener( const Reference
< XConfirmDeleteListener
>& /*_Listener*/ ) throw (RuntimeException
)
417 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::addConfirmDeleteListener: no support!" );
420 //------------------------------------------------------------------
421 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::removeConfirmDeleteListener( const Reference
< XConfirmDeleteListener
>& /*_Listener*/ ) throw (RuntimeException
)
423 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::removeConfirmDeleteListener: no support!" );
426 //------------------------------------------------------------------
427 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::addSQLErrorListener( const Reference
< XSQLErrorListener
>& /*_Listener*/ ) throw (RuntimeException
)
429 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::addSQLErrorListener: no support!" );
432 //------------------------------------------------------------------
433 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::removeSQLErrorListener( const Reference
< XSQLErrorListener
>& /*_Listener*/ ) throw (RuntimeException
)
435 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::removeSQLErrorListener: no support!" );
438 //------------------------------------------------------------------
439 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::addRowSetApproveListener( const Reference
< XRowSetApproveListener
>& /*_Listener*/ ) throw (RuntimeException
)
441 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::addRowSetApproveListener: no support!" );
444 //------------------------------------------------------------------
445 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::removeRowSetApproveListener( const Reference
< XRowSetApproveListener
>& /*_Listener*/ ) throw (RuntimeException
)
447 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::removeRowSetApproveListener: no support!" );
450 //------------------------------------------------------------------
451 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::addDatabaseParameterListener( const Reference
< XDatabaseParameterListener
>& /*_Listener*/ ) throw (RuntimeException
)
453 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::addDatabaseParameterListener: no support!" );
456 //------------------------------------------------------------------
457 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::removeDatabaseParameterListener( const Reference
< XDatabaseParameterListener
>& /*_Listener*/ ) throw (RuntimeException
)
459 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::removeDatabaseParameterListener: no support!" );
462 //------------------------------------------------------------------
463 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::addParameterListener( const Reference
< XDatabaseParameterListener
>& /*_Listener*/ ) throw (RuntimeException
)
465 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::addParameterListener: no support!" );
468 //------------------------------------------------------------------
469 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::removeParameterListener( const Reference
< XDatabaseParameterListener
>& /*_Listener*/ ) throw (RuntimeException
)
471 OSL_FAIL( "SbaXDataBrowserController::FormControllerImpl::removeParameterListener: no support!" );
474 //------------------------------------------------------------------
475 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::setMode( const ::rtl::OUString
& _rMode
) throw (NoSupportException
, RuntimeException
)
477 if ( !supportsMode( _rMode
) )
478 throw NoSupportException();
481 //------------------------------------------------------------------
482 ::rtl::OUString SAL_CALL
SbaXDataBrowserController::FormControllerImpl::getMode( ) throw (RuntimeException
)
484 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DataMode" ) );
487 //------------------------------------------------------------------
488 Sequence
< ::rtl::OUString
> SAL_CALL
SbaXDataBrowserController::FormControllerImpl::getSupportedModes( ) throw (RuntimeException
)
490 Sequence
< ::rtl::OUString
> aModes(1);
491 aModes
[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DataMode" ) );
495 //------------------------------------------------------------------
496 ::sal_Bool SAL_CALL
SbaXDataBrowserController::FormControllerImpl::supportsMode( const ::rtl::OUString
& aMode
) throw (RuntimeException
)
498 return aMode
.compareToAscii( "DataMode" ) == 0;
501 //------------------------------------------------------------------
502 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::setModel(const Reference
< ::com::sun::star::awt::XTabControllerModel
> & /*Model*/) throw( RuntimeException
)
504 OSL_FAIL("SbaXDataBrowserController::FormControllerImpl::setModel : invalid call, can't change my model !");
507 //------------------------------------------------------------------
508 Reference
< ::com::sun::star::awt::XTabControllerModel
> SAL_CALL
SbaXDataBrowserController::FormControllerImpl::getModel(void) throw( RuntimeException
)
510 return Reference
< XTabControllerModel
>(m_pOwner
->getRowSet(), UNO_QUERY
);
513 //------------------------------------------------------------------
514 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::setContainer(const Reference
< ::com::sun::star::awt::XControlContainer
> & /*_Container*/) throw( RuntimeException
)
516 OSL_FAIL("SbaXDataBrowserController::FormControllerImpl::setContainer : invalid call, can't change my container !");
519 //------------------------------------------------------------------
520 Reference
< ::com::sun::star::awt::XControlContainer
> SAL_CALL
SbaXDataBrowserController::FormControllerImpl::getContainer(void) throw( RuntimeException
)
522 if (m_pOwner
->getBrowserView())
523 return m_pOwner
->getBrowserView()->getContainer();
524 return Reference
< ::com::sun::star::awt::XControlContainer
> ();
527 //------------------------------------------------------------------
528 Sequence
< Reference
< ::com::sun::star::awt::XControl
> > SAL_CALL
SbaXDataBrowserController::FormControllerImpl::getControls(void) throw( RuntimeException
)
530 if (m_pOwner
->getBrowserView())
532 Reference
< ::com::sun::star::awt::XControl
> xGrid
= m_pOwner
->getBrowserView()->getGridControl();
533 return Sequence
< Reference
< ::com::sun::star::awt::XControl
> >(&xGrid
, 1);
535 return Sequence
< Reference
< ::com::sun::star::awt::XControl
> >();
538 //------------------------------------------------------------------
539 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::autoTabOrder(void) throw( RuntimeException
)
541 OSL_FAIL("SbaXDataBrowserController::FormControllerImpl::autoTabOrder : nothing to do (always have only one control) !");
544 //------------------------------------------------------------------
545 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::activateTabOrder(void) throw( RuntimeException
)
547 OSL_FAIL("SbaXDataBrowserController::FormControllerImpl::activateTabOrder : nothing to do (always have only one control) !");
550 //------------------------------------------------------------------
551 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::activateFirst(void) throw( RuntimeException
)
553 if (m_pOwner
->getBrowserView())
554 m_pOwner
->getBrowserView()->getVclControl()->ActivateCell();
557 //------------------------------------------------------------------
558 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::activateLast(void) throw( RuntimeException
)
560 if (m_pOwner
->getBrowserView())
561 m_pOwner
->getBrowserView()->getVclControl()->ActivateCell();
564 //------------------------------------------------------------------
565 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::frameAction(const ::com::sun::star::frame::FrameActionEvent
& /*aEvent*/) throw( RuntimeException
)
569 //------------------------------------------------------------------
570 void SAL_CALL
SbaXDataBrowserController::FormControllerImpl::disposing(const ::com::sun::star::lang::EventObject
& /*Source*/) throw( RuntimeException
)
573 // we don't add ourself as listener to any broadcasters, so we are not resposible for removing us
576 //==================================================================
577 //= SbaXDataBrowserController
578 //==================================================================
579 //------------------------------------------------------------------
580 Sequence
< Type
> SAL_CALL
SbaXDataBrowserController::getTypes( ) throw (RuntimeException
)
582 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::getTypes" );
583 return ::comphelper::concatSequences(
584 SbaXDataBrowserController_Base::getTypes(),
585 m_pFormControllerImpl
->getTypes()
589 //------------------------------------------------------------------
590 Sequence
< sal_Int8
> SAL_CALL
SbaXDataBrowserController::getImplementationId( ) throw (RuntimeException
)
592 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::getImplementationId" );
593 static ::cppu::OImplementationId
* pId
= 0;
596 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
599 static ::cppu::OImplementationId aId
;
603 return pId
->getImplementationId();
606 //------------------------------------------------------------------
607 Any SAL_CALL
SbaXDataBrowserController::queryInterface(const Type
& _rType
) throw (RuntimeException
)
609 // check for our additional interfaces
610 Any aRet
= SbaXDataBrowserController_Base::queryInterface(_rType
);
612 // check for our aggregate (implementing the XFormController)
613 if (!aRet
.hasValue())
614 aRet
= m_xFormControllerImpl
->queryAggregation(_rType
);
620 DBG_NAME(SbaXDataBrowserController
)
621 //------------------------------------------------------------------------------
622 SbaXDataBrowserController::SbaXDataBrowserController(const Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rM
)
623 :SbaXDataBrowserController_Base(_rM
)
624 ,m_nRowSetPrivileges(0)
625 ,m_pClipbordNotifier( NULL
)
626 ,m_aAsyncGetCellFocus(LINK(this, SbaXDataBrowserController
, OnAsyncGetCellFocus
))
627 ,m_aAsyncDisplayError( LINK( this, SbaXDataBrowserController
, OnAsyncDisplayError
) )
628 ,m_sStateSaveRecord(ModuleRes(RID_STR_SAVE_CURRENT_RECORD
))
629 ,m_sStateUndoRecord(ModuleRes(RID_STR_UNDO_MODIFY_RECORD
))
630 ,m_sModuleIdentifier( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.DataSourceBrowser" ) ) )
631 ,m_pFormControllerImpl(NULL
)
632 ,m_nPendingLoadFinished(0)
633 ,m_nFormActionNestingLevel(0)
634 ,m_bLoadCanceled( sal_False
)
635 ,m_bClosingKillOpen( sal_False
)
636 ,m_bCannotSelectUnfiltered( true )
638 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::SbaXDataBrowserController" );
639 DBG_CTOR(SbaXDataBrowserController
,NULL
);
641 // create the form controller aggregate
642 ::comphelper::increment(m_refCount
);
644 m_pFormControllerImpl
= new FormControllerImpl(this);
645 m_xFormControllerImpl
= m_pFormControllerImpl
;
646 m_xFormControllerImpl
->setDelegator(*this);
648 ::comphelper::decrement(m_refCount
);
650 m_aInvalidateClipboard
.SetTimeoutHdl(LINK(this, SbaXDataBrowserController
, OnInvalidateClipboard
));
651 m_aInvalidateClipboard
.SetTimeout(300);
654 //------------------------------------------------------------------------------
655 SbaXDataBrowserController::~SbaXDataBrowserController()
657 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::~SbaXDataBrowserController" );
659 // release the aggregated form controller
660 if (m_xFormControllerImpl
.is())
662 Reference
< XInterface
> xEmpty
;
663 m_xFormControllerImpl
->setDelegator(xEmpty
);
666 DBG_DTOR(SbaXDataBrowserController
,NULL
);
669 // -----------------------------------------------------------------------
670 void SbaXDataBrowserController::startFrameListening( const Reference
< XFrame
>& _rxFrame
)
672 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::startFrameListening" );
673 SbaXDataBrowserController_Base::startFrameListening( _rxFrame
);
675 Reference
< XFrameActionListener
> xAggListener
;
676 if ( m_xFormControllerImpl
.is() )
677 m_xFormControllerImpl
->queryAggregation( XFrameActionListener::static_type() ) >>= xAggListener
;
679 if ( _rxFrame
.is() && xAggListener
.is() )
680 _rxFrame
->addFrameActionListener( xAggListener
);
683 // -----------------------------------------------------------------------
684 void SbaXDataBrowserController::stopFrameListening( const Reference
< XFrame
>& _rxFrame
)
686 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::stopFrameListening" );
687 SbaXDataBrowserController_Base::stopFrameListening( _rxFrame
);
689 Reference
< XFrameActionListener
> xAggListener
;
690 if ( m_xFormControllerImpl
.is() )
691 m_xFormControllerImpl
->queryAggregation( XFrameActionListener::static_type() ) >>= xAggListener
;
693 if ( _rxFrame
.is() && xAggListener
.is() )
694 _rxFrame
->removeFrameActionListener( xAggListener
);
697 // -----------------------------------------------------------------------------
698 void SbaXDataBrowserController::onStartLoading( const Reference
< XLoadable
>& _rxLoadable
)
700 m_bLoadCanceled
= sal_False
;
701 m_bCannotSelectUnfiltered
= false;
703 Reference
< XWarningsSupplier
> xWarnings( _rxLoadable
, UNO_QUERY
);
704 if ( xWarnings
.is() )
705 xWarnings
->clearWarnings();
708 // -----------------------------------------------------------------------------
709 void SbaXDataBrowserController::impl_checkForCannotSelectUnfiltered( const SQLExceptionInfo
& _rError
)
711 ::connectivity::SQLError
aError( getORB() );
712 ::connectivity::ErrorCode
nErrorCode( aError
.getErrorCode( ErrorCondition::DATA_CANNOT_SELECT_UNFILTERED
) );
713 if ( ((const SQLException
*)_rError
)->ErrorCode
== nErrorCode
)
715 m_bCannotSelectUnfiltered
= true;
716 InvalidateFeature( ID_BROWSER_FILTERCRIT
);
720 // -----------------------------------------------------------------------------
721 sal_Bool
SbaXDataBrowserController::reloadForm( const Reference
< XLoadable
>& _rxLoadable
)
723 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::reloadForm" );
724 WaitObject
aWO(getBrowserView());
726 onStartLoading( _rxLoadable
);
728 FormErrorHelper
aReportError(this);
729 if (_rxLoadable
->isLoaded())
730 _rxLoadable
->reload();
735 const Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
736 if (::comphelper::getBOOL(xFormSet
->getPropertyValue(PROPERTY_ESCAPE_PROCESSING
)))
737 xFormSet
->getPropertyValue(PROPERTY_SINGLESELECTQUERYCOMPOSER
) >>= m_xParser
;
740 const Reference
< XPropertySet
> xRowSetProps( getRowSet(), UNO_QUERY
);
741 const Reference
< XSingleSelectQueryAnalyzer
> xAnalyzer( xRowSetProps
->getPropertyValue( PROPERTY_SINGLESELECTQUERYCOMPOSER
), UNO_QUERY
);
742 if ( xAnalyzer
.is() )
744 const Reference
< XIndexAccess
> xOrderColumns( xAnalyzer
->getOrderColumns(), UNO_SET_THROW
);
745 const sal_Int32
nOrderColumns( xOrderColumns
->getCount() );
746 for ( sal_Int32 c
=0; c
<nOrderColumns
; ++c
)
748 const Reference
< XPropertySet
> xOrderColumn( xOrderColumns
->getByIndex(c
), UNO_QUERY_THROW
);
749 ::rtl::OUString sColumnName
;
750 OSL_VERIFY( xOrderColumn
->getPropertyValue( PROPERTY_NAME
) >>= sColumnName
);
751 ::rtl::OUString sTableName
;
752 OSL_VERIFY( xOrderColumn
->getPropertyValue( PROPERTY_TABLENAME
) >>= sTableName
);
760 Reference
< XWarningsSupplier
> xWarnings( _rxLoadable
, UNO_QUERY
);
761 if ( xWarnings
.is() )
765 SQLExceptionInfo
aInfo( xWarnings
->getWarnings() );
766 if ( aInfo
.isValid() )
769 impl_checkForCannotSelectUnfiltered( aInfo
);
772 catch(const SQLException
& e
)
778 return _rxLoadable
->isLoaded();
781 // -----------------------------------------------------------------------------
782 void SbaXDataBrowserController::initFormatter()
784 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::initFormatter" );
785 // ---------------------------------------------------------------
786 // create a formatter working with the connections format supplier
787 Reference
< ::com::sun::star::util::XNumberFormatsSupplier
> xSupplier(::dbtools::getNumberFormats(::dbtools::getConnection(m_xRowSet
), sal_True
,getORB()));
791 // create a new formatter
792 m_xFormatter
= Reference
< ::com::sun::star::util::XNumberFormatter
> (
793 getORB()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatter"))), UNO_QUERY
);
794 if (m_xFormatter
.is())
795 m_xFormatter
->attachNumberFormatsSupplier(xSupplier
);
797 else // clear the formatter
800 // -----------------------------------------------------------------------------
801 void SbaXDataBrowserController::describeSupportedFeatures()
803 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::describeSupportedFeatures" );
804 SbaXDataBrowserController_Base::describeSupportedFeatures();
805 implDescribeSupportedFeature( ".uno:FormSlots/undoRecord", ID_BROWSER_UNDORECORD
, CommandGroup::CONTROLS
);
806 implDescribeSupportedFeature( ".uno:FormController/undoRecord", ID_BROWSER_UNDORECORD
, CommandGroup::CONTROLS
);
807 implDescribeSupportedFeature( ".uno:RecUndo", ID_BROWSER_UNDORECORD
, CommandGroup::CONTROLS
);
808 implDescribeSupportedFeature( ".uno:FormSlots/saveRecord", ID_BROWSER_SAVERECORD
, CommandGroup::CONTROLS
);
809 implDescribeSupportedFeature( ".uno:FormController/saveRecord", ID_BROWSER_SAVERECORD
, CommandGroup::CONTROLS
);
810 implDescribeSupportedFeature( ".uno:RecSave", ID_BROWSER_SAVERECORD
, CommandGroup::CONTROLS
);
811 implDescribeSupportedFeature( ".uno:Save", ID_BROWSER_SAVERECORD
, CommandGroup::DOCUMENT
);
812 implDescribeSupportedFeature( ".uno:RecSearch", SID_FM_SEARCH
, CommandGroup::CONTROLS
);
813 implDescribeSupportedFeature( ".uno:AutoFilter", SID_FM_AUTOFILTER
, CommandGroup::CONTROLS
);
814 implDescribeSupportedFeature( ".uno:Refresh", SID_FM_REFRESH
, CommandGroup::CONTROLS
);
815 implDescribeSupportedFeature( ".uno:OrderCrit", SID_FM_ORDERCRIT
, CommandGroup::CONTROLS
);
816 implDescribeSupportedFeature( ".uno:RemoveFilterSort", SID_FM_REMOVE_FILTER_SORT
,CommandGroup::CONTROLS
);
817 implDescribeSupportedFeature( ".uno:FormFiltered", SID_FM_FORM_FILTERED
, CommandGroup::CONTROLS
);
818 implDescribeSupportedFeature( ".uno:FilterCrit", SID_FM_FILTERCRIT
, CommandGroup::CONTROLS
);
819 implDescribeSupportedFeature( ".uno:Sortup", ID_BROWSER_SORTUP
, CommandGroup::CONTROLS
);
820 implDescribeSupportedFeature( ".uno:SortDown", ID_BROWSER_SORTDOWN
, CommandGroup::CONTROLS
);
821 implDescribeSupportedFeature( ".uno:FormSlots/deleteRecord", SID_FM_DELETEROWS
, CommandGroup::EDIT
);
822 implDescribeSupportedFeature( ".uno:FormSlots/insertRecord", ID_BROWSER_INSERT_ROW
, CommandGroup::INSERT
);
824 //------------------------------------------------------------------------------
825 sal_Bool
SbaXDataBrowserController::Construct(Window
* pParent
)
827 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::Construct" );
828 // ---------------------------------------------
829 // create/initialize the form and the grid model
830 m_xRowSet
= CreateForm();
834 m_xColumnsSupplier
.set(m_xRowSet
,UNO_QUERY
);
835 m_xLoadable
.set(m_xRowSet
,UNO_QUERY
);
837 Reference
< XPropertySet
> xFormProperties( m_xRowSet
, UNO_QUERY
);
838 if ( !InitializeForm( xFormProperties
) )
841 m_xGridModel
= CreateGridModel();
842 if (!m_xGridModel
.is())
845 // set the formatter if available
847 // ---------------------------------------------------------------
849 // we want to have a grid with a "flat" border
850 Reference
< XPropertySet
> xGridSet(m_xGridModel
, UNO_QUERY
);
852 xGridSet
->setPropertyValue(PROPERTY_BORDER
, makeAny((sal_Int16
)2));
856 Reference
< ::com::sun::star::container::XNameContainer
> xNameCont(m_xRowSet
, UNO_QUERY
);
858 String
sText(ModuleRes(STR_DATASOURCE_GRIDCONTROL_NAME
));
859 xNameCont
->insertByName(::rtl::OUString(sText
), makeAny(m_xGridModel
));
864 setView( * new UnoDataBrowserView( pParent
, *this, getORB() ) );
865 if (!getBrowserView())
869 sal_Bool bSuccess
= sal_False
;
872 getBrowserView()->Construct(getControlModel());
880 OSL_FAIL("SbaXDataBrowserController::Construct : the construction of UnoDataBrowserView failed !");
889 // now that we have a view we can create the clipboard listener
890 m_aSystemClipboard
= TransferableDataHelper::CreateFromSystemClipboard( getView() );
891 m_aSystemClipboard
.StartClipboardListening( );
893 m_pClipbordNotifier
= new TransferableClipboardListener( LINK( this, SbaXDataBrowserController
, OnClipboardChanged
) );
894 m_pClipbordNotifier
->acquire();
895 m_pClipbordNotifier
->AddRemoveListener( getView(), sal_True
);
897 // this call create the toolbox
898 SbaXDataBrowserController_Base::Construct(pParent
);
900 getBrowserView()->Show();
902 // set the callbacks for the grid control
903 SbaGridControl
* pVclGrid
= getBrowserView()->getVclControl();
904 OSL_ENSURE(pVclGrid
, "SbaXDataBrowserController::Construct : have no VCL control !");
905 pVclGrid
->SetMasterListener(this);
907 // --------------------------
910 // ... to the form model
911 Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
914 xFormSet
->addPropertyChangeListener(PROPERTY_ISNEW
, static_cast<XPropertyChangeListener
*>(this));
915 xFormSet
->addPropertyChangeListener(PROPERTY_ISMODIFIED
, static_cast<XPropertyChangeListener
*>(this));
916 xFormSet
->addPropertyChangeListener(PROPERTY_ROWCOUNT
, static_cast<XPropertyChangeListener
*>(this));
917 xFormSet
->addPropertyChangeListener(PROPERTY_ACTIVECOMMAND
, static_cast<XPropertyChangeListener
*>(this));
918 xFormSet
->addPropertyChangeListener(PROPERTY_ORDER
, static_cast<XPropertyChangeListener
*>(this));
919 xFormSet
->addPropertyChangeListener(PROPERTY_FILTER
, static_cast<XPropertyChangeListener
*>(this));
920 xFormSet
->addPropertyChangeListener(PROPERTY_HAVING_CLAUSE
, static_cast<XPropertyChangeListener
*>(this));
921 xFormSet
->addPropertyChangeListener(PROPERTY_APPLYFILTER
, static_cast<XPropertyChangeListener
*>(this));
923 Reference
< ::com::sun::star::sdb::XSQLErrorBroadcaster
> xFormError(getRowSet(), UNO_QUERY
);
925 xFormError
->addSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener
*)this);
927 if (m_xLoadable
.is())
928 m_xLoadable
->addLoadListener(this);
930 Reference
< ::com::sun::star::form::XDatabaseParameterBroadcaster
> xFormParameter(getRowSet(), UNO_QUERY
);
931 if (xFormParameter
.is())
932 xFormParameter
->addParameterListener((::com::sun::star::form::XDatabaseParameterListener
*)this);
934 addModelListeners(getControlModel());
935 addControlListeners(getBrowserView()->getGridControl());
942 //------------------------------------------------------------------------------
943 sal_Bool
SbaXDataBrowserController::LoadForm()
945 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::LoadForm" );
946 reloadForm( m_xLoadable
);
949 //------------------------------------------------------------------------------
950 void SbaXDataBrowserController::AddColumnListener(const Reference
< XPropertySet
> & /*xCol*/)
952 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::AddColumnListener" );
953 // we're not interested in any column properties ...
956 //------------------------------------------------------------------------------
957 void SbaXDataBrowserController::RemoveColumnListener(const Reference
< XPropertySet
> & /*xCol*/)
959 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::RemoveColumnListener" );
961 //------------------------------------------------------------------------------
962 Reference
< XRowSet
> SbaXDataBrowserController::CreateForm()
964 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::CreateForm" );
965 return Reference
< XRowSet
> (getORB()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.Form"))), UNO_QUERY
);
968 //------------------------------------------------------------------------------
969 Reference
< ::com::sun::star::form::XFormComponent
> SbaXDataBrowserController::CreateGridModel()
971 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::CreateGridModel" );
972 return Reference
< ::com::sun::star::form::XFormComponent
> (getORB()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.GridControl"))), UNO_QUERY
);
975 // -------------------------------------------------------------------------
976 void SbaXDataBrowserController::addModelListeners(const Reference
< ::com::sun::star::awt::XControlModel
> & _xGridControlModel
)
978 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::addModelListeners" );
979 // ... all the grid columns
980 addColumnListeners(_xGridControlModel
);
982 // (we are interested in all columns the grid has (and only in these) so we have to listen to the container, too)
983 Reference
< ::com::sun::star::container::XContainer
> xColContainer(_xGridControlModel
, UNO_QUERY
);
984 if (xColContainer
.is())
985 xColContainer
->addContainerListener((::com::sun::star::container::XContainerListener
*)this);
987 Reference
< ::com::sun::star::form::XReset
> xReset(_xGridControlModel
, UNO_QUERY
);
989 xReset
->addResetListener((::com::sun::star::form::XResetListener
*)this);
992 // -------------------------------------------------------------------------
993 void SbaXDataBrowserController::removeModelListeners(const Reference
< XControlModel
> & _xGridControlModel
)
995 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::removeModelListeners" );
996 // every single column model
997 Reference
< XIndexContainer
> xColumns(_xGridControlModel
, UNO_QUERY
);
1000 sal_Int32 nCount
= xColumns
->getCount();
1001 for (sal_uInt16 i
=0; i
< nCount
; ++i
)
1003 Reference
< XPropertySet
> xCol(xColumns
->getByIndex(i
),UNO_QUERY
);
1004 RemoveColumnListener(xCol
);
1008 Reference
< XContainer
> xColContainer(_xGridControlModel
, UNO_QUERY
);
1009 if (xColContainer
.is())
1010 xColContainer
->removeContainerListener( this );
1012 Reference
< XReset
> xReset(_xGridControlModel
, UNO_QUERY
);
1014 xReset
->removeResetListener( this );
1017 // -------------------------------------------------------------------------
1018 void SbaXDataBrowserController::addControlListeners(const Reference
< ::com::sun::star::awt::XControl
> & _xGridControl
)
1020 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::addControlListeners" );
1021 // to ge the 'modified' for the current cell
1022 Reference
< XModifyBroadcaster
> xBroadcaster(getBrowserView()->getGridControl(), UNO_QUERY
);
1023 if (xBroadcaster
.is())
1024 xBroadcaster
->addModifyListener(static_cast<XModifyListener
*>(this));
1026 // introduce ourself as dispatch provider for the grid
1027 Reference
< XDispatchProviderInterception
> xInterception(getBrowserView()->getGridControl(), UNO_QUERY
);
1028 if (xInterception
.is())
1029 xInterception
->registerDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor
*>(this));
1031 // add as focus listener to the control (needed for the form controller functionality)
1032 Reference
< XWindow
> xWindow(_xGridControl
, UNO_QUERY
);
1034 xWindow
->addFocusListener(this);
1037 // -------------------------------------------------------------------------
1038 void SbaXDataBrowserController::removeControlListeners(const Reference
< ::com::sun::star::awt::XControl
> & _xGridControl
)
1040 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::removeControlListeners" );
1041 Reference
< XModifyBroadcaster
> xBroadcaster(_xGridControl
, UNO_QUERY
);
1042 if (xBroadcaster
.is())
1043 xBroadcaster
->removeModifyListener(static_cast<XModifyListener
*>(this));
1045 Reference
< XDispatchProviderInterception
> xInterception(_xGridControl
, UNO_QUERY
);
1046 if (xInterception
.is())
1047 xInterception
->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor
*>(this));
1049 Reference
< XWindow
> xWindow(_xGridControl
, UNO_QUERY
);
1051 xWindow
->removeFocusListener(this);
1054 //------------------------------------------------------------------
1055 void SAL_CALL
SbaXDataBrowserController::focusGained(const FocusEvent
& /*e*/) throw( RuntimeException
)
1057 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::focusGained" );
1058 // notify our activate listeners (registered on the form controller aggregate)
1059 EventObject
aEvt(*this);
1060 ::cppu::OInterfaceIteratorHelper
aIter(m_pFormControllerImpl
->m_aActivateListeners
);
1061 while (aIter
.hasMoreElements())
1062 static_cast<XFormControllerListener
*>(aIter
.next())->formActivated(aEvt
);
1065 //------------------------------------------------------------------
1066 void SAL_CALL
SbaXDataBrowserController::focusLost(const FocusEvent
& e
) throw( RuntimeException
)
1068 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::focusLost" );
1069 // some general checks
1070 if (!getBrowserView() || !getBrowserView()->getGridControl().is())
1072 Reference
< XVclWindowPeer
> xMyGridPeer(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY
);
1073 if (!xMyGridPeer
.is())
1075 Reference
< XWindowPeer
> xNextControlPeer(e
.NextFocus
, UNO_QUERY
);
1076 if (!xNextControlPeer
.is())
1079 // don't do a notification if it remains in the family (i.e. a child of the grid control gets the focus)
1080 if (xMyGridPeer
->isChild(xNextControlPeer
))
1083 if (xMyGridPeer
== xNextControlPeer
)
1086 // notify the listeners that the "form" we represent has been deactivated
1087 EventObject
aEvt(*this);
1088 ::cppu::OInterfaceIteratorHelper
aIter(m_pFormControllerImpl
->m_aActivateListeners
);
1089 while (aIter
.hasMoreElements())
1090 static_cast<XFormControllerListener
*>(aIter
.next())->formDeactivated(aEvt
);
1092 // commit the changes of the grid control (as we're deactivated)
1093 Reference
< XBoundComponent
> xCommitable(getBrowserView()->getGridControl(), UNO_QUERY
);
1094 if (xCommitable
.is())
1095 xCommitable
->commit();
1097 OSL_FAIL("SbaXDataBrowserController::focusLost : why is my control not commitable ?");
1100 // -------------------------------------------------------------------------
1101 void SbaXDataBrowserController::disposingGridControl(const ::com::sun::star::lang::EventObject
& /*Source*/)
1103 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::disposingGridControl" );
1104 removeControlListeners(getBrowserView()->getGridControl());
1107 // -------------------------------------------------------------------------
1108 void SbaXDataBrowserController::disposingGridModel(const ::com::sun::star::lang::EventObject
& /*Source*/)
1110 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::disposingGridModel" );
1111 removeModelListeners(getControlModel());
1114 // -------------------------------------------------------------------------
1115 void SbaXDataBrowserController::disposingFormModel(const ::com::sun::star::lang::EventObject
& Source
)
1117 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::disposingFormModel" );
1118 Reference
< XPropertySet
> xSourceSet(Source
.Source
, UNO_QUERY
);
1119 if (xSourceSet
.is())
1121 xSourceSet
->removePropertyChangeListener(PROPERTY_ISNEW
, static_cast<XPropertyChangeListener
*>(this));
1122 xSourceSet
->removePropertyChangeListener(PROPERTY_ISMODIFIED
, static_cast<XPropertyChangeListener
*>(this));
1123 xSourceSet
->removePropertyChangeListener(PROPERTY_ROWCOUNT
, static_cast<XPropertyChangeListener
*>(this));
1124 xSourceSet
->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND
, static_cast<XPropertyChangeListener
*>(this));
1125 xSourceSet
->removePropertyChangeListener(PROPERTY_ORDER
, static_cast<XPropertyChangeListener
*>(this));
1126 xSourceSet
->removePropertyChangeListener(PROPERTY_FILTER
, static_cast<XPropertyChangeListener
*>(this));
1127 xSourceSet
->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE
, static_cast<XPropertyChangeListener
*>(this));
1128 xSourceSet
->removePropertyChangeListener(PROPERTY_APPLYFILTER
, static_cast<XPropertyChangeListener
*>(this));
1131 Reference
< ::com::sun::star::sdb::XSQLErrorBroadcaster
> xFormError(Source
.Source
, UNO_QUERY
);
1132 if (xFormError
.is())
1133 xFormError
->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener
*)this);
1135 if (m_xLoadable
.is())
1136 m_xLoadable
->removeLoadListener(this);
1138 Reference
< ::com::sun::star::form::XDatabaseParameterBroadcaster
> xFormParameter(Source
.Source
, UNO_QUERY
);
1139 if (xFormParameter
.is())
1140 xFormParameter
->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener
*)this);
1143 // -------------------------------------------------------------------------
1144 void SbaXDataBrowserController::disposingColumnModel(const ::com::sun::star::lang::EventObject
& Source
)
1146 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::disposingColumnModel" );
1147 RemoveColumnListener(Reference
< XPropertySet
> (Source
.Source
, UNO_QUERY
));
1150 // -------------------------------------------------------------------------
1151 void SbaXDataBrowserController::disposing(const EventObject
& Source
) throw( RuntimeException
)
1153 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::disposing" );
1154 // if it's a component other than our aggregate, forward it to the aggregate
1155 if ( m_xFormControllerImpl
!= Source
.Source
)
1157 Reference
< XEventListener
> xAggListener
;
1158 m_xFormControllerImpl
->queryAggregation( ::getCppuType( &xAggListener
) ) >>= xAggListener
;
1159 if ( xAggListener
.is( ))
1160 xAggListener
->disposing( Source
);
1163 // is it the grid control ?
1164 if (getBrowserView())
1166 Reference
< ::com::sun::star::awt::XControl
> xSourceControl(Source
.Source
, UNO_QUERY
);
1167 if (xSourceControl
== getBrowserView()->getGridControl())
1168 disposingGridControl(Source
);
1171 // it's model (the container of the columns) ?
1172 if (getControlModel() == Source
.Source
)
1173 disposingGridModel(Source
);
1175 // the form's model ?
1176 if ((getRowSet() == Source
.Source
))
1177 disposingFormModel(Source
);
1179 // from a single column model ?
1180 Reference
< XPropertySet
> xSourceSet(Source
.Source
, UNO_QUERY
);
1181 if (xSourceSet
.is())
1183 Reference
< XPropertySetInfo
> xInfo
= xSourceSet
->getPropertySetInfo();
1184 // we assume that columns have a Width property and all other sets we are listening to don't have
1185 if (xInfo
->hasPropertyByName(PROPERTY_WIDTH
))
1186 disposingColumnModel(Source
);
1188 SbaXDataBrowserController_Base::OGenericUnoController::disposing( Source
);
1191 // -----------------------------------------------------------------------
1192 void SAL_CALL
SbaXDataBrowserController::setIdentifier( const ::rtl::OUString
& _Identifier
) throw (RuntimeException
)
1194 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::setIdentifier" );
1195 ::osl::MutexGuard
aGuard( getMutex() );
1196 m_sModuleIdentifier
= _Identifier
;
1199 // -----------------------------------------------------------------------
1200 ::rtl::OUString SAL_CALL
SbaXDataBrowserController::getIdentifier( ) throw (RuntimeException
)
1202 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::getIdentifier" );
1203 ::osl::MutexGuard
aGuard( getMutex() );
1204 return m_sModuleIdentifier
;
1207 // -----------------------------------------------------------------------
1208 void SbaXDataBrowserController::propertyChange(const PropertyChangeEvent
& evt
) throw ( RuntimeException
)
1210 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::propertyChange" );
1211 Reference
< XPropertySet
> xSource(evt
.Source
, UNO_QUERY
);
1215 SolarMutexGuard aGuard
;
1216 // the IsModified changed to sal_False ?
1217 if ( (evt
.PropertyName
.equals(PROPERTY_ISMODIFIED
))
1218 && (::comphelper::getBOOL(evt
.NewValue
) == sal_False
)
1220 { // -> the current field isn't modified anymore, too
1221 setCurrentModified( sal_False
);
1224 // switching to a new record ?
1225 if ( (evt
.PropertyName
.equals(PROPERTY_ISNEW
))
1226 && (::comphelper::getBOOL(evt
.NewValue
) == sal_True
)
1229 if (::comphelper::getINT32(xSource
->getPropertyValue(PROPERTY_ROWCOUNT
)) == 0)
1230 // if we're switching to a new record and didn't have any records before we need to invalidate
1231 // all slots (as the cursor was invalid before the mode change and so the slots were disabled)
1236 if (evt
.PropertyName
.equals(PROPERTY_FILTER
))
1238 InvalidateFeature(ID_BROWSER_REMOVEFILTER
);
1240 else if (evt
.PropertyName
.equals(PROPERTY_HAVING_CLAUSE
))
1242 InvalidateFeature(ID_BROWSER_REMOVEFILTER
);
1244 else if (evt
.PropertyName
.equals(PROPERTY_ORDER
))
1246 InvalidateFeature(ID_BROWSER_REMOVEFILTER
);
1249 // a new record count ? -> may be our search availability has changed
1250 if (evt
.PropertyName
.equals(PROPERTY_ROWCOUNT
))
1252 sal_Int32 nNewValue
= 0, nOldValue
= 0;
1253 evt
.NewValue
>>= nNewValue
;
1254 evt
.OldValue
>>= nOldValue
;
1255 if((nOldValue
== 0 && nNewValue
!= 0) || (nOldValue
!= 0 && nNewValue
== 0))
1260 //------------------------------------------------------------------------
1261 void SbaXDataBrowserController::modified(const ::com::sun::star::lang::EventObject
& /*aEvent*/) throw( RuntimeException
)
1263 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::modified" );
1264 setCurrentModified( sal_True
);
1267 // -----------------------------------------------------------------------
1268 void SbaXDataBrowserController::elementInserted(const ::com::sun::star::container::ContainerEvent
& evt
) throw( RuntimeException
)
1270 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::elementInserted" );
1271 OSL_ENSURE(Reference
< XInterface
>(evt
.Source
, UNO_QUERY
).get() == Reference
< XInterface
>(getControlModel(), UNO_QUERY
).get(),
1272 "SbaXDataBrowserController::elementInserted: where did this come from (not from the grid model)?!");
1273 Reference
< XPropertySet
> xNewColumn(evt
.Element
,UNO_QUERY
);
1274 if ( xNewColumn
.is() )
1275 AddColumnListener(xNewColumn
);
1278 // -----------------------------------------------------------------------
1279 void SbaXDataBrowserController::elementRemoved(const ::com::sun::star::container::ContainerEvent
& evt
) throw( RuntimeException
)
1281 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::elementRemoved" );
1282 OSL_ENSURE(Reference
< XInterface
>(evt
.Source
, UNO_QUERY
).get() == Reference
< XInterface
>(getControlModel(), UNO_QUERY
).get(),
1283 "SbaXDataBrowserController::elementRemoved: where did this come from (not from the grid model)?!");
1284 Reference
< XPropertySet
> xOldColumn(evt
.Element
,UNO_QUERY
);
1285 if ( xOldColumn
.is() )
1286 RemoveColumnListener(xOldColumn
);
1289 // -----------------------------------------------------------------------
1290 void SbaXDataBrowserController::elementReplaced(const ::com::sun::star::container::ContainerEvent
& evt
) throw( RuntimeException
)
1292 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::elementReplaced" );
1293 OSL_ENSURE(Reference
< XInterface
>(evt
.Source
, UNO_QUERY
).get() == Reference
< XInterface
>(getControlModel(), UNO_QUERY
).get(),
1294 "SbaXDataBrowserController::elementReplaced: where did this come from (not from the grid model)?!");
1295 Reference
< XPropertySet
> xOldColumn(evt
.ReplacedElement
,UNO_QUERY
);
1296 if ( xOldColumn
.is() )
1297 RemoveColumnListener(xOldColumn
);
1299 Reference
< XPropertySet
> xNewColumn(evt
.Element
,UNO_QUERY
);
1300 if ( xNewColumn
.is() )
1301 AddColumnListener(xNewColumn
);
1304 // -----------------------------------------------------------------------
1305 sal_Bool
SbaXDataBrowserController::suspend(sal_Bool
/*bSuspend*/) throw( RuntimeException
)
1307 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::suspend" );
1308 OSL_ENSURE(m_nPendingLoadFinished
== 0, "SbaXDataBrowserController::suspend : there shouldn't be a pending load !");
1310 m_aAsyncGetCellFocus
.CancelCall();
1311 m_aAsyncDisplayError
.CancelCall();
1312 m_aAsyncInvalidateAll
.CancelCall();
1314 sal_Bool bSuccess
= SaveModified();
1317 // -----------------------------------------------------------------------
1318 void SbaXDataBrowserController::disposing()
1321 SbaXDataBrowserController_Base::OGenericUnoController::disposing();
1324 Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
1327 xFormSet
->removePropertyChangeListener(PROPERTY_ISNEW
, static_cast<XPropertyChangeListener
*>(this));
1328 xFormSet
->removePropertyChangeListener(PROPERTY_ISMODIFIED
, static_cast<XPropertyChangeListener
*>(this));
1329 xFormSet
->removePropertyChangeListener(PROPERTY_ROWCOUNT
, static_cast<XPropertyChangeListener
*>(this));
1330 xFormSet
->removePropertyChangeListener(PROPERTY_ACTIVECOMMAND
, static_cast<XPropertyChangeListener
*>(this));
1331 xFormSet
->removePropertyChangeListener(PROPERTY_ORDER
, static_cast<XPropertyChangeListener
*>(this));
1332 xFormSet
->removePropertyChangeListener(PROPERTY_FILTER
, static_cast<XPropertyChangeListener
*>(this));
1333 xFormSet
->removePropertyChangeListener(PROPERTY_HAVING_CLAUSE
, static_cast<XPropertyChangeListener
*>(this));
1334 xFormSet
->removePropertyChangeListener(PROPERTY_APPLYFILTER
, static_cast<XPropertyChangeListener
*>(this));
1337 Reference
< ::com::sun::star::sdb::XSQLErrorBroadcaster
> xFormError(getRowSet(), UNO_QUERY
);
1338 if (xFormError
.is())
1339 xFormError
->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener
*)this);
1341 if (m_xLoadable
.is())
1342 m_xLoadable
->removeLoadListener(this);
1344 Reference
< ::com::sun::star::form::XDatabaseParameterBroadcaster
> xFormParameter(getRowSet(), UNO_QUERY
);
1345 if (xFormParameter
.is())
1346 xFormParameter
->removeParameterListener((::com::sun::star::form::XDatabaseParameterListener
*)this);
1348 removeModelListeners(getControlModel());
1350 if ( getView() && m_pClipbordNotifier
)
1352 m_pClipbordNotifier
->ClearCallbackLink();
1353 m_pClipbordNotifier
->AddRemoveListener( getView(), sal_False
);
1354 m_pClipbordNotifier
->release();
1355 m_pClipbordNotifier
= NULL
;
1358 if (getBrowserView())
1360 removeControlListeners(getBrowserView()->getGridControl());
1361 // don't delete explicitly, this is done by the owner (and user) of this controller (me hopes ...)
1365 if(m_aInvalidateClipboard
.IsActive())
1366 m_aInvalidateClipboard
.Stop();
1368 // dispose the row set
1371 ::comphelper::disposeComponent(m_xRowSet
);
1374 m_xColumnsSupplier
= NULL
;
1379 DBG_UNHANDLED_EXCEPTION();
1382 // don't dispose, just reset - it's owned by the RowSet
1384 //------------------------------------------------------------------------------
1385 void SbaXDataBrowserController::frameAction(const ::com::sun::star::frame::FrameActionEvent
& aEvent
) throw( RuntimeException
)
1387 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::frameAction" );
1388 ::osl::MutexGuard
aGuard( getMutex() );
1390 SbaXDataBrowserController_Base::frameAction( aEvent
);
1392 if ( aEvent
.Source
== getFrame() )
1393 switch ( aEvent
.Action
)
1395 case FrameAction_FRAME_ACTIVATED
:
1396 case FrameAction_FRAME_UI_ACTIVATED
:
1397 // ensure that the active cell (if any) has the focus
1398 m_aAsyncGetCellFocus
.Call();
1399 // start the clipboard timer
1400 if (getBrowserView() && getBrowserView()->getVclControl() && !m_aInvalidateClipboard
.IsActive())
1402 m_aInvalidateClipboard
.Start();
1403 OnInvalidateClipboard( NULL
);
1406 case FrameAction_FRAME_DEACTIVATING
:
1407 case FrameAction_FRAME_UI_DEACTIVATING
:
1408 // stop the clipboard invalidator
1409 if (getBrowserView() && getBrowserView()->getVclControl() && m_aInvalidateClipboard
.IsActive())
1411 m_aInvalidateClipboard
.Stop();
1412 OnInvalidateClipboard( NULL
);
1414 // remove the "get cell focus"-event
1415 m_aAsyncGetCellFocus
.CancelCall();
1422 //------------------------------------------------------------------------------
1423 IMPL_LINK( SbaXDataBrowserController
, OnAsyncDisplayError
, void*, /* _pNotInterestedIn */ )
1425 if ( m_aCurrentError
.isValid() )
1427 OSQLMessageBox
aDlg( getBrowserView(), m_aCurrentError
);
1433 //------------------------------------------------------------------------------
1434 void SbaXDataBrowserController::errorOccured(const ::com::sun::star::sdb::SQLErrorEvent
& aEvent
) throw( RuntimeException
)
1436 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::errorOccurred" );
1437 ::osl::MutexGuard
aGuard( getMutex() );
1439 SQLExceptionInfo
aInfo( aEvent
.Reason
);
1440 if ( !aInfo
.isValid() )
1443 if ( m_nFormActionNestingLevel
)
1445 OSL_ENSURE( !m_aCurrentError
.isValid(), "SbaXDataBrowserController::errorOccurred: can handle one error per transaction only!" );
1446 m_aCurrentError
= aInfo
;
1450 m_aCurrentError
= aInfo
;
1451 m_aAsyncDisplayError
.Call();
1455 //------------------------------------------------------------------------------
1456 sal_Bool
SbaXDataBrowserController::approveParameter(const ::com::sun::star::form::DatabaseParameterEvent
& aEvent
) throw( RuntimeException
)
1458 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::approveParameter" );
1459 if (aEvent
.Source
!= getRowSet())
1461 // not my data source -> allow anything
1462 OSL_FAIL("SbaXDataBrowserController::approveParameter : invalid event source !");
1466 Reference
< ::com::sun::star::container::XIndexAccess
> xParameters
= aEvent
.Parameters
;
1467 SolarMutexGuard aSolarGuard
;
1469 // default handling: instantiate an interaction handler and let it handle the parameter request
1472 // two continuations allowed: OK and Cancel
1473 OParameterContinuation
* pParamValues
= new OParameterContinuation
;
1474 OInteractionAbort
* pAbort
= new OInteractionAbort
;
1476 ParametersRequest aRequest
;
1477 aRequest
.Parameters
= xParameters
;
1478 aRequest
.Connection
= getConnection(Reference
< XRowSet
>(aEvent
.Source
, UNO_QUERY
));
1479 OInteractionRequest
* pParamRequest
= new OInteractionRequest(makeAny(aRequest
));
1480 Reference
< XInteractionRequest
> xParamRequest(pParamRequest
);
1482 pParamRequest
->addContinuation(pParamValues
);
1483 pParamRequest
->addContinuation(pAbort
);
1485 // create the handler, let it handle the request
1486 Reference
< XInteractionHandler
> xHandler(getORB()->createInstance(SERVICE_TASK_INTERACTION_HANDLER
), UNO_QUERY
);
1488 xHandler
->handle(xParamRequest
);
1490 if (!pParamValues
->wasSelected())
1492 setLoadingCancelled();
1496 // transfer the values into the parameter supplier
1497 Sequence
< PropertyValue
> aFinalValues
= pParamValues
->getValues();
1498 if (aFinalValues
.getLength() != aRequest
.Parameters
->getCount())
1500 OSL_FAIL("SbaXDataBrowserController::approveParameter: the InteractionHandler returned nonsense!");
1501 setLoadingCancelled();
1504 const PropertyValue
* pFinalValues
= aFinalValues
.getConstArray();
1505 for (sal_Int32 i
=0; i
<aFinalValues
.getLength(); ++i
, ++pFinalValues
)
1507 Reference
< XPropertySet
> xParam
;
1508 ::cppu::extractInterface(xParam
, aRequest
.Parameters
->getByIndex(i
));
1509 OSL_ENSURE(xParam
.is(), "SbaXDataBrowserController::approveParameter: one of the parameters is no property set!");
1513 ::rtl::OUString sName
;
1514 xParam
->getPropertyValue(PROPERTY_NAME
) >>= sName
;
1515 OSL_ENSURE(sName
.equals(pFinalValues
->Name
), "SbaXDataBrowserController::approveParameter: suspicious value names!");
1517 try { xParam
->setPropertyValue(PROPERTY_VALUE
, pFinalValues
->Value
); }
1520 OSL_FAIL("SbaXDataBrowserController::approveParameter: setting one of the properties failed!");
1525 catch( const Exception
& )
1527 DBG_UNHANDLED_EXCEPTION();
1534 //------------------------------------------------------------------------------
1535 sal_Bool
SbaXDataBrowserController::approveReset(const ::com::sun::star::lang::EventObject
& /*rEvent*/) throw( RuntimeException
)
1537 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::approveReset" );
1541 //------------------------------------------------------------------------------
1542 void SbaXDataBrowserController::resetted(const ::com::sun::star::lang::EventObject
& rEvent
) throw( RuntimeException
)
1544 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::resetted" );
1545 OSL_ENSURE(rEvent
.Source
== getControlModel(), "SbaXDataBrowserController::resetted : where did this come from ?");
1547 setCurrentModified( sal_False
);
1550 //------------------------------------------------------------------------------
1551 sal_Bool
SbaXDataBrowserController::confirmDelete(const ::com::sun::star::sdb::RowChangeEvent
& /*aEvent*/) throw( RuntimeException
)
1553 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::confirmDelete" );
1554 if (QueryBox(getBrowserView(), ModuleRes(QUERY_BRW_DELETE_ROWS
)).Execute() != RET_YES
)
1559 //------------------------------------------------------------------------------
1560 FeatureState
SbaXDataBrowserController::GetState(sal_uInt16 nId
) const
1562 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::GetState" );
1563 FeatureState aReturn
;
1564 // (disabled automatically)
1568 // no chance without a view
1569 if (!getBrowserView() || !getBrowserView()->getVclControl())
1574 case ID_BROWSER_REMOVEFILTER
:
1575 if (!m_xParser
.is())
1577 aReturn
.bEnabled
= false;
1580 // any filter or sort order set ?
1581 aReturn
.bEnabled
= m_xParser
->getFilter().getLength() || m_xParser
->getHavingClause().getLength() || m_xParser
->getOrder().getLength();
1584 // no chance without valid models
1585 if (isValid() && !isValidCursor())
1590 case ID_BROWSER_SEARCH
:
1592 Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
1593 sal_Int32 nCount
= ::comphelper::getINT32(xFormSet
->getPropertyValue(PROPERTY_ROWCOUNT
));
1594 aReturn
.bEnabled
= nCount
!= 0;
1597 case ID_BROWSER_INSERT_ROW
:
1599 // check if it is available
1600 sal_Bool bInsertPrivilege
= ( m_nRowSetPrivileges
& Privilege::INSERT
) != 0;
1601 sal_Bool bAllowInsertions
= sal_True
;
1604 Reference
< XPropertySet
> xRowSetProps( getRowSet(), UNO_QUERY_THROW
);
1605 OSL_VERIFY( xRowSetProps
->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowInserts")) ) >>= bAllowInsertions
);
1607 catch( const Exception
& )
1609 DBG_UNHANDLED_EXCEPTION();
1611 aReturn
.bEnabled
= bInsertPrivilege
&& bAllowInsertions
;
1614 case SID_FM_DELETEROWS
:
1616 // check if it is available
1617 sal_Bool bDeletePrivilege
= ( m_nRowSetPrivileges
& Privilege::INSERT
) != 0;
1618 sal_Bool bAllowDeletions
= sal_True
;
1619 sal_Int32 nRowCount
= 0;
1620 sal_Bool bInsertionRow
= sal_False
;
1623 Reference
< XPropertySet
> xRowSetProps( getRowSet(), UNO_QUERY_THROW
);
1624 OSL_VERIFY( xRowSetProps
->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowDeletes")) ) >>= bAllowDeletions
);
1625 OSL_VERIFY( xRowSetProps
->getPropertyValue( PROPERTY_ROWCOUNT
) >>= nRowCount
);
1626 OSL_VERIFY( xRowSetProps
->getPropertyValue( PROPERTY_ISNEW
) >>= bInsertionRow
);
1628 catch( const Exception
& )
1630 DBG_UNHANDLED_EXCEPTION();
1632 aReturn
.bEnabled
= bDeletePrivilege
&& bAllowDeletions
&& ( nRowCount
!= 0 ) && !bInsertionRow
;
1636 case ID_BROWSER_COPY
:
1637 if ( getBrowserView()->getVclControl()->GetSelectRowCount() )
1639 aReturn
.bEnabled
= m_aCurrentFrame
.isActive();
1643 case ID_BROWSER_PASTE
:
1644 case ID_BROWSER_CUT
:
1646 CellControllerRef xCurrentController
= getBrowserView()->getVclControl()->Controller();
1647 if (xCurrentController
.Is() && xCurrentController
->ISA(EditCellController
))
1649 Edit
& rEdit
= (Edit
&)xCurrentController
->GetWindow();
1650 sal_Bool bHasLen
= (rEdit
.GetSelection().Len() != 0);
1651 sal_Bool bIsReadOnly
= rEdit
.IsReadOnly();
1654 case ID_BROWSER_CUT
: aReturn
.bEnabled
= m_aCurrentFrame
.isActive() && bHasLen
&& !bIsReadOnly
; break;
1655 case SID_COPY
: aReturn
.bEnabled
= m_aCurrentFrame
.isActive() && bHasLen
; break;
1656 case ID_BROWSER_PASTE
:
1657 aReturn
.bEnabled
= m_aCurrentFrame
.isActive() && !bIsReadOnly
;
1658 if(aReturn
.bEnabled
)
1660 aReturn
.bEnabled
= aReturn
.bEnabled
&& IsFormatSupported( m_aSystemClipboard
.GetDataFlavorExVector(), FORMAT_STRING
);
1668 case ID_BROWSER_SORTUP
:
1669 case ID_BROWSER_SORTDOWN
:
1670 case ID_BROWSER_AUTOFILTER
:
1672 // a native statement can't be filtered or sorted
1673 const Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
1674 if ( !::comphelper::getBOOL(xFormSet
->getPropertyValue(PROPERTY_ESCAPE_PROCESSING
)) || !m_xParser
.is() )
1677 Reference
< XPropertySet
> xCurrentField
= getBoundField();
1678 if (!xCurrentField
.is())
1681 aReturn
.bEnabled
= ::comphelper::getBOOL(xCurrentField
->getPropertyValue(PROPERTY_ISSEARCHABLE
));
1682 const Reference
< XRowSet
> xRow
= getRowSet();
1683 aReturn
.bEnabled
= aReturn
.bEnabled
1685 && !xRow
->isBeforeFirst()
1686 && !xRow
->isAfterLast()
1687 && !xRow
->rowDeleted()
1688 && ( ::comphelper::getINT32( xFormSet
->getPropertyValue( PROPERTY_ROWCOUNT
) ) != 0 );
1692 case ID_BROWSER_FILTERCRIT
:
1693 if ( m_bCannotSelectUnfiltered
&& m_xParser
.is() )
1695 aReturn
.bEnabled
= sal_True
;
1699 case ID_BROWSER_ORDERCRIT
:
1701 const Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
1702 if ( !::comphelper::getBOOL(xFormSet
->getPropertyValue(PROPERTY_ESCAPE_PROCESSING
)) || !m_xParser
.is() )
1705 aReturn
.bEnabled
= getRowSet().is()
1706 && ( ::comphelper::getINT32( xFormSet
->getPropertyValue( PROPERTY_ROWCOUNT
) ) != 0 );
1710 case ID_BROWSER_REFRESH
:
1711 aReturn
.bEnabled
= sal_True
;
1714 case ID_BROWSER_REDO
:
1715 aReturn
.bEnabled
= sal_False
; // simply forget it ;). no redo possible.
1718 case ID_BROWSER_UNDORECORD
:
1719 case ID_BROWSER_SAVERECORD
:
1721 if (!m_bCurrentlyModified
)
1723 Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
1725 aReturn
.bEnabled
= ::comphelper::getBOOL(xFormSet
->getPropertyValue(PROPERTY_ISMODIFIED
));
1728 aReturn
.bEnabled
= sal_True
;
1730 aReturn
.sTitle
= (ID_BROWSER_UNDORECORD
== nId
) ? m_sStateUndoRecord
: m_sStateSaveRecord
;
1733 case ID_BROWSER_EDITDOC
:
1735 // check if it is available
1736 Reference
< XPropertySet
> xDataSourceSet(getRowSet(), UNO_QUERY
);
1737 if (!xDataSourceSet
.is())
1738 break; // no datasource -> no edit mode
1740 sal_Int32 nDataSourcePrivileges
= ::comphelper::getINT32(xDataSourceSet
->getPropertyValue(PROPERTY_PRIVILEGES
));
1741 sal_Bool bInsertAllowedAndPossible
= ((nDataSourcePrivileges
& ::com::sun::star::sdbcx::Privilege::INSERT
) != 0) && ::comphelper::getBOOL(xDataSourceSet
->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowInserts"))));
1742 sal_Bool bUpdateAllowedAndPossible
= ((nDataSourcePrivileges
& ::com::sun::star::sdbcx::Privilege::UPDATE
) != 0) && ::comphelper::getBOOL(xDataSourceSet
->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowUpdates"))));
1743 sal_Bool bDeleteAllowedAndPossible
= ((nDataSourcePrivileges
& ::com::sun::star::sdbcx::Privilege::DELETE
) != 0) && ::comphelper::getBOOL(xDataSourceSet
->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AllowDeletes"))));
1744 if (!bInsertAllowedAndPossible
&& !bUpdateAllowedAndPossible
&& !bDeleteAllowedAndPossible
)
1745 break; // no insert/update/delete -> no edit mode
1747 if (!isValidCursor() || !isLoaded())
1748 break; // no cursor -> no edit mode
1750 aReturn
.bEnabled
= sal_True
;
1752 sal_Int16 nGridMode
= getBrowserView()->getVclControl()->GetOptions();
1753 aReturn
.bChecked
= nGridMode
> DbGridControl::OPT_READONLY
;
1756 case ID_BROWSER_FILTERED
:
1758 aReturn
.bEnabled
= sal_False
;
1759 Reference
< XPropertySet
> xActiveSet(getRowSet(), UNO_QUERY
);
1760 ::rtl::OUString aFilter
= ::comphelper::getString(xActiveSet
->getPropertyValue(PROPERTY_FILTER
));
1761 ::rtl::OUString aHaving
= ::comphelper::getString(xActiveSet
->getPropertyValue(PROPERTY_HAVING_CLAUSE
));
1762 if ( !(aFilter
.isEmpty() && aHaving
.isEmpty()) )
1764 xActiveSet
->getPropertyValue( PROPERTY_APPLYFILTER
) >>= aReturn
.bChecked
;
1765 aReturn
.bEnabled
= sal_True
;
1769 aReturn
.bChecked
= sal_False
;
1770 aReturn
.bEnabled
= sal_False
;
1775 return SbaXDataBrowserController_Base::GetState(nId
);
1778 catch(const Exception
& )
1780 DBG_UNHANDLED_EXCEPTION();
1786 //------------------------------------------------------------------------------
1787 void SbaXDataBrowserController::applyParserOrder(const ::rtl::OUString
& _rOldOrder
,const Reference
< XSingleSelectQueryComposer
>& _xParser
)
1789 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::applyParserOrder" );
1790 Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
1791 if (!m_xLoadable
.is())
1793 OSL_FAIL("SbaXDataBrowserController::applyParserOrder: invalid row set!");
1797 sal_uInt16 nPos
= getCurrentColumnPosition();
1798 sal_Bool bSuccess
= sal_False
;
1801 xFormSet
->setPropertyValue(PROPERTY_ORDER
, makeAny(_xParser
->getOrder()));
1802 bSuccess
= reloadForm(m_xLoadable
);
1810 xFormSet
->setPropertyValue(PROPERTY_ORDER
, makeAny(_rOldOrder
));
1814 if (loadingCancelled() || !reloadForm(m_xLoadable
))
1823 InvalidateFeature(ID_BROWSER_REMOVEFILTER
);
1825 setCurrentColumnPosition(nPos
);
1828 //------------------------------------------------------------------------------
1829 void SbaXDataBrowserController::applyParserFilter(const ::rtl::OUString
& _rOldFilter
, sal_Bool _bOldFilterApplied
,const ::rtl::OUString
& _sOldHaving
,const Reference
< XSingleSelectQueryComposer
>& _xParser
)
1831 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::applyParserFilter" );
1832 Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
1833 if (!m_xLoadable
.is())
1835 OSL_FAIL("SbaXDataBrowserController::applyParserFilter: invalid row set!");
1839 sal_uInt16 nPos
= getCurrentColumnPosition();
1841 sal_Bool bSuccess
= sal_False
;
1844 FormErrorHelper
aError(this);
1845 xFormSet
->setPropertyValue(PROPERTY_FILTER
, makeAny(_xParser
->getFilter()));
1846 xFormSet
->setPropertyValue(PROPERTY_HAVING_CLAUSE
, makeAny(_xParser
->getHavingClause()));
1847 xFormSet
->setPropertyValue(PROPERTY_APPLYFILTER
, ::comphelper::makeBoolAny(sal_Bool(sal_True
)));
1849 bSuccess
= reloadForm(m_xLoadable
);
1857 xFormSet
->setPropertyValue(PROPERTY_FILTER
, makeAny(_rOldFilter
));
1858 xFormSet
->setPropertyValue(PROPERTY_HAVING_CLAUSE
, makeAny(_sOldHaving
));
1859 xFormSet
->setPropertyValue(PROPERTY_APPLYFILTER
, ::comphelper::makeBoolAny(_bOldFilterApplied
));
1863 if (loadingCancelled() || !reloadForm(m_xLoadable
))
1872 InvalidateFeature(ID_BROWSER_REMOVEFILTER
);
1874 setCurrentColumnPosition(nPos
);
1877 //------------------------------------------------------------------------------
1878 Reference
< XSingleSelectQueryComposer
> SbaXDataBrowserController::createParser_nothrow()
1880 Reference
< XSingleSelectQueryComposer
> xComposer
;
1883 const Reference
< XPropertySet
> xRowSetProps( getRowSet(), UNO_QUERY_THROW
);
1884 const Reference
< XMultiServiceFactory
> xFactory(
1885 xRowSetProps
->getPropertyValue( PROPERTY_ACTIVE_CONNECTION
), UNO_QUERY_THROW
);
1886 xComposer
.set( xFactory
->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER
), UNO_QUERY_THROW
);
1888 ::rtl::OUString sActiveCommand
;
1889 OSL_VERIFY( xRowSetProps
->getPropertyValue( PROPERTY_ACTIVECOMMAND
) >>= sActiveCommand
);
1890 if ( !sActiveCommand
.isEmpty() )
1892 xComposer
->setElementaryQuery( sActiveCommand
);
1896 ::rtl::OUString sCommand
;
1897 OSL_VERIFY( xRowSetProps
->getPropertyValue( PROPERTY_COMMAND
) >>= sCommand
);
1898 sal_Int32 nCommandType
= CommandType::COMMAND
;
1899 OSL_VERIFY( xRowSetProps
->getPropertyValue( PROPERTY_COMMAND_TYPE
) >>= nCommandType
);
1900 xComposer
->setCommand( sCommand
, nCommandType
);
1903 ::rtl::OUString sFilter
;
1904 OSL_VERIFY( xRowSetProps
->getPropertyValue( PROPERTY_FILTER
) >>= sFilter
);
1905 xComposer
->setFilter( sFilter
);
1907 ::rtl::OUString sHavingClause
;
1908 OSL_VERIFY( xRowSetProps
->getPropertyValue( PROPERTY_HAVING_CLAUSE
) >>= sHavingClause
);
1909 xComposer
->setHavingClause( sHavingClause
);
1911 ::rtl::OUString sOrder
;
1912 OSL_VERIFY( xRowSetProps
->getPropertyValue( PROPERTY_ORDER
) >>= sOrder
);
1913 xComposer
->setOrder( sOrder
);
1915 catch ( const Exception
& )
1917 DBG_UNHANDLED_EXCEPTION();
1921 //------------------------------------------------------------------------------
1922 void SbaXDataBrowserController::ExecuteFilterSortCrit(sal_Bool bFilter
)
1924 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::ExecuteFilterSortCrit" );
1925 if (!SaveModified())
1928 Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
1930 const ::rtl::OUString sOldVal
= bFilter
? m_xParser
->getFilter() : m_xParser
->getOrder();
1931 const ::rtl::OUString sOldHaving
= m_xParser
->getHavingClause();
1932 Reference
< XSingleSelectQueryComposer
> xParser
= createParser_nothrow();
1935 Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
> xSup
= getColumnsSupplier();
1936 Reference
< XConnection
> xCon(xFormSet
->getPropertyValue(PROPERTY_ACTIVE_CONNECTION
),UNO_QUERY
);
1939 DlgFilterCrit
aDlg( getBrowserView(), getORB(), xCon
, xParser
, xSup
->getColumns() );
1941 if ( !aDlg
.Execute() )
1942 return; // if so we don't need to update the grid
1943 aDlg
.BuildWherePart();
1947 DlgOrderCrit
aDlg( getBrowserView(),xCon
,xParser
,xSup
->getColumns() );
1951 return; // if so we don't need to actualize the grid
1953 aDlg
.BuildOrderPart();
1956 catch(const SQLException
& )
1958 SQLExceptionInfo
aError( ::cppu::getCaughtException() );
1959 showError( aError
);
1967 ::rtl::OUString sNewVal
= bFilter
? xParser
->getFilter() : xParser
->getOrder();
1968 sal_Bool
bOldFilterApplied(sal_False
);
1971 try { bOldFilterApplied
= ::comphelper::getBOOL(xFormSet
->getPropertyValue(PROPERTY_APPLYFILTER
)); } catch(Exception
&) { } ;
1974 ::rtl::OUString sNewHaving
= xParser
->getHavingClause();
1975 if ( sOldVal
.equals(sNewVal
) && (!bFilter
|| sOldHaving
.equals(sNewHaving
)) )
1976 // nothing to be done
1980 applyParserFilter(sOldVal
, bOldFilterApplied
,sOldHaving
,xParser
);
1982 applyParserOrder(sOldVal
,xParser
);
1984 ::comphelper::disposeComponent(xParser
);
1987 //------------------------------------------------------------------------------
1988 void SbaXDataBrowserController::ExecuteSearch()
1990 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::ExecuteSearch" );
1991 // calculate the control source of the active field
1992 Reference
< ::com::sun::star::form::XGrid
> xGrid(getBrowserView()->getGridControl(), UNO_QUERY
);
1993 OSL_ENSURE(xGrid
.is(), "SbaXDataBrowserController::ExecuteSearch : the control should have an ::com::sun::star::form::XGrid interface !");
1995 Reference
< ::com::sun::star::form::XGridPeer
> xGridPeer(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY
);
1996 Reference
< ::com::sun::star::container::XIndexContainer
> xColumns
= xGridPeer
->getColumns();
1997 OSL_ENSURE(xGridPeer
.is() && xColumns
.is(), "SbaXDataBrowserController::ExecuteSearch : invalid peer !");
1999 sal_Int16 nViewCol
= xGrid
->getCurrentColumnPosition();
2000 sal_Int16 nModelCol
= getBrowserView()->View2ModelPos(nViewCol
);
2002 Reference
< XPropertySet
> xCurrentCol(xColumns
->getByIndex(nModelCol
),UNO_QUERY
);
2003 String sActiveField
= ::comphelper::getString(xCurrentCol
->getPropertyValue(PROPERTY_CONTROLSOURCE
));
2005 // the text within the current cell
2006 String sInitialText
;
2007 Reference
< ::com::sun::star::container::XIndexAccess
> xColControls(xGridPeer
, UNO_QUERY
);
2008 Reference
< XInterface
> xCurControl(xColControls
->getByIndex(nViewCol
),UNO_QUERY
);
2009 ::rtl::OUString aInitialText
;
2010 if (IsSearchableControl(xCurControl
, &aInitialText
))
2011 sInitialText
= aInitialText
;
2013 // prohibit the synchronization of the grid's display with the cursor's position
2014 Reference
< XPropertySet
> xModelSet(getControlModel(), UNO_QUERY
);
2015 OSL_ENSURE(xModelSet
.is(), "SbaXDataBrowserController::ExecuteSearch : no model set ?!");
2016 xModelSet
->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DisplayIsSynchron")), ::comphelper::makeBoolAny(sal_Bool(sal_False
)));
2017 xModelSet
->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AlwaysShowCursor")), ::comphelper::makeBoolAny(sal_Bool(sal_True
)));
2018 xModelSet
->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CursorColor")), makeAny(sal_Int32(COL_LIGHTRED
)));
2020 Reference
< ::com::sun::star::util::XNumberFormatsSupplier
> xNFS(::dbtools::getNumberFormats(::dbtools::getConnection(m_xRowSet
), sal_True
,getORB()));
2022 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
2023 AbstractFmSearchDialog
* pDialog
= NULL
;
2026 ::std::vector
< String
> aContextNames
;
2027 aContextNames
.push_back( String::CreateFromAscii("Standard") );
2028 pDialog
= pFact
->CreateFmSearchDialog(getBrowserView(), sInitialText
, aContextNames
, 0, LINK(this, SbaXDataBrowserController
, OnSearchContextRequest
));
2030 OSL_ENSURE( pDialog
, "SbaXDataBrowserController::ExecuteSearch: could not get the search dialog!" );
2033 pDialog
->SetActiveField( sActiveField
);
2034 pDialog
->SetFoundHandler( LINK( this, SbaXDataBrowserController
, OnFoundData
) );
2035 pDialog
->SetCanceledNotFoundHdl( LINK( this, SbaXDataBrowserController
, OnCanceledNotFound
) );
2040 // restore the grid's normal operating state
2041 xModelSet
->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DisplayIsSynchron")), ::comphelper::makeBoolAny(sal_Bool(sal_True
)));
2042 xModelSet
->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AlwaysShowCursor")), ::comphelper::makeBoolAny(sal_Bool(sal_False
)));
2043 xModelSet
->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CursorColor")), Any());
2046 //------------------------------------------------------------------------------
2047 void SbaXDataBrowserController::Execute(sal_uInt16 nId
, const Sequence
< PropertyValue
>& _rArgs
)
2049 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::Execute" );
2050 sal_Bool bSortUp
= sal_True
;
2055 SbaXDataBrowserController_Base::Execute( nId
, _rArgs
);
2058 case ID_BROWSER_INSERT_ROW
:
2063 getRowSet()->afterLast();
2064 // check if it is available
2065 Reference
< XResultSetUpdate
> xUpdateCursor(getRowSet(), UNO_QUERY_THROW
);
2066 xUpdateCursor
->moveToInsertRow();
2071 OSL_FAIL("Exception caught!");
2074 case SID_FM_DELETEROWS
:
2078 SbaGridControl
* pVclGrid
= getBrowserView()->getVclControl();
2081 if( !pVclGrid
->GetSelectRowCount() )
2083 pVclGrid
->DeactivateCell();
2084 pVclGrid
->SelectRow(pVclGrid
->GetCurRow());
2086 pVclGrid
->DeleteSelectedRows();
2091 case ID_BROWSER_FILTERED
:
2094 Reference
< XPropertySet
> xActiveSet(getRowSet(), UNO_QUERY
);
2095 sal_Bool bApplied
= ::comphelper::getBOOL(xActiveSet
->getPropertyValue(PROPERTY_APPLYFILTER
));
2096 xActiveSet
->setPropertyValue(PROPERTY_APPLYFILTER
, ::comphelper::makeBoolAny(sal_Bool(!bApplied
)));
2097 reloadForm(m_xLoadable
);
2099 InvalidateFeature(ID_BROWSER_FILTERED
);
2101 case ID_BROWSER_EDITDOC
:
2103 sal_Int16 nGridMode
= getBrowserView()->getVclControl()->GetOptions();
2104 if (nGridMode
== DbGridControl::OPT_READONLY
)
2105 getBrowserView()->getVclControl()->SetOptions(DbGridControl::OPT_UPDATE
| DbGridControl::OPT_INSERT
| DbGridControl::OPT_DELETE
);
2106 // the options not supported by the data source will be removed automatically
2109 if ( !SaveModified( ) )
2110 // give the user a chance to save the current record (if neccessary)
2113 // maybe the user wanted to reject the modified record ?
2114 if (GetState(ID_BROWSER_UNDORECORD
).bEnabled
)
2115 Execute(ID_BROWSER_UNDORECORD
,Sequence
<PropertyValue
>());
2117 getBrowserView()->getVclControl()->SetOptions(DbGridControl::OPT_READONLY
);
2119 InvalidateFeature(ID_BROWSER_EDITDOC
);
2123 case ID_BROWSER_SEARCH
:
2124 if ( SaveModified( ) )
2128 case ID_BROWSER_COPY
:
2129 if ( getBrowserView()->getVclControl()->GetSelectRowCount() > 0 )
2131 getBrowserView()->getVclControl()->CopySelectedRowsToClipboard();
2135 case ID_BROWSER_CUT
:
2136 case ID_BROWSER_PASTE
:
2138 CellControllerRef xCurrentController
= getBrowserView()->getVclControl()->Controller();
2139 if (!xCurrentController
.Is())
2140 // should be intercepted by GetState. Normally.
2141 // Unfortunately ID_BROWSER_PASTE is a 'fast call' slot, which means it may be executed without checking if it is
2142 // enabled. This would be really deadly herein if the current cell has no controller ...
2145 Edit
& rEdit
= (Edit
&)xCurrentController
->GetWindow();
2148 case ID_BROWSER_CUT
: rEdit
.Cut(); break;
2149 case SID_COPY
: rEdit
.Copy(); break;
2150 case ID_BROWSER_PASTE
: rEdit
.Paste(); break;
2152 if (ID_BROWSER_CUT
== nId
|| ID_BROWSER_PASTE
== nId
)
2154 xCurrentController
->SetModified();
2160 case ID_BROWSER_SORTDOWN
:
2161 bSortUp
= sal_False
;
2163 case ID_BROWSER_SORTUP
:
2165 if (!SaveModified())
2168 if (!isValidCursor())
2171 // only one sort order
2172 Reference
< XPropertySet
> xField(getBoundField(), UNO_QUERY
);
2176 Reference
< XSingleSelectQueryComposer
> xParser
= createParser_nothrow();
2177 const ::rtl::OUString sOldSort
= xParser
->getOrder();
2178 sal_Bool bParserSuccess
= sal_False
;
2180 xParser
->setOrder(::rtl::OUString()); xParser
->appendOrderByColumn(xField
, bSortUp
),
2182 ModuleRes(SBA_BROWSER_SETTING_ORDER
).toString(),
2183 "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"
2187 applyParserOrder(sOldSort
,xParser
);
2191 case ID_BROWSER_AUTOFILTER
:
2193 if (!SaveModified())
2196 if (!isValidCursor())
2199 Reference
< XPropertySet
> xField(getBoundField(), UNO_QUERY
);
2203 // check if the column is a aggregate function
2204 sal_Bool bHaving
= sal_False
;
2205 ::rtl::OUString sName
;
2206 xField
->getPropertyValue(PROPERTY_NAME
) >>= sName
;
2207 Reference
< XColumnsSupplier
> xColumnsSupplier(m_xParser
, UNO_QUERY
);
2208 Reference
< ::com::sun::star::container::XNameAccess
> xCols
= xColumnsSupplier
.is() ? xColumnsSupplier
->getColumns() : Reference
< ::com::sun::star::container::XNameAccess
> ();
2209 if ( xCols
.is() && xCols
->hasByName(sName
) )
2211 Reference
<XPropertySet
> xProp(xCols
->getByName(sName
),UNO_QUERY
);
2212 static ::rtl::OUString
sAgg(RTL_CONSTASCII_USTRINGPARAM("AggregateFunction"));
2213 if ( xProp
->getPropertySetInfo()->hasPropertyByName(sAgg
) )
2214 xProp
->getPropertyValue(sAgg
) >>= bHaving
;
2217 Reference
< XSingleSelectQueryComposer
> xParser
= createParser_nothrow();
2218 const ::rtl::OUString sOldFilter
= xParser
->getFilter();
2219 const ::rtl::OUString sOldHaving
= xParser
->getHavingClause();
2221 Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
2222 sal_Bool bApplied
= ::comphelper::getBOOL(xFormSet
->getPropertyValue(PROPERTY_APPLYFILTER
));
2223 // do we have a filter but it's not applied ?
2224 // -> completely overwrite it, else append one
2227 DO_SAFE( (bHaving
? xParser
->setHavingClause(::rtl::OUString()) : xParser
->setFilter(::rtl::OUString())), "SbaXDataBrowserController::Execute : caught an exception while resetting the new filter !" );
2230 sal_Bool bParserSuccess
= sal_False
;
2232 sal_Int32 nOp
= SQLFilterOperator::EQUAL
;
2235 sal_Int32 nType
= 0;
2236 xField
->getPropertyValue(PROPERTY_TYPE
) >>= nType
;
2239 case DataType::VARCHAR
:
2240 case DataType::CHAR
:
2241 case DataType::LONGVARCHAR
:
2242 nOp
= SQLFilterOperator::LIKE
;
2245 nOp
= SQLFilterOperator::EQUAL
;
2252 xParser
->appendHavingClauseByColumn(xField
,sal_True
,nOp
),
2254 ModuleRes(SBA_BROWSER_SETTING_FILTER
).toString(),
2255 "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"
2261 xParser
->appendFilterByColumn(xField
,sal_True
,nOp
),
2263 ModuleRes(SBA_BROWSER_SETTING_FILTER
).toString(),
2264 "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"
2269 applyParserFilter(sOldFilter
, bApplied
,sOldHaving
,xParser
);
2271 InvalidateFeature(ID_BROWSER_REMOVEFILTER
);
2272 InvalidateFeature(ID_BROWSER_FILTERED
);
2276 case ID_BROWSER_ORDERCRIT
:
2277 ExecuteFilterSortCrit(sal_False
);
2280 case ID_BROWSER_FILTERCRIT
:
2281 ExecuteFilterSortCrit(sal_True
);
2282 InvalidateFeature(ID_BROWSER_FILTERED
);
2285 case ID_BROWSER_REMOVEFILTER
:
2287 if (!SaveModified())
2290 sal_Bool bNeedPostReload
= preReloadForm();
2291 // reset the filter and the sort property simutaneously so only _one_ new statement has to be
2293 Reference
< XPropertySet
> xSet(getRowSet(), UNO_QUERY
);
2296 xSet
->setPropertyValue(PROPERTY_FILTER
,makeAny(::rtl::OUString()));
2297 xSet
->setPropertyValue(PROPERTY_HAVING_CLAUSE
,makeAny(::rtl::OUString()));
2298 xSet
->setPropertyValue(PROPERTY_ORDER
,makeAny(::rtl::OUString()));
2302 reloadForm(m_xLoadable
);
2303 if ( bNeedPostReload
)
2309 InvalidateFeature(ID_BROWSER_REMOVEFILTER
);
2310 InvalidateFeature(ID_BROWSER_FILTERED
);
2314 case ID_BROWSER_REFRESH
:
2315 if ( SaveModified( ) )
2317 if (!reloadForm(m_xLoadable
))
2322 case ID_BROWSER_SAVERECORD
:
2323 if ( SaveModified( sal_False
) )
2324 setCurrentModified( sal_False
);
2327 case ID_BROWSER_UNDORECORD
:
2331 // restore the cursor state
2332 Reference
< XResultSetUpdate
> xCursor(getRowSet(), UNO_QUERY
);
2333 Reference
< XPropertySet
> xSet(xCursor
, UNO_QUERY
);
2334 Any aVal
= xSet
->getPropertyValue(PROPERTY_ISNEW
);
2335 if (aVal
.hasValue() && ::comphelper::getBOOL(aVal
))
2337 xCursor
->moveToInsertRow();
2338 // no need to reset the grid model after we moved to the insert row, this is done implicitly by the
2340 // (and in some cases it may be deadly to do the reset explicitly after the form did it implicitly,
2341 // cause the form's reset may be async, and this leads to some nice deadlock scenarios ....)
2345 xCursor
->cancelRowUpdates();
2347 // restore the grids state
2348 Reference
< ::com::sun::star::form::XReset
> xReset(getControlModel(), UNO_QUERY
);
2353 catch(SQLException
&)
2357 setCurrentModified( sal_False
);
2362 //------------------------------------------------------------------------------
2363 sal_Bool
SbaXDataBrowserController::SaveModified(sal_Bool bAskFor
)
2365 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::SaveModified" );
2366 if ( bAskFor
&& GetState(ID_BROWSER_SAVERECORD
).bEnabled
)
2368 getBrowserView()->getVclControl()->GrabFocus();
2370 QueryBox
aQry(getBrowserView()->getVclControl(), ModuleRes(QUERY_BRW_SAVEMODIFIED
));
2372 switch (aQry
.Execute())
2375 Execute(ID_BROWSER_UNDORECORD
,Sequence
<PropertyValue
>());
2382 if ( !CommitCurrent() ) // das aktuelle Control committen lassen
2385 Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
2386 sal_Bool bResult
= sal_False
;
2389 if (::comphelper::getBOOL(xFormSet
->getPropertyValue(PROPERTY_ISMODIFIED
)))
2391 Reference
< XResultSetUpdate
> xCursor(getRowSet(), UNO_QUERY
);
2392 if (::comphelper::getBOOL(xFormSet
->getPropertyValue(PROPERTY_ISNEW
)))
2393 xCursor
->insertRow();
2395 xCursor
->updateRow();
2399 catch(SQLException
&)
2404 OSL_FAIL("SbaXDataBrowserController::SaveModified : could not save the current record !");
2405 bResult
= sal_False
;
2408 InvalidateFeature(ID_BROWSER_SAVERECORD
);
2409 InvalidateFeature(ID_BROWSER_UNDORECORD
);
2413 //------------------------------------------------------------------------------
2414 sal_Bool
SbaXDataBrowserController::CommitCurrent()
2416 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::CommitCurrent" );
2417 if (!getBrowserView())
2420 Reference
< ::com::sun::star::awt::XControl
> xActiveControl(getBrowserView()->getGridControl());
2421 Reference
< ::com::sun::star::form::XBoundControl
> xLockingTest(xActiveControl
, UNO_QUERY
);
2422 sal_Bool bControlIsLocked
= xLockingTest
.is() && xLockingTest
->getLock();
2423 if (xActiveControl
.is() && !bControlIsLocked
)
2425 // zunaechst das Control fragen ob es das IFace unterstuetzt
2426 Reference
< ::com::sun::star::form::XBoundComponent
> xBoundControl(xActiveControl
, UNO_QUERY
);
2427 if (!xBoundControl
.is())
2428 xBoundControl
= Reference
< ::com::sun::star::form::XBoundComponent
> (xActiveControl
->getModel(), UNO_QUERY
);
2429 if (xBoundControl
.is() && !xBoundControl
->commit())
2435 //------------------------------------------------------------------------------
2436 void SbaXDataBrowserController::setCurrentModified( sal_Bool _bSet
)
2438 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::setCurrentModified" );
2439 m_bCurrentlyModified
= _bSet
;
2440 InvalidateFeature( ID_BROWSER_SAVERECORD
);
2441 InvalidateFeature( ID_BROWSER_UNDORECORD
);
2444 //------------------------------------------------------------------------------
2445 void SbaXDataBrowserController::RowChanged()
2447 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::RowChanged" );
2448 setCurrentModified( sal_False
);
2451 //------------------------------------------------------------------------------
2452 void SbaXDataBrowserController::ColumnChanged()
2454 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::ColumnChanged" );
2455 InvalidateFeature(ID_BROWSER_SORTUP
);
2456 InvalidateFeature(ID_BROWSER_SORTDOWN
);
2457 InvalidateFeature(ID_BROWSER_ORDERCRIT
);
2458 InvalidateFeature(ID_BROWSER_FILTERCRIT
);
2459 InvalidateFeature(ID_BROWSER_AUTOFILTER
);
2460 InvalidateFeature(ID_BROWSER_REMOVEFILTER
);
2462 setCurrentModified( sal_False
);
2465 //------------------------------------------------------------------------------
2466 void SbaXDataBrowserController::SelectionChanged()
2468 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::SelectionChanged" );
2469 // not interested in
2472 //------------------------------------------------------------------------------
2473 void SbaXDataBrowserController::CellActivated()
2475 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::CellActivated" );
2476 m_aInvalidateClipboard
.Start();
2477 OnInvalidateClipboard( NULL
);
2480 //------------------------------------------------------------------------------
2481 void SbaXDataBrowserController::CellDeactivated()
2483 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::CellDeactivated" );
2484 m_aInvalidateClipboard
.Stop();
2485 OnInvalidateClipboard( NULL
);
2488 //------------------------------------------------------------------------------
2489 IMPL_LINK_NOARG(SbaXDataBrowserController
, OnClipboardChanged
)
2491 SolarMutexGuard aGuard
;
2492 return OnInvalidateClipboard( NULL
);
2495 //------------------------------------------------------------------------------
2496 IMPL_LINK(SbaXDataBrowserController
, OnInvalidateClipboard
, AutoTimer
*, _pTimer
)
2498 InvalidateFeature(ID_BROWSER_CUT
);
2499 InvalidateFeature(ID_BROWSER_COPY
);
2501 // if the invalidation was triggered by the timer, we do not need to invalidate PASTE.
2502 // The timer is only for checking the CUT/COPY slots regulariry, which depend on the
2503 // selection state of the active cell
2504 // TODO: get a callback at the Edit which allows to be notified when the selection
2505 // changes. This would be much better than this cycle-eating polling mechanism here ....
2506 if ( _pTimer
!= &m_aInvalidateClipboard
)
2507 InvalidateFeature(ID_BROWSER_PASTE
);
2512 // -------------------------------------------------------------------------
2513 Reference
< XPropertySet
> SbaXDataBrowserController::getBoundField(sal_uInt16 nViewPos
) const
2515 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::SaveData" );
2516 Reference
< XPropertySet
> xEmptyReturn
;
2518 // get the current column from the grid
2519 if (nViewPos
== (sal_uInt16
)-1)
2521 Reference
< ::com::sun::star::form::XGrid
> xGrid(getBrowserView()->getGridControl(), UNO_QUERY
);
2523 return xEmptyReturn
;
2524 nViewPos
= xGrid
->getCurrentColumnPosition();
2526 sal_uInt16 nCurrentCol
= getBrowserView()->View2ModelPos(nViewPos
);
2527 if (nCurrentCol
== (sal_uInt16
)-1)
2528 return xEmptyReturn
;
2530 // get the according column from the model
2531 Reference
< ::com::sun::star::container::XIndexContainer
> xCols(getControlModel(), UNO_QUERY
);
2532 Reference
< XPropertySet
> xCurrentCol(xCols
->getByIndex(nCurrentCol
),UNO_QUERY
);
2533 if (!xCurrentCol
.is())
2534 return xEmptyReturn
;
2536 xEmptyReturn
.set(xCurrentCol
->getPropertyValue(PROPERTY_BOUNDFIELD
) ,UNO_QUERY
);
2537 return xEmptyReturn
;
2540 //------------------------------------------------------------------------------
2541 IMPL_LINK(SbaXDataBrowserController
, OnSearchContextRequest
, FmSearchContext
*, pContext
)
2543 Reference
< ::com::sun::star::container::XIndexAccess
> xPeerContainer(getBrowserView()->getGridControl(), UNO_QUERY
);
2545 // check all grid columns for their control source
2546 Reference
< ::com::sun::star::container::XIndexAccess
> xModelColumns(getFormComponent(), UNO_QUERY
);
2547 OSL_ENSURE(xModelColumns
.is(), "SbaXDataBrowserController::OnSearchContextRequest : there is a grid control without columns !");
2548 // the case 'no columns' should be indicated with an empty container, I think ...
2549 OSL_ENSURE(xModelColumns
->getCount() >= xPeerContainer
->getCount(), "SbaXDataBrowserController::OnSearchContextRequest : impossible : have more view than model columns !");
2552 for (sal_Int32 nViewPos
=0; nViewPos
<xPeerContainer
->getCount(); ++nViewPos
)
2554 Reference
< XInterface
> xCurrentColumn(xPeerContainer
->getByIndex(nViewPos
),UNO_QUERY
);
2555 if (!xCurrentColumn
.is())
2558 // can we use this column control for searching ?
2559 if (!IsSearchableControl(xCurrentColumn
))
2562 sal_uInt16 nModelPos
= getBrowserView()->View2ModelPos((sal_uInt16
)nViewPos
);
2563 Reference
< XPropertySet
> xCurrentColModel(xModelColumns
->getByIndex(nModelPos
),UNO_QUERY
);
2564 String aName
= ::comphelper::getString(xCurrentColModel
->getPropertyValue(PROPERTY_CONTROLSOURCE
));
2566 sFieldList
+= aName
;
2569 pContext
->arrFields
.push_back(xCurrentColumn
);
2571 sFieldList
.EraseTrailingChars(';');
2573 pContext
->xCursor
.set(getRowSet(),UNO_QUERY
);
2574 pContext
->strUsedFields
= sFieldList
;
2576 // if the cursor is in a mode other than STANDARD -> reset
2577 Reference
< XPropertySet
> xCursorSet(pContext
->xCursor
, UNO_QUERY
);
2578 OSL_ENSURE(xCursorSet
.is() && !::comphelper::getBOOL(xCursorSet
->getPropertyValue(PROPERTY_ISMODIFIED
)),
2579 "SbaXDataBrowserController::OnSearchContextRequest : please do not call for cursors with modified rows !");
2580 if (xCursorSet
.is() && ::comphelper::getBOOL(xCursorSet
->getPropertyValue(PROPERTY_ISNEW
)))
2582 Reference
< XResultSetUpdate
> xUpdateCursor(pContext
->xCursor
, UNO_QUERY
);
2583 xUpdateCursor
->moveToCurrentRow();
2585 return pContext
->arrFields
.size();
2588 //------------------------------------------------------------------------------
2589 IMPL_LINK(SbaXDataBrowserController
, OnFoundData
, FmFoundRecordInformation
*, pInfo
)
2591 Reference
< ::com::sun::star::sdbcx::XRowLocate
> xCursor(getRowSet(), UNO_QUERY
);
2592 OSL_ENSURE(xCursor
.is(), "SbaXDataBrowserController::OnFoundData : shit happens. sometimes. but this is simply impossible !");
2595 xCursor
->moveToBookmark(pInfo
->aPosition
);
2597 // let the grid snyc it's display with the cursor
2598 Reference
< XPropertySet
> xModelSet(getControlModel(), UNO_QUERY
);
2599 OSL_ENSURE(xModelSet
.is(), "SbaXDataBrowserController::OnFoundData : no model set ?!");
2600 Any aOld
= xModelSet
->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DisplayIsSynchron")));
2601 xModelSet
->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DisplayIsSynchron")), ::comphelper::makeBoolAny(sal_Bool(sal_True
)));
2602 xModelSet
->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DisplayIsSynchron")), aOld
);
2604 // and move to the field
2605 Reference
< ::com::sun::star::container::XIndexAccess
> aColumnControls(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY
);
2606 sal_uInt16 nViewPos
;
2608 for ( nViewPos
= 0; nViewPos
< aColumnControls
->getCount(); ++nViewPos
)
2610 Reference
< XInterface
> xCurrent(aColumnControls
->getByIndex(nViewPos
),UNO_QUERY
);
2611 if (IsSearchableControl(xCurrent
))
2613 if (pInfo
->nFieldPos
)
2620 Reference
< ::com::sun::star::form::XGrid
> xGrid(getBrowserView()->getGridControl(), UNO_QUERY
);
2621 xGrid
->setCurrentColumnPosition(nViewPos
);
2626 //------------------------------------------------------------------------------
2627 IMPL_LINK(SbaXDataBrowserController
, OnCanceledNotFound
, FmFoundRecordInformation
*, pInfo
)
2629 Reference
< ::com::sun::star::sdbcx::XRowLocate
> xCursor(getRowSet(), UNO_QUERY
);
2633 OSL_ENSURE(xCursor
.is(), "SbaXDataBrowserController::OnCanceledNotFound : shit happens. sometimes. but this is simply impossible !");
2635 xCursor
->moveToBookmark(pInfo
->aPosition
);
2637 catch( const Exception
& )
2639 DBG_UNHANDLED_EXCEPTION();
2644 // let the grid snyc its display with the cursor
2645 Reference
< XPropertySet
> xModelSet(getControlModel(), UNO_QUERY
);
2646 OSL_ENSURE(xModelSet
.is(), "SbaXDataBrowserController::OnCanceledNotFound : no model set ?!");
2647 Any aOld
= xModelSet
->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DisplayIsSynchron")));
2648 xModelSet
->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DisplayIsSynchron")), ::comphelper::makeBoolAny(sal_Bool(sal_True
)));
2649 xModelSet
->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DisplayIsSynchron")), aOld
);
2651 catch( const Exception
& )
2653 DBG_UNHANDLED_EXCEPTION();
2659 //------------------------------------------------------------------------------
2660 IMPL_LINK_NOARG(SbaXDataBrowserController
, OnAsyncGetCellFocus
)
2662 SbaGridControl
* pVclGrid
= getBrowserView() ? getBrowserView()->getVclControl() : NULL
;
2663 // if we have a controller, but the window for the controller doesn't have the focus, we correct this
2666 if (!pVclGrid
->IsEditing())
2669 if (pVclGrid
->HasChildPathFocus())
2670 pVclGrid
->Controller()->GetWindow().GrabFocus();
2676 //------------------------------------------------------------------------------
2677 void SbaXDataBrowserController::criticalFail()
2679 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::criticalFail" );
2681 m_nRowSetPrivileges
= 0;
2684 //------------------------------------------------------------------------------
2685 void SbaXDataBrowserController::LoadFinished(sal_Bool
/*bWasSynch*/)
2687 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::LoadFinished" );
2688 m_nRowSetPrivileges
= 0;
2690 if (isValid() && !loadingCancelled())
2692 // obtain cached values
2695 Reference
< XPropertySet
> xFormProps( m_xLoadable
, UNO_QUERY_THROW
);
2696 OSL_VERIFY( xFormProps
->getPropertyValue( PROPERTY_PRIVILEGES
) >>= m_nRowSetPrivileges
);
2698 catch( const Exception
& )
2700 DBG_UNHANDLED_EXCEPTION();
2703 // --------------------------------
2704 // switch the control to alive mode
2705 getBrowserView()->getGridControl()->setDesignMode(sal_False
);
2707 // -------------------------------
2710 // -------------------------------
2713 m_aAsyncGetCellFocus
.Call();
2716 // -----------------------------------------------------------------------------
2717 void SbaXDataBrowserController::initializeParser() const
2719 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::initializeParser" );
2720 if ( !m_xParser
.is() )
2722 // ----------------------------------------------
2723 // create a parser (needed for filtering/sorting)
2726 const Reference
< XPropertySet
> xFormSet(getRowSet(), UNO_QUERY
);
2727 if (::comphelper::getBOOL(xFormSet
->getPropertyValue(PROPERTY_ESCAPE_PROCESSING
)))
2728 { // (only if the statement isn't native)
2729 // (it is allowed to use the PROPERTY_ISPASSTHROUGH : _after_ loading a form it is valid)
2730 xFormSet
->getPropertyValue(PROPERTY_SINGLESELECTQUERYCOMPOSER
) >>= m_xParser
;
2735 DBG_UNHANDLED_EXCEPTION();
2737 // no further handling, we ignore the error
2741 //------------------------------------------------------------------------------
2742 void SbaXDataBrowserController::loaded(const EventObject
& /*aEvent*/) throw( RuntimeException
)
2744 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::loaded" );
2745 // not interested in
2746 // we're loading within an separate thread and have a handling for it's "finished event"
2749 //------------------------------------------------------------------------------
2750 void SbaXDataBrowserController::unloading(const EventObject
& /*aEvent*/) throw( RuntimeException
)
2752 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::unloading" );
2753 // not interested in
2756 //------------------------------------------------------------------------------
2757 void SbaXDataBrowserController::unloaded(const EventObject
& /*aEvent*/) throw( RuntimeException
)
2759 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::unloaded" );
2762 // do this asynchronously, there are other listeners reacting on this message ...
2763 // (it's a little hack : the grid columns are listening to this event, too, and their bound field may
2764 // change as a reaction on that event. as we have no chance to be notified of this change (which is
2765 // the one we're interested in) we give them time to do what they want to before invalidating our
2766 // bound-field-dependent slots ....
2769 //------------------------------------------------------------------------------
2770 void SbaXDataBrowserController::reloading(const EventObject
& /*aEvent*/) throw( RuntimeException
)
2772 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::reloading" );
2773 // not interested in
2776 //------------------------------------------------------------------------------
2777 void SbaXDataBrowserController::reloaded(const EventObject
& /*aEvent*/) throw( RuntimeException
)
2779 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::reloaded" );
2781 // do this asynchronously, there are other listeners reacting on this message ...
2782 // (it's a little hack : the grid columns are listening to this event, too, and their bound field may
2783 // change as a reaction on that event. as we have no chance to be notified of this change (which is
2784 // the one we're interested in) we give them time to do what they want to before invalidating our
2785 // bound-field-dependent slots ....
2787 //------------------------------------------------------------------------------
2788 void SbaXDataBrowserController::enterFormAction()
2790 if ( !m_nFormActionNestingLevel
)
2791 // first action -> reset
2792 m_aCurrentError
.clear();
2794 ++m_nFormActionNestingLevel
;
2797 //------------------------------------------------------------------------------
2798 void SbaXDataBrowserController::leaveFormAction()
2800 OSL_ENSURE( m_nFormActionNestingLevel
> 0, "SbaXDataBrowserController::leaveFormAction : invalid call !" );
2801 if ( --m_nFormActionNestingLevel
> 0 )
2804 if ( !m_aCurrentError
.isValid() )
2807 m_aAsyncDisplayError
.Call();
2810 // -------------------------------------------------------------------------
2811 sal_Bool
SbaXDataBrowserController::isLoaded() const
2813 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::isLoaded" );
2814 return m_xLoadable
.is() && m_xLoadable
->isLoaded();
2817 // -------------------------------------------------------------------------
2818 sal_Bool
SbaXDataBrowserController::isValidCursor() const
2820 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::isValidCursor" );
2821 if (!m_xColumnsSupplier
.is())
2823 Reference
< ::com::sun::star::container::XNameAccess
> xCols
= m_xColumnsSupplier
->getColumns();
2824 if (!xCols
.is() || !xCols
->hasElements())
2827 sal_Bool bIsValid
= !(m_xRowSet
->isBeforeFirst() || m_xRowSet
->isAfterLast());
2830 Reference
<XPropertySet
> xProp(m_xRowSet
,UNO_QUERY
);
2831 bIsValid
= ::cppu::any2bool(xProp
->getPropertyValue(PROPERTY_ISNEW
));
2834 bIsValid
= m_xParser
.is();
2840 // -----------------------------------------------------------------------------
2841 sal_Int16
SbaXDataBrowserController::getCurrentColumnPosition()
2843 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::getCurrentColumnPosition" );
2844 Reference
< ::com::sun::star::form::XGrid
> xGrid(getBrowserView()->getGridControl(), UNO_QUERY
);
2845 sal_Int16 nViewPos
= -1;
2849 nViewPos
= xGrid
->getCurrentColumnPosition();
2851 catch(Exception
&) {}
2854 // -----------------------------------------------------------------------------
2855 void SbaXDataBrowserController::setCurrentColumnPosition( sal_Int16 _nPos
)
2857 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::setCurrentColumnPosition" );
2858 Reference
< ::com::sun::star::form::XGrid
> xGrid(getBrowserView()->getGridControl(), UNO_QUERY
);
2862 xGrid
->setCurrentColumnPosition(_nPos
);
2864 catch(Exception
&) {}
2866 // -----------------------------------------------------------------------------
2867 void SbaXDataBrowserController::BeforeDrop()
2869 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::BeforeDrop" );
2870 Reference
< ::com::sun::star::sdb::XSQLErrorBroadcaster
> xFormError(getRowSet(), UNO_QUERY
);
2871 if (xFormError
.is())
2872 xFormError
->removeSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener
*)this);
2874 // -----------------------------------------------------------------------------
2875 void SbaXDataBrowserController::AfterDrop()
2877 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::AfterDrop" );
2878 Reference
< ::com::sun::star::sdb::XSQLErrorBroadcaster
> xFormError(getRowSet(), UNO_QUERY
);
2879 if (xFormError
.is())
2880 xFormError
->addSQLErrorListener((::com::sun::star::sdb::XSQLErrorListener
*)this);
2882 // -----------------------------------------------------------------------------
2883 void SbaXDataBrowserController::addColumnListeners(const Reference
< ::com::sun::star::awt::XControlModel
> & _xGridControlModel
)
2885 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::addColumnListeners" );
2886 // ... all the grid columns
2887 Reference
< ::com::sun::star::container::XIndexContainer
> xColumns(_xGridControlModel
, UNO_QUERY
);
2890 sal_Int32 nCount
= xColumns
->getCount();
2891 for (sal_uInt16 i
=0; i
< nCount
; ++i
)
2893 Reference
< XPropertySet
> xCol(xColumns
->getByIndex(i
),UNO_QUERY
);
2894 AddColumnListener(xCol
);
2898 // -----------------------------------------------------------------------------
2899 sal_Bool
SbaXDataBrowserController::InitializeGridModel(const Reference
< ::com::sun::star::form::XFormComponent
> & /*xGrid*/)
2901 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::InitializeGridModel" );
2904 //..................................................................
2905 } // namespace dbaui
2906 //..................................................................
2908 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */