Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / propctrlr / xsdvalidationpropertyhandler.cxx
blob0ead90425b6169d4bb94e1a347b040c106df5861
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include "pcrservices.hxx"
23 #include "xsdvalidationpropertyhandler.hxx"
24 #include "formstrings.hxx"
25 #include "formmetadata.hxx"
26 #include "xsddatatypes.hxx"
27 #include "modulepcr.hxx"
28 #include <strings.hrc>
29 #include <propctrlr.h>
30 #include "newdatatype.hxx"
31 #include "xsdvalidationhelper.hxx"
32 #include "pcrcommon.hxx"
33 #include "handlerhelper.hxx"
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include <com/sun/star/lang/NullPointerException.hpp>
37 #include <com/sun/star/xsd/WhiteSpaceTreatment.hpp>
38 #include <com/sun/star/xsd/DataTypeClass.hpp>
39 #include <com/sun/star/inspection/PropertyControlType.hpp>
40 #include <com/sun/star/beans/Optional.hpp>
41 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
42 #include <com/sun/star/inspection/PropertyLineElement.hpp>
43 #include <vcl/svapp.hxx>
44 #include <vcl/weld.hxx>
45 #include <tools/debug.hxx>
46 #include <sal/macros.h>
48 #include <algorithm>
49 #include <functional>
50 #include <limits>
53 extern "C" void createRegistryInfo_XSDValidationPropertyHandler()
55 ::pcr::XSDValidationPropertyHandler::registerImplementation();
59 namespace pcr
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::lang;
66 using namespace ::com::sun::star::beans;
67 using namespace ::com::sun::star::xforms;
68 using namespace ::com::sun::star::xsd;
69 using namespace ::com::sun::star::script;
70 using namespace ::com::sun::star::inspection;
72 using ::com::sun::star::beans::PropertyAttribute::MAYBEVOID;
75 //= XSDValidationPropertyHandler
77 XSDValidationPropertyHandler::XSDValidationPropertyHandler( const Reference< XComponentContext >& _rxContext )
78 :XSDValidationPropertyHandler_Base( _rxContext )
83 XSDValidationPropertyHandler::~XSDValidationPropertyHandler()
88 OUString XSDValidationPropertyHandler::getImplementationName_static( )
90 return "com.sun.star.comp.extensions.XSDValidationPropertyHandler";
94 Sequence< OUString > XSDValidationPropertyHandler::getSupportedServiceNames_static( )
96 Sequence<OUString> aSupported { "com.sun.star.form.inspection.XSDValidationPropertyHandler" };
97 return aSupported;
101 Any SAL_CALL XSDValidationPropertyHandler::getPropertyValue( const OUString& _rPropertyName )
103 ::osl::MutexGuard aGuard( m_aMutex );
104 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
106 OSL_ENSURE(m_pHelper, "XSDValidationPropertyHandler::getPropertyValue: inconsistency!");
107 // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
109 Any aReturn;
110 ::rtl::Reference< XSDDataType > pType = m_pHelper->getValidatingDataType();
111 switch ( nPropId )
113 // common facets
114 case PROPERTY_ID_XSD_DATA_TYPE: aReturn = pType.is() ? pType->getFacet( PROPERTY_NAME ) : makeAny( OUString() ); break;
115 case PROPERTY_ID_XSD_WHITESPACES:aReturn = pType.is() ? pType->getFacet( PROPERTY_XSD_WHITESPACES ) : makeAny( WhiteSpaceTreatment::Preserve ); break;
116 case PROPERTY_ID_XSD_PATTERN: aReturn = pType.is() ? pType->getFacet( PROPERTY_XSD_PATTERN ) : makeAny( OUString() ); break;
118 // all other properties are simply forwarded, if they exist at the given type
119 default:
121 if ( pType.is() && pType->hasFacet( _rPropertyName ) )
122 aReturn = pType->getFacet( _rPropertyName );
124 break;
127 return aReturn;
131 void SAL_CALL XSDValidationPropertyHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue )
133 ::osl::MutexGuard aGuard( m_aMutex );
134 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
136 OSL_ENSURE(m_pHelper, "XSDValidationPropertyHandler::getPropertyValue: inconsistency!");
137 // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
139 if ( PROPERTY_ID_XSD_DATA_TYPE == nPropId )
141 OUString sTypeName;
142 OSL_VERIFY( _rValue >>= sTypeName );
143 m_pHelper->setValidatingDataTypeByName( sTypeName );
144 impl_setContextDocumentModified_nothrow();
145 return;
148 ::rtl::Reference< XSDDataType > pType = m_pHelper->getValidatingDataType();
149 if ( !pType.is() )
151 OSL_FAIL( "XSDValidationPropertyHandler::setPropertyValue: you're trying to set a type facet, without a current type!" );
152 return;
155 pType->setFacet( _rPropertyName, _rValue );
156 impl_setContextDocumentModified_nothrow();
160 void XSDValidationPropertyHandler::onNewComponent()
162 XSDValidationPropertyHandler_Base::onNewComponent();
164 Reference< frame::XModel > xDocument( impl_getContextDocument_nothrow() );
165 DBG_ASSERT( xDocument.is(), "XSDValidationPropertyHandler::onNewComponent: no document!" );
166 if ( EFormsHelper::isEForm( xDocument ) )
167 m_pHelper.reset( new XSDValidationHelper( m_aMutex, m_xComponent, xDocument ) );
168 else
169 m_pHelper.reset();
173 Sequence< Property > XSDValidationPropertyHandler::doDescribeSupportedProperties() const
175 std::vector< Property > aProperties;
177 if (m_pHelper)
179 bool bAllowBinding = m_pHelper->canBindToAnyDataType();
181 if ( bAllowBinding )
183 aProperties.reserve( 12 );
185 addStringPropertyDescription( aProperties, PROPERTY_XSD_DATA_TYPE );
186 addInt16PropertyDescription ( aProperties, PROPERTY_XSD_WHITESPACES );
187 addStringPropertyDescription( aProperties, PROPERTY_XSD_PATTERN );
189 // string facets
190 addInt32PropertyDescription( aProperties, PROPERTY_XSD_LENGTH, MAYBEVOID );
191 addInt32PropertyDescription( aProperties, PROPERTY_XSD_MIN_LENGTH, MAYBEVOID );
192 addInt32PropertyDescription( aProperties, PROPERTY_XSD_MAX_LENGTH, MAYBEVOID );
194 // decimal facets
195 addInt32PropertyDescription( aProperties, PROPERTY_XSD_TOTAL_DIGITS, MAYBEVOID );
196 addInt32PropertyDescription( aProperties, PROPERTY_XSD_FRACTION_DIGITS, MAYBEVOID );
198 // facets for different types
199 addInt16PropertyDescription( aProperties, PROPERTY_XSD_MAX_INCLUSIVE_INT, MAYBEVOID );
200 addInt16PropertyDescription( aProperties, PROPERTY_XSD_MAX_EXCLUSIVE_INT, MAYBEVOID );
201 addInt16PropertyDescription( aProperties, PROPERTY_XSD_MIN_INCLUSIVE_INT, MAYBEVOID );
202 addInt16PropertyDescription( aProperties, PROPERTY_XSD_MIN_EXCLUSIVE_INT, MAYBEVOID );
203 addDoublePropertyDescription( aProperties, PROPERTY_XSD_MAX_INCLUSIVE_DOUBLE, MAYBEVOID );
204 addDoublePropertyDescription( aProperties, PROPERTY_XSD_MAX_EXCLUSIVE_DOUBLE, MAYBEVOID );
205 addDoublePropertyDescription( aProperties, PROPERTY_XSD_MIN_INCLUSIVE_DOUBLE, MAYBEVOID );
206 addDoublePropertyDescription( aProperties, PROPERTY_XSD_MIN_EXCLUSIVE_DOUBLE, MAYBEVOID );
207 addDatePropertyDescription( aProperties, PROPERTY_XSD_MAX_INCLUSIVE_DATE, MAYBEVOID );
208 addDatePropertyDescription( aProperties, PROPERTY_XSD_MAX_EXCLUSIVE_DATE, MAYBEVOID );
209 addDatePropertyDescription( aProperties, PROPERTY_XSD_MIN_INCLUSIVE_DATE, MAYBEVOID );
210 addDatePropertyDescription( aProperties, PROPERTY_XSD_MIN_EXCLUSIVE_DATE, MAYBEVOID );
211 addTimePropertyDescription( aProperties, PROPERTY_XSD_MAX_INCLUSIVE_TIME, MAYBEVOID );
212 addTimePropertyDescription( aProperties, PROPERTY_XSD_MAX_EXCLUSIVE_TIME, MAYBEVOID );
213 addTimePropertyDescription( aProperties, PROPERTY_XSD_MIN_INCLUSIVE_TIME, MAYBEVOID );
214 addTimePropertyDescription( aProperties, PROPERTY_XSD_MIN_EXCLUSIVE_TIME, MAYBEVOID );
215 addDateTimePropertyDescription( aProperties, PROPERTY_XSD_MAX_INCLUSIVE_DATE_TIME, MAYBEVOID );
216 addDateTimePropertyDescription( aProperties, PROPERTY_XSD_MAX_EXCLUSIVE_DATE_TIME, MAYBEVOID );
217 addDateTimePropertyDescription( aProperties, PROPERTY_XSD_MIN_INCLUSIVE_DATE_TIME, MAYBEVOID );
218 addDateTimePropertyDescription( aProperties, PROPERTY_XSD_MIN_EXCLUSIVE_DATE_TIME, MAYBEVOID );
222 return comphelper::containerToSequence( aProperties );
226 Sequence< OUString > SAL_CALL XSDValidationPropertyHandler::getSupersededProperties( )
228 ::osl::MutexGuard aGuard( m_aMutex );
230 std::vector< OUString > aSuperfluous;
231 if (m_pHelper)
233 aSuperfluous.push_back( OUString(PROPERTY_CONTROLSOURCE) );
234 aSuperfluous.push_back( OUString(PROPERTY_EMPTY_IS_NULL) );
235 aSuperfluous.push_back( OUString(PROPERTY_FILTERPROPOSAL) );
236 aSuperfluous.push_back( OUString(PROPERTY_LISTSOURCETYPE) );
237 aSuperfluous.push_back( OUString(PROPERTY_LISTSOURCE) );
238 aSuperfluous.push_back( OUString(PROPERTY_BOUNDCOLUMN) );
240 bool bAllowBinding = m_pHelper->canBindToAnyDataType();
242 if ( bAllowBinding )
244 aSuperfluous.push_back( OUString(PROPERTY_MAXTEXTLEN) );
245 aSuperfluous.push_back( OUString(PROPERTY_VALUEMIN) );
246 aSuperfluous.push_back( OUString(PROPERTY_VALUEMAX) );
247 aSuperfluous.push_back( OUString(PROPERTY_DECIMAL_ACCURACY) );
248 aSuperfluous.push_back( OUString(PROPERTY_TIMEMIN) );
249 aSuperfluous.push_back( OUString(PROPERTY_TIMEMAX) );
250 aSuperfluous.push_back( OUString(PROPERTY_DATEMIN) );
251 aSuperfluous.push_back( OUString(PROPERTY_DATEMAX) );
252 aSuperfluous.push_back( OUString(PROPERTY_EFFECTIVE_MIN) );
253 aSuperfluous.push_back( OUString(PROPERTY_EFFECTIVE_MAX) );
257 return comphelper::containerToSequence( aSuperfluous );
261 Sequence< OUString > SAL_CALL XSDValidationPropertyHandler::getActuatingProperties( )
263 ::osl::MutexGuard aGuard( m_aMutex );
264 std::vector< OUString > aInterestedInActuations;
265 if (m_pHelper)
267 aInterestedInActuations.push_back( OUString(PROPERTY_XSD_DATA_TYPE) );
268 aInterestedInActuations.push_back( OUString(PROPERTY_XML_DATA_MODEL) );
270 return comphelper::containerToSequence( aInterestedInActuations );
274 namespace
276 void showPropertyUI( const Reference< XObjectInspectorUI >& _rxInspectorUI, const OUString& _rPropertyName, bool _bShow )
278 if ( _bShow )
279 _rxInspectorUI->showPropertyUI( _rPropertyName );
280 else
281 _rxInspectorUI->hidePropertyUI( _rPropertyName );
286 LineDescriptor SAL_CALL XSDValidationPropertyHandler::describePropertyLine( const OUString& _rPropertyName,
287 const Reference< XPropertyControlFactory >& _rxControlFactory )
289 ::osl::MutexGuard aGuard( m_aMutex );
290 if ( !_rxControlFactory.is() )
291 throw NullPointerException();
292 if (!m_pHelper)
293 throw RuntimeException();
295 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
297 LineDescriptor aDescriptor;
298 if ( nPropId != PROPERTY_ID_XSD_DATA_TYPE )
299 aDescriptor.IndentLevel = 1;
301 // collect some information about the to-be-created control
302 sal_Int16 nControlType = PropertyControlType::TextField;
303 std::vector< OUString > aListEntries;
304 Optional< double > aMinValue( false, 0 );
305 Optional< double > aMaxValue( false, 0 );
307 switch ( nPropId )
309 case PROPERTY_ID_XSD_DATA_TYPE:
310 nControlType = PropertyControlType::ListBox;
312 implGetAvailableDataTypeNames( aListEntries );
314 aDescriptor.PrimaryButtonId = UID_PROP_ADD_DATA_TYPE;
315 aDescriptor.SecondaryButtonId = UID_PROP_REMOVE_DATA_TYPE;
316 aDescriptor.HasPrimaryButton = aDescriptor.HasSecondaryButton = true;
317 aDescriptor.PrimaryButtonImageURL = "private:graphicrepository/extensions/res/buttonplus.png";
318 aDescriptor.SecondaryButtonImageURL = "private:graphicrepository/extensions/res/buttonminus.png";
319 break;
321 case PROPERTY_ID_XSD_WHITESPACES:
323 nControlType = PropertyControlType::ListBox;
324 aListEntries = m_pInfoService->getPropertyEnumRepresentations( PROPERTY_ID_XSD_WHITESPACES );
326 break;
328 case PROPERTY_ID_XSD_PATTERN:
329 nControlType = PropertyControlType::TextField;
330 break;
332 case PROPERTY_ID_XSD_LENGTH:
333 case PROPERTY_ID_XSD_MIN_LENGTH:
334 case PROPERTY_ID_XSD_MAX_LENGTH:
335 nControlType = PropertyControlType::NumericField;
336 break;
338 case PROPERTY_ID_XSD_TOTAL_DIGITS:
339 case PROPERTY_ID_XSD_FRACTION_DIGITS:
340 nControlType = PropertyControlType::NumericField;
341 break;
343 case PROPERTY_ID_XSD_MAX_INCLUSIVE_INT:
344 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_INT:
345 case PROPERTY_ID_XSD_MIN_INCLUSIVE_INT:
346 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_INT:
348 nControlType = PropertyControlType::NumericField;
350 // handle limits for various 'INT' types according to
351 // their actual semantics (year, month, day)
353 ::rtl::Reference< XSDDataType > xDataType( m_pHelper->getValidatingDataType() );
354 sal_Int16 nTypeClass = xDataType.is() ? xDataType->classify() : DataTypeClass::STRING;
356 aMinValue.IsPresent = aMaxValue.IsPresent = true;
357 aMinValue.Value = DataTypeClass::gYear == nTypeClass ? 0 : 1;
358 aMaxValue.Value = std::numeric_limits< sal_Int32 >::max();
359 if ( DataTypeClass::gMonth == nTypeClass )
360 aMaxValue.Value = 12;
361 else if ( DataTypeClass::gDay == nTypeClass )
362 aMaxValue.Value = 31;
364 break;
366 case PROPERTY_ID_XSD_MAX_INCLUSIVE_DOUBLE:
367 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DOUBLE:
368 case PROPERTY_ID_XSD_MIN_INCLUSIVE_DOUBLE:
369 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DOUBLE:
370 nControlType = PropertyControlType::NumericField;
371 // TODO/eForms: do we have "auto-digits"?
372 break;
374 case PROPERTY_ID_XSD_MAX_INCLUSIVE_DATE:
375 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DATE:
376 case PROPERTY_ID_XSD_MIN_INCLUSIVE_DATE:
377 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DATE:
378 nControlType = PropertyControlType::DateField;
379 break;
381 case PROPERTY_ID_XSD_MAX_INCLUSIVE_TIME:
382 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_TIME:
383 case PROPERTY_ID_XSD_MIN_INCLUSIVE_TIME:
384 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_TIME:
385 nControlType = PropertyControlType::TimeField;
386 break;
388 case PROPERTY_ID_XSD_MAX_INCLUSIVE_DATE_TIME:
389 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DATE_TIME:
390 case PROPERTY_ID_XSD_MIN_INCLUSIVE_DATE_TIME:
391 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DATE_TIME:
392 nControlType = PropertyControlType::DateTimeField;
393 break;
395 default:
396 OSL_FAIL( "XSDValidationPropertyHandler::describePropertyLine: cannot handle this property!" );
397 break;
400 switch ( nControlType )
402 case PropertyControlType::ListBox:
403 aDescriptor.Control = PropertyHandlerHelper::createListBoxControl( _rxControlFactory, aListEntries, false, false );
404 break;
405 case PropertyControlType::NumericField:
406 aDescriptor.Control = PropertyHandlerHelper::createNumericControl( _rxControlFactory, 0, aMinValue, aMaxValue );
407 break;
408 default:
409 aDescriptor.Control = _rxControlFactory->createPropertyControl( nControlType, false );
410 break;
413 aDescriptor.Category = "Data";
414 aDescriptor.DisplayName = m_pInfoService->getPropertyTranslation( nPropId );
415 aDescriptor.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nPropId ) );
417 return aDescriptor;
421 InteractiveSelectionResult SAL_CALL XSDValidationPropertyHandler::onInteractivePropertySelection( const OUString& _rPropertyName, sal_Bool _bPrimary, Any& /*_rData*/, const Reference< XObjectInspectorUI >& _rxInspectorUI )
423 if ( !_rxInspectorUI.is() )
424 throw NullPointerException();
426 ::osl::MutexGuard aGuard( m_aMutex );
427 OSL_ENSURE(m_pHelper, "XSDValidationPropertyHandler::onInteractivePropertySelection: we "
428 "don't have any SupportedProperties!");
429 if (!m_pHelper)
430 return InteractiveSelectionResult_Cancelled;
432 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
434 switch ( nPropId )
436 case PROPERTY_ID_XSD_DATA_TYPE:
438 if ( _bPrimary )
440 OUString sNewDataTypeName;
441 if ( implPrepareCloneDataCurrentType( sNewDataTypeName ) )
443 implDoCloneCurrentDataType( sNewDataTypeName );
444 return InteractiveSelectionResult_Success;
447 else
448 return implPrepareRemoveCurrentDataType() && implDoRemoveCurrentDataType() ? InteractiveSelectionResult_Success : InteractiveSelectionResult_Cancelled;
450 break;
452 default:
453 OSL_FAIL( "XSDValidationPropertyHandler::onInteractivePropertySelection: unexpected property to build a dedicated UI!" );
454 break;
456 return InteractiveSelectionResult_Cancelled;
460 void SAL_CALL XSDValidationPropertyHandler::addPropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener )
462 ::osl::MutexGuard aGuard( m_aMutex );
463 XSDValidationPropertyHandler_Base::addPropertyChangeListener( _rxListener );
464 if (m_pHelper)
465 m_pHelper->registerBindingListener( _rxListener );
469 void SAL_CALL XSDValidationPropertyHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _rxListener )
471 ::osl::MutexGuard aGuard( m_aMutex );
472 if (m_pHelper)
473 m_pHelper->revokeBindingListener( _rxListener );
474 XSDValidationPropertyHandler_Base::removePropertyChangeListener( _rxListener );
478 bool XSDValidationPropertyHandler::implPrepareCloneDataCurrentType( OUString& _rNewName )
480 OSL_PRECOND(
481 m_pHelper,
482 "XSDValidationPropertyHandler::implPrepareCloneDataCurrentType: this will crash!");
484 ::rtl::Reference< XSDDataType > pType = m_pHelper->getValidatingDataType();
485 if ( !pType.is() )
487 OSL_FAIL( "XSDValidationPropertyHandler::implPrepareCloneDataCurrentType: invalid current data type!" );
488 return false;
491 std::vector< OUString > aExistentNames;
492 m_pHelper->getAvailableDataTypeNames( aExistentNames );
494 NewDataTypeDialog aDialog( nullptr, pType->getName(), aExistentNames ); // TODO/eForms: proper parent
495 if (aDialog.run() != RET_OK)
496 return false;
498 _rNewName = aDialog.GetName();
499 return true;
503 void XSDValidationPropertyHandler::implDoCloneCurrentDataType( const OUString& _rNewName )
505 OSL_PRECOND(m_pHelper,
506 "XSDValidationPropertyHandler::implDoCloneCurrentDataType: this will crash!");
508 ::rtl::Reference< XSDDataType > pType = m_pHelper->getValidatingDataType();
509 if ( !pType.is() )
510 return;
512 if ( !m_pHelper->cloneDataType( pType, _rNewName ) )
513 return;
515 m_pHelper->setValidatingDataTypeByName( _rNewName );
518 bool XSDValidationPropertyHandler::implPrepareRemoveCurrentDataType()
520 OSL_PRECOND(
521 m_pHelper,
522 "XSDValidationPropertyHandler::implPrepareRemoveCurrentDataType: this will crash!");
524 ::rtl::Reference< XSDDataType > pType = m_pHelper->getValidatingDataType();
525 if ( !pType.is() )
527 OSL_FAIL( "XSDValidationPropertyHandler::implPrepareRemoveCurrentDataType: invalid current data type!" );
528 return false;
531 // confirmation message
532 OUString sConfirmation( PcrRes( RID_STR_CONFIRM_DELETE_DATA_TYPE ) );
533 sConfirmation = sConfirmation.replaceFirst( "#type#", pType->getName() );
535 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(nullptr, // TODO/eForms: proper parent
536 VclMessageType::Question, VclButtonsType::YesNo,
537 sConfirmation));
538 return xQueryBox->run() == RET_YES;
541 bool XSDValidationPropertyHandler::implDoRemoveCurrentDataType()
543 OSL_PRECOND(m_pHelper,
544 "XSDValidationPropertyHandler::implDoRemoveCurrentDataType: this will crash!");
546 ::rtl::Reference< XSDDataType > pType = m_pHelper->getValidatingDataType();
547 if ( !pType.is() )
548 return false;
550 // set a new data type at the binding, which is the "basic" type for the one
551 // we are going to delete
552 // (do this before the actual deletion, so the old type is still valid for property change
553 // notifications)
554 m_pHelper->setValidatingDataTypeByName( m_pHelper->getBasicTypeNameForClass( pType->classify() ) );
555 // now remove the type
556 m_pHelper->removeDataTypeFromRepository( pType->getName() );
558 return true;
562 void SAL_CALL XSDValidationPropertyHandler::actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& _rOldValue, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool _bFirstTimeInit )
564 if ( !_rxInspectorUI.is() )
565 throw NullPointerException();
567 ::osl::MutexGuard aGuard( m_aMutex );
568 PropertyId nActuatingPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName ) );
569 if (!m_pHelper)
570 throw RuntimeException();
571 // if we survived impl_getPropertyId_throwRuntime, we should have a helper, since no helper implies no properties
573 switch ( nActuatingPropId )
575 case PROPERTY_ID_XSD_DATA_TYPE:
577 ::rtl::Reference< XSDDataType > xDataType( m_pHelper->getValidatingDataType() );
579 // is removal of this type possible?
580 bool bIsBasicType = xDataType.is() && xDataType->isBasicType();
581 _rxInspectorUI->enablePropertyUIElements( PROPERTY_XSD_DATA_TYPE, PropertyLineElement::PrimaryButton, xDataType.is() );
582 _rxInspectorUI->enablePropertyUIElements( PROPERTY_XSD_DATA_TYPE, PropertyLineElement::SecondaryButton, xDataType.is() && !bIsBasicType );
585 // show the facets which are available at the data type
586 OUString aFacets[] = {
587 OUString(PROPERTY_XSD_WHITESPACES), OUString(PROPERTY_XSD_PATTERN),
588 OUString(PROPERTY_XSD_LENGTH), OUString(PROPERTY_XSD_MIN_LENGTH), OUString(PROPERTY_XSD_MAX_LENGTH), OUString(PROPERTY_XSD_TOTAL_DIGITS),
589 OUString(PROPERTY_XSD_FRACTION_DIGITS),
590 OUString(PROPERTY_XSD_MAX_INCLUSIVE_INT),
591 OUString(PROPERTY_XSD_MAX_EXCLUSIVE_INT),
592 OUString(PROPERTY_XSD_MIN_INCLUSIVE_INT),
593 OUString(PROPERTY_XSD_MIN_EXCLUSIVE_INT),
594 OUString(PROPERTY_XSD_MAX_INCLUSIVE_DOUBLE),
595 OUString(PROPERTY_XSD_MAX_EXCLUSIVE_DOUBLE),
596 OUString(PROPERTY_XSD_MIN_INCLUSIVE_DOUBLE),
597 OUString(PROPERTY_XSD_MIN_EXCLUSIVE_DOUBLE),
598 OUString(PROPERTY_XSD_MAX_INCLUSIVE_DATE),
599 OUString(PROPERTY_XSD_MAX_EXCLUSIVE_DATE),
600 OUString(PROPERTY_XSD_MIN_INCLUSIVE_DATE),
601 OUString(PROPERTY_XSD_MIN_EXCLUSIVE_DATE),
602 OUString(PROPERTY_XSD_MAX_INCLUSIVE_TIME),
603 OUString(PROPERTY_XSD_MAX_EXCLUSIVE_TIME),
604 OUString(PROPERTY_XSD_MIN_INCLUSIVE_TIME),
605 OUString(PROPERTY_XSD_MIN_EXCLUSIVE_TIME),
606 OUString(PROPERTY_XSD_MAX_INCLUSIVE_DATE_TIME),
607 OUString(PROPERTY_XSD_MAX_EXCLUSIVE_DATE_TIME),
608 OUString(PROPERTY_XSD_MIN_INCLUSIVE_DATE_TIME),
609 OUString(PROPERTY_XSD_MIN_EXCLUSIVE_DATE_TIME)
612 size_t i=0;
613 const OUString* pLoop = nullptr;
614 for ( i = 0, pLoop = aFacets;
615 i < SAL_N_ELEMENTS( aFacets );
616 ++i, ++pLoop
619 showPropertyUI( _rxInspectorUI, *pLoop, xDataType.is() && xDataType->hasFacet( *pLoop ) );
620 _rxInspectorUI->enablePropertyUI( *pLoop, !bIsBasicType );
623 break;
625 case PROPERTY_ID_XML_DATA_MODEL:
627 // The data type which the current binding works with may not be present in the
628 // new model. Thus, transfer it.
629 OUString sOldModelName; _rOldValue >>= sOldModelName;
630 OUString sNewModelName; _rNewValue >>= sNewModelName;
631 OUString sDataType = m_pHelper->getValidatingDataTypeName();
632 m_pHelper->copyDataType( sOldModelName, sNewModelName, sDataType );
634 // the list of available data types depends on the chosen model, so update this
635 if ( !_bFirstTimeInit )
636 _rxInspectorUI->rebuildPropertyUI( PROPERTY_XSD_DATA_TYPE );
638 break;
640 default:
641 OSL_FAIL( "XSDValidationPropertyHandler::actuatingPropertyChanged: cannot handle this property!" );
642 return;
645 // in both cases, we need to care for the current value of the XSD_DATA_TYPE property,
646 // and update the FormatKey of the formatted field we're inspecting (if any)
647 if ( !_bFirstTimeInit && m_pHelper->isInspectingFormattedField() )
648 m_pHelper->findDefaultFormatForIntrospectee();
652 void XSDValidationPropertyHandler::implGetAvailableDataTypeNames( std::vector< OUString >& /* [out] */ _rNames ) const
654 OSL_PRECOND(
655 m_pHelper,
656 "XSDValidationPropertyHandler::implGetAvailableDataTypeNames: this will crash!");
657 // start with *all* types which are available at the model
658 std::vector< OUString > aAllTypes;
659 m_pHelper->getAvailableDataTypeNames( aAllTypes );
660 _rNames.clear();
661 _rNames.reserve( aAllTypes.size() );
663 // then allow only those which are "compatible" with our control
664 for (auto const& dataType : aAllTypes)
666 ::rtl::Reference< XSDDataType > pType = m_pHelper->getDataTypeByName(dataType);
667 if ( pType.is() && m_pHelper->canBindToDataType( pType->classify() ) )
668 _rNames.push_back(dataType);
673 } // namespace pcr
676 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */