diff options
3 files changed, 67 insertions, 6 deletions
diff --git a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/validation/DelegatingConstraintProvider.java b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/validation/DelegatingConstraintProvider.java index 931b4f9f..d17e45b9 100644 --- a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/validation/DelegatingConstraintProvider.java +++ b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/validation/DelegatingConstraintProvider.java @@ -93,10 +93,13 @@ public class DelegatingConstraintProvider UMLPlugin.INSTANCE.getSymbolicName(), "No generated validator available for package: " + next)); //$NON-NLS-1$ } else { + EValidator.SubstitutionLabelProvider labelProvider = validatorProvider + .getSubstitutionLabelProvider(epackage); + try { Iterable<? extends IModelConstraint> constraints = createConstraints( config.getNamespaceIdentifier(), epackage, - validator); + validator, labelProvider); if (!categories.isEmpty()) { Category[] cats = categories @@ -164,7 +167,8 @@ public class DelegatingConstraintProvider private Iterable<? extends IModelConstraint> createConstraints( final String namespace, final EPackage epackage, - final EValidator validator) + final EValidator validator, + final EValidator.SubstitutionLabelProvider labelProvider) throws ConstraintExistsException { final List<IModelConstraint> result = new java.util.ArrayList<IModelConstraint>(); @@ -185,7 +189,7 @@ public class DelegatingConstraintProvider // framework doesn't handle them if (eclass != null) { result.add(new DelegatingModelConstraint(namespace, - validator, eclass, next)); + validator, labelProvider, eclass, next)); } } } diff --git a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/validation/DelegatingModelConstraint.java b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/validation/DelegatingModelConstraint.java index deff6bf3..5d6f381f 100644 --- a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/validation/DelegatingModelConstraint.java +++ b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/validation/DelegatingModelConstraint.java @@ -21,6 +21,7 @@ import org.eclipse.emf.common.util.Diagnostic; import org.eclipse.emf.common.util.DiagnosticChain; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.EValidator; import org.eclipse.emf.validation.IValidationContext; import org.eclipse.emf.validation.model.ConstraintStatus; @@ -40,13 +41,16 @@ class DelegatingModelConstraint private final EValidator delegate; + private final EValidator.SubstitutionLabelProvider labelProvider; + private final Method constraintMethod; /** * Initializes me. */ DelegatingModelConstraint(String namespace, EValidator delegate, - EClass target, Method constraintMethod) { + EValidator.SubstitutionLabelProvider labelProvider, EClass target, + Method constraintMethod) { // strip the type-qualifying part off of the validator method name String name = constraintMethod.getName(); String expectedPrefix = String.format("validate%s_validate", //$NON-NLS-1$ @@ -58,6 +62,7 @@ class DelegatingModelConstraint this.descriptor = new DelegatingConstraintDescriptor(namespace, target, name); this.delegate = delegate; + this.labelProvider = labelProvider; this.constraintMethod = constraintMethod; } @@ -73,6 +78,10 @@ class DelegatingModelConstraint final Map<Object, Object> contextMap = ctxAdapter.getContextMap(); try { + // pass the label provider (if any) to the validator + contextMap.put(EValidator.SubstitutionLabelProvider.class, + labelProvider); + boolean isOK = (Boolean) constraintMethod.invoke(delegate, ctx.getTarget(), diagnostics, contextMap); diff --git a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/validation/IEValidatorProvider.java b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/validation/IEValidatorProvider.java index fb380c0d..c69b6751 100644 --- a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/validation/IEValidatorProvider.java +++ b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/validation/IEValidatorProvider.java @@ -10,9 +10,15 @@ */ package org.eclipse.uml2.uml.validation; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.EValidator; +import org.eclipse.emf.ecore.EValidator.SubstitutionLabelProvider; +import org.eclipse.emf.ecore.util.Diagnostician; import org.eclipse.uml2.uml.UMLPackage; +import org.eclipse.uml2.uml.util.UMLUtil; import org.eclipse.uml2.uml.util.UMLValidator; /** @@ -31,6 +37,19 @@ public interface IEValidatorProvider { */ EValidator getEValidator(EPackage ePackage); + /** + * Obtains an appropriate substitution-label provider for presentation of + * element names in validation of elements of the specified {@code ePackage} + * . + * + * @param ePackage + * a package for which to obtain a substitution-label provider + * + * @return a suitable provider, or @{code null} if none could be found + */ + EValidator.SubstitutionLabelProvider getSubstitutionLabelProvider( + EPackage ePackage); + // // Nested types // @@ -45,11 +64,40 @@ public interface IEValidatorProvider { public EValidator getEValidator(EPackage ePackage) { return EValidator.Registry.INSTANCE.getEValidator(ePackage); } + + public SubstitutionLabelProvider getSubstitutionLabelProvider( + EPackage ePackage) { + + return new EValidator.SubstitutionLabelProvider() { + + public String getObjectLabel(EObject eObject) { + String result = UMLUtil.getQualifiedText(eObject); + + if ((result == null) || (result.length() == 0)) { + result = Diagnostician.INSTANCE.getObjectLabel(eObject); + } + + return result; + } + + public String getFeatureLabel( + EStructuralFeature eStructuralFeature) { + + return Diagnostician.INSTANCE + .getFeatureLabel(eStructuralFeature); + } + + public String getValueLabel(EDataType eDataType, Object value) { + return Diagnostician.INSTANCE.getValueLabel(eDataType, + value); + } + }; + } } /** - * The UML {@link EValidator} maps the UML package to the standard UML - * validator. For other packageos, uses the validator registry to look up + * The UML {@link IEValidatorProvider} maps the UML package to the standard UML + * validator. For other packages, uses the validator registry to look up * whatever validator is there. */ class UML |