1
|
/**
|
2
|
* Copyright (C) 2011 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.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.model.FeatureNodeContainer;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
import eu.etaxonomy.taxeditor.store.UsageTermCollection;
|
28
|
|
29
|
/**
|
30
|
* UsesLabelProvider Class
|
31
|
* @author a.theys
|
32
|
* @created mar 13, 2012
|
33
|
* @version 1.0
|
34
|
*/
|
35
|
public class UsesLabelProvider extends ColumnLabelProvider implements
|
36
|
IStyledLabelProvider {
|
37
|
|
38
|
/** {@inheritDoc} */
|
39
|
public String getText(Object element) {
|
40
|
String text = "";
|
41
|
|
42
|
if (element instanceof DescriptionBase) {
|
43
|
text = ((DescriptionBase) element).getTitleCache();
|
44
|
if (text == null || text.length() == 0) {
|
45
|
text = "Use: No label provided";
|
46
|
}
|
47
|
else {
|
48
|
text = "Use: " + text;
|
49
|
}
|
50
|
}
|
51
|
else if (element instanceof CategoricalData) {
|
52
|
if (!((CategoricalData) element).getStateData().isEmpty()) {
|
53
|
boolean isUseCategoryAbsent = true;
|
54
|
for (StateData statedata : ((CategoricalData) element).getStateData()) {
|
55
|
if(statedata.getState() != null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) !=null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useCategoryVocabularyLabel)) {
|
56
|
text = text + statedata.getState().getTitleCache() + ";";
|
57
|
isUseCategoryAbsent = false;
|
58
|
}
|
59
|
}
|
60
|
if(isUseCategoryAbsent) {
|
61
|
text = text + UsageTermCollection.notAvailableLabel + ";";
|
62
|
}
|
63
|
|
64
|
boolean isUseSubCategoryAbsent = true;
|
65
|
for (StateData statedata : ((CategoricalData) element).getStateData()) {
|
66
|
if(statedata.getState() != null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) !=null && statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useSubCategoryVocabularyLabel)) {
|
67
|
text = text + statedata.getState().getTitleCache() + ";";
|
68
|
isUseSubCategoryAbsent = false;
|
69
|
}
|
70
|
}
|
71
|
if(isUseSubCategoryAbsent) {
|
72
|
text = text + UsageTermCollection.notAvailableLabel + ";";
|
73
|
}
|
74
|
}
|
75
|
else {
|
76
|
text = text + UsageTermCollection.notAvailableLabel + ";" + UsageTermCollection.notAvailableLabel + ";";
|
77
|
}
|
78
|
if (!((CategoricalData) element).getModifiers().isEmpty()) {
|
79
|
for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){
|
80
|
modifier.getPartOf();
|
81
|
modifier.getVocabulary();
|
82
|
}
|
83
|
|
84
|
boolean isPlantPartAbsent = true;
|
85
|
for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){
|
86
|
if(GetVocabularyType(modifier, UsageTermCollection.plantPartLabel)) {
|
87
|
text = text + modifier.getTitleCache()+ ";";
|
88
|
isPlantPartAbsent = false;
|
89
|
}
|
90
|
|
91
|
}
|
92
|
if (isPlantPartAbsent) {
|
93
|
text = text + UsageTermCollection.notAvailableLabel + ";";
|
94
|
}
|
95
|
|
96
|
boolean isHumanGroupAbsent = true;
|
97
|
for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){
|
98
|
if(GetVocabularyType(modifier, UsageTermCollection.humanGroupLabel)) {
|
99
|
text = text + modifier.getTitleCache()+ ";";
|
100
|
isHumanGroupAbsent = false;
|
101
|
}
|
102
|
}
|
103
|
if (isHumanGroupAbsent) {
|
104
|
text = text + UsageTermCollection.notAvailableLabel + ";";
|
105
|
}
|
106
|
|
107
|
boolean isEthnicGroupAbsent = true;
|
108
|
for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){
|
109
|
if(GetVocabularyType(modifier, UsageTermCollection.ethnicGroupLabel)) {
|
110
|
text = text + modifier.getTitleCache()+ ";";
|
111
|
isEthnicGroupAbsent = false;
|
112
|
}
|
113
|
}
|
114
|
if (isEthnicGroupAbsent) {
|
115
|
text = text + UsageTermCollection.notAvailableLabel + ";";
|
116
|
}
|
117
|
|
118
|
boolean isCountryAbsent = true;
|
119
|
for (DefinedTerm modifier: ((CategoricalData) element).getModifiers()){
|
120
|
if(GetVocabularyType(modifier, UsageTermCollection.countryLabel)) {
|
121
|
text = text + modifier.getTitleCache()+ ";";
|
122
|
isCountryAbsent = false;
|
123
|
}
|
124
|
}
|
125
|
if (isCountryAbsent) {
|
126
|
text = text + UsageTermCollection.notAvailableLabel + ";";
|
127
|
}
|
128
|
}
|
129
|
else {
|
130
|
text = text + UsageTermCollection.notAvailableLabel + ";" + UsageTermCollection.notAvailableLabel + ";" + UsageTermCollection.notAvailableLabel + ";" + UsageTermCollection.notAvailableLabel + ";";
|
131
|
}
|
132
|
|
133
|
if (text == null || text.length() == 0) {
|
134
|
text = "No data provided";
|
135
|
}
|
136
|
else {
|
137
|
String[] textElements = text.split(";");
|
138
|
String dataportalString = textElements[0] + ";" + textElements[1] + ";" + textElements[5] + ";" + textElements[2] + ";" + textElements[3] + ";" + textElements[4] + ";" ;
|
139
|
|
140
|
((CategoricalData)element).putModifyingText(CdmStore.getDefaultLanguage(), dataportalString);
|
141
|
}
|
142
|
return text;
|
143
|
}
|
144
|
|
145
|
else if (element instanceof TextData) {
|
146
|
List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
|
147
|
LanguageString languageString = ((TextData) element).getPreferredLanguageString(languages);
|
148
|
text = languageString != null ? languageString.getText() : null;
|
149
|
if (text == null || text.length() == 0) {
|
150
|
text = "No data provided";
|
151
|
}
|
152
|
}
|
153
|
|
154
|
else if (element instanceof FeatureNodeContainer){
|
155
|
text = ((FeatureNodeContainer)element).getFeature().getTitleCache();
|
156
|
}
|
157
|
|
158
|
return text;
|
159
|
}
|
160
|
|
161
|
/** Function dertmining which vocabulary is the term part of
|
162
|
*
|
163
|
* @param term
|
164
|
* @param vocabularyExpected
|
165
|
* @return
|
166
|
*/
|
167
|
private boolean GetVocabularyType(DefinedTerm term, String vocabularyExpected) {
|
168
|
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(vocabularyExpected))) {
|
169
|
return true;
|
170
|
}
|
171
|
else if ((term.getVocabulary() != null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals(vocabularyExpected))) {
|
172
|
return true;
|
173
|
}
|
174
|
else if ((vocabularyExpected.equals(UsageTermCollection.ethnicGroupLabel)) && ((term.getPartOf() != null))) {
|
175
|
return true;
|
176
|
}
|
177
|
return false;
|
178
|
}
|
179
|
|
180
|
/** {@inheritDoc} */
|
181
|
@Override
|
182
|
public StyledString getStyledText(Object element) {
|
183
|
return new StyledString(this.getText(element),
|
184
|
StyledString.QUALIFIER_STYLER);
|
185
|
}
|
186
|
|
187
|
|
188
|
|
189
|
}
|