1 |
926f488d
|
Patrick Plitzner
|
/**
|
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 |
652496d7
|
Andreas Müller
|
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
|
10 |
926f488d
|
Patrick Plitzner
|
|
11 |
7cc57f1d
|
Patrick Plitzner
|
import java.util.ArrayList;
|
12 |
|
|
import java.util.Collection;
|
13 |
|
|
import java.util.List;
|
14 |
|
|
import java.util.UUID;
|
15 |
|
|
import java.util.stream.Collectors;
|
16 |
|
|
|
17 |
926f488d
|
Patrick Plitzner
|
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
|
18 |
|
|
|
19 |
7cc57f1d
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
20 |
f5f64287
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
|
21 |
e15dfd39
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
|
22 |
61473b5a
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
|
23 |
926f488d
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.description.Feature;
|
24 |
7cc57f1d
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.description.State;
|
25 |
|
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
26 |
|
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
27 |
|
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28 |
926f488d
|
Patrick Plitzner
|
|
29 |
|
|
/**
|
30 |
787a37f1
|
Patrick Plitzner
|
* Property accessor class which maps setting and getting data for
|
31 |
06ab7f53
|
Patrick Plitzner
|
* each row in the character matrix
|
32 |
926f488d
|
Patrick Plitzner
|
* @author pplitzner
|
33 |
|
|
* @since Nov 26, 2017
|
34 |
|
|
*
|
35 |
|
|
*/
|
36 |
fcd9dc61
|
Patrick Plitzner
|
public class SpecimenColumnPropertyAccessor implements IColumnPropertyAccessor<Object>{
|
37 |
926f488d
|
Patrick Plitzner
|
|
38 |
4fbf8f87
|
Patrick Plitzner
|
private CharacterMatrix matrix;
|
39 |
926f488d
|
Patrick Plitzner
|
|
40 |
4fbf8f87
|
Patrick Plitzner
|
public SpecimenColumnPropertyAccessor(CharacterMatrix matrix) {
|
41 |
|
|
this.matrix = matrix;
|
42 |
926f488d
|
Patrick Plitzner
|
}
|
43 |
|
|
|
44 |
|
|
@Override
|
45 |
fcd9dc61
|
Patrick Plitzner
|
public Object getDataValue(Object rowObject, int columnIndex) {
|
46 |
e15dfd39
|
Patrick Plitzner
|
if(rowObject instanceof SpecimenRowWrapperDTO){
|
47 |
|
|
SpecimenRowWrapperDTO rowWrapper = (SpecimenRowWrapperDTO) rowObject;
|
48 |
43d417f5
|
Patrick Plitzner
|
switch (columnIndex) {
|
49 |
|
|
case 0:
|
50 |
16621f1f
|
Patrick Plitzner
|
if(matrix.isTreeView()){
|
51 |
|
|
return "#"+rowWrapper.getSpecimen().getId();
|
52 |
|
|
}
|
53 |
|
|
else{
|
54 |
|
|
return rowWrapper.getTaxonNode();
|
55 |
|
|
}
|
56 |
43d417f5
|
Patrick Plitzner
|
case 1:
|
57 |
|
|
return rowWrapper.getFieldUnit();
|
58 |
|
|
case 2:
|
59 |
|
|
return rowWrapper.getIdentifier();
|
60 |
|
|
case 3:
|
61 |
|
|
return rowWrapper.getCountry();
|
62 |
4fbf8f87
|
Patrick Plitzner
|
|
63 |
43d417f5
|
Patrick Plitzner
|
default:
|
64 |
|
|
break;
|
65 |
|
|
}
|
66 |
df79024a
|
Patrick Plitzner
|
Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
|
67 |
c2f509ab
|
pplitzner
|
return rowWrapper.getDisplayDataForFeature(feature);
|
68 |
|
|
}
|
69 |
|
|
else if(rowObject instanceof TaxonRowWrapperDTO){
|
70 |
61473b5a
|
Patrick Plitzner
|
TaxonRowWrapperDTO taxonWrapper = (TaxonRowWrapperDTO)rowObject;
|
71 |
|
|
if(columnIndex==0){
|
72 |
18c8b6f9
|
Patrick Plitzner
|
return taxonWrapper.getDescription();
|
73 |
61473b5a
|
Patrick Plitzner
|
}
|
74 |
df79024a
|
Patrick Plitzner
|
Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
|
75 |
c2f509ab
|
pplitzner
|
return taxonWrapper.getDisplayDataForFeature(feature);
|
76 |
61473b5a
|
Patrick Plitzner
|
|
77 |
|
|
}
|
78 |
|
|
else if (columnIndex == 0) {
|
79 |
43d417f5
|
Patrick Plitzner
|
return rowObject;
|
80 |
cb531fce
|
Patrick Plitzner
|
}
|
81 |
|
|
return null;
|
82 |
926f488d
|
Patrick Plitzner
|
}
|
83 |
|
|
|
84 |
|
|
@Override
|
85 |
fcd9dc61
|
Patrick Plitzner
|
public void setDataValue(Object rowObject, int columnIndex, Object newValue) {
|
86 |
|
|
if(rowObject instanceof RowWrapperDTO){
|
87 |
|
|
RowWrapperDTO rowWrapper = (RowWrapperDTO)rowObject;
|
88 |
030ddaa9
|
Patrick Plitzner
|
matrix.addRowToSave(rowWrapper);
|
89 |
df79024a
|
Patrick Plitzner
|
Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
|
90 |
c335a01c
|
Patrick Plitzner
|
if(feature.isSupportsCategoricalData()
|
91 |
|
|
&& newValue instanceof Collection
|
92 |
|
|
&& ((Collection) newValue).stream().allMatch(o->o instanceof TermDto)){
|
93 |
7cc57f1d
|
Patrick Plitzner
|
List<TermDto> dtos = (List<TermDto>)newValue;
|
94 |
|
|
List<UUID> termUuids = dtos.stream().map(dto->dto.getUuid()).collect(Collectors.toList());
|
95 |
|
|
List<DefinedTermBase> terms = CdmStore.getService(ITermService.class).load(termUuids, null);
|
96 |
|
|
List<State> states = new ArrayList<>();
|
97 |
|
|
for (DefinedTermBase definedTermBase : terms) {
|
98 |
|
|
if(definedTermBase instanceof State){
|
99 |
|
|
states.add((State) definedTermBase);
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
c335a01c
|
Patrick Plitzner
|
rowWrapper.setDataValueForCategoricalData(feature, states);
|
103 |
7cc57f1d
|
Patrick Plitzner
|
}
|
104 |
fcd9dc61
|
Patrick Plitzner
|
}
|
105 |
926f488d
|
Patrick Plitzner
|
}
|
106 |
|
|
|
107 |
|
|
@Override
|
108 |
|
|
public int getColumnCount() {
|
109 |
4fbf8f87
|
Patrick Plitzner
|
return matrix.getPropertyToLabelMap().size();
|
110 |
926f488d
|
Patrick Plitzner
|
}
|
111 |
|
|
|
112 |
|
|
@Override
|
113 |
|
|
public String getColumnProperty(int columnIndex) {
|
114 |
4fbf8f87
|
Patrick Plitzner
|
return matrix.getPropertyToLabelMap().get(columnIndex);
|
115 |
926f488d
|
Patrick Plitzner
|
}
|
116 |
|
|
|
117 |
|
|
@Override
|
118 |
|
|
public int getColumnIndex(String propertyName){
|
119 |
4fbf8f87
|
Patrick Plitzner
|
return matrix.getPropertyToLabelMap().indexOf(propertyName);
|
120 |
926f488d
|
Patrick Plitzner
|
}
|
121 |
|
|
|
122 |
|
|
}
|