ref #6805 Fix term dragging into feature tree editor
[taxeditor.git] / 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 import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
15 import eu.etaxonomy.cdm.model.description.Feature;
16 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
17
18 /**
19 * @author pplitzner
20 * @since Jul 6, 2018
21 *
22 */
23 public class CharacterMatrixConfigLabelAccumulator implements IConfigLabelAccumulator {
24
25 public static final String QUANTITATIVE = "QUANTITATIVE";
26 public static final String CATEGORICAL = "CATEGORICAL";
27 public static final String CATEGORICAL_EDITABLE = CATEGORICAL+"_EDITABLE";
28 public static final String QUANTITATIVE_EDITABLE = QUANTITATIVE+"_EDITABLE";
29
30 private CharacterMatrix matrix;
31
32 public CharacterMatrixConfigLabelAccumulator(CharacterMatrix matrix) {
33 super();
34 this.matrix = matrix;
35 }
36
37 @Override
38 public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
39 boolean isEditable = true;
40
41 Object rowObject = matrix.getBodyDataProvider().getRowObject(rowPosition);
42 if(rowObject instanceof TaxonNode){
43 configLabels.addLabel(CharacterMatrix.LABEL_TAXON_ROW);
44 }
45 else if(rowObject instanceof TaxonRowWrapperDTO){
46 TaxonRowWrapperDTO taxonRowWrapper = (TaxonRowWrapperDTO) rowObject;
47 if(MatrixUtility.isAggregatedTaxonDescription(taxonRowWrapper)){
48 configLabels.addLabel(CharacterMatrix.LABEL_TAXON_AGGREGATED_DESCRIPTION);
49 isEditable = false;
50 if(columnPosition==0){
51 configLabels.addLabel(CharacterMatrix.LABEL_TAXON_AGGREGATED_DESCRIPTION_ICON);
52 }
53 }
54 else if(MatrixUtility.isDefaultTaxonDescription(taxonRowWrapper)){
55 configLabels.addLabel(CharacterMatrix.LABEL_TAXON_DEFAULT_DESCRIPTION);
56 if(columnPosition==0){
57 configLabels.addLabel(CharacterMatrix.LABEL_TAXON_DEFAULT_DESCRIPTION_ICON);
58 }
59 }
60 else if(MatrixUtility.isLiteratureTaxonDescription(taxonRowWrapper)){
61 configLabels.addLabel(CharacterMatrix.LABEL_TAXON_LITERATURE_DESCRIPTION);
62 if(columnPosition==0){
63 configLabels.addLabel(CharacterMatrix.LABEL_TAXON_LITERATURE_DESCRIPTION_ICON);
64 }
65 }
66 //check for supplemental data
67 if(!taxonRowWrapper.getDescription().getSources().isEmpty() && columnPosition==0){
68 configLabels.addLabel(CharacterMatrix.LABEL_DESCRIPTION_HAS_SUPPLEMENTAL_DATA);
69 }
70 configLabels.addLabel(CharacterMatrix.LABEL_TAXON_DESCRIPTION);
71 }
72
73 if(columnPosition==0){
74 configLabels.addLabel(CharacterMatrix.TAXON_COLUMN);
75 }
76 else if(columnPosition==1){
77 configLabels.addLabel(CharacterMatrix.COLLECTOR_COLUMN);
78 }
79 else if(columnPosition==2){
80 configLabels.addLabel(CharacterMatrix.IDENTIFIER_COLUMN);
81 }
82 else if(columnPosition==3){
83 configLabels.addLabel(CharacterMatrix.COUNTRY_COLUMN);
84 }
85 else{
86 Feature feature = matrix.getFeatures().get(columnPosition-CharacterMatrix.LEADING_COLUMN_COUNT);
87 configLabels.addLabel(MatrixUtility.getProperty(feature));
88 if(feature.isSupportsCategoricalData()){
89 configLabels.addLabel(CATEGORICAL);
90 if(isEditable){
91 configLabels.addLabel(CATEGORICAL_EDITABLE);
92 }
93 }
94 else if(feature.isSupportsQuantitativeData()){
95 configLabels.addLabel(QUANTITATIVE);
96 if(isEditable){
97 configLabels.addLabel(QUANTITATIVE_EDITABLE);
98 }
99 }
100 }
101 }
102 }