Project

General

Profile

Download (22.9 KB) Statistics
| Branch: | Tag: | Revision:
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.ui.section.userecords;
10

    
11
import java.util.ArrayList;
12
import java.util.Iterator;
13
import java.util.List;
14
import java.util.ListIterator;
15
import java.util.Map;
16
import java.util.Set;
17

    
18
import org.apache.log4j.Logger;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.events.SelectionListener;
21

    
22
import eu.etaxonomy.cdm.model.common.DefinedTerm;
23
import eu.etaxonomy.cdm.model.common.Language;
24
import eu.etaxonomy.cdm.model.common.LanguageString;
25
import eu.etaxonomy.cdm.model.common.Marker;
26
import eu.etaxonomy.cdm.model.common.TermType;
27
import eu.etaxonomy.cdm.model.description.CategoricalData;
28
import eu.etaxonomy.cdm.model.description.State;
29
import eu.etaxonomy.cdm.model.description.StateData;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31
import eu.etaxonomy.taxeditor.store.TermStore;
32
import eu.etaxonomy.taxeditor.store.UsageTermCollection;
33
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
34
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
35
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
36
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
37

    
38

    
39
/**
40
 * The context manager mediates context start/stop and workbench shutdowns to all registered listeners.
41
 *
42
 * @author a.theys
43
 * @created mar 13, 2012
44
 * @version 1.0
45
 */
46
public class UseRecordDetailElement extends
47
		AbstractCdmDetailElement<CategoricalData> implements SelectionListener {
48

    
49
	@SuppressWarnings("unused")
50
	private static final Logger logger = Logger.getLogger(UseRecordDetailElement.class);
51

    
52
	private TermComboElement<State> combo_UseCategory;
53
	private TermComboElement<State> combo_UseSubCategory;
54
	private TermComboElement<DefinedTerm> combo_PlantPart;
55
	private TermComboElement<DefinedTerm> combo_Country;
56
	private TermComboElement<DefinedTerm> combo_HumanGroup;
57
	private TermComboElement<DefinedTerm> combo_EthnicGroup;
58

    
59
	public UseRecordDetailElement(CdmFormFactory formFactory,
60
			ICdmFormElement formElement) {
61
		super(formFactory, formElement);
62
	}
63

    
64
	/** {@inheritDoc} */
65
	@Override
66
	protected void createControls(ICdmFormElement formElement,
67
			CategoricalData entity, int style) {
68

    
69
		combo_UseCategory = formFactory.createDefinedTermComboElement(TermType.State, this, UsageTermCollection.useCategoryVocabularyLabel, null, style);
70
		combo_UseCategory.addSelectionListener(this);
71
		combo_UseSubCategory = formFactory.createDefinedTermComboElement(TermType.State, this, UsageTermCollection.useSubCategoryVocabularyLabel, null, style);
72
		combo_PlantPart = formFactory.createDefinedTermComboElement(TermType.Modifier, this, UsageTermCollection.plantPartLabel, null, style);
73
		combo_HumanGroup = formFactory.createDefinedTermComboElement(TermType.Modifier, this, UsageTermCollection.humanGroupLabel, null, style);
74
		combo_HumanGroup.addSelectionListener(this);
75
		combo_EthnicGroup = formFactory.createDefinedTermComboElement(TermType.Modifier, this, UsageTermCollection.ethnicGroupLabel, null, style);
76
		combo_Country	= formFactory.createDefinedTermComboElement(TermType.Modifier, this, UsageTermCollection.countryLabel, null, style);
77

    
78

    
79
		List<State> termsUseCategory = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false));
80
		combo_UseCategory.setTerms(termsUseCategory);
81
		combo_UseCategory.setSelection(stateSelection(UsageTermCollection.useCategoryVocabularyLabel));
82

    
83
		List<State> termsSubCategory = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false), combo_UseCategory.getSelection());
84

    
85
		if (termsSubCategory != null) {
86
			combo_UseSubCategory.setTerms(termsSubCategory);
87
			combo_UseSubCategory.setSelection(stateSelection(UsageTermCollection.useSubCategoryVocabularyLabel));
88
			combo_UseSubCategory.setEnabled(true);
89
		}
90
		else {
91
			combo_UseSubCategory.setEnabled(false);
92
		}
93

    
94
		List<DefinedTerm> plantPartsToAdd = setModifierComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), UsageTermCollection.plantPartLabel);
95
		combo_PlantPart.setTerms(plantPartsToAdd);
96
		combo_PlantPart.setSelection(modifierSelection(UsageTermCollection.plantPartLabel));
97

    
98
		List<DefinedTerm> countriesToAdd = setModifierComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), UsageTermCollection.countryLabel);
99
		combo_Country.setTerms(countriesToAdd);
100
		combo_Country.setSelection(modifierSelection(UsageTermCollection.countryLabel));
101

    
102
		List<DefinedTerm> humanGroupToAdd = setModifierComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), UsageTermCollection.humanGroupLabel);
103
		combo_HumanGroup.setTerms(humanGroupToAdd);
104
		combo_HumanGroup.setSelection(modifierSelection(UsageTermCollection.humanGroupLabel));
105

    
106
		List<DefinedTerm> ethnicGroupToAdd = setEthnicGroupComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), combo_HumanGroup.getSelection());
107
		if (ethnicGroupToAdd != null) {
108
			combo_EthnicGroup.setTerms(ethnicGroupToAdd);
109
			combo_EthnicGroup.setSelection(modifierSelection(UsageTermCollection.ethnicGroupLabel));
110
			combo_EthnicGroup.setEnabled(true);
111
		} else {
112
			combo_EthnicGroup.setEnabled(false);
113
		}
114

    
115
	}
116

    
117
	/**
118
	 * Returns the select modifier
119
	 * @param comboCategory
120
	 * @return
121
	 */
122
	private DefinedTerm modifierSelection(String comboCategory) {
123
		if(!getEntity().getModifiers().isEmpty()) {
124
			for (DefinedTerm modifier : getEntity().getModifiers()) {
125
				if(GetVocabularyType(modifier, comboCategory)) {
126
					return modifier;
127
				}
128
			}
129
		} else {
130
			return null;
131
		}
132
		return null;
133

    
134
	}
135

    
136
	/**
137
	 * Returns the selected state
138
	 * @param comboCategory
139
	 * @return
140
	 */
141
	private State stateSelection(String comboCategory) {
142
		if (!getEntity().getStateData().isEmpty()) {
143
			for (StateData statedata : getEntity().getStateData()) {
144
				if (statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
145
					String testString = statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText();
146
					if(testString.equals(comboCategory)) {
147
						if(statedata.getState() !=null) {
148
							return statedata.getState();
149
						}
150
					}
151
				}
152
			}
153
		}
154
		else {
155
			return null;
156
		}
157
		return null;
158

    
159
	}
160

    
161
	/**
162
	 * This function sets the combo terms (Besides EthnicGroup
163
	 * @param listOfTerms
164
	 * @param modType
165
	 * @return
166
	 */
167
	private List<DefinedTerm> setModifierComboTerms(List<DefinedTerm> listOfTerms, String modType) {
168
		List<DefinedTerm> termsToAdd = new ArrayList<DefinedTerm>();
169
		for (DefinedTerm term : listOfTerms) {
170

    
171
			if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(modType))) {
172
				termsToAdd.add(term);
173
			}
174
			else if ((term.getVocabulary() != null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals(modType))) {
175
				termsToAdd.add(term);
176
			}
177
		}
178

    
179
		return termsToAdd;
180
	}
181

    
182

    
183
	/**
184
	 * This function sets the Use Category combo term
185
	 * @param listOfTerms
186
	 * @return
187
	 */
188
	private List<State> setUseCategoryComboTerms(List<State> listOfTerms) {
189
		List<State> termsToAdd = new ArrayList<State>();
190
		for (State term : listOfTerms) {
191

    
192
			if ((term.getPartOf() != null) && (term.getPartOf().getUuid().equals( UsageTermCollection.uuidUseCategoryVocabulary))) {
193
				termsToAdd.add(term);
194
			}
195
			else if ((term.getVocabulary() !=null) && (term.getPartOf() == null) && (term.getVocabulary().getUuid().equals(UsageTermCollection.uuidUseCategoryVocabulary))) {
196
				termsToAdd.add(term);
197
			}
198
		}
199
		return termsToAdd;
200

    
201
	}
202

    
203
	/**
204
	 * This function sets the Use SubCategory combo term
205
	 * @param listOfTerms
206
	 * @param selectedUseCategory
207
	 * @return
208
	 */
209
	private List<State> setUseCategoryComboTerms(List<State> listOfTerms,
210
			State selectedUseCategory) {
211
		List<State> termsToAdd = new ArrayList<State>();
212
		if (combo_UseCategory.getSelection() != null) {
213

    
214
			for (State term : listOfTerms) {
215
				if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(selectedUseCategory.getTitleCache()))) {
216
					termsToAdd.add(term);
217
				}
218
				else if ((term.getVocabulary() !=null) && (term.getVocabulary().getTitleCache().equals(selectedUseCategory.getTitleCache()))) {
219
					termsToAdd.add(term);
220
				}
221

    
222
			}
223
		}
224
		else if (!getEntity().getStateData().isEmpty()) {
225
			for (StateData stateData : getEntity().getStateData()) {
226
				if (stateData.getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
227
					if ((stateData.getState() != null) && (stateData.getModifyingText().get(CdmStore.getDefaultLanguage()).getText() == UsageTermCollection.useCategoryVocabularyLabel)) {
228
						for (State term : listOfTerms) {
229
							if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(stateData.getState().getTitleCache()))) {
230
								termsToAdd.add(term);
231
							} else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(stateData.getState().getTitleCache()))) {
232
								termsToAdd.add(term);
233
							}
234
						}
235

    
236
					}
237
				}
238
			}
239

    
240
		}
241

    
242
		else {
243
			return null;
244
		}
245

    
246
		return termsToAdd;
247
	}
248

    
249

    
250
	/**
251
	 * This function sets the EthnicGroup combo term
252
	 * @param listOfTerms
253
	 * @param selectedHumangroup
254
	 * @return
255
	 */
256
	private List<DefinedTerm> setEthnicGroupComboTerms(List<DefinedTerm> listOfTerms,
257
			DefinedTerm selectedHumangroup) {
258
		List<DefinedTerm> termsToAdd = new ArrayList<DefinedTerm>();
259
		if (combo_HumanGroup.getSelection() != null) {
260
			for (DefinedTerm term : listOfTerms) {
261

    
262
				if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(selectedHumangroup.getTitleCache()))) {
263
					termsToAdd.add(term);
264
				}
265
				else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(selectedHumangroup.getTitleCache()))) {
266
					termsToAdd.add(term);
267
				}
268
			}
269
		}
270
		else if (!getEntity().getModifiers().isEmpty()) {
271
			for (DefinedTerm modifier : getEntity().getModifiers()) {
272
				if (modifier.getMarkers() != null) {
273
					for (Marker marker : modifier.getMarkers()) {
274
						if(marker.getMarkerType().getTitleCache().equals(UsageTermCollection.humanGroupLabel)) {
275
							for (DefinedTerm term : listOfTerms) {
276
								if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(modifier.getTitleCache()))) {
277
									termsToAdd.add(modifier);
278
								} else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(modifier.getTitleCache()))) {
279
									termsToAdd.add(modifier);
280
								}
281
							}
282

    
283
						}
284
					}
285
				}
286
			}
287
		} else {
288
			return null;
289
		}
290

    
291
		return termsToAdd;
292
	}
293

    
294

    
295
	/** {@inheritDoc} */
296
	@Override
297
	public void handleEvent(Object eventSource) {
298
		if (eventSource == combo_UseCategory) {
299
			if (combo_UseCategory.getSelection() != null) {
300
				boolean isChanged = false;
301
				boolean isUseCategoryChanged = false;
302
				if (!getEntity().getStateData().isEmpty()) {
303
					for (StateData useCategoryStateDataCheck : getEntity().getStateData()) {
304
						Map<Language, LanguageString> modText = useCategoryStateDataCheck.getModifyingText();
305
						if(modText.get(CdmStore.getDefaultLanguage()) != null && modText.get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useCategoryVocabularyLabel)) {
306
							if(!useCategoryStateDataCheck.getState().getTitleCache().equals(combo_UseCategory.getSelection().getTitleCache())) {
307
								isUseCategoryChanged = true;
308
							}
309

    
310
						}
311
					}
312
					ListIterator<StateData> itrExistingStates = getEntity().getStateData().listIterator();
313
					while(itrExistingStates.hasNext()) {
314
						StateData existingStateData = itrExistingStates.next();
315
						Map<Language, LanguageString> modifyingText = existingStateData
316
								.getModifyingText();
317
						if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
318
							if (modifyingText.get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useCategoryVocabularyLabel)) {
319
								isChanged = true;
320
								if(!existingStateData.getState().getTitleCache().equals(combo_UseCategory.getSelection().getTitleCache())) {
321
									itrExistingStates.remove();
322
									StateData stateData = StateData.NewInstance(combo_UseCategory.getSelection());
323
									stateData.setState(combo_UseCategory.getSelection());
324
									stateData.putModifyingText(CdmStore.getDefaultLanguage(),UsageTermCollection.useCategoryVocabularyLabel);
325
									itrExistingStates.add(stateData);
326

    
327
								}
328
							} else if (modifyingText.get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useSubCategoryVocabularyLabel) && isUseCategoryChanged == true) {
329
								itrExistingStates.remove();
330
							}
331
						}
332
					}
333
				}
334

    
335

    
336
				if (isChanged == false) {
337
					StateData stateData = StateData
338
							.NewInstance(combo_UseCategory.getSelection());
339
					stateData.setState(combo_UseCategory.getSelection());
340
					stateData.putModifyingText(CdmStore.getDefaultLanguage(), UsageTermCollection.useCategoryVocabularyLabel);
341
					getEntity().addStateData(stateData);
342
				}
343

    
344
				combo_UseSubCategory.setEnabled(true);
345

    
346
			}
347
			else {
348
				if (!getEntity().getStateData().isEmpty()) {
349
					Iterator<StateData> itr = getEntity().getStateData().iterator();
350
					while(itr.hasNext()) {
351
						StateData stateToRemove = itr.next();
352
						itr.remove();
353
					}
354
					List<State> termsSubCategory = new ArrayList<State>();
355
					State emptyState = State.NewInstance();
356
					termsSubCategory.add(emptyState);
357
					combo_UseSubCategory.setTerms(termsSubCategory);
358
					combo_UseSubCategory.setEnabled(false);
359
				}
360
			}
361
		}
362

    
363
		if (eventSource == combo_UseSubCategory) {
364
			if (combo_UseSubCategory.getSelection() != null) {
365
				boolean isChanged = false;
366
				if (!getEntity().getStateData().isEmpty()) {
367
					ListIterator<StateData> itrExistingStates = getEntity().getStateData().listIterator();
368
					while(itrExistingStates.hasNext()) {
369
						StateData existingStateData = itrExistingStates.next();
370
						Map<Language, LanguageString> modifyingText = existingStateData
371
								.getModifyingText();
372
						if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
373
							if (modifyingText.get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useSubCategoryVocabularyLabel)) {
374
								isChanged = true;
375
								if(!existingStateData.getState().getTitleCache().equals(combo_UseSubCategory.getSelection().getTitleCache())) {
376
									itrExistingStates.remove();
377
									StateData stateData = StateData.NewInstance(combo_UseSubCategory.getSelection());
378
									stateData.setState(combo_UseSubCategory.getSelection());
379
									stateData.putModifyingText(CdmStore.getDefaultLanguage(),UsageTermCollection.useSubCategoryVocabularyLabel);
380
									itrExistingStates.add(stateData);
381
								}
382
							}
383
						}
384
					}
385
				}
386

    
387
				if (isChanged == false){
388
					StateData stateData = StateData
389
							.NewInstance(combo_UseSubCategory.getSelection());
390
					stateData.setState(combo_UseSubCategory.getSelection());
391
					stateData.putModifyingText(CdmStore.getDefaultLanguage(), UsageTermCollection.useSubCategoryVocabularyLabel);
392
					getEntity().addStateData(stateData);
393
				}
394

    
395
			} else {
396
				if (!getEntity().getStateData().isEmpty()) {
397
					Iterator<StateData> itrStateData = getEntity().getStateData().iterator();
398
					while(itrStateData.hasNext()) {
399
						StateData existingStateData = itrStateData.next();
400
						Map<Language, LanguageString> modifyingText = existingStateData
401
								.getModifyingText();
402

    
403
						if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
404
							if (modifyingText.get(CdmStore.getDefaultLanguage()).getText() == UsageTermCollection.useSubCategoryVocabularyLabel) {
405
								itrStateData.remove();
406
							}
407
						}
408
					}
409
				}
410
			}
411
		}
412
		if (eventSource == combo_PlantPart) {
413
			if (combo_PlantPart.getSelection() != null) {
414
				Iterator<DefinedTerm> itrExistingModifiers = getEntity().getModifiers().iterator();
415
				while (itrExistingModifiers.hasNext()) {
416
					DefinedTerm modifier = itrExistingModifiers.next();
417
					if(GetVocabularyType(modifier, UsageTermCollection.plantPartLabel)) {
418
						itrExistingModifiers.remove();
419
					}
420

    
421
				}
422
				DefinedTerm plantPart = combo_PlantPart.getSelection();
423
				getEntity().addModifier(plantPart);
424
			} else {
425
				Set<DefinedTerm> modifiers = getEntity().getModifiers();
426
				if(!modifiers.isEmpty()) {
427
					Iterator<DefinedTerm> itr = modifiers.iterator();
428
					while (itr.hasNext()) {
429
						DefinedTerm currentMod = itr.next();
430
						if(GetVocabularyType(currentMod, UsageTermCollection.plantPartLabel)) {
431
							itr.remove();
432
						}
433
					}
434
				}
435

    
436
			}
437
		}
438
		if (eventSource == combo_Country) {
439
			if (combo_Country.getSelection() != null) {
440
				Iterator<DefinedTerm> itrExistingModifiers = getEntity().getModifiers().iterator();
441
				while (itrExistingModifiers.hasNext()) {
442
					DefinedTerm modifier = itrExistingModifiers.next();
443
					if(GetVocabularyType(modifier, UsageTermCollection.countryLabel)) {
444
						itrExistingModifiers.remove();
445
					}
446

    
447
				}
448
				DefinedTerm country = combo_Country.getSelection();
449
				getEntity().addModifier(country);
450
			} else {
451
				Set<DefinedTerm> modifiers = getEntity().getModifiers();
452
				if(!modifiers.isEmpty()) {
453
					Iterator<DefinedTerm> itr = modifiers.iterator();
454
					while (itr.hasNext()) {
455
						DefinedTerm currentMod = itr.next();
456
						if(GetVocabularyType(currentMod, UsageTermCollection.countryLabel)) {
457
							itr.remove();
458
						}
459
					}
460
				}
461
			}
462
		}
463
		if (eventSource == combo_HumanGroup) {
464
			if (combo_HumanGroup.getSelection() != null) {
465
				boolean isHumanGroupChanged = true;
466
				for (DefinedTerm modToCheck: getEntity().getModifiers()) {
467
					if(modToCheck.equals(combo_HumanGroup.getSelection()) && (GetVocabularyType(modToCheck, UsageTermCollection.humanGroupLabel))) {
468
						isHumanGroupChanged = false;
469
				}
470

    
471

    
472
				}
473
				Iterator<DefinedTerm> itrExistingModifiers = getEntity().getModifiers().iterator();
474
				while (itrExistingModifiers.hasNext()) {
475
					DefinedTerm modifier = itrExistingModifiers.next();
476
					if((GetVocabularyType(modifier, UsageTermCollection.humanGroupLabel) || GetVocabularyType(modifier, UsageTermCollection.ethnicGroupLabel)) && isHumanGroupChanged) {
477
						itrExistingModifiers.remove();
478
					}
479

    
480
				}
481
				if(isHumanGroupChanged){
482
					DefinedTerm humanGroup = combo_HumanGroup.getSelection();
483
					getEntity().addModifier(humanGroup);
484
				}
485
				combo_EthnicGroup.setEnabled(true);
486
			} else {
487
				Set<DefinedTerm> modifiers = getEntity().getModifiers();
488
				if(!modifiers.isEmpty()) {
489
					Iterator<DefinedTerm> itr = modifiers.iterator();
490
					while (itr.hasNext()) {
491
						DefinedTerm currentMod = itr.next();
492
						if(GetVocabularyType(currentMod, UsageTermCollection.humanGroupLabel) || GetVocabularyType(currentMod, UsageTermCollection.ethnicGroupLabel)) {
493
							itr.remove();
494
						}
495
					}
496
				}
497
				List<DefinedTerm> emptyListToResetComboBox = new ArrayList<DefinedTerm>();
498

    
499
//				DefinedTerm emptyMod = DefinedTerm.NewInstance();
500
				DefinedTerm emptyMod = null;
501

    
502

    
503
				emptyListToResetComboBox.add(emptyMod);
504
				combo_EthnicGroup.setTerms(emptyListToResetComboBox);
505
				combo_EthnicGroup.setEnabled(false);
506

    
507
			}
508
		}
509
		if (eventSource == combo_EthnicGroup) {
510
			if (combo_EthnicGroup.getSelection() != null) {
511
				Iterator<DefinedTerm> itrExistingModifiers = getEntity().getModifiers().iterator();
512
					while (itrExistingModifiers.hasNext()) {
513
						DefinedTerm modifier = itrExistingModifiers.next();
514
						if(GetVocabularyType(modifier, combo_HumanGroup.getSelection().getTitleCache())) {
515
							itrExistingModifiers.remove();
516
						}
517

    
518
					}
519
					DefinedTerm ethnicGroup = combo_EthnicGroup.getSelection();
520
					getEntity().addModifier(ethnicGroup);
521
			} else {
522
				Set<DefinedTerm> modifiers = getEntity().getModifiers();
523
				if(!modifiers.isEmpty()) {
524

    
525
					Iterator<DefinedTerm> itr = modifiers.iterator();
526
					while (itr.hasNext()) {
527
						DefinedTerm currentMod = itr.next();
528
						if(GetVocabularyType(currentMod, UsageTermCollection.ethnicGroupLabel)) {
529
							itr.remove();
530
						}
531
					}
532

    
533
				}
534
			}
535
		}
536
	}
537

    
538

    
539

    
540
	/**
541
	 * This function Checks the vocabulary type
542
	 * @param term
543
	 * @param vocabularyExpected
544
	 * @return
545
	 */
546
	private boolean GetVocabularyType(DefinedTerm term, String vocabularyExpected) {
547
		if ((term.getPartOf() != null)  && (term.getPartOf().getTitleCache().equals(vocabularyExpected))) {
548
			return true;
549
		}
550
		else if ((term.getVocabulary() != null) && (term.getPartOf()==null) && (term.getVocabulary().getTitleCache().equals(vocabularyExpected))) {
551
			return true;
552
		}
553
		else if ((vocabularyExpected.equals(UsageTermCollection.ethnicGroupLabel))  && ((term.getPartOf() != null))) {
554
			return true;
555
		}
556
	return false;
557
	}
558

    
559

    
560

    
561
	/** {@inheritDoc} */
562
	@Override
563
	public void setEntity(CategoricalData entity) {
564
		super.setEntity(entity);
565
	}
566

    
567
	/** {@inheritDoc} */
568
	@Override
569
	public void widgetSelected(SelectionEvent e) {
570
		Object eventSource = e.getSource();
571
		for (Object object: combo_UseCategory.getControls()) {
572
			if (object == eventSource) {
573
				State selectedUseCategory = combo_UseCategory.getSelection();
574
				if (selectedUseCategory != null) {
575
					combo_UseSubCategory.setTerms(setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false),selectedUseCategory));
576

    
577
					if (!getEntity().getStateData().isEmpty()) {
578
						Iterator<StateData> itrExistingState = getEntity().getStateData().iterator();
579
						while(itrExistingState.hasNext()) {
580
							StateData existingStateData = itrExistingState.next();
581
							Map<Language, LanguageString> modifyingText = existingStateData.getModifyingText();
582
							if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
583
								if (modifyingText.get(CdmStore.getDefaultLanguage())
584
										.getText().equals(UsageTermCollection.useSubCategoryVocabularyLabel)) {
585
									combo_UseSubCategory.setSelection(stateSelection(UsageTermCollection.useSubCategoryVocabularyLabel));
586
								}
587
							}
588
						}
589
					}
590
				}
591
			}
592
		}
593
		for (Object object: combo_HumanGroup.getControls()) {
594
			if (object == eventSource) {
595
				DefinedTerm selectedHumanGroup = combo_HumanGroup.getSelection();
596
				if (selectedHumanGroup != null) {
597
					combo_EthnicGroup.setTerms(setEthnicGroupComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), selectedHumanGroup));
598
					if (!getEntity().getModifiers().isEmpty()) {
599
						Iterator<DefinedTerm> iterModifiers = getEntity().getModifiers().iterator();
600
						while (iterModifiers.hasNext()) {
601
							DefinedTerm existingModifier = iterModifiers.next();
602
							if(GetVocabularyType(existingModifier, UsageTermCollection.ethnicGroupLabel)) {
603
								combo_EthnicGroup.setSelection(modifierSelection(UsageTermCollection.ethnicGroupLabel));
604
							}
605
						}
606
					}
607

    
608
				}
609
			}
610
		}
611
	}
612

    
613
	/** {@inheritDoc} */
614
	@Override
615
	public void widgetDefaultSelected(SelectionEvent e) {
616
		// TODO Auto-generated method stub
617

    
618
	}
619

    
620
}
(1-1/2)