commit f6f03fa33526f43dda6397e7848b20efd4e3bedc
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Tue May 29 12:34:39 2018 +0200

    ref #7439 Show titleCache in NatTable in bulk editors

diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
index 51bacce2f..7fc8f38a3 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
@@ -9,8 +9,9 @@
 
 package eu.etaxonomy.taxeditor.bulkeditor.e4;
 
-import java.util.EventObject;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
@@ -27,21 +28,10 @@ import org.eclipse.e4.ui.services.EMenuService;
 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.ColumnViewerEditor;
-import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
-import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
-import org.eclipse.jface.viewers.ICellModifier;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
 import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.TableViewerEditor;
-import org.eclipse.jface.viewers.TableViewerFocusCellManager;
-import org.eclipse.jface.viewers.TextCellEditor;
 import org.eclipse.nebula.widgets.nattable.NatTable;
 import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
 import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
@@ -52,18 +42,19 @@ import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
 import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
 import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
 import org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer;
-import org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer;
 import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer;
+import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
+import org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer;
+import org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform;
 import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
-import org.eclipse.nebula.widgets.nattable.layer.ILayer;
 import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
+import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
+import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
+import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Table;
 
 import ca.odell.glazedlists.BasicEventList;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
@@ -131,92 +122,93 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
     public BulkEditorE4() {
 	}
 
-	public void init(AbstractBulkEditorInput<?> input){
+	@SuppressWarnings("unused")
+    public void init(AbstractBulkEditorInput<?> input){
 	    this.input = input;
 	    this.conversation = input.getConversation();
 
-	    BulkEditorSearchE4 searchBar = new BulkEditorSearchE4(this, topComposite, SWT.NONE);
+	    new BulkEditorSearchE4(this, topComposite, SWT.NONE);
 	    //layout needed because the search bar is added after @PostConstuct method
 	    topComposite.getParent().layout();
 
 	    thisPart.setLabel(input.getEditorName());
 
-	    //create columns
-	    Table table = viewer.getTable();
-	    String[] titles = {input.getName(), "Type"};
-	    int[] bounds = {500, 100};
-
-	    ColumnViewerEditorActivationStrategy activationSupport = new ColumnViewerEditorActivationStrategy(viewer) {
-            @Override
-            protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
-                // Enable editor only with mouse double click
-                if (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION) {
-                    EventObject source = event.sourceEvent;
-                    if (source instanceof MouseEvent && ((MouseEvent)source).button == 3) {
-                        return false;
-                    }
-
-                    return true;
-                }
-
-                return false;
-            }
-        };
-        TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new BulkEditorFocusCellOwnerDrawHighLighter(viewer));
-
-        TableViewerEditor.create(viewer, focusCellManager, activationSupport, ColumnViewerEditor.TABBING_HORIZONTAL |
-                ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR |
-                ColumnViewerEditor.TABBING_VERTICAL |
-                ColumnViewerEditor.KEYBOARD_ACTIVATION );
-
-	    CellEditor[] editors = new CellEditor[titles.length];
-	    for (int i = 0; i < titles.length; i++) {
-	        TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
-	        editors[i] = new TextCellEditor(table);
-
-	        column.getColumn().setText(titles[i]);
-	        column.getColumn().setWidth(bounds[i]);
-	        column.getColumn().setResizable(true);
-	        column.getColumn().setMoveable(true);
-
-	    }
-
-	    table.setHeaderVisible(true);
-	    table.setLinesVisible(true);
-
-	    viewer.setCellEditors(editors);
-	    viewer.setColumnProperties(titles);
-
-	    //content and label provider (NOTE: has to be set AFTER creating cell editors
-	    viewer.setContentProvider(new ArrayContentProvider());
-        BulkEditorLabelProvider labelProvider = new BulkEditorLabelProvider(this);
-        viewer.setLabelProvider(labelProvider);
-
-
-        //allow text selection
-        viewer.setCellModifier(new ICellModifier() {
-            @Override
-            public void modify(Object element, String property, Object value) {
-            }
-            @Override
-            public Object getValue(Object element, String property) {
-                ITableLabelProvider tableLabelProvider = null;
-                if(viewer.getLabelProvider() instanceof ITableLabelProvider){
-                    tableLabelProvider = (ITableLabelProvider) viewer.getLabelProvider();
-                }
-                Object[] columnProperties = viewer.getColumnProperties();
-                for (int i=0;i<columnProperties.length;i++) {
-                    if(columnProperties[i].equals(property) && tableLabelProvider!=null){
-                        return tableLabelProvider.getColumnText(element, i);
-                    }
-                }
-                return "";
-            }
-            @Override
-            public boolean canModify(Object element, String property) {
-                return true;
-            }
-        });
+//	    //create columns
+//	    Table table = viewer.getTable();
+//	    String[] titles = {input.getName(), "Type"};
+//	    int[] bounds = {500, 100};
+//
+//	    ColumnViewerEditorActivationStrategy activationSupport = new ColumnViewerEditorActivationStrategy(viewer) {
+//            @Override
+//            protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
+//                // Enable editor only with mouse double click
+//                if (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION) {
+//                    EventObject source = event.sourceEvent;
+//                    if (source instanceof MouseEvent && ((MouseEvent)source).button == 3) {
+//                        return false;
+//                    }
+//
+//                    return true;
+//                }
+//
+//                return false;
+//            }
+//        };
+//        TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new BulkEditorFocusCellOwnerDrawHighLighter(viewer));
+//
+//        TableViewerEditor.create(viewer, focusCellManager, activationSupport, ColumnViewerEditor.TABBING_HORIZONTAL |
+//                ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR |
+//                ColumnViewerEditor.TABBING_VERTICAL |
+//                ColumnViewerEditor.KEYBOARD_ACTIVATION );
+//
+//	    CellEditor[] editors = new CellEditor[titles.length];
+//	    for (int i = 0; i < titles.length; i++) {
+//	        TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
+//	        editors[i] = new TextCellEditor(table);
+//
+//	        column.getColumn().setText(titles[i]);
+//	        column.getColumn().setWidth(bounds[i]);
+//	        column.getColumn().setResizable(true);
+//	        column.getColumn().setMoveable(true);
+//
+//	    }
+//
+//	    table.setHeaderVisible(true);
+//	    table.setLinesVisible(true);
+//
+//	    viewer.setCellEditors(editors);
+//	    viewer.setColumnProperties(titles);
+//
+//	    //content and label provider (NOTE: has to be set AFTER creating cell editors
+//	    viewer.setContentProvider(new ArrayContentProvider());
+//        BulkEditorLabelProvider labelProvider = new BulkEditorLabelProvider(this);
+//        viewer.setLabelProvider(labelProvider);
+//
+//
+//        //allow text selection
+//        viewer.setCellModifier(new ICellModifier() {
+//            @Override
+//            public void modify(Object element, String property, Object value) {
+//            }
+//            @Override
+//            public Object getValue(Object element, String property) {
+//                ITableLabelProvider tableLabelProvider = null;
+//                if(viewer.getLabelProvider() instanceof ITableLabelProvider){
+//                    tableLabelProvider = (ITableLabelProvider) viewer.getLabelProvider();
+//                }
+//                Object[] columnProperties = viewer.getColumnProperties();
+//                for (int i=0;i<columnProperties.length;i++) {
+//                    if(columnProperties[i].equals(property) && tableLabelProvider!=null){
+//                        return tableLabelProvider.getColumnText(element, i);
+//                    }
+//                }
+//                return "";
+//            }
+//            @Override
+//            public boolean canModify(Object element, String property) {
+//                return true;
+//            }
+//        });
 
 
 
@@ -238,74 +230,101 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
 
 		Composite bottomComposite = new Composite(parent, SWT.NONE);
 		bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-		bottomComposite.setLayout(new FillLayout());
+		bottomComposite.setLayout(new GridLayout());
 
 
 		//++++NatTable++++
-		natTable = new NatTable(parent, false);
-		list = new BasicEventList<>();
-        ListDataProvider<Object> dataProvider = new ListDataProvider<>(list, new ReflectiveColumnPropertyAccessor<>("titleCache"));
-        DataLayer dataLayer = new DataLayer(dataProvider);
-        GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(dataLayer, list);
-        DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(eventLayer);
+		natTable = createExampleControl(bottomComposite);
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
 
-        /**
-         * column header layer
-         */
-        IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(new String[] {"titleCache"});
-        DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
-        ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
 
-        /**
-         * row header layer
-         */
-        IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(dataProvider);
-        DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
 
 
-        /**
-         * corner layer
-         */
-        ILayer cornerLayer = new CornerLayer(
-                new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
-                rowHeaderDataLayer, rowHeaderDataLayer);
 
 
-        /**
-         * GRID layer (composition of all other layers)
-         */
-        GridLayer gridLayer = new GridLayer(bodyLayerStack, columnHeaderLayer, rowHeaderDataLayer, cornerLayer);
 
-        natTable.setLayer(gridLayer);
 
-        natTable.configure();
 
-        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
 
 
 
 
+//		viewer = new TableViewer(bottomComposite, SWT.MULTI | SWT.FULL_SELECTION);
 
+//		createColumns(viewer);
 
+        //propagate selection
+        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
+//        viewer.addSelectionChangedListener(selectionChangedListener);
 
+        //create context menu
+//        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor"); //$NON-NLS-1$
 
+	}
+    private IDataProvider bodyDataProvider;
+    private String[] propertyNames;
+    private Map<String, String> propertyToLabels;
+
+    public NatTable createExampleControl(Composite parent) {
+        this.bodyDataProvider = setupBodyDataProvider();
+        DefaultColumnHeaderDataProvider colHeaderDataProvider = new DefaultColumnHeaderDataProvider(
+                this.propertyNames, this.propertyToLabels);
+        DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
+                this.bodyDataProvider);
+
+        DataLayer dataLayer = new DataLayer(bodyDataProvider);
+        GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(dataLayer, list);
+        DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(eventLayer);
 
+        ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(
+                new DataLayer(colHeaderDataProvider),
+                bodyLayer, bodyLayer.getSelectionLayer());
 
+        RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowHeaderDataProvider, 50, 20),
+                bodyLayer, bodyLayer.getSelectionLayer());
 
+        DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(
+                colHeaderDataProvider, rowHeaderDataProvider);
+        CornerLayer cornerLayer = new CornerLayer(new DataLayer(
+                cornerDataProvider), rowHeaderLayer, columnHeaderLayer);
 
+        GridLayer gridLayer = new GridLayer(bodyLayer, columnHeaderLayer,
+                rowHeaderLayer, cornerLayer);
+        NatTable natTable = new NatTable(parent, gridLayer);
 
-		viewer = new TableViewer(bottomComposite, SWT.MULTI | SWT.FULL_SELECTION);
+        return natTable;
+    }
 
-//		createColumns(viewer);
+    private IDataProvider setupBodyDataProvider() {
+        list = new BasicEventList<>();
 
-        //propagate selection
-        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
-        viewer.addSelectionChangedListener(selectionChangedListener);
+        this.propertyToLabels = new HashMap<>();
+        this.propertyToLabels.put("titleCache", "Title Cache");
+        this.propertyNames = new String[] { "titleCache" };
+        return new ListDataProvider(list,
+                new ReflectiveColumnPropertyAccessor(this.propertyNames));
 
-        //create context menu
-        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor"); //$NON-NLS-1$
+    }
 
-	}
+    public class BodyLayerStack extends AbstractLayerTransform {
+
+        private SelectionLayer selectionLayer;
+
+        public BodyLayerStack(IDataProvider dataProvider) {
+            DataLayer bodyDataLayer = new DataLayer(dataProvider);
+            ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(
+                    bodyDataLayer);
+            ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(
+                    columnReorderLayer);
+            this.selectionLayer = new SelectionLayer(columnHideShowLayer);
+            ViewportLayer viewportLayer = new ViewportLayer(this.selectionLayer);
+            setUnderlyingLayer(viewportLayer);
+        }
+
+        public SelectionLayer getSelectionLayer() {
+            return this.selectionLayer;
+        }
+    }
 
 	@Override
 	@Persist
@@ -349,7 +368,7 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
             performSearch(lastQuery);
             getViewer().setSelection(selection, true);
         }
-        viewer.refresh();
+//        viewer.refresh();
 
 
 	}
@@ -375,7 +394,7 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
             getEditorInput().performSearch(query);
             lastQuery = query;
             List model = getEditorInput().getModel();
-            viewer.setInput(model);
+//            viewer.setInput(model);
             list.clear();
             list.addAll(model);
 
@@ -389,9 +408,9 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
 
     public void refresh(boolean resetInput) {
         if(resetInput){
-            viewer.setInput(getEditorInput().getModel());
+//            viewer.setInput(getEditorInput().getModel());
         }
-        viewer.refresh();
+//        viewer.refresh();
     }
 
     public TableViewer getViewer() {
