Skip to content
Snippets Groups Projects
Commit 10361bb8 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Extends the Derived annotation, such that element-specfic values can be...

Extends the Derived annotation, such that element-specfic values can be returned; Useful for aggregate annotations.
refs 2150
parent fa3a0ee7
No related branches found
No related tags found
No related merge requests found
Showing
with 137 additions and 24 deletions
......@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
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;
......@@ -158,6 +159,25 @@ public final class AnnotationEntry {
return null;
}
/**
* Returns the {@link EStructuralFeature} that is returned whenever the value is retrieved by
* the given specification of this {@link AnnotationEntry}.
*/
public EStructuralFeature getSpecificationElementFeature(
Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
try {
return providerSpecMapping.get(clazz).getEStructuralFeatureOf(s);
} catch(Exception e) {
// Ignore exception
}
}
}
return null;
}
/**
* Sets a new value for the given specification clazz.
*/
......@@ -229,7 +249,7 @@ public final class AnnotationEntry {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
return providerSpecMapping.get(clazz).createEditingSupport(viewer, clazz,
instanceKey);
instanceKey, getSpecificationElementFeature(clazz));
}
}
......
......@@ -19,6 +19,7 @@ package org.fortiss.tooling.base.ui.annotation.editingsupport;
import java.util.Collection;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
......@@ -117,7 +118,8 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase {
}
comboBoxLabelValueMapping =
createComboBoxLabelValueMapping(((AnnotationEntry)element).getModelElement());
createComboBoxLabelValueMapping(((AnnotationEntry)element).getModelElement(),
((AnnotationEntry)element).getSpecificationElementFeature(specClass));
cellEditor.setInput(comboBoxLabelValueMapping.getLabels());
......@@ -128,9 +130,12 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase {
* Creates a {@link ComboBoxLabelValueMapping} for the annotation shown in this
* {@link ComboBoxEditingSupport}.
*/
public ComboBoxLabelValueMapping createComboBoxLabelValueMapping(EObject modelElement) {
return new ComboBoxLabelValueMapping(eStructuralFeatureDescriptor, modelElement,
stringInputChoice);
public ComboBoxLabelValueMapping createComboBoxLabelValueMapping(EObject modelElement,
EStructuralFeature feature) {
// TODO: AD: Make the creation of the feature descriptor dependent on the need for supporting multiple features.
// Remove the cast.
return new ComboBoxLabelValueMapping(new EStructuralFeatureDescriptor((EAttribute)feature),
modelElement, stringInputChoice);
}
/** {@inheritDoc} */
......
......@@ -124,7 +124,7 @@ public abstract class DerivedAnnotationValueProviderBase<T extends IDerivedAnnot
/** {@inheritDoc} */
@Override
public boolean canEdit(T specification, String instanceKey) {
if(isDerivedKey(instanceKey)) {
if(isDerivedKey(instanceKey) && !isEditableByUser) {
return false;
}
return super.canEdit(specification, instanceKey);
......@@ -146,16 +146,55 @@ public abstract class DerivedAnnotationValueProviderBase<T extends IDerivedAnnot
return super.getAnnotationValue(specification, instanceKey);
}
/** {@inheritDoc} */
@Override
public <U> void setAnnotationValue(U value, T specification, String instanceKey)
throws Exception {
if(isDerivedKey(instanceKey) && specification.getDerivedFeature() != null) {
specification.eSet(specification.getDerivedFeature(), value);
return;
}
super.setAnnotationValue(value, specification, instanceKey);
}
/** {@inheritDoc} */
@Override
public EStructuralFeature getEStructuralFeatureOf(T specification) {
if(specification != null) {
return specification.getDerivedFeature();
}
return null;
}
/** {@inheritDoc} */
@Override
public EditingSupport createEditingSupport(ColumnViewer viewer,
Class<? extends IAnnotatedSpecification> clazz, String instanceKey) throws Exception {
Class<? extends IAnnotatedSpecification> clazz, String instanceKey,
EStructuralFeature structuralFeature) throws Exception {
if(isDerivedKey(instanceKey) && !isEditableByUser) {
return null;
}
return super.createEditingSupport(viewer, clazz, instanceKey);
return super.createEditingSupport(viewer, clazz, instanceKey, structuralFeature);
}
/**
* Determines the {@link EStructuralFeature}s of the {@link IDerivedAnnotation}. This methods
* handles the case in which a specification returns different features dependent on the model
* type. Otherwise, the logic o {@link EStructuralFeatureValueProviderBase} is used.
*/
protected EStructuralFeature getEStructuralFeature(T specification, String instanceKey)
throws Exception {
if(specification != null) {
EStructuralFeature feature = specification.getDerivedFeature();
if(feature != null) {
return feature;
}
}
return super.getEStructuralFeature(instanceKey);
}
/** {@inheritDoc} */
......
......@@ -27,6 +27,7 @@ import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EReference;
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;
......@@ -148,7 +149,8 @@ public abstract class DynamicInstanceAnnotationValueProviderBase<T extends IAnno
/** {@inheritDoc} */
@Override
public EditingSupport createEditingSupport(ColumnViewer viewer,
Class<? extends IAnnotatedSpecification> clazz, String instanceKey) {
Class<? extends IAnnotatedSpecification> clazz, String instanceKey,
EStructuralFeature structralFeature) {
return new TextEditingSupport(viewer, clazz, instanceKey);
}
......
......@@ -295,18 +295,22 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp
/** {@inheritDoc} */
@Override
public EditingSupport createEditingSupport(ColumnViewer viewer,
Class<? extends IAnnotatedSpecification> clazz, String instanceKey) throws Exception {
Class<? extends IAnnotatedSpecification> clazz, String instanceKey,
EStructuralFeature structuralFeature) throws Exception {
EStructuralFeature feature = structuralFeature;
if(feature == null) {
feature = getEStructuralFeature(instanceKey);
}
EStructuralFeature structuralFeature = getEStructuralFeature(instanceKey);
if(structuralFeature.getUpperBound() > 1 ||
structuralFeature.getUpperBound() == ETypedElement.UNBOUNDED_MULTIPLICITY) {
if(feature.getUpperBound() > 1 ||
feature.getUpperBound() == ETypedElement.UNBOUNDED_MULTIPLICITY) {
throw new Exception(
"EStructuralValueProvider has not been implemented for structural feature multiplicity > 1.");
}
EClassifier eType = null;
try {
eType = structuralFeature.getEType();
eType = feature.getEType();
} catch(Exception e) {
// Ignore
}
......@@ -315,11 +319,23 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp
((eType instanceof EClass) && (structuralFeatureDescriptorMap.get(instanceKey)
.getEReferenceScope() == null))) {
return super.createEditingSupport(viewer, clazz, instanceKey);
return super.createEditingSupport(viewer, clazz, instanceKey, null);
}
return new ComboBoxEditingSupport(viewer, clazz, instanceKey,
structuralFeatureDescriptorMap.get(instanceKey));
// Create a new EStructuralFeatureDescriptor for specifications that return different
// features per model element.
EStructuralFeatureDescriptor descriptor = null;
if(structuralFeature != null) {
if(feature instanceof EAttribute) {
descriptor = new EStructuralFeatureDescriptor((EAttribute)feature);
} else {
throw new Exception(
"Creating EStructuralFeature-dependent EditingSupports is not implemented for features that are not of the tye EAttribute.");
}
} else {
descriptor = structuralFeatureDescriptorMap.get(instanceKey);
}
return new ComboBoxEditingSupport(viewer, clazz, instanceKey, descriptor);
}
/**
......
......@@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
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;
......@@ -94,6 +95,14 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext
*/
public <U> U getAnnotationValue(T specification, String instanceKey) throws Exception;
/**
* Returns the {@link EStructuralFeature} which is the return values of the given
* specification. This function is useful, if different features are returned depending on the
* model element this specification is attached to. Otherwise, the {@link EStructuralFeature}s
* can be obtained via the annotation class type.
*/
public EStructuralFeature getEStructuralFeatureOf(T specification) throws Exception;
/**
* Sets a new value for the annotation.
*
......@@ -150,7 +159,8 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext
* {@link IAnnotatedSpecification}.
*/
public EditingSupport createEditingSupport(ColumnViewer viewer,
Class<? extends IAnnotatedSpecification> clazz, String instanceKey) throws Exception;
Class<? extends IAnnotatedSpecification> clazz, String instanceKey,
EStructuralFeature structuralFeature) throws Exception;
/**
* Factory method that creates a new {@link IAnnotatedSpecification} specialization of type T to
......
......@@ -32,6 +32,7 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EObject;
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;
......@@ -116,6 +117,14 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple
return getAnnotationValue(specification);
}
/** {@inheritDoc} */
@Override
public EStructuralFeature getEStructuralFeatureOf(T specification) throws Exception {
throw new Exception(
"getEStructuralFeatureOf(T) is not supported / has not been implemented for annotations of type " +
specification.getClass());
}
/** {@inheritDoc} */
@Override
public void setAnnotationValue(String value, T specification) throws Exception {
......@@ -153,7 +162,8 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple
*/
@Override
public EditingSupport createEditingSupport(ColumnViewer viewer,
Class<? extends IAnnotatedSpecification> clazz, String instanceKey) throws Exception {
Class<? extends IAnnotatedSpecification> clazz, String instanceKey,
EStructuralFeature structuralFeature) throws Exception {
try {
initializeInputChoice(viewer, clazz, instanceKey);
......@@ -179,12 +189,12 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple
/**
* Creates the editing support without referring to the optional {@code instanceKey} (see
* {@link #createEditingSupport(ColumnViewer, Class, String)}).
* {@link #createEditingSupport(ColumnViewer, Class, String, EStructuralFeature)}).
*/
public EditingSupport createEditingSupport(ColumnViewer viewer,
Class<? extends IAnnotatedSpecification> clazz) throws Exception {
return createEditingSupport(viewer, clazz, null);
return createEditingSupport(viewer, clazz, null, null);
}
/** {@inheritDoc} */
......
......@@ -17,6 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.swt.graphics.Color;
import org.eclipse.wb.swt.SWTResourceManager;
......@@ -73,8 +74,10 @@ public class AnnotationLabelProvider extends LabelProviderBase {
AnnotationEntry annotationEntry = (AnnotationEntry)element;
Object value = null;
EStructuralFeature feature = null;
try {
value = annotationEntry.getSpecificationValue(specClass, instanceKey);
feature = annotationEntry.getSpecificationElementFeature(specClass);
} catch(Exception e) {
// Ignore. Return "" in this case.
}
......@@ -82,8 +85,8 @@ public class AnnotationLabelProvider extends LabelProviderBase {
if(editingSupport instanceof ComboBoxEditingSupport) {
ComboBoxLabelValueMapping comboBoxLabelValueMapping =
((ComboBoxEditingSupport)editingSupport)
.createComboBoxLabelValueMapping(annotationEntry
.getModelElement());
.createComboBoxLabelValueMapping(
annotationEntry.getModelElement(), feature);
return comboBoxLabelValueMapping.getLabelForValue(value);
}
......
......@@ -27,6 +27,7 @@ import java.util.Set;
import java.util.TreeSet;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.EditingSupport;
......@@ -71,7 +72,7 @@ import org.fortiss.tooling.kernel.model.INamedElement;
* </p>
* <p>
* In order to support displaying and editing specific annotation types, the corresponding
* {@link IAnnotationValueProvider#createEditingSupport(org.eclipse.jface.viewers.ColumnViewer, Class, String)}
* {@link IAnnotationValueProvider#createEditingSupport(org.eclipse.jface.viewers.ColumnViewer, Class, String, EStructuralFeature)}
* factory method must return an appropriate {@link EditingSupport}.
* </p>
*
......
......@@ -171,6 +171,12 @@
</eAnnotations>
<eGenericType eTypeParameter="#//element/IDerivedAnnotation/T"/>
</eOperations>
<eOperations name="getDerivedFeature" eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStructuralFeature">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Returns the {@link EStructuralFeature} that stores the annotation of the model element associated with this {@link IDerivedAnnotation}. Returns null if no element specific behavior is desired."/>
<details key="body" value="return null;"/>
</eAnnotations>
</eOperations>
<eOperations name="isUserAnnotatedValuePreferred" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Default implementation of a method indicating whether the user annotated value, if available, shall be preferred over the derived one. The default is 'true', i.e. user annotated values are preferred. Shall be overridden, if another bahaviour is desired."/>
......
......@@ -52,6 +52,7 @@
<genTypeParameters ecoreTypeParameter="base.ecore#//element/IDerivedAnnotation/T"/>
<genOperations ecoreOperation="base.ecore#//element/IDerivedAnnotation/getValue"/>
<genOperations ecoreOperation="base.ecore#//element/IDerivedAnnotation/getDerivedValue"/>
<genOperations ecoreOperation="base.ecore#//element/IDerivedAnnotation/getDerivedFeature"/>
<genOperations ecoreOperation="base.ecore#//element/IDerivedAnnotation/isUserAnnotatedValuePreferred"/>
<genOperations ecoreOperation="base.ecore#//element/IDerivedAnnotation/getUserAnnotatedValue"/>
</genClasses>
......
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