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 "eformspropertyhandler.hxx"
21 : #include "formstrings.hxx"
22 : #include "formmetadata.hxx"
23 : #include "propctrlr.hrc"
24 : #include "formbrowsertools.hxx"
25 : #include "eformshelper.hxx"
26 : #include "handlerhelper.hxx"
27 :
28 : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
29 : #include <com/sun/star/inspection/PropertyControlType.hpp>
30 : #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
31 : #include <tools/debug.hxx>
32 :
33 : #include <functional>
34 :
35 :
36 0 : extern "C" void SAL_CALL createRegistryInfo_EFormsPropertyHandler()
37 : {
38 0 : ::pcr::EFormsPropertyHandler::registerImplementation();
39 0 : }
40 :
41 :
42 : namespace pcr
43 : {
44 :
45 :
46 : using namespace ::com::sun::star;
47 : using namespace ::com::sun::star::uno;
48 : using namespace ::com::sun::star::lang;
49 : using namespace ::com::sun::star::beans;
50 : using namespace ::com::sun::star::xforms;
51 : using namespace ::com::sun::star::script;
52 : using namespace ::com::sun::star::ui::dialogs;
53 : using namespace ::com::sun::star::form::binding;
54 : using namespace ::com::sun::star::inspection;
55 :
56 :
57 : //= EFormsPropertyHandler
58 :
59 :
60 0 : EFormsPropertyHandler::EFormsPropertyHandler( const Reference< XComponentContext >& _rxContext )
61 : :EFormsPropertyHandler_Base( _rxContext )
62 0 : ,m_bSimulatingModelChange( false )
63 : {
64 0 : }
65 :
66 :
67 0 : EFormsPropertyHandler::~EFormsPropertyHandler( )
68 : {
69 0 : }
70 :
71 :
72 0 : OUString SAL_CALL EFormsPropertyHandler::getImplementationName_static( ) throw (RuntimeException)
73 : {
74 0 : return OUString( "com.sun.star.comp.extensions.EFormsPropertyHandler" );
75 : }
76 :
77 :
78 0 : Sequence< OUString > SAL_CALL EFormsPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException)
79 : {
80 0 : Sequence< OUString > aSupported( 1 );
81 0 : aSupported[0] = "com.sun.star.form.inspection.XMLFormsPropertyHandler";
82 0 : return aSupported;
83 : }
84 :
85 :
86 0 : OUString EFormsPropertyHandler::getModelNamePropertyValue() const
87 : {
88 0 : OUString sModelName = m_pHelper->getCurrentFormModelName();
89 0 : if ( sModelName.isEmpty() )
90 0 : sModelName = m_sBindingLessModelName;
91 0 : return sModelName;
92 : }
93 :
94 :
95 0 : Any SAL_CALL EFormsPropertyHandler::getPropertyValue( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException, std::exception)
96 : {
97 0 : ::osl::MutexGuard aGuard( m_aMutex );
98 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
99 :
100 : OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::getPropertyValue: we don't have any SupportedProperties!" );
101 : // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
102 :
103 0 : Any aReturn;
104 : try
105 : {
106 0 : switch ( nPropId )
107 : {
108 : case PROPERTY_ID_LIST_BINDING:
109 0 : aReturn <<= m_pHelper->getCurrentListSourceBinding();
110 0 : break;
111 :
112 : case PROPERTY_ID_XML_DATA_MODEL:
113 0 : aReturn <<= getModelNamePropertyValue();
114 0 : break;
115 :
116 : case PROPERTY_ID_BINDING_NAME:
117 0 : aReturn <<= m_pHelper->getCurrentBindingName();
118 0 : break;
119 :
120 : case PROPERTY_ID_BIND_EXPRESSION:
121 : case PROPERTY_ID_XSD_CONSTRAINT:
122 : case PROPERTY_ID_XSD_CALCULATION:
123 : case PROPERTY_ID_XSD_REQUIRED:
124 : case PROPERTY_ID_XSD_RELEVANT:
125 : case PROPERTY_ID_XSD_READONLY:
126 : {
127 0 : Reference< XPropertySet > xBindingProps( m_pHelper->getCurrentBinding() );
128 0 : if ( xBindingProps.is() )
129 : {
130 0 : aReturn = xBindingProps->getPropertyValue( _rPropertyName );
131 : DBG_ASSERT( aReturn.getValueType().equals( ::getCppuType( static_cast< OUString* >( NULL ) ) ),
132 : "EFormsPropertyHandler::getPropertyValue: invalid BindingExpression value type!" );
133 : }
134 : else
135 0 : aReturn <<= OUString();
136 : }
137 0 : break;
138 :
139 : default:
140 : OSL_FAIL( "EFormsPropertyHandler::getPropertyValue: cannot handle this property!" );
141 0 : break;
142 : }
143 : }
144 0 : catch( const Exception& )
145 : {
146 : #if OSL_DEBUG_LEVEL > 0
147 : OString sMessage( "EFormsPropertyHandler::getPropertyValue: caught an exception!" );
148 : sMessage += "\n(have been asked for the \"";
149 : sMessage += OString( _rPropertyName.getStr(), _rPropertyName.getLength(), RTL_TEXTENCODING_ASCII_US );
150 : sMessage += "\" property.)";
151 : OSL_FAIL( sMessage.getStr() );
152 : #endif
153 : }
154 0 : return aReturn;
155 : }
156 :
157 :
158 0 : void SAL_CALL EFormsPropertyHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException, std::exception)
159 : {
160 0 : ::osl::MutexGuard aGuard( m_aMutex );
161 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
162 :
163 : OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::setPropertyValue: we don't have any SupportedProperties!" );
164 : // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
165 :
166 : try
167 : {
168 0 : Any aOldValue = getPropertyValue( _rPropertyName );
169 :
170 0 : switch ( nPropId )
171 : {
172 : case PROPERTY_ID_LIST_BINDING:
173 : {
174 0 : Reference< XListEntrySource > xSource;
175 0 : OSL_VERIFY( _rValue >>= xSource );
176 0 : m_pHelper->setListSourceBinding( xSource );
177 : }
178 0 : break;
179 :
180 : case PROPERTY_ID_XML_DATA_MODEL:
181 : {
182 0 : OSL_VERIFY( _rValue >>= m_sBindingLessModelName );
183 :
184 : // if the model changed, reset the binding to NULL
185 0 : if ( m_pHelper->getCurrentFormModelName() != m_sBindingLessModelName )
186 : {
187 0 : OUString sOldBindingName = m_pHelper->getCurrentBindingName();
188 0 : m_pHelper->setBinding( NULL );
189 : firePropertyChange( PROPERTY_BINDING_NAME, PROPERTY_ID_BINDING_NAME,
190 0 : makeAny( sOldBindingName ), makeAny( OUString() ) );
191 : }
192 : }
193 0 : break;
194 :
195 : case PROPERTY_ID_BINDING_NAME:
196 : {
197 0 : OUString sNewBindingName;
198 0 : OSL_VERIFY( _rValue >>= sNewBindingName );
199 :
200 0 : bool bPreviouslyEmptyModel = !m_pHelper->getCurrentFormModel().is();
201 :
202 0 : Reference< XPropertySet > xNewBinding;
203 0 : if ( !sNewBindingName.isEmpty() )
204 : // obtain the binding with this name, for the current model
205 0 : xNewBinding = m_pHelper->getOrCreateBindingForModel( getModelNamePropertyValue(), sNewBindingName );
206 :
207 0 : m_pHelper->setBinding( xNewBinding );
208 :
209 0 : if ( bPreviouslyEmptyModel )
210 : { // simulate a property change for the model property
211 : // This is because we "simulate" the Model property by remembering the
212 : // value ourself. Other instances might, however, not know this value,
213 : // but prefer to retrieve it somewhere else - e.g. from the EFormsHelper
214 :
215 : // The really correct solution would be if *all* property handlers
216 : // obtain a "current property value" for *all* properties from a central
217 : // instance. Then, handler A could ask it for the value of property
218 : // X, and this request would be re-routed to handler B, which ultimately
219 : // knows the current value.
220 : // However, there's no such mechanism in place currently.
221 0 : m_bSimulatingModelChange = true;
222 : firePropertyChange( PROPERTY_XML_DATA_MODEL, PROPERTY_ID_XML_DATA_MODEL,
223 0 : makeAny( OUString() ), makeAny( getModelNamePropertyValue() ) );
224 0 : m_bSimulatingModelChange = false;
225 0 : }
226 : }
227 0 : break;
228 :
229 : case PROPERTY_ID_BIND_EXPRESSION:
230 : {
231 0 : Reference< XPropertySet > xBinding( m_pHelper->getCurrentBinding() );
232 : OSL_ENSURE( xBinding.is(), "You should not reach this without an active binding!" );
233 0 : if ( xBinding.is() )
234 0 : xBinding->setPropertyValue( PROPERTY_BIND_EXPRESSION, _rValue );
235 : }
236 0 : break;
237 :
238 : case PROPERTY_ID_XSD_REQUIRED:
239 : case PROPERTY_ID_XSD_RELEVANT:
240 : case PROPERTY_ID_XSD_READONLY:
241 : case PROPERTY_ID_XSD_CONSTRAINT:
242 : case PROPERTY_ID_XSD_CALCULATION:
243 : {
244 0 : Reference< XPropertySet > xBindingProps( m_pHelper->getCurrentBinding() );
245 : DBG_ASSERT( xBindingProps.is(), "EFormsPropertyHandler::setPropertyValue: how can I set a property if there's no binding?" );
246 0 : if ( xBindingProps.is() )
247 : {
248 : DBG_ASSERT( _rValue.getValueType().equals( ::getCppuType( static_cast< OUString* >( NULL ) ) ),
249 : "EFormsPropertyHandler::setPropertyValue: invalid value type!" );
250 0 : xBindingProps->setPropertyValue( _rPropertyName, _rValue );
251 0 : }
252 : }
253 0 : break;
254 :
255 : default:
256 : OSL_FAIL( "EFormsPropertyHandler::setPropertyValue: cannot handle this property!" );
257 0 : break;
258 : }
259 :
260 0 : impl_setContextDocumentModified_nothrow();
261 :
262 0 : Any aNewValue( getPropertyValue( _rPropertyName ) );
263 0 : firePropertyChange( _rPropertyName, nPropId, aOldValue, aNewValue );
264 : }
265 0 : catch( const Exception& )
266 : {
267 : OSL_FAIL( "EFormsPropertyHandler::setPropertyValue: caught an exception!" );
268 0 : }
269 0 : }
270 :
271 :
272 0 : void EFormsPropertyHandler::onNewComponent()
273 : {
274 0 : EFormsPropertyHandler_Base::onNewComponent();
275 :
276 0 : Reference< frame::XModel > xDocument( impl_getContextDocument_nothrow() );
277 : DBG_ASSERT( xDocument.is(), "EFormsPropertyHandler::onNewComponent: no document!" );
278 0 : if ( EFormsHelper::isEForm( xDocument ) )
279 0 : m_pHelper.reset( new EFormsHelper( m_aMutex, m_xComponent, xDocument ) );
280 : else
281 0 : m_pHelper.reset();
282 0 : }
283 :
284 :
285 0 : Sequence< Property > SAL_CALL EFormsPropertyHandler::doDescribeSupportedProperties() const
286 : {
287 0 : ::std::vector< Property > aProperties;
288 :
289 0 : if ( m_pHelper.get() )
290 : {
291 0 : if ( m_pHelper->canBindToAnyDataType() )
292 : {
293 0 : aProperties.reserve( 7 );
294 0 : addStringPropertyDescription( aProperties, PROPERTY_XML_DATA_MODEL );
295 0 : addStringPropertyDescription( aProperties, PROPERTY_BINDING_NAME );
296 0 : addStringPropertyDescription( aProperties, PROPERTY_BIND_EXPRESSION );
297 0 : addStringPropertyDescription( aProperties, PROPERTY_XSD_REQUIRED );
298 0 : addStringPropertyDescription( aProperties, PROPERTY_XSD_RELEVANT );
299 0 : addStringPropertyDescription( aProperties, PROPERTY_XSD_READONLY );
300 0 : addStringPropertyDescription( aProperties, PROPERTY_XSD_CONSTRAINT );
301 0 : addStringPropertyDescription( aProperties, PROPERTY_XSD_CALCULATION );
302 : }
303 0 : if ( m_pHelper->isListEntrySink() )
304 : {
305 : implAddPropertyDescription( aProperties, PROPERTY_LIST_BINDING,
306 0 : ::getCppuType( static_cast< Reference< XListEntrySource > * >( NULL ) ) );
307 : }
308 : }
309 :
310 0 : if ( aProperties.empty() )
311 0 : return Sequence< Property >();
312 0 : return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
313 : }
314 :
315 :
316 0 : Any SAL_CALL EFormsPropertyHandler::convertToPropertyValue( const OUString& _rPropertyName, const Any& _rControlValue ) throw (UnknownPropertyException, RuntimeException, std::exception)
317 : {
318 0 : ::osl::MutexGuard aGuard( m_aMutex );
319 0 : Any aReturn;
320 :
321 : OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::convertToPropertyValue: we have no SupportedProperties!" );
322 0 : if ( !m_pHelper.get() )
323 0 : return aReturn;
324 :
325 0 : PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) );
326 :
327 0 : OUString sControlValue;
328 0 : switch ( nPropId )
329 : {
330 : case PROPERTY_ID_LIST_BINDING:
331 : {
332 0 : OSL_VERIFY( _rControlValue >>= sControlValue );
333 0 : Reference< XListEntrySource > xListSource( m_pHelper->getModelElementFromUIName( EFormsHelper::Binding, sControlValue ), UNO_QUERY );
334 : OSL_ENSURE( xListSource.is() || !m_pHelper->getModelElementFromUIName( EFormsHelper::Binding, sControlValue ).is(),
335 : "EFormsPropertyHandler::convertToPropertyValue: there's a binding which is no ListEntrySource!" );
336 0 : aReturn <<= xListSource;
337 : }
338 0 : break;
339 :
340 : default:
341 0 : aReturn = EFormsPropertyHandler_Base::convertToPropertyValue( _rPropertyName, _rControlValue );
342 0 : break;
343 : }
344 :
345 0 : return aReturn;
346 : }
347 :
348 :
349 0 : Any SAL_CALL EFormsPropertyHandler::convertToControlValue( const OUString& _rPropertyName, const Any& _rPropertyValue, const Type& _rControlValueType ) throw (UnknownPropertyException, RuntimeException, std::exception)
350 : {
351 0 : ::osl::MutexGuard aGuard( m_aMutex );
352 0 : Any aReturn;
353 :
354 : OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::convertToControlValue: we have no SupportedProperties!" );
355 0 : if ( !m_pHelper.get() )
356 0 : return aReturn;
357 :
358 0 : PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) );
359 :
360 : OSL_ENSURE( _rControlValueType.getTypeClass() == TypeClass_STRING,
361 : "EFormsPropertyHandler::convertToControlValue: all our controls should use strings for value exchange!" );
362 :
363 0 : switch ( nPropId )
364 : {
365 : case PROPERTY_ID_LIST_BINDING:
366 : {
367 0 : Reference< XPropertySet > xListSourceBinding( _rPropertyValue, UNO_QUERY );
368 0 : if ( xListSourceBinding.is() )
369 0 : aReturn <<= m_pHelper->getModelElementUIName( EFormsHelper::Binding, xListSourceBinding );
370 : }
371 0 : break;
372 :
373 : default:
374 0 : aReturn = EFormsPropertyHandler_Base::convertToControlValue( _rPropertyName, _rPropertyValue, _rControlValueType );
375 0 : break;
376 : }
377 :
378 0 : return aReturn;
379 : }
380 :
381 :
382 0 : Sequence< OUString > SAL_CALL EFormsPropertyHandler::getActuatingProperties( ) throw (RuntimeException, std::exception)
383 : {
384 0 : ::osl::MutexGuard aGuard( m_aMutex );
385 0 : if ( !m_pHelper.get() )
386 0 : return Sequence< OUString >();
387 :
388 0 : ::std::vector< OUString > aInterestedInActuations( 2 );
389 0 : aInterestedInActuations[ 0 ] = PROPERTY_XML_DATA_MODEL;
390 0 : aInterestedInActuations[ 1 ] = PROPERTY_BINDING_NAME;
391 0 : return Sequence< OUString >( &(*aInterestedInActuations.begin()), aInterestedInActuations.size() );
392 : }
393 :
394 :
395 0 : Sequence< OUString > SAL_CALL EFormsPropertyHandler::getSupersededProperties( ) throw (RuntimeException, std::exception)
396 : {
397 0 : ::osl::MutexGuard aGuard( m_aMutex );
398 0 : if ( !m_pHelper.get() )
399 0 : return Sequence< OUString >();
400 :
401 0 : Sequence< OUString > aReturn( 1 );
402 0 : aReturn[ 0 ] = PROPERTY_INPUT_REQUIRED;
403 0 : return aReturn;
404 : }
405 :
406 :
407 0 : LineDescriptor SAL_CALL EFormsPropertyHandler::describePropertyLine( const OUString& _rPropertyName,
408 : const Reference< XPropertyControlFactory >& _rxControlFactory )
409 : throw (UnknownPropertyException, NullPointerException, RuntimeException, std::exception)
410 : {
411 0 : ::osl::MutexGuard aGuard( m_aMutex );
412 0 : if ( !_rxControlFactory.is() )
413 0 : throw NullPointerException();
414 0 : if ( !m_pHelper.get() )
415 0 : throw RuntimeException();
416 :
417 0 : LineDescriptor aDescriptor;
418 0 : sal_Int16 nControlType = PropertyControlType::TextField;
419 0 : ::std::vector< OUString > aListEntries;
420 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
421 0 : switch ( nPropId )
422 : {
423 : case PROPERTY_ID_LIST_BINDING:
424 0 : nControlType = PropertyControlType::ListBox;
425 0 : const_cast< EFormsHelper* >( m_pHelper.get() )->getAllElementUINames( EFormsHelper::Binding, aListEntries, true );
426 0 : break;
427 :
428 : case PROPERTY_ID_XML_DATA_MODEL:
429 0 : nControlType = PropertyControlType::ListBox;
430 0 : m_pHelper->getFormModelNames( aListEntries );
431 0 : break;
432 :
433 : case PROPERTY_ID_BINDING_NAME:
434 : {
435 0 : nControlType = PropertyControlType::ComboBox;
436 0 : OUString sCurrentModel( getModelNamePropertyValue() );
437 0 : if ( !sCurrentModel.isEmpty() )
438 0 : m_pHelper->getBindingNames( sCurrentModel, aListEntries );
439 : }
440 0 : break;
441 :
442 0 : case PROPERTY_ID_BIND_EXPRESSION: aDescriptor.PrimaryButtonId = OUString::createFromAscii(UID_PROP_DLG_BIND_EXPRESSION); break;
443 0 : case PROPERTY_ID_XSD_REQUIRED: aDescriptor.PrimaryButtonId = OUString::createFromAscii(UID_PROP_DLG_XSD_REQUIRED); break;
444 0 : case PROPERTY_ID_XSD_RELEVANT: aDescriptor.PrimaryButtonId = OUString::createFromAscii(UID_PROP_DLG_XSD_RELEVANT); break;
445 0 : case PROPERTY_ID_XSD_READONLY: aDescriptor.PrimaryButtonId = OUString::createFromAscii(UID_PROP_DLG_XSD_READONLY); break;
446 0 : case PROPERTY_ID_XSD_CONSTRAINT: aDescriptor.PrimaryButtonId = OUString::createFromAscii(UID_PROP_DLG_XSD_CONSTRAINT); break;
447 0 : case PROPERTY_ID_XSD_CALCULATION: aDescriptor.PrimaryButtonId = OUString::createFromAscii(UID_PROP_DLG_XSD_CALCULATION); break;
448 :
449 : default:
450 : OSL_FAIL( "EFormsPropertyHandler::describePropertyLine: cannot handle this property!" );
451 0 : break;
452 : }
453 :
454 0 : switch ( nControlType )
455 : {
456 : case PropertyControlType::ListBox:
457 0 : aDescriptor.Control = PropertyHandlerHelper::createListBoxControl( _rxControlFactory, aListEntries, sal_False, sal_True );
458 0 : break;
459 : case PropertyControlType::ComboBox:
460 0 : aDescriptor.Control = PropertyHandlerHelper::createComboBoxControl( _rxControlFactory, aListEntries, sal_False, sal_True );
461 0 : break;
462 : default:
463 0 : aDescriptor.Control = _rxControlFactory->createPropertyControl( nControlType, sal_False );
464 0 : break;
465 : }
466 :
467 0 : aDescriptor.DisplayName = m_pInfoService->getPropertyTranslation( nPropId );
468 0 : aDescriptor.Category = "Data";
469 0 : aDescriptor.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nPropId ) );
470 0 : return aDescriptor;
471 : }
472 :
473 :
474 0 : InteractiveSelectionResult SAL_CALL EFormsPropertyHandler::onInteractivePropertySelection( const OUString& _rPropertyName, sal_Bool /*_bPrimary*/, Any& _rData, const Reference< XObjectInspectorUI >& _rxInspectorUI ) throw (UnknownPropertyException, NullPointerException, RuntimeException, std::exception)
475 : {
476 0 : if ( !_rxInspectorUI.is() )
477 0 : throw NullPointerException();
478 :
479 0 : ::osl::MutexGuard aGuard( m_aMutex );
480 : OSL_ENSURE( m_pHelper.get(), "EFormsPropertyHandler::onInteractivePropertySelection: we do not have any SupportedProperties!" );
481 0 : if ( !m_pHelper.get() )
482 0 : return InteractiveSelectionResult_Cancelled;
483 :
484 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
485 : (void)nPropId;
486 : OSL_ENSURE( ( PROPERTY_ID_BINDING_NAME == nPropId )
487 : || ( PROPERTY_ID_BIND_EXPRESSION == nPropId )
488 : || ( PROPERTY_ID_XSD_REQUIRED == nPropId )
489 : || ( PROPERTY_ID_XSD_RELEVANT == nPropId )
490 : || ( PROPERTY_ID_XSD_READONLY == nPropId )
491 : || ( PROPERTY_ID_XSD_CONSTRAINT == nPropId )
492 : || ( PROPERTY_ID_XSD_CALCULATION == nPropId ), "EFormsPropertyHandler::onInteractivePropertySelection: unexpected!" );
493 :
494 : try
495 : {
496 0 : Reference< XExecutableDialog > xDialog;
497 0 : xDialog.set( m_xContext->getServiceManager()->createInstanceWithContext( "com.sun.star.xforms.ui.dialogs.AddCondition", m_xContext ), UNO_QUERY );
498 0 : Reference< XPropertySet > xDialogProps( xDialog, UNO_QUERY_THROW );
499 :
500 : // the model for the dialog to work with
501 0 : Reference< xforms::XModel > xModel( m_pHelper->getCurrentFormModel() );
502 : // the binding for the dialog to work with
503 0 : Reference< XPropertySet > xBinding( m_pHelper->getCurrentBinding() );
504 : // the aspect of the binding which the dialog should modify
505 0 : OUString sFacetName( _rPropertyName );
506 :
507 : OSL_ENSURE( xModel.is() && xBinding.is() && !sFacetName.isEmpty(),
508 : "EFormsPropertyHandler::onInteractivePropertySelection: something is missing for the dialog initialization!" );
509 0 : if ( !( xModel.is() && xBinding.is() && !sFacetName.isEmpty() ) )
510 0 : return InteractiveSelectionResult_Cancelled;
511 :
512 0 : xDialogProps->setPropertyValue("FormModel", makeAny( xModel ) );
513 0 : xDialogProps->setPropertyValue("Binding", makeAny( xBinding ) );
514 0 : xDialogProps->setPropertyValue("FacetName", makeAny( sFacetName ) );
515 :
516 0 : if ( !xDialog->execute() )
517 : // cancelled
518 0 : return InteractiveSelectionResult_Cancelled;
519 :
520 0 : _rData = xDialogProps->getPropertyValue("ConditionValue");
521 0 : return InteractiveSelectionResult_ObtainedValue;
522 : }
523 0 : catch( const Exception& )
524 : {
525 : OSL_FAIL( "EFormsPropertyHandler::onInteractivePropertySelection: caught an exception!" );
526 : }
527 :
528 : // something went wrong here ...(but has been asserted already)
529 0 : return InteractiveSelectionResult_Cancelled;
530 : }
531 :
532 :
533 0 : void SAL_CALL EFormsPropertyHandler::addPropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (NullPointerException, RuntimeException, std::exception)
534 : {
535 0 : ::osl::MutexGuard aGuard( m_aMutex );
536 0 : EFormsPropertyHandler_Base::addPropertyChangeListener( _rxListener );
537 0 : if ( m_pHelper.get() )
538 0 : m_pHelper->registerBindingListener( _rxListener );
539 0 : }
540 :
541 :
542 0 : void SAL_CALL EFormsPropertyHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener ) throw (RuntimeException, std::exception)
543 : {
544 0 : ::osl::MutexGuard aGuard( m_aMutex );
545 0 : if ( m_pHelper.get() )
546 0 : m_pHelper->revokeBindingListener( _rxListener );
547 0 : EFormsPropertyHandler_Base::removePropertyChangeListener( _rxListener );
548 0 : }
549 :
550 :
551 0 : void SAL_CALL EFormsPropertyHandler::actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool ) throw (NullPointerException, RuntimeException, std::exception)
552 : {
553 0 : if ( !_rxInspectorUI.is() )
554 0 : throw NullPointerException();
555 :
556 0 : ::osl::MutexGuard aGuard( m_aMutex );
557 0 : PropertyId nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
558 : OSL_PRECOND( m_pHelper.get(), "EFormsPropertyHandler::actuatingPropertyChanged: inconsistentcy!" );
559 : // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
560 :
561 : DBG_ASSERT( _rxInspectorUI.is(), "EFormsPropertyHandler::actuatingPropertyChanged: invalid callback!" );
562 0 : if ( !_rxInspectorUI.is() )
563 0 : return;
564 :
565 0 : switch ( nActuatingPropId )
566 : {
567 : case PROPERTY_ID_XML_DATA_MODEL:
568 : {
569 0 : if ( m_bSimulatingModelChange )
570 0 : break;
571 0 : OUString sDataModelName;
572 0 : OSL_VERIFY( _rNewValue >>= sDataModelName );
573 0 : sal_Bool bBoundToSomeModel = !sDataModelName.isEmpty();
574 0 : _rxInspectorUI->rebuildPropertyUI( PROPERTY_BINDING_NAME );
575 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_BINDING_NAME, bBoundToSomeModel );
576 : }
577 : // NO break
578 :
579 : case PROPERTY_ID_BINDING_NAME:
580 : {
581 0 : sal_Bool bHaveABinding = !m_pHelper->getCurrentBindingName().isEmpty();
582 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_BIND_EXPRESSION, bHaveABinding );
583 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_REQUIRED, bHaveABinding );
584 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_RELEVANT, bHaveABinding );
585 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_READONLY, bHaveABinding );
586 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_CONSTRAINT, bHaveABinding );
587 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_CALCULATION, bHaveABinding );
588 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_XSD_DATA_TYPE, bHaveABinding );
589 : }
590 0 : break;
591 :
592 : default:
593 : OSL_FAIL( "EFormsPropertyHandler::actuatingPropertyChanged: cannot handle this property!" );
594 0 : break;
595 0 : }
596 : }
597 :
598 :
599 : } // namespace pcr
600 :
601 :
602 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|