1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: submissionhandler.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "submissionhandler.hxx"
34 #include "formmetadata.hxx"
35 #include "formstrings.hxx"
36 #include "handlerhelper.hxx"
38 /** === begin UNO includes === **/
39 #include <com/sun/star/form/FormButtonType.hpp>
40 #include <com/sun/star/container/XNamed.hpp>
41 #include <com/sun/star/container/XIndexAccess.hpp>
42 #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
43 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
44 /** === end UNO includes === **/
45 #include <tools/debug.hxx>
46 #include <rtl/ustrbuf.hxx>
48 //------------------------------------------------------------------------
49 extern "C" void SAL_CALL
createRegistryInfo_SubmissionPropertyHandler()
51 ::pcr::SubmissionPropertyHandler::registerImplementation();
54 //........................................................................
57 //........................................................................
59 using namespace ::comphelper
;
60 using namespace ::com::sun::star
;
61 using namespace ::com::sun::star::uno
;
62 using namespace ::com::sun::star::lang
;
63 using namespace ::com::sun::star::beans
;
64 using namespace ::com::sun::star::script
;
65 using namespace ::com::sun::star::form
;
66 using namespace ::com::sun::star::xforms
;
67 using namespace ::com::sun::star::container
;
68 using namespace ::com::sun::star::inspection
;
70 //====================================================================
72 //====================================================================
73 //--------------------------------------------------------------------
74 SubmissionHelper::SubmissionHelper( ::osl::Mutex
& _rMutex
, const Reference
< XPropertySet
>& _rxIntrospectee
, const Reference
< frame::XModel
>& _rxContextDocument
)
75 :EFormsHelper( _rMutex
, _rxIntrospectee
, _rxContextDocument
)
77 OSL_ENSURE( canTriggerSubmissions( _rxIntrospectee
, _rxContextDocument
),
78 "SubmissionHelper::SubmissionHelper: you should not have instantiated me!" );
81 //--------------------------------------------------------------------
82 bool SubmissionHelper::canTriggerSubmissions( const Reference
< XPropertySet
>& _rxControlModel
,
83 const Reference
< frame::XModel
>& _rxContextDocument
) SAL_THROW(())
85 if ( !EFormsHelper::isEForm( _rxContextDocument
) )
90 Reference
< submission::XSubmissionSupplier
> xSubmissionSupp( _rxControlModel
, UNO_QUERY
);
91 if ( xSubmissionSupp
.is() )
94 catch( const Exception
& )
96 OSL_ENSURE( sal_False
, "SubmissionHelper::canTriggerSubmissions: caught an exception!" );
101 //====================================================================
102 //= SubmissionPropertyHandler
103 //====================================================================
104 DBG_NAME( SubmissionPropertyHandler
)
105 //--------------------------------------------------------------------
106 SubmissionPropertyHandler::SubmissionPropertyHandler( const Reference
< XComponentContext
>& _rxContext
)
107 :EditPropertyHandler_Base( _rxContext
)
108 ,OPropertyChangeListener( m_aMutex
)
109 ,m_pPropChangeMultiplexer( NULL
)
111 DBG_CTOR( SubmissionPropertyHandler
, NULL
);
114 //--------------------------------------------------------------------
115 SubmissionPropertyHandler::~SubmissionPropertyHandler( )
118 DBG_DTOR( SubmissionPropertyHandler
, NULL
);
121 //--------------------------------------------------------------------
122 ::rtl::OUString SAL_CALL
SubmissionPropertyHandler::getImplementationName_static( ) throw (RuntimeException
)
124 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.SubmissionPropertyHandler" ) );
127 //--------------------------------------------------------------------
128 Sequence
< ::rtl::OUString
> SAL_CALL
SubmissionPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException
)
130 Sequence
< ::rtl::OUString
> aSupported( 1 );
131 aSupported
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.SubmissionPropertyHandler" ) );
135 //--------------------------------------------------------------------
136 Any SAL_CALL
SubmissionPropertyHandler::getPropertyValue( const ::rtl::OUString
& _rPropertyName
) throw (UnknownPropertyException
, RuntimeException
)
138 ::osl::MutexGuard
aGuard( m_aMutex
);
139 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
141 OSL_ENSURE( m_pHelper
.get(), "SubmissionPropertyHandler::getPropertyValue: inconsistency!" );
142 // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
149 case PROPERTY_ID_SUBMISSION_ID
:
151 Reference
< submission::XSubmissionSupplier
> xSubmissionSupp( m_xComponent
, UNO_QUERY
);
152 OSL_ENSURE( xSubmissionSupp
.is(), "SubmissionPropertyHandler::getPropertyValue: this should never happen ..." );
153 // this handler is not intended for components which are no XSubmissionSupplier
154 Reference
< submission::XSubmission
> xSubmission
;
155 if ( xSubmissionSupp
.is() )
156 xSubmission
= xSubmissionSupp
->getSubmission( );
157 aReturn
<<= xSubmission
;
161 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
163 FormButtonType eType
= FormButtonType_PUSH
;
164 OSL_VERIFY( m_xComponent
->getPropertyValue( PROPERTY_BUTTONTYPE
) >>= eType
);
165 if ( ( eType
!= FormButtonType_PUSH
) && ( eType
!= FormButtonType_SUBMIT
) )
166 eType
= FormButtonType_PUSH
;
172 DBG_ERROR( "SubmissionPropertyHandler::getPropertyValue: cannot handle this property!" );
176 catch( const Exception
& )
178 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::getPropertyValue: caught an exception!" );
184 //--------------------------------------------------------------------
185 void SAL_CALL
SubmissionPropertyHandler::setPropertyValue( const ::rtl::OUString
& _rPropertyName
, const Any
& _rValue
) throw (UnknownPropertyException
, RuntimeException
)
187 ::osl::MutexGuard
aGuard( m_aMutex
);
188 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
190 OSL_ENSURE( m_pHelper
.get(), "SubmissionPropertyHandler::setPropertyValue: inconsistency!" );
191 // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
197 case PROPERTY_ID_SUBMISSION_ID
:
199 Reference
< submission::XSubmission
> xSubmission
;
200 OSL_VERIFY( _rValue
>>= xSubmission
);
202 Reference
< submission::XSubmissionSupplier
> xSubmissionSupp( m_xComponent
, UNO_QUERY
);
203 OSL_ENSURE( xSubmissionSupp
.is(), "SubmissionPropertyHandler::setPropertyValue: this should never happen ..." );
204 // this handler is not intended for components which are no XSubmissionSupplier
205 if ( xSubmissionSupp
.is() )
207 xSubmissionSupp
->setSubmission( xSubmission
);
208 impl_setContextDocumentModified_nothrow();
213 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
214 m_xComponent
->setPropertyValue( PROPERTY_BUTTONTYPE
, _rValue
);
218 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::setPropertyValue: cannot handle this id!" );
221 catch( const Exception
& )
223 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::setPropertyValue: caught an exception!" );
227 //--------------------------------------------------------------------
228 Sequence
< ::rtl::OUString
> SAL_CALL
SubmissionPropertyHandler::getActuatingProperties( ) throw (RuntimeException
)
230 ::osl::MutexGuard
aGuard( m_aMutex
);
231 if ( !m_pHelper
.get() )
232 return Sequence
< ::rtl::OUString
>();
234 Sequence
< ::rtl::OUString
> aReturn( 1 );
235 aReturn
[ 0 ] = PROPERTY_XFORMS_BUTTONTYPE
;
239 //--------------------------------------------------------------------
240 Sequence
< ::rtl::OUString
> SAL_CALL
SubmissionPropertyHandler::getSupersededProperties( ) throw (RuntimeException
)
242 ::osl::MutexGuard
aGuard( m_aMutex
);
243 if ( !m_pHelper
.get() )
244 return Sequence
< ::rtl::OUString
>();
246 Sequence
< ::rtl::OUString
> aReturn( 3 );
247 aReturn
[ 0 ] = PROPERTY_TARGET_URL
;
248 aReturn
[ 1 ] = PROPERTY_TARGET_FRAME
;
249 aReturn
[ 2 ] = PROPERTY_BUTTONTYPE
;
253 //--------------------------------------------------------------------
254 void SubmissionPropertyHandler::onNewComponent()
256 if ( m_pPropChangeMultiplexer
)
258 m_pPropChangeMultiplexer
->dispose();
259 m_pPropChangeMultiplexer
->release();
260 m_pPropChangeMultiplexer
= NULL
;
263 EditPropertyHandler_Base::onNewComponent();
265 Reference
< frame::XModel
> xDocument( impl_getContextDocument_nothrow() );
266 DBG_ASSERT( xDocument
.is(), "SubmissionPropertyHandler::onNewComponent: no document!" );
268 m_pHelper
.reset( NULL
);
270 if ( SubmissionHelper::canTriggerSubmissions( m_xComponent
, xDocument
) )
272 m_pHelper
.reset( new SubmissionHelper( m_aMutex
, m_xComponent
, xDocument
) );
274 m_pPropChangeMultiplexer
= new OPropertyChangeMultiplexer( this, m_xComponent
);
275 m_pPropChangeMultiplexer
->acquire();
276 m_pPropChangeMultiplexer
->addProperty( PROPERTY_BUTTONTYPE
);
280 //--------------------------------------------------------------------
281 Sequence
< Property
> SAL_CALL
SubmissionPropertyHandler::doDescribeSupportedProperties() const
283 ::std::vector
< Property
> aProperties
;
284 if ( m_pHelper
.get() )
286 implAddPropertyDescription( aProperties
, PROPERTY_SUBMISSION_ID
, ::getCppuType( static_cast< Reference
< submission::XSubmission
> * >( NULL
) ) );
287 implAddPropertyDescription( aProperties
, PROPERTY_XFORMS_BUTTONTYPE
, ::getCppuType( static_cast< FormButtonType
* >( NULL
) ) );
289 if ( aProperties
.empty() )
290 return Sequence
< Property
>();
291 return Sequence
< Property
>( &(*aProperties
.begin()), aProperties
.size() );
294 //--------------------------------------------------------------------
295 LineDescriptor SAL_CALL
SubmissionPropertyHandler::describePropertyLine( const ::rtl::OUString
& _rPropertyName
,
296 const Reference
< XPropertyControlFactory
>& _rxControlFactory
)
297 throw (UnknownPropertyException
, NullPointerException
, RuntimeException
)
299 ::osl::MutexGuard
aGuard( m_aMutex
);
300 if ( !_rxControlFactory
.is() )
301 throw NullPointerException();
302 if ( !m_pHelper
.get() )
305 ::std::vector
< ::rtl::OUString
> aListEntries
;
306 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
309 case PROPERTY_ID_SUBMISSION_ID
:
310 const_cast< SubmissionHelper
* >( m_pHelper
.get() )->getAllElementUINames( EFormsHelper::Submission
, aListEntries
, false );
313 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
315 // available options are nearly the same as for the "normal" button type, but only the
317 aListEntries
= m_pInfoService
->getPropertyEnumRepresentations( PROPERTY_ID_BUTTONTYPE
);
318 aListEntries
.resize( 2 );
323 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::describePropertyLine: cannot handle this id!" );
324 return LineDescriptor();
327 LineDescriptor aDescriptor
;
328 aDescriptor
.Control
= PropertyHandlerHelper::createListBoxControl( _rxControlFactory
, aListEntries
, sal_False
, sal_True
);
329 aDescriptor
.DisplayName
= m_pInfoService
->getPropertyTranslation( nPropId
);
330 aDescriptor
.Category
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "General" ) );
331 aDescriptor
.HelpURL
= HelpIdUrl::getHelpURL( m_pInfoService
->getPropertyHelpId( nPropId
) );
335 //--------------------------------------------------------------------
336 void SAL_CALL
SubmissionPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString
& _rActuatingPropertyName
, const Any
& _rNewValue
, const Any
& /*_rOldValue*/, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, sal_Bool
) throw (NullPointerException
, RuntimeException
)
338 if ( !_rxInspectorUI
.is() )
339 throw NullPointerException();
341 ::osl::MutexGuard
aGuard( m_aMutex
);
342 PropertyId
nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName
) );
343 OSL_PRECOND( m_pHelper
.get(), "SubmissionPropertyHandler::actuatingPropertyChanged: inconsistentcy!" );
344 // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
346 switch ( nActuatingPropId
)
348 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
350 FormButtonType eType
= FormButtonType_PUSH
;
351 OSL_VERIFY( _rNewValue
>>= eType
);
352 _rxInspectorUI
->enablePropertyUI( PROPERTY_SUBMISSION_ID
, eType
== FormButtonType_SUBMIT
);
357 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
361 //--------------------------------------------------------------------
362 Any SAL_CALL
SubmissionPropertyHandler::convertToPropertyValue( const ::rtl::OUString
& _rPropertyName
, const Any
& _rControlValue
) throw (UnknownPropertyException
, RuntimeException
)
364 ::osl::MutexGuard
aGuard( m_aMutex
);
367 OSL_ENSURE( m_pHelper
.get(), "SubmissionPropertyHandler::convertToPropertyValue: we have no SupportedProperties!" );
368 if ( !m_pHelper
.get() )
369 return aPropertyValue
;
371 ::rtl::OUString sControlValue
;
372 OSL_VERIFY( _rControlValue
>>= sControlValue
);
374 PropertyId
nPropId( m_pInfoService
->getPropertyId( _rPropertyName
) );
377 case PROPERTY_ID_SUBMISSION_ID
:
379 Reference
< XSubmission
> xSubmission( m_pHelper
->getModelElementFromUIName( EFormsHelper::Submission
, sControlValue
), UNO_QUERY
);
380 aPropertyValue
<<= xSubmission
;
384 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
386 ::rtl::Reference
< IPropertyEnumRepresentation
> aEnumConversion(
387 new DefaultEnumRepresentation( *m_pInfoService
, ::getCppuType( static_cast< FormButtonType
* >( NULL
) ), PROPERTY_ID_BUTTONTYPE
) );
388 // TODO/UNOize: make aEnumConversion a member?
389 aEnumConversion
->getValueFromDescription( sControlValue
, aPropertyValue
);
394 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::convertToPropertyValue: cannot handle this id!" );
397 return aPropertyValue
;
400 //--------------------------------------------------------------------
401 Any SAL_CALL
SubmissionPropertyHandler::convertToControlValue( const ::rtl::OUString
& _rPropertyName
, const Any
& _rPropertyValue
, const Type
& _rControlValueType
) throw (UnknownPropertyException
, RuntimeException
)
403 ::osl::MutexGuard
aGuard( m_aMutex
);
406 OSL_ENSURE( m_pHelper
.get(), "SubmissionPropertyHandler::convertToControlValue: we have no SupportedProperties!" );
407 if ( !m_pHelper
.get() )
408 return aControlValue
;
410 OSL_ENSURE( _rControlValueType
.getTypeClass() == TypeClass_STRING
,
411 "SubmissionPropertyHandler::convertToControlValue: all our controls should use strings for value exchange!" );
412 (void)_rControlValueType
;
414 PropertyId
nPropId( m_pInfoService
->getPropertyId( _rPropertyName
) );
417 case PROPERTY_ID_SUBMISSION_ID
:
419 Reference
< XPropertySet
> xSubmission( _rPropertyValue
, UNO_QUERY
);
420 if ( xSubmission
.is() )
421 aControlValue
<<= m_pHelper
->getModelElementUIName( EFormsHelper::Submission
, xSubmission
);
425 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
427 ::rtl::Reference
< IPropertyEnumRepresentation
> aEnumConversion(
428 new DefaultEnumRepresentation( *m_pInfoService
, _rPropertyValue
.getValueType(), PROPERTY_ID_BUTTONTYPE
) );
429 // TODO/UNOize: make aEnumConversion a member?
430 aControlValue
<<= aEnumConversion
->getDescriptionForValue( _rPropertyValue
);
435 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::convertToControlValue: cannot handle this id!" );
438 return aControlValue
;
441 //--------------------------------------------------------------------
442 void SubmissionPropertyHandler::_propertyChanged( const PropertyChangeEvent
& _rEvent
) throw(RuntimeException
)
444 if ( _rEvent
.PropertyName
== PROPERTY_BUTTONTYPE
)
445 firePropertyChange( PROPERTY_XFORMS_BUTTONTYPE
, PROPERTY_ID_XFORMS_BUTTONTYPE
, _rEvent
.OldValue
, _rEvent
.NewValue
);
448 //........................................................................
450 //........................................................................