diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ComboBoxEditingSupport.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ComboBoxEditingSupport.java index fa214172294e39733cd9516bb9ca5ac3e5b15c76..bd9ffeaadd76c2c7cf3e5889a6b85b047514c103 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ComboBoxEditingSupport.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/editingsupport/ComboBoxEditingSupport.java @@ -31,6 +31,7 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.widgets.Composite; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; +import org.fortiss.tooling.base.model.element.IDerivedAnnotation; import org.fortiss.tooling.base.ui.annotation.AnnotationEntry; import org.fortiss.tooling.base.ui.annotation.valueprovider.EStructuralFeatureDescriptor; @@ -51,12 +52,6 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { /** Flag if this {@link ComboBoxEditingSupport} is editable. */ boolean isEditable; - /** - * Translates between labels shown in this {@link ComboBoxEditingSupport}, and the underlying - * actual values (e.g., required for {@link EReference}s. - */ - private LabelValueMapping comboBoxLabelValueMapping; - /** * Input-choice based on an {@link EStructuralFeature} (i.e., {@link EEnum} or * {@link EReference}). @@ -114,6 +109,16 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { this.stringInputChoice = stringInputChoice; } + /** + * Creates a {@link LabelValueMapping} for the given {@link AnnotationEntry}. Note: Since + * {@link IDerivedAnnotation}s support that the {@link EStructuralFeature} of their return value + * is changed at runtime, the resulting {@link LabelValueMapping} should not be cached. + */ + private LabelValueMapping getLabelValueMapping(AnnotationEntry entry) { + return new LabelValueMapping(eStructuralFeatureDescriptor, + entry.getSpecification(specClass), entry.getModelElement(), stringInputChoice); + } + /** {@inheritDoc} */ @Override protected CellEditor getCellEditor(Object element) { @@ -122,14 +127,7 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { return null; } - AnnotationEntry entry = (AnnotationEntry)element; - - comboBoxLabelValueMapping = - new LabelValueMapping(eStructuralFeatureDescriptor, - entry.getSpecification(specClass), entry.getModelElement(), - stringInputChoice); - - cellEditor.setInput(comboBoxLabelValueMapping.getLabels()); + cellEditor.setInput(getLabelValueMapping((AnnotationEntry)element).getLabels()); return cellEditor; } @@ -137,6 +135,10 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { /** {@inheritDoc} */ @Override protected void setValue(Object element, Object label) { + if(!(element instanceof AnnotationEntry)) { + return; + } + if(isEditable && label == null) { // New values, i.e values that have been entered into the text input field, and have not // been selected from the combo box are indicated by a null value. Hence, fetch the text @@ -145,7 +147,8 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { } if(label != null) { - super.setValue(element, comboBoxLabelValueMapping.getValueForLabel(label.toString())); + super.setValue(element, getLabelValueMapping((AnnotationEntry)element) + .getValueForLabel(label.toString())); } } @@ -160,11 +163,14 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { * {@link AnnotationEntry}). */ public String getLabel(Object element) { - // super.getValue() checks if element is actually an AnnotationEntry + if(!(element instanceof AnnotationEntry)) { + return null; + } + Object value = super.getValue(element); - if(value != null && comboBoxLabelValueMapping != null) { - return comboBoxLabelValueMapping.getLabelForValue(value); + if(value != null) { + return getLabelValueMapping((AnnotationEntry)element).getLabelForValue(value); } return null;