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