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
.List
;
16 import java
.util
.SortedSet
;
17 import java
.util
.TreeSet
;
18 import java
.util
.UUID
;
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
.jface
.viewers
.TableViewer
;
24 import org
.eclipse
.swt
.graphics
.Image
;
25 import org
.eclipse
.swt
.widgets
.TableColumn
;
27 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
28 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
29 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
30 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
31 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
32 import eu
.etaxonomy
.cdm
.model
.common
.TermLanguageComparator
;
33 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
34 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
35 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
36 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
38 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
39 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
47 public class ChecklistLabelProvider
extends LabelProvider
implements ITableLabelProvider
{
49 public static final String DEFAULT_ENTRY
= "";
50 private IDescriptionService descriptionService
;
51 private final List
<DefinedTermBase
<?
>> namedAreas
;
52 TableViewer viewer
= null;
57 public ChecklistLabelProvider() {
58 namedAreas
= loadNamedAreas();
61 public ChecklistLabelProvider(TableViewer viewer
) {
62 namedAreas
= loadNamedAreas();
70 * org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang
75 public Image
getColumnImage(Object element
, int columnIndex
) {
84 * org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang
89 public String
getColumnText(Object element
, int columnIndex
) {
90 descriptionService
= CdmStore
.getService(IDescriptionService
.class);
91 Taxon taxon
= (Taxon
) element
;
92 //TODO load areas by this list
94 List
<TaxonDescription
> listTaxonDescriptions
= descriptionService
.listTaxonDescriptions(taxon
, null, null, null, null, null, DESC_INIT_STRATEGY
);;
95 NonViralName
<?
> nonVirlaName
= HibernateProxyHelper
.deproxy(taxon
.getName(), NonViralName
.class);
97 switch (columnIndex
) {
99 String taxonName
= null;
100 taxonName
= (nonVirlaName
!= null) ? nonVirlaName
.getNameCache() : null;
101 return (taxonName
!= null) ? taxonName
: DEFAULT_ENTRY
;
104 String authorship
= null;
105 authorship
= (nonVirlaName
!= null) ? nonVirlaName
.getAuthorshipCache() : null;
106 return (authorship
!= null) ? authorship
: DEFAULT_ENTRY
;
108 // String ref = null;
109 // if (taxon.getName() != null) {
110 // INomenclaturalReference nomenclaturalReference = HibernateProxyHelper.deproxy(
111 // nonVirlaName.getNomenclaturalReference(), Reference.class);
112 // ref = (nomenclaturalReference != null) ? nomenclaturalReference.getAbbrevTitleCache() : null;
114 // return (ref != null) ? ref : DEFAULT_ENTRY;
117 if (taxon
.getName().getRank() != null) {
118 rank
= taxon
.getName().getRank().toString();
120 return (rank
!= null) ? rank
: DEFAULT_ENTRY
;
125 for (TaxonDescription td
: listTaxonDescriptions
) {
126 for (DescriptionElementBase deb
: td
.getElements()) {
127 if (deb
instanceof Distribution
) {
128 Distribution distribution
= (Distribution
) deb
;
129 String area
= distribution
.toString();
131 TableColumn column
= viewer
.getTable().getColumn(columnIndex
);
132 if (area
.equalsIgnoreCase(column
.getText())) {
133 return (distribution
.getStatus().getTitleCache() != null)?distribution
.getStatus().getTitleCache():DEFAULT_ENTRY
;
140 return DEFAULT_ENTRY
;
144 private static final List
<String
> DESC_INIT_STRATEGY
= Arrays
.asList(new String
[] { "descriptions",
145 "descriptions.*", "description.state" });
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
);
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
);
177 * @return the namedAreas
179 public List
<DefinedTermBase
<?
>> getNamedAreas() {