From a62c96a2d2d2b6572b7351c183cd2d2f6b1b9abb Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Fri, 26 Jun 2020 17:28:22 +0200 Subject: [PATCH] Enable workaround to use text-based checkboxes in tables also on Linux * Factorize decision to useTextIcon() predicate * Use unicode labels to display checked/unchecked items Issue-Ref: 4032 Issue-Url: https://af3-developer.fortiss.org/issues/4032 Signed-off-by: Simon Barner <barner@fortiss.org> --- .../base/ui/annotation/labelprovider/.ratings | 2 +- .../labelprovider/CheckBoxLabelProvider.java | 9 +++++---- .../fortiss/tooling/base/ui/viewers/.ratings | 2 +- .../ui/viewers/CheckBoxLabelProvider.java | 20 ++++++++++++++----- 4 files changed, 22 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 c2963d740..434fed13e 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,5 +1,5 @@ AnnotationLabelProvider.java 27d5bbb02d122e603abd158fa5a1fb39e79b0dc5 GREEN -CheckBoxLabelProvider.java 4030bef65a3b919cb087828b4616e5c966380e3e GREEN +CheckBoxLabelProvider.java 894ef9b2ae1a86d8916c8872da1d94b9e3eeb7bf YELLOW ElementCommentLabelProvider.java 76aa6e9b930ce5680607852fd776172942c89ce5 GREEN ElementLabelProviderBase.java f33502f73033ebdf30316df627e8a9c87e7d1b28 GREEN ElementNameLabelProvider.java 897296ac8318b6dfdea9c50fc73aaeea23c2fffa GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/CheckBoxLabelProvider.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/CheckBoxLabelProvider.java index 4030bef65..894ef9b2a 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/CheckBoxLabelProvider.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/annotation/labelprovider/CheckBoxLabelProvider.java @@ -14,7 +14,9 @@ *******************************************************************************/ package org.fortiss.tooling.base.ui.annotation.labelprovider; -import static org.fortiss.tooling.base.utils.SystemUtils.isMacOSXPlatform; +import static org.fortiss.tooling.base.ui.viewers.CheckBoxLabelProvider.CHECKED_LABEL; +import static org.fortiss.tooling.base.ui.viewers.CheckBoxLabelProvider.UNCHECKED_LABEL; +import static org.fortiss.tooling.base.ui.viewers.CheckBoxLabelProvider.useTextIcon; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.EditingSupport; @@ -48,10 +50,9 @@ public class CheckBoxLabelProvider extends AnnotationLabelProvider { /** {@inheritDoc} */ @Override public String getText(Object element) { - // See #2443 - if(isMacOSXPlatform() && element instanceof AnnotationEntry && + if(useTextIcon() && element instanceof AnnotationEntry && ((AnnotationEntry)element).canEdit(clazz)) { - return isChecked(element) ? "[X]" : "[ ]"; + return isChecked(element) ? CHECKED_LABEL : UNCHECKED_LABEL; } return null; diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/viewers/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/viewers/.ratings index 0c7f37f5d..c9342bcc2 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/viewers/.ratings +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/viewers/.ratings @@ -1,4 +1,4 @@ AbstractIntegerSpinnerEditingSupport.java 7391e5b0d8e10baf5ab2c7f9543ed732a23bbd9d GREEN CheckBoxEditingSupport.java 173a63ee86dc396946ddb625a41d48ffad23982f GREEN -CheckBoxLabelProvider.java 4eb2a54a17225da5a0f4f3a4212cde0c23d50d11 GREEN +CheckBoxLabelProvider.java 99285af6cfd2f286123ffbb023d95ae83bf9e0f8 YELLOW IconNameLabelProvider.java 19eaf843b4b6059c1dc49dca8ede15d07deb30d5 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/viewers/CheckBoxLabelProvider.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/viewers/CheckBoxLabelProvider.java index 4eb2a54a1..99285af6c 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/viewers/CheckBoxLabelProvider.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/viewers/CheckBoxLabelProvider.java @@ -17,6 +17,7 @@ package org.fortiss.tooling.base.ui.viewers; import static org.eclipse.core.runtime.Platform.getBundle; import static org.eclipse.jface.resource.JFaceResources.getImageRegistry; +import static org.fortiss.tooling.base.utils.SystemUtils.isLinuxPlatform; import static org.fortiss.tooling.base.utils.SystemUtils.isMacOSXPlatform; import org.eclipse.jface.resource.ImageRegistry; @@ -53,6 +54,17 @@ public abstract class CheckBoxLabelProvider extends ColumnLabelProvider { /** {@link JFaceResources} id for disabled, checked image. */ private static final String DISABLED_CHECKED_KEY = "DISABLED_CHECKED"; + /** Predicate whether to use a text-based icon (see #4032 and #2443). */ + public static boolean useTextIcon() { + return isMacOSXPlatform() || isLinuxPlatform(); + } + + /** Text label for unchecked checkboxes when {@link #useTextIcon()} returns {@code true}. */ + public static final String UNCHECKED_LABEL = "\u25A1"; + + /** Text label for checked checkboxes when {@link #useTextIcon()} returns {@code true}. */ + public static final String CHECKED_LABEL = "\u2612"; + /** Creates an image of checkbox SWT control. */ private static Image makeShot(boolean selected, boolean enabled) { Shell shell = new Shell(SWT.NO_TRIM); @@ -119,8 +131,7 @@ public abstract class CheckBoxLabelProvider extends ColumnLabelProvider { * @return {@link Image} representing the checkbox. */ public static Image getImage(boolean checked, boolean enabled) { - // See #2443 - if(isMacOSXPlatform()) { + if(useTextIcon()) { return null; } ImageRegistry imgReg = getImageRegistry(); @@ -147,9 +158,8 @@ public abstract class CheckBoxLabelProvider extends ColumnLabelProvider { /** {@inheritDoc} */ @Override public String getText(Object element) { - // See #2443 - if(isMacOSXPlatform() && isEnabled(element)) { - return isChecked(element) ? "[X]" : "[ ]"; + if(useTextIcon() && isEnabled(element)) { + return isChecked(element) ? CHECKED_LABEL : UNCHECKED_LABEL; } return null; } -- GitLab