Commit af5000d5 authored by Adrien's avatar Adrien Committed by GitHub

fix(selected line): selected line bg color is white white dark theme on macos (#2534)

macos

* For table using OwnerDrawLabelProvider, we have to draw manually the
bg of the selected line for now (see
https://bugs.eclipse.org/bugs/show_bug.cgi?id=565969 ). But it seems
that the GC default background color isn't the expected one when the
line to draw is selected but unfocused (white instead of dark gray). ->
It makes the text of the items invisible.
So we force the correct background color until this behavior is properly
fix on SWT.

[STUDIO-3705](https://bonitasoft.atlassian.net/browse/STUDIO-3705)
parent 98f5154b
......@@ -24,6 +24,7 @@ import org.bonitasoft.studio.businessobject.editor.model.RelationField;
import org.bonitasoft.studio.businessobject.editor.model.SimpleField;
import org.bonitasoft.studio.businessobject.ui.DateTypeLabels;
import org.bonitasoft.studio.businessobject.validator.AttributeReferenceExitenceValidator;
import org.bonitasoft.studio.preferences.PreferenceUtil;
import org.bonitasoft.studio.ui.ColorConstants;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.IStatus;
......@@ -48,6 +49,9 @@ public class TypeLabelProvider extends StyledCellLabelProvider implements ILabel
private DeprecatedTypeStyler deprecatedStyler = new DeprecatedTypeStyler();
private AttributeReferenceExitenceValidator validator;
private Color errorColor;
private ColumnViewer viewer;
private boolean isDarkTheme;
private Color darkModeSelectLineUnfocused;
public TypeLabelProvider(IObservableValue<BusinessObjectModel> workingCopy) {
validator = new AttributeReferenceExitenceValidator(workingCopy);
......@@ -57,6 +61,10 @@ public class TypeLabelProvider extends StyledCellLabelProvider implements ILabel
@Override
public void initialize(ColumnViewer viewer, ViewerColumn column) {
super.initialize(viewer, column);
this.viewer = viewer;
isDarkTheme = PreferenceUtil.isDarkTheme();
darkModeSelectLineUnfocused = new Color(Display.getDefault(),
ColorConstants.DARK_MODE_TABLE_SELECTED_UNFOCUS);
}
@Override
......@@ -135,14 +143,19 @@ public class TypeLabelProvider extends StyledCellLabelProvider implements ILabel
// Necessary since the MacOS Big Sur update -> Seems that table with StyledCellLabelProvider aren't redraw automatically
// TODO Hopefully this could be removed on the futur (current date: 19/11/2020)
if (Objects.equals(Platform.OS_MACOSX, Platform.getOS())) {
Rectangle bounds = event.getBounds();
if ((event.detail & SWT.SELECTED) != 0) {
Color oldForeground = event.gc.getForeground();
event.gc.setForeground(event.item.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION_TEXT));
Rectangle bounds = event.getBounds();
Color oldBg = event.gc.getBackground();
if (isDarkTheme
&& !Objects.equals(viewer.getControl(),
viewer.getControl().getDisplay().getFocusControl())) {
// Selected line background is white on dark theme if the table doesn't have the focus (only for Owner drawn cells ofc).
// We force it to a gray so it stays consistant with the theme (and became usable btw).
// Should be fixed on swt.cocoa.macosx soon (please).
event.gc.setBackground(darkModeSelectLineUnfocused);
}
event.gc.fillRectangle(bounds);
/* restore the old GC colors */
event.gc.setForeground(oldForeground);
event.gc.setBackground(oldBg);
event.detail &= ~SWT.SELECTED;
}
}
......@@ -151,6 +164,7 @@ public class TypeLabelProvider extends StyledCellLabelProvider implements ILabel
@Override
public void dispose() {
errorColor.dispose();
darkModeSelectLineUnfocused.dispose();
super.dispose();
}
......
......@@ -18,21 +18,39 @@ import java.util.Objects;
import org.bonitasoft.studio.pics.Pics;
import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.PlatformUI;
public abstract class AbstractCheckboxLabelProvider extends StyledCellLabelProvider
implements ILabelProvider {
private boolean isDarkTheme = false;
private Color darkModeSelectLineUnfocused;
private ColumnViewer viewer;
public AbstractCheckboxLabelProvider(final ColumnViewer viewer) {
this.viewer = viewer;
this.darkModeSelectLineUnfocused = new Color(viewer.getControl().getDisplay(), new RGB(70, 70, 70));
try {
IThemeEngine engine = PlatformUI.getWorkbench().getService(IThemeEngine.class);
if (engine.getActiveTheme() != null
&& Objects.equals(engine.getActiveTheme().getId(), "org.bonitasoft.studio.preferences.theme.dark")) {
isDarkTheme = true;
}
} catch (IllegalStateException e) {
// Workbench not created yet, ignored.
}
}
/*
......@@ -106,17 +124,27 @@ public abstract class AbstractCheckboxLabelProvider extends StyledCellLabelProvi
// Necessary since the MacOS Big Sur update -> Seems that table with StyledCellLabelProvider aren't redraw automatically
// TODO Hopefully this could be removed on the futur (current date: 19/11/2020)
if (Objects.equals(Platform.OS_MACOSX, Platform.getOS())) {
Rectangle bounds = event.getBounds();
if ((event.detail & SWT.SELECTED) != 0) {
Color oldForeground = event.gc.getForeground();
event.gc.setForeground(event.item.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION_TEXT));
Rectangle bounds = event.getBounds();
Color oldBg = event.gc.getBackground();
if (isDarkTheme
&& !Objects.equals(viewer.getControl(), viewer.getControl().getDisplay().getFocusControl())) {
// Selected line background is white on dark theme is the table doesn't have the focus (only for Owner drawn cells ofc).
// We force it to a gray so it stays consistant with the theme (and became usable btw).
// Should be fixed on swt.cocoa.macosx soon (please).
event.gc.setBackground(darkModeSelectLineUnfocused);
}
event.gc.fillRectangle(bounds);
/* restore the old GC colors */
event.gc.setForeground(oldForeground);
event.gc.setBackground(oldBg);
event.detail &= ~SWT.SELECTED;
}
}
}
@Override
public void dispose() {
darkModeSelectLineUnfocused.dispose();
super.dispose();
}
}
......@@ -29,7 +29,7 @@ public class ContractInputTypeCellLabelProviderTest {
@Before
public void setUp() throws Exception {
contractInputTypeCellLabelProvider = new ContractInputTypeCellLabelProvider();
contractInputTypeCellLabelProvider = new ContractInputTypeCellLabelProvider(null);
}
@Test
......
......@@ -18,8 +18,6 @@ import org.bonitasoft.studio.common.jface.SWTBotConstants;
import org.bonitasoft.studio.common.widgets.GTKStyleHandler;
import org.bonitasoft.studio.contract.ContractPlugin;
import org.bonitasoft.studio.contract.i18n.Messages;
import org.bonitasoft.studio.contract.ui.property.AddRowOnEnterCellNavigationStrategy;
import org.bonitasoft.studio.contract.ui.property.CharriageColumnViewerEditorActivationStrategy;
import org.bonitasoft.studio.contract.ui.property.IViewerController;
import org.bonitasoft.studio.contract.ui.property.constraint.edit.ConstraintExpressionPropertyEditingSupport;
import org.bonitasoft.studio.contract.ui.property.constraint.edit.ConstraintNameObservableEditingSupport;
......@@ -33,17 +31,12 @@ import org.eclipse.emf.databinding.EMFDataBindingContext;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.viewers.CellNavigationStrategy;
import org.eclipse.jface.viewers.ColumnViewerEditor;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TableViewerEditor;
import org.eclipse.jface.viewers.TableViewerFocusCellManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.SelectionAdapter;
......@@ -79,22 +72,8 @@ public class ContractConstraintsTableViewer extends TableViewer {
propertySourceProvider = new AdapterFactoryContentProvider(adapterFactory);
adapterFactoryLabelProvider = new AdapterFactoryLabelProvider(adapterFactory);
getTable().setHeaderVisible(true);
getTable().setLinesVisible(true);
setContentProvider(new ObservableListContentProvider());
final CellNavigationStrategy cellNavigationStrategy = new AddRowOnEnterCellNavigationStrategy(this,
constraintController);
final TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(this,
new FocusCellOwnerDrawHighlighter(
this),
cellNavigationStrategy);
TableViewerEditor.create(this, focusCellManager, new CharriageColumnViewerEditorActivationStrategy(this),
ColumnViewerEditor.TABBING_HORIZONTAL |
ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR |
ColumnViewerEditor.TABBING_VERTICAL |
ColumnViewerEditor.KEYBOARD_ACTIVATION);
ColumnViewerToolTipSupport.enableFor(this);
createColumns();
configureTableLayout();
......
......@@ -18,8 +18,6 @@ import org.bonitasoft.studio.common.jface.SWTBotConstants;
import org.bonitasoft.studio.common.widgets.GTKStyleHandler;
import org.bonitasoft.studio.contract.core.refactoring.ContractInputRefactorOperationFactory;
import org.bonitasoft.studio.contract.i18n.Messages;
import org.bonitasoft.studio.contract.ui.property.AddRowOnEnterCellNavigationStrategy;
import org.bonitasoft.studio.contract.ui.property.CharriageColumnViewerEditorActivationStrategy;
import org.bonitasoft.studio.contract.ui.property.input.edit.CheckboxPropertyEditingSupport;
import org.bonitasoft.studio.contract.ui.property.input.edit.ContractInputTypeEditingSupport;
import org.bonitasoft.studio.contract.ui.property.input.edit.ContractInputTypePropertyDescriptor;
......@@ -37,17 +35,12 @@ import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider;
import org.eclipse.jface.viewers.CellNavigationStrategy;
import org.eclipse.jface.viewers.ColumnViewerEditor;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.TreeViewerEditor;
import org.eclipse.jface.viewers.TreeViewerFocusCellManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.SelectionAdapter;
......@@ -121,7 +114,6 @@ public class ContractInputTreeViewer extends TreeViewer {
propertySourceProvider = new ContractInputTypePropertyDescriptor(adapterFactory);
adapterFactoryLabelProvider = new AdapterFactoryLabelProvider(adapterFactory);
getTree().setHeaderVisible(true);
getTree().setLinesVisible(true);
addFilter(new ComplexTypeChildrenViewerFilter());
final ObservableListTreeContentProvider contentProvider = new ObservableListTreeContentProvider(
new ContractInputObservableFactory(),
......@@ -129,18 +121,6 @@ public class ContractInputTreeViewer extends TreeViewer {
setContentProvider(contentProvider);
ColumnViewerToolTipSupport.enableFor(this);
final CellNavigationStrategy cellNavigationStrategy = new AddRowOnEnterCellNavigationStrategy(this,
inputController);
final TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(this,
new FocusCellOwnerDrawHighlighter(
this),
cellNavigationStrategy);
TreeViewerEditor.create(this, focusCellManager, new CharriageColumnViewerEditorActivationStrategy(this),
ColumnViewerEditor.TABBING_HORIZONTAL |
ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR |
ColumnViewerEditor.TABBING_VERTICAL |
ColumnViewerEditor.KEYBOARD_ACTIVATION);
createColumns();
configureTableLayout();
}
......@@ -197,7 +177,7 @@ public class ContractInputTreeViewer extends TreeViewer {
protected void createInputTypeColumn() {
final TreeViewerColumn typeColumnViewer = createColumnViewer(Messages.type, SWT.FILL);
typeColumnViewer.setLabelProvider(new ContractInputTypeCellLabelProvider());
typeColumnViewer.setLabelProvider(new ContractInputTypeCellLabelProvider(typeColumnViewer.getViewer()));
typeColumnViewer
.setEditingSupport(new ContractInputTypeEditingSupport(this, propertySourceProvider, inputController,
new ContractInputRefactorOperationFactory(), progressService,
......
......@@ -19,7 +19,10 @@ import java.util.Objects;
import org.bonitasoft.studio.businessobject.ui.DateTypeLabels;
import org.bonitasoft.studio.model.process.ContractInput;
import org.bonitasoft.studio.model.process.ContractInputType;
import org.bonitasoft.studio.preferences.PreferenceUtil;
import org.bonitasoft.studio.ui.ColorConstants;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
......@@ -37,6 +40,16 @@ import org.eclipse.swt.widgets.Event;
*/
public class ContractInputTypeCellLabelProvider extends StyledCellLabelProvider implements ILabelProvider {
private boolean isDarkTheme;
private Color darkModeSelectLineUnfocused;
private ColumnViewer viewer;
public ContractInputTypeCellLabelProvider(ColumnViewer viewer) {
this.viewer = viewer;
isDarkTheme = PreferenceUtil.isDarkTheme();
darkModeSelectLineUnfocused = new Color(Display.getDefault(), ColorConstants.DARK_MODE_TABLE_SELECTED_UNFOCUS);
}
@Override
public Image getImage(final Object element) {
return null;
......@@ -84,18 +97,27 @@ public class ContractInputTypeCellLabelProvider extends StyledCellLabelProvider
// Necessary since the MacOS Big Sur update -> Seems that table with StyledCellLabelProvider aren't redraw automatically
// TODO Hopefully this could be removed on the futur (current date: 19/11/2020)
if (Objects.equals(Platform.OS_MACOSX, Platform.getOS())) {
Rectangle bounds = event.getBounds();
if ((event.detail & SWT.SELECTED) != 0) {
Color oldForeground = event.gc.getForeground();
event.gc.setForeground(event.item.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION_TEXT));
Rectangle bounds = event.getBounds();
Color oldBg = event.gc.getBackground();
if (isDarkTheme
&& !Objects.equals(viewer.getControl(), viewer.getControl().getDisplay().getFocusControl())) {
// Selected line background is white on dark theme is the table doesn't have the focus (only for Owner drawn cells ofc).
// We force it to a gray so it stays consistant with the theme (and became usable btw).
// Should be fixed on swt.cocoa.macosx soon (please).
event.gc.setBackground(darkModeSelectLineUnfocused);
}
event.gc.fillRectangle(bounds);
/* restore the old GC colors */
event.gc.setForeground(oldForeground);
/* ensure that default selection is not drawn */
event.gc.setBackground(oldBg);
event.detail &= ~SWT.SELECTED;
}
}
}
@Override
public void dispose() {
darkModeSelectLineUnfocused.dispose();
super.dispose();
}
}
......@@ -27,6 +27,7 @@ public interface ColorConstants {
static final RGB DARK_MODE_DIAGRAMS_FONT_COLOR = new RGB(200, 200, 200);
static final RGB DARK_MODE_DIAGRAMS_LINE_COLOR = new RGB(100, 100, 100);
static final RGB DARK_MODE_DIAGRAMS_TASK_FONT_COLOR = new RGB(64, 64, 64);
static final RGB DARK_MODE_TABLE_SELECTED_UNFOCUS = new RGB(70, 70, 70);
static final String DARK_MODE_ACTIVITY_GRADIENT_HEXA_COLOR = "#c8c8c8";
......
......@@ -22,6 +22,7 @@ import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import org.bonitasoft.studio.preferences.PreferenceUtil;
import org.bonitasoft.studio.ui.ColorConstants;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
......@@ -97,12 +98,19 @@ public class LabelProviderBuilder<T> {
private Color errorColor;
private Color warningColor;
private ColumnViewer viewer;
private boolean isDarkTheme;
private Color darkModeSelectLineUnfocused;
@Override
public void initialize(ColumnViewer viewer, ViewerColumn column) {
super.initialize(viewer, column);
this.viewer = viewer;
errorColor = new Color(Display.getDefault(), ColorConstants.ERROR_RGB);
warningColor = new Color(Display.getDefault(), ColorConstants.WARNING_RGB);
isDarkTheme = PreferenceUtil.isDarkTheme();
darkModeSelectLineUnfocused = new Color(Display.getDefault(),
ColorConstants.DARK_MODE_TABLE_SELECTED_UNFOCUS);
viewer.getColumnViewerEditor().addEditorActivationListener(refreshAllAfterEdit());
}
......@@ -175,15 +183,19 @@ public class LabelProviderBuilder<T> {
// Necessary since the MacOS Big Sur update -> Seems that table with StyledCellLabelProvider aren't redraw automatically
// TODO Hopefully this could be removed on the futur (current date: 19/11/2020)
if (Objects.equals(Platform.OS_MACOSX, Platform.getOS())) {
Rectangle bounds = event.getBounds();
if ((event.detail & SWT.SELECTED) != 0) {
Color oldForeground = event.gc.getForeground();
event.gc.setForeground(event.item.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION_TEXT));
Rectangle bounds = event.getBounds();
Color oldBg = event.gc.getBackground();
if (isDarkTheme
&& !Objects.equals(viewer.getControl(),
viewer.getControl().getDisplay().getFocusControl())) {
// Selected line background is white on dark theme if the table doesn't have the focus (only for Owner drawn cells ofc).
// We force it to a gray so it stays consistant with the theme (and became usable btw).
// Should be fixed on swt.cocoa.macosx soon (please).
event.gc.setBackground(darkModeSelectLineUnfocused);
}
event.gc.fillRectangle(bounds);
/* restore the old GC colors */
event.gc.setForeground(oldForeground);
/* ensure that default selection is not drawn */
event.gc.setBackground(oldBg);
event.detail &= ~SWT.SELECTED;
}
}
......@@ -193,6 +205,7 @@ public class LabelProviderBuilder<T> {
public void dispose() {
errorColor.dispose();
warningColor.dispose();
darkModeSelectLineUnfocused.dispose();
super.dispose();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment