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
.HashSet
;
15 import java
.util
.List
;
17 import java
.util
.SortedSet
;
18 import java
.util
.TreeSet
;
19 import java
.util
.UUID
;
21 import org
.eclipse
.jface
.preference
.IPreferenceStore
;
22 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
23 import org
.eclipse
.jface
.viewers
.LabelProvider
;
24 import org
.eclipse
.jface
.viewers
.TableViewer
;
25 import org
.eclipse
.swt
.graphics
.Image
;
26 import org
.eclipse
.swt
.widgets
.TableColumn
;
28 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
29 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
30 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
31 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
32 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
33 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
34 import eu
.etaxonomy
.cdm
.model
.common
.TermIdInVocabularyComparator
;
35 import eu
.etaxonomy
.cdm
.model
.common
.TermLanguageComparator
;
36 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
37 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
38 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
39 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
41 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
42 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
43 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
51 public class ChecklistLabelProvider
extends LabelProvider
implements ITableLabelProvider
{
53 public static final String DEFAULT_ENTRY
= "";
54 private IDescriptionService descriptionService
;
55 private final SortedSet
<DefinedTermBase
> namedAreas
;
56 TableViewer viewer
= null;
61 public ChecklistLabelProvider() {
62 namedAreas
= loadNamedAreas();
65 public ChecklistLabelProvider(TableViewer viewer
) {
66 namedAreas
= loadNamedAreas();
74 * org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang
79 public Image
getColumnImage(Object element
, int columnIndex
) {
88 * org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang
93 public String
getColumnText(Object element
, int columnIndex
) {
94 // descriptionService = CdmStore.getService(IDescriptionService.class);
95 Taxon taxon
= (Taxon
) element
;
96 //TODO load areas by this list
98 // List<TaxonDescription> listTaxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null, null, null, null, DESC_INIT_STRATEGY);;
99 Set
<TaxonDescription
> listTaxonDescriptions
= taxon
.getDescriptions();
100 NonViralName
<?
> nonViralName
= HibernateProxyHelper
.deproxy(taxon
.getName(), NonViralName
.class);
102 switch (columnIndex
) {
104 String taxonName
= null;
105 taxonName
= (nonViralName
!= null) ? nonViralName
.getNameCache() : null;
106 return (taxonName
!= null) ? taxonName
: DEFAULT_ENTRY
;
109 // String authorship = null;
110 // authorship = (nonViralName != null) ? nonViralName.getAuthorshipCache() : null;
111 // return (authorship != null) ? authorship : DEFAULT_ENTRY;
113 // String ref = null;
114 // if (taxon.getName() != null) {
115 // INomenclaturalReference nomenclaturalReference = HibernateProxyHelper.deproxy(
116 // nonVirlaName.getNomenclaturalReference(), Reference.class);
117 // ref = (nomenclaturalReference != null) ? nomenclaturalReference.getAbbrevTitleCache() : null;
119 // return (ref != null) ? ref : DEFAULT_ENTRY;
121 if (PreferencesUtil
.isShowRankInChecklistEditor()){
124 if (taxon
.getName().getRank() != null) {
125 rank
= taxon
.getName().getRank().toString();
127 return (rank
!= null) ? rank
: DEFAULT_ENTRY
;
131 if(columnIndex
>2 || (!PreferencesUtil
.isShowRankInChecklistEditor() && columnIndex
> 0)){
133 for (TaxonDescription td
: listTaxonDescriptions
) {
134 for (DescriptionElementBase deb
: td
.getElements()) {
135 if (deb
instanceof Distribution
) {
136 Distribution distribution
= HibernateProxyHelper
.deproxy(deb
, Distribution
.class);
138 if (distribution
.getArea() != null ){
139 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
140 if (distribution
.getArea().getIdInVocabulary() != null){
141 area
= distribution
.getArea().getIdInVocabulary();
143 area
= distribution
.getArea().getTitleCache();
146 area
= distribution
.getArea().getTitleCache();
153 TableColumn column
= viewer
.getTable().getColumn(columnIndex
);
154 if (area
.equalsIgnoreCase(column
.getText())) {
155 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
156 return (distribution
.getStatus().getIdInVocabulary() != null)?distribution
.getStatus().getIdInVocabulary():CdmUtils
.Nz(distribution
.getStatus().getTitleCache());
158 return (distribution
.getStatus().getTitleCache() != null)?distribution
.getStatus().getTitleCache():DEFAULT_ENTRY
;
167 return DEFAULT_ENTRY
;
171 private static final List
<String
> DESC_INIT_STRATEGY
= Arrays
.asList(new String
[] { "descriptions",
172 "descriptions.*", "description.state" });
175 private SortedSet
<DefinedTermBase
> loadNamedAreas() {
176 IPreferenceStore preferenceStore
= PreferencesUtil
.getPreferenceStore();
177 String values
= preferenceStore
.getString(PreferencesUtil
.DISTRIBUTION_AREA_OCCURENCE_STATUS
);
179 if (values
!= null && values
!= "") {
180 String
[] split
= values
.split(",");
181 List
<String
> listValue
= Arrays
.asList(split
);
182 List
<DefinedTermBase
> termlist
= new ArrayList
<DefinedTermBase
>();
183 Set
<UUID
> uuidList
= new HashSet
<UUID
>();
185 for(String s
: listValue
){
186 uuid
= UUID
.fromString(s
);
190 ITermService service
= CdmStore
.getService(ITermService
.class);
191 termlist
= service
.find(uuidList
);
192 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
193 return getTermsOrderedByIdInVocabulary(termlist
);
195 return getTermsOrderedByLabels(termlist
, CdmStore
.getDefaultLanguage());
201 public SortedSet
<DefinedTermBase
> getTermsOrderedByLabels(List
<DefinedTermBase
> listTerm
,Language language
){
202 TermLanguageComparator comp
= new TermLanguageComparator();
203 comp
.setCompareLanguage(language
);
204 SortedSet result
= new TreeSet(comp
);
205 if(listTerm
!= null){
206 result
.addAll(listTerm
);
212 * @return the namedAreas
214 public SortedSet
<DefinedTermBase
> getNamedAreas() {
220 * @param defaultLanguage
223 public SortedSet
<DefinedTermBase
> getTermsOrderedByIdInVocabulary(List
<DefinedTermBase
> namedAreas
) {
224 TermIdInVocabularyComparator comp
= new TermIdInVocabularyComparator();
226 SortedSet result
= new TreeSet(comp
);
227 if(namedAreas
!= null){
228 result
.addAll(namedAreas
);