From 3428ae9c584b4316783f8e219327093fcab6c110 Mon Sep 17 00:00:00 2001 From: Patrick Plitzner Date: Mon, 9 Jul 2018 13:57:06 +0200 Subject: [PATCH 1/1] Refactor character matrix - extract label accumulator --- .../matrix/CharacterMatrix.java | 33 +++++++------ ...CharacterMatrixConfigLabelAccumulator.java | 47 +++++++++++++++++++ 2 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixConfigLabelAccumulator.java diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java index 8d23f0d17..f4ddd1569 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java @@ -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 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 index 000000000..d86db071e --- /dev/null +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixConfigLabelAccumulator.java @@ -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))); + } + } +} -- 2.34.1