From b0f2d575c5e29b25c465705acd338b0101b1c3a5 Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Mon, 25 Aug 2014 11:29:07 +0000 Subject: [PATCH] - IAnnotationValueProvider - add setAnnotationValue(String value, T specification) in addition to setAnnotationValue(V value, T specification) variant - This enables to use the String-based AnnotationEditingSupportStandard for non-String annotations. - Concrete AnnotationValueProviders must implement this method and convert the String representation of the input to the storage format provided by the respective annotation class (e.g., for Double, just by using the Double(String) constructor) - The current implementation has been tested with String, Double, enum and multiple value String annotations - TODO: - Cleanup of IAnnotationValueProvider - Base class hierarchy for common concrete annotation value providers - multiple value annotation support in GenericAnnotationView --- .../AnnotationEditingSupportStandard.java | 2 +- .../base/ui/annotation/AnnotationEntry.java | 27 ++++++++++++++----- .../annotation/AnnotationLabelProvider.java | 2 +- .../annotation/IAnnotationValueProvider.java | 9 ++++--- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/AnnotationEditingSupportStandard.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/AnnotationEditingSupportStandard.java index 894fe511c..673ae2a49 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/AnnotationEditingSupportStandard.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/AnnotationEditingSupportStandard.java @@ -77,7 +77,7 @@ public class AnnotationEditingSupportStandard extends EditingSupport { protected Object getValue(Object element) { if(element instanceof AnnotationEntry) { AnnotationEntry data = (AnnotationEntry)element; - return data.getSpecificationValue(specClass); + return data.getSpecificationValue(specClass).toString(); } return null; } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/AnnotationEntry.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/AnnotationEntry.java index 85c71cd49..531ab2b3d 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/AnnotationEntry.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/AnnotationEntry.java @@ -82,8 +82,8 @@ public final class AnnotationEntry { return false; } - /** Returns the annotation's name */ - public <V> V getSpecificationAnnotationName(Class<? extends IAnnotatedSpecification> clazz) { + /** Returns the name / "label" for a given annotation {@code clazz}. */ + public String getSpecificationAnnotationName(Class<? extends IAnnotatedSpecification> clazz) { for(IAnnotatedSpecification s : specificationsList) { if(clazz.isInstance(s)) { return providerSpecMapping.get(clazz).getAnnotationName(s); @@ -94,9 +94,9 @@ public final class AnnotationEntry { } /** - * adds a new value to the given specification clazz and overrides the old one + * Sets the name / "label" for a given annotation {@code clazz}. */ - public <V> void setSpecificationAnnotationName(V name, + public void setSpecificationAnnotationName(String name, Class<? extends IAnnotatedSpecification> clazz) throws Exception { for(IAnnotatedSpecification s : specificationsList) { if(clazz.isInstance(s)) { @@ -108,7 +108,7 @@ public final class AnnotationEntry { throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString()); } - /** Returns the string representation of the annotation value */ + /** Returns the annotation value */ public <V> V getSpecificationValue(Class<? extends IAnnotatedSpecification> clazz) { for(IAnnotatedSpecification s : specificationsList) { if(clazz.isInstance(s)) { @@ -120,7 +120,7 @@ public final class AnnotationEntry { } /** - * adds a new value to the given specification clazz and overrides the old one + * Sets a new value for the given specification clazz. */ public <V> void setSpecificationValue(V value, Class<? extends IAnnotatedSpecification> clazz) throws Exception { @@ -134,6 +134,21 @@ public final class AnnotationEntry { throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString()); } + /** + * Sets a new value for the given specification clazz from a {@link String} representation. + */ + public void setSpecificationValue(String value, Class<? extends IAnnotatedSpecification> clazz) + throws Exception { + for(IAnnotatedSpecification s : specificationsList) { + if(clazz.isInstance(s)) { + providerSpecMapping.get(clazz).setAnnotationValue(value, s); + return; + } + } + + throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString()); + } + /** Returns the possible values of the the given specification clazz */ public List<String> getFixedSpecificationValues(Class<? extends IAnnotatedSpecification> clazz) { for(IAnnotatedSpecification s : specificationsList) { diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/AnnotationLabelProvider.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/AnnotationLabelProvider.java index 2d562989c..527ff75d3 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/AnnotationLabelProvider.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/AnnotationLabelProvider.java @@ -56,7 +56,7 @@ public class AnnotationLabelProvider extends ColumnLabelProvider { public String getText(Object element) { if(element instanceof AnnotationEntry) { AnnotationEntry data = (AnnotationEntry)element; - return data.getSpecificationValue(specClass); + return data.getSpecificationValue(specClass).toString(); } return "-"; } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/IAnnotationValueProvider.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/IAnnotationValueProvider.java index 1ebce9558..f980d25ae 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/IAnnotationValueProvider.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/IAnnotationValueProvider.java @@ -46,17 +46,20 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext public boolean allowsMultipleValues(); /** Returns the name of the Annotation for 'specification' */ - public <V> V getAnnotationName(T specification); + public String getAnnotationName(T specification); /** Sets a new name for the annotation and overrides the old one */ - public <V> void setAnnotationName(V name, T specification) throws IllegalArgumentException; + public void setAnnotationName(String name, T specification) throws IllegalArgumentException; /** Returns the value of the annotation for 'specification' */ public <V> V getAnnotationValue(T specification); - /** Sets a new value in the annotation and overrides the old one */ + /** Sets a new value for the annotation. */ public <V> void setAnnotationValue(V value, T specification) throws IllegalArgumentException; + /** Sets a new value in the annotation from a {@link String} representation. */ + public void setAnnotationValue(String value, T specification) throws Exception; + /** * If this method does not return null, a combo box is provided with the specific return values */ -- GitLab