2 * Copyright (C) 2011 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.
9 package eu
.etaxonomy
.taxeditor
.editor
.view
.uses
;
11 import java
.util
.Arrays
;
12 import java
.util
.List
;
14 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
15 import org
.eclipse
.jface
.viewers
.DelegatingStyledCellLabelProvider
.IStyledLabelProvider
;
16 import org
.eclipse
.jface
.viewers
.StyledString
;
18 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
19 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
20 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
21 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
22 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
23 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
24 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
25 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
27 import eu
.etaxonomy
.taxeditor
.editor
.UsageTermCollection
;
30 * UsesLabelProvider Class
32 * @created mar 13, 2012
35 public class UsesLabelProvider
extends ColumnLabelProvider
implements
36 IStyledLabelProvider
{
39 public String
getText(Object element
) {
42 if (element
instanceof DescriptionBase
) {
43 text
= ((DescriptionBase
) element
).getTitleCache();
44 if (text
== null || text
.length() == 0) {
45 text
= "Use: No label provided";
48 text
= "Use: " + text
;
51 else if (element
instanceof CategoricalData
) {
52 if (!((CategoricalData
) element
).getStateData().isEmpty()) {
53 boolean isUseCategoryAbsent
= true;
54 for (StateData statedata
: ((CategoricalData
) element
).getStateData()) {
55 if(statedata
.getState() != null && statedata
.getModifyingText().get(CdmStore
.getDefaultLanguage()) !=null && statedata
.getModifyingText().get(CdmStore
.getDefaultLanguage()).getText().equals(UsageTermCollection
.useCategoryVocabularyLabel
)) {
56 text
= text
+ statedata
.getState().getTitleCache() + ";";
57 isUseCategoryAbsent
= false;
60 if(isUseCategoryAbsent
) {
61 text
= text
+ UsageTermCollection
.notAvailableLabel
+ ";";
64 boolean isUseSubCategoryAbsent
= true;
65 for (StateData statedata
: ((CategoricalData
) element
).getStateData()) {
66 if(statedata
.getState() != null && statedata
.getModifyingText().get(CdmStore
.getDefaultLanguage()) !=null && statedata
.getModifyingText().get(CdmStore
.getDefaultLanguage()).getText().equals(UsageTermCollection
.useSubCategoryVocabularyLabel
)) {
67 text
= text
+ statedata
.getState().getTitleCache() + ";";
68 isUseSubCategoryAbsent
= false;
71 if(isUseSubCategoryAbsent
) {
72 text
= text
+ UsageTermCollection
.notAvailableLabel
+ ";";
76 text
= text
+ UsageTermCollection
.notAvailableLabel
+ ";" + UsageTermCollection
.notAvailableLabel
+ ";";
78 if (!((CategoricalData
) element
).getModifiers().isEmpty()) {
79 for (DefinedTerm modifier
: ((CategoricalData
) element
).getModifiers()){
81 modifier
.getVocabulary();
84 boolean isPlantPartAbsent
= true;
85 for (DefinedTerm modifier
: ((CategoricalData
) element
).getModifiers()){
86 if(GetVocabularyType(modifier
, UsageTermCollection
.plantPartLabel
)) {
87 text
= text
+ modifier
.getTitleCache()+ ";";
88 isPlantPartAbsent
= false;
92 if (isPlantPartAbsent
) {
93 text
= text
+ UsageTermCollection
.notAvailableLabel
+ ";";
96 boolean isHumanGroupAbsent
= true;
97 for (DefinedTerm modifier
: ((CategoricalData
) element
).getModifiers()){
98 if(GetVocabularyType(modifier
, UsageTermCollection
.humanGroupLabel
)) {
99 text
= text
+ modifier
.getTitleCache()+ ";";
100 isHumanGroupAbsent
= false;
103 if (isHumanGroupAbsent
) {
104 text
= text
+ UsageTermCollection
.notAvailableLabel
+ ";";
107 boolean isEthnicGroupAbsent
= true;
108 for (DefinedTerm modifier
: ((CategoricalData
) element
).getModifiers()){
109 if(GetVocabularyType(modifier
, UsageTermCollection
.ethnicGroupLabel
)) {
110 text
= text
+ modifier
.getTitleCache()+ ";";
111 isEthnicGroupAbsent
= false;
114 if (isEthnicGroupAbsent
) {
115 text
= text
+ UsageTermCollection
.notAvailableLabel
+ ";";
118 boolean isCountryAbsent
= true;
119 for (DefinedTerm modifier
: ((CategoricalData
) element
).getModifiers()){
120 if(GetVocabularyType(modifier
, UsageTermCollection
.countryLabel
)) {
121 text
= text
+ modifier
.getTitleCache()+ ";";
122 isCountryAbsent
= false;
125 if (isCountryAbsent
) {
126 text
= text
+ UsageTermCollection
.notAvailableLabel
+ ";";
130 text
= text
+ UsageTermCollection
.notAvailableLabel
+ ";" + UsageTermCollection
.notAvailableLabel
+ ";" + UsageTermCollection
.notAvailableLabel
+ ";" + UsageTermCollection
.notAvailableLabel
+ ";";
133 if (text
== null || text
.length() == 0) {
134 text
= "No data provided";
137 String
[] textElements
= text
.split(";");
138 String dataportalString
= textElements
[0] + ";" + textElements
[1] + ";" + textElements
[5] + ";" + textElements
[2] + ";" + textElements
[3] + ";" + textElements
[4] + ";" ;
140 ((CategoricalData
)element
).putModifyingText(CdmStore
.getDefaultLanguage(), dataportalString
);
145 else if (element
instanceof TextData
) {
146 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
147 LanguageString languageString
= ((TextData
) element
).getPreferredLanguageString(languages
);
148 text
= languageString
!= null ? languageString
.getText() : null;
149 if (text
== null || text
.length() == 0) {
150 text
= "No data provided";
154 else if (element
instanceof FeatureNodeContainer
){
155 text
= ((FeatureNodeContainer
)element
).getFeature().getTitleCache();
161 /** Function dertmining which vocabulary is the term part of
164 * @param vocabularyExpected
167 private boolean GetVocabularyType(DefinedTerm term
, String vocabularyExpected
) {
168 if ((term
.getPartOf() != null) && (term
.getPartOf().getTitleCache().equals(vocabularyExpected
))) {
171 else if ((term
.getVocabulary() != null) && (term
.getPartOf() == null) && (term
.getVocabulary().getTitleCache().equals(vocabularyExpected
))) {
174 else if ((vocabularyExpected
.equals(UsageTermCollection
.ethnicGroupLabel
)) && ((term
.getPartOf() != null))) {
182 public StyledString
getStyledText(Object element
) {
183 return new StyledString(this.getText(element
),
184 StyledString
.QUALIFIER_STYLER
);