From 6034d10e7157989b9a60155564e13b1fe335452d Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Mon, 15 Dec 2014 17:01:08 +0000
Subject: [PATCH] ComboBoxEditingSupport: - Do not expose
 createComboBoxLabelValueMapping() - Instead, provide getLabel() refs 1841

---
 .../ComboBoxEditingSupport.java               | 30 +++++++++----------
 .../AnnotationLabelProvider.java              |  8 +----
 2 files changed, 16 insertions(+), 22 deletions(-)

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 3dd9becbb..f77a7a233 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
@@ -20,7 +20,6 @@ package org.fortiss.tooling.base.ui.annotation.editingsupport;
 import java.util.Collection;
 
 import org.eclipse.emf.ecore.EEnum;
-import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.EReference;
 import org.eclipse.emf.ecore.EStructuralFeature;
 import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -117,26 +116,18 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase {
 			return null;
 		}
 
+		AnnotationEntry entry = (AnnotationEntry)element;
+
 		comboBoxLabelValueMapping =
-				createComboBoxLabelValueMapping(((AnnotationEntry)element).getModelElement(),
-						((AnnotationEntry)element).getSpecification((specClass)));
+				new LabelValueMapping(eStructuralFeatureDescriptor,
+						entry.getSpecification(specClass), entry.getModelElement(),
+						stringInputChoice);
 
 		cellEditor.setInput(comboBoxLabelValueMapping.getLabels());
 
 		return cellEditor;
 	}
 
-	/**
-	 * Creates a {@link LabelValueMapping} for the annotation shown in this
-	 * {@link ComboBoxEditingSupport}.
-	 */
-	public LabelValueMapping createComboBoxLabelValueMapping(EObject modelElement,
-			IAnnotatedSpecification specification) {
-
-		return new LabelValueMapping(eStructuralFeatureDescriptor, specification,
-				modelElement, stringInputChoice);
-	}
-
 	/** {@inheritDoc} */
 	@Override
 	protected void setValue(Object element, Object label) {
@@ -155,9 +146,18 @@ public class ComboBoxEditingSupport extends AnnotationEditingSupportBase {
 	/** {@inheritDoc} */
 	@Override
 	protected Object getValue(Object element) {
+		return getLabel(element);
+	}
+
+	/**
+	 * Returns a {@link String} label for the given annotation (identified by its
+	 * {@link AnnotationEntry}).
+	 */
+	public String getLabel(Object element) {
+		// super.getValue() checks if element is actually an AnnotationEntry
 		Object value = super.getValue(element);
 
-		if(value != null) {
+		if(value != null && comboBoxLabelValueMapping != null) {
 			return comboBoxLabelValueMapping.getLabelForValue(value);
 		}
 
diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java
index 998e7b304..c73560dd6 100644
--- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java
@@ -25,7 +25,6 @@ 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.editingsupport.ComboBoxEditingSupport;
-import org.fortiss.tooling.base.ui.annotation.editingsupport.LabelValueMapping;
 import org.fortiss.tooling.base.ui.annotation.editingsupport.MultiSelectionEditingSupport;
 import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart;
 
@@ -83,12 +82,7 @@ public class AnnotationLabelProvider extends LabelProviderBase {
 			}
 			if(value != null) {
 				if(editingSupport instanceof ComboBoxEditingSupport) {
-					LabelValueMapping comboBoxLabelValueMapping =
-							((ComboBoxEditingSupport)editingSupport)
-									.createComboBoxLabelValueMapping(
-											annotationEntry.getModelElement(),
-											annotationEntry.getSpecification(specClass));
-					return comboBoxLabelValueMapping.getLabelForValue(value);
+					return ((ComboBoxEditingSupport)editingSupport).getLabel(element);
 				} else if(editingSupport instanceof MultiSelectionEditingSupport) {
 					return ((MultiSelectionEditingSupport)editingSupport).getLabel(element);
 				}
-- 
GitLab