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
.term
.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
.editor
.l10n
.Messages
;
26 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
28 import eu
.etaxonomy
.taxeditor
.store
.UsageTermCollection
;
31 * UsesLabelProvider Class
33 * @created mar 13, 2012
36 public class UsesLabelProvider
extends ColumnLabelProvider
implements
37 IStyledLabelProvider
{
39 private static final String USE
= Messages
.UsesLabelProvider_USE
;
40 private static final String NO_DATA_PROVIDED
= Messages
.UsesLabelProvider_NO_DATA
;
41 private static final String SEMICOLON
= ";"; //$NON-NLS-1$
45 public String
getText(Object element
) {
46 String text
= ""; //$NON-NLS-1$
48 if (element
instanceof DescriptionBase
) {
49 text
= ((DescriptionBase
) element
).getTitleCache();
50 if (text
== null || text
.length() == 0) {
51 text
= USE
+Messages
.UsesLabelProvider_NO_LABEL
;
57 else if (element
instanceof CategoricalData
) {
58 if (!((CategoricalData
) element
).getStateData().isEmpty()) {
59 boolean isUseCategoryAbsent
= true;
60 for (StateData statedata
: ((CategoricalData
) element
).getStateData()) {
61 if(statedata
.getState() != null && statedata
.getModifyingText().get(CdmStore
.getDefaultLanguage()) !=null && statedata
.getModifyingText().get(CdmStore
.getDefaultLanguage()).getText().equals(UsageTermCollection
.useCategoryVocabularyLabel
)) {
62 text
= text
+ statedata
.getState().getTitleCache() + SEMICOLON
;
63 isUseCategoryAbsent
= false;
66 if(isUseCategoryAbsent
) {
67 text
= text
+ UsageTermCollection
.notAvailableLabel
+ SEMICOLON
;
70 boolean isUseSubCategoryAbsent
= true;
71 for (StateData statedata
: ((CategoricalData
) element
).getStateData()) {
72 if(statedata
.getState() != null && statedata
.getModifyingText().get(CdmStore
.getDefaultLanguage()) !=null && statedata
.getModifyingText().get(CdmStore
.getDefaultLanguage()).getText().equals(UsageTermCollection
.useSubCategoryVocabularyLabel
)) {
73 text
= text
+ statedata
.getState().getTitleCache() + SEMICOLON
;
74 isUseSubCategoryAbsent
= false;
77 if(isUseSubCategoryAbsent
) {
78 text
= text
+ UsageTermCollection
.notAvailableLabel
+ SEMICOLON
;
82 text
= text
+ UsageTermCollection
.notAvailableLabel
+ SEMICOLON
+ UsageTermCollection
.notAvailableLabel
+ SEMICOLON
;
84 if (!((CategoricalData
) element
).getModifiers().isEmpty()) {
85 for (DefinedTerm modifier
: ((CategoricalData
) element
).getModifiers()){
87 modifier
.getVocabulary();
90 boolean isPlantPartAbsent
= true;
91 for (DefinedTerm modifier
: ((CategoricalData
) element
).getModifiers()){
92 if(GetVocabularyType(modifier
, UsageTermCollection
.plantPartLabel
)) {
93 text
= text
+ modifier
.getTitleCache()+ SEMICOLON
;
94 isPlantPartAbsent
= false;
98 if (isPlantPartAbsent
) {
99 text
= text
+ UsageTermCollection
.notAvailableLabel
+ SEMICOLON
;
102 boolean isHumanGroupAbsent
= true;
103 for (DefinedTerm modifier
: ((CategoricalData
) element
).getModifiers()){
104 if(GetVocabularyType(modifier
, UsageTermCollection
.humanGroupLabel
)) {
105 text
= text
+ modifier
.getTitleCache()+ SEMICOLON
;
106 isHumanGroupAbsent
= false;
109 if (isHumanGroupAbsent
) {
110 text
= text
+ UsageTermCollection
.notAvailableLabel
+ SEMICOLON
;
113 boolean isEthnicGroupAbsent
= true;
114 for (DefinedTerm modifier
: ((CategoricalData
) element
).getModifiers()){
115 if(GetVocabularyType(modifier
, UsageTermCollection
.ethnicGroupLabel
)) {
116 text
= text
+ modifier
.getTitleCache()+ SEMICOLON
;
117 isEthnicGroupAbsent
= false;
120 if (isEthnicGroupAbsent
) {
121 text
= text
+ UsageTermCollection
.notAvailableLabel
+ SEMICOLON
;
124 boolean isCountryAbsent
= true;
125 for (DefinedTerm modifier
: ((CategoricalData
) element
).getModifiers()){
126 if(GetVocabularyType(modifier
, UsageTermCollection
.countryLabel
)) {
127 text
= text
+ modifier
.getTitleCache()+ SEMICOLON
;
128 isCountryAbsent
= false;
131 if (isCountryAbsent
) {
132 text
= text
+ UsageTermCollection
.notAvailableLabel
+ SEMICOLON
;
136 text
= text
+ UsageTermCollection
.notAvailableLabel
+ SEMICOLON
+ UsageTermCollection
.notAvailableLabel
+ SEMICOLON
+ UsageTermCollection
.notAvailableLabel
+ SEMICOLON
+ UsageTermCollection
.notAvailableLabel
+ SEMICOLON
;
139 if (text
== null || text
.length() == 0) {
140 text
= NO_DATA_PROVIDED
;
143 String
[] textElements
= text
.split(SEMICOLON
);
144 String dataportalString
= textElements
[0] + SEMICOLON
+ textElements
[1] + SEMICOLON
+ textElements
[5] + SEMICOLON
+ textElements
[2] + SEMICOLON
+ textElements
[3] + SEMICOLON
+ textElements
[4] + SEMICOLON
;
146 ((CategoricalData
)element
).putModifyingText(CdmStore
.getDefaultLanguage(), dataportalString
);
151 else if (element
instanceof TextData
) {
152 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
153 LanguageString languageString
= ((TextData
) element
).getPreferredLanguageString(languages
);
154 text
= languageString
!= null ? languageString
.getText() : null;
155 if (text
== null || text
.length() == 0) {
156 text
= NO_DATA_PROVIDED
;
160 else if (element
instanceof FeatureNodeContainer
){
161 text
= ((FeatureNodeContainer
)element
).getFeature().getTitleCache();
167 /** Function dertmining which vocabulary is the term part of
170 * @param vocabularyExpected
173 private boolean GetVocabularyType(DefinedTerm term
, String vocabularyExpected
) {
174 if ((term
.getPartOf() != null) && (term
.getPartOf().getTitleCache().equals(vocabularyExpected
))) {
177 else if ((term
.getVocabulary() != null) && (term
.getPartOf() == null) && (term
.getVocabulary().getTitleCache().equals(vocabularyExpected
))) {
180 else if ((vocabularyExpected
.equals(UsageTermCollection
.ethnicGroupLabel
)) && ((term
.getPartOf() != null))) {
188 public StyledString
getStyledText(Object element
) {
189 return new StyledString(this.getText(element
),
190 StyledString
.QUALIFIER_STYLER
);