3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Arrays
;
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
.TermIdInVocabularyComparator
;
36 import eu
.etaxonomy
.cdm
.model
.common
.TermLanguageComparator
;
37 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
38 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
39 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
40 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
41 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
42 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
43 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
44 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
52 public class ChecklistLabelProvider
extends LabelProvider
implements ITableLabelProvider
{
54 public static final String DEFAULT_ENTRY
= "";
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
) {
89 * org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang
94 public String
getColumnText(Object element
, int columnIndex
) {
95 // descriptionService = CdmStore.getService(IDescriptionService.class);
96 Taxon taxon
= (Taxon
) element
;
97 //TODO load areas by this list
99 // List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null, null, null, null, DESC_INIT_STRATEGY);;
100 Set
<TaxonDescription
> listTaxonDescriptions
= taxon
.getDescriptions();
101 NonViralName
<?
> nonViralName
= HibernateProxyHelper
.deproxy(taxon
.getName(), NonViralName
.class);
103 switch (columnIndex
) {
105 String taxonName
= null;
106 taxonName
= (nonViralName
!= null) ? nonViralName
.getNameCache() : null;
107 return (taxonName
!= null) ? taxonName
: DEFAULT_ENTRY
;
110 // String authorship = null;
111 // authorship = (nonViralName != null) ? nonViralName.getAuthorshipCache() : null;
112 // return (authorship != null) ? authorship : DEFAULT_ENTRY;
114 // String ref = null;
115 // if (taxon.getName() != null) {
116 // INomenclaturalReference nomenclaturalReference = HibernateProxyHelper.deproxy(
117 // nonVirlaName.getNomenclaturalReference(), Reference.class);
118 // ref = (nomenclaturalReference != null) ? nomenclaturalReference.getAbbrevTitleCache() : null;
120 // return (ref != null) ? ref : DEFAULT_ENTRY;
122 if (PreferencesUtil
.isShowRankInChecklistEditor()){
125 if (taxon
.getName().getRank() != null) {
126 rank
= taxon
.getName().getRank().toString();
128 return (rank
!= null) ? rank
: DEFAULT_ENTRY
;
132 if(columnIndex
>2 || (!PreferencesUtil
.isShowRankInChecklistEditor() && columnIndex
> 0)){
134 for (TaxonDescription td
: listTaxonDescriptions
) {
135 for (DescriptionElementBase deb
: td
.getElements()) {
136 if (deb
instanceof Distribution
) {
137 Distribution distribution
= HibernateProxyHelper
.deproxy(deb
, Distribution
.class);
139 if (distribution
.getArea() != null ){
140 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
141 if (distribution
.getArea().getIdInVocabulary() != null){
142 area
= distribution
.getArea().getIdInVocabulary();
144 area
= distribution
.getArea().getTitleCache();
147 area
= distribution
.getArea().getTitleCache();
154 TableColumn column
= viewer
.getTable().getColumn(columnIndex
);
155 if (area
.equalsIgnoreCase(column
.getText())) {
156 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
157 return (distribution
.getStatus().getIdInVocabulary() != null)?distribution
.getStatus().getIdInVocabulary():CdmUtils
.Nz(distribution
.getStatus().getTitleCache());
159 return (distribution
.getStatus().getTitleCache() != null)?distribution
.getStatus().getTitleCache():DEFAULT_ENTRY
;
168 return DEFAULT_ENTRY
;
172 private static final List
<String
> DESC_INIT_STRATEGY
= Arrays
.asList(new String
[] { "descriptions",
173 "descriptions.*", "description.state" });
176 private SortedSet
<DefinedTermBase
> loadNamedAreas() {
177 IPreferenceStore preferenceStore
= PreferencesUtil
.getPreferenceStore();
178 String values
= preferenceStore
.getString(PreferencesUtil
.DISTRIBUTION_AREA_OCCURENCE_STATUS
);
180 if (values
!= null && values
!= "") {
181 String
[] split
= values
.split(",");
182 List
<String
> listValue
= Arrays
.asList(split
);
183 List
<DefinedTermBase
> termlist
= new ArrayList
<DefinedTermBase
>();
184 Set
<UUID
> uuidList
= new HashSet
<UUID
>();
186 for(String s
: listValue
){
187 uuid
= UUID
.fromString(s
);
191 ITermService service
= CdmStore
.getService(ITermService
.class);
192 termlist
= service
.find(uuidList
);
193 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
194 return getTermsOrderedByIdInVocabulary(termlist
);
196 return getTermsOrderedByLabels(termlist
, CdmStore
.getDefaultLanguage());
202 public SortedSet
<DefinedTermBase
> getTermsOrderedByLabels(List
<DefinedTermBase
> listTerm
,Language language
){
203 TermLanguageComparator comp
= new TermLanguageComparator();
204 comp
.setCompareLanguage(language
);
205 SortedSet result
= new TreeSet(comp
);
206 if(listTerm
!= null){
207 result
.addAll(listTerm
);
213 * @return the namedAreas
215 public SortedSet
<DefinedTermBase
> getNamedAreas() {
221 * @param defaultLanguage
224 public SortedSet
<DefinedTermBase
> getTermsOrderedByIdInVocabulary(List
<DefinedTermBase
> namedAreas
) {
225 TermIdInVocabularyComparator comp
= new TermIdInVocabularyComparator();
227 SortedSet result
= new TreeSet(comp
);
228 if(namedAreas
!= null){
229 result
.addAll(namedAreas
);