1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "xsdvalidationpropertyhandler.hxx"
23 #include "formstrings.hxx"
24 #include "formmetadata.hxx"
25 #include "xsddatatypes.hxx"
26 #include "modulepcr.hxx"
27 #include <strings.hrc>
28 #include <propctrlr.h>
29 #include "newdatatype.hxx"
30 #include "xsdvalidationhelper.hxx"
31 #include "pcrcommon.hxx"
32 #include "handlerhelper.hxx"
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/lang/NullPointerException.hpp>
36 #include <com/sun/star/xsd/WhiteSpaceTreatment.hpp>
37 #include <com/sun/star/xsd/DataTypeClass.hpp>
38 #include <com/sun/star/inspection/PropertyControlType.hpp>
39 #include <com/sun/star/beans/Optional.hpp>
40 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
41 #include <com/sun/star/inspection/PropertyLineElement.hpp>
42 #include <vcl/svapp.hxx>
43 #include <vcl/weld.hxx>
44 #include <tools/debug.hxx>
45 #include <sal/macros.h>
55 using namespace ::com::sun::star
;
56 using namespace ::com::sun::star::uno
;
57 using namespace ::com::sun::star::lang
;
58 using namespace ::com::sun::star::beans
;
59 using namespace ::com::sun::star::xsd
;
60 using namespace ::com::sun::star::inspection
;
62 using ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
;
65 //= XSDValidationPropertyHandler
67 XSDValidationPropertyHandler::XSDValidationPropertyHandler( const Reference
< XComponentContext
>& _rxContext
)
68 :PropertyHandlerComponent( _rxContext
)
73 XSDValidationPropertyHandler::~XSDValidationPropertyHandler()
78 OUString
XSDValidationPropertyHandler::getImplementationName( )
80 return u
"com.sun.star.comp.extensions.XSDValidationPropertyHandler"_ustr
;
84 Sequence
< OUString
> XSDValidationPropertyHandler::getSupportedServiceNames( )
86 return{ u
"com.sun.star.form.inspection.XSDValidationPropertyHandler"_ustr
};
90 Any SAL_CALL
XSDValidationPropertyHandler::getPropertyValue( const OUString
& _rPropertyName
)
92 ::osl::MutexGuard
aGuard( m_aMutex
);
93 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
95 OSL_ENSURE(m_pHelper
, "XSDValidationPropertyHandler::getPropertyValue: inconsistency!");
96 // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
99 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getValidatingDataType();
103 case PROPERTY_ID_XSD_DATA_TYPE
: aReturn
= pType
.is() ? pType
->getFacet( PROPERTY_NAME
) : Any( OUString() ); break;
104 case PROPERTY_ID_XSD_WHITESPACES
:aReturn
= pType
.is() ? pType
->getFacet( PROPERTY_XSD_WHITESPACES
) : Any( WhiteSpaceTreatment::Preserve
); break;
105 case PROPERTY_ID_XSD_PATTERN
: aReturn
= pType
.is() ? pType
->getFacet( PROPERTY_XSD_PATTERN
) : Any( OUString() ); break;
107 // all other properties are simply forwarded, if they exist at the given type
110 if ( pType
.is() && pType
->hasFacet( _rPropertyName
) )
111 aReturn
= pType
->getFacet( _rPropertyName
);
120 void SAL_CALL
XSDValidationPropertyHandler::setPropertyValue( const OUString
& _rPropertyName
, const Any
& _rValue
)
122 ::osl::MutexGuard
aGuard( m_aMutex
);
123 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
125 OSL_ENSURE(m_pHelper
, "XSDValidationPropertyHandler::getPropertyValue: inconsistency!");
126 // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
128 if ( PROPERTY_ID_XSD_DATA_TYPE
== nPropId
)
131 OSL_VERIFY( _rValue
>>= sTypeName
);
132 m_pHelper
->setValidatingDataTypeByName( sTypeName
);
133 impl_setContextDocumentModified_nothrow();
137 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getValidatingDataType();
140 OSL_FAIL( "XSDValidationPropertyHandler::setPropertyValue: you're trying to set a type facet, without a current type!" );
144 pType
->setFacet( _rPropertyName
, _rValue
);
145 impl_setContextDocumentModified_nothrow();
149 void XSDValidationPropertyHandler::onNewComponent()
151 PropertyHandlerComponent::onNewComponent();
153 Reference
< frame::XModel
> xDocument( impl_getContextDocument_nothrow() );
154 DBG_ASSERT( xDocument
.is(), "XSDValidationPropertyHandler::onNewComponent: no document!" );
155 if ( EFormsHelper::isEForm( xDocument
) )
156 m_pHelper
.reset( new XSDValidationHelper( m_aMutex
, m_xComponent
, xDocument
) );
162 Sequence
< Property
> XSDValidationPropertyHandler::doDescribeSupportedProperties() const
164 std::vector
< Property
> aProperties
;
168 bool bAllowBinding
= m_pHelper
->canBindToAnyDataType();
172 aProperties
.reserve( 28 );
174 addStringPropertyDescription( aProperties
, PROPERTY_XSD_DATA_TYPE
);
175 addInt16PropertyDescription ( aProperties
, PROPERTY_XSD_WHITESPACES
);
176 addStringPropertyDescription( aProperties
, PROPERTY_XSD_PATTERN
);
179 addInt32PropertyDescription( aProperties
, PROPERTY_XSD_LENGTH
, MAYBEVOID
);
180 addInt32PropertyDescription( aProperties
, PROPERTY_XSD_MIN_LENGTH
, MAYBEVOID
);
181 addInt32PropertyDescription( aProperties
, PROPERTY_XSD_MAX_LENGTH
, MAYBEVOID
);
184 addInt32PropertyDescription( aProperties
, PROPERTY_XSD_TOTAL_DIGITS
, MAYBEVOID
);
185 addInt32PropertyDescription( aProperties
, PROPERTY_XSD_FRACTION_DIGITS
, MAYBEVOID
);
187 // facets for different types
188 addInt16PropertyDescription( aProperties
, PROPERTY_XSD_MAX_INCLUSIVE_INT
, MAYBEVOID
);
189 addInt16PropertyDescription( aProperties
, PROPERTY_XSD_MAX_EXCLUSIVE_INT
, MAYBEVOID
);
190 addInt16PropertyDescription( aProperties
, PROPERTY_XSD_MIN_INCLUSIVE_INT
, MAYBEVOID
);
191 addInt16PropertyDescription( aProperties
, PROPERTY_XSD_MIN_EXCLUSIVE_INT
, MAYBEVOID
);
192 addDoublePropertyDescription( aProperties
, PROPERTY_XSD_MAX_INCLUSIVE_DOUBLE
, MAYBEVOID
);
193 addDoublePropertyDescription( aProperties
, PROPERTY_XSD_MAX_EXCLUSIVE_DOUBLE
, MAYBEVOID
);
194 addDoublePropertyDescription( aProperties
, PROPERTY_XSD_MIN_INCLUSIVE_DOUBLE
, MAYBEVOID
);
195 addDoublePropertyDescription( aProperties
, PROPERTY_XSD_MIN_EXCLUSIVE_DOUBLE
, MAYBEVOID
);
196 addDatePropertyDescription( aProperties
, PROPERTY_XSD_MAX_INCLUSIVE_DATE
, MAYBEVOID
);
197 addDatePropertyDescription( aProperties
, PROPERTY_XSD_MAX_EXCLUSIVE_DATE
, MAYBEVOID
);
198 addDatePropertyDescription( aProperties
, PROPERTY_XSD_MIN_INCLUSIVE_DATE
, MAYBEVOID
);
199 addDatePropertyDescription( aProperties
, PROPERTY_XSD_MIN_EXCLUSIVE_DATE
, MAYBEVOID
);
200 addTimePropertyDescription( aProperties
, PROPERTY_XSD_MAX_INCLUSIVE_TIME
, MAYBEVOID
);
201 addTimePropertyDescription( aProperties
, PROPERTY_XSD_MAX_EXCLUSIVE_TIME
, MAYBEVOID
);
202 addTimePropertyDescription( aProperties
, PROPERTY_XSD_MIN_INCLUSIVE_TIME
, MAYBEVOID
);
203 addTimePropertyDescription( aProperties
, PROPERTY_XSD_MIN_EXCLUSIVE_TIME
, MAYBEVOID
);
204 addDateTimePropertyDescription( aProperties
, PROPERTY_XSD_MAX_INCLUSIVE_DATE_TIME
, MAYBEVOID
);
205 addDateTimePropertyDescription( aProperties
, PROPERTY_XSD_MAX_EXCLUSIVE_DATE_TIME
, MAYBEVOID
);
206 addDateTimePropertyDescription( aProperties
, PROPERTY_XSD_MIN_INCLUSIVE_DATE_TIME
, MAYBEVOID
);
207 addDateTimePropertyDescription( aProperties
, PROPERTY_XSD_MIN_EXCLUSIVE_DATE_TIME
, MAYBEVOID
);
211 return comphelper::containerToSequence( aProperties
);
215 Sequence
< OUString
> SAL_CALL
XSDValidationPropertyHandler::getSupersededProperties( )
217 ::osl::MutexGuard
aGuard( m_aMutex
);
219 std::vector
< OUString
> aSuperfluous
;
222 aSuperfluous
.push_back( PROPERTY_CONTROLSOURCE
);
223 aSuperfluous
.push_back( PROPERTY_EMPTY_IS_NULL
);
224 aSuperfluous
.push_back( PROPERTY_FILTERPROPOSAL
);
225 aSuperfluous
.push_back( PROPERTY_LISTSOURCETYPE
);
226 aSuperfluous
.push_back( PROPERTY_LISTSOURCE
);
227 aSuperfluous
.push_back( PROPERTY_BOUNDCOLUMN
);
229 bool bAllowBinding
= m_pHelper
->canBindToAnyDataType();
233 aSuperfluous
.push_back( PROPERTY_MAXTEXTLEN
);
234 aSuperfluous
.push_back( PROPERTY_VALUEMIN
);
235 aSuperfluous
.push_back( PROPERTY_VALUEMAX
);
236 aSuperfluous
.push_back( PROPERTY_DECIMAL_ACCURACY
);
237 aSuperfluous
.push_back( PROPERTY_TIMEMIN
);
238 aSuperfluous
.push_back( PROPERTY_TIMEMAX
);
239 aSuperfluous
.push_back( PROPERTY_DATEMIN
);
240 aSuperfluous
.push_back( PROPERTY_DATEMAX
);
241 aSuperfluous
.push_back( PROPERTY_EFFECTIVE_MIN
);
242 aSuperfluous
.push_back( PROPERTY_EFFECTIVE_MAX
);
246 return comphelper::containerToSequence( aSuperfluous
);
250 Sequence
< OUString
> SAL_CALL
XSDValidationPropertyHandler::getActuatingProperties( )
252 ::osl::MutexGuard
aGuard( m_aMutex
);
253 std::vector
< OUString
> aInterestedInActuations
;
256 aInterestedInActuations
.push_back( PROPERTY_XSD_DATA_TYPE
);
257 aInterestedInActuations
.push_back( PROPERTY_XML_DATA_MODEL
);
259 return comphelper::containerToSequence( aInterestedInActuations
);
265 void showPropertyUI( const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, const OUString
& _rPropertyName
, bool _bShow
)
268 _rxInspectorUI
->showPropertyUI( _rPropertyName
);
270 _rxInspectorUI
->hidePropertyUI( _rPropertyName
);
275 LineDescriptor SAL_CALL
XSDValidationPropertyHandler::describePropertyLine( const OUString
& _rPropertyName
,
276 const Reference
< XPropertyControlFactory
>& _rxControlFactory
)
278 ::osl::MutexGuard
aGuard( m_aMutex
);
279 if ( !_rxControlFactory
.is() )
280 throw NullPointerException();
282 throw RuntimeException();
284 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
286 LineDescriptor aDescriptor
;
287 if ( nPropId
!= PROPERTY_ID_XSD_DATA_TYPE
)
288 aDescriptor
.IndentLevel
= 1;
290 // collect some information about the to-be-created control
291 sal_Int16 nControlType
= PropertyControlType::TextField
;
292 std::vector
< OUString
> aListEntries
;
293 Optional
< double > aMinValue( false, 0 );
294 Optional
< double > aMaxValue( false, 0 );
298 case PROPERTY_ID_XSD_DATA_TYPE
:
299 nControlType
= PropertyControlType::ListBox
;
301 implGetAvailableDataTypeNames( aListEntries
);
303 aDescriptor
.PrimaryButtonId
= UID_PROP_ADD_DATA_TYPE
;
304 aDescriptor
.SecondaryButtonId
= UID_PROP_REMOVE_DATA_TYPE
;
305 aDescriptor
.HasPrimaryButton
= aDescriptor
.HasSecondaryButton
= true;
306 aDescriptor
.PrimaryButtonImageURL
= "private:graphicrepository/extensions/res/buttonplus.png";
307 aDescriptor
.SecondaryButtonImageURL
= "private:graphicrepository/extensions/res/buttonminus.png";
310 case PROPERTY_ID_XSD_WHITESPACES
:
312 nControlType
= PropertyControlType::ListBox
;
313 aListEntries
= m_pInfoService
->getPropertyEnumRepresentations( PROPERTY_ID_XSD_WHITESPACES
);
317 case PROPERTY_ID_XSD_PATTERN
:
318 nControlType
= PropertyControlType::TextField
;
321 case PROPERTY_ID_XSD_LENGTH
:
322 case PROPERTY_ID_XSD_MIN_LENGTH
:
323 case PROPERTY_ID_XSD_MAX_LENGTH
:
324 nControlType
= PropertyControlType::NumericField
;
327 case PROPERTY_ID_XSD_TOTAL_DIGITS
:
328 case PROPERTY_ID_XSD_FRACTION_DIGITS
:
329 nControlType
= PropertyControlType::NumericField
;
332 case PROPERTY_ID_XSD_MAX_INCLUSIVE_INT
:
333 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_INT
:
334 case PROPERTY_ID_XSD_MIN_INCLUSIVE_INT
:
335 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_INT
:
337 nControlType
= PropertyControlType::NumericField
;
339 // handle limits for various 'INT' types according to
340 // their actual semantics (year, month, day)
342 ::rtl::Reference
< XSDDataType
> xDataType( m_pHelper
->getValidatingDataType() );
343 sal_Int16 nTypeClass
= xDataType
.is() ? xDataType
->classify() : DataTypeClass::STRING
;
345 aMinValue
.IsPresent
= aMaxValue
.IsPresent
= true;
346 aMinValue
.Value
= DataTypeClass::gYear
== nTypeClass
? 0 : 1;
347 aMaxValue
.Value
= std::numeric_limits
< sal_Int32
>::max();
348 if ( DataTypeClass::gMonth
== nTypeClass
)
349 aMaxValue
.Value
= 12;
350 else if ( DataTypeClass::gDay
== nTypeClass
)
351 aMaxValue
.Value
= 31;
355 case PROPERTY_ID_XSD_MAX_INCLUSIVE_DOUBLE
:
356 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DOUBLE
:
357 case PROPERTY_ID_XSD_MIN_INCLUSIVE_DOUBLE
:
358 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DOUBLE
:
359 nControlType
= PropertyControlType::NumericField
;
360 // TODO/eForms: do we have "auto-digits"?
363 case PROPERTY_ID_XSD_MAX_INCLUSIVE_DATE
:
364 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DATE
:
365 case PROPERTY_ID_XSD_MIN_INCLUSIVE_DATE
:
366 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DATE
:
367 nControlType
= PropertyControlType::DateField
;
370 case PROPERTY_ID_XSD_MAX_INCLUSIVE_TIME
:
371 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_TIME
:
372 case PROPERTY_ID_XSD_MIN_INCLUSIVE_TIME
:
373 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_TIME
:
374 nControlType
= PropertyControlType::TimeField
;
377 case PROPERTY_ID_XSD_MAX_INCLUSIVE_DATE_TIME
:
378 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DATE_TIME
:
379 case PROPERTY_ID_XSD_MIN_INCLUSIVE_DATE_TIME
:
380 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DATE_TIME
:
381 nControlType
= PropertyControlType::DateTimeField
;
385 OSL_FAIL( "XSDValidationPropertyHandler::describePropertyLine: cannot handle this property!" );
389 switch ( nControlType
)
391 case PropertyControlType::ListBox
:
392 aDescriptor
.Control
= PropertyHandlerHelper::createListBoxControl( _rxControlFactory
, std::move(aListEntries
), false, false );
394 case PropertyControlType::NumericField
:
395 aDescriptor
.Control
= PropertyHandlerHelper::createNumericControl( _rxControlFactory
, 0, aMinValue
, aMaxValue
);
398 aDescriptor
.Control
= _rxControlFactory
->createPropertyControl( nControlType
, false );
402 aDescriptor
.Category
= "Data";
403 aDescriptor
.DisplayName
= m_pInfoService
->getPropertyTranslation( nPropId
);
404 aDescriptor
.HelpURL
= HelpIdUrl::getHelpURL( m_pInfoService
->getPropertyHelpId( nPropId
) );
410 InteractiveSelectionResult SAL_CALL
XSDValidationPropertyHandler::onInteractivePropertySelection( const OUString
& _rPropertyName
, sal_Bool _bPrimary
, Any
& /*_rData*/, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
)
412 if ( !_rxInspectorUI
.is() )
413 throw NullPointerException();
415 ::osl::MutexGuard
aGuard( m_aMutex
);
416 OSL_ENSURE(m_pHelper
, "XSDValidationPropertyHandler::onInteractivePropertySelection: we "
417 "don't have any SupportedProperties!");
419 return InteractiveSelectionResult_Cancelled
;
421 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
425 case PROPERTY_ID_XSD_DATA_TYPE
:
429 OUString sNewDataTypeName
;
430 if ( implPrepareCloneDataCurrentType( sNewDataTypeName
) )
432 implDoCloneCurrentDataType( sNewDataTypeName
);
433 return InteractiveSelectionResult_Success
;
437 return implPrepareRemoveCurrentDataType() && implDoRemoveCurrentDataType() ? InteractiveSelectionResult_Success
: InteractiveSelectionResult_Cancelled
;
442 OSL_FAIL( "XSDValidationPropertyHandler::onInteractivePropertySelection: unexpected property to build a dedicated UI!" );
445 return InteractiveSelectionResult_Cancelled
;
449 void SAL_CALL
XSDValidationPropertyHandler::addPropertyChangeListener( const Reference
< XPropertyChangeListener
>& _rxListener
)
451 ::osl::MutexGuard
aGuard( m_aMutex
);
452 PropertyHandlerComponent::addPropertyChangeListener( _rxListener
);
454 m_pHelper
->registerBindingListener( _rxListener
);
458 void SAL_CALL
XSDValidationPropertyHandler::removePropertyChangeListener( const Reference
< XPropertyChangeListener
>& _rxListener
)
460 ::osl::MutexGuard
aGuard( m_aMutex
);
462 m_pHelper
->revokeBindingListener( _rxListener
);
463 PropertyHandlerComponent::removePropertyChangeListener( _rxListener
);
467 bool XSDValidationPropertyHandler::implPrepareCloneDataCurrentType( OUString
& _rNewName
)
471 "XSDValidationPropertyHandler::implPrepareCloneDataCurrentType: this will crash!");
473 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getValidatingDataType();
476 OSL_FAIL( "XSDValidationPropertyHandler::implPrepareCloneDataCurrentType: invalid current data type!" );
480 std::vector
< OUString
> aExistentNames
;
481 m_pHelper
->getAvailableDataTypeNames( aExistentNames
);
483 NewDataTypeDialog
aDialog( nullptr, pType
->getName(), aExistentNames
); // TODO/eForms: proper parent
484 if (aDialog
.run() != RET_OK
)
487 _rNewName
= aDialog
.GetName();
492 void XSDValidationPropertyHandler::implDoCloneCurrentDataType( const OUString
& _rNewName
)
494 OSL_PRECOND(m_pHelper
,
495 "XSDValidationPropertyHandler::implDoCloneCurrentDataType: this will crash!");
497 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getValidatingDataType();
501 if ( !m_pHelper
->cloneDataType( pType
, _rNewName
) )
504 m_pHelper
->setValidatingDataTypeByName( _rNewName
);
507 bool XSDValidationPropertyHandler::implPrepareRemoveCurrentDataType()
511 "XSDValidationPropertyHandler::implPrepareRemoveCurrentDataType: this will crash!");
513 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getValidatingDataType();
516 OSL_FAIL( "XSDValidationPropertyHandler::implPrepareRemoveCurrentDataType: invalid current data type!" );
520 // confirmation message
521 OUString
sConfirmation( PcrRes( RID_STR_CONFIRM_DELETE_DATA_TYPE
) );
522 sConfirmation
= sConfirmation
.replaceFirst( "#type#", pType
->getName() );
524 std::unique_ptr
<weld::MessageDialog
> xQueryBox(Application::CreateMessageDialog(nullptr, // TODO/eForms: proper parent
525 VclMessageType::Question
, VclButtonsType::YesNo
,
527 return xQueryBox
->run() == RET_YES
;
530 bool XSDValidationPropertyHandler::implDoRemoveCurrentDataType()
532 OSL_PRECOND(m_pHelper
,
533 "XSDValidationPropertyHandler::implDoRemoveCurrentDataType: this will crash!");
535 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getValidatingDataType();
539 // set a new data type at the binding, which is the "basic" type for the one
540 // we are going to delete
541 // (do this before the actual deletion, so the old type is still valid for property change
543 m_pHelper
->setValidatingDataTypeByName( m_pHelper
->getBasicTypeNameForClass( pType
->classify() ) );
544 // now remove the type
545 m_pHelper
->removeDataTypeFromRepository( pType
->getName() );
551 void SAL_CALL
XSDValidationPropertyHandler::actuatingPropertyChanged( const OUString
& _rActuatingPropertyName
, const Any
& _rNewValue
, const Any
& _rOldValue
, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, sal_Bool _bFirstTimeInit
)
553 if ( !_rxInspectorUI
.is() )
554 throw NullPointerException();
556 ::osl::MutexGuard
aGuard( m_aMutex
);
557 PropertyId
nActuatingPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName
) );
559 throw RuntimeException();
560 // if we survived impl_getPropertyId_throwRuntime, we should have a helper, since no helper implies no properties
562 switch ( nActuatingPropId
)
564 case PROPERTY_ID_XSD_DATA_TYPE
:
566 ::rtl::Reference
< XSDDataType
> xDataType( m_pHelper
->getValidatingDataType() );
568 // is removal of this type possible?
569 bool bIsBasicType
= xDataType
.is() && xDataType
->isBasicType();
570 _rxInspectorUI
->enablePropertyUIElements( PROPERTY_XSD_DATA_TYPE
, PropertyLineElement::PrimaryButton
, xDataType
.is() );
571 _rxInspectorUI
->enablePropertyUIElements( PROPERTY_XSD_DATA_TYPE
, PropertyLineElement::SecondaryButton
, xDataType
.is() && !bIsBasicType
);
574 // show the facets which are available at the data type
575 OUString aFacets
[] = {
576 PROPERTY_XSD_WHITESPACES
, PROPERTY_XSD_PATTERN
,
577 PROPERTY_XSD_LENGTH
, PROPERTY_XSD_MIN_LENGTH
, PROPERTY_XSD_MAX_LENGTH
, PROPERTY_XSD_TOTAL_DIGITS
,
578 PROPERTY_XSD_FRACTION_DIGITS
,
579 PROPERTY_XSD_MAX_INCLUSIVE_INT
,
580 PROPERTY_XSD_MAX_EXCLUSIVE_INT
,
581 PROPERTY_XSD_MIN_INCLUSIVE_INT
,
582 PROPERTY_XSD_MIN_EXCLUSIVE_INT
,
583 PROPERTY_XSD_MAX_INCLUSIVE_DOUBLE
,
584 PROPERTY_XSD_MAX_EXCLUSIVE_DOUBLE
,
585 PROPERTY_XSD_MIN_INCLUSIVE_DOUBLE
,
586 PROPERTY_XSD_MIN_EXCLUSIVE_DOUBLE
,
587 PROPERTY_XSD_MAX_INCLUSIVE_DATE
,
588 PROPERTY_XSD_MAX_EXCLUSIVE_DATE
,
589 PROPERTY_XSD_MIN_INCLUSIVE_DATE
,
590 PROPERTY_XSD_MIN_EXCLUSIVE_DATE
,
591 PROPERTY_XSD_MAX_INCLUSIVE_TIME
,
592 PROPERTY_XSD_MAX_EXCLUSIVE_TIME
,
593 PROPERTY_XSD_MIN_INCLUSIVE_TIME
,
594 PROPERTY_XSD_MIN_EXCLUSIVE_TIME
,
595 PROPERTY_XSD_MAX_INCLUSIVE_DATE_TIME
,
596 PROPERTY_XSD_MAX_EXCLUSIVE_DATE_TIME
,
597 PROPERTY_XSD_MIN_INCLUSIVE_DATE_TIME
,
598 PROPERTY_XSD_MIN_EXCLUSIVE_DATE_TIME
602 const OUString
* pLoop
= nullptr;
603 for ( i
= 0, pLoop
= aFacets
;
604 i
< SAL_N_ELEMENTS( aFacets
);
608 showPropertyUI( _rxInspectorUI
, *pLoop
, xDataType
.is() && xDataType
->hasFacet( *pLoop
) );
609 _rxInspectorUI
->enablePropertyUI( *pLoop
, !bIsBasicType
);
614 case PROPERTY_ID_XML_DATA_MODEL
:
616 // The data type which the current binding works with may not be present in the
617 // new model. Thus, transfer it.
618 OUString sOldModelName
; _rOldValue
>>= sOldModelName
;
619 OUString sNewModelName
; _rNewValue
>>= sNewModelName
;
620 OUString sDataType
= m_pHelper
->getValidatingDataTypeName();
621 m_pHelper
->copyDataType( sOldModelName
, sNewModelName
, sDataType
);
623 // the list of available data types depends on the chosen model, so update this
624 if ( !_bFirstTimeInit
)
625 _rxInspectorUI
->rebuildPropertyUI( PROPERTY_XSD_DATA_TYPE
);
630 OSL_FAIL( "XSDValidationPropertyHandler::actuatingPropertyChanged: cannot handle this property!" );
634 // in both cases, we need to care for the current value of the XSD_DATA_TYPE property,
635 // and update the FormatKey of the formatted field we're inspecting (if any)
636 if ( !_bFirstTimeInit
&& m_pHelper
->isInspectingFormattedField() )
637 m_pHelper
->findDefaultFormatForIntrospectee();
641 void XSDValidationPropertyHandler::implGetAvailableDataTypeNames( std::vector
< OUString
>& /* [out] */ _rNames
) const
645 "XSDValidationPropertyHandler::implGetAvailableDataTypeNames: this will crash!");
646 // start with *all* types which are available at the model
647 std::vector
< OUString
> aAllTypes
;
648 m_pHelper
->getAvailableDataTypeNames( aAllTypes
);
650 _rNames
.reserve( aAllTypes
.size() );
652 // then allow only those which are "compatible" with our control
653 for (auto const& dataType
: aAllTypes
)
655 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getDataTypeByName(dataType
);
656 if ( pType
.is() && m_pHelper
->canBindToDataType( pType
->classify() ) )
657 _rNames
.push_back(dataType
);
664 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
665 extensions_propctrlr_XSDValidationPropertyHandler_get_implementation(
666 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
668 return cppu::acquire(new pcr::XSDValidationPropertyHandler(context
));
671 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */