85601542a46112d7b855eaf83f4e0edc12d5bca1
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / uses / UsesLabelProvider.java
1 package eu.etaxonomy.taxeditor.editor.view.uses;
2
3 import java.util.Arrays;
4 import java.util.List;
5 import java.util.Map;
6
7 import javax.swing.text.html.HTMLDocument.HTMLReader.IsindexAction;
8
9 import org.eclipse.jface.viewers.ColumnLabelProvider;
10 import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
11 import org.eclipse.jface.viewers.StyledString;
12
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;
25
26 public class UsesLabelProvider extends ColumnLabelProvider implements
27 IStyledLabelProvider {
28
29 private static DescriptionBuilder<CategoricalData> categoricalDescriptionBuilder = new DefaultCategoricalDescriptionBuilder();
30 public String getText(Object element) {
31 String text = "";
32 /*
33 * return DescriptionHelper.getLabel(element);
34 *
35 * for (Marker marker : element.getMarkers()) { if
36 * (marker.getMarkerType().getTitleCache().equals("use")) { return
37 * "Use: " + text; } }
38 */
39 if (element instanceof DescriptionBase) {
40 text = ((DescriptionBase) element).getTitleCache();
41 if (text == null || text.length() == 0) {
42 text = "Use: No label provided";
43 }
44 else {
45 text = "Use: " + text;
46 }
47 }
48 else if (element instanceof CategoricalData) {
49 //String text = "";
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() + "; ";
55 }
56 }
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() + "; ";
60 }
61 }
62 }
63 if (!((CategoricalData) element).getModifiers().isEmpty()) {
64 for (Modifier modifier: ((CategoricalData) element).getModifiers()){
65 modifier.getPartOf();
66 modifier.getVocabulary();
67 }
68 for (Modifier modifier: ((CategoricalData) element).getModifiers()){
69 if(GetVocabularyType(modifier, "Country")) {
70 text = text + modifier.getTitleCache()+ "; ";
71 }
72
73 }
74 for (Modifier modifier: ((CategoricalData) element).getModifiers()){
75 if(GetVocabularyType(modifier, "Plant Part")) {
76 text = text + modifier.getTitleCache()+ "; ";
77 }
78
79 }
80 for (Modifier modifier: ((CategoricalData) element).getModifiers()){
81 if(GetVocabularyType(modifier, "Human Group")) {
82 text = text + modifier.getTitleCache()+ "; ";
83 }
84
85 }
86 for (Modifier modifier: ((CategoricalData) element).getModifiers()){
87 if(GetVocabularyType(modifier, "Ethnic Group")) {
88 text = text + modifier.getTitleCache()+ "; ";
89 }
90
91 }
92 }
93
94 if (text == null || text.length() == 0) {
95 text = "No data provided";
96 }
97 else {
98 ((CategoricalData)element).putModifyingText(CdmStore.getDefaultLanguage(), text);
99 }
100 return text;
101 }
102
103 else{
104 text = "Use Record";
105 }
106
107 return text;
108 }
109
110
111 private boolean GetVocabularyType(Modifier term, String vocabularyExpected) {
112 if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(vocabularyExpected))) {
113 return true;
114 }
115 else if ((term.getVocabulary() != null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals(vocabularyExpected))) {
116 return true;
117 }
118 else if ((vocabularyExpected.equals("Ethnic Group")) && (term.getVocabulary() != null) && ((term.getPartOf() != null))) {
119 return true;
120 }
121 return false;
122 }
123 @Override
124 public StyledString getStyledText(Object element) {
125 return new StyledString(this.getText(element),
126 StyledString.QUALIFIER_STYLER);
127 }
128
129 private static List<Language> getLanguageList(){
130 return Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
131 }
132
133 }