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
.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
.preference
.PreferencesUtil
;
42 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
50 public class ChecklistLabelProvider
extends LabelProvider
implements ITableLabelProvider
{
52 public static final String DEFAULT_ENTRY
= "";
53 private IDescriptionService descriptionService
;
54 private final SortedSet
<DefinedTermBase
> namedAreas
;
55 TableViewer viewer
= null;
60 public ChecklistLabelProvider() {
61 namedAreas
= loadNamedAreas();
64 public ChecklistLabelProvider(TableViewer viewer
) {
65 namedAreas
= loadNamedAreas();
73 * org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang
78 public Image
getColumnImage(Object element
, int columnIndex
) {
87 * org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang
92 public String
getColumnText(Object element
, int columnIndex
) {
93 descriptionService
= CdmStore
.getService(IDescriptionService
.class);
94 Taxon taxon
= (Taxon
) element
;
95 //TODO load areas by this list
97 List
<TaxonDescription
> listTaxonDescriptions
= descriptionService
.listTaxonDescriptions(taxon
, null, null, null, null, null, DESC_INIT_STRATEGY
);;
98 NonViralName
<?
> nonViralName
= HibernateProxyHelper
.deproxy(taxon
.getName(), NonViralName
.class);
100 switch (columnIndex
) {
102 String taxonName
= null;
103 taxonName
= (nonViralName
!= null) ? nonViralName
.getNameCache() : null;
104 return (taxonName
!= null) ? taxonName
: DEFAULT_ENTRY
;
107 String authorship
= null;
108 authorship
= (nonViralName
!= null) ? nonViralName
.getAuthorshipCache() : null;
109 return (authorship
!= null) ? authorship
: DEFAULT_ENTRY
;
111 // String ref = null;
112 // if (taxon.getName() != null) {
113 // INomenclaturalReference nomenclaturalReference = HibernateProxyHelper.deproxy(
114 // nonVirlaName.getNomenclaturalReference(), Reference.class);
115 // ref = (nomenclaturalReference != null) ? nomenclaturalReference.getAbbrevTitleCache() : null;
117 // return (ref != null) ? ref : DEFAULT_ENTRY;
120 if (taxon
.getName().getRank() != null) {
121 rank
= taxon
.getName().getRank().toString();
123 return (rank
!= null) ? rank
: DEFAULT_ENTRY
;
128 for (TaxonDescription td
: listTaxonDescriptions
) {
129 for (DescriptionElementBase deb
: td
.getElements()) {
130 if (deb
instanceof Distribution
) {
131 Distribution distribution
= HibernateProxyHelper
.deproxy(deb
, Distribution
.class);
133 if (distribution
.getArea() != null ){
134 if (PreferencesUtil
.isShowIdInVocabularyInChecklistEditor()){
135 area
= distribution
.getArea().getIdInVocabulary();
137 area
= distribution
.getArea().getTitleCache();
144 TableColumn column
= viewer
.getTable().getColumn(columnIndex
);
145 if (area
.equalsIgnoreCase(column
.getText())) {
146 return (distribution
.getStatus().getTitleCache() != null)?distribution
.getStatus().getTitleCache():DEFAULT_ENTRY
;
154 return DEFAULT_ENTRY
;
158 private static final List
<String
> DESC_INIT_STRATEGY
= Arrays
.asList(new String
[] { "descriptions",
159 "descriptions.*", "description.state" });
162 private SortedSet
<DefinedTermBase
> loadNamedAreas() {
163 IPreferenceStore preferenceStore
= PreferencesUtil
.getPreferenceStore();
164 String values
= preferenceStore
.getString(PreferencesUtil
.DISTRIBUTION_AREA_OCCURENCE_STATUS
);
165 if (values
!= null && values
!= "") {
166 String
[] split
= values
.split(",");
167 List
<String
> listValue
= Arrays
.asList(split
);
168 List
<DefinedTermBase
> termlist
= new ArrayList
<DefinedTermBase
>();
169 Set
<UUID
> uuidList
= new HashSet
<UUID
>();
171 for(String s
: listValue
){
172 uuid
= UUID
.fromString(s
);
176 ITermService service
= CdmStore
.getService(ITermService
.class);
177 termlist
= service
.find(uuidList
);
179 return getTermsOrderedByIdInVocabulary(termlist
);
184 public SortedSet
<?
> getTermsOrderedByLabels(List
<DefinedTermBase
<?
>> listTerm
,Language language
){
185 TermLanguageComparator comp
= new TermLanguageComparator();
186 comp
.setCompareLanguage(language
);
187 SortedSet result
= new TreeSet(comp
);
188 if(listTerm
!= null){
189 result
.addAll(listTerm
);
195 * @return the namedAreas
197 public SortedSet
<DefinedTermBase
> getNamedAreas() {
203 * @param defaultLanguage
206 public SortedSet
<DefinedTermBase
> getTermsOrderedByIdInVocabulary(List
<DefinedTermBase
> namedAreas
) {
207 TermIdInVocabularyComparator comp
= new TermIdInVocabularyComparator();
209 SortedSet result
= new TreeSet(comp
);
210 if(namedAreas
!= null){
211 result
.addAll(namedAreas
);