Project

General

Profile

« Previous | Next » 

Revision 3428ae9c

Added by Patrick Plitzner almost 6 years ago

Refactor character matrix

  • extract label accumulator

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
124 124

  
125 125
    private static final String CHARACTER_MATRIX_STATE_PROPERTIES = "characterMatrixState.properties"; //$NON-NLS-1$
126 126

  
127
    private static final int LEADING_COLUMN_COUNT = 4;
128
    private static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
129
    private static final String COLLECTOR_COLUMN = "collector_column"; //$NON-NLS-1$
130
    private static final String IDENTIFIER_COLUMN = "identifier_column"; //$NON-NLS-1$
131
    private static final String COUNTRY_COLUMN = "country_column"; //$NON-NLS-1$
127
    static final int LEADING_COLUMN_COUNT = 4;
128
    static final String TAXON_COLUMN = "taxon_column"; //$NON-NLS-1$
129
    static final String COLLECTOR_COLUMN = "collector_column"; //$NON-NLS-1$
130
    static final String IDENTIFIER_COLUMN = "identifier_column"; //$NON-NLS-1$
131
    static final String COUNTRY_COLUMN = "country_column"; //$NON-NLS-1$
132 132

  
133 133
    private DescriptiveDataSet descriptiveDataSet;
134 134

  
......
363 363
         */
364 364
        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
365 365

  
366
        //register labels for columns
367
        ColumnOverrideLabelAccumulator bodyColumnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
368
        bodyDataLayer.setConfigLabelAccumulator(bodyColumnLabelAccumulator);
366
        //register labels
367
        CharacterMatrixConfigLabelAccumulator labelAccumulator = new CharacterMatrixConfigLabelAccumulator(this);
368
        bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
369

  
370

  
369 371
        propertyToLabelMap.put(TAXON_COLUMN, Messages.CharacterMatrix_TAXON);
370
        bodyColumnLabelAccumulator.registerColumnOverrides(0, TAXON_COLUMN);
371 372
        propertyToLabelMap.put(COLLECTOR_COLUMN, Messages.CharacterMatrix_COLLECTOR_NO);
372
        bodyColumnLabelAccumulator.registerColumnOverrides(1, COLLECTOR_COLUMN);
373 373
        propertyToLabelMap.put(IDENTIFIER_COLUMN, Messages.CharacterMatrix_IDENTIFIER);
374
        bodyColumnLabelAccumulator.registerColumnOverrides(2, IDENTIFIER_COLUMN);
375 374
        propertyToLabelMap.put(COUNTRY_COLUMN, Messages.CharacterMatrix_COUNTRY);
376
        bodyColumnLabelAccumulator.registerColumnOverrides(3, COUNTRY_COLUMN);
377 375
        for(int i=0;i<features.size();i++){
378 376
            Feature feature = features.get(i);
379
            initLabels(bodyColumnLabelAccumulator, i, feature);
377
            initLabels(i, feature);
380 378
        }
381 379

  
382 380
        // layer for event handling of GlazedLists and PropertyChanges
......
604 602
        }
605 603
    }
606 604

  
607
    private void initLabels(final ColumnOverrideLabelAccumulator columnLabelAccumulator,
608
            int index, Feature feature) {
609

  
610
        columnLabelAccumulator.registerColumnOverrides(index+LEADING_COLUMN_COUNT, MatrixUtility.getProperty(feature));
605
    private void initLabels(int index, Feature feature) {
611 606
        indexToFeatureMap.put(index+LEADING_COLUMN_COUNT, feature);
612 607

  
613 608
        String featureLabel = feature.getLabel();
......
753 748
        return new File(WorkbenchUtility.getBaseLocation(), CHARACTER_MATRIX_STATE_PROPERTIES);
754 749
    }
755 750

  
751
    public List<Feature> getFeatures() {
752
        return features;
753
    }
754

  
756 755
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixConfigLabelAccumulator.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
10

  
11
import org.eclipse.nebula.widgets.nattable.layer.LabelStack;
12
import org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator;
13

  
14
/**
15
 * @author pplitzner
16
 * @since Jul 6, 2018
17
 *
18
 */
19
public class CharacterMatrixConfigLabelAccumulator implements IConfigLabelAccumulator {
20

  
21
    private CharacterMatrix matrix;
22

  
23
    public CharacterMatrixConfigLabelAccumulator(CharacterMatrix matrix) {
24
        super();
25
        this.matrix = matrix;
26
    }
27

  
28

  
29
    @Override
30
    public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
31
        if(columnPosition==0){
32
            configLabels.addLabel(CharacterMatrix.TAXON_COLUMN);
33
        }
34
        else if(columnPosition==1){
35
            configLabels.addLabel(CharacterMatrix.COLLECTOR_COLUMN);
36
        }
37
        else if(columnPosition==2){
38
            configLabels.addLabel(CharacterMatrix.IDENTIFIER_COLUMN);
39
        }
40
        else if(columnPosition==3){
41
            configLabels.addLabel(CharacterMatrix.COUNTRY_COLUMN);
42
        }
43
        else{
44
            configLabels.addLabel(MatrixUtility.getProperty(matrix.getFeatures().get(columnPosition-CharacterMatrix.LEADING_COLUMN_COUNT)));
45
        }
46
    }
47
}

Also available in: Unified diff