2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Arrays
;
14 import java
.util
.HashMap
;
15 import java
.util
.HashSet
;
16 import java
.util
.List
;
18 import java
.util
.SortedSet
;
19 import java
.util
.TreeSet
;
20 import java
.util
.UUID
;
22 import org
.eclipse
.jface
.preference
.IPreferenceStore
;
23 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
24 import org
.eclipse
.jface
.viewers
.LabelProvider
;
25 import org
.eclipse
.jface
.viewers
.TableViewer
;
26 import org
.eclipse
.swt
.graphics
.Image
;
27 import org
.eclipse
.swt
.widgets
.TableColumn
;
29 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
30 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
31 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
32 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
33 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
34 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
35 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermComparator
;
36 import eu
.etaxonomy
.cdm
.model
.common
.TermIdInVocabularyComparator
;
37 import eu
.etaxonomy
.cdm
.model
.common
.TermLanguageComparator
;
38 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
39 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
40 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
41 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
42 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
43 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
44 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
45 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
52 public class ChecklistLabelProvider
extends LabelProvider
implements ITableLabelProvider
{
54 public static final String DEFAULT_ENTRY
= ""; //$NON-NLS-1$
55 private IDescriptionService descriptionService
;
56 private final SortedSet
<DefinedTermBase
> namedAreas
;
57 TableViewer viewer
= null;
62 public ChecklistLabelProvider() {
63 namedAreas
= loadNamedAreas();
66 public ChecklistLabelProvider(TableViewer viewer
) {
67 namedAreas
= loadNamedAreas();
75 * org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang
80 public Image
getColumnImage(Object element
, int columnIndex
) {
87 public String
getColumnText(Object element
, int columnIndex
) {
88 // descriptionService = CdmStore.getService(IDescriptionService.class);
89 Taxon taxon
= (Taxon
) element
;
90 //TODO load areas by this list
92 // List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null, null, null, null, DESC_INIT_STRATEGY);;
93 Set
<TaxonDescription
> listTaxonDescriptions
= taxon
.getDescriptions();
94 TaxonName nonViralName
= HibernateProxyHelper
.deproxy(taxon
.getName());
96 switch (columnIndex
) {
98 String taxonName
= null;
99 taxonName
= (nonViralName
!= null) ? nonViralName
.getNameCache() : null;
100 return (taxonName
!= null) ? taxonName
: DEFAULT_ENTRY
;
103 // String authorship = null;
104 // authorship = (nonViralName != null) ? nonViralName.getAuthorshipCache() : null;
105 // return (authorship != null) ? authorship : DEFAULT_ENTRY;
107 // String ref = null;
108 // if (taxon.getName() != null) {
109 // INomenclaturalReference nomenclaturalReference = HibernateProxyHelper.deproxy(
110 // nonVirlaName.getNomenclaturalReference(), Reference.class);
111 // ref = (nomenclaturalReference != null) ? nomenclaturalReference.getAbbrevTitleCache() : null;
113 // return (ref != null) ? ref : DEFAULT_ENTRY;
115 if (PreferencesUtil
.isShowRankInChecklistEditor()){
118 if (taxon
.getName().getRank() != null) {
119 rank
= taxon
.getName().getRank().toString();
121 return (rank
!= null) ? rank
: DEFAULT_ENTRY
;
125 if(columnIndex
>2 || (!PreferencesUtil
.isShowRankInChecklistEditor() && columnIndex
> 0)){
127 for (TaxonDescription td
: listTaxonDescriptions
) {
128 for (DescriptionElementBase deb
: td
.getElements()) {
129 if (deb
instanceof Distribution
) {
130 Distribution distribution
= HibernateProxyHelper
.deproxy(deb
, Distribution
.class);
132 if (distribution
.getArea() != null ){
133 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
134 if (distribution
.getArea().getIdInVocabulary() != null){
135 area
= distribution
.getArea().getIdInVocabulary();
137 area
= distribution
.getArea().getTitleCache();
140 area
= distribution
.getArea().getTitleCache();
148 TableColumn column
= viewer
.getTable().getColumn(columnIndex
);
149 if (area
.equalsIgnoreCase(column
.getText())) {
150 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
151 return (distribution
.getStatus().getIdInVocabulary() != null)?distribution
.getStatus().getIdInVocabulary():CdmUtils
.Nz(distribution
.getStatus().getTitleCache());
153 return (distribution
.getStatus().getTitleCache() != null)?distribution
.getStatus().getTitleCache():DEFAULT_ENTRY
;
162 return DEFAULT_ENTRY
;
166 private static final List
<String
> DESC_INIT_STRATEGY
= Arrays
.asList(new String
[] { "descriptions", //$NON-NLS-1$
167 "descriptions.*", "description.state" }); //$NON-NLS-1$ //$NON-NLS-2$
170 private SortedSet
<DefinedTermBase
> loadNamedAreas() {
171 IPreferenceStore preferenceStore
= PreferencesUtil
.getPreferenceStore();
173 String values
= preferenceStore
.getString(PreferencesUtil
.DISTRIBUTION_AREA_OCCURENCE_STATUS
);
175 if (values
!= null && values
!= "") { //$NON-NLS-1$
176 String
[] split
= values
.split(","); //$NON-NLS-1$
177 List
<String
> listValue
= Arrays
.asList(split
);
178 List
<DefinedTermBase
> termlist
= new ArrayList
<DefinedTermBase
>();
179 Set
<UUID
> uuidList
= new HashSet
<UUID
>();
181 for(String s
: listValue
){
182 uuid
= UUID
.fromString(s
);
186 ITermService service
= CdmStore
.getService(ITermService
.class);
187 termlist
= service
.find(uuidList
);
188 if (PreferencesUtil
.isSortNamedAreaByOrderInVocabulary()){
189 return getTermsOrderedByVocabularyOrder(termlist
);
190 } else if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
191 return getTermsOrderedByIdInVocabulary(termlist
);
193 return getTermsOrderedByLabels(termlist
, CdmStore
.getDefaultLanguage());
199 public SortedSet
<DefinedTermBase
> getTermsOrderedByLabels(List
<DefinedTermBase
> listTerm
,Language language
){
200 TermLanguageComparator
<?
> comp
= new TermLanguageComparator
<>();
201 comp
.setCompareLanguage(language
);
202 SortedSet
<DefinedTermBase
> result
= new TreeSet(comp
);
203 if(listTerm
!= null){
204 result
.addAll(listTerm
);
209 public SortedSet
<DefinedTermBase
> getTermsOrderedByVocabularyOrder(List
<DefinedTermBase
> listAreas
){
210 HashMap
<TermVocabulary
<DefinedTermBase
>, List
<DefinedTermBase
>> vocs
= new HashMap
<>();
211 OrderedTermComparator
<?
> comp
= new OrderedTermComparator
<>();
213 SortedSet
<DefinedTermBase
> result
= new TreeSet(comp
.reversed());
214 result
.addAll(listAreas
);
220 * @return the namedAreas
222 public SortedSet
<DefinedTermBase
> getNamedAreas() {
228 * @param defaultLanguage
231 public SortedSet
<DefinedTermBase
> getTermsOrderedByIdInVocabulary(List
<DefinedTermBase
> namedAreas
) {
232 TermIdInVocabularyComparator
<?
> comp
= new TermIdInVocabularyComparator
<>();
234 SortedSet
<DefinedTermBase
> result
= new TreeSet(comp
);
235 if(namedAreas
!= null){
236 result
.addAll(namedAreas
);