From 569298eb9be776e134d64ca2025b14e8394c6e9b Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Tue, 30 Sep 2014 12:33:10 +0000 Subject: [PATCH] - Derive DerivedAnnotationValueProviderBase from EStructuralFeatureValueProviderBase - Add constructor to DerivedAnnotationValueProviderBase that eases to build "mixed" annotations, i.e. those that provide one derived / calculated value, and one or more values backed by EStructuralFeatures refs 1841 --- .../DerivedAnnotationValueProviderBase.java | 81 ++++++++++++++++--- 1 file changed, 70 insertions(+), 11 deletions(-) diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/DerivedAnnotationValueProviderBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/DerivedAnnotationValueProviderBase.java index fa5e9ab78..8a8cd835b 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/DerivedAnnotationValueProviderBase.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/DerivedAnnotationValueProviderBase.java @@ -17,7 +17,12 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.base.ui.annotation.valueprovider; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.jface.viewers.ColumnViewer; import org.eclipse.jface.viewers.EditingSupport; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; @@ -33,38 +38,92 @@ import org.fortiss.tooling.base.model.element.IDerivedAnnotation; * @ConQAT.Rating RED Hash: */ public abstract class DerivedAnnotationValueProviderBase<T extends IDerivedAnnotation<?>> extends - ValueProviderBase<T> { + EStructuralFeatureValueProviderBase<T> { + + /** Key representing the derived / calculated value. */ + private String derivedKey; + + /** List of all supported instance keys. */ + private List<String> keys = new ArrayList<String>(); /** - * Constructs a {@link IAnnotationValueProvider} for derived annotations (i.e., based on - * {@link IDerivedAnnotation}). + * Constructs a {@link IAnnotationValueProvider} for a pure derived annotations (i.e., an + * {@link IDerivedAnnotation} that does not contain any additional {@link EStructuralFeature}s. */ public DerivedAnnotationValueProviderBase(EClass annotatedSpecificationEClass) { super(annotatedSpecificationEClass); + handlesMultipleEstructuralFeatures = false; + derivedKey = DEFAULT_KEY; + + keys.add(DEFAULT_KEY); + } + + /** + * Constructs a {@link IAnnotationValueProvider} for a derived annotations (i.e., based on an + * {@link IDerivedAnnotation}) contains additional {@link EStructuralFeature}s. + * + * @param annotatedSpecificationEClass + * {@link EClass} implementing the annotation + * @param structuralFeatureMap + * map: instance key -> values provided by {@link EStructuralFeature}s + * @param derivedKey + * key representing the derived / calculated value (must not be contained in + * structuralFeatureMap). + */ + public DerivedAnnotationValueProviderBase(EClass annotatedSpecificationEClass, + Map<String, EStructuralFeature> structuralFeatureMap, String derivedKey) { + super(annotatedSpecificationEClass, structuralFeatureMap); + + this.derivedKey = derivedKey; + keys.addAll(structuralFeatureMap.keySet()); + keys.add(derivedKey); + + } + + /** + * Predicate if the given instanceKey is the key representing the derived / calculated value + * provided by this {@link IAnnotationValueProvider}. + */ + private boolean isDerivedKey(String instanceKey) { + return (instanceKey == DEFAULT_KEY) || (instanceKey.equals(derivedKey)); } /** {@inheritDoc} */ @Override public boolean canEdit(T specification, String instanceKey) { - return false; + if(isDerivedKey(instanceKey)) { + return false; + } + return super.canEdit(specification, instanceKey); } /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override - public <U> U getAnnotationValue(T specification) { - // Delegate retrieval of annotation value to {@link EOperation} to be provided for the - // concrete @link DerivedAnnotationBase}. - return (U)specification.getValue(); + public <U> U getAnnotationValue(T specification, String instanceKey) throws Exception { + if(isDerivedKey(instanceKey)) { + return (U)specification.getValue(); + } + + return super.getAnnotationValue(specification, instanceKey); } /** {@inheritDoc} */ @Override public EditingSupport createEditingSupport(ColumnViewer viewer, - Class<? extends IAnnotatedSpecification> clazz, String instanceKey) { + Class<? extends IAnnotatedSpecification> clazz, String instanceKey) throws Exception { - // Derived annotations are results of calculations can thus cannot be edited. - return null; + if(isDerivedKey(instanceKey)) { + return null; + } + + return super.createEditingSupport(viewer, clazz, instanceKey); + } + + /** {@inheritDoc} */ + @Override + public List<String> getInstanceKeys(T specification) { + return keys; } } -- GitLab