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

- IAnnotationValueProvider: Introduce canEdit() methods

- Add color code for uneditable annotations values
  - light gray: annotation does not exist for the given model elemnt
  - light blue: annotation is a derived / computed value
refs 1841
parent e7e54954
No related branches found
No related tags found
No related merge requests found
Showing
with 70 additions and 21 deletions
......@@ -94,6 +94,36 @@ public final class AnnotationEntry {
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
}
/** Predicate if the given annotation can be edited. */
public boolean canEdit(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
try {
return providerSpecMapping.get(clazz).canEdit(s);
} catch(Exception e) {
return false;
}
}
}
return false;
}
/** Predicate if the given annotation can be edited. */
public boolean canEdit(Class<? extends IAnnotatedSpecification> clazz, String instanceKey) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
try {
return providerSpecMapping.get(clazz).canEdit(s, instanceKey);
} catch(Exception e) {
return false;
}
}
}
return false;
}
/** Returns the annotation value */
public <V> V getSpecificationValue(Class<? extends IAnnotatedSpecification> clazz,
String instanceKey) {
......
......@@ -51,8 +51,8 @@ public abstract class AnnotationEditingSupportBase extends EditingSupport {
@Override
protected boolean canEdit(Object element) {
if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element;
return data.getSpecificationValue(specClass) != null;
AnnotationEntry annotationEntry = (AnnotationEntry)element;
return annotationEntry.canEdit(specClass);
}
return true;
......
......@@ -20,7 +20,6 @@ package org.fortiss.tooling.base.ui.annotation.editingsupport;
import org.eclipse.jface.viewers.ColumnViewer;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.ui.annotation.AnnotationEntry;
import org.fortiss.tooling.base.ui.annotation.IAnnotationValueService;
import org.fortiss.tooling.base.ui.annotation.valueprovider.DynamicInstanceAnnotationValueProviderBase;
/**
......@@ -63,22 +62,9 @@ public class MultiInstanceAnnotationTextEditingSupport extends TextEditingSuppor
@Override
protected boolean canEdit(Object element) {
if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element;
AnnotationEntry annotationEntry = (AnnotationEntry)element;
// Check if a value already exists.
if(data.getSpecificationValue(specClass, instanceKey) != null) {
return true;
}
// For dynamically instantiated annotations, check if the key exists with at least one
// model element.
for(AnnotationEntry entry : IAnnotationValueService.INSTANCE.getValues(data
.getModelElement())) {
if(entry.getInstanceKeys(specClass).contains(instanceKey)) {
return true;
}
}
return annotationEntry.canEdit(specClass);
}
return false;
......
......@@ -43,6 +43,12 @@ public abstract class DerivedAnnotationValueProviderBase<T extends IDerivedAnnot
super(annotatedSpecificationEClass);
}
/** {@inheritDoc} */
@Override
public boolean canEdit(T specification, String instanceKey) {
return false;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
......
......@@ -166,6 +166,12 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp
((EAttribute)structuralFeature).getEAttributeType(), value));
}
/** {@inheritDoc} */
@Override
public boolean canEdit(T specification, String instanceKey) {
return true;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
......
......@@ -80,6 +80,12 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> ext
*/
public boolean setAnnotationName(String name, T specification);
/** Predicate if the given annotation can be edited. */
public boolean canEdit(T specification);
/** Predicate if the given annotation can be edited. */
public boolean canEdit(T specification, String instanceKey);
/** Returns the value of the annotation. */
public <U> U getAnnotationValue(T specification) throws Exception;
......
......@@ -104,6 +104,12 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple
return false;
}
/** {@inheritDoc} */
@Override
public boolean canEdit(T specification) {
return canEdit(specification, DEFAULT_KEY);
}
/** {@inheritDoc} */
@Override
public <U> U getAnnotationValue(T specification, String instanceKey) throws Exception {
......
......@@ -21,6 +21,7 @@ import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.wb.swt.SWTResourceManager;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IDerivedAnnotation;
import org.fortiss.tooling.base.ui.annotation.AnnotationEntry;
/**
......@@ -80,12 +81,20 @@ public class AnnotationLabelProvider extends ColumnLabelProvider {
@Override
public Color getBackground(Object element) {
if(element instanceof AnnotationEntry) {
AnnotationEntry data = (AnnotationEntry)element;
if(data.getModelElement().equals(parentView.getCurrentlySelectedObject())) {
AnnotationEntry annotationEntry = (AnnotationEntry)element;
if(annotationEntry.getModelElement().equals(parentView.getCurrentlySelectedObject())) {
return SWTResourceManager.getColor(0, 255, 0);
}
if(!annotationEntry.canEdit(specClass, instanceKey)) {
if(IDerivedAnnotation.class.isAssignableFrom(specClass) &&
annotationEntry.getSpecificationValue(specClass, instanceKey) != null) {
return SWTResourceManager.getColor(200, 240, 250);
}
return SWTResourceManager.getColor(230, 230, 230);
}
}
return super.getBackground(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