From 4a69a9141b3d78f505a05fd0b4b92cd90a68afbc Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Thu, 9 May 2019 16:23:21 +0200 Subject: [PATCH] Add getAnnotatationBackgroundColor() * Enable re-use of color scheme also for other editors that embed annotations Issue-Ref: 3696 Issue-Url: https://af3-developer.fortiss.org/issues/3696 Signed-off-by: Simon Barner <barner@fortiss.org> --- .../base/ui/annotation/labelprovider/.ratings | 2 +- .../AnnotationLabelProvider.java | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/.ratings index a39d9e2e8..71eaf932e 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/.ratings +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/.ratings @@ -1,4 +1,4 @@ -AnnotationLabelProvider.java b45aa4fcfb72726a4c43d2053a713aa5f6b3b7b5 GREEN +AnnotationLabelProvider.java 27d5bbb02d122e603abd158fa5a1fb39e79b0dc5 YELLOW CheckBoxLabelProvider.java 4030bef65a3b919cb087828b4616e5c966380e3e GREEN ElementCommentLabelProvider.java 76aa6e9b930ce5680607852fd776172942c89ce5 GREEN ElementLabelProviderBase.java f33502f73033ebdf30316df627e8a9c87e7d1b28 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java index b45aa4fcf..27d5bbb02 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/AnnotationLabelProvider.java @@ -35,7 +35,7 @@ import org.fortiss.tooling.base.ui.annotation.view.IAnnotationViewPart; public class AnnotationLabelProvider extends LabelProviderBase { /** Background color for annotations that cannot be edited (and that are not derived). */ - private static final Color READ_ONLY_ANNOTATION_BACKGROUND_COLOR = + public static final Color READ_ONLY_ANNOTATION_BACKGROUND_COLOR = SWTResourceManager.getColor(230, 230, 230); /** Background color for derived (computed) annotations. */ @@ -96,21 +96,33 @@ public class AnnotationLabelProvider extends LabelProviderBase { /** {@inheritDoc} */ @Override public Color getBackground(Object element) { + Color color = super.getBackground(element); if(element instanceof AnnotationEntry) { AnnotationEntry annotationEntry = (AnnotationEntry)element; if(annotationEntry.getModelElement().equals(viewPart.getCurrentlySelectedObject())) { - return super.getBackground(element); + return color; } - if(!annotationEntry.canEdit(clazz)) { - if(IDerivedAnnotation.class.isAssignableFrom(clazz) && - annotationEntry.getSpecificationValue(clazz) != null) { - return DERIVED_ANNOTATION_BACKGROUND_COLOR; - } - return READ_ONLY_ANNOTATION_BACKGROUND_COLOR; - } + return getAnnotatationBackgroundColor(annotationEntry, clazz, color); + } + return color; + } + + /** + * Returns the background {@link Color} for the {@link AnnotationEntry} of the given + * {@code type}. The method returns dedicated colors for special cases such as read-only or + * "derived" annotations. Otherwise, the provided {@code defaultColor} is returned. + */ + public static Color getAnnotatationBackgroundColor(AnnotationEntry annotationEntry, + Class<? extends IAnnotatedSpecification> type, Color defaultColor) { + if(annotationEntry.canEdit(type)) { + return defaultColor; + } + if(IDerivedAnnotation.class.isAssignableFrom(type) && + annotationEntry.getSpecificationValue(type) != null) { + return DERIVED_ANNOTATION_BACKGROUND_COLOR; } - return super.getBackground(element); + return READ_ONLY_ANNOTATION_BACKGROUND_COLOR; } /** -- GitLab