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

- Do not cache LabelValueMapping since {@link IDerivedAnnotation}s support...

- Do not cache LabelValueMapping since {@link IDerivedAnnotation}s support that the {@link {EStructuralFeature} of their return value is changed at runtime
refs 1841
parent 862f3696
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ import org.eclipse.jface.viewers.LabelProvider; ...@@ -31,6 +31,7 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; 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.AnnotationEntry;
import org.fortiss.tooling.base.ui.annotation.valueprovider.EStructuralFeatureDescriptor; import org.fortiss.tooling.base.ui.annotation.valueprovider.EStructuralFeatureDescriptor;
...@@ -51,12 +52,6 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { ...@@ -51,12 +52,6 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase {
/** Flag if this {@link ComboBoxEditingSupport} is editable. */ /** Flag if this {@link ComboBoxEditingSupport} is editable. */
boolean isEditable; 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 * Input-choice based on an {@link EStructuralFeature} (i.e., {@link EEnum} or
* {@link EReference}). * {@link EReference}).
...@@ -114,6 +109,16 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { ...@@ -114,6 +109,16 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase {
this.stringInputChoice = stringInputChoice; 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} */ /** {@inheritDoc} */
@Override @Override
protected CellEditor getCellEditor(Object element) { protected CellEditor getCellEditor(Object element) {
...@@ -122,14 +127,7 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { ...@@ -122,14 +127,7 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase {
return null; return null;
} }
AnnotationEntry entry = (AnnotationEntry)element; cellEditor.setInput(getLabelValueMapping((AnnotationEntry)element).getLabels());
comboBoxLabelValueMapping =
new LabelValueMapping(eStructuralFeatureDescriptor,
entry.getSpecification(specClass), entry.getModelElement(),
stringInputChoice);
cellEditor.setInput(comboBoxLabelValueMapping.getLabels());
return cellEditor; return cellEditor;
} }
...@@ -137,6 +135,10 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { ...@@ -137,6 +135,10 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void setValue(Object element, Object label) { protected void setValue(Object element, Object label) {
if(!(element instanceof AnnotationEntry)) {
return;
}
if(isEditable && label == null) { if(isEditable && label == null) {
// New values, i.e values that have been entered into the text input field, and have not // 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 // 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 { ...@@ -145,7 +147,8 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase {
} }
if(label != null) { 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 { ...@@ -160,11 +163,14 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase {
* {@link AnnotationEntry}). * {@link AnnotationEntry}).
*/ */
public String getLabel(Object element) { 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); Object value = super.getValue(element);
if(value != null && comboBoxLabelValueMapping != null) { if(value != null) {
return comboBoxLabelValueMapping.getLabelForValue(value); return getLabelValueMapping((AnnotationEntry)element).getLabelForValue(value);
} }
return null; return null;
......
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