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

- 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
parent 031a1593
No related branches found
No related tags found
No related merge requests found
...@@ -77,7 +77,7 @@ public class AnnotationEditingSupportStandard extends EditingSupport { ...@@ -77,7 +77,7 @@ public class AnnotationEditingSupportStandard extends EditingSupport {
protected Object getValue(Object element) { protected Object getValue(Object element) {
if(element instanceof AnnotationEntry) { if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element; AnnotationEntry data = (AnnotationEntry)element;
return data.getSpecificationValue(specClass); return data.getSpecificationValue(specClass).toString();
} }
return null; return null;
} }
......
...@@ -82,8 +82,8 @@ public final class AnnotationEntry { ...@@ -82,8 +82,8 @@ public final class AnnotationEntry {
return false; return false;
} }
/** Returns the annotation's name */ /** Returns the name / "label" for a given annotation {@code clazz}. */
public <V> V getSpecificationAnnotationName(Class<? extends IAnnotatedSpecification> clazz) { public String getSpecificationAnnotationName(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) { for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) { if(clazz.isInstance(s)) {
return providerSpecMapping.get(clazz).getAnnotationName(s); return providerSpecMapping.get(clazz).getAnnotationName(s);
...@@ -94,9 +94,9 @@ public final class AnnotationEntry { ...@@ -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 { Class<? extends IAnnotatedSpecification> clazz) throws Exception {
for(IAnnotatedSpecification s : specificationsList) { for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) { if(clazz.isInstance(s)) {
...@@ -108,7 +108,7 @@ public final class AnnotationEntry { ...@@ -108,7 +108,7 @@ public final class AnnotationEntry {
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString()); 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) { public <V> V getSpecificationValue(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) { for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) { if(clazz.isInstance(s)) {
...@@ -120,7 +120,7 @@ public final class AnnotationEntry { ...@@ -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) public <V> void setSpecificationValue(V value, Class<? extends IAnnotatedSpecification> clazz)
throws Exception { throws Exception {
...@@ -134,6 +134,21 @@ public final class AnnotationEntry { ...@@ -134,6 +134,21 @@ public final class AnnotationEntry {
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString()); 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 */ /** Returns the possible values of the the given specification clazz */
public List<String> getFixedSpecificationValues(Class<? extends IAnnotatedSpecification> clazz) { public List<String> getFixedSpecificationValues(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) { for(IAnnotatedSpecification s : specificationsList) {
......
...@@ -56,7 +56,7 @@ public class AnnotationLabelProvider extends ColumnLabelProvider { ...@@ -56,7 +56,7 @@ public class AnnotationLabelProvider extends ColumnLabelProvider {
public String getText(Object element) { public String getText(Object element) {
if(element instanceof AnnotationEntry) { if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element; AnnotationEntry data = (AnnotationEntry)element;
return data.getSpecificationValue(specClass); return data.getSpecificationValue(specClass).toString();
} }
return "-"; return "-";
} }
......
...@@ -46,17 +46,20 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext ...@@ -46,17 +46,20 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext
public boolean allowsMultipleValues(); public boolean allowsMultipleValues();
/** Returns the name of the Annotation for 'specification' */ /** 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 */ /** 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' */ /** Returns the value of the annotation for 'specification' */
public <V> V getAnnotationValue(T 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; 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 * If this method does not return null, a combo box is provided with the specific return values
*/ */
......
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