1 package eu
.etaxonomy
.taxeditor
.editor
.view
.uses
;
3 import java
.util
.Arrays
;
7 import javax
.swing
.text
.html
.HTMLDocument
.HTMLReader
.IsindexAction
;
9 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
10 import org
.eclipse
.jface
.viewers
.DelegatingStyledCellLabelProvider
.IStyledLabelProvider
;
11 import org
.eclipse
.jface
.viewers
.StyledString
;
13 import eu
.etaxonomy
.cdm
.api
.service
.DefaultCategoricalDescriptionBuilder
;
14 import eu
.etaxonomy
.cdm
.api
.service
.DescriptionBuilder
;
15 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
16 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
17 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
18 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
19 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
20 import eu
.etaxonomy
.cdm
.model
.description
.Modifier
;
21 import eu
.etaxonomy
.cdm
.model
.description
.State
;
22 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
23 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
24 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 public class UsesLabelProvider
extends ColumnLabelProvider
implements
27 IStyledLabelProvider
{
29 private static DescriptionBuilder
<CategoricalData
> categoricalDescriptionBuilder
= new DefaultCategoricalDescriptionBuilder();
30 public String
getText(Object element
) {
33 * return DescriptionHelper.getLabel(element);
35 * for (Marker marker : element.getMarkers()) { if
36 * (marker.getMarkerType().getTitleCache().equals("use")) { return
39 if (element
instanceof DescriptionBase
) {
40 text
= ((DescriptionBase
) element
).getTitleCache();
41 if (text
== null || text
.length() == 0) {
42 text
= "Use: No label provided";
45 text
= "Use: " + text
;
48 else if (element
instanceof CategoricalData
) {
50 //TextData textData = categoricalDescriptionBuilder.build((CategoricalData) element, getLanguageList());
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
, "Country")) {
70 text
= text
+ modifier
.getTitleCache()+ "; ";
74 for (Modifier modifier
: ((CategoricalData
) element
).getModifiers()){
75 if(GetVocabularyType(modifier
, "Plant Part")) {
76 text
= text
+ modifier
.getTitleCache()+ "; ";
80 for (Modifier modifier
: ((CategoricalData
) element
).getModifiers()){
81 if(GetVocabularyType(modifier
, "Human Group")) {
82 text
= text
+ modifier
.getTitleCache()+ "; ";
86 for (Modifier modifier
: ((CategoricalData
) element
).getModifiers()){
87 if(GetVocabularyType(modifier
, "Ethnic Group")) {
88 text
= text
+ modifier
.getTitleCache()+ "; ";
94 if (text
== null || text
.length() == 0) {
95 text
= "No data provided";
98 ((CategoricalData
)element
).putModifyingText(CdmStore
.getDefaultLanguage(), text
);
111 private boolean GetVocabularyType(Modifier term
, String vocabularyExpected
) {
112 if ((term
.getPartOf() != null) && (term
.getPartOf().getTitleCache().equals(vocabularyExpected
))) {
115 else if ((term
.getVocabulary() != null) && (term
.getPartOf() == null) && (term
.getVocabulary().getTitleCache().equals(vocabularyExpected
))) {
118 else if ((vocabularyExpected
.equals("Ethnic Group")) && (term
.getVocabulary() != null) && ((term
.getPartOf() != null))) {
124 public StyledString
getStyledText(Object element
) {
125 return new StyledString(this.getText(element
),
126 StyledString
.QUALIFIER_STYLER
);
129 private static List
<Language
> getLanguageList(){
130 return Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});