ref #7518 Colorize deduplication rows + tooltip
authorPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 6 Jul 2018 10:02:50 +0000 (12:02 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 6 Jul 2018 10:02:50 +0000 (12:02 +0200)
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorTooltip.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/l10n/Messages.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/l10n/messages.properties
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/l10n/messages_de.properties

index 76b68989f886d8dc0ec49028b7972fc9315fe068..0673d594fcb900f414891e342d6302fd62e18d57 100644 (file)
@@ -41,6 +41,7 @@ import org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand;
 import org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommandHandler;
 import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
 import org.eclipse.nebula.widgets.nattable.config.AbstractUiBindingConfiguration;
+import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
 import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
 import org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration;
 import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
@@ -63,18 +64,23 @@ import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
 import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
 import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
 import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
+import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
+import org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator;
 import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
 import org.eclipse.nebula.widgets.nattable.selection.RowSelectionModel;
 import org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider;
 import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
 import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
+import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
 import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
+import org.eclipse.nebula.widgets.nattable.style.Style;
 import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
 import org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry;
 import org.eclipse.nebula.widgets.nattable.ui.matcher.CellEditorMouseEventMatcher;
 import org.eclipse.nebula.widgets.nattable.ui.matcher.MouseEventMatcher;
 import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuAction;
 import org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder;
+import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.dnd.Clipboard;
 import org.eclipse.swt.dnd.TextTransfer;
@@ -119,6 +125,9 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
         IDirtyMarkable, IDerivedUnitFacadePart, IPartContentHasFactualData,
         IPartContentHasSupplementalData, IPartContentHasMedia, IE4SavablePart, ITaxonEditor {
 
+    public static final String TARGET_LABEL = "target";
+    public static final String CANDIDATE_LABEL = "candidate";
+
     public static final String TYPE_PROPERTY = Messages.BulkEditorE4_TYPE;
 
     @Inject
@@ -214,6 +223,11 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
         dataLayer.registerCommandHandler(new VisualRefreshCommandHandler());
         GlazedListsEventLayer<CdmBase> eventLayer = new GlazedListsEventLayer<>(dataLayer, input.getModel());
         bodyLayer = new DefaultBodyLayerStack(eventLayer);
+
+        dataLayer.setColumnPercentageSizing(true);
+        dataLayer.setColumnWidthPercentageByPosition(0, 80);
+        dataLayer.setColumnWidthPercentageByPosition(1, 20);
+
         //column
         DataLayer columnHeaderDataLayer = new DataLayer(colHeaderDataProvider);
         ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(
@@ -233,9 +247,6 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
         DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider);
         RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer,
                 bodyLayer, bodyLayer.getSelectionLayer());
-        dataLayer.setColumnPercentageSizing(true);
-        dataLayer.setColumnWidthPercentageByPosition(0, 80);
-        dataLayer.setColumnWidthPercentageByPosition(1, 20);
 
         //corner
         DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(
@@ -255,6 +266,24 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
                 return input.getModel().indexOf(rowObject);
             }
         }));
+
+        //add label to deduplication rows
+        dataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {
+
+            @Override
+            public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
+                CdmBase rowObject = bodyDataProvider.getRowObject(rowPosition);
+                if(input.getMergeCandidates().contains(rowObject)){
+                    configLabels.addLabel(CANDIDATE_LABEL);
+                }
+                else if(input.getMergeTarget()==rowObject){
+                    configLabels.addLabel(TARGET_LABEL);
+                }
+            }
+        });
+
+        //add tooltip to table
+        new BulkEditorTooltip(natTable);
        }
 
        private void configureTable(){
@@ -318,6 +347,30 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
 
         //enable sorting
         natTable.addConfiguration(new SingleClickSortConfiguration());
+
+        // Custom style for deduplication labels
+        natTable.addConfiguration(new AbstractRegistryConfiguration() {
+            @Override
+            public void configureRegistry(IConfigRegistry configRegistry) {
+                Style cellStyle = new Style();
+                cellStyle.setAttributeValue(
+                        CellStyleAttributes.BACKGROUND_COLOR,
+                        GUIHelper.COLOR_YELLOW);
+                configRegistry.registerConfigAttribute(
+                        CellConfigAttributes.CELL_STYLE, cellStyle,
+                        DisplayMode.NORMAL, CANDIDATE_LABEL);
+
+                cellStyle = new Style();
+                cellStyle.setAttributeValue(
+                        CellStyleAttributes.BACKGROUND_COLOR,
+                        GUIHelper.COLOR_GREEN);
+                configRegistry.registerConfigAttribute(
+                        CellConfigAttributes.CELL_STYLE, cellStyle,
+                        DisplayMode.NORMAL, TARGET_LABEL);
+
+            }
+        });
+
         //add default configuration because autoconfigure is set to false in constructor
         natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
         natTable.configure();
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorTooltip.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorTooltip.java
new file mode 100644 (file)
index 0000000..73c11cb
--- /dev/null
@@ -0,0 +1,77 @@
+/**
+* Copyright (C) 2018 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.bulkeditor.e4;
+
+import org.eclipse.jface.window.DefaultToolTip;
+import org.eclipse.jface.window.ToolTip;
+import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+
+import eu.etaxonomy.taxeditor.l10n.Messages;
+
+/**
+ * @author pplitzner
+ * @since Jul 6, 2018
+ *
+ */
+public class BulkEditorTooltip extends DefaultToolTip {
+
+    private NatTable natTable;
+
+    public BulkEditorTooltip(NatTable natTable) {
+        super(natTable, ToolTip.NO_RECREATE, false);
+        this.natTable = natTable;
+}
+
+    @Override
+    protected Object getToolTipArea(Event event) {
+        int col = this.natTable.getColumnPositionByX(event.x);
+        int row = this.natTable.getRowPositionByY(event.y);
+
+        return new Point(col, row);
+    }
+
+    @Override
+    protected String getText(Event event) {
+        int col = this.natTable.getColumnPositionByX(event.x);
+        int row = this.natTable.getRowPositionByY(event.y);
+
+        LabelStack configLabels = natTable.getConfigLabelsByPosition(col, row);
+        if(configLabels.hasLabel(BulkEditorE4.TARGET_LABEL)){
+            return Messages.BulkEditorTooltip_TARGET;
+        }
+        else if(configLabels.hasLabel(BulkEditorE4.CANDIDATE_LABEL)){
+            return Messages.BulkEditorTooltip_CANDIDATE;
+        }
+        return ""; //$NON-NLS-1$
+    }
+
+    @Override
+    protected Composite createToolTipContentArea(Event event,
+            Composite parent) {
+        return super.createToolTipContentArea(event, parent);
+    }
+
+    @Override
+    protected boolean shouldCreateToolTip(Event event) {
+        int col = this.natTable.getColumnPositionByX(event.x);
+        int row = this.natTable.getRowPositionByY(event.y);
+
+        LabelStack configLabels = natTable.getConfigLabelsByPosition(col, row);
+        if(configLabels.hasLabel(BulkEditorE4.CANDIDATE_LABEL)
+                || configLabels.hasLabel(BulkEditorE4.TARGET_LABEL)){
+            return true;
+        }
+        return false;
+    }
+
+}
index 77cea10b012479f6d55bacc7b8ad876f57fc1a5b..9c9de3eca166e178f64212180c18da10aa3a804b 100644 (file)
@@ -30,7 +30,9 @@ public class Messages extends NLS {
     public static String BulkEditorSearchE4_SEARCH;
     public static String BulkEditorSearchE4_TITLE_CACHE;
     public static String BulkEditorSearchE4_WILDCARD;
-       public static String ReferencingObjectsLabelProvider_No_description_available;
+       public static String BulkEditorTooltip_CANDIDATE;
+    public static String BulkEditorTooltip_TARGET;
+    public static String ReferencingObjectsLabelProvider_No_description_available;
     public static String ConvertPerson2TeamHandler_warning;
     public static String ConvertPerson2TeamHandler_lable;
     public static String DeleteHandler_CAN_BE_DELETED;
index d168fe1a745b57bfbbc172d50a217e735119c858..b34d3b229d7bbf6f3e4c39c7656b5b936dfff877 100644 (file)
@@ -22,6 +22,8 @@ BulkEditorInputType_8=Media
 BulkEditorSearchE4_SEARCH=Search
 BulkEditorSearchE4_TITLE_CACHE=Title Cache
 BulkEditorSearchE4_WILDCARD=Use '%s' for wildcard searching
+BulkEditorTooltip_CANDIDATE=Candidate for duplicate removal
+BulkEditorTooltip_TARGET=Target for duplicate removal
 
 USER_CREATOR_user_exists_title=The user already exists
 USER_CREATOR_user_exists=The user already exists in database
index a44e37624e1d8225e6364efbefb68a79ad27bb8c..9044ddde5acb7d0e4248e838abdb936194bf1956 100644 (file)
@@ -22,6 +22,8 @@ BulkEditorInputType_8=Medien
 BulkEditorSearchE4_SEARCH=Suche
 BulkEditorSearchE4_TITLE_CACHE=Title-Cache
 BulkEditorSearchE4_WILDCARD='%s' f\u00FCr Platzhalter-Suche benutzen
+BulkEditorTooltip_CANDIDATE= Kandidat für Duplikatenentfernung
+BulkEditorTooltip_TARGET=Ziel für Duplikatenentfernung
 
 USER_CREATOR_user_exists_title=Der Benutzer existiert bereits
 USER_CREATOR_user_exists=Der Benutzer existiert bereits in der Datenbank.