Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "submissionhandler.hxx"
21 : #include "formmetadata.hxx"
22 : #include "formstrings.hxx"
23 : #include "handlerhelper.hxx"
24 :
25 : #include <com/sun/star/form/FormButtonType.hpp>
26 : #include <com/sun/star/container/XNamed.hpp>
27 : #include <com/sun/star/container/XIndexAccess.hpp>
28 : #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
29 : #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
30 : #include <tools/debug.hxx>
31 : #include <rtl/ustrbuf.hxx>
32 :
33 :
34 0 : extern "C" void SAL_CALL createRegistryInfo_SubmissionPropertyHandler()
35 : {
36 0 : ::pcr::SubmissionPropertyHandler::registerImplementation();
37 0 : }
38 :
39 :
40 : namespace pcr
41 : {
42 :
43 :
44 : using namespace ::comphelper;
45 : using namespace ::com::sun::star;
46 : using namespace ::com::sun::star::uno;
47 : using namespace ::com::sun::star::lang;
48 : using namespace ::com::sun::star::beans;
49 : using namespace ::com::sun::star::script;
50 : using namespace ::com::sun::star::form;
51 : using namespace ::com::sun::star::xforms;
52 : using namespace ::com::sun::star::container;
53 : using namespace ::com::sun::star::inspection;
54 :
55 :
56 : //= SubmissionHelper
57 :
58 :
59 0 : SubmissionHelper::SubmissionHelper( ::osl::Mutex& _rMutex, const Reference< XPropertySet >& _rxIntrospectee, const Reference< frame::XModel >& _rxContextDocument )
60 0 : :EFormsHelper( _rMutex, _rxIntrospectee, _rxContextDocument )
61 : {
62 : OSL_ENSURE( canTriggerSubmissions( _rxIntrospectee, _rxContextDocument ),
63 : "SubmissionHelper::SubmissionHelper: you should not have instantiated me!" );
64 0 : }
65 :
66 :
67 0 : bool SubmissionHelper::canTriggerSubmissions( const Reference< XPropertySet >& _rxControlModel,
68 : const Reference< frame::XModel >& _rxContextDocument ) SAL_THROW(())
69 : {
70 0 : if ( !EFormsHelper::isEForm( _rxContextDocument ) )
71 0 : return false;
72 :
73 : try
74 : {
75 0 : Reference< submission::XSubmissionSupplier > xSubmissionSupp( _rxControlModel, UNO_QUERY );
76 0 : if ( xSubmissionSupp.is() )
77 0 : return true;
78 : }
79 0 : catch( const Exception& )
80 : {
81 : OSL_FAIL( "SubmissionHelper::canTriggerSubmissions: caught an exception!" );
82 : }
83 0 : return false;
84 : }
85 :
86 :
87 : //= SubmissionPropertyHandler
88 :
89 :
90 0 : SubmissionPropertyHandler::SubmissionPropertyHandler( const Reference< XComponentContext >& _rxContext )
91 : :EditPropertyHandler_Base( _rxContext )
92 : ,OPropertyChangeListener( m_aMutex )
93 0 : ,m_pPropChangeMultiplexer( NULL )
94 : {
95 0 : }
96 :
97 :
98 0 : SubmissionPropertyHandler::~SubmissionPropertyHandler( )
99 : {
100 0 : disposeAdapter();
101 0 : }
102 :
103 :
104 0 : OUString SAL_CALL SubmissionPropertyHandler::getImplementationName_static( ) throw (RuntimeException)
105 : {
106 0 : return OUString( "com.sun.star.comp.extensions.SubmissionPropertyHandler" );
107 : }
108 :
109 :
110 0 : Sequence< OUString > SAL_CALL SubmissionPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException)
111 : {
112 0 : Sequence< OUString > aSupported( 1 );
113 0 : aSupported[0] = "com.sun.star.form.inspection.SubmissionPropertyHandler";
114 0 : return aSupported;
115 : }
116 :
117 :
118 0 : Any SAL_CALL SubmissionPropertyHandler::getPropertyValue( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException, std::exception)
119 : {
120 0 : ::osl::MutexGuard aGuard( m_aMutex );
121 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
122 :
123 : OSL_ENSURE( m_pHelper.get(), "SubmissionPropertyHandler::getPropertyValue: inconsistency!" );
124 : // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
125 :
126 0 : Any aReturn;
127 : try
128 : {
129 0 : switch ( nPropId )
130 : {
131 : case PROPERTY_ID_SUBMISSION_ID:
132 : {
133 0 : Reference< submission::XSubmissionSupplier > xSubmissionSupp( m_xComponent, UNO_QUERY );
134 : OSL_ENSURE( xSubmissionSupp.is(), "SubmissionPropertyHandler::getPropertyValue: this should never happen ..." );
135 : // this handler is not intended for components which are no XSubmissionSupplier
136 0 : Reference< submission::XSubmission > xSubmission;
137 0 : if ( xSubmissionSupp.is() )
138 0 : xSubmission = xSubmissionSupp->getSubmission( );
139 0 : aReturn <<= xSubmission;
140 : }
141 0 : break;
142 :
143 : case PROPERTY_ID_XFORMS_BUTTONTYPE:
144 : {
145 0 : FormButtonType eType = FormButtonType_PUSH;
146 0 : OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_BUTTONTYPE ) >>= eType );
147 0 : if ( ( eType != FormButtonType_PUSH ) && ( eType != FormButtonType_SUBMIT ) )
148 0 : eType = FormButtonType_PUSH;
149 0 : aReturn <<= eType;
150 : }
151 0 : break;
152 :
153 : default:
154 : OSL_FAIL( "SubmissionPropertyHandler::getPropertyValue: cannot handle this property!" );
155 0 : break;
156 : }
157 : }
158 0 : catch( const Exception& )
159 : {
160 : OSL_FAIL( "SubmissionPropertyHandler::getPropertyValue: caught an exception!" );
161 : }
162 :
163 0 : return aReturn;
164 : }
165 :
166 :
167 0 : void SAL_CALL SubmissionPropertyHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException, std::exception)
168 : {
169 0 : ::osl::MutexGuard aGuard( m_aMutex );
170 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
171 :
172 : OSL_ENSURE( m_pHelper.get(), "SubmissionPropertyHandler::setPropertyValue: inconsistency!" );
173 : // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
174 :
175 : try
176 : {
177 0 : switch ( nPropId )
178 : {
179 : case PROPERTY_ID_SUBMISSION_ID:
180 : {
181 0 : Reference< submission::XSubmission > xSubmission;
182 0 : OSL_VERIFY( _rValue >>= xSubmission );
183 :
184 0 : Reference< submission::XSubmissionSupplier > xSubmissionSupp( m_xComponent, UNO_QUERY );
185 : OSL_ENSURE( xSubmissionSupp.is(), "SubmissionPropertyHandler::setPropertyValue: this should never happen ..." );
186 : // this handler is not intended for components which are no XSubmissionSupplier
187 0 : if ( xSubmissionSupp.is() )
188 : {
189 0 : xSubmissionSupp->setSubmission( xSubmission );
190 0 : impl_setContextDocumentModified_nothrow();
191 0 : }
192 : }
193 0 : break;
194 :
195 : case PROPERTY_ID_XFORMS_BUTTONTYPE:
196 0 : m_xComponent->setPropertyValue( PROPERTY_BUTTONTYPE, _rValue );
197 0 : break;
198 :
199 : default:
200 : OSL_FAIL( "SubmissionPropertyHandler::setPropertyValue: cannot handle this id!" );
201 : }
202 : }
203 0 : catch( const Exception& )
204 : {
205 : OSL_FAIL( "SubmissionPropertyHandler::setPropertyValue: caught an exception!" );
206 0 : }
207 0 : }
208 :
209 :
210 0 : Sequence< OUString > SAL_CALL SubmissionPropertyHandler::getActuatingProperties( ) throw (RuntimeException, std::exception)
211 : {
212 0 : ::osl::MutexGuard aGuard( m_aMutex );
213 0 : if ( !m_pHelper.get() )
214 0 : return Sequence< OUString >();
215 :
216 0 : Sequence< OUString > aReturn( 1 );
217 0 : aReturn[ 0 ] = PROPERTY_XFORMS_BUTTONTYPE;
218 0 : return aReturn;
219 : }
220 :
221 :
222 0 : Sequence< OUString > SAL_CALL SubmissionPropertyHandler::getSupersededProperties( ) throw (RuntimeException, std::exception)
223 : {
224 0 : ::osl::MutexGuard aGuard( m_aMutex );
225 0 : if ( !m_pHelper.get() )
226 0 : return Sequence< OUString >();
227 :
228 0 : Sequence< OUString > aReturn( 3 );
229 0 : aReturn[ 0 ] = PROPERTY_TARGET_URL;
230 0 : aReturn[ 1 ] = PROPERTY_TARGET_FRAME;
231 0 : aReturn[ 2 ] = PROPERTY_BUTTONTYPE;
232 0 : return aReturn;
233 : }
234 :
235 :
236 0 : void SubmissionPropertyHandler::onNewComponent()
237 : {
238 0 : if ( m_pPropChangeMultiplexer )
239 : {
240 0 : m_pPropChangeMultiplexer->dispose();
241 0 : m_pPropChangeMultiplexer->release();
242 0 : m_pPropChangeMultiplexer = NULL;
243 : }
244 :
245 0 : EditPropertyHandler_Base::onNewComponent();
246 :
247 0 : Reference< frame::XModel > xDocument( impl_getContextDocument_nothrow() );
248 : DBG_ASSERT( xDocument.is(), "SubmissionPropertyHandler::onNewComponent: no document!" );
249 :
250 0 : m_pHelper.reset();
251 :
252 0 : if ( SubmissionHelper::canTriggerSubmissions( m_xComponent, xDocument ) )
253 : {
254 0 : m_pHelper.reset( new SubmissionHelper( m_aMutex, m_xComponent, xDocument ) );
255 :
256 0 : m_pPropChangeMultiplexer = new OPropertyChangeMultiplexer( this, m_xComponent );
257 0 : m_pPropChangeMultiplexer->acquire();
258 0 : m_pPropChangeMultiplexer->addProperty( PROPERTY_BUTTONTYPE );
259 0 : }
260 0 : }
261 :
262 :
263 0 : Sequence< Property > SAL_CALL SubmissionPropertyHandler::doDescribeSupportedProperties() const
264 : {
265 0 : ::std::vector< Property > aProperties;
266 0 : if ( m_pHelper.get() )
267 : {
268 0 : implAddPropertyDescription( aProperties, PROPERTY_SUBMISSION_ID, ::getCppuType( static_cast< Reference< submission::XSubmission > * >( NULL ) ) );
269 0 : implAddPropertyDescription( aProperties, PROPERTY_XFORMS_BUTTONTYPE, ::getCppuType( static_cast< FormButtonType* >( NULL ) ) );
270 : }
271 0 : if ( aProperties.empty() )
272 0 : return Sequence< Property >();
273 0 : return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
274 : }
275 :
276 :
277 0 : LineDescriptor SAL_CALL SubmissionPropertyHandler::describePropertyLine( const OUString& _rPropertyName,
278 : const Reference< XPropertyControlFactory >& _rxControlFactory )
279 : throw (UnknownPropertyException, NullPointerException, RuntimeException, std::exception)
280 : {
281 0 : ::osl::MutexGuard aGuard( m_aMutex );
282 0 : if ( !_rxControlFactory.is() )
283 0 : throw NullPointerException();
284 0 : if ( !m_pHelper.get() )
285 0 : RuntimeException();
286 :
287 0 : ::std::vector< OUString > aListEntries;
288 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
289 0 : switch ( nPropId )
290 : {
291 : case PROPERTY_ID_SUBMISSION_ID:
292 0 : const_cast< SubmissionHelper* >( m_pHelper.get() )->getAllElementUINames( EFormsHelper::Submission, aListEntries, false );
293 0 : break;
294 :
295 : case PROPERTY_ID_XFORMS_BUTTONTYPE:
296 : {
297 : // available options are nearly the same as for the "normal" button type, but only the
298 : // first two options
299 0 : aListEntries = m_pInfoService->getPropertyEnumRepresentations( PROPERTY_ID_BUTTONTYPE );
300 0 : aListEntries.resize( 2 );
301 : }
302 0 : break;
303 :
304 : default:
305 : OSL_FAIL( "SubmissionPropertyHandler::describePropertyLine: cannot handle this id!" );
306 0 : return LineDescriptor();
307 : }
308 :
309 0 : LineDescriptor aDescriptor;
310 0 : aDescriptor.Control = PropertyHandlerHelper::createListBoxControl( _rxControlFactory, aListEntries, sal_False, sal_True );
311 0 : aDescriptor.DisplayName = m_pInfoService->getPropertyTranslation( nPropId );
312 0 : aDescriptor.Category = "General";
313 0 : aDescriptor.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nPropId ) );
314 0 : return aDescriptor;
315 : }
316 :
317 :
318 0 : void SAL_CALL SubmissionPropertyHandler::actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool ) throw (NullPointerException, RuntimeException, std::exception)
319 : {
320 0 : if ( !_rxInspectorUI.is() )
321 0 : throw NullPointerException();
322 :
323 0 : ::osl::MutexGuard aGuard( m_aMutex );
324 0 : PropertyId nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
325 : OSL_PRECOND( m_pHelper.get(), "SubmissionPropertyHandler::actuatingPropertyChanged: inconsistentcy!" );
326 : // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
327 :
328 0 : switch ( nActuatingPropId )
329 : {
330 : case PROPERTY_ID_XFORMS_BUTTONTYPE:
331 : {
332 0 : FormButtonType eType = FormButtonType_PUSH;
333 0 : OSL_VERIFY( _rNewValue >>= eType );
334 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_SUBMISSION_ID, eType == FormButtonType_SUBMIT );
335 : }
336 0 : break;
337 :
338 : default:
339 : OSL_FAIL( "SubmissionPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
340 0 : }
341 0 : }
342 :
343 :
344 0 : Any SAL_CALL SubmissionPropertyHandler::convertToPropertyValue( const OUString& _rPropertyName, const Any& _rControlValue ) throw (UnknownPropertyException, RuntimeException, std::exception)
345 : {
346 0 : ::osl::MutexGuard aGuard( m_aMutex );
347 0 : Any aPropertyValue;
348 :
349 : OSL_ENSURE( m_pHelper.get(), "SubmissionPropertyHandler::convertToPropertyValue: we have no SupportedProperties!" );
350 0 : if ( !m_pHelper.get() )
351 0 : return aPropertyValue;
352 :
353 0 : OUString sControlValue;
354 0 : OSL_VERIFY( _rControlValue >>= sControlValue );
355 :
356 0 : PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) );
357 0 : switch ( nPropId )
358 : {
359 : case PROPERTY_ID_SUBMISSION_ID:
360 : {
361 0 : Reference< XSubmission > xSubmission( m_pHelper->getModelElementFromUIName( EFormsHelper::Submission, sControlValue ), UNO_QUERY );
362 0 : aPropertyValue <<= xSubmission;
363 : }
364 0 : break;
365 :
366 : case PROPERTY_ID_XFORMS_BUTTONTYPE:
367 : {
368 : ::rtl::Reference< IPropertyEnumRepresentation > aEnumConversion(
369 0 : new DefaultEnumRepresentation( *m_pInfoService, ::getCppuType( static_cast< FormButtonType* >( NULL ) ), PROPERTY_ID_BUTTONTYPE ) );
370 : // TODO/UNOize: make aEnumConversion a member?
371 0 : aEnumConversion->getValueFromDescription( sControlValue, aPropertyValue );
372 : }
373 0 : break;
374 :
375 : default:
376 : OSL_FAIL( "SubmissionPropertyHandler::convertToPropertyValue: cannot handle this id!" );
377 : }
378 :
379 0 : return aPropertyValue;
380 : }
381 :
382 :
383 0 : Any SAL_CALL SubmissionPropertyHandler::convertToControlValue( const OUString& _rPropertyName, const Any& _rPropertyValue, const Type& _rControlValueType ) throw (UnknownPropertyException, RuntimeException, std::exception)
384 : {
385 0 : ::osl::MutexGuard aGuard( m_aMutex );
386 0 : Any aControlValue;
387 :
388 : OSL_ENSURE( m_pHelper.get(), "SubmissionPropertyHandler::convertToControlValue: we have no SupportedProperties!" );
389 0 : if ( !m_pHelper.get() )
390 0 : return aControlValue;
391 :
392 : OSL_ENSURE( _rControlValueType.getTypeClass() == TypeClass_STRING,
393 : "SubmissionPropertyHandler::convertToControlValue: all our controls should use strings for value exchange!" );
394 : (void)_rControlValueType;
395 :
396 0 : PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) );
397 0 : switch ( nPropId )
398 : {
399 : case PROPERTY_ID_SUBMISSION_ID:
400 : {
401 0 : Reference< XPropertySet > xSubmission( _rPropertyValue, UNO_QUERY );
402 0 : if ( xSubmission.is() )
403 0 : aControlValue <<= m_pHelper->getModelElementUIName( EFormsHelper::Submission, xSubmission );
404 : }
405 0 : break;
406 :
407 : case PROPERTY_ID_XFORMS_BUTTONTYPE:
408 : {
409 : ::rtl::Reference< IPropertyEnumRepresentation > aEnumConversion(
410 0 : new DefaultEnumRepresentation( *m_pInfoService, _rPropertyValue.getValueType(), PROPERTY_ID_BUTTONTYPE ) );
411 : // TODO/UNOize: make aEnumConversion a member?
412 0 : aControlValue <<= aEnumConversion->getDescriptionForValue( _rPropertyValue );
413 : }
414 0 : break;
415 :
416 : default:
417 : OSL_FAIL( "SubmissionPropertyHandler::convertToControlValue: cannot handle this id!" );
418 : }
419 :
420 0 : return aControlValue;
421 : }
422 :
423 :
424 0 : void SubmissionPropertyHandler::_propertyChanged( const PropertyChangeEvent& _rEvent ) throw(RuntimeException)
425 : {
426 0 : if ( _rEvent.PropertyName == PROPERTY_BUTTONTYPE )
427 0 : firePropertyChange( PROPERTY_XFORMS_BUTTONTYPE, PROPERTY_ID_XFORMS_BUTTONTYPE, _rEvent.OldValue, _rEvent.NewValue );
428 0 : }
429 :
430 :
431 : } // namespace pcr
432 :
433 :
434 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|