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

Annotation View: Display value of EReference annotations

Issue-Ref: 4092
Issue-Url: af3#4092



Signed-off-by: default avatarSimon Barner <barner@fortiss.org>
parent c4723292
No related branches found
No related tags found
1 merge request!1474092: Implement a JFX controller for the creation and visualization of reference lists
This commit is part of merge request !147. Comments created here will be created in the context of that merge request.
AnnotationFxViewPart.java ca1548c49aa3842a9436262531464ba345b83688 GREEN
AnnotationTreeTableUIProvider.java 85dfcf003c79d45f82c901b0f3f6bb30db59effa GREEN
AnnotationTreeTableUIProvider.java 9efdeb7261cafe9dfe763daf20af186c906c3ec3 YELLOW
AnnotationViewFXController.java 7d62ea076e87b14c4916935d3466168503c83c6f YELLOW
AnnotationsFXUtils.java 754152735e037da59a4c40fa045602c3ed85a40f GREEN
AnnotationsFXUtils.java e180d593b69b1e4b90adf83ba47753b29f9d6ff8 YELLOW
ColumnHandle.java 7b0fe536d4eb9faa63c4d812f0c078cf83d0fd42 GREEN
FXAnnotationFilterContentProvider.java ca4587ef5dce1288ee4d7bf3bea5bd544ce6b89e GREEN
......@@ -15,11 +15,17 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view.fx;
import static java.util.stream.Collectors.joining;
import static org.fortiss.tooling.base.ui.annotation.view.fx.AnnotationsFXUtils.SELECTED_ANNOTATION_BACKGROUND_COLOR;
import static org.fortiss.tooling.base.ui.annotation.view.fx.AnnotationsFXUtils.getBackgroundColorForEntry;
import static org.fortiss.tooling.base.ui.annotation.view.fx.AnnotationsFXUtils.getValueLabel;
import java.util.Collection;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.base.annotation.AnnotationEntry;
import org.fortiss.tooling.base.annotation.IAnnotationValueService;
import org.fortiss.tooling.base.annotation.valueprovider.EStructuralFeatureDescriptor;
import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
......@@ -62,13 +68,32 @@ import javafx.scene.paint.Color;
this.viewController.colIdxAnnotationMap.get(column)
.getAnnotatedSpecificationType();
IAnnotationValueProvider<IAnnotatedSpecification> valueProvider =
entry.getAnnotationValueProvider(columnSpecType);
EStructuralFeatureDescriptor eStructuralFeatureDescriptor = valueProvider != null
? valueProvider.getEStructuralFeatureDescriptor() : null;
Object specificationValue = entry.getSpecificationValue(columnSpecType);
if(specificationValue != null) {
return specificationValue.toString();
if(specificationValue instanceof Collection) {
Collection<?> values = (Collection<?>)specificationValue;
return "[" + values.stream().map(o -> getLabel(o, eStructuralFeatureDescriptor))
.collect(joining(", ")) + "]";
} else if(specificationValue != null) {
return getLabel(specificationValue, eStructuralFeatureDescriptor);
}
return "";
}
}
/** Returns a label for the given value. */
private String getLabel(Object value,
EStructuralFeatureDescriptor eStructuralFeatureDescriptor) {
EObject root = null;
if(value instanceof IModelElement) {
root = eStructuralFeatureDescriptor.getValueRootElement((IModelElement)value);
}
return getValueLabel(value, root);
}
/** {@inheritDoc} */
......@@ -91,7 +116,7 @@ import javafx.scene.paint.Color;
@Override
public void updateValue(AnnotationEntry element, int column, Object value) {
IAnnotatedSpecification spec = getAnnotation(column, element);
this.viewController.setAnnotationEntryValue(spec, element, (String)value);
this.viewController.setAnnotationEntryValue(spec, element, value);
super.updateValue(element, column, value);
}
......
......@@ -20,11 +20,15 @@ import static javafx.scene.paint.Color.LIGHTGREY;
import static javafx.scene.paint.Color.LIGHTSEAGREEN;
import static javafx.scene.paint.Color.WHITE;
import static org.eclipse.swt.widgets.Display.getCurrent;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.computeFullyQualifiedName;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.computeRelativeName;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.swt.graphics.Device;
import org.fortiss.tooling.base.annotation.AnnotationEntry;
import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvider;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.kernel.model.INamedElement;
import javafx.scene.paint.Color;
......@@ -132,4 +136,18 @@ public class AnnotationsFXUtils {
int blue = (int)color.getBlue();
return new org.eclipse.swt.graphics.Color(device, red, green, blue);
}
/**
* Returns the label for a value shown in the annotation view. For values of EReferences, the
* hierarchical name of the value relative to the given {@code root} model element is returned.
*/
public static String getValueLabel(Object modelELement, EObject root) {
if(modelELement instanceof INamedElement) {
if(root instanceof INamedElement) {
return computeRelativeName((INamedElement)root, (INamedElement)modelELement);
}
return computeFullyQualifiedName((INamedElement)modelELement);
}
return modelELement.toString();
}
}
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