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 4a2e771e975f26d6ce8a4232e6358dab0c09b8c8..517032f53ed40617dca8e280a383b4dd7a5ac471 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 @@ -32,6 +32,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.IModelElement; import org.fortiss.tooling.base.ui.annotation.AnnotationEntry; import org.fortiss.tooling.base.ui.annotation.valueprovider.EStructuralFeatureDescriptor; @@ -132,10 +133,12 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { */ 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); + if(labelValueMappingMayChange(feature)) { + return new ComboBoxLabelValueMapping(new EStructuralFeatureDescriptor( + (EAttribute)feature), modelElement, stringInputChoice); + } + return new ComboBoxLabelValueMapping(eStructuralFeatureDescriptor, modelElement, + stringInputChoice); } /** {@inheritDoc} */ @@ -165,4 +168,15 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase { return null; } + /** + * Check, whether the {@link EStructuralFeatureDescriptor} may depend on the + * {@link IModelElement}. + */ + private boolean labelValueMappingMayChange(EStructuralFeature feature) { + if(feature != null && feature instanceof EAttribute) { + return true; + } + return false; + } + } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/EStructuralFeatureValueProviderBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/EStructuralFeatureValueProviderBase.java index 9d27d7505c31f6646ef64b4be03fa1503e6d2d54..0942e9bad14192594d299f87c062f78381a2aa27 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/EStructuralFeatureValueProviderBase.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/valueprovider/EStructuralFeatureValueProviderBase.java @@ -297,45 +297,40 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp public EditingSupport createEditingSupport(ColumnViewer viewer, Class<? extends IAnnotatedSpecification> clazz, String instanceKey, EStructuralFeature structuralFeature) throws Exception { - EStructuralFeature feature = structuralFeature; - if(feature == null) { - feature = getEStructuralFeature(instanceKey); - } + EStructuralFeatureDescriptor descriptor = null; + if(structuralFeature == null) { + structuralFeature = getEStructuralFeature(instanceKey); - if(feature.getUpperBound() > 1 || - feature.getUpperBound() == ETypedElement.UNBOUNDED_MULTIPLICITY) { - throw new Exception( - "EStructuralValueProvider has not been implemented for structural feature multiplicity > 1."); - } + if(structuralFeature.getUpperBound() > 1 || + structuralFeature.getUpperBound() == ETypedElement.UNBOUNDED_MULTIPLICITY) { + throw new Exception( + "EStructuralValueProvider has not been implemented for structural feature multiplicity > 1."); + } - EClassifier eType = null; - try { - eType = feature.getEType(); - } catch(Exception e) { - // Ignore - } + EClassifier eType = null; + try { + eType = structuralFeature.getEType(); + } catch(Exception e) { + // Ignore + } - if(((!(eType instanceof EEnum)) && (!(eType instanceof EClass))) || - ((eType instanceof EClass) && (structuralFeatureDescriptorMap.get(instanceKey) - .getEReferenceScope() == null))) { + if(((!(eType instanceof EEnum)) && (!(eType instanceof EClass))) || + ((eType instanceof EClass) && (structuralFeatureDescriptorMap.get(instanceKey) + .getEReferenceScope() == null))) { - return super.createEditingSupport(viewer, clazz, instanceKey, null); + 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); + if(structuralFeature instanceof EAttribute) { + descriptor = new EStructuralFeatureDescriptor((EAttribute)structuralFeature); + return new ComboBoxEditingSupport(viewer, clazz, instanceKey, descriptor); } - return new ComboBoxEditingSupport(viewer, clazz, instanceKey, descriptor); + throw new Exception("Creating an EditingSupport for EStructuralFeatures of the type " + + structuralFeature.getEType().toString() + " is not supported"); } /**