Skip to content
Snippets Groups Projects
Commit 63811b4a authored by Alexander Diewald's avatar Alexander Diewald
Browse files

- Modified the annotation interface to handle generic data types inside the annotation

- Modified 'GenericAnnotationView' to load custom Editing elements in the table if provided
parent 1b05efe5
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,8 @@ import java.util.Collections; ...@@ -22,6 +22,8 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement; import org.fortiss.tooling.base.model.element.IModelElement;
...@@ -33,9 +35,9 @@ import org.fortiss.tooling.base.model.element.IModelElement; ...@@ -33,9 +35,9 @@ import org.fortiss.tooling.base.model.element.IModelElement;
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: * @ConQAT.Rating RED Hash:
*/ */
final class AnnotationEntry { public final class AnnotationEntry {
/** Value not availabe */ /** Value not available */
public static final String NOVAL = "-"; public static final String NOVAL = "-";
/** Model Element */ /** Model Element */
...@@ -62,32 +64,51 @@ final class AnnotationEntry { ...@@ -62,32 +64,51 @@ final class AnnotationEntry {
specificationsList.add(spec); specificationsList.add(spec);
} }
/** Returns the string representation of the annotation value */ /** Returns the annotation name */
public String getSpecificationValue(Class<? extends IAnnotatedSpecification> clazz) { public <V> V 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).getValue(s); return providerSpecMapping.get(clazz).getAnnotationName(s);
} }
} }
return NOVAL;
throw null;
} }
/** Returns the possible values of the the given specification clazz */ /**
public List<String> getFixedSpecificationValues(Class<? extends IAnnotatedSpecification> clazz) { * adds a new value to the given specification clazz and overrides the old one
*/
public <V> void setSpecificationAnnotationName(V name,
Class<? extends IAnnotatedSpecification> clazz) throws Exception {
for(IAnnotatedSpecification s : specificationsList) { for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) { if(clazz.isInstance(s)) {
return providerSpecMapping.get(clazz).getFixedValues(); providerSpecMapping.get(clazz).setAnnotationName(name, s);
return;
} }
} }
return Collections.emptyList();
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
} }
/** adds a new value to the given specification clazz and overrides the old one */ /** Returns the string representation of the annotation value */
public void setSpecificationValue(String value, Class<? extends IAnnotatedSpecification> clazz) public <V> V getSpecificationValue(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
return providerSpecMapping.get(clazz).getAnnotationValue(s);
}
}
throw null;
}
/**
* adds a new value to the given specification clazz and overrides the old one
*/
public <V> void setSpecificationValue(V value, Class<? extends IAnnotatedSpecification> clazz)
throws Exception { throws Exception {
for(IAnnotatedSpecification s : specificationsList) { for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) { if(clazz.isInstance(s)) {
providerSpecMapping.get(clazz).setValue(value, s); providerSpecMapping.get(clazz).setAnnotationValue(value, s);
return; return;
} }
} }
...@@ -95,19 +116,35 @@ final class AnnotationEntry { ...@@ -95,19 +116,35 @@ 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 modelElement. */ /** Returns the possible values of the the given specification clazz */
public IModelElement getModelElement() { public List<String> getFixedSpecificationValues(Class<? extends IAnnotatedSpecification> clazz) {
return modelElement; for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
return providerSpecMapping.get(clazz).getFixedValues();
}
}
return Collections.emptyList();
} }
/** Returns the annotation name */ /**
public String getAnnotationName(Class<? extends IAnnotatedSpecification> clazz) { * Returns a custom EditingSupport element for the annotation view
*/
public EditingSupport getSpecificationEditElement(ColumnViewer viewer,
Class<? extends IAnnotatedSpecification> clazz, Object parent) {
for(IAnnotatedSpecification s : specificationsList) { for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) { if(clazz.isInstance(s)) {
return providerSpecMapping.get(clazz).getAnnotationName(); return providerSpecMapping.get(clazz).getEditElement(viewer, clazz, parent);
} }
} }
return "Provider not found";
return null;
// throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
}
/** Returns modelElement. */
public IModelElement getModelElement() {
return modelElement;
} }
/** Returns specificationsList. */ /** Returns specificationsList. */
......
...@@ -60,7 +60,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -60,7 +60,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
new HashMap<Class<? extends IAnnotatedSpecification>, TableViewerColumn>(); new HashMap<Class<? extends IAnnotatedSpecification>, TableViewerColumn>();
/** The table viewer */ /** The table viewer */
private TableViewer tableViewer; public TableViewer tableViewer;
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
...@@ -120,9 +120,21 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -120,9 +120,21 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
for(IAnnotatedSpecification spec : entry.getSpecificationsList()) { for(IAnnotatedSpecification spec : entry.getSpecificationsList()) {
if(!isExistingColumn(spec)) { if(!isExistingColumn(spec)) {
TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE);
column.getColumn().setText(entry.getAnnotationName(spec.getClass())); column.getColumn().setText("Annotation: Name->Value");
column.getColumn().setWidth(100); column.getColumn().setWidth(200);
columns.put(spec.getClass(), column); columns.put(spec.getClass(), column);
/*
* Whenever an editing element is defined use this instead of the generic fixed
* Combo List or the simple text edit field
*/
if(entry.getSpecificationEditElement(tableViewer, spec.getClass(), this) != null) {
column.setLabelProvider(new AnnotationLabelProvider(spec.getClass()));
EditingSupport editingSupport =
entry.getSpecificationEditElement(tableViewer, spec.getClass(),
this);
column.setEditingSupport(editingSupport);
} else {
if(entry.getFixedSpecificationValues(spec.getClass()) == null) { if(entry.getFixedSpecificationValues(spec.getClass()) == null) {
column.setLabelProvider(new AnnotationLabelProvider(spec.getClass())); column.setLabelProvider(new AnnotationLabelProvider(spec.getClass()));
EditingSupport editingSupport = EditingSupport editingSupport =
...@@ -137,7 +149,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -137,7 +149,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
column.setEditingSupport(editingSupport); column.setEditingSupport(editingSupport);
} }
} }
}
} }
} }
...@@ -171,16 +183,14 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -171,16 +183,14 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
* the values for the combo box * the values for the combo box
* @param class1 * @param class1
*/ */
private ComboEditingSupport(ColumnViewer viewer, List<String> values, public ComboEditingSupport(ColumnViewer viewer, List<String> values,
Class<? extends IAnnotatedSpecification> class1) { Class<? extends IAnnotatedSpecification> class1) {
super(viewer); super(viewer);
cellEditor = cellEditor = new ComboBoxViewerCellEditor((Composite)getViewer().getControl());
new ComboBoxViewerCellEditor((Composite)getViewer().getControl(), SWT.READ_ONLY);
cellEditor.setLabelProvider(new LabelProvider()); cellEditor.setLabelProvider(new LabelProvider());
cellEditor.setContentProvider(new ArrayContentProvider()); cellEditor.setContentProvider(new ArrayContentProvider());
cellEditor.setInput(values); cellEditor.setInput(values);
specClass = class1; specClass = class1;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
...@@ -248,8 +258,8 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -248,8 +258,8 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
} }
/** Editing Suppourt for standard table cells */ /** Editing Support for standard table cells */
private class StandardEditingSupport extends EditingSupport { public class StandardEditingSupport extends EditingSupport {
/** Text cell editor */ /** Text cell editor */
private TextCellEditor cellEditor = null; private TextCellEditor cellEditor = null;
...@@ -261,6 +271,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -261,6 +271,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
Class<? extends IAnnotatedSpecification> class1) { Class<? extends IAnnotatedSpecification> class1) {
super(viewer); super(viewer);
cellEditor = new TextCellEditor((Composite)getViewer().getControl(), SWT.NONE); cellEditor = new TextCellEditor((Composite)getViewer().getControl(), SWT.NONE);
cellEditor.setValue("test");
specClass = class1; specClass = class1;
} }
...@@ -329,7 +340,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -329,7 +340,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
} }
/** Label provider for {@link AnnotationEntry}s */ /** Label provider for {@link AnnotationEntry}s */
public class AnnotationLabelProvider extends ColumnLabelProvider { private class AnnotationLabelProvider extends ColumnLabelProvider {
/** Specification class of this column */ /** Specification class of this column */
Class<? extends IAnnotatedSpecification> specClass; Class<? extends IAnnotatedSpecification> specClass;
...@@ -345,7 +356,8 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -345,7 +356,8 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
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.getSpecificationAnnotationName(specClass) + " -> " +
data.getSpecificationValue(specClass);
} }
return "-"; return "-";
} }
...@@ -368,7 +380,6 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -368,7 +380,6 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
@Override @Override
public void setFocus() { public void setFocus() {
// nothing to do // nothing to do
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
...@@ -377,4 +388,5 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -377,4 +388,5 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
tableViewer.getTable().dispose(); tableViewer.getTable().dispose();
super.dispose(); super.dispose();
} }
} }
...@@ -20,6 +20,8 @@ package org.fortiss.tooling.base.ui.annotation; ...@@ -20,6 +20,8 @@ package org.fortiss.tooling.base.ui.annotation;
import java.util.List; import java.util.List;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement; import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.service.base.IEObjectAware; import org.fortiss.tooling.kernel.service.base.IEObjectAware;
...@@ -27,7 +29,7 @@ import org.fortiss.tooling.kernel.service.base.IEObjectAware; ...@@ -27,7 +29,7 @@ import org.fortiss.tooling.kernel.service.base.IEObjectAware;
/** /**
* Interface for {@link IAnnotatedSpecification}s * Interface for {@link IAnnotatedSpecification}s
* *
* @author eder * @author eder, diewald
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating RED Hash: * @ConQAT.Rating RED Hash:
...@@ -35,16 +37,28 @@ import org.fortiss.tooling.kernel.service.base.IEObjectAware; ...@@ -35,16 +37,28 @@ import org.fortiss.tooling.kernel.service.base.IEObjectAware;
public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> extends public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> extends
IEObjectAware<IModelElement> { IEObjectAware<IModelElement> {
/** Returns the specific value */ /** Returns the name of the Annotation for 'specification' */
public String getValue(T specification); public <V> V 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;
/** 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 */
public <V> void setAnnotationValue(V value, T specification) throws IllegalArgumentException;
/** /**
* 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
*/ */
public List<String> getFixedValues(); public List<String> getFixedValues();
/** Sets a new value in the annotation and overrides the old one */ /**
public void setValue(String value, T specification) throws IllegalArgumentException; * Returns a custom EditingSupport element for the annotation view
*/
public EditingSupport getEditElement(ColumnViewer viewer,
Class<? extends IAnnotatedSpecification> class1, Object parent);
/** /**
* Adds a new {@link IAnnotatedSpecification} of type T to the given model element and returns * Adds a new {@link IAnnotatedSpecification} of type T to the given model element and returns
...@@ -55,9 +69,6 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext ...@@ -55,9 +69,6 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext
/** Returns the class of T */ /** Returns the class of T */
public Class<T> getClazz(); public Class<T> getClazz();
/** Returns the desired name of the Annotation */
public String getAnnotationName();
/** Returns a List of Objects which children will not have {@link IAnnotatedSpecification}s */ /** Returns a List of Objects which children will not have {@link IAnnotatedSpecification}s */
public List<Class<? extends EObject>> filterOut(); public List<Class<? extends EObject>> filterOut();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment