Skip to content
Snippets Groups Projects
Commit bf187ad2 authored by Johannes Eder's avatar Johannes Eder
Browse files

bug fix

refs 1841
parent 5a00c01b
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,9 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
......@@ -30,39 +33,66 @@ import org.fortiss.tooling.base.model.element.IModelElement;
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
@SuppressWarnings("unchecked")
public class AnnotationEntry<T extends IAnnotatedSpecification> {
public class AnnotationEntry {
/** Value not availabe */
public static final String NOVAL = "-";
/** Model Element */
private IModelElement modelElement;
/** Specification of the model element */
private IAnnotatedSpecification specification;
/** Hash map {@link IAnnotatedSpecification} -> {@link IAnnotationValueProvider} */
HashMap<Class<? extends IAnnotatedSpecification>, IAnnotationValueProvider<IAnnotatedSpecification>> providerSpecMapping =
new HashMap<Class<? extends IAnnotatedSpecification>, IAnnotationValueProvider<IAnnotatedSpecification>>();
/** Value Provider to handle the specification */
private IAnnotationValueProvider<T> valueProvider;
/** List of specifications of {@link #modelElement} */
private List<IAnnotatedSpecification> specificationsList =
new ArrayList<IAnnotatedSpecification>();
/** Constructor */
public AnnotationEntry(IModelElement modelElement, IAnnotatedSpecification specification,
IAnnotationValueProvider<T> valueProvider) {
public AnnotationEntry(IModelElement modelElement) {
this.modelElement = modelElement;
this.specification = specification;
this.valueProvider = valueProvider;
}
/** Returns the string representaion of the annotation value */
public String getSpecificationValue() {
return valueProvider.getValue((T)specification);
/** adds a new touple {@link IAnnotationValueProvider} {@link IAnnotatedSpecification} */
public void addNewSpecification(IAnnotationValueProvider<IAnnotatedSpecification> provider,
IAnnotatedSpecification spec) {
providerSpecMapping.put(spec.getClass(), provider);
specificationsList.add(spec);
}
/** Returns the possible values of the {@link #specification} */
public List<String> getFixedSpecificationValues() {
return valueProvider.getFixedValues();
/** Returns the string representation of the annotation value */
public String getSpecificationValue(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
return providerSpecMapping.get(clazz).getValue(s);
}
}
return NOVAL;
}
/** adds a new value to the {@link #specification} and overrides the old one */
public void setSpecificationValue(String value) {
valueProvider.setValue(value, (T)specification);
/** 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();
}
/** adds a new value to the given specification clazz and overrides the old one */
public void setSpecificationValue(String value, Class<? extends IAnnotatedSpecification> clazz)
throws Exception {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
providerSpecMapping.get(clazz).setValue(value, s);
return;
}
}
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
}
/** Returns modelElement. */
......@@ -70,18 +100,18 @@ public class AnnotationEntry<T extends IAnnotatedSpecification> {
return modelElement;
}
/** Returns specification. */
public IAnnotatedSpecification getSpecification() {
return specification;
}
/** Returns the annotation name */
public String getAnnotationName() {
return valueProvider.getAnnotationName();
public String getAnnotationName(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
return providerSpecMapping.get(clazz).getAnnotationName();
}
}
return "Provider not found";
}
/** Returns the class of the specification */
public Class<IAnnotatedSpecification> getSpecificationClass() {
return (Class<IAnnotatedSpecification>)specification.getClass();
/** Returns specificationsList. */
public List<IAnnotatedSpecification> getSpecificationsList() {
return specificationsList;
}
}
......@@ -60,25 +60,15 @@ public class AnnotationValueService extends
/** {@inheritDoc} */
@Override
public List<AnnotationEntry<? extends IAnnotatedSpecification>> getValues(
final IModelElement element) {
public List<AnnotationEntry> getValues(final IModelElement element) {
if(element == null) {
return Collections.emptyList();
}
final List<AnnotationEntry<? extends IAnnotatedSpecification>> result =
new ArrayList<AnnotationEntry<? extends IAnnotatedSpecification>>();// Collections.emptyMap();
final List<AnnotationEntry> result = new ArrayList<AnnotationEntry>();// Collections.emptyMap();
final List<IAnnotationValueProvider<IAnnotatedSpecification>> registeredHandlers =
getRegisteredHandlers(element.getClass());
if(registeredHandlers != null && !registeredHandlers.isEmpty()) {
// getAllChildren(element, clazz, exceptions)
// TreeIterator<EObject> eAllContents = element.eAllContents();
// EList<EObject> eContents = element.eContents();
// List<? extends IModelElement> allChildren =
// getAllChildren(element, element.getClass(), null);
// final IAnnotationValueProvider<IAnnotatedSpecification> annotationProvider =
// registeredHandlers.get(0);
KernelModelElementUtils.runAsCommand(element, new Runnable() {
@Override
......@@ -87,8 +77,6 @@ public class AnnotationValueService extends
while(!(root instanceof IProjectRootElement)) {
root = root.eContainer();
}
// final List<? extends IModelElement> childrenWithType =
// EcoreUtils.getChildrenWithType(root, element.getClass());
for(IAnnotationValueProvider<IAnnotatedSpecification> annotationProvider : registeredHandlers) {
List<? extends IModelElement> allChildren =
......@@ -96,27 +84,28 @@ public class AnnotationValueService extends
annotationProvider.filterOut());
for(final IModelElement e : allChildren) {
EList<IAnnotatedSpecification> annotatedSpecifications =
EcoreUtils.pickInstanceOf(IAnnotatedSpecification.class,
IAnnotatedSpecification annotatedSpecification =
EcoreUtils.pickFirstInstanceOf(annotationProvider.getClazz(),
e.getSpecifications());
IAnnotatedSpecification annotatedSpec = null;
for(IAnnotatedSpecification spec : annotatedSpecifications) {
if(spec.getClass().isInstance(annotationProvider)) {
annotatedSpec = spec;
}
if(annotatedSpecification == null) {
annotatedSpecification =
annotationProvider.addNewSpecToModelElement(e);
}
if(annotatedSpec == null) {
annotatedSpec = annotationProvider.addNewSpecToModelElement(e);
boolean add = true;
for(AnnotationEntry entry : result) {
if(entry.getModelElement().equals(e)) {
entry.addNewSpecification(annotationProvider,
annotatedSpecification);
add = false;
}
}
if(add) {
AnnotationEntry entry = new AnnotationEntry(e);
entry.addNewSpecification(annotationProvider,
annotatedSpecification);
result.add(entry);
}
AnnotationEntry<? extends IAnnotatedSpecification> entry =
new AnnotationEntry<IAnnotatedSpecification>(e, annotatedSpec,
annotationProvider);
result.add(entry);
// if(annotatedSpec.getClass().isInstance(annotationProvider)) {
// result.put(e, annotationProvider.getValues(annotatedSpec));
// }
}
}
......@@ -131,12 +120,14 @@ public class AnnotationValueService extends
* Returns all children from element of the given type and filters out children of the given
* filterOut list
*/
private <S, T> List<T> getAllChildren(EObject element, Class<? extends IModelElement> type,
List<Class<? extends EObject>> filterOut) {
List<T> results = new ArrayList<T>();
getAllChildren2(element, type, filterOut, results);
private <S, T> List<? extends IModelElement> getAllChildren(EObject element,
Class<? extends IModelElement> type, List<Class<? extends EObject>> filterOut) {
List<? extends IModelElement> results = new ArrayList<IModelElement>();
if(filterOut != null)
getAllChildren2(element, type, filterOut, results);
else
results = EcoreUtils.getChildrenWithType(element, type);
return results;
}
......
......@@ -25,7 +25,6 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.ViewPart;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.ui.editpart.DiagramEditPartBase;
import org.fortiss.tooling.base.ui.editpart.ElementEditPartBase;
......@@ -44,8 +43,7 @@ public abstract class AnnotationViewPartBase2 extends ViewPart implements ISelec
private IModelElement currentlySelectedObject;
/** List of all Annotation entries of the {@link #currentlySelectedObject} */
protected List<AnnotationEntry<? extends IAnnotatedSpecification>> values =
new ArrayList<AnnotationEntry<? extends IAnnotatedSpecification>>();
protected List<AnnotationEntry> values = new ArrayList<AnnotationEntry>();
/** {@inheritDoc} */
@Override
......
......@@ -83,7 +83,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
/** {@inheritDoc} */
@Override
public String getText(Object element) {
AnnotationEntry<?> entry = (AnnotationEntry<?>)element;
AnnotationEntry entry = (AnnotationEntry)element;
String modelElementName = entry.getModelElement().getClass().getSimpleName();
modelElementName = modelElementName.replace("Impl", "");
firstColumn.getColumn().setText(modelElementName);
......@@ -93,8 +93,8 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
/** {@inheritDoc} */
@Override
public Color getBackground(Object element) {
if(element instanceof AnnotationEntry<?>) {
AnnotationEntry<?> data = (AnnotationEntry<?>)element;
if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element;
if(data.getModelElement().equals(getCurrentlySelectedObject())) {
return SWTResourceManager.getColor(0, 255, 0);
}
......@@ -116,25 +116,29 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
}
columns.clear();
for(AnnotationEntry<? extends IAnnotatedSpecification> entry : values) {
if(!isExistingColumn(entry.getSpecification())) {
TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE);
column.getColumn().setText(entry.getAnnotationName());
column.getColumn().setWidth(100);
columns.put(entry.getSpecification().getClass(), column);
if(entry.getFixedSpecificationValues() == null) {
column.setLabelProvider(new AnnotationLabelProvider());
EditingSupport editingSupport = new StandardEditingSupport(column.getViewer());
column.setEditingSupport(editingSupport);
} else {
column.setLabelProvider(new AnnotationLabelProvider());
EditingSupport editingSupport =
new ComboEditingSupport(column.getViewer(),
entry.getFixedSpecificationValues());
column.setEditingSupport(editingSupport);
for(AnnotationEntry entry : values) {
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);
columns.put(spec.getClass(), column);
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);
}
}
}
}
}
if(!tableViewer.getTable().isDisposed())
......@@ -150,11 +154,14 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
}
/** Editing support for combo table cells */
private final class ComboEditingSupport extends EditingSupport {
private class ComboEditingSupport extends EditingSupport {
/** Combo box cell editor */
private ComboBoxViewerCellEditor cellEditor = null;
/** Specification class of this column */
private Class<? extends IAnnotatedSpecification> specClass;
/**
* Constructor.
*
......@@ -162,14 +169,17 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
* the column viewer
* @param values
* the values for the combo box
* @param class1
*/
private ComboEditingSupport(ColumnViewer viewer, List<String> values) {
private ComboEditingSupport(ColumnViewer viewer, List<String> values,
Class<? extends IAnnotatedSpecification> class1) {
super(viewer);
cellEditor =
new ComboBoxViewerCellEditor((Composite)getViewer().getControl(), SWT.READ_ONLY);
cellEditor.setLabelProvider(new LabelProvider());
cellEditor.setContentProvider(new ArrayContentProvider());
cellEditor.setInput(values);
specClass = class1;
}
......@@ -182,15 +192,19 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
/** {@inheritDoc} */
@Override
protected boolean canEdit(Object element) {
if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element;
return data.getSpecificationValue(specClass) != AnnotationEntry.NOVAL;
}
return true;
}
/** {@inheritDoc} */
@Override
protected Object getValue(Object element) {
if(element instanceof AnnotationEntry<?>) {
AnnotationEntry<?> data = (AnnotationEntry<?>)element;
return data.getSpecificationValue();
if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element;
return data.getSpecificationValue(specClass);
}
return null;
}
......@@ -198,10 +212,10 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
/** {@inheritDoc} */
@Override
protected void setValue(Object element, final Object value) {
if(element instanceof AnnotationEntry<?> && value instanceof String) {
final AnnotationEntry<?> data = (AnnotationEntry<?>)element;
if(element instanceof AnnotationEntry && value instanceof String) {
final AnnotationEntry data = (AnnotationEntry)element;
if(!value.equals(data.getSpecificationValue())) {
if(!value.equals(data.getSpecificationValue(specClass))) {
ITopLevelElement modelContext =
IPersistencyService.INSTANCE.getTopLevelElementFor(data
.getModelElement());
......@@ -211,11 +225,18 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
public void run() {
try {
data.setSpecificationValue((String)value);
data.setSpecificationValue((String)value, specClass);
} catch(IllegalArgumentException e) {
// should not happen with combo boxes and given values
MessageDialog.openError(new Shell(), "ERROR",
"The value you entered does not have the desired type.");
MessageDialog
.openError(
new Shell(),
"ERROR",
"The value you entered does not have the desired type.\nDetailed message:\n" +
e.getMessage());
} catch(Exception e) {
// e.printStackTrace();
MessageDialog.openError(new Shell(), "ERROR", e.getMessage());
}
}
});
......@@ -228,17 +249,19 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
}
/** Editing Suppourt for standard table cells */
private final class StandardEditingSupport extends EditingSupport {
private class StandardEditingSupport extends EditingSupport {
/** Text cell editor */
private TextCellEditor cellEditor = null;
/** Specification class of this column */
private Class<? extends IAnnotatedSpecification> specClass;
/**
* @param viewer
*/
public StandardEditingSupport(ColumnViewer viewer) {
/** Constructor. */
public StandardEditingSupport(ColumnViewer viewer,
Class<? extends IAnnotatedSpecification> class1) {
super(viewer);
cellEditor = new TextCellEditor((Composite)getViewer().getControl(), SWT.NONE);
specClass = class1;
}
/** {@inheritDoc} */
......@@ -250,15 +273,20 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
/** {@inheritDoc} */
@Override
protected boolean canEdit(Object element) {
if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element;
return data.getSpecificationValue(specClass) != AnnotationEntry.NOVAL;
}
return true;
}
/** {@inheritDoc} */
@Override
protected Object getValue(Object element) {
if(element instanceof AnnotationEntry<?>) {
AnnotationEntry<?> data = (AnnotationEntry<?>)element;
return data.getSpecificationValue();
if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element;
return data.getSpecificationValue(specClass);
}
return null;
}
......@@ -266,10 +294,10 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
/** {@inheritDoc} */
@Override
protected void setValue(Object element, final Object value) {
if(element instanceof AnnotationEntry<?> && value instanceof String) {
final AnnotationEntry<?> data = (AnnotationEntry<?>)element;
if(element instanceof AnnotationEntry && value instanceof String) {
final AnnotationEntry data = (AnnotationEntry)element;
if(!value.equals(data.getSpecificationValue())) {
if(!value.equals(data.getSpecificationValue(specClass))) {
ITopLevelElement modelContext =
IPersistencyService.INSTANCE.getTopLevelElementFor(data
.getModelElement());
......@@ -278,11 +306,17 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
@Override
public void run() {
try {
data.setSpecificationValue((String)value);
data.setSpecificationValue((String)value, specClass);
} catch(IllegalArgumentException e) {
// e.printStackTrace();
MessageDialog.openError(new Shell(), "ERROR",
"The value you entered does not have the desired type.");
MessageDialog
.openError(
new Shell(),
"ERROR",
"The value you entered does not have the desired type.\nDetailed message:\n" +
e.getMessage());
} catch(Exception e) {
MessageDialog.openError(new Shell(), "ERROR", e.getMessage());
}
}
});
......@@ -295,14 +329,23 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
}
/** Label provider for {@link AnnotationEntry}s */
public final class AnnotationLabelProvider extends ColumnLabelProvider {
public class AnnotationLabelProvider extends ColumnLabelProvider {
/** Specification class of this column */
Class<? extends IAnnotatedSpecification> specClass;
/**
* @param class1
*/
public AnnotationLabelProvider(Class<? extends IAnnotatedSpecification> class1) {
specClass = class1;
}
/** {@inheritDoc} */
@Override
public String getText(Object element) {
if(element instanceof AnnotationEntry<?>) {
AnnotationEntry<?> data = (AnnotationEntry<?>)element;
return data.getSpecificationValue();
if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element;
return data.getSpecificationValue(specClass);
}
return "-";
}
......@@ -310,8 +353,8 @@ public class GenericAnnotationView extends AnnotationViewPartBase2 {
/** {@inheritDoc} */
@Override
public Color getBackground(Object element) {
if(element instanceof AnnotationEntry<?>) {
AnnotationEntry<?> data = (AnnotationEntry<?>)element;
if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element;
if(data.getModelElement().equals(getCurrentlySelectedObject())) {
return SWTResourceManager.getColor(0, 255, 0);
}
......
......@@ -19,7 +19,6 @@ package org.fortiss.tooling.base.ui.annotation;
import java.util.List;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
/**
......@@ -35,6 +34,6 @@ public interface IAnnotationValueService {
public static final IAnnotationValueService INSTANCE = new AnnotationValueService();
/** Return the annotated values of the given element */
List<AnnotationEntry<? extends IAnnotatedSpecification>> getValues(IModelElement element);
List<AnnotationEntry> getValues(IModelElement element);
}
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