ref #7439 Show titleCache and type in NatTable in bulk editors
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 29 May 2018 12:35:28 +0000 (14:35 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 29 May 2018 12:35:28 +0000 (14:35 +0200)
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java

index 7fc8f38a3376f290680efe7df4ed771b734b2689..77faffec03c75886d5feb758df93950c2fa7fcc5 100644 (file)
@@ -33,9 +33,9 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
 import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
 import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
-import org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor;
 import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
 import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
 import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
@@ -44,13 +44,8 @@ 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.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.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.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
@@ -90,7 +85,9 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
         IDirtyMarkable, IDerivedUnitFacadePart, IPartContentHasFactualData,
         IPartContentHasSupplementalData, IPartContentHasMedia, IE4SavablePart, ITaxonEditor {
 
-       @Inject
+    private static final String TYPE = "Type";
+
+    @Inject
        private MDirtyable dirty;
 
     private AbstractBulkEditorInput<?> input;
@@ -116,7 +113,9 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
 
     private BulkEditorQuery lastQuery = null;
 
-    private BasicEventList<Object> list;
+    private BasicEventList<CdmBase> list;
+
+    private Composite bottomComposite;
 
     @Inject
     public BulkEditorE4() {
@@ -215,65 +214,66 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
         if(input.getEntityUuid()!=null){
             performSearch(new BulkEditorQuery(input.getEntityUuid().toString(), null));
         }
-       }
-
-       /** {@inheritDoc} */
-       @PostConstruct
-       public void createPartControl(Composite parent, EMenuService menuService) {
-               parent.setLayout(new GridLayout());
-
-               topComposite = new Composite(parent, SWT.NONE);
-               topComposite.setLayout(new GridLayout());
-
-               GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
-               topComposite.setLayoutData(gridData);
-
-               Composite bottomComposite = new Composite(parent, SWT.NONE);
-               bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-               bottomComposite.setLayout(new GridLayout());
-
-
-               //++++NatTable++++
-               natTable = createExampleControl(bottomComposite);
-        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$
+        //++++NatTable++++
+        list = new BasicEventList<>();
+        Map<String, String> propertyToLabels = new HashMap<>();
+        propertyToLabels.put(getEditorInput().getName(), getEditorInput().getName());
+        propertyToLabels.put(TYPE, TYPE);
+        String[] propertyNames = new String[] { getEditorInput().getName(), TYPE };
+        IDataProvider bodyDataProvider = new ListDataProvider<CdmBase>(list,
+                new IColumnPropertyAccessor<CdmBase>() {
+
+                    @Override
+                    public Object getDataValue(CdmBase rowObject, int columnIndex) {
+                        if(columnIndex==0){
+                            return getEditorInput().getText(rowObject);
+                        }else if(columnIndex==1){
+                            return getEditorInput().getTypeText(rowObject);
+                        }
+                        return null;
+                    }
+
+                    @Override
+                    public void setDataValue(CdmBase rowObject, int columnIndex, Object newValue) {
+                        //no editing allowed
+                    }
+
+                    @Override
+                    public int getColumnCount() {
+                        return 2;
+                    }
+
+                    @Override
+                    public String getColumnProperty(int columnIndex) {
+                        if(columnIndex==0){
+                            return getEditorInput().getName();
+                        }else if(columnIndex==1){
+                            return TYPE;
+                        }
+                        return null;
+                    }
+
+                    @Override
+                    public int getColumnIndex(String propertyName) {
+                        if(propertyName.equals(getEditorInput().getName())){
+                            return 0;
+                        }
+                        else if(propertyName.equals(TYPE)){
+                            return 1;
+                        }
+                        return 0;
+                    }
+                });
 
-       }
-    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);
+                propertyNames, propertyToLabels);
         DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
-                this.bodyDataProvider);
+                bodyDataProvider);
 
         DataLayer dataLayer = new DataLayer(bodyDataProvider);
-        GlazedListsEventLayer eventLayer = new GlazedListsEventLayer<>(dataLayer, list);
+        GlazedListsEventLayer<CdmBase> eventLayer = new GlazedListsEventLayer<>(dataLayer, list);
         DefaultBodyLayerStack bodyLayer = new DefaultBodyLayerStack(eventLayer);
 
         ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(
@@ -290,41 +290,39 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
 
         GridLayer gridLayer = new GridLayer(bodyLayer, columnHeaderLayer,
                 rowHeaderLayer, cornerLayer);
-        NatTable natTable = new NatTable(parent, gridLayer);
 
-        return natTable;
-    }
+        dataLayer.setColumnPercentageSizing(true);
+        NatTable natTable = new NatTable(bottomComposite, gridLayer);
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
+       }
 
-    private IDataProvider setupBodyDataProvider() {
-        list = new BasicEventList<>();
+       /** {@inheritDoc} */
+       @PostConstruct
+       public void createPartControl(Composite parent, EMenuService menuService) {
+               parent.setLayout(new GridLayout());
+
+               topComposite = new Composite(parent, SWT.NONE);
+               topComposite.setLayout(new GridLayout());
 
-        this.propertyToLabels = new HashMap<>();
-        this.propertyToLabels.put("titleCache", "Title Cache");
-        this.propertyNames = new String[] { "titleCache" };
-        return new ListDataProvider(list,
-                new ReflectiveColumnPropertyAccessor(this.propertyNames));
+               GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
+               topComposite.setLayoutData(gridData);
 
-    }
+               bottomComposite = new Composite(parent, SWT.NONE);
+               bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+               bottomComposite.setLayout(new GridLayout());
 
-    public class BodyLayerStack extends AbstractLayerTransform {
+//             viewer = new TableViewer(bottomComposite, SWT.MULTI | SWT.FULL_SELECTION);
 
-        private SelectionLayer selectionLayer;
+//             createColumns(viewer);
 
-        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);
-        }
+        //propagate selection
+        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
+//        viewer.addSelectionChangedListener(selectionChangedListener);
 
-        public SelectionLayer getSelectionLayer() {
-            return this.selectionLayer;
-        }
-    }
+        //create context menu
+//        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.bulkeditor"); //$NON-NLS-1$
+
+       }
 
        @Override
        @Persist