1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "submissionhandler.hxx"
31 #include "formmetadata.hxx"
32 #include "formstrings.hxx"
33 #include "handlerhelper.hxx"
35 /** === begin UNO includes === **/
36 #include <com/sun/star/form/FormButtonType.hpp>
37 #include <com/sun/star/container/XNamed.hpp>
38 #include <com/sun/star/container/XIndexAccess.hpp>
39 #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
40 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
41 /** === end UNO includes === **/
42 #include <tools/debug.hxx>
43 #include <rtl/ustrbuf.hxx>
45 //------------------------------------------------------------------------
46 extern "C" void SAL_CALL
createRegistryInfo_SubmissionPropertyHandler()
48 ::pcr::SubmissionPropertyHandler::registerImplementation();
51 //........................................................................
54 //........................................................................
56 using namespace ::comphelper
;
57 using namespace ::com::sun::star
;
58 using namespace ::com::sun::star::uno
;
59 using namespace ::com::sun::star::lang
;
60 using namespace ::com::sun::star::beans
;
61 using namespace ::com::sun::star::script
;
62 using namespace ::com::sun::star::form
;
63 using namespace ::com::sun::star::xforms
;
64 using namespace ::com::sun::star::container
;
65 using namespace ::com::sun::star::inspection
;
67 //====================================================================
69 //====================================================================
70 //--------------------------------------------------------------------
71 SubmissionHelper::SubmissionHelper( ::osl::Mutex
& _rMutex
, const Reference
< XPropertySet
>& _rxIntrospectee
, const Reference
< frame::XModel
>& _rxContextDocument
)
72 :EFormsHelper( _rMutex
, _rxIntrospectee
, _rxContextDocument
)
74 OSL_ENSURE( canTriggerSubmissions( _rxIntrospectee
, _rxContextDocument
),
75 "SubmissionHelper::SubmissionHelper: you should not have instantiated me!" );
78 //--------------------------------------------------------------------
79 bool SubmissionHelper::canTriggerSubmissions( const Reference
< XPropertySet
>& _rxControlModel
,
80 const Reference
< frame::XModel
>& _rxContextDocument
) SAL_THROW(())
82 if ( !EFormsHelper::isEForm( _rxContextDocument
) )
87 Reference
< submission::XSubmissionSupplier
> xSubmissionSupp( _rxControlModel
, UNO_QUERY
);
88 if ( xSubmissionSupp
.is() )
91 catch( const Exception
& )
93 OSL_ENSURE( sal_False
, "SubmissionHelper::canTriggerSubmissions: caught an exception!" );
98 //====================================================================
99 //= SubmissionPropertyHandler
100 //====================================================================
101 DBG_NAME( SubmissionPropertyHandler
)
102 //--------------------------------------------------------------------
103 SubmissionPropertyHandler::SubmissionPropertyHandler( const Reference
< XComponentContext
>& _rxContext
)
104 :EditPropertyHandler_Base( _rxContext
)
105 ,OPropertyChangeListener( m_aMutex
)
106 ,m_pPropChangeMultiplexer( NULL
)
108 DBG_CTOR( SubmissionPropertyHandler
, NULL
);
111 //--------------------------------------------------------------------
112 SubmissionPropertyHandler::~SubmissionPropertyHandler( )
115 DBG_DTOR( SubmissionPropertyHandler
, NULL
);
118 //--------------------------------------------------------------------
119 ::rtl::OUString SAL_CALL
SubmissionPropertyHandler::getImplementationName_static( ) throw (RuntimeException
)
121 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.SubmissionPropertyHandler" ) );
124 //--------------------------------------------------------------------
125 Sequence
< ::rtl::OUString
> SAL_CALL
SubmissionPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException
)
127 Sequence
< ::rtl::OUString
> aSupported( 1 );
128 aSupported
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.SubmissionPropertyHandler" ) );
132 //--------------------------------------------------------------------
133 Any SAL_CALL
SubmissionPropertyHandler::getPropertyValue( const ::rtl::OUString
& _rPropertyName
) throw (UnknownPropertyException
, RuntimeException
)
135 ::osl::MutexGuard
aGuard( m_aMutex
);
136 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
138 OSL_ENSURE( m_pHelper
.get(), "SubmissionPropertyHandler::getPropertyValue: inconsistency!" );
139 // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
146 case PROPERTY_ID_SUBMISSION_ID
:
148 Reference
< submission::XSubmissionSupplier
> xSubmissionSupp( m_xComponent
, UNO_QUERY
);
149 OSL_ENSURE( xSubmissionSupp
.is(), "SubmissionPropertyHandler::getPropertyValue: this should never happen ..." );
150 // this handler is not intended for components which are no XSubmissionSupplier
151 Reference
< submission::XSubmission
> xSubmission
;
152 if ( xSubmissionSupp
.is() )
153 xSubmission
= xSubmissionSupp
->getSubmission( );
154 aReturn
<<= xSubmission
;
158 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
160 FormButtonType eType
= FormButtonType_PUSH
;
161 OSL_VERIFY( m_xComponent
->getPropertyValue( PROPERTY_BUTTONTYPE
) >>= eType
);
162 if ( ( eType
!= FormButtonType_PUSH
) && ( eType
!= FormButtonType_SUBMIT
) )
163 eType
= FormButtonType_PUSH
;
169 DBG_ERROR( "SubmissionPropertyHandler::getPropertyValue: cannot handle this property!" );
173 catch( const Exception
& )
175 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::getPropertyValue: caught an exception!" );
181 //--------------------------------------------------------------------
182 void SAL_CALL
SubmissionPropertyHandler::setPropertyValue( const ::rtl::OUString
& _rPropertyName
, const Any
& _rValue
) throw (UnknownPropertyException
, RuntimeException
)
184 ::osl::MutexGuard
aGuard( m_aMutex
);
185 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
187 OSL_ENSURE( m_pHelper
.get(), "SubmissionPropertyHandler::setPropertyValue: inconsistency!" );
188 // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
194 case PROPERTY_ID_SUBMISSION_ID
:
196 Reference
< submission::XSubmission
> xSubmission
;
197 OSL_VERIFY( _rValue
>>= xSubmission
);
199 Reference
< submission::XSubmissionSupplier
> xSubmissionSupp( m_xComponent
, UNO_QUERY
);
200 OSL_ENSURE( xSubmissionSupp
.is(), "SubmissionPropertyHandler::setPropertyValue: this should never happen ..." );
201 // this handler is not intended for components which are no XSubmissionSupplier
202 if ( xSubmissionSupp
.is() )
204 xSubmissionSupp
->setSubmission( xSubmission
);
205 impl_setContextDocumentModified_nothrow();
210 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
211 m_xComponent
->setPropertyValue( PROPERTY_BUTTONTYPE
, _rValue
);
215 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::setPropertyValue: cannot handle this id!" );
218 catch( const Exception
& )
220 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::setPropertyValue: caught an exception!" );
224 //--------------------------------------------------------------------
225 Sequence
< ::rtl::OUString
> SAL_CALL
SubmissionPropertyHandler::getActuatingProperties( ) throw (RuntimeException
)
227 ::osl::MutexGuard
aGuard( m_aMutex
);
228 if ( !m_pHelper
.get() )
229 return Sequence
< ::rtl::OUString
>();
231 Sequence
< ::rtl::OUString
> aReturn( 1 );
232 aReturn
[ 0 ] = PROPERTY_XFORMS_BUTTONTYPE
;
236 //--------------------------------------------------------------------
237 Sequence
< ::rtl::OUString
> SAL_CALL
SubmissionPropertyHandler::getSupersededProperties( ) throw (RuntimeException
)
239 ::osl::MutexGuard
aGuard( m_aMutex
);
240 if ( !m_pHelper
.get() )
241 return Sequence
< ::rtl::OUString
>();
243 Sequence
< ::rtl::OUString
> aReturn( 3 );
244 aReturn
[ 0 ] = PROPERTY_TARGET_URL
;
245 aReturn
[ 1 ] = PROPERTY_TARGET_FRAME
;
246 aReturn
[ 2 ] = PROPERTY_BUTTONTYPE
;
250 //--------------------------------------------------------------------
251 void SubmissionPropertyHandler::onNewComponent()
253 if ( m_pPropChangeMultiplexer
)
255 m_pPropChangeMultiplexer
->dispose();
256 m_pPropChangeMultiplexer
->release();
257 m_pPropChangeMultiplexer
= NULL
;
260 EditPropertyHandler_Base::onNewComponent();
262 Reference
< frame::XModel
> xDocument( impl_getContextDocument_nothrow() );
263 DBG_ASSERT( xDocument
.is(), "SubmissionPropertyHandler::onNewComponent: no document!" );
265 m_pHelper
.reset( NULL
);
267 if ( SubmissionHelper::canTriggerSubmissions( m_xComponent
, xDocument
) )
269 m_pHelper
.reset( new SubmissionHelper( m_aMutex
, m_xComponent
, xDocument
) );
271 m_pPropChangeMultiplexer
= new OPropertyChangeMultiplexer( this, m_xComponent
);
272 m_pPropChangeMultiplexer
->acquire();
273 m_pPropChangeMultiplexer
->addProperty( PROPERTY_BUTTONTYPE
);
277 //--------------------------------------------------------------------
278 Sequence
< Property
> SAL_CALL
SubmissionPropertyHandler::doDescribeSupportedProperties() const
280 ::std::vector
< Property
> aProperties
;
281 if ( m_pHelper
.get() )
283 implAddPropertyDescription( aProperties
, PROPERTY_SUBMISSION_ID
, ::getCppuType( static_cast< Reference
< submission::XSubmission
> * >( NULL
) ) );
284 implAddPropertyDescription( aProperties
, PROPERTY_XFORMS_BUTTONTYPE
, ::getCppuType( static_cast< FormButtonType
* >( NULL
) ) );
286 if ( aProperties
.empty() )
287 return Sequence
< Property
>();
288 return Sequence
< Property
>( &(*aProperties
.begin()), aProperties
.size() );
291 //--------------------------------------------------------------------
292 LineDescriptor SAL_CALL
SubmissionPropertyHandler::describePropertyLine( const ::rtl::OUString
& _rPropertyName
,
293 const Reference
< XPropertyControlFactory
>& _rxControlFactory
)
294 throw (UnknownPropertyException
, NullPointerException
, RuntimeException
)
296 ::osl::MutexGuard
aGuard( m_aMutex
);
297 if ( !_rxControlFactory
.is() )
298 throw NullPointerException();
299 if ( !m_pHelper
.get() )
302 ::std::vector
< ::rtl::OUString
> aListEntries
;
303 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
306 case PROPERTY_ID_SUBMISSION_ID
:
307 const_cast< SubmissionHelper
* >( m_pHelper
.get() )->getAllElementUINames( EFormsHelper::Submission
, aListEntries
, false );
310 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
312 // available options are nearly the same as for the "normal" button type, but only the
314 aListEntries
= m_pInfoService
->getPropertyEnumRepresentations( PROPERTY_ID_BUTTONTYPE
);
315 aListEntries
.resize( 2 );
320 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::describePropertyLine: cannot handle this id!" );
321 return LineDescriptor();
324 LineDescriptor aDescriptor
;
325 aDescriptor
.Control
= PropertyHandlerHelper::createListBoxControl( _rxControlFactory
, aListEntries
, sal_False
, sal_True
);
326 aDescriptor
.DisplayName
= m_pInfoService
->getPropertyTranslation( nPropId
);
327 aDescriptor
.Category
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "General" ) );
328 aDescriptor
.HelpURL
= HelpIdUrl::getHelpURL( m_pInfoService
->getPropertyHelpId( nPropId
) );
332 //--------------------------------------------------------------------
333 void SAL_CALL
SubmissionPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString
& _rActuatingPropertyName
, const Any
& _rNewValue
, const Any
& /*_rOldValue*/, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, sal_Bool
) throw (NullPointerException
, RuntimeException
)
335 if ( !_rxInspectorUI
.is() )
336 throw NullPointerException();
338 ::osl::MutexGuard
aGuard( m_aMutex
);
339 PropertyId
nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName
) );
340 OSL_PRECOND( m_pHelper
.get(), "SubmissionPropertyHandler::actuatingPropertyChanged: inconsistentcy!" );
341 // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
343 switch ( nActuatingPropId
)
345 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
347 FormButtonType eType
= FormButtonType_PUSH
;
348 OSL_VERIFY( _rNewValue
>>= eType
);
349 _rxInspectorUI
->enablePropertyUI( PROPERTY_SUBMISSION_ID
, eType
== FormButtonType_SUBMIT
);
354 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
358 //--------------------------------------------------------------------
359 Any SAL_CALL
SubmissionPropertyHandler::convertToPropertyValue( const ::rtl::OUString
& _rPropertyName
, const Any
& _rControlValue
) throw (UnknownPropertyException
, RuntimeException
)
361 ::osl::MutexGuard
aGuard( m_aMutex
);
364 OSL_ENSURE( m_pHelper
.get(), "SubmissionPropertyHandler::convertToPropertyValue: we have no SupportedProperties!" );
365 if ( !m_pHelper
.get() )
366 return aPropertyValue
;
368 ::rtl::OUString sControlValue
;
369 OSL_VERIFY( _rControlValue
>>= sControlValue
);
371 PropertyId
nPropId( m_pInfoService
->getPropertyId( _rPropertyName
) );
374 case PROPERTY_ID_SUBMISSION_ID
:
376 Reference
< XSubmission
> xSubmission( m_pHelper
->getModelElementFromUIName( EFormsHelper::Submission
, sControlValue
), UNO_QUERY
);
377 aPropertyValue
<<= xSubmission
;
381 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
383 ::rtl::Reference
< IPropertyEnumRepresentation
> aEnumConversion(
384 new DefaultEnumRepresentation( *m_pInfoService
, ::getCppuType( static_cast< FormButtonType
* >( NULL
) ), PROPERTY_ID_BUTTONTYPE
) );
385 // TODO/UNOize: make aEnumConversion a member?
386 aEnumConversion
->getValueFromDescription( sControlValue
, aPropertyValue
);
391 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::convertToPropertyValue: cannot handle this id!" );
394 return aPropertyValue
;
397 //--------------------------------------------------------------------
398 Any SAL_CALL
SubmissionPropertyHandler::convertToControlValue( const ::rtl::OUString
& _rPropertyName
, const Any
& _rPropertyValue
, const Type
& _rControlValueType
) throw (UnknownPropertyException
, RuntimeException
)
400 ::osl::MutexGuard
aGuard( m_aMutex
);
403 OSL_ENSURE( m_pHelper
.get(), "SubmissionPropertyHandler::convertToControlValue: we have no SupportedProperties!" );
404 if ( !m_pHelper
.get() )
405 return aControlValue
;
407 OSL_ENSURE( _rControlValueType
.getTypeClass() == TypeClass_STRING
,
408 "SubmissionPropertyHandler::convertToControlValue: all our controls should use strings for value exchange!" );
409 (void)_rControlValueType
;
411 PropertyId
nPropId( m_pInfoService
->getPropertyId( _rPropertyName
) );
414 case PROPERTY_ID_SUBMISSION_ID
:
416 Reference
< XPropertySet
> xSubmission( _rPropertyValue
, UNO_QUERY
);
417 if ( xSubmission
.is() )
418 aControlValue
<<= m_pHelper
->getModelElementUIName( EFormsHelper::Submission
, xSubmission
);
422 case PROPERTY_ID_XFORMS_BUTTONTYPE
:
424 ::rtl::Reference
< IPropertyEnumRepresentation
> aEnumConversion(
425 new DefaultEnumRepresentation( *m_pInfoService
, _rPropertyValue
.getValueType(), PROPERTY_ID_BUTTONTYPE
) );
426 // TODO/UNOize: make aEnumConversion a member?
427 aControlValue
<<= aEnumConversion
->getDescriptionForValue( _rPropertyValue
);
432 OSL_ENSURE( sal_False
, "SubmissionPropertyHandler::convertToControlValue: cannot handle this id!" );
435 return aControlValue
;
438 //--------------------------------------------------------------------
439 void SubmissionPropertyHandler::_propertyChanged( const PropertyChangeEvent
& _rEvent
) throw(RuntimeException
)
441 if ( _rEvent
.PropertyName
== PROPERTY_BUTTONTYPE
)
442 firePropertyChange( PROPERTY_XFORMS_BUTTONTYPE
, PROPERTY_ID_XFORMS_BUTTONTYPE
, _rEvent
.OldValue
, _rEvent
.NewValue
);
445 //........................................................................
447 //........................................................................