1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.editor.view.checklist;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.Arrays;
|
15
|
import java.util.List;
|
16
|
import java.util.SortedSet;
|
17
|
import java.util.TreeSet;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import org.eclipse.jface.preference.IPreferenceStore;
|
21
|
import org.eclipse.jface.viewers.ITableLabelProvider;
|
22
|
import org.eclipse.jface.viewers.LabelProvider;
|
23
|
import org.eclipse.swt.graphics.Image;
|
24
|
|
25
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
26
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
27
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
28
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
29
|
import eu.etaxonomy.cdm.model.common.Language;
|
30
|
import eu.etaxonomy.cdm.model.common.TermLanguageComparator;
|
31
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
32
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
33
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
34
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
35
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
36
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
37
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
38
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
39
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
40
|
|
41
|
/**
|
42
|
*
|
43
|
* @author a.oppermann
|
44
|
* @created 30.04.2014
|
45
|
* @version 1.0
|
46
|
*/
|
47
|
public class ChecklistLabelProvider extends LabelProvider implements ITableLabelProvider {
|
48
|
|
49
|
public static final String DEFAULT_ENTRY = "";
|
50
|
private IDescriptionService descriptionService;
|
51
|
private final List<DefinedTermBase<?>> namedAreas;
|
52
|
|
53
|
|
54
|
|
55
|
/**
|
56
|
*
|
57
|
*/
|
58
|
public ChecklistLabelProvider() {
|
59
|
namedAreas = loadNamedAreas();
|
60
|
}
|
61
|
|
62
|
/*
|
63
|
* (non-Javadoc)
|
64
|
*
|
65
|
* @see
|
66
|
* org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang
|
67
|
* .Object, int)
|
68
|
*/
|
69
|
/** {@inheritDoc} */
|
70
|
@Override
|
71
|
public Image getColumnImage(Object element, int columnIndex) {
|
72
|
// TODO
|
73
|
return null;
|
74
|
}
|
75
|
|
76
|
/*
|
77
|
* (non-Javadoc)
|
78
|
*
|
79
|
* @see
|
80
|
* org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang
|
81
|
* .Object, int)
|
82
|
*/
|
83
|
/** {@inheritDoc} */
|
84
|
@Override
|
85
|
public String getColumnText(Object element, int columnIndex) {
|
86
|
descriptionService = CdmStore.getService(IDescriptionService.class);
|
87
|
Taxon taxon = (Taxon) element;
|
88
|
//TODO load areas by this list
|
89
|
SortedSet<DefinedTermBase<?>> sortedNamedAreas = (SortedSet<DefinedTermBase<?>>) getTermsOrderedByLabels(namedAreas, CdmStore.getDefaultLanguage());
|
90
|
|
91
|
List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null, null, null, null, DESC_INIT_STRATEGY);;
|
92
|
NonViralName<?> nonVirlaName = HibernateProxyHelper.deproxy(taxon.getName(), NonViralName.class);
|
93
|
|
94
|
switch (columnIndex) {
|
95
|
case 0:
|
96
|
String taxonName = null;
|
97
|
taxonName = (nonVirlaName != null) ? nonVirlaName.getNameCache() : null;
|
98
|
return (taxonName != null) ? taxonName : DEFAULT_ENTRY;
|
99
|
|
100
|
case 1:
|
101
|
String authorship = null;
|
102
|
authorship = (nonVirlaName != null) ? nonVirlaName.getAuthorshipCache() : null;
|
103
|
return (authorship != null) ? authorship : DEFAULT_ENTRY;
|
104
|
case 2:
|
105
|
String ref = null;
|
106
|
if (taxon.getName() != null) {
|
107
|
INomenclaturalReference nomenclaturalReference = HibernateProxyHelper.deproxy(
|
108
|
nonVirlaName.getNomenclaturalReference(), Reference.class);
|
109
|
ref = (nomenclaturalReference != null) ? nomenclaturalReference.getAbbrevTitleCache() : null;
|
110
|
}
|
111
|
return (ref != null) ? ref : DEFAULT_ENTRY;
|
112
|
case 3:
|
113
|
String rank = null;
|
114
|
if (taxon.getName().getRank() != null) {
|
115
|
rank = taxon.getName().getRank().toString();
|
116
|
}
|
117
|
return (rank != null) ? rank : DEFAULT_ENTRY;
|
118
|
}
|
119
|
|
120
|
if(columnIndex >3){
|
121
|
|
122
|
for (TaxonDescription td : listTaxonDescriptions) {
|
123
|
for (DescriptionElementBase deb : td.getElements()) {
|
124
|
if (deb instanceof Distribution) {
|
125
|
Distribution distribution = (Distribution) deb;
|
126
|
String area = distribution.toString();
|
127
|
if(sortedNamedAreas != null){
|
128
|
Object[] array = sortedNamedAreas.toArray();
|
129
|
DefinedTermBase<DefinedTermBase> term = (DefinedTermBase<DefinedTermBase>) array[columnIndex-4];
|
130
|
if(term != null){
|
131
|
if (area.equalsIgnoreCase(term.getTitleCache())) {
|
132
|
return (distribution.getStatus().getTitleCache() != null)?distribution.getStatus().getTitleCache():DEFAULT_ENTRY;
|
133
|
}
|
134
|
}
|
135
|
}
|
136
|
}
|
137
|
}
|
138
|
}
|
139
|
}
|
140
|
return DEFAULT_ENTRY;
|
141
|
|
142
|
}
|
143
|
|
144
|
private static final List<String> DESC_INIT_STRATEGY = Arrays.asList(new String[] { "descriptions",
|
145
|
"descriptions.*", "description.state" });
|
146
|
|
147
|
|
148
|
private List<DefinedTermBase<?>> loadNamedAreas() {
|
149
|
IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
|
150
|
String values = preferenceStore.getString(PreferencesUtil.DISTRIBUTION_AREA_OCCURENCE_STATUS);
|
151
|
if (values != null && values != "") {
|
152
|
String[] split = values.split(",");
|
153
|
List<String> listValue = Arrays.asList(split);
|
154
|
ArrayList<DefinedTermBase<?>> termlist = new ArrayList<DefinedTermBase<?>>();
|
155
|
for(String s : listValue){
|
156
|
UUID uuid = UUID.fromString(s);
|
157
|
ITermService service = CdmStore.getService(ITermService.class);
|
158
|
DefinedTermBase definedTermBase = service.load(uuid);
|
159
|
termlist.add(definedTermBase);
|
160
|
}
|
161
|
return termlist;
|
162
|
}
|
163
|
return null;
|
164
|
}
|
165
|
|
166
|
public SortedSet<?> getTermsOrderedByLabels(List<DefinedTermBase<?>> listTerm,Language language){
|
167
|
TermLanguageComparator comp = new TermLanguageComparator();
|
168
|
comp.setCompareLanguage(language);
|
169
|
SortedSet result = new TreeSet(comp);
|
170
|
if(listTerm != null){
|
171
|
result.addAll(listTerm);
|
172
|
}
|
173
|
return result;
|
174
|
}
|
175
|
|
176
|
/**
|
177
|
* @return the namedAreas
|
178
|
*/
|
179
|
public List<DefinedTermBase<?>> getNamedAreas() {
|
180
|
return namedAreas;
|
181
|
}
|
182
|
}
|