AT: committing changes to the TaxEditor Post second round of code review
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / uses / UsesLabelProvider.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.editor.view.uses;
10
11 import java.util.Arrays;
12 import java.util.List;
13
14 import org.eclipse.jface.viewers.ColumnLabelProvider;
15 import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
16 import org.eclipse.jface.viewers.StyledString;
17
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;
27
28 /**
29 * UsesLabelProvider Class
30 * @author a.theys
31 * @created mar 13, 2012
32 * @version 1.0
33 */
34 public class UsesLabelProvider extends ColumnLabelProvider implements
35 IStyledLabelProvider {
36
37 /** {@inheritDoc} */
38 public String getText(Object element) {
39 String text = "";
40
41 if (element instanceof DescriptionBase) {
42 text = ((DescriptionBase) element).getTitleCache();
43 if (text == null || text.length() == 0) {
44 text = "Use: No label provided";
45 }
46 else {
47 text = "Use: " + text;
48 }
49 }
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() + ";";
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, "Plant Part")) {
70 text = text + modifier.getTitleCache()+ ";";
71 }
72
73 }
74 for (Modifier modifier: ((CategoricalData) element).getModifiers()){
75 if(GetVocabularyType(modifier, "Human Group")) {
76 text = text + modifier.getTitleCache()+ ";";
77 }
78
79 }
80 for (Modifier modifier: ((CategoricalData) element).getModifiers()){
81 if(GetVocabularyType(modifier, "Ethnic Group")) {
82 text = text + modifier.getTitleCache()+ ";";
83 }
84
85 }
86 for (Modifier modifier: ((CategoricalData) element).getModifiers()){
87 if(GetVocabularyType(modifier, "Country")) {
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 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";
109 }
110 }
111
112 else if (element instanceof FeatureNodeContainer){
113 text = ((FeatureNodeContainer)element).getFeature().getTitleCache();
114 }
115
116 return text;
117 }
118
119 /** Function dertmining which vocabulary is the term part of
120 *
121 * @param term
122 * @param vocabularyExpected
123 * @return
124 */
125 private boolean GetVocabularyType(Modifier term, String vocabularyExpected) {
126 if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(vocabularyExpected))) {
127 return true;
128 }
129 else if ((term.getVocabulary() != null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals(vocabularyExpected))) {
130 return true;
131 }
132 else if ((vocabularyExpected.equals("Ethnic Group")) && (term.getVocabulary() != null) && ((term.getPartOf() != null))) {
133 return true;
134 }
135 return false;
136 }
137
138 /** {@inheritDoc} */
139 @Override
140 public StyledString getStyledText(Object element) {
141 return new StyledString(this.getText(element),
142 StyledString.QUALIFIER_STYLER);
143 }
144
145
146
147 }