1
|
package eu.etaxonomy.taxeditor.ui.section.userecords;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.Iterator;
|
5
|
import java.util.List;
|
6
|
import java.util.ListIterator;
|
7
|
import java.util.Map;
|
8
|
import java.util.Set;
|
9
|
import org.apache.log4j.Logger;
|
10
|
import org.eclipse.swt.events.SelectionEvent;
|
11
|
import org.eclipse.swt.events.SelectionListener;
|
12
|
import eu.etaxonomy.cdm.model.common.Language;
|
13
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
14
|
import eu.etaxonomy.cdm.model.common.Marker;
|
15
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
16
|
import eu.etaxonomy.cdm.model.description.Modifier;
|
17
|
import eu.etaxonomy.cdm.model.description.State;
|
18
|
import eu.etaxonomy.cdm.model.description.StateData;
|
19
|
import eu.etaxonomy.taxeditor.editor.UsageTermCollection;
|
20
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
21
|
import eu.etaxonomy.taxeditor.store.TermStore;
|
22
|
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
25
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
26
|
|
27
|
|
28
|
/**
|
29
|
* The context manager mediates context start/stop and workbench shutdowns to all registered listeners.
|
30
|
*
|
31
|
* @author a.theys
|
32
|
* @created mar 13, 2012
|
33
|
* @version 1.0
|
34
|
*/
|
35
|
public class UseRecordDetailElement extends
|
36
|
AbstractCdmDetailElement<CategoricalData> implements SelectionListener {
|
37
|
|
38
|
private static final Logger logger = Logger
|
39
|
.getLogger(UseRecordDetailElement.class);
|
40
|
|
41
|
private TermComboElement<State> combo_UseCategory;
|
42
|
private TermComboElement<State> combo_UseSubCategory;
|
43
|
private TermComboElement<Modifier> combo_PlantPart;
|
44
|
private TermComboElement<Modifier> combo_Country;
|
45
|
private TermComboElement<Modifier> combo_HumanGroup;
|
46
|
private TermComboElement<Modifier> combo_EthnicGroup;
|
47
|
|
48
|
public UseRecordDetailElement(CdmFormFactory formFactory,
|
49
|
ICdmFormElement formElement) {
|
50
|
super(formFactory, formElement);
|
51
|
}
|
52
|
|
53
|
/** {@inheritDoc} */
|
54
|
@Override
|
55
|
protected void createControls(ICdmFormElement formElement,
|
56
|
CategoricalData entity, int style) {
|
57
|
|
58
|
combo_UseCategory = formFactory.createTermComboElement(State.class, this, UsageTermCollection.useCategoryVocabularyLabel, null, style);
|
59
|
combo_UseCategory.addSelectionListener(this);
|
60
|
combo_UseSubCategory = formFactory.createTermComboElement(State.class, this, UsageTermCollection.useSubCategoryVocabularyLabel, null, style);
|
61
|
combo_PlantPart = formFactory.createTermComboElement(Modifier.class, this, UsageTermCollection.plantPartLabel, null, style);
|
62
|
combo_HumanGroup = formFactory.createTermComboElement(Modifier.class, this, UsageTermCollection.humanGroupLabel, null, style);
|
63
|
combo_HumanGroup.addSelectionListener(this);
|
64
|
combo_EthnicGroup = formFactory.createTermComboElement(Modifier.class, this, UsageTermCollection.ethnicGroupLabel, null, style);
|
65
|
combo_Country = formFactory.createTermComboElement(Modifier.class, this, UsageTermCollection.countryLabel, null, style);
|
66
|
|
67
|
|
68
|
List<State> termsUseCategory = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false));
|
69
|
combo_UseCategory.setTerms(termsUseCategory);
|
70
|
combo_UseCategory.setSelection(stateSelection(UsageTermCollection.useCategoryVocabularyLabel));
|
71
|
|
72
|
List<State> termsSubCategory = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false), combo_UseCategory.getSelection());
|
73
|
|
74
|
if (termsSubCategory != null) {
|
75
|
combo_UseSubCategory.setTerms(termsSubCategory);
|
76
|
combo_UseSubCategory.setSelection(stateSelection(UsageTermCollection.useSubCategoryVocabularyLabel));
|
77
|
combo_UseSubCategory.setEnabled(true);
|
78
|
}
|
79
|
else {
|
80
|
combo_UseSubCategory.setEnabled(false);
|
81
|
}
|
82
|
|
83
|
List<Modifier> plantPartsToAdd = setModifierComboTerms(TermStore.getTerms(Modifier.class, null, false), UsageTermCollection.plantPartLabel);
|
84
|
combo_PlantPart.setTerms(plantPartsToAdd);
|
85
|
combo_PlantPart.setSelection(modifierSelection(UsageTermCollection.plantPartLabel));
|
86
|
|
87
|
List<Modifier> countriesToAdd = setModifierComboTerms(TermStore.getTerms(Modifier.class, null, false), UsageTermCollection.countryLabel);
|
88
|
combo_Country.setTerms(countriesToAdd);
|
89
|
combo_Country.setSelection(modifierSelection(UsageTermCollection.countryLabel));
|
90
|
|
91
|
List<Modifier> humanGroupToAdd = setModifierComboTerms(TermStore.getTerms(Modifier.class, null, false), UsageTermCollection.humanGroupLabel);
|
92
|
combo_HumanGroup.setTerms(humanGroupToAdd);
|
93
|
combo_HumanGroup.setSelection(modifierSelection(UsageTermCollection.humanGroupLabel));
|
94
|
|
95
|
List<Modifier> ethnicGroupToAdd = setEthnicGroupComboTerms(TermStore.getTerms(Modifier.class, null, false), combo_HumanGroup.getSelection());
|
96
|
if (ethnicGroupToAdd != null) {
|
97
|
combo_EthnicGroup.setTerms(ethnicGroupToAdd);
|
98
|
combo_EthnicGroup.setSelection(modifierSelection(UsageTermCollection.ethnicGroupLabel));
|
99
|
combo_EthnicGroup.setEnabled(true);
|
100
|
} else {
|
101
|
combo_EthnicGroup.setEnabled(false);
|
102
|
}
|
103
|
|
104
|
}
|
105
|
|
106
|
private Modifier modifierSelection(String comboCategory) {
|
107
|
if(!getEntity().getModifiers().isEmpty()) {
|
108
|
for (Modifier modifier : getEntity().getModifiers()) {
|
109
|
if(GetVocabularyType(modifier, comboCategory)) {
|
110
|
return modifier;
|
111
|
}
|
112
|
}
|
113
|
} else {
|
114
|
return null;
|
115
|
}
|
116
|
return null;
|
117
|
|
118
|
}
|
119
|
|
120
|
private State stateSelection(String comboCategory) {
|
121
|
if (!getEntity().getStates().isEmpty()) {
|
122
|
for (StateData statedata : getEntity().getStates()) {
|
123
|
if (statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
|
124
|
String testString = statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText();
|
125
|
if(testString.equals(comboCategory)) {
|
126
|
if(statedata.getState() !=null) {
|
127
|
return statedata.getState();
|
128
|
}
|
129
|
}
|
130
|
}
|
131
|
}
|
132
|
}
|
133
|
else {
|
134
|
return null;
|
135
|
}
|
136
|
return null;
|
137
|
|
138
|
}
|
139
|
|
140
|
private List<Modifier> setModifierComboTerms(List<Modifier> listOfTerms, String modType) {
|
141
|
List<Modifier> termsToAdd = new ArrayList<Modifier>();
|
142
|
for (Modifier term : listOfTerms) {
|
143
|
|
144
|
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(modType))) {
|
145
|
termsToAdd.add(term);
|
146
|
}
|
147
|
else if ((term.getVocabulary() != null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals(modType))) {
|
148
|
termsToAdd.add(term);
|
149
|
}
|
150
|
}
|
151
|
|
152
|
return termsToAdd;
|
153
|
}
|
154
|
|
155
|
|
156
|
|
157
|
private List<State> setUseCategoryComboTerms(List<State> listOfTerms) {
|
158
|
List<State> termsToAdd = new ArrayList<State>();
|
159
|
for (State term : listOfTerms) {
|
160
|
|
161
|
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(UsageTermCollection.useCategoryVocabularyLabel))) {
|
162
|
termsToAdd.add(term);
|
163
|
}
|
164
|
else if ((term.getVocabulary() !=null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals(UsageTermCollection.useCategoryVocabularyLabel))) {
|
165
|
termsToAdd.add(term);
|
166
|
}
|
167
|
}
|
168
|
return termsToAdd;
|
169
|
|
170
|
}
|
171
|
|
172
|
private List<State> setUseCategoryComboTerms(List<State> listOfTerms,
|
173
|
State selectedUseCategory) {
|
174
|
List<State> termsToAdd = new ArrayList<State>();
|
175
|
if (combo_UseCategory.getSelection() != null) {
|
176
|
|
177
|
for (State term : listOfTerms) {
|
178
|
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(selectedUseCategory.getTitleCache()))) {
|
179
|
termsToAdd.add(term);
|
180
|
}
|
181
|
else if ((term.getVocabulary() !=null) && (term.getVocabulary().getTitleCache().equals(selectedUseCategory.getTitleCache()))) {
|
182
|
termsToAdd.add(term);
|
183
|
}
|
184
|
|
185
|
}
|
186
|
}
|
187
|
else if (!getEntity().getStates().isEmpty()) {
|
188
|
for (StateData stateData : getEntity().getStates()) {
|
189
|
if (stateData.getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
|
190
|
if ((stateData.getState() != null) && (stateData.getModifyingText().get(CdmStore.getDefaultLanguage()).getText() == UsageTermCollection.useCategoryVocabularyLabel)) {
|
191
|
for (State term : listOfTerms) {
|
192
|
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(stateData.getState().getTitleCache()))) {
|
193
|
termsToAdd.add(term);
|
194
|
} else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(stateData.getState().getTitleCache()))) {
|
195
|
termsToAdd.add(term);
|
196
|
}
|
197
|
}
|
198
|
|
199
|
}
|
200
|
}
|
201
|
}
|
202
|
|
203
|
}
|
204
|
|
205
|
else {
|
206
|
return null;
|
207
|
}
|
208
|
|
209
|
return termsToAdd;
|
210
|
}
|
211
|
|
212
|
private List<Modifier> setEthnicGroupComboTerms(List<Modifier> listOfTerms,
|
213
|
Modifier selectedHumangroup) {
|
214
|
List<Modifier> termsToAdd = new ArrayList<Modifier>();
|
215
|
if (combo_HumanGroup.getSelection() != null) {
|
216
|
for (Modifier term : listOfTerms) {
|
217
|
|
218
|
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(selectedHumangroup.getTitleCache()))) {
|
219
|
termsToAdd.add(term);
|
220
|
}
|
221
|
else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(selectedHumangroup.getTitleCache()))) {
|
222
|
termsToAdd.add(term);
|
223
|
}
|
224
|
}
|
225
|
}
|
226
|
else if (!getEntity().getModifiers().isEmpty()) {
|
227
|
for (Modifier modifier : getEntity().getModifiers()) {
|
228
|
if (modifier.getMarkers() != null) {
|
229
|
for (Marker marker : modifier.getMarkers()) {
|
230
|
if(marker.getMarkerType().getTitleCache().equals(UsageTermCollection.humanGroupLabel)) {
|
231
|
for (Modifier term : listOfTerms) {
|
232
|
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(modifier.getTitleCache()))) {
|
233
|
termsToAdd.add(modifier);
|
234
|
} else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(modifier.getTitleCache()))) {
|
235
|
termsToAdd.add(modifier);
|
236
|
}
|
237
|
}
|
238
|
|
239
|
}
|
240
|
}
|
241
|
}
|
242
|
}
|
243
|
} else {
|
244
|
return null;
|
245
|
}
|
246
|
|
247
|
return termsToAdd;
|
248
|
}
|
249
|
|
250
|
/** {@inheritDoc} */
|
251
|
@Override
|
252
|
public void handleEvent(Object eventSource) {
|
253
|
if (eventSource == combo_UseCategory) {
|
254
|
if (combo_UseCategory.getSelection() != null) {
|
255
|
boolean isChanged = false;
|
256
|
boolean isUseCategoryChanged = false;
|
257
|
if (!getEntity().getStates().isEmpty()) {
|
258
|
for (StateData useCategoryStateDataCheck : getEntity().getStates()) {
|
259
|
Map<Language, LanguageString> modText = useCategoryStateDataCheck.getModifyingText();
|
260
|
if(modText.get(CdmStore.getDefaultLanguage()) != null && modText.get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useCategoryVocabularyLabel)) {
|
261
|
if(!useCategoryStateDataCheck.getState().getTitleCache().equals(combo_UseCategory.getSelection().getTitleCache())) {
|
262
|
isUseCategoryChanged = true;
|
263
|
}
|
264
|
|
265
|
}
|
266
|
}
|
267
|
ListIterator<StateData> itrExistingStates = getEntity().getStates().listIterator();
|
268
|
while(itrExistingStates.hasNext()) {
|
269
|
StateData existingStateData = itrExistingStates.next();
|
270
|
Map<Language, LanguageString> modifyingText = existingStateData
|
271
|
.getModifyingText();
|
272
|
if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
|
273
|
if (modifyingText.get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useCategoryVocabularyLabel)) {
|
274
|
isChanged = true;
|
275
|
if(!existingStateData.getState().getTitleCache().equals(combo_UseCategory.getSelection().getTitleCache())) {
|
276
|
itrExistingStates.remove();
|
277
|
StateData stateData = StateData.NewInstance(combo_UseCategory.getSelection());
|
278
|
stateData.setState(combo_UseCategory.getSelection());
|
279
|
stateData.putModifyingText(CdmStore.getDefaultLanguage(),UsageTermCollection.useCategoryVocabularyLabel);
|
280
|
itrExistingStates.add(stateData);
|
281
|
|
282
|
}
|
283
|
} else if (modifyingText.get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useSubCategoryVocabularyLabel) && isUseCategoryChanged == true) {
|
284
|
itrExistingStates.remove();
|
285
|
}
|
286
|
}
|
287
|
}
|
288
|
}
|
289
|
|
290
|
|
291
|
if (isChanged == false) {
|
292
|
StateData stateData = StateData
|
293
|
.NewInstance(combo_UseCategory.getSelection());
|
294
|
stateData.setState(combo_UseCategory.getSelection());
|
295
|
stateData.putModifyingText(CdmStore.getDefaultLanguage(), UsageTermCollection.useCategoryVocabularyLabel);
|
296
|
getEntity().addState(stateData);
|
297
|
}
|
298
|
|
299
|
combo_UseSubCategory.setEnabled(true);
|
300
|
|
301
|
}
|
302
|
else {
|
303
|
if (!getEntity().getStates().isEmpty()) {
|
304
|
Iterator<StateData> itr = getEntity().getStates().iterator();
|
305
|
while(itr.hasNext()) {
|
306
|
StateData stateToRemove = itr.next();
|
307
|
itr.remove();
|
308
|
}
|
309
|
List<State> termsSubCategory = new ArrayList<State>();
|
310
|
State emptyState = State.NewInstance();
|
311
|
termsSubCategory.add(emptyState);
|
312
|
combo_UseSubCategory.setTerms(termsSubCategory);
|
313
|
combo_UseSubCategory.setEnabled(false);
|
314
|
}
|
315
|
}
|
316
|
}
|
317
|
|
318
|
if (eventSource == combo_UseSubCategory) {
|
319
|
if (combo_UseSubCategory.getSelection() != null) {
|
320
|
boolean isChanged = false;
|
321
|
if (!getEntity().getStates().isEmpty()) {
|
322
|
ListIterator<StateData> itrExistingStates = getEntity().getStates().listIterator();
|
323
|
while(itrExistingStates.hasNext()) {
|
324
|
StateData existingStateData = itrExistingStates.next();
|
325
|
Map<Language, LanguageString> modifyingText = existingStateData
|
326
|
.getModifyingText();
|
327
|
if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
|
328
|
if (modifyingText.get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useSubCategoryVocabularyLabel)) {
|
329
|
isChanged = true;
|
330
|
if(!existingStateData.getState().getTitleCache().equals(combo_UseSubCategory.getSelection().getTitleCache())) {
|
331
|
itrExistingStates.remove();
|
332
|
StateData stateData = StateData.NewInstance(combo_UseSubCategory.getSelection());
|
333
|
stateData.setState(combo_UseSubCategory.getSelection());
|
334
|
stateData.putModifyingText(CdmStore.getDefaultLanguage(),UsageTermCollection.useSubCategoryVocabularyLabel);
|
335
|
itrExistingStates.add(stateData);
|
336
|
}
|
337
|
}
|
338
|
}
|
339
|
}
|
340
|
}
|
341
|
|
342
|
if (isChanged == false){
|
343
|
StateData stateData = StateData
|
344
|
.NewInstance(combo_UseSubCategory.getSelection());
|
345
|
stateData.setState(combo_UseSubCategory.getSelection());
|
346
|
stateData.putModifyingText(CdmStore.getDefaultLanguage(), UsageTermCollection.useSubCategoryVocabularyLabel);
|
347
|
getEntity().addState(stateData);
|
348
|
}
|
349
|
|
350
|
} else {
|
351
|
if (!getEntity().getStates().isEmpty()) {
|
352
|
Iterator<StateData> itrStateData = getEntity().getStates().iterator();
|
353
|
while(itrStateData.hasNext()) {
|
354
|
StateData existingStateData = itrStateData.next();
|
355
|
Map<Language, LanguageString> modifyingText = existingStateData
|
356
|
.getModifyingText();
|
357
|
|
358
|
if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
|
359
|
if (modifyingText.get(CdmStore.getDefaultLanguage()).getText() == UsageTermCollection.useSubCategoryVocabularyLabel) {
|
360
|
itrStateData.remove();
|
361
|
}
|
362
|
}
|
363
|
}
|
364
|
}
|
365
|
}
|
366
|
}
|
367
|
if (eventSource == combo_PlantPart) {
|
368
|
if (combo_PlantPart.getSelection() != null) {
|
369
|
Iterator<Modifier> itrExistingModifiers = getEntity().getModifiers().iterator();
|
370
|
while (itrExistingModifiers.hasNext()) {
|
371
|
Modifier modifier = itrExistingModifiers.next();
|
372
|
if(GetVocabularyType(modifier, UsageTermCollection.plantPartLabel)) {
|
373
|
itrExistingModifiers.remove();
|
374
|
}
|
375
|
|
376
|
}
|
377
|
Modifier plantPart = combo_PlantPart.getSelection();
|
378
|
getEntity().addModifier(plantPart);
|
379
|
} else {
|
380
|
Set<Modifier> modifiers = getEntity().getModifiers();
|
381
|
if(!modifiers.isEmpty()) {
|
382
|
Iterator<Modifier> itr = modifiers.iterator();
|
383
|
while (itr.hasNext()) {
|
384
|
Modifier currentMod = itr.next();
|
385
|
if(GetVocabularyType(currentMod, UsageTermCollection.plantPartLabel)) {
|
386
|
itr.remove();
|
387
|
}
|
388
|
}
|
389
|
}
|
390
|
|
391
|
}
|
392
|
}
|
393
|
if (eventSource == combo_Country) {
|
394
|
if (combo_Country.getSelection() != null) {
|
395
|
Iterator<Modifier> itrExistingModifiers = getEntity().getModifiers().iterator();
|
396
|
while (itrExistingModifiers.hasNext()) {
|
397
|
Modifier modifier = itrExistingModifiers.next();
|
398
|
if(GetVocabularyType(modifier, UsageTermCollection.countryLabel)) {
|
399
|
itrExistingModifiers.remove();
|
400
|
}
|
401
|
|
402
|
}
|
403
|
Modifier country = combo_Country.getSelection();
|
404
|
getEntity().addModifier(country);
|
405
|
} else {
|
406
|
Set<Modifier> modifiers = getEntity().getModifiers();
|
407
|
if(!modifiers.isEmpty()) {
|
408
|
Iterator<Modifier> itr = modifiers.iterator();
|
409
|
while (itr.hasNext()) {
|
410
|
Modifier currentMod = itr.next();
|
411
|
if(GetVocabularyType(currentMod, UsageTermCollection.countryLabel)) {
|
412
|
itr.remove();
|
413
|
}
|
414
|
}
|
415
|
}
|
416
|
}
|
417
|
}
|
418
|
if (eventSource == combo_HumanGroup) {
|
419
|
if (combo_HumanGroup.getSelection() != null) {
|
420
|
boolean isHumanGroupChanged = true;
|
421
|
for (Modifier modToCheck: getEntity().getModifiers()) {
|
422
|
if(modToCheck.equals(combo_HumanGroup.getSelection()) && (GetVocabularyType(modToCheck, UsageTermCollection.humanGroupLabel))) {
|
423
|
isHumanGroupChanged = false;
|
424
|
}
|
425
|
|
426
|
|
427
|
}
|
428
|
Iterator<Modifier> itrExistingModifiers = getEntity().getModifiers().iterator();
|
429
|
while (itrExistingModifiers.hasNext()) {
|
430
|
Modifier modifier = itrExistingModifiers.next();
|
431
|
if((GetVocabularyType(modifier, UsageTermCollection.humanGroupLabel) || GetVocabularyType(modifier, UsageTermCollection.ethnicGroupLabel)) && isHumanGroupChanged) {
|
432
|
itrExistingModifiers.remove();
|
433
|
}
|
434
|
|
435
|
}
|
436
|
if(isHumanGroupChanged){
|
437
|
Modifier humanGroup = combo_HumanGroup.getSelection();
|
438
|
getEntity().addModifier(humanGroup);
|
439
|
}
|
440
|
combo_EthnicGroup.setEnabled(true);
|
441
|
} else {
|
442
|
Set<Modifier> modifiers = getEntity().getModifiers();
|
443
|
if(!modifiers.isEmpty()) {
|
444
|
Iterator<Modifier> itr = modifiers.iterator();
|
445
|
while (itr.hasNext()) {
|
446
|
Modifier currentMod = itr.next();
|
447
|
if(GetVocabularyType(currentMod, UsageTermCollection.humanGroupLabel) || GetVocabularyType(currentMod, UsageTermCollection.ethnicGroupLabel)) {
|
448
|
itr.remove();
|
449
|
}
|
450
|
}
|
451
|
}
|
452
|
List<Modifier> emptyListToResetComboBox = new ArrayList<Modifier>();
|
453
|
Modifier emptyMod = Modifier.NewInstance();
|
454
|
emptyListToResetComboBox.add(emptyMod);
|
455
|
combo_EthnicGroup.setTerms(emptyListToResetComboBox);
|
456
|
combo_EthnicGroup.setEnabled(false);
|
457
|
|
458
|
}
|
459
|
}
|
460
|
if (eventSource == combo_EthnicGroup) {
|
461
|
if (combo_EthnicGroup.getSelection() != null) {
|
462
|
Iterator<Modifier> itrExistingModifiers = getEntity().getModifiers().iterator();
|
463
|
while (itrExistingModifiers.hasNext()) {
|
464
|
Modifier modifier = itrExistingModifiers.next();
|
465
|
if(GetVocabularyType(modifier, combo_HumanGroup.getSelection().getTitleCache())) {
|
466
|
itrExistingModifiers.remove();
|
467
|
}
|
468
|
|
469
|
}
|
470
|
Modifier ethnicGroup = combo_EthnicGroup.getSelection();
|
471
|
getEntity().addModifier(ethnicGroup);
|
472
|
} else {
|
473
|
Set<Modifier> modifiers = getEntity().getModifiers();
|
474
|
if(!modifiers.isEmpty()) {
|
475
|
|
476
|
Iterator<Modifier> itr = modifiers.iterator();
|
477
|
while (itr.hasNext()) {
|
478
|
Modifier currentMod = itr.next();
|
479
|
if(GetVocabularyType(currentMod, UsageTermCollection.ethnicGroupLabel)) {
|
480
|
itr.remove();
|
481
|
}
|
482
|
}
|
483
|
|
484
|
}
|
485
|
}
|
486
|
}
|
487
|
}
|
488
|
|
489
|
|
490
|
|
491
|
private boolean GetVocabularyType(Modifier term, String vocabularyExpected) {
|
492
|
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(vocabularyExpected))) {
|
493
|
return true;
|
494
|
}
|
495
|
else if ((term.getVocabulary() != null) && (term.getPartOf()==null) && (term.getVocabulary().getTitleCache().equals(vocabularyExpected))) {
|
496
|
return true;
|
497
|
}
|
498
|
else if ((vocabularyExpected.equals(UsageTermCollection.ethnicGroupLabel)) && (term.getVocabulary() == null) && ((term.getPartOf() != null))) {
|
499
|
return true;
|
500
|
}
|
501
|
return false;
|
502
|
}
|
503
|
|
504
|
|
505
|
|
506
|
/** {@inheritDoc} */
|
507
|
@Override
|
508
|
public void setEntity(CategoricalData entity) {
|
509
|
super.setEntity(entity);
|
510
|
}
|
511
|
|
512
|
@Override
|
513
|
public void widgetSelected(SelectionEvent e) {
|
514
|
Object eventSource = e.getSource();
|
515
|
for (Object object: combo_UseCategory.getControls()) {
|
516
|
if (object == eventSource) {
|
517
|
State selectedUseCategory = combo_UseCategory.getSelection();
|
518
|
if (selectedUseCategory != null) {
|
519
|
combo_UseSubCategory.setTerms(setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false),selectedUseCategory));
|
520
|
|
521
|
if (!getEntity().getStates().isEmpty()) {
|
522
|
Iterator<StateData> itrExistingState = getEntity().getStates().iterator();
|
523
|
while(itrExistingState.hasNext()) {
|
524
|
StateData existingStateData = (StateData) itrExistingState.next();
|
525
|
Map<Language, LanguageString> modifyingText = existingStateData.getModifyingText();
|
526
|
if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
|
527
|
if (modifyingText.get(CdmStore.getDefaultLanguage())
|
528
|
.getText().equals(UsageTermCollection.useSubCategoryVocabularyLabel)) {
|
529
|
combo_UseSubCategory.setSelection(stateSelection(UsageTermCollection.useSubCategoryVocabularyLabel));
|
530
|
}
|
531
|
}
|
532
|
}
|
533
|
}
|
534
|
}
|
535
|
}
|
536
|
}
|
537
|
for (Object object: combo_HumanGroup.getControls()) {
|
538
|
if (object == eventSource) {
|
539
|
Modifier selectedHumanGroup = combo_HumanGroup.getSelection();
|
540
|
if (selectedHumanGroup != null) {
|
541
|
combo_EthnicGroup.setTerms(setEthnicGroupComboTerms(TermStore.getTerms(Modifier.class, null, false), selectedHumanGroup));
|
542
|
if (!getEntity().getModifiers().isEmpty()) {
|
543
|
Iterator<Modifier> iterModifiers = getEntity().getModifiers().iterator();
|
544
|
while (iterModifiers.hasNext()) {
|
545
|
Modifier existingModifier = iterModifiers.next();
|
546
|
if(GetVocabularyType(existingModifier, UsageTermCollection.ethnicGroupLabel)) {
|
547
|
combo_EthnicGroup.setSelection(modifierSelection(UsageTermCollection.ethnicGroupLabel));
|
548
|
}
|
549
|
}
|
550
|
}
|
551
|
|
552
|
}
|
553
|
}
|
554
|
}
|
555
|
}
|
556
|
|
557
|
@Override
|
558
|
public void widgetDefaultSelected(SelectionEvent e) {
|
559
|
// TODO Auto-generated method stub
|
560
|
|
561
|
}
|
562
|
|
563
|
}
|