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;
import java.util.HashMap;
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.IModelElement;
......@@ -33,9 +35,9 @@ import org.fortiss.tooling.base.model.element.IModelElement;
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
final class AnnotationEntry {
public final class AnnotationEntry {
/** Value not availabe */
/** Value not available */
public static final String NOVAL = "-";
/** Model Element */
......@@ -62,32 +64,51 @@ final class AnnotationEntry {
specificationsList.add(spec);
}
/** Returns the string representation of the annotation value */
public String getSpecificationValue(Class<? extends IAnnotatedSpecification> clazz) {
/** Returns the annotation name */
public <V> V getSpecificationAnnotationName(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) {
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) {
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 */
public void setSpecificationValue(String value, Class<? extends IAnnotatedSpecification> clazz)
/** Returns the string representation of the annotation value */
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 {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
providerSpecMapping.get(clazz).setValue(value, s);
providerSpecMapping.get(clazz).setAnnotationValue(value, s);
return;
}
}
......@@ -95,19 +116,35 @@ final class AnnotationEntry {
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
}
/** Returns modelElement. */
public IModelElement getModelElement() {
return modelElement;
/** Returns the possible values of the the given specification clazz */
public List<String> getFixedSpecificationValues(Class<? extends IAnnotatedSpecification> clazz) {
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) {
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. */
......
......@@ -60,7 +60,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
new HashMap<Class<? extends IAnnotatedSpecification>, TableViewerColumn>();
/** The table viewer */
private TableViewer tableViewer;
public TableViewer tableViewer;
/** {@inheritDoc} */
@Override
......@@ -120,24 +120,36 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
for(IAnnotatedSpecification spec : entry.getSpecificationsList()) {
if(!isExistingColumn(spec)) {
TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE);
column.getColumn().setText(entry.getAnnotationName(spec.getClass()));
column.getColumn().setWidth(100);
column.getColumn().setText("Annotation: Name->Value");
column.getColumn().setWidth(200);
columns.put(spec.getClass(), column);
if(entry.getFixedSpecificationValues(spec.getClass()) == null) {
/*
* 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 =
new StandardEditingSupport(column.getViewer(), spec.getClass());
entry.getSpecificationEditElement(tableViewer, spec.getClass(),
this);
column.setEditingSupport(editingSupport);
} else {
column.setLabelProvider(new AnnotationLabelProvider(spec.getClass()));
EditingSupport editingSupport =
new ComboEditingSupport(column.getViewer(),
entry.getFixedSpecificationValues(spec.getClass()),
spec.getClass());
column.setEditingSupport(editingSupport);
if(entry.getFixedSpecificationValues(spec.getClass()) == null) {
column.setLabelProvider(new AnnotationLabelProvider(spec.getClass()));
EditingSupport editingSupport =
new StandardEditingSupport(column.getViewer(), spec.getClass());
column.setEditingSupport(editingSupport);
} else {
column.setLabelProvider(new AnnotationLabelProvider(spec.getClass()));
EditingSupport editingSupport =
new ComboEditingSupport(column.getViewer(),
entry.getFixedSpecificationValues(spec.getClass()),
spec.getClass());
column.setEditingSupport(editingSupport);
}
}
}
}
}
......@@ -171,16 +183,14 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
* the values for the combo box
* @param class1
*/
private ComboEditingSupport(ColumnViewer viewer, List<String> values,
public ComboEditingSupport(ColumnViewer viewer, List<String> values,
Class<? extends IAnnotatedSpecification> class1) {
super(viewer);
cellEditor =
new ComboBoxViewerCellEditor((Composite)getViewer().getControl(), SWT.READ_ONLY);
cellEditor = new ComboBoxViewerCellEditor((Composite)getViewer().getControl());
cellEditor.setLabelProvider(new LabelProvider());
cellEditor.setContentProvider(new ArrayContentProvider());
cellEditor.setInput(values);
specClass = class1;
}
/** {@inheritDoc} */
......@@ -248,8 +258,8 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
}
/** Editing Suppourt for standard table cells */
private class StandardEditingSupport extends EditingSupport {
/** Editing Support for standard table cells */
public class StandardEditingSupport extends EditingSupport {
/** Text cell editor */
private TextCellEditor cellEditor = null;
......@@ -261,6 +271,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
Class<? extends IAnnotatedSpecification> class1) {
super(viewer);
cellEditor = new TextCellEditor((Composite)getViewer().getControl(), SWT.NONE);
cellEditor.setValue("test");
specClass = class1;
}
......@@ -329,7 +340,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
}
/** Label provider for {@link AnnotationEntry}s */
public class AnnotationLabelProvider extends ColumnLabelProvider {
private class AnnotationLabelProvider extends ColumnLabelProvider {
/** Specification class of this column */
Class<? extends IAnnotatedSpecification> specClass;
......@@ -345,7 +356,8 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
public String getText(Object element) {
if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element;
return data.getSpecificationValue(specClass);
return data.getSpecificationAnnotationName(specClass) + " -> " +
data.getSpecificationValue(specClass);
}
return "-";
}
......@@ -368,7 +380,6 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
@Override
public void setFocus() {
// nothing to do
}
/** {@inheritDoc} */
......@@ -377,4 +388,5 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
tableViewer.getTable().dispose();
super.dispose();
}
}
......@@ -20,6 +20,8 @@ package org.fortiss.tooling.base.ui.annotation;
import java.util.List;
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.IModelElement;
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
*
* @author eder
* @author eder, diewald
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
......@@ -35,16 +37,28 @@ import org.fortiss.tooling.kernel.service.base.IEObjectAware;
public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> extends
IEObjectAware<IModelElement> {
/** Returns the specific value */
public String getValue(T specification);
/** Returns the name of the Annotation for '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
*/
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
......@@ -55,9 +69,6 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext
/** Returns the class of T */
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 */
public List<Class<? extends EObject>> filterOut();
......
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