Skip to content
Snippets Groups Projects
Commit 569298eb authored by Simon Barner's avatar Simon Barner
Browse files

- 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
parent a468781d
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment