ref #7095 Add column sorting to character matrix
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 4 Dec 2017 05:34:21 +0000 (06:34 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 4 Dec 2017 05:34:21 +0000 (06:34 +0100)
eu.etaxonomy.taxeditor.editor/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java
eu.etaxonomy.taxeditor.feature.platform/feature.xml

index f94dc91a9a4a758dea18ceff93ec0a100c07ff26..9d2cfc9e8d9342b1b182eca216bc2932c4758b5e 100644 (file)
@@ -39,7 +39,9 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.e4.core.commands,
  org.eclipse.e4.core.services,
  org.eclipse.e4.core.contexts,
- org.eclipse.nebula.widgets.nattable.core
+ org.eclipse.nebula.widgets.nattable.core,
+ org.eclipse.nebula.widgets.nattable.extension.glazedlists,
+ ca.odell.glazedlists
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ActivationPolicy: lazy
 Import-Package: javax.annotation;version="1.0.0";resolution:=optional,
index baac7ac964235125f562235f84763f93d1cbe7c7..a3b4fd6d17d79a365476cbd51f0586a1a4323dd4 100644 (file)
@@ -27,12 +27,15 @@ import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.nebula.widgets.nattable.NatTable;
 import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
 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;
 import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
 import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
 import org.eclipse.nebula.widgets.nattable.export.command.ExportCommand;
 import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
+import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
+import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel;
 import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
 import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
 import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
@@ -46,8 +49,12 @@ import org.eclipse.nebula.widgets.nattable.layer.ILayerListener;
 import org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator;
 import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
 import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
+import org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer;
+import org.eclipse.nebula.widgets.nattable.reorder.RowReorderLayer;
 import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
 import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
+import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
+import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
 import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
 import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
 import org.eclipse.swt.SWT;
@@ -57,6 +64,9 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 
+import ca.odell.glazedlists.EventList;
+import ca.odell.glazedlists.GlazedLists;
+import ca.odell.glazedlists.SortedList;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.api.service.IWorkingSetService;
@@ -110,12 +120,19 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
         this.workingSet = workingSet;
         thisPart.setLabel(workingSet.getLabel());
 
+        EventList<SpecimenDescription> descriptions = GlazedLists.eventList(getDescriptions(workingSet));
+        SortedList<SpecimenDescription> sortedList = new SortedList<>(descriptions, null);
+
         // create the data provider
         SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(workingSet);
-        IDataProvider bodyDataProvider = new ListDataProvider<SpecimenDescription>(getDescriptions(workingSet), columnPropertyAccessor);
+        IDataProvider bodyDataProvider = new ListDataProvider<SpecimenDescription>(sortedList, columnPropertyAccessor);
 
         DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
-        SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
+        GlazedListsEventLayer<SpecimenDescription> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, sortedList);
+
+        RowReorderLayer rowReorderLayer = new RowReorderLayer(eventLayer);
+        ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(rowReorderLayer);
+        SelectionLayer selectionLayer = new SelectionLayer(columnReorderLayer);
         ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
 
         // build the column header layer stack
@@ -124,6 +141,20 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
         DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
         ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
 
+        ConfigRegistry configRegistry = new ConfigRegistry();
+
+        // add the SortHeaderLayer to the column header layer stack
+        // as we use GlazedLists, we use the GlazedListsSortModel which
+        // delegates the sorting to the SortedList
+        final SortHeaderLayer sortHeaderLayer =
+                new SortHeaderLayer<>(
+                        columnHeaderLayer,
+                        new GlazedListsSortModel<>(
+                                sortedList,
+                                columnPropertyAccessor,
+                                configRegistry,
+                                columnHeaderDataLayer));
+
         // build the row header layer stack
         IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
         DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider, 40, 20);
@@ -132,10 +163,10 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
         // build the corner layer stack
         ILayer cornerLayer = new CornerLayer(
                 new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
-                rowHeaderLayer, columnHeaderLayer);
+                rowHeaderLayer, sortHeaderLayer);
 
         // create the grid layer composed with the prior created layer stacks
-        GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
+        GridLayer gridLayer = new GridLayer(viewportLayer, sortHeaderLayer, rowHeaderLayer, cornerLayer);
 
 
         //Create a ColumnLabelAccumulator to allow adding different configuration for columns
@@ -145,9 +176,18 @@ public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails,
 
         natTable = new NatTable(parent, gridLayer, false);
 
+        natTable.setConfigRegistry(configRegistry);
+
+
         //add default configuration because autoconfigure is set to false in constructor
         natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
 
+        // override the default sort configuration and change the mouse bindings
+        // to sort on a single click
+        natTable.addConfiguration(new SingleClickSortConfiguration());
+
+//        natTable.addConfiguration( new DefaultSortConfiguration());
+
         // add custom configuration for data conversion
         viewportLayer.addConfiguration(new AbstractRegistryConfiguration() {
 
index 71a31454a47b2bda090c8481339e9b45ed1a8360..3025914465da803091d1b933d3ec62ce8ca0da91 100644 (file)
          version="0.0.0"
          unpack="false"/>
 
+   <plugin
+         id="ca.odell.glazedlists"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
+         id="org.eclipse.nebula.widgets.nattable.extension.glazedlists"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
 </feature>