1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_extensions.hxx"
31 #include "xsdvalidationpropertyhandler.hxx"
32 #include "formstrings.hxx"
33 #include "formmetadata.hxx"
34 #include "xsddatatypes.hxx"
35 #include "modulepcr.hxx"
36 #include "formresid.hrc"
37 #include "formlocalid.hrc"
38 #include "propctrlr.hrc"
39 #include "newdatatype.hxx"
40 #include "xsdvalidationhelper.hxx"
41 #include "pcrcommon.hxx"
42 #include "handlerhelper.hxx"
44 /** === begin UNO includes === **/
45 #include <com/sun/star/beans/PropertyAttribute.hpp>
46 #include <com/sun/star/xsd/WhiteSpaceTreatment.hpp>
47 #include <com/sun/star/xsd/DataTypeClass.hpp>
48 #include <com/sun/star/inspection/PropertyControlType.hpp>
49 #include <com/sun/star/beans/Optional.hpp>
50 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
51 #include <com/sun/star/inspection/PropertyLineElement.hpp>
52 /** === end UNO includes === **/
53 #include <vcl/msgbox.hxx>
54 #include <tools/debug.hxx>
55 #include <svtools/localresaccess.hxx>
56 #include <sal/macros.h>
62 //------------------------------------------------------------------------
63 extern "C" void SAL_CALL
createRegistryInfo_XSDValidationPropertyHandler()
65 ::pcr::XSDValidationPropertyHandler::registerImplementation();
68 //........................................................................
71 //........................................................................
73 using namespace ::com::sun::star
;
74 using namespace ::com::sun::star::uno
;
75 using namespace ::com::sun::star::lang
;
76 using namespace ::com::sun::star::beans
;
77 using namespace ::com::sun::star::xforms
;
78 using namespace ::com::sun::star::xsd
;
79 using namespace ::com::sun::star::script
;
80 using namespace ::com::sun::star::inspection
;
82 using ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
;
84 //====================================================================
85 //= XSDValidationPropertyHandler
86 //====================================================================
87 DBG_NAME( XSDValidationPropertyHandler
)
88 //--------------------------------------------------------------------
89 XSDValidationPropertyHandler::XSDValidationPropertyHandler( const Reference
< XComponentContext
>& _rxContext
)
90 :XSDValidationPropertyHandler_Base( _rxContext
)
92 DBG_CTOR( XSDValidationPropertyHandler
, NULL
);
95 //--------------------------------------------------------------------
96 XSDValidationPropertyHandler::~XSDValidationPropertyHandler()
98 DBG_DTOR( XSDValidationPropertyHandler
, NULL
);
101 //--------------------------------------------------------------------
102 ::rtl::OUString SAL_CALL
XSDValidationPropertyHandler::getImplementationName_static( ) throw (RuntimeException
)
104 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.XSDValidationPropertyHandler" ) );
107 //--------------------------------------------------------------------
108 Sequence
< ::rtl::OUString
> SAL_CALL
XSDValidationPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException
)
110 Sequence
< ::rtl::OUString
> aSupported( 1 );
111 aSupported
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.XSDValidationPropertyHandler" ) );
115 //--------------------------------------------------------------------
116 Any SAL_CALL
XSDValidationPropertyHandler::getPropertyValue( const ::rtl::OUString
& _rPropertyName
) throw (UnknownPropertyException
, RuntimeException
)
118 ::osl::MutexGuard
aGuard( m_aMutex
);
119 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
121 OSL_ENSURE( m_pHelper
.get(), "XSDValidationPropertyHandler::getPropertyValue: inconsistency!" );
122 // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
125 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getValidatingDataType();
129 case PROPERTY_ID_XSD_DATA_TYPE
: aReturn
= pType
.is() ? pType
->getFacet( PROPERTY_NAME
) : makeAny( ::rtl::OUString() ); break;
130 case PROPERTY_ID_XSD_WHITESPACES
:aReturn
= pType
.is() ? pType
->getFacet( PROPERTY_XSD_WHITESPACES
) : makeAny( WhiteSpaceTreatment::Preserve
); break;
131 case PROPERTY_ID_XSD_PATTERN
: aReturn
= pType
.is() ? pType
->getFacet( PROPERTY_XSD_PATTERN
) : makeAny( ::rtl::OUString() ); break;
133 // all other properties are simply forwarded, if they exist at the given type
136 if ( pType
.is() && pType
->hasFacet( _rPropertyName
) )
137 aReturn
= pType
->getFacet( _rPropertyName
);
145 //--------------------------------------------------------------------
146 void SAL_CALL
XSDValidationPropertyHandler::setPropertyValue( const ::rtl::OUString
& _rPropertyName
, const Any
& _rValue
) throw (UnknownPropertyException
, RuntimeException
)
148 ::osl::MutexGuard
aGuard( m_aMutex
);
149 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
151 OSL_ENSURE( m_pHelper
.get(), "XSDValidationPropertyHandler::getPropertyValue: inconsistency!" );
152 // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
154 if ( PROPERTY_ID_XSD_DATA_TYPE
== nPropId
)
156 ::rtl::OUString sTypeName
;
157 OSL_VERIFY( _rValue
>>= sTypeName
);
158 m_pHelper
->setValidatingDataTypeByName( sTypeName
);
159 impl_setContextDocumentModified_nothrow();
163 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getValidatingDataType();
166 DBG_ERROR( "XSDValidationPropertyHandler::setPropertyValue: you're trying to set a type facet, without a current type!" );
170 pType
->setFacet( _rPropertyName
, _rValue
);
171 impl_setContextDocumentModified_nothrow();
174 //--------------------------------------------------------------------
175 void XSDValidationPropertyHandler::onNewComponent()
177 XSDValidationPropertyHandler_Base::onNewComponent();
179 Reference
< frame::XModel
> xDocument( impl_getContextDocument_nothrow() );
180 DBG_ASSERT( xDocument
.is(), "XSDValidationPropertyHandler::onNewComponent: no document!" );
181 if ( EFormsHelper::isEForm( xDocument
) )
182 m_pHelper
.reset( new XSDValidationHelper( m_aMutex
, m_xComponent
, xDocument
) );
184 m_pHelper
.reset( NULL
);
187 //--------------------------------------------------------------------
188 Sequence
< Property
> XSDValidationPropertyHandler::doDescribeSupportedProperties() const
190 ::std::vector
< Property
> aProperties
;
192 if ( m_pHelper
.get() )
194 bool bAllowBinding
= m_pHelper
->canBindToAnyDataType();
198 aProperties
.reserve( 12 );
200 addStringPropertyDescription( aProperties
, PROPERTY_XSD_DATA_TYPE
);
201 addInt16PropertyDescription ( aProperties
, PROPERTY_XSD_WHITESPACES
);
202 addStringPropertyDescription( aProperties
, PROPERTY_XSD_PATTERN
);
205 addInt32PropertyDescription( aProperties
, PROPERTY_XSD_LENGTH
, MAYBEVOID
);
206 addInt32PropertyDescription( aProperties
, PROPERTY_XSD_MIN_LENGTH
, MAYBEVOID
);
207 addInt32PropertyDescription( aProperties
, PROPERTY_XSD_MAX_LENGTH
, MAYBEVOID
);
210 addInt32PropertyDescription( aProperties
, PROPERTY_XSD_TOTAL_DIGITS
, MAYBEVOID
);
211 addInt32PropertyDescription( aProperties
, PROPERTY_XSD_FRACTION_DIGITS
, MAYBEVOID
);
213 // facets for different types
214 addInt16PropertyDescription( aProperties
, PROPERTY_XSD_MAX_INCLUSIVE_INT
, MAYBEVOID
);
215 addInt16PropertyDescription( aProperties
, PROPERTY_XSD_MAX_EXCLUSIVE_INT
, MAYBEVOID
);
216 addInt16PropertyDescription( aProperties
, PROPERTY_XSD_MIN_INCLUSIVE_INT
, MAYBEVOID
);
217 addInt16PropertyDescription( aProperties
, PROPERTY_XSD_MIN_EXCLUSIVE_INT
, MAYBEVOID
);
218 addDoublePropertyDescription( aProperties
, PROPERTY_XSD_MAX_INCLUSIVE_DOUBLE
, MAYBEVOID
);
219 addDoublePropertyDescription( aProperties
, PROPERTY_XSD_MAX_EXCLUSIVE_DOUBLE
, MAYBEVOID
);
220 addDoublePropertyDescription( aProperties
, PROPERTY_XSD_MIN_INCLUSIVE_DOUBLE
, MAYBEVOID
);
221 addDoublePropertyDescription( aProperties
, PROPERTY_XSD_MIN_EXCLUSIVE_DOUBLE
, MAYBEVOID
);
222 addDatePropertyDescription( aProperties
, PROPERTY_XSD_MAX_INCLUSIVE_DATE
, MAYBEVOID
);
223 addDatePropertyDescription( aProperties
, PROPERTY_XSD_MAX_EXCLUSIVE_DATE
, MAYBEVOID
);
224 addDatePropertyDescription( aProperties
, PROPERTY_XSD_MIN_INCLUSIVE_DATE
, MAYBEVOID
);
225 addDatePropertyDescription( aProperties
, PROPERTY_XSD_MIN_EXCLUSIVE_DATE
, MAYBEVOID
);
226 addTimePropertyDescription( aProperties
, PROPERTY_XSD_MAX_INCLUSIVE_TIME
, MAYBEVOID
);
227 addTimePropertyDescription( aProperties
, PROPERTY_XSD_MAX_EXCLUSIVE_TIME
, MAYBEVOID
);
228 addTimePropertyDescription( aProperties
, PROPERTY_XSD_MIN_INCLUSIVE_TIME
, MAYBEVOID
);
229 addTimePropertyDescription( aProperties
, PROPERTY_XSD_MIN_EXCLUSIVE_TIME
, MAYBEVOID
);
230 addDateTimePropertyDescription( aProperties
, PROPERTY_XSD_MAX_INCLUSIVE_DATE_TIME
, MAYBEVOID
);
231 addDateTimePropertyDescription( aProperties
, PROPERTY_XSD_MAX_EXCLUSIVE_DATE_TIME
, MAYBEVOID
);
232 addDateTimePropertyDescription( aProperties
, PROPERTY_XSD_MIN_INCLUSIVE_DATE_TIME
, MAYBEVOID
);
233 addDateTimePropertyDescription( aProperties
, PROPERTY_XSD_MIN_EXCLUSIVE_DATE_TIME
, MAYBEVOID
);
237 if ( aProperties
.empty() )
238 return Sequence
< Property
>();
239 return Sequence
< Property
>( &(*aProperties
.begin()), aProperties
.size() );
242 //--------------------------------------------------------------------
243 Sequence
< ::rtl::OUString
> SAL_CALL
XSDValidationPropertyHandler::getSupersededProperties( ) throw (RuntimeException
)
245 ::osl::MutexGuard
aGuard( m_aMutex
);
247 ::std::vector
< ::rtl::OUString
> aSuperfluous
;
248 if ( m_pHelper
.get() )
250 aSuperfluous
.push_back( PROPERTY_CONTROLSOURCE
);
251 aSuperfluous
.push_back( PROPERTY_EMPTY_IS_NULL
);
252 aSuperfluous
.push_back( PROPERTY_FILTERPROPOSAL
);
253 aSuperfluous
.push_back( PROPERTY_LISTSOURCETYPE
);
254 aSuperfluous
.push_back( PROPERTY_LISTSOURCE
);
255 aSuperfluous
.push_back( PROPERTY_BOUNDCOLUMN
);
257 bool bAllowBinding
= m_pHelper
->canBindToAnyDataType();
261 aSuperfluous
.push_back( PROPERTY_MAXTEXTLEN
);
262 aSuperfluous
.push_back( PROPERTY_VALUEMIN
);
263 aSuperfluous
.push_back( PROPERTY_VALUEMAX
);
264 aSuperfluous
.push_back( PROPERTY_DECIMAL_ACCURACY
);
265 aSuperfluous
.push_back( PROPERTY_TIMEMIN
);
266 aSuperfluous
.push_back( PROPERTY_TIMEMAX
);
267 aSuperfluous
.push_back( PROPERTY_DATEMIN
);
268 aSuperfluous
.push_back( PROPERTY_DATEMAX
);
269 aSuperfluous
.push_back( PROPERTY_EFFECTIVE_MIN
);
270 aSuperfluous
.push_back( PROPERTY_EFFECTIVE_MAX
);
274 if ( aSuperfluous
.empty() )
275 return Sequence
< ::rtl::OUString
>();
276 return Sequence
< ::rtl::OUString
>( &(*aSuperfluous
.begin()), aSuperfluous
.size() );
279 //--------------------------------------------------------------------
280 Sequence
< ::rtl::OUString
> SAL_CALL
XSDValidationPropertyHandler::getActuatingProperties( ) throw (RuntimeException
)
282 ::osl::MutexGuard
aGuard( m_aMutex
);
283 ::std::vector
< ::rtl::OUString
> aInterestedInActuations( 2 );
284 if ( m_pHelper
.get() )
286 aInterestedInActuations
.push_back( PROPERTY_XSD_DATA_TYPE
);
287 aInterestedInActuations
.push_back( PROPERTY_XML_DATA_MODEL
);
289 if ( aInterestedInActuations
.empty() )
290 return Sequence
< ::rtl::OUString
>();
291 return Sequence
< ::rtl::OUString
>( &(*aInterestedInActuations
.begin()), aInterestedInActuations
.size() );
294 //--------------------------------------------------------------------
297 void showPropertyUI( const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, const ::rtl::OUString
& _rPropertyName
, bool _bShow
)
300 _rxInspectorUI
->showPropertyUI( _rPropertyName
);
302 _rxInspectorUI
->hidePropertyUI( _rPropertyName
);
306 //--------------------------------------------------------------------
307 LineDescriptor SAL_CALL
XSDValidationPropertyHandler::describePropertyLine( const ::rtl::OUString
& _rPropertyName
,
308 const Reference
< XPropertyControlFactory
>& _rxControlFactory
)
309 throw (UnknownPropertyException
, NullPointerException
, RuntimeException
)
311 ::osl::MutexGuard
aGuard( m_aMutex
);
312 if ( !_rxControlFactory
.is() )
313 throw NullPointerException();
314 if ( !m_pHelper
.get() )
315 throw RuntimeException();
317 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
319 LineDescriptor aDescriptor
;
320 if ( nPropId
!= PROPERTY_ID_XSD_DATA_TYPE
)
321 aDescriptor
.IndentLevel
= 1;
323 // collect some information about the to-be-created control
324 sal_Int16 nControlType
= PropertyControlType::TextField
;
325 ::std::vector
< ::rtl::OUString
> aListEntries
;
326 Optional
< double > aMinValue( sal_False
, 0 );
327 Optional
< double > aMaxValue( sal_False
, 0 );
331 case PROPERTY_ID_XSD_DATA_TYPE
:
332 nControlType
= PropertyControlType::ListBox
;
334 implGetAvailableDataTypeNames( aListEntries
);
336 aDescriptor
.PrimaryButtonId
= UID_PROP_ADD_DATA_TYPE
;
337 aDescriptor
.SecondaryButtonId
= UID_PROP_REMOVE_DATA_TYPE
;
338 aDescriptor
.HasPrimaryButton
= aDescriptor
.HasSecondaryButton
= sal_True
;
339 aDescriptor
.PrimaryButtonImageURL
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/extensions/res/buttonplus.png" ) );
340 aDescriptor
.SecondaryButtonImageURL
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/extensions/res/buttonminus.png" ) );
343 case PROPERTY_ID_XSD_WHITESPACES
:
345 nControlType
= PropertyControlType::ListBox
;
346 aListEntries
= m_pInfoService
->getPropertyEnumRepresentations( PROPERTY_ID_XSD_WHITESPACES
);
350 case PROPERTY_ID_XSD_PATTERN
:
351 nControlType
= PropertyControlType::TextField
;
354 case PROPERTY_ID_XSD_LENGTH
:
355 case PROPERTY_ID_XSD_MIN_LENGTH
:
356 case PROPERTY_ID_XSD_MAX_LENGTH
:
357 nControlType
= PropertyControlType::NumericField
;
360 case PROPERTY_ID_XSD_TOTAL_DIGITS
:
361 case PROPERTY_ID_XSD_FRACTION_DIGITS
:
362 nControlType
= PropertyControlType::NumericField
;
365 case PROPERTY_ID_XSD_MAX_INCLUSIVE_INT
:
366 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_INT
:
367 case PROPERTY_ID_XSD_MIN_INCLUSIVE_INT
:
368 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_INT
:
370 nControlType
= PropertyControlType::NumericField
;
372 // handle limits for various 'INT' types according to
373 // their actual semantics (year, month, day)
375 ::rtl::Reference
< XSDDataType
> xDataType( m_pHelper
->getValidatingDataType() );
376 sal_Int16 nTypeClass
= xDataType
.is() ? xDataType
->classify() : DataTypeClass::STRING
;
378 aMinValue
.IsPresent
= aMaxValue
.IsPresent
= sal_True
;
379 aMinValue
.Value
= DataTypeClass::gYear
== nTypeClass
? 0 : 1;
380 aMaxValue
.Value
= ::std::numeric_limits
< sal_Int32
>::max();
381 if ( DataTypeClass::gMonth
== nTypeClass
)
382 aMaxValue
.Value
= 12;
383 else if ( DataTypeClass::gDay
== nTypeClass
)
384 aMaxValue
.Value
= 31;
388 case PROPERTY_ID_XSD_MAX_INCLUSIVE_DOUBLE
:
389 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DOUBLE
:
390 case PROPERTY_ID_XSD_MIN_INCLUSIVE_DOUBLE
:
391 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DOUBLE
:
392 nControlType
= PropertyControlType::NumericField
;
393 // TODO/eForms: do we have "auto-digits"?
396 case PROPERTY_ID_XSD_MAX_INCLUSIVE_DATE
:
397 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DATE
:
398 case PROPERTY_ID_XSD_MIN_INCLUSIVE_DATE
:
399 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DATE
:
400 nControlType
= PropertyControlType::DateField
;
403 case PROPERTY_ID_XSD_MAX_INCLUSIVE_TIME
:
404 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_TIME
:
405 case PROPERTY_ID_XSD_MIN_INCLUSIVE_TIME
:
406 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_TIME
:
407 nControlType
= PropertyControlType::TimeField
;
410 case PROPERTY_ID_XSD_MAX_INCLUSIVE_DATE_TIME
:
411 case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DATE_TIME
:
412 case PROPERTY_ID_XSD_MIN_INCLUSIVE_DATE_TIME
:
413 case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DATE_TIME
:
414 nControlType
= PropertyControlType::DateTimeField
;
418 DBG_ERROR( "XSDValidationPropertyHandler::describePropertyLine: cannot handle this property!" );
422 switch ( nControlType
)
424 case PropertyControlType::ListBox
:
425 aDescriptor
.Control
= PropertyHandlerHelper::createListBoxControl( _rxControlFactory
, aListEntries
, sal_False
, sal_False
);
427 case PropertyControlType::NumericField
:
428 aDescriptor
.Control
= PropertyHandlerHelper::createNumericControl( _rxControlFactory
, 0, aMinValue
, aMaxValue
, sal_False
);
431 aDescriptor
.Control
= _rxControlFactory
->createPropertyControl( nControlType
, sal_False
);
435 aDescriptor
.Category
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Data" ) );
436 aDescriptor
.DisplayName
= m_pInfoService
->getPropertyTranslation( nPropId
);
437 aDescriptor
.HelpURL
= HelpIdUrl::getHelpURL( m_pInfoService
->getPropertyHelpId( nPropId
) );
442 //--------------------------------------------------------------------
443 InteractiveSelectionResult SAL_CALL
XSDValidationPropertyHandler::onInteractivePropertySelection( const ::rtl::OUString
& _rPropertyName
, sal_Bool _bPrimary
, Any
& /*_rData*/, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
) throw (UnknownPropertyException
, NullPointerException
, RuntimeException
)
445 if ( !_rxInspectorUI
.is() )
446 throw NullPointerException();
448 ::osl::MutexGuard
aGuard( m_aMutex
);
449 OSL_ENSURE( m_pHelper
.get(), "XSDValidationPropertyHandler::onInteractivePropertySelection: we don't have any SupportedProperties!" );
450 if ( !m_pHelper
.get() )
451 return InteractiveSelectionResult_Cancelled
;
453 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
457 case PROPERTY_ID_XSD_DATA_TYPE
:
461 ::rtl::OUString sNewDataTypeName
;
462 if ( implPrepareCloneDataCurrentType( sNewDataTypeName
) )
464 implDoCloneCurrentDataType( sNewDataTypeName
);
465 return InteractiveSelectionResult_Success
;
469 return implPrepareRemoveCurrentDataType() && implDoRemoveCurrentDataType() ? InteractiveSelectionResult_Success
: InteractiveSelectionResult_Cancelled
;
474 DBG_ERROR( "XSDValidationPropertyHandler::onInteractivePropertySelection: unexpected property to build a dedicated UI!" );
477 return InteractiveSelectionResult_Cancelled
;
480 //--------------------------------------------------------------------
481 void SAL_CALL
XSDValidationPropertyHandler::addPropertyChangeListener( const Reference
< XPropertyChangeListener
>& _rxListener
) throw (RuntimeException
)
483 ::osl::MutexGuard
aGuard( m_aMutex
);
484 XSDValidationPropertyHandler_Base::addPropertyChangeListener( _rxListener
);
485 if ( m_pHelper
.get() )
486 m_pHelper
->registerBindingListener( _rxListener
);
489 //--------------------------------------------------------------------
490 void SAL_CALL
XSDValidationPropertyHandler::removePropertyChangeListener( const Reference
< XPropertyChangeListener
>& _rxListener
) throw (RuntimeException
)
492 ::osl::MutexGuard
aGuard( m_aMutex
);
493 if ( m_pHelper
.get() )
494 m_pHelper
->revokeBindingListener( _rxListener
);
495 XSDValidationPropertyHandler_Base::removePropertyChangeListener( _rxListener
);
498 //--------------------------------------------------------------------
499 bool XSDValidationPropertyHandler::implPrepareCloneDataCurrentType( ::rtl::OUString
& _rNewName
) SAL_THROW(())
501 OSL_PRECOND( m_pHelper
.get(), "XSDValidationPropertyHandler::implPrepareCloneDataCurrentType: this will crash!" );
503 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getValidatingDataType();
506 DBG_ERROR( "XSDValidationPropertyHandler::implPrepareCloneDataCurrentType: invalid current data type!" );
510 ::std::vector
< ::rtl::OUString
> aExistentNames
;
511 m_pHelper
->getAvailableDataTypeNames( aExistentNames
);
513 NewDataTypeDialog
aDialog( NULL
, pType
->getName(), aExistentNames
); // TODO/eForms: proper parent
514 if ( aDialog
.Execute() != RET_OK
)
517 _rNewName
= aDialog
.GetName();
521 //--------------------------------------------------------------------
522 bool XSDValidationPropertyHandler::implDoCloneCurrentDataType( const ::rtl::OUString
& _rNewName
) SAL_THROW(())
524 OSL_PRECOND( m_pHelper
.get(), "XSDValidationPropertyHandler::implDoCloneCurrentDataType: this will crash!" );
526 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getValidatingDataType();
530 if ( !m_pHelper
->cloneDataType( pType
, _rNewName
) )
533 m_pHelper
->setValidatingDataTypeByName( _rNewName
);
537 //--------------------------------------------------------------------
538 bool XSDValidationPropertyHandler::implPrepareRemoveCurrentDataType() SAL_THROW(())
540 OSL_PRECOND( m_pHelper
.get(), "XSDValidationPropertyHandler::implPrepareRemoveCurrentDataType: this will crash!" );
542 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getValidatingDataType();
545 DBG_ERROR( "XSDValidationPropertyHandler::implPrepareRemoveCurrentDataType: invalid current data type!" );
549 // confirmation message
550 String
sConfirmation( PcrRes( RID_STR_CONFIRM_DELETE_DATA_TYPE
) );
551 sConfirmation
.SearchAndReplaceAscii( "#type#", pType
->getName() );
552 QueryBox
aQuery( NULL
, WB_YES_NO
, sConfirmation
); // TODO/eForms: proper parent
553 if ( aQuery
.Execute() != RET_YES
)
559 //--------------------------------------------------------------------
560 bool XSDValidationPropertyHandler::implDoRemoveCurrentDataType() SAL_THROW(())
562 OSL_PRECOND( m_pHelper
.get(), "XSDValidationPropertyHandler::implDoRemoveCurrentDataType: this will crash!" );
564 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getValidatingDataType();
568 // set a new data type at the binding, which is the "basic" type for the one
569 // we are going to delete
570 // (do this before the actual deletion, so the old type is still valid for property change
572 m_pHelper
->setValidatingDataTypeByName( m_pHelper
->getBasicTypeNameForClass( pType
->classify() ) );
573 // now remove the type
574 m_pHelper
->removeDataTypeFromRepository( pType
->getName() );
579 //--------------------------------------------------------------------
580 void SAL_CALL
XSDValidationPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString
& _rActuatingPropertyName
, const Any
& _rNewValue
, const Any
& _rOldValue
, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, sal_Bool _bFirstTimeInit
) throw (NullPointerException
, RuntimeException
)
582 if ( !_rxInspectorUI
.is() )
583 throw NullPointerException();
585 ::osl::MutexGuard
aGuard( m_aMutex
);
586 PropertyId
nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName
) );
587 if ( !m_pHelper
.get() )
588 throw RuntimeException();
589 // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
591 switch ( nActuatingPropId
)
593 case PROPERTY_ID_XSD_DATA_TYPE
:
595 ::rtl::Reference
< XSDDataType
> xDataType( m_pHelper
->getValidatingDataType() );
597 // is removal of this type possible?
598 sal_Bool bIsBasicType
= xDataType
.is() && xDataType
->isBasicType();
599 _rxInspectorUI
->enablePropertyUIElements( PROPERTY_XSD_DATA_TYPE
, PropertyLineElement::PrimaryButton
, xDataType
.is() );
600 _rxInspectorUI
->enablePropertyUIElements( PROPERTY_XSD_DATA_TYPE
, PropertyLineElement::SecondaryButton
, xDataType
.is() && !bIsBasicType
);
602 //------------------------------------------------------------
603 // show the facets which are available at the data type
604 ::rtl::OUString aFacets
[] = {
605 PROPERTY_XSD_WHITESPACES
, PROPERTY_XSD_PATTERN
,
606 PROPERTY_XSD_LENGTH
, PROPERTY_XSD_MIN_LENGTH
, PROPERTY_XSD_MAX_LENGTH
, PROPERTY_XSD_TOTAL_DIGITS
,
607 PROPERTY_XSD_FRACTION_DIGITS
,
608 PROPERTY_XSD_MAX_INCLUSIVE_INT
,
609 PROPERTY_XSD_MAX_EXCLUSIVE_INT
,
610 PROPERTY_XSD_MIN_INCLUSIVE_INT
,
611 PROPERTY_XSD_MIN_EXCLUSIVE_INT
,
612 PROPERTY_XSD_MAX_INCLUSIVE_DOUBLE
,
613 PROPERTY_XSD_MAX_EXCLUSIVE_DOUBLE
,
614 PROPERTY_XSD_MIN_INCLUSIVE_DOUBLE
,
615 PROPERTY_XSD_MIN_EXCLUSIVE_DOUBLE
,
616 PROPERTY_XSD_MAX_INCLUSIVE_DATE
,
617 PROPERTY_XSD_MAX_EXCLUSIVE_DATE
,
618 PROPERTY_XSD_MIN_INCLUSIVE_DATE
,
619 PROPERTY_XSD_MIN_EXCLUSIVE_DATE
,
620 PROPERTY_XSD_MAX_INCLUSIVE_TIME
,
621 PROPERTY_XSD_MAX_EXCLUSIVE_TIME
,
622 PROPERTY_XSD_MIN_INCLUSIVE_TIME
,
623 PROPERTY_XSD_MIN_EXCLUSIVE_TIME
,
624 PROPERTY_XSD_MAX_INCLUSIVE_DATE_TIME
,
625 PROPERTY_XSD_MAX_EXCLUSIVE_DATE_TIME
,
626 PROPERTY_XSD_MIN_INCLUSIVE_DATE_TIME
,
627 PROPERTY_XSD_MIN_EXCLUSIVE_DATE_TIME
631 const ::rtl::OUString
* pLoop
= NULL
;
632 for ( i
= 0, pLoop
= aFacets
;
633 i
< SAL_N_ELEMENTS( aFacets
);
637 showPropertyUI( _rxInspectorUI
, *pLoop
, xDataType
.is() && xDataType
->hasFacet( *pLoop
) );
638 _rxInspectorUI
->enablePropertyUI( *pLoop
, !bIsBasicType
);
643 case PROPERTY_ID_XML_DATA_MODEL
:
645 // The data type which the current binding works with may not be present in the
646 // new model. Thus, transfer it.
647 ::rtl::OUString sOldModelName
; _rOldValue
>>= sOldModelName
;
648 ::rtl::OUString sNewModelName
; _rNewValue
>>= sNewModelName
;
649 ::rtl::OUString sDataType
= m_pHelper
->getValidatingDataTypeName();
650 m_pHelper
->copyDataType( sOldModelName
, sNewModelName
, sDataType
);
652 // the list of available data types depends on the chosen model, so update this
653 if ( !_bFirstTimeInit
)
654 _rxInspectorUI
->rebuildPropertyUI( PROPERTY_XSD_DATA_TYPE
);
659 DBG_ERROR( "XSDValidationPropertyHandler::actuatingPropertyChanged: cannot handle this property!" );
663 // in both cases, we need to care for the current value of the XSD_DATA_TYPE property,
664 // and update the FormatKey of the formatted field we're inspecting (if any)
665 if ( !_bFirstTimeInit
&& m_pHelper
->isInspectingFormattedField() )
666 m_pHelper
->findDefaultFormatForIntrospectee();
669 //--------------------------------------------------------------------
670 void XSDValidationPropertyHandler::implGetAvailableDataTypeNames( ::std::vector
< ::rtl::OUString
>& /* [out] */ _rNames
) const SAL_THROW(())
672 OSL_PRECOND( m_pHelper
.get(), "XSDValidationPropertyHandler::implGetAvailableDataTypeNames: this will crash!" );
673 // start with *all* types which are available at the model
674 ::std::vector
< ::rtl::OUString
> aAllTypes
;
675 m_pHelper
->getAvailableDataTypeNames( aAllTypes
);
677 _rNames
.reserve( aAllTypes
.size() );
679 // then allow only those which are "compatible" with our control
680 for ( ::std::vector
< ::rtl::OUString
>::const_iterator dataType
= aAllTypes
.begin();
681 dataType
!= aAllTypes
.end();
685 ::rtl::Reference
< XSDDataType
> pType
= m_pHelper
->getDataTypeByName( *dataType
);
686 if ( pType
.is() && m_pHelper
->canBindToDataType( pType
->classify() ) )
687 _rNames
.push_back( *dataType
);
691 //........................................................................
693 //........................................................................
695 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */