Refactor character matrix
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 9 Jul 2018 11:57:06 +0000 (13:57 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 9 Jul 2018 11:57:06 +0000 (13:57 +0200)
 - extract label accumulator

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixConfigLabelAccumulator.java [new file with mode: 0644]

index 8d23f0d1704222a51edde088f149ff504f992061..f4ddd156995fe41e963af7e4709ce57fa2c04004 100644 (file)
@@ -124,11 +124,11 @@ public class CharacterMatrix extends Composite {
 
     private static final String CHARACTER_MATRIX_STATE_PROPERTIES = "characterMatrixState.properties"; //$NON-NLS-1$
 
-    private static final int LEADING_COLUMN_COUNT = 4;
-    private static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
-    private static final String COLLECTOR_COLUMN = "collector_column"; //$NON-NLS-1$
-    private static final String IDENTIFIER_COLUMN = "identifier_column"; //$NON-NLS-1$
-    private static final String COUNTRY_COLUMN = "country_column"; //$NON-NLS-1$
+    static final int LEADING_COLUMN_COUNT = 4;
+    static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
+    static final String COLLECTOR_COLUMN = "collector_column"; //$NON-NLS-1$
+    static final String IDENTIFIER_COLUMN = "identifier_column"; //$NON-NLS-1$
+    static final String COUNTRY_COLUMN = "country_column"; //$NON-NLS-1$
 
     private DescriptiveDataSet descriptiveDataSet;
 
@@ -363,20 +363,18 @@ public class CharacterMatrix extends Composite {
          */
         DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
 
-        //register labels for columns
-        ColumnOverrideLabelAccumulator bodyColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
-        bodyDataLayer.setConfigLabelAccumulator(bodyColumnLabelAccumulator);
+        //register labels
+        CharacterMatrixConfigLabelAccumulator labelAccumulator = new CharacterMatrixConfigLabelAccumulator(this);
+        bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
+
+
         propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON);
-        bodyColumnLabelAccumulator.registerColumnOverrides(0, TAXON_COLUMN);
         propertyToLabelMap.put(COLLECTOR_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO);
-        bodyColumnLabelAccumulator.registerColumnOverrides(1, COLLECTOR_COLUMN);
         propertyToLabelMap.put(IDENTIFIER_COLUMN, Messages.CharacterMatrix_IDENTIFIER);
-        bodyColumnLabelAccumulator.registerColumnOverrides(2, IDENTIFIER_COLUMN);
         propertyToLabelMap.put(COUNTRY_COLUMN, Messages.CharacterMatrix_COUNTRY);
-        bodyColumnLabelAccumulator.registerColumnOverrides(3, COUNTRY_COLUMN);
         for(int i=0;i<features.size();i++){
             Feature feature = features.get(i);
-            initLabels(bodyColumnLabelAccumulator, i, feature);
+            initLabels(i, feature);
         }
 
         // layer for event handling of GlazedLists and PropertyChanges
@@ -604,10 +602,7 @@ public class CharacterMatrix extends Composite {
         }
     }
 
-    private void initLabels(final ColumnOverrideLabelAccumulator columnLabelAccumulator,
-            int index, Feature feature) {
-
-        columnLabelAccumulator.registerColumnOverrides(index+LEADING_COLUMN_COUNT, MatrixUtility.getProperty(feature));
+    private void initLabels(int index, Feature feature) {
         indexToFeatureMap.put(index+LEADING_COLUMN_COUNT, feature);
 
         String featureLabel = feature.getLabel();
@@ -753,4 +748,8 @@ public class CharacterMatrix extends Composite {
         return new File(WorkbenchUtility.getBaseLocation(), CHARACTER_MATRIX_STATE_PROPERTIES);
     }
 
+    public List<Feature> getFeatures() {
+        return features;
+    }
+
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixConfigLabelAccumulator.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixConfigLabelAccumulator.java
new file mode 100644 (file)
index 0000000..d86db07
--- /dev/null
@@ -0,0 +1,47 @@
+/**
+* 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.editor.descriptiveDataSet.matrix;
+
+import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
+import org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator;
+
+/**
+ * @author pplitzner
+ * @since Jul 6, 2018
+ *
+ */
+public class CharacterMatrixConfigLabelAccumulator implements IConfigLabelAccumulator {
+
+    private CharacterMatrix matrix;
+
+    public CharacterMatrixConfigLabelAccumulator(CharacterMatrix matrix) {
+        super();
+        this.matrix = matrix;
+    }
+
+
+    @Override
+    public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
+        if(columnPosition==0){
+            configLabels.addLabel(CharacterMatrix.TAXON_COLUMN);
+        }
+        else if(columnPosition==1){
+            configLabels.addLabel(CharacterMatrix.COLLECTOR_COLUMN);
+        }
+        else if(columnPosition==2){
+            configLabels.addLabel(CharacterMatrix.IDENTIFIER_COLUMN);
+        }
+        else if(columnPosition==3){
+            configLabels.addLabel(CharacterMatrix.COUNTRY_COLUMN);
+        }
+        else{
+            configLabels.addLabel(MatrixUtility.getProperty(matrix.getFeatures().get(columnPosition-CharacterMatrix.LEADING_COLUMN_COUNT)));
+        }
+    }
+}