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.view.checklist.e4;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Collections;
|
13
|
import java.util.Comparator;
|
14
|
import java.util.List;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.apache.commons.lang.StringUtils;
|
18
|
import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
21
|
import eu.etaxonomy.cdm.model.common.OrderedTermComparator;
|
22
|
import eu.etaxonomy.cdm.model.common.Representation;
|
23
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
24
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
25
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
|
28
|
/**
|
29
|
* @author k.luther
|
30
|
* @since 05.12.2018
|
31
|
*
|
32
|
*/
|
33
|
public class StatusComboBoxDataProvider implements IComboBoxDataProvider {
|
34
|
|
35
|
private DistributionEditor editor;
|
36
|
private int maxVisibleItems;
|
37
|
|
38
|
public StatusComboBoxDataProvider(DistributionEditor editor) {
|
39
|
super();
|
40
|
this.editor = editor;
|
41
|
|
42
|
}
|
43
|
|
44
|
@Override
|
45
|
public List<?> getValues(int columnIndex, int rowIndex) {
|
46
|
return getValues();
|
47
|
}
|
48
|
|
49
|
public static List<?> getValues(){
|
50
|
List<DefinedTermBase> inputAll = new ArrayList<>();
|
51
|
PresenceAbsenceTerm noneTerm = PresenceAbsenceTerm.NewInstance();
|
52
|
noneTerm.setTitleCache(" - ", true);
|
53
|
noneTerm.addRepresentation(Representation.NewInstance(" - ", " ", " ", CdmStore.getDefaultLanguage()));
|
54
|
inputAll.add(noneTerm);
|
55
|
String statusString = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionStatus.getKey());
|
56
|
List<PresenceAbsenceTerm> inputList;
|
57
|
if (!StringUtils.isBlank(statusString)){
|
58
|
|
59
|
String [] statusArray = statusString.split(";");
|
60
|
List<UUID> uuidList = new ArrayList();
|
61
|
for (String status: statusArray){
|
62
|
uuidList.add(UUID.fromString(status));
|
63
|
}
|
64
|
|
65
|
inputList = CdmStore.getTermManager().getTerms(uuidList, PresenceAbsenceTerm.class);
|
66
|
}else{
|
67
|
|
68
|
inputList = CdmStore.getTermManager().getPreferredTerms(PresenceAbsenceTerm.class);
|
69
|
}
|
70
|
Comparator<DefinedTermBase> comp = new OrderedTermComparator<>();
|
71
|
Collections.sort(inputList, comp);
|
72
|
Collections.sort(inputList, Collections.reverseOrder());
|
73
|
|
74
|
inputAll.addAll(1, inputList);
|
75
|
return inputAll;
|
76
|
}
|
77
|
|
78
|
public int getMaxVisibleItems(){
|
79
|
return maxVisibleItems;
|
80
|
}
|
81
|
|
82
|
}
|