From 192df69736fbbbe8b3c73156481c1ead49030b17 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sat, 21 Nov 2020 10:14:00 +0100 Subject: [PATCH] fix(selection): selected line is invisible on macos (#2512) * Since the Big Sur update, the behavior of the StyledCellLabelProvider has changed. Depending on the content of the styled cell, the erase method needs to perform some stuff or others (sending en paint signal isn't always enough). [STUDIO-3705](https://bonitasoft.atlassian.net/browse/STUDIO-3705) [STUDIO-3708](https://bonitasoft.atlassian.net/browse/STUDIO-3708) --- .../ui/control/DeployTreeLabelProvider.java | 36 ++++++- .../attribute/AttributeEditionControl.java | 12 ++- .../editor/ui/provider/TypeLabelProvider.java | 26 +++++ .../jface/AbstractCheckboxLabelProvider.java | 37 +++++-- .../ContractConstraintControllerTest.java | 4 +- .../ContractConstraintsTableViewerTest.java | 36 +++++-- ...traintExpressionCellLabelProviderTest.java | 60 ----------- .../InputNameCellLabelProviderTest.java | 51 --------- .../ContractConstraintController.java | 27 ++++- .../ContractConstraintsTableViewer.java | 74 +++++++++---- ...onstraintDescriptionCellLabelProvider.java | 37 ------- ...nstraintErrorMessageCellLabelProvider.java | 37 ------- ...ConstraintExpressionCellLabelProvider.java | 54 ---------- .../ConstraintNameCellLabelProvider.java | 39 ------- .../input/ContractInputTreeViewer.java | 23 ++-- .../ContractInputTypeCellLabelProvider.java | 27 +++++ .../DescriptionCellLabelProvider.java | 43 -------- .../InputNameCellLabelProvider.java | 37 ------- .../ImportModelLabelProviderTest.java | 21 ++-- .../bos/handler/ImportBosHandler.java | 10 +- .../provider/ImportModelLabelProvider.java | 101 ++++++++++++------ .../bos/provider/ImportModelStyler.java | 86 --------------- .../ImportBosArchiveControlSupplier.java | 14 +-- .../viewer/CheckboxLabelProviderBuilder.java | 2 +- .../ui/viewer/LabelProviderBuilder.java | 26 +++++ 25 files changed, 363 insertions(+), 557 deletions(-) delete mode 100644 bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintExpressionCellLabelProviderTest.java delete mode 100644 bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/input/labelProvider/InputNameCellLabelProviderTest.java delete mode 100644 bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintDescriptionCellLabelProvider.java delete mode 100644 bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintErrorMessageCellLabelProvider.java delete mode 100644 bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintExpressionCellLabelProvider.java delete mode 100644 bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintNameCellLabelProvider.java delete mode 100644 bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/labelProvider/DescriptionCellLabelProvider.java delete mode 100644 bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/labelProvider/InputNameCellLabelProvider.java delete mode 100644 bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/provider/ImportModelStyler.java diff --git a/bundles/plugins/org.bonitasoft.studio.application/src/org/bonitasoft/studio/application/ui/control/DeployTreeLabelProvider.java b/bundles/plugins/org.bonitasoft.studio.application/src/org/bonitasoft/studio/application/ui/control/DeployTreeLabelProvider.java index e8ca1ee093..3efed36c74 100644 --- a/bundles/plugins/org.bonitasoft.studio.application/src/org/bonitasoft/studio/application/ui/control/DeployTreeLabelProvider.java +++ b/bundles/plugins/org.bonitasoft.studio.application/src/org/bonitasoft/studio/application/ui/control/DeployTreeLabelProvider.java @@ -14,13 +14,19 @@ */ package org.bonitasoft.studio.application.ui.control; +import java.util.Objects; + import org.bonitasoft.studio.common.repository.model.IDisplayable; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.StyledCellLabelProvider; import org.eclipse.jface.viewers.StyledString; import org.eclipse.jface.viewers.ViewerCell; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; - +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Event; public class DeployTreeLabelProvider extends StyledCellLabelProvider implements ILabelProvider { @@ -42,18 +48,38 @@ public class DeployTreeLabelProvider extends StyledCellLabelProvider implements @Override public Image getImage(Object element) { - if(element instanceof IDisplayable) { - return ((IDisplayable) element).getIcon(); + if (element instanceof IDisplayable) { + return ((IDisplayable) element).getIcon(); } return null; } @Override public String getText(Object element) { - if(element instanceof IDisplayable) { - return ((IDisplayable) element).getDisplayName(); + if (element instanceof IDisplayable) { + return ((IDisplayable) element).getDisplayName(); } return element.toString(); } + @Override + protected void erase(Event event, Object element) { + super.erase(event, element); + + // 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)); + event.gc.fillRectangle(bounds); + /* restore the old GC colors */ + event.gc.setForeground(oldForeground); + event.detail &= ~SWT.SELECTED; + } + } + } + } diff --git a/bundles/plugins/org.bonitasoft.studio.businessobject/src/org/bonitasoft/studio/businessobject/editor/editor/ui/control/attribute/AttributeEditionControl.java b/bundles/plugins/org.bonitasoft.studio.businessobject/src/org/bonitasoft/studio/businessobject/editor/editor/ui/control/attribute/AttributeEditionControl.java index f7f7897866..c4d6bc3b60 100644 --- a/bundles/plugins/org.bonitasoft.studio.businessobject/src/org/bonitasoft/studio/businessobject/editor/editor/ui/control/attribute/AttributeEditionControl.java +++ b/bundles/plugins/org.bonitasoft.studio.businessobject/src/org/bonitasoft/studio/businessobject/editor/editor/ui/control/attribute/AttributeEditionControl.java @@ -45,6 +45,7 @@ import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.observable.Realm; import org.eclipse.core.databinding.observable.list.IObservableList; import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.core.runtime.Platform; import org.eclipse.emf.databinding.EMFObservables; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.jface.databinding.swt.typed.WidgetProperties; @@ -57,6 +58,7 @@ import org.eclipse.jface.layout.LayoutConstants; import org.eclipse.jface.viewers.CheckboxCellEditor; import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.StyledString; import org.eclipse.jface.viewers.TableLayout; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; @@ -205,6 +207,12 @@ public class AttributeEditionControl extends Composite { viewer.setInput(fieldsObservable); selectedFieldObservable = ViewerProperties.singleSelection(Field.class).observe(viewer); + // 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())) { + selectedBoObservable.addValueChangeListener(e -> viewer.getTable().redraw()); + } + addDragAndDropSupport(); } @@ -302,10 +310,10 @@ public class AttributeEditionControl extends Composite { FieldNameValidator fieldNameValidator = new FieldNameValidator(); column.setLabelProvider(new LabelProviderBuilder() - .withTextProvider(element -> element.getName()) + .withStyledStringProvider((element -> new StyledString(element.getName()))) .withStatusProvider(fieldNameValidator::validate) .shouldRefreshAllLabels(viewer) - .createColumnLabelProvider()); + .createStyledCellLabelProvider()); column.setEditingSupport(new EditingSupportBuilder(viewer) .withId(SWTBotConstants.SWTBOT_ID_ATTRIBUTE_NAME_TEXTEDITOR) .withValueProvider(Field::getName) diff --git a/bundles/plugins/org.bonitasoft.studio.businessobject/src/org/bonitasoft/studio/businessobject/editor/editor/ui/provider/TypeLabelProvider.java b/bundles/plugins/org.bonitasoft.studio.businessobject/src/org/bonitasoft/studio/businessobject/editor/editor/ui/provider/TypeLabelProvider.java index ab47c97214..85dc7e2ea9 100644 --- a/bundles/plugins/org.bonitasoft.studio.businessobject/src/org/bonitasoft/studio/businessobject/editor/editor/ui/provider/TypeLabelProvider.java +++ b/bundles/plugins/org.bonitasoft.studio.businessobject/src/org/bonitasoft/studio/businessobject/editor/editor/ui/provider/TypeLabelProvider.java @@ -14,6 +14,8 @@ */ package org.bonitasoft.studio.businessobject.editor.editor.ui.provider; +import java.util.Objects; + import org.bonitasoft.studio.businessobject.editor.editor.ui.styler.DeprecatedTypeStyler; import org.bonitasoft.studio.businessobject.editor.model.BusinessObject; import org.bonitasoft.studio.businessobject.editor.model.BusinessObjectModel; @@ -25,6 +27,7 @@ import org.bonitasoft.studio.businessobject.validator.AttributeReferenceExitence import org.bonitasoft.studio.ui.ColorConstants; import org.eclipse.core.databinding.observable.value.IObservableValue; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.ColumnViewer; @@ -33,9 +36,12 @@ import org.eclipse.jface.viewers.StyledCellLabelProvider; import org.eclipse.jface.viewers.StyledString; import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.jface.viewers.ViewerColumn; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; public class TypeLabelProvider extends StyledCellLabelProvider implements ILabelProvider { @@ -122,6 +128,26 @@ public class TypeLabelProvider extends StyledCellLabelProvider implements ILabel return getStyledString(element).getString(); } + @Override + protected void erase(Event event, Object element) { + super.erase(event, element); + + // 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)); + event.gc.fillRectangle(bounds); + /* restore the old GC colors */ + event.gc.setForeground(oldForeground); + event.detail &= ~SWT.SELECTED; + } + } + } + @Override public void dispose() { errorColor.dispose(); diff --git a/bundles/plugins/org.bonitasoft.studio.common/src/org/bonitasoft/studio/common/jface/AbstractCheckboxLabelProvider.java b/bundles/plugins/org.bonitasoft.studio.common/src/org/bonitasoft/studio/common/jface/AbstractCheckboxLabelProvider.java index 24c341e7ce..7db247b35e 100644 --- a/bundles/plugins/org.bonitasoft.studio.common/src/org/bonitasoft/studio/common/jface/AbstractCheckboxLabelProvider.java +++ b/bundles/plugins/org.bonitasoft.studio.common/src/org/bonitasoft/studio/common/jface/AbstractCheckboxLabelProvider.java @@ -14,18 +14,23 @@ */ package org.bonitasoft.studio.common.jface; +import java.util.Objects; + import org.bonitasoft.studio.pics.Pics; +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.swt.SWT; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.TreeItem; -public abstract class AbstractCheckboxLabelProvider extends StyledCellLabelProvider implements ILabelProvider { +public abstract class AbstractCheckboxLabelProvider extends StyledCellLabelProvider + implements ILabelProvider { public AbstractCheckboxLabelProvider(final ColumnViewer viewer) { } @@ -54,20 +59,21 @@ public abstract class AbstractCheckboxLabelProvider extends StyledCellLabelProvi return true; } - private Image checkboxImage(final boolean selected, final boolean enabled) { if (selected) { - return enabled ? Pics.getImage("/checkboxes/checkbox_yes.png") : Pics.getImage("/checkboxes/checkbox_yes_disabled.png"); + return enabled ? Pics.getImage("/checkboxes/checkbox_yes.png") + : Pics.getImage("/checkboxes/checkbox_yes_disabled.png"); } - return enabled ? Pics.getImage("/checkboxes/checkbox_no.png") : Pics.getImage("/checkboxes/checkbox_no_disabled.png"); + return enabled ? Pics.getImage("/checkboxes/checkbox_no.png") + : Pics.getImage("/checkboxes/checkbox_no_disabled.png"); } @Override protected void paint(final Event event, final Object element) { final Image img = getImage(element); if (img != null) { - final Rectangle bounds = event.item instanceof TableItem ? ((TableItem) event.item).getBounds(event.index) : - ((TreeItem) event.item).getBounds(event.index); + final Rectangle bounds = event.item instanceof TableItem ? ((TableItem) event.item).getBounds(event.index) + : ((TreeItem) event.item).getBounds(event.index); final Rectangle imgBounds = img.getBounds(); bounds.width /= 2; bounds.width -= imgBounds.width / 2; @@ -91,7 +97,26 @@ public abstract class AbstractCheckboxLabelProvider extends StyledCellLabelProvi if (image != null) { event.height = image.getBounds().height; } + } + @Override + protected void erase(Event event, Object element) { + super.erase(event, element); + + // 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)); + event.gc.fillRectangle(bounds); + /* restore the old GC colors */ + event.gc.setForeground(oldForeground); + event.detail &= ~SWT.SELECTED; + } + } } } diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintControllerTest.java b/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintControllerTest.java index b6c1062dc6..d821652c46 100644 --- a/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintControllerTest.java +++ b/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintControllerTest.java @@ -66,7 +66,9 @@ public class ContractConstraintControllerTest { FileActionDialog.setDisablePopup(true); controller = spy(new ContractConstraintController(new WritableValue(aContract().build(), Contract.class))); contract = ProcessFactory.eINSTANCE.createContract(); - when(viewer.getInput()).thenReturn(EMFObservables.observeList(contract, ProcessPackage.Literals.CONTRACT__CONSTRAINTS)); + when(viewer.getInput()) + .thenReturn(EMFObservables.observeList(contract, ProcessPackage.Literals.CONTRACT__CONSTRAINTS)); + doReturn(false).when(controller).isMacos(); } @Test diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintsTableViewerTest.java b/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintsTableViewerTest.java index b909c09c43..2d10ee539c 100644 --- a/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintsTableViewerTest.java +++ b/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintsTableViewerTest.java @@ -16,6 +16,8 @@ package org.bonitasoft.studio.contract.ui.property.constraint; import static org.assertj.core.api.Assertions.assertThat; import static org.bonitasoft.studio.model.process.builders.ContractBuilder.aContract; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; import org.bonitasoft.studio.common.jface.FileActionDialog; import org.bonitasoft.studio.model.process.Contract; @@ -30,6 +32,7 @@ import org.eclipse.core.databinding.observable.value.WritableValue; import org.eclipse.emf.databinding.EMFDataBindingContext; import org.eclipse.emf.databinding.EMFObservables; import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.StyledString; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; @@ -67,8 +70,9 @@ public class ContractConstraintsTableViewerTest { parent = realm.createComposite(); FileActionDialog.setDisablePopup(true); viewer = new ContractConstraintsTableViewer(parent, new FormToolkit(parent.getDisplay())); - final ContractConstraintController inputController = new ContractConstraintController(new WritableValue(aContract() - .build(), Contract.class)); + ContractConstraintController inputController = spy( + new ContractConstraintController(new WritableValue(aContract().build(), Contract.class))); + doReturn(false).when(inputController).isMacos(); viewer.initialize(inputController, messageManager, new EMFDataBindingContext()); final Contract contract = ProcessFactory.eINSTANCE.createContract(); final ContractInput input = ProcessFactory.eINSTANCE.createContractInput(); @@ -81,7 +85,8 @@ public class ContractConstraintsTableViewerTest { constraint2.setName("c2"); contract.getConstraints().add(constraint); contract.getConstraints().add(constraint2); - viewer.setInput(EMFObservables.observeList(Realm.getDefault(), contract, ProcessPackage.Literals.CONTRACT__CONSTRAINTS)); + viewer.setInput( + EMFObservables.observeList(Realm.getDefault(), contract, ProcessPackage.Literals.CONTRACT__CONSTRAINTS)); } @Test @@ -94,7 +99,8 @@ public class ContractConstraintsTableViewerTest { } @Test - public void shoud_createRemoveListener_add_a_selection_listener_that_remove_selected_contract_constraints() throws Exception { + public void shoud_createRemoveListener_add_a_selection_listener_that_remove_selected_contract_constraints() + throws Exception { final Button button = new Button(parent, SWT.PUSH); viewer.createRemoveListener(button); viewer.setSelection(new StructuredSelection(constraint)); @@ -104,7 +110,8 @@ public class ContractConstraintsTableViewerTest { } @Test - public void shoud_createMoveUpListener_add_a_selection_listener_that_moveUp_selected_contract_constraint() throws Exception { + public void shoud_createMoveUpListener_add_a_selection_listener_that_moveUp_selected_contract_constraint() + throws Exception { final Button button = new Button(parent, SWT.PUSH); viewer.createMoveUpListener(button); assertThat(viewer.getTable().getItem(1).getData()).isEqualTo(constraint2); @@ -114,7 +121,8 @@ public class ContractConstraintsTableViewerTest { } @Test - public void shoud_createMoveUpListener_add_a_selection_listener_that_moveDown_selected_contract_constraint() throws Exception { + public void shoud_createMoveUpListener_add_a_selection_listener_that_moveDown_selected_contract_constraint() + throws Exception { final Button button = new Button(parent, SWT.PUSH); viewer.createMoveDownListener(button); assertThat(viewer.getTable().getItem(0).getData()).isEqualTo(constraint); @@ -123,4 +131,20 @@ public class ContractConstraintsTableViewerTest { assertThat(viewer.getTable().getItem(1).getData()).isEqualTo(constraint); } + @Test + public void should_getStyledText_strip_expression_charriage() throws Exception { + final ContractConstraint constraint = ProcessFactory.eINSTANCE.createContractConstraint(); + constraint.setExpression("toto == true && \n titi == false \r"); + final StyledString styledText = viewer.getExpressionStyledText(constraint); + assertThat(styledText.toString()).doesNotContain("\n").doesNotContain("\r"); + } + + @Test + public void should_getStyledText_supportNull() throws Exception { + final ContractConstraint constraint = ProcessFactory.eINSTANCE.createContractConstraint(); + constraint.setExpression(null); + final StyledString styledText = viewer.getExpressionStyledText(constraint); + assertThat(styledText.toString()).doesNotContain("\n").doesNotContain("\r"); + } + } diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintExpressionCellLabelProviderTest.java b/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintExpressionCellLabelProviderTest.java deleted file mode 100644 index 6646905b3a..0000000000 --- a/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintExpressionCellLabelProviderTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (C) 2014 BonitaSoft S.A. - * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2.0 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.bonitasoft.studio.contract.ui.property.constraint.labelProvider; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.bonitasoft.studio.contract.ui.property.constraint.labelProvider.ConstraintExpressionCellLabelProvider; -import org.bonitasoft.studio.model.process.ContractConstraint; -import org.bonitasoft.studio.model.process.ProcessFactory; -import org.bonitasoft.studio.model.process.provider.ProcessItemProviderAdapterFactory; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; -import org.eclipse.jface.viewers.StyledString; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; - -/** - * @author Romain Bioteau - */ -@RunWith(MockitoJUnitRunner.class) -public class ConstraintExpressionCellLabelProviderTest { - - private ConstraintExpressionCellLabelProvider labelProvider; - - @Before - public void setUp() throws Exception { - labelProvider = new ConstraintExpressionCellLabelProvider(new AdapterFactoryContentProvider(new ProcessItemProviderAdapterFactory()), new WritableSet()); - } - - @Test - public void should_getStyledText_strip_expression_charriage() throws Exception { - final ContractConstraint constraint = ProcessFactory.eINSTANCE.createContractConstraint(); - constraint.setExpression("toto == true && \n titi == false \r"); - final StyledString styledText = labelProvider.getStyledText(constraint); - assertThat(styledText.toString()).doesNotContain("\n").doesNotContain("\r"); - } - - @Test - public void should_getStyledText_supportNull() throws Exception { - final ContractConstraint constraint = ProcessFactory.eINSTANCE.createContractConstraint(); - constraint.setExpression(null); - final StyledString styledText = labelProvider.getStyledText(constraint); - assertThat(styledText.toString()).doesNotContain("\n").doesNotContain("\r"); - } - -} diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/input/labelProvider/InputNameCellLabelProviderTest.java b/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/input/labelProvider/InputNameCellLabelProviderTest.java deleted file mode 100644 index 3662e0e8db..0000000000 --- a/bundles/plugins/org.bonitasoft.studio.contract/src-test/java/org/bonitasoft/studio/contract/ui/property/input/labelProvider/InputNameCellLabelProviderTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright (C) 2014 BonitaSoft S.A. - * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2.0 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.bonitasoft.studio.contract.ui.property.input.labelProvider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.bonitasoft.studio.model.process.builders.ContractInputBuilder.aContractInput; - -import org.bonitasoft.studio.model.process.provider.ProcessItemProviderAdapterFactory; -import org.bonitasoft.studio.swt.rules.RealmWithDisplay; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; -import org.junit.Rule; -import org.junit.Test; - -/** - * @author Romain Bioteau - */ -public class InputNameCellLabelProviderTest { - - @Rule - public RealmWithDisplay realmWithDisplay = new RealmWithDisplay(); - - @Test - public void should_display_contract_input_name_as_text() throws Exception { - final InputNameCellLabelProvider labelProvider = new InputNameCellLabelProvider(new AdapterFactoryContentProvider( - new ProcessItemProviderAdapterFactory()), new WritableSet()); - - assertThat(labelProvider.getText(aContractInput().withName("myInput").build())).isEqualTo("myInput"); - } - - @Test - public void should_not_display_an_icon() throws Exception { - final InputNameCellLabelProvider labelProvider = new InputNameCellLabelProvider(new AdapterFactoryContentProvider( - new ProcessItemProviderAdapterFactory()), new WritableSet()); - - assertThat(labelProvider.getImage(aContractInput().build())).isNull(); - } - -} diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintController.java b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintController.java index 30e40db501..04cc1115aa 100644 --- a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintController.java +++ b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintController.java @@ -32,6 +32,7 @@ import org.bonitasoft.studio.model.process.ProcessFactory; import org.bonitasoft.studio.model.process.ProcessPackage; import org.eclipse.core.databinding.observable.list.IObservableList; import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ColumnViewer; import org.eclipse.jface.viewers.IStructuredSelection; @@ -40,6 +41,7 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import com.google.common.base.Function; +import com.google.common.base.Objects; /** * @author Romain Bioteau @@ -71,7 +73,8 @@ public class ContractConstraintController implements IViewerController { private String defaultConstraintName() { final Contract contract = (Contract) contractObservableValue.getValue(); return NamingUtils.generateNewName( - newHashSet(transform(getAllElementOfTypeIn(contract, ContractConstraint.class), toConstraintName())), "constraint", 1); + newHashSet(transform(getAllElementOfTypeIn(contract, ContractConstraint.class), toConstraintName())), + "constraint", 1); } private Function toConstraintName() { @@ -101,27 +104,45 @@ public class ContractConstraintController implements IViewerController { public void moveUp(final ColumnViewer viewer) { final ContractConstraint selectedConstraint = getSelectedConstraint(viewer); final Contract contract = ModelHelper.getFirstContainerOfType(selectedConstraint, Contract.class); - final IObservableList list = CustomEMFEditObservables.observeList(contract, ProcessPackage.Literals.CONTRACT__CONSTRAINTS); + final IObservableList list = CustomEMFEditObservables.observeList(contract, + ProcessPackage.Literals.CONTRACT__CONSTRAINTS); final int index = list.indexOf(selectedConstraint); if (index > 0) { list.move(index, index - 1); //refresh button enablement viewer.setSelection(new StructuredSelection()); viewer.setSelection(new StructuredSelection(selectedConstraint)); + + // 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: 20/11/2020) + if (isMacos()) { + viewer.getControl().redraw(); + } } } + protected boolean isMacos() { + return Objects.equal(Platform.getOS(), Platform.OS_MACOSX); + } + @Override public void moveDown(final ColumnViewer viewer) { final ContractConstraint selectedConstraint = getSelectedConstraint(viewer); final Contract contract = ModelHelper.getFirstContainerOfType(selectedConstraint, Contract.class); - final IObservableList list = CustomEMFEditObservables.observeList(contract, ProcessPackage.Literals.CONTRACT__CONSTRAINTS); + final IObservableList list = CustomEMFEditObservables.observeList(contract, + ProcessPackage.Literals.CONTRACT__CONSTRAINTS); final int index = list.indexOf(selectedConstraint); if (index < list.size() - 1) { list.move(index, index + 1); //refresh button enablement viewer.setSelection(new StructuredSelection()); viewer.setSelection(new StructuredSelection(selectedConstraint)); + + // 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: 20/11/2020) + if (isMacos()) { + viewer.getControl().redraw(); + } } } diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintsTableViewer.java b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintsTableViewer.java index 2c4ad74c2f..663d920b3b 100644 --- a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintsTableViewer.java +++ b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/ContractConstraintsTableViewer.java @@ -16,6 +16,7 @@ package org.bonitasoft.studio.contract.ui.property.constraint; 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; @@ -24,12 +25,10 @@ import org.bonitasoft.studio.contract.ui.property.constraint.edit.ConstraintExpr import org.bonitasoft.studio.contract.ui.property.constraint.edit.ConstraintNameObservableEditingSupport; import org.bonitasoft.studio.contract.ui.property.constraint.edit.DescriptionObservableEditingSupport; import org.bonitasoft.studio.contract.ui.property.constraint.edit.ErrorMessageObservableEditingSupport; -import org.bonitasoft.studio.contract.ui.property.constraint.labelProvider.ConstraintDescriptionCellLabelProvider; -import org.bonitasoft.studio.contract.ui.property.constraint.labelProvider.ConstraintErrorMessageCellLabelProvider; -import org.bonitasoft.studio.contract.ui.property.constraint.labelProvider.ConstraintExpressionCellLabelProvider; -import org.bonitasoft.studio.contract.ui.property.constraint.labelProvider.ConstraintNameCellLabelProvider; +import org.bonitasoft.studio.model.process.ContractConstraint; import org.bonitasoft.studio.model.process.provider.ProcessItemProviderAdapterFactory; -import org.eclipse.core.databinding.observable.set.IObservableSet; +import org.bonitasoft.studio.pics.Pics; +import org.bonitasoft.studio.ui.viewer.LabelProviderBuilder; import org.eclipse.emf.databinding.EMFDataBindingContext; import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; @@ -39,6 +38,7 @@ 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; @@ -82,14 +82,18 @@ public class ContractConstraintsTableViewer extends TableViewer { getTable().setLinesVisible(true); setContentProvider(new ObservableListContentProvider()); - final CellNavigationStrategy cellNavigationStrategy = new AddRowOnEnterCellNavigationStrategy(this, constraintController); - final TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(this, new FocusCellOwnerDrawHighlighter( - this), cellNavigationStrategy); + 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); + 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(); @@ -154,37 +158,61 @@ public class ContractConstraintsTableViewer extends TableViewer { protected void createConstraintNameColumn() { final TableViewerColumn nameColumnViewer = createColumnViewer(Messages.name + " *", SWT.FILL); - nameColumnViewer.setLabelProvider(new ConstraintNameCellLabelProvider(propertySourceProvider, knowElements())); - final ConstraintNameObservableEditingSupport editingSupport = new ConstraintNameObservableEditingSupport(this, messageManager, + nameColumnViewer.setLabelProvider(new LabelProviderBuilder() + .withStyledStringProvider( + constraint -> new StyledString(constraint.getName() == null ? "" : constraint.getName())) + .withImageProvider(constraint -> Pics.getImage("ContractConstraint.gif", ContractPlugin.getDefault())) + .createStyledCellLabelProvider()); + final ConstraintNameObservableEditingSupport editingSupport = new ConstraintNameObservableEditingSupport(this, + messageManager, emfDataBindingContext); editingSupport.setControlId(SWTBotConstants.SWTBOT_ID_CONSTRAINT_NAME_TEXTEDITOR); nameColumnViewer.setEditingSupport(editingSupport); } - private IObservableSet knowElements() { - final ObservableListContentProvider contentProvider = (ObservableListContentProvider) getContentProvider(); - return contentProvider.getKnownElements(); - } - protected void createConstraintExpressionColumn() { final TableViewerColumn nameColumnViewer = createColumnViewer(Messages.expression + " *", SWT.FILL); - nameColumnViewer.setLabelProvider(new ConstraintExpressionCellLabelProvider(propertySourceProvider, knowElements())); + nameColumnViewer.setLabelProvider(new LabelProviderBuilder() + .withStyledStringProvider(this::getExpressionStyledText) + .createStyledCellLabelProvider()); nameColumnViewer.setEditingSupport(new ConstraintExpressionPropertyEditingSupport(this, propertySourceProvider)); } + protected StyledString getExpressionStyledText(ContractConstraint constraint) { + String text = constraint.getExpression(); + if (text != null) { + text = stripCharriage(text); + } else { + text = ""; + } + return new StyledString(text); + } + + private String stripCharriage(String text) { + text = text.replace("\n", " "); + text = text.replace("\r", " "); + return text; + } + protected void createConstraintErrorMessageColumn() { final TableViewerColumn descriptionColumnViewer = createColumnViewer(Messages.technicalErrorMessage, SWT.FILL); - descriptionColumnViewer.setLabelProvider(new ConstraintErrorMessageCellLabelProvider(propertySourceProvider, knowElements())); + descriptionColumnViewer.setLabelProvider(new LabelProviderBuilder() + .withStyledStringProvider(constraint -> new StyledString( + constraint.getErrorMessage() == null ? "" : constraint.getErrorMessage())) + .createStyledCellLabelProvider()); final ErrorMessageObservableEditingSupport editingSupport = new ErrorMessageObservableEditingSupport(this, messageManager, emfDataBindingContext); editingSupport.setControlId(SWTBotConstants.SWTBOT_ID_CONSTRAINT_ERROR_MESSAGE_TEXTEDITOR); descriptionColumnViewer.setEditingSupport(editingSupport); } - + protected void createConstraintDescriptionColumn() { final TableViewerColumn descriptionColumnViewer = createColumnViewer(Messages.description, SWT.FILL); - descriptionColumnViewer.setLabelProvider(new ConstraintDescriptionCellLabelProvider(propertySourceProvider, knowElements())); + descriptionColumnViewer.setLabelProvider(new LabelProviderBuilder() + .withStyledStringProvider(constraint -> new StyledString( + constraint.getDescription() == null ? "" : constraint.getDescription())) + .createStyledCellLabelProvider()); final DescriptionObservableEditingSupport editingSupport = new DescriptionObservableEditingSupport(this, messageManager, emfDataBindingContext); diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintDescriptionCellLabelProvider.java b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintDescriptionCellLabelProvider.java deleted file mode 100644 index 5925b1314d..0000000000 --- a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintDescriptionCellLabelProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2014 BonitaSoft S.A. - * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2.0 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.bonitasoft.studio.contract.ui.property.constraint.labelProvider; - -import org.bonitasoft.studio.common.jface.databinding.CustomPropertyColumnLabelProvider; -import org.bonitasoft.studio.model.process.ProcessPackage; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.views.properties.IPropertySourceProvider; - -/** - * @author Romain Bioteau - */ -public class ConstraintDescriptionCellLabelProvider extends CustomPropertyColumnLabelProvider { - - public ConstraintDescriptionCellLabelProvider(final IPropertySourceProvider propertySourceProvider, final IObservableSet knownElements) { - super(propertySourceProvider, ProcessPackage.Literals.CONTRACT_CONSTRAINT__DESCRIPTION, knownElements); - } - - @Override - public Image getImage(final Object element) { - return null; - } - -} diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintErrorMessageCellLabelProvider.java b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintErrorMessageCellLabelProvider.java deleted file mode 100644 index 8eebb41ed4..0000000000 --- a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintErrorMessageCellLabelProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2014 BonitaSoft S.A. - * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2.0 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.bonitasoft.studio.contract.ui.property.constraint.labelProvider; - -import org.bonitasoft.studio.common.jface.databinding.CustomPropertyColumnLabelProvider; -import org.bonitasoft.studio.model.process.ProcessPackage; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.views.properties.IPropertySourceProvider; - -/** - * @author Romain Bioteau - */ -public class ConstraintErrorMessageCellLabelProvider extends CustomPropertyColumnLabelProvider { - - public ConstraintErrorMessageCellLabelProvider(final IPropertySourceProvider propertySourceProvider, final IObservableSet knownElements) { - super(propertySourceProvider, ProcessPackage.Literals.CONTRACT_CONSTRAINT__ERROR_MESSAGE, knownElements); - } - - @Override - public Image getImage(final Object element) { - return null; - } - -} diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintExpressionCellLabelProvider.java b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintExpressionCellLabelProvider.java deleted file mode 100644 index fe1df257a5..0000000000 --- a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintExpressionCellLabelProvider.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (C) 2014 BonitaSoft S.A. - * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2.0 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.bonitasoft.studio.contract.ui.property.constraint.labelProvider; - -import org.bonitasoft.studio.common.jface.databinding.CustomPropertyColumnLabelProvider; -import org.bonitasoft.studio.model.process.ProcessPackage; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; -import org.eclipse.jface.viewers.StyledString; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.views.properties.IPropertySourceProvider; - -/** - * @author Romain Bioteau - */ -public class ConstraintExpressionCellLabelProvider extends CustomPropertyColumnLabelProvider implements IStyledLabelProvider { - - public ConstraintExpressionCellLabelProvider(final IPropertySourceProvider propertySourceProvider, final IObservableSet knowElements) { - super(propertySourceProvider, ProcessPackage.Literals.CONTRACT_CONSTRAINT__EXPRESSION, knowElements); - } - - @Override - public Image getImage(final Object element) { - return null; - } - - @Override - public StyledString getStyledText(final Object element) { - String text = getText(element); - if (text != null) { - text = stripCharriage(text); - } - return new StyledString(text); - } - - protected String stripCharriage(String text) { - text = text.replace("\n", " "); - text = text.replace("\r", " "); - return text; - } - -} diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintNameCellLabelProvider.java b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintNameCellLabelProvider.java deleted file mode 100644 index 61d6a6f361..0000000000 --- a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/constraint/labelProvider/ConstraintNameCellLabelProvider.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (C) 2014 BonitaSoft S.A. - * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2.0 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.bonitasoft.studio.contract.ui.property.constraint.labelProvider; - -import org.bonitasoft.studio.common.jface.databinding.CustomPropertyColumnLabelProvider; -import org.bonitasoft.studio.contract.ContractPlugin; -import org.bonitasoft.studio.model.process.ProcessPackage; -import org.bonitasoft.studio.pics.Pics; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.views.properties.IPropertySourceProvider; - -/** - * @author Romain Bioteau - */ -public class ConstraintNameCellLabelProvider extends CustomPropertyColumnLabelProvider { - - public ConstraintNameCellLabelProvider(final IPropertySourceProvider propertySourceProvider, final IObservableSet knownElements) { - super(propertySourceProvider, ProcessPackage.Literals.CONTRACT_CONSTRAINT__NAME, knownElements); - } - - @Override - public Image getImage(final Object element) { - return Pics.getImage("ContractConstraint.gif", ContractPlugin.getDefault()); - } - -} diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/ContractInputTreeViewer.java b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/ContractInputTreeViewer.java index 38744fe67d..43f5d9880b 100644 --- a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/ContractInputTreeViewer.java +++ b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/ContractInputTreeViewer.java @@ -26,10 +26,10 @@ import org.bonitasoft.studio.contract.ui.property.input.edit.ContractInputTypePr import org.bonitasoft.studio.contract.ui.property.input.edit.DescriptionObservableEditingSupport; import org.bonitasoft.studio.contract.ui.property.input.edit.InputNameObservableEditingSupport; import org.bonitasoft.studio.contract.ui.property.input.labelProvider.ContractInputTypeCellLabelProvider; -import org.bonitasoft.studio.contract.ui.property.input.labelProvider.DescriptionCellLabelProvider; -import org.bonitasoft.studio.contract.ui.property.input.labelProvider.InputNameCellLabelProvider; import org.bonitasoft.studio.contract.ui.property.input.labelProvider.MultipleInputCheckboxLabelProvider; +import org.bonitasoft.studio.model.process.ContractInput; import org.bonitasoft.studio.model.process.ProcessPackage; +import org.bonitasoft.studio.ui.viewer.LabelProviderBuilder; import org.eclipse.core.databinding.observable.set.IObservableSet; import org.eclipse.emf.databinding.EMFDataBindingContext; import org.eclipse.emf.edit.provider.ComposedAdapterFactory; @@ -42,6 +42,7 @@ 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; @@ -126,20 +127,20 @@ public class ContractInputTreeViewer extends TreeViewer { new ContractInputObservableFactory(), new ContractInputTreeStructureAdvisor()); setContentProvider(contentProvider); - final CellNavigationStrategy cellNavigationStrategy = new AddRowOnEnterCellNavigationStrategy(this, inputController); + 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); - ColumnViewerToolTipSupport.enableFor(this); - createColumns(); configureTableLayout(); } @@ -167,8 +168,9 @@ public class ContractInputTreeViewer extends TreeViewer { protected void createInputNameColumn() { final TreeViewerColumn nameColumnViewer = createColumnViewer(Messages.name + " *", SWT.FILL); - nameColumnViewer.setLabelProvider(new InputNameCellLabelProvider(propertySourceProvider, - knownElements())); + nameColumnViewer.setLabelProvider(new LabelProviderBuilder() + .withStyledStringProvider(input -> new StyledString(input.getName())) + .createStyledCellLabelProvider()); final InputNameObservableEditingSupport editingSupport = new InputNameObservableEditingSupport(this, messageManager, emfDataBindingContext, @@ -183,7 +185,10 @@ public class ContractInputTreeViewer extends TreeViewer { final TreeColumn column = descriptionColumnViewer.getColumn(); column.setToolTipText(Messages.contractInputDescriptionTooltip); column.setImage(sharedImages.getImage(ISharedImages.IMG_OBJS_INFO_TSK)); - descriptionColumnViewer.setLabelProvider(new DescriptionCellLabelProvider(propertySourceProvider, knownElements())); + descriptionColumnViewer.setLabelProvider(new LabelProviderBuilder() + .withStyledStringProvider( + input -> new StyledString(input.getDescription() == null ? "" : input.getDescription())) + .createStyledCellLabelProvider()); final DescriptionObservableEditingSupport editingSupport = new DescriptionObservableEditingSupport(this, messageManager, emfDataBindingContext); editingSupport.setControlId(SWTBotConstants.SWTBOT_ID_INPUT_DESCRIPTION_TEXTEDITOR); diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/labelProvider/ContractInputTypeCellLabelProvider.java b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/labelProvider/ContractInputTypeCellLabelProvider.java index 3ee21f0d9c..895864c973 100644 --- a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/labelProvider/ContractInputTypeCellLabelProvider.java +++ b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/labelProvider/ContractInputTypeCellLabelProvider.java @@ -14,17 +14,23 @@ */ package org.bonitasoft.studio.contract.ui.property.input.labelProvider; +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.eclipse.core.runtime.Platform; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.StyledCellLabelProvider; import org.eclipse.jface.viewers.StyledString; import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.TextStyle; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; /** * @author Romain Bioteau @@ -71,4 +77,25 @@ public class ContractInputTypeCellLabelProvider extends StyledCellLabelProvider } } + @Override + protected void erase(Event event, Object element) { + super.erase(event, element); + + // 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)); + event.gc.fillRectangle(bounds); + /* restore the old GC colors */ + event.gc.setForeground(oldForeground); + /* ensure that default selection is not drawn */ + event.detail &= ~SWT.SELECTED; + } + } + } + } diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/labelProvider/DescriptionCellLabelProvider.java b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/labelProvider/DescriptionCellLabelProvider.java deleted file mode 100644 index 069650c653..0000000000 --- a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/labelProvider/DescriptionCellLabelProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (C) 2014 BonitaSoft S.A. - * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2.0 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.bonitasoft.studio.contract.ui.property.input.labelProvider; - -import org.bonitasoft.studio.common.jface.databinding.CustomPropertyColumnLabelProvider; -import org.bonitasoft.studio.model.process.ContractInput; -import org.bonitasoft.studio.model.process.ProcessPackage; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.views.properties.IPropertySourceProvider; - -/** - * @author Romain Bioteau - */ -public class DescriptionCellLabelProvider extends CustomPropertyColumnLabelProvider { - - public DescriptionCellLabelProvider(final IPropertySourceProvider propertySourceProvider, final IObservableSet knownElements) { - super(propertySourceProvider, ProcessPackage.Literals.CONTRACT_INPUT__DESCRIPTION, knownElements); - } - - @Override - public Image getImage(final Object element) { - return null; - } - - @Override - public String getToolTipText(final Object element) { - return ((ContractInput) element).getDescription(); - } - -} diff --git a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/labelProvider/InputNameCellLabelProvider.java b/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/labelProvider/InputNameCellLabelProvider.java deleted file mode 100644 index 48547d273d..0000000000 --- a/bundles/plugins/org.bonitasoft.studio.contract/src/org/bonitasoft/studio/contract/ui/property/input/labelProvider/InputNameCellLabelProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2014 BonitaSoft S.A. - * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2.0 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.bonitasoft.studio.contract.ui.property.input.labelProvider; - -import org.bonitasoft.studio.common.jface.databinding.CustomPropertyColumnLabelProvider; -import org.bonitasoft.studio.model.process.ProcessPackage; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.views.properties.IPropertySourceProvider; - -/** - * @author Romain Bioteau - */ -public class InputNameCellLabelProvider extends CustomPropertyColumnLabelProvider { - - public InputNameCellLabelProvider(final IPropertySourceProvider propertySourceProvider, final IObservableSet knownElements) { - super(propertySourceProvider, ProcessPackage.Literals.CONTRACT_INPUT__NAME, knownElements); - } - - @Override - public Image getImage(final Object object) { - return null; - } - -} diff --git a/bundles/plugins/org.bonitasoft.studio.importer.bos/src-test/java/org/bonitasoft/studio/importer/bos/provider/ImportModelLabelProviderTest.java b/bundles/plugins/org.bonitasoft.studio.importer.bos/src-test/java/org/bonitasoft/studio/importer/bos/provider/ImportModelLabelProviderTest.java index 6c682b4371..5c644095ed 100644 --- a/bundles/plugins/org.bonitasoft.studio.importer.bos/src-test/java/org/bonitasoft/studio/importer/bos/provider/ImportModelLabelProviderTest.java +++ b/bundles/plugins/org.bonitasoft.studio.importer.bos/src-test/java/org/bonitasoft/studio/importer/bos/provider/ImportModelLabelProviderTest.java @@ -18,14 +18,13 @@ import org.bonitasoft.studio.common.repository.model.IRepositoryStore; import org.bonitasoft.studio.importer.bos.model.AbstractFileModel; import org.bonitasoft.studio.importer.bos.model.ImportFileStoreModel; import org.bonitasoft.studio.importer.bos.model.ImportStoreModel; -import org.eclipse.jface.viewers.StyledString; import org.junit.Test; public class ImportModelLabelProviderTest { @Test public void should_display_folder_name() throws Exception { - final ImportModelLabelProvider labelProvider = new ImportModelLabelProvider(new ImportModelStyler()); + final ImportModelLabelProvider labelProvider = new ImportModelLabelProvider(); final String text = labelProvider.getText(new ImportStoreModel("myRepo", repositoryStore("myRepo"))); @@ -33,21 +32,15 @@ public class ImportModelLabelProviderTest { } @Test - public void should_apply_conflict_style() throws Exception { - final ImportModelLabelProvider labelProvider = new ImportModelLabelProvider(new ImportModelStyler()); - - final StyledString styledText = labelProvider.getStyledText(conflictingImportFileModel()); - - assertThat(styledText.getStyleRanges()).hasSize(1); + public void should_detect_conflicting_status() throws Exception { + ImportModelLabelProvider labelProvider = new ImportModelLabelProvider(); + assertThat(labelProvider.hasStatus(conflictingImportFileModel(), ConflictStatus.CONFLICTING)).isTrue(); } @Test - public void should_apply_same_content_style() throws Exception { - final ImportModelLabelProvider labelProvider = new ImportModelLabelProvider(new ImportModelStyler()); - - final StyledString styledText = labelProvider.getStyledText(sameContentImportFileModel()); - - assertThat(styledText.getStyleRanges()).hasSize(1); + public void should_detect_same_content_status() throws Exception { + final ImportModelLabelProvider labelProvider = new ImportModelLabelProvider(); + assertThat(labelProvider.hasStatus(sameContentImportFileModel(), ConflictStatus.SAME_CONTENT)).isTrue(); } private Object sameContentImportFileModel() { diff --git a/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/handler/ImportBosHandler.java b/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/handler/ImportBosHandler.java index 96242ea3f8..6ce1441437 100644 --- a/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/handler/ImportBosHandler.java +++ b/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/handler/ImportBosHandler.java @@ -36,7 +36,8 @@ public class ImportBosHandler { @org.eclipse.e4.core.di.annotations.Optional @Named("org.bonitasoft.studio.importer.bos.commandparameter.file") String file, @org.eclipse.e4.core.di.annotations.Optional @Named("org.bonitasoft.studio.importer.bos.commandparameter.targetProjectName") String projectName) { final ImportBosArchiveControlSupplier bosArchiveControlSupplier = newImportBosArchiveControlSupplier( - repositoryAccessor, exceptionDialogHandler, file, projectName == null ? repositoryAccessor.getCurrentRepository().getName() : projectName); + repositoryAccessor, exceptionDialogHandler, file, + projectName == null ? repositoryAccessor.getCurrentRepository().getName() : projectName); final Optional archiveModel = WizardBuilder. newWizard() .withTitle(Messages.importBosArchiveTitle) .needProgress() @@ -63,7 +64,8 @@ public class ImportBosHandler { return Optional.ofNullable(bosArchiveControlSupplier.getArchiveModel()); } - protected void importArchive(Shell activeShell, ImportArchiveModel model, ImportBosArchiveControlSupplier bosArchiveControlSupplier, + protected void importArchive(Shell activeShell, ImportArchiveModel model, + ImportBosArchiveControlSupplier bosArchiveControlSupplier, RepositoryAccessor repositoryAccessor) { final SkippableProgressMonitorJobsDialog progressManager = new SkippableProgressMonitorJobsDialog(activeShell); File archiveFile = new File(bosArchiveControlSupplier.getFilePath()); @@ -74,8 +76,8 @@ public class ImportBosHandler { progressManager.run(true, false, operation); } catch (final InvocationTargetException | InterruptedException e) { throw new RuntimeException(e); - }finally { - if(bosArchiveControlSupplier.shouldDeleteTempFile()) { + } finally { + if (bosArchiveControlSupplier.shouldDeleteTempFile()) { archiveFile.delete(); } } diff --git a/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/provider/ImportModelLabelProvider.java b/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/provider/ImportModelLabelProvider.java index 8520b46773..a32987526e 100644 --- a/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/provider/ImportModelLabelProvider.java +++ b/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/provider/ImportModelLabelProvider.java @@ -3,6 +3,7 @@ package org.bonitasoft.studio.importer.bos.provider; import static com.google.common.base.Preconditions.checkArgument; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Objects; @@ -14,50 +15,87 @@ import org.bonitasoft.studio.importer.bos.i18n.Messages; import org.bonitasoft.studio.importer.bos.model.AbstractFileModel; import org.bonitasoft.studio.importer.bos.model.AbstractImportModel; import org.bonitasoft.studio.importer.bos.model.LegacyStoreModel; -import org.bonitasoft.studio.importer.bos.provider.ImportModelStyler.ConflictStyler; import org.bonitasoft.studio.pics.Pics; +import org.bonitasoft.studio.ui.ColorConstants; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ColumnViewer; +import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; +import org.eclipse.jface.viewers.ColumnViewerEditorActivationListener; +import org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEvent; import org.eclipse.jface.viewers.DecorationOverlayIcon; -import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; import org.eclipse.jface.viewers.IDecoration; -import org.eclipse.jface.viewers.IToolTipProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.StyledString; -import org.eclipse.jface.viewers.StyledString.Styler; +import org.eclipse.jface.viewers.ViewerCell; +import org.eclipse.jface.viewers.ViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; -public class ImportModelLabelProvider extends LabelProvider implements IStyledLabelProvider, IToolTipProvider { +public class ImportModelLabelProvider extends ColumnLabelProvider { - private static final int START_OFFSET = 0; private final List toDispose = new ArrayList<>(); - private final ConflictStyler conflictStyler; - private final Styler sameContentStyler; - private Styler notImportedStyle; - - public ImportModelLabelProvider(ImportModelStyler styler) { - this.conflictStyler = styler.createConflictStyler(); - this.sameContentStyler = styler.createSameContentStyler(); - this.notImportedStyle = styler.createNotImportedStyler(); + private Color conflictColor; + private Color notImportedColor; + + @Override + protected void initialize(ColumnViewer viewer, ViewerColumn column) { + super.initialize(viewer, column); + LocalResourceManager localResourceManager = new LocalResourceManager(JFaceResources.getResources(), + viewer.getControl()); + conflictColor = localResourceManager.createColor(ColorConstants.ERROR_RGB); + notImportedColor = Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); + viewer.getColumnViewerEditor().addEditorActivationListener(refreshAllAfterEdit(viewer)); + } + + private ColumnViewerEditorActivationListener refreshAllAfterEdit(ColumnViewer viewer) { + return new ColumnViewerEditorActivationListener() { + + @Override + public void beforeEditorDeactivated(ColumnViewerEditorDeactivationEvent event) { + } + + @Override + public void beforeEditorActivated(ColumnViewerEditorActivationEvent event) { + } + + @Override + public void afterEditorDeactivated(ColumnViewerEditorDeactivationEvent event) { + if (viewer.getInput() instanceof Collection) { + viewer.getControl().getDisplay().asyncExec( + () -> { + if (viewer != null && !viewer.getControl().isDisposed() + && viewer.getInput() != null) { + viewer.update(((Collection) viewer.getInput()).toArray(), null); + } + }); + } + } + + @Override + public void afterEditorActivated(ColumnViewerEditorActivationEvent event) { + } + }; } @Override - public StyledString getStyledText(Object element) { - String name = getText(element); - StyledString styledString = new StyledString(name); + public void update(ViewerCell cell) { + Object element = cell.getElement(); + cell.setText(getText(element)); + cell.setImage(getImage(element)); + if (hasStatus(element, ConflictStatus.CONFLICTING)) { - styledString.setStyle(START_OFFSET, name.length(), conflictStyler); + cell.setForeground(conflictColor); } if (hasStatus(element, ConflictStatus.SAME_CONTENT)) { - styledString.append(String.format(" (%s)", Messages.skipped)); - styledString.setStyle(START_OFFSET, styledString.length(), sameContentStyler); + cell.setForeground(notImportedColor); } if (element instanceof LegacyStoreModel) { - styledString.setStyle(START_OFFSET, styledString.length(), notImportedStyle); - styledString.append(String.format(" (%s)", Messages.legacyFormsNotImported)); + cell.setForeground(notImportedColor); } - return styledString; } public boolean hasStatus(Object element, ConflictStatus status) { @@ -119,13 +157,6 @@ public class ImportModelLabelProvider extends LabelProvider implements IStyledLa } } - @Override - public void dispose() { - super.dispose(); - conflictStyler.dispose(); - toDispose.stream().forEach(Image::dispose); - } - @Override public String getToolTipText(Object element) { if (element instanceof AbstractImportModel) { @@ -149,4 +180,10 @@ public class ImportModelLabelProvider extends LabelProvider implements IStyledLa return null; } + @Override + public void dispose() { + super.dispose(); + toDispose.forEach(Image::dispose); + } + } diff --git a/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/provider/ImportModelStyler.java b/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/provider/ImportModelStyler.java deleted file mode 100644 index 51aff38f93..0000000000 --- a/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/provider/ImportModelStyler.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Copyright (C) 2016 Bonitasoft S.A. - * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2.0 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.bonitasoft.studio.importer.bos.provider; - -import org.bonitasoft.studio.ui.ColorConstants; -import org.eclipse.jface.viewers.StyledString.Styler; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.TextStyle; -import org.eclipse.swt.widgets.Display; - -public class ImportModelStyler { - - public static class ConflictStyler extends Styler { - - private final Color fForegroundColor; - - public ConflictStyler() { - fForegroundColor = new Color(Display.getCurrent(), ColorConstants.ERROR_RGB); - } - - @Override - public void applyStyles(TextStyle textStyle) { - textStyle.foreground = fForegroundColor; - } - - public void dispose() { - fForegroundColor.dispose(); - } - } - - public static class SameContentStyler extends Styler { - - private final Color fForegroundColor; - - public SameContentStyler() { - fForegroundColor = Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); - } - - @Override - public void applyStyles(TextStyle textStyle) { - textStyle.foreground = fForegroundColor; - } - - } - - public static class NotImportedStyler extends Styler { - - private final Color fForegroundColor; - - public NotImportedStyler() { - fForegroundColor = Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); - } - - @Override - public void applyStyles(TextStyle textStyle) { - textStyle.foreground = fForegroundColor; - textStyle.strikeout = true; - } - - } - - public ConflictStyler createConflictStyler() { - return new ConflictStyler(); - } - - public Styler createSameContentStyler() { - return new SameContentStyler(); - } - - public Styler createNotImportedStyler() { - return new NotImportedStyler(); - } -} diff --git a/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/wizard/ImportBosArchiveControlSupplier.java b/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/wizard/ImportBosArchiveControlSupplier.java index edaaa2621f..b3b81c0191 100644 --- a/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/wizard/ImportBosArchiveControlSupplier.java +++ b/bundles/plugins/org.bonitasoft.studio.importer.bos/src/org/bonitasoft/studio/importer/bos/wizard/ImportBosArchiveControlSupplier.java @@ -33,7 +33,6 @@ import org.bonitasoft.studio.importer.bos.operation.ParseBosArchiveOperation; import org.bonitasoft.studio.importer.bos.provider.ArchiveTreeContentProvider; import org.bonitasoft.studio.importer.bos.provider.ImportActionEditingSupport; import org.bonitasoft.studio.importer.bos.provider.ImportModelLabelProvider; -import org.bonitasoft.studio.importer.bos.provider.ImportModelStyler; import org.bonitasoft.studio.ui.ColorConstants; import org.bonitasoft.studio.ui.dialog.ExceptionDialogHandler; import org.bonitasoft.studio.ui.validator.MultiValidator; @@ -58,7 +57,6 @@ import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.LocalResourceManager; import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; import org.eclipse.jface.viewers.TableLayout; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewerColumn; @@ -150,7 +148,8 @@ public class ImportBosArchiveControlSupplier implements ControlSupplier { try { myFile = fetchArchive(filePath); } catch (FetchRemoteBosArchiveException e) { - textWidget.getValueBinding().getValidationStatus().setValue(ValidationStatus.error(String.format(Messages.cannotImportRemoteArchive,e.getLocalizedMessage()))); + textWidget.getValueBinding().getValidationStatus().setValue(ValidationStatus + .error(String.format(Messages.cannotImportRemoteArchive, e.getLocalizedMessage()))); return; } } @@ -236,8 +235,8 @@ public class ImportBosArchiveControlSupplier implements ControlSupplier { final TreeViewerColumn archiveColumn = new TreeViewerColumn(viewer, SWT.NONE); archiveColumn.getColumn().setText(Messages.archiveColumn); - archiveColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(new ImportModelLabelProvider( - new ImportModelStyler()))); + + archiveColumn.setLabelProvider(new ImportModelLabelProvider()); final TreeViewerColumn actionColumn = new TreeViewerColumn(viewer, SWT.NONE); actionColumn.getColumn().setText(Messages.actionColumn); @@ -355,7 +354,8 @@ public class ImportBosArchiveControlSupplier implements ControlSupplier { try { myFile = fetchArchive(filePath); } catch (FetchRemoteBosArchiveException ex) { - textWidget.getValueBinding().getValidationStatus().setValue(ValidationStatus.error(String.format(Messages.cannotImportRemoteArchive,ex.getLocalizedMessage()))); + textWidget.getValueBinding().getValidationStatus().setValue(ValidationStatus + .error(String.format(Messages.cannotImportRemoteArchive, ex.getLocalizedMessage()))); return; } } @@ -377,7 +377,7 @@ public class ImportBosArchiveControlSupplier implements ControlSupplier { exceptionDialogHandler.openErrorDialog(Display.getDefault().getActiveShell(), Messages.errorOccuredWhileParsingBosArchive, ex); } - if(!operation.getStatus().isOK()) { + if (!operation.getStatus().isOK()) { throw new FetchRemoteBosArchiveException(operation.getStatus().getException()); } urlTempPath = operation.getURLTempPath(); diff --git a/bundles/plugins/org.bonitasoft.studio.ui/src/org/bonitasoft/studio/ui/viewer/CheckboxLabelProviderBuilder.java b/bundles/plugins/org.bonitasoft.studio.ui/src/org/bonitasoft/studio/ui/viewer/CheckboxLabelProviderBuilder.java index e6e9542355..64b48e24fe 100644 --- a/bundles/plugins/org.bonitasoft.studio.ui/src/org/bonitasoft/studio/ui/viewer/CheckboxLabelProviderBuilder.java +++ b/bundles/plugins/org.bonitasoft.studio.ui/src/org/bonitasoft/studio/ui/viewer/CheckboxLabelProviderBuilder.java @@ -3,7 +3,7 @@ * BonitaSoft is a trademark of BonitaSoft SA. * This software file is BONITASOFT CONFIDENTIAL. Not For Distribution. * For commercial licensing information, contact: - * BonitaSoft, 32 rue Gustave Eiffel – 38000 Grenoble + * BonitaSoft, 32 rue Gustave Eiffel � 38000 Grenoble * or BonitaSoft US, 51 Federal Street, Suite 305, San Francisco, CA 94107 *******************************************************************************/ package org.bonitasoft.studio.ui.viewer; diff --git a/bundles/plugins/org.bonitasoft.studio.ui/src/org/bonitasoft/studio/ui/viewer/LabelProviderBuilder.java b/bundles/plugins/org.bonitasoft.studio.ui/src/org/bonitasoft/studio/ui/viewer/LabelProviderBuilder.java index 853e0511df..6aa2e23f3f 100644 --- a/bundles/plugins/org.bonitasoft.studio.ui/src/org/bonitasoft/studio/ui/viewer/LabelProviderBuilder.java +++ b/bundles/plugins/org.bonitasoft.studio.ui/src/org/bonitasoft/studio/ui/viewer/LabelProviderBuilder.java @@ -18,12 +18,14 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.function.Function; import org.bonitasoft.studio.ui.ColorConstants; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.ColumnLabelProvider; @@ -36,10 +38,13 @@ import org.eclipse.jface.viewers.StyledCellLabelProvider; import org.eclipse.jface.viewers.StyledString; import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.jface.viewers.ViewerColumn; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; public class LabelProviderBuilder { @@ -163,6 +168,27 @@ public class LabelProviderBuilder { return refreshAfterEditListener(); } + @Override + protected void erase(Event event, Object element) { + super.erase(event, element); + + // 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)); + event.gc.fillRectangle(bounds); + /* restore the old GC colors */ + event.gc.setForeground(oldForeground); + /* ensure that default selection is not drawn */ + event.detail &= ~SWT.SELECTED; + } + } + } + @Override public void dispose() { errorColor.dispose(); -- GitLab