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.
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
.Language
;
19 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
20 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
21 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
22 import eu
.etaxonomy
.cdm
.model
.description
.Modifier
;
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
;
29 * UsesLabelProvider Class
31 * @created mar 13, 2012
34 public class UsesLabelProvider
extends ColumnLabelProvider
implements
35 IStyledLabelProvider
{
38 public String
getText(Object element
) {
41 if (element
instanceof DescriptionBase
) {
42 text
= ((DescriptionBase
) element
).getTitleCache();
43 if (text
== null || text
.length() == 0) {
44 text
= "Use: No label provided";
47 text
= "Use: " + text
;
50 else if (element
instanceof CategoricalData
) {
51 if (!((CategoricalData
) element
).getStates().isEmpty()) {
52 for (StateData statedata
: ((CategoricalData
) element
).getStates()) {
53 if(statedata
.getState() != null && statedata
.getModifyingText().get(CdmStore
.getDefaultLanguage()) !=null && statedata
.getModifyingText().get(CdmStore
.getDefaultLanguage()).getText().equals("Use Category")) {
54 text
= text
+ statedata
.getState().getTitleCache() + ";";
57 for (StateData statedata
: ((CategoricalData
) element
).getStates()) {
58 if(statedata
.getState() != null && statedata
.getModifyingText().get(CdmStore
.getDefaultLanguage()) !=null && statedata
.getModifyingText().get(CdmStore
.getDefaultLanguage()).getText().equals("Use SubCategory")) {
59 text
= text
+ statedata
.getState().getTitleCache() + ";";
63 if (!((CategoricalData
) element
).getModifiers().isEmpty()) {
64 for (Modifier modifier
: ((CategoricalData
) element
).getModifiers()){
66 modifier
.getVocabulary();
68 for (Modifier modifier
: ((CategoricalData
) element
).getModifiers()){
69 if(GetVocabularyType(modifier
, "Plant Part")) {
70 text
= text
+ modifier
.getTitleCache()+ ";";
74 for (Modifier modifier
: ((CategoricalData
) element
).getModifiers()){
75 if(GetVocabularyType(modifier
, "Human Group")) {
76 text
= text
+ modifier
.getTitleCache()+ ";";
80 for (Modifier modifier
: ((CategoricalData
) element
).getModifiers()){
81 if(GetVocabularyType(modifier
, "Ethnic Group")) {
82 text
= text
+ modifier
.getTitleCache()+ ";";
86 for (Modifier modifier
: ((CategoricalData
) element
).getModifiers()){
87 if(GetVocabularyType(modifier
, "Country")) {
88 text
= text
+ modifier
.getTitleCache()+ ";";
94 if (text
== null || text
.length() == 0) {
95 text
= "No data provided";
98 ((CategoricalData
)element
).putModifyingText(CdmStore
.getDefaultLanguage(), text
);
103 else if (element
instanceof TextData
) {
104 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
105 LanguageString languageString
= ((TextData
) element
).getPreferredLanguageString(languages
);
106 text
= languageString
!= null ? languageString
.getText() : null;
107 if (text
== null || text
.length() == 0) {
108 text
= "No data provided";
112 else if (element
instanceof FeatureNodeContainer
){
113 text
= ((FeatureNodeContainer
)element
).getFeature().getTitleCache();
119 /** Function dertmining which vocabulary is the term part of
122 * @param vocabularyExpected
125 private boolean GetVocabularyType(Modifier term
, String vocabularyExpected
) {
126 if ((term
.getPartOf() != null) && (term
.getPartOf().getTitleCache().equals(vocabularyExpected
))) {
129 else if ((term
.getVocabulary() != null) && (term
.getPartOf() == null) && (term
.getVocabulary().getTitleCache().equals(vocabularyExpected
))) {
132 else if ((vocabularyExpected
.equals("Ethnic Group")) && (term
.getVocabulary() != null) && ((term
.getPartOf() != null))) {
140 public StyledString
getStyledText(Object element
) {
141 return new StyledString(this.getText(element
),
142 StyledString
.QUALIFIER_STYLER
);