Project

General

Profile

« Previous | Next » 

Revision d8bd1bdc

Added by Patrick Plitzner over 6 years ago

ref #7095 Add display converter for supplemental info

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java
91 91
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.categorical.CategoricalDataDisplayConverter;
92 92
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.quantitative.QuantitativeDataCellEditor;
93 93
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.quantitative.QuantitativeDataDisplayConverter;
94
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.supplementalInfo.SupplementalInfoDisplayConverter;
94 95
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
95 96
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
96 97
import eu.etaxonomy.taxeditor.model.MessagingUtils;
......
167 168
         * BODY layer
168 169
         */
169 170
        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
171

  
172
        //register labels for columns
170 173
        final ColumnOverrideLabelAccumulator columnLabelAccumulator =new ColumnOverrideLabelAccumulator(bodyDataLayer);
171 174
        bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
172 175
        propertyToLabelMap.put(TAXON_COLUMN, "Taxon");
176
        columnLabelAccumulator.registerColumnOverrides(0, TAXON_COLUMN);
173 177
        propertyToLabelMap.put(COLLECTOR_COLUMN, "Collector + No");
178
        columnLabelAccumulator.registerColumnOverrides(1, COLLECTOR_COLUMN);
174 179
        propertyToLabelMap.put(IDENTIFIER_COLUMN, "Identifier");
180
        columnLabelAccumulator.registerColumnOverrides(2, IDENTIFIER_COLUMN);
175 181
        propertyToLabelMap.put(COUNTRY_COLUMN, "Country");
182
        columnLabelAccumulator.registerColumnOverrides(3, COUNTRY_COLUMN);
176 183
        for(int i=0;i<features.size();i++){
177 184
            Feature feature = features.get(i);
178 185
            initLabels(columnLabelAccumulator, i, feature);
179 186
        }
187

  
180 188
        GlazedListsEventLayer<RowWrapper> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, sortedList);
181 189

  
182 190
        RowReorderLayer rowReorderLayer = new RowReorderLayer(eventLayer);
......
241 249
        natTable.addConfiguration(new SingleClickSortConfiguration());
242 250

  
243 251

  
244
        // add custom configuration for data conversion and add column labels for each feature
252
        // add custom configuration for data conversion and add column labels
245 253
        viewportLayer.addConfiguration(new AbstractRegistryConfiguration() {
246 254
            @Override
247 255
            public void configureRegistry(IConfigRegistry configRegistry) {
256
                //add display converter for string representation
257
                configRegistry.registerConfigAttribute(
258
                        CellConfigAttributes.DISPLAY_CONVERTER,
259
                        new SupplementalInfoDisplayConverter(),
260
                        DisplayMode.NORMAL,
261
                        TAXON_COLUMN);
262
                configRegistry.registerConfigAttribute(
263
                        CellConfigAttributes.DISPLAY_CONVERTER,
264
                        new SupplementalInfoDisplayConverter(),
265
                        DisplayMode.NORMAL,
266
                        COLLECTOR_COLUMN);
267
                configRegistry.registerConfigAttribute(
268
                        CellConfigAttributes.DISPLAY_CONVERTER,
269
                        new SupplementalInfoDisplayConverter(),
270
                        DisplayMode.NORMAL,
271
                        IDENTIFIER_COLUMN);
272
                configRegistry.registerConfigAttribute(
273
                        CellConfigAttributes.DISPLAY_CONVERTER,
274
                        new SupplementalInfoDisplayConverter(),
275
                        DisplayMode.NORMAL,
276
                        COUNTRY_COLUMN);
248 277
                features.forEach(feature->registerColumnConfiguration(feature, configRegistry));
249 278
            }
250 279

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/supplementalInfo/SupplementalInfoDisplayConverter.java
1
/**
2
* Copyright (C) 2017 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.workingSet.matrix.supplementalInfo;
10

  
11
import java.util.Collection;
12

  
13
import org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter;
14

  
15
import eu.etaxonomy.cdm.model.agent.AgentBase;
16
import eu.etaxonomy.cdm.model.location.NamedArea;
17
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
18
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
19
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
20

  
21
/**
22
 * @author pplitzner
23
 * @since Dec 14, 2017
24
 *
25
 */
26
public class SupplementalInfoDisplayConverter extends DisplayConverter{
27

  
28
    /**
29
     * {@inheritDoc}
30
     */
31
    @Override
32
    public Object canonicalToDisplayValue(Object canonicalValue) {
33
        String displayValue = "";
34
        if(canonicalValue instanceof FieldUnit){
35
            FieldUnit fieldUnit = (FieldUnit)canonicalValue;
36
            GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
37
            if(gatheringEvent!=null){
38
                AgentBase collector = gatheringEvent.getCollector();
39
                if(collector!=null){
40
                    displayValue += collector.getTitleCache()+" ";
41
                }
42
                String fieldNumber = fieldUnit.getFieldNumber();
43
                if(fieldNumber!=null){
44
                    displayValue += fieldNumber;
45
                }
46
            }
47
        }
48
        else if(canonicalValue instanceof NamedArea){
49
            displayValue = ((NamedArea) canonicalValue).getLabel();
50
        }
51
        else if(canonicalValue instanceof Collection){
52
            String separator = ", ";
53
            for(Object object:((Collection<?>) canonicalValue)){
54
                if(object instanceof TaxonBase && ((TaxonBase) object).getName()!=null){
55
                    displayValue += ((TaxonBase) object).getName()+separator;
56
                }
57
            }
58
            displayValue = displayValue.substring(0, displayValue.length()-separator.length());
59
        }
60

  
61
        if(displayValue.isEmpty() && canonicalValue!=null){
62
            return canonicalValue.toString();
63
        }
64
        return displayValue;
65
    }
66

  
67
    /**
68
     * {@inheritDoc}
69
     */
70
    @Override
71
    public Object displayToCanonicalValue(Object displayValue) {
72
        return null;
73
    }
74

  
75
}

Also available in: Unified diff