Project

General

Profile

Download (23 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
import org.apache.log4j.Logger;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.events.SelectionListener;
20

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

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

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

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

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

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

    
67
		combo_UseCategory = formFactory.createTermComboElement(State.class,	this, UsageTermCollection.useCategoryVocabularyLabel, null, style);
68
		combo_UseCategory.addSelectionListener(this);
69
		combo_UseSubCategory = formFactory.createTermComboElement(State.class, this, UsageTermCollection.useSubCategoryVocabularyLabel, null, style);
70
		combo_PlantPart = formFactory.createTermComboElement(DefinedTerm.class, this, UsageTermCollection.plantPartLabel, null, style);
71
		combo_HumanGroup = formFactory.createTermComboElement(DefinedTerm.class, this, UsageTermCollection.humanGroupLabel, null, style);
72
		combo_HumanGroup.addSelectionListener(this);
73
		combo_EthnicGroup = formFactory.createTermComboElement(DefinedTerm.class, this, UsageTermCollection.ethnicGroupLabel, null, style);
74
		combo_Country	= formFactory.createTermComboElement(DefinedTerm.class, this, UsageTermCollection.countryLabel, null, style);
75
		
76

    
77
		List<State> termsUseCategory = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false));
78
		combo_UseCategory.setTerms(termsUseCategory);
79
		combo_UseCategory.setSelection(stateSelection(UsageTermCollection.useCategoryVocabularyLabel));
80
		
81
		List<State> termsSubCategory = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false), combo_UseCategory.getSelection());
82
		
83
		if (termsSubCategory != null) {
84
			combo_UseSubCategory.setTerms(termsSubCategory);
85
			combo_UseSubCategory.setSelection(stateSelection(UsageTermCollection.useSubCategoryVocabularyLabel));
86
			combo_UseSubCategory.setEnabled(true);
87
		}
88
		else {
89
			combo_UseSubCategory.setEnabled(false);
90
		}
91
		
92
		List<DefinedTerm> plantPartsToAdd = setModifierComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), UsageTermCollection.plantPartLabel);
93
		combo_PlantPart.setTerms(plantPartsToAdd);
94
		combo_PlantPart.setSelection(modifierSelection(UsageTermCollection.plantPartLabel));
95
		
96
		List<DefinedTerm> countriesToAdd = setModifierComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), UsageTermCollection.countryLabel);
97
		combo_Country.setTerms(countriesToAdd);
98
		combo_Country.setSelection(modifierSelection(UsageTermCollection.countryLabel));
99
		
100
		List<DefinedTerm> humanGroupToAdd = setModifierComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), UsageTermCollection.humanGroupLabel);
101
		combo_HumanGroup.setTerms(humanGroupToAdd);
102
		combo_HumanGroup.setSelection(modifierSelection(UsageTermCollection.humanGroupLabel));
103
		
104
		List<DefinedTerm> ethnicGroupToAdd = setEthnicGroupComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), combo_HumanGroup.getSelection());
105
		if (ethnicGroupToAdd != null) {
106
			combo_EthnicGroup.setTerms(ethnicGroupToAdd);
107
			combo_EthnicGroup.setSelection(modifierSelection(UsageTermCollection.ethnicGroupLabel));
108
			combo_EthnicGroup.setEnabled(true);
109
		} else {
110
			combo_EthnicGroup.setEnabled(false);
111
		}
112

    
113
	}
114

    
115
	/**
116
	 * Returns the select modifier
117
	 * @param comboCategory
118
	 * @return
119
	 */
120
	private DefinedTerm modifierSelection(String comboCategory) {
121
		if(!getEntity().getModifiers().isEmpty()) {
122
			for (DefinedTerm modifier : getEntity().getModifiers()) {
123
				if(GetVocabularyType(modifier, comboCategory)) {
124
					return modifier;
125
				}
126
			}
127
		} else {
128
			return null;
129
		}
130
		return null;
131
		
132
	}
133
	
134
	/**
135
	 * Returns the selected state
136
	 * @param comboCategory
137
	 * @return
138
	 */
139
	private State stateSelection(String comboCategory) {
140
		if (!getEntity().getStateData().isEmpty()) {
141
			for (StateData statedata : getEntity().getStateData()) {
142
				if (statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
143
					String testString = statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText();
144
					if(testString.equals(comboCategory)) {
145
						if(statedata.getState() !=null) {
146
							return statedata.getState();
147
						}
148
					}
149
				}				
150
			}
151
		}
152
		else {
153
			return null;
154
		}
155
		return null;
156
		
157
	}
158
	
159
	/**
160
	 * This function sets the combo terms (Besides EthnicGroup
161
	 * @param listOfTerms
162
	 * @param modType
163
	 * @return
164
	 */
165
	private List<DefinedTerm> setModifierComboTerms(List<DefinedTerm> listOfTerms, String modType) {
166
		List<DefinedTerm> termsToAdd = new ArrayList<DefinedTerm>();
167
		for (DefinedTerm term : listOfTerms) {
168

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

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

    
190
			if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(UsageTermCollection.useCategoryVocabularyLabel))) {
191
				termsToAdd.add(term);
192
			}
193
			else if ((term.getVocabulary() !=null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals(UsageTermCollection.useCategoryVocabularyLabel))) {
194
				termsToAdd.add(term);
195
			}
196
		}
197
		return termsToAdd;
198

    
199
	}
200

    
201
	/**
202
	 * This function sets the Use SubCategory combo term
203
	 * @param listOfTerms
204
	 * @param selectedUseCategory
205
	 * @return
206
	 */
207
	private List<State> setUseCategoryComboTerms(List<State> listOfTerms,
208
			State selectedUseCategory) {
209
		List<State> termsToAdd = new ArrayList<State>();
210
		if (combo_UseCategory.getSelection() != null) {
211
			
212
			for (State term : listOfTerms) {
213
				if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(selectedUseCategory.getTitleCache()))) {
214
					termsToAdd.add(term);
215
				}
216
				else if ((term.getVocabulary() !=null) && (term.getVocabulary().getTitleCache().equals(selectedUseCategory.getTitleCache()))) {
217
					termsToAdd.add(term);
218
				}
219
	
220
			}
221
		}
222
		else if (!getEntity().getStateData().isEmpty()) {
223
			for (StateData stateData : getEntity().getStateData()) {
224
				if (stateData.getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
225
					if ((stateData.getState() != null) && (stateData.getModifyingText().get(CdmStore.getDefaultLanguage()).getText() == UsageTermCollection.useCategoryVocabularyLabel)) {
226
						for (State term : listOfTerms) {
227
							if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(stateData.getState().getTitleCache()))) {
228
								termsToAdd.add(term);
229
							} else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(stateData.getState().getTitleCache()))) {
230
								termsToAdd.add(term);
231
							}
232
						}
233
						
234
					}
235
				}
236
			}
237
			
238
		}
239
			
240
		else {
241
			return null;
242
		}
243

    
244
		return termsToAdd;
245
	}
246
	
247
	
248
	/**
249
	 * This function sets the EthnicGroup combo term
250
	 * @param listOfTerms
251
	 * @param selectedHumangroup
252
	 * @return
253
	 */
254
	private List<DefinedTerm> setEthnicGroupComboTerms(List<DefinedTerm> listOfTerms,
255
			DefinedTerm selectedHumangroup) {
256
		List<DefinedTerm> termsToAdd = new ArrayList<DefinedTerm>();
257
		if (combo_HumanGroup.getSelection() != null) {
258
			for (DefinedTerm term : listOfTerms) {
259
	
260
				if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(selectedHumangroup.getTitleCache()))) {
261
					termsToAdd.add(term);
262
				}
263
				else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(selectedHumangroup.getTitleCache()))) {
264
					termsToAdd.add(term);
265
				}
266
			}
267
		}
268
		else if (!getEntity().getModifiers().isEmpty()) {
269
			for (DefinedTerm modifier : getEntity().getModifiers()) {
270
				if (modifier.getMarkers() != null) {
271
					for (Marker marker : modifier.getMarkers()) {
272
						if(marker.getMarkerType().getTitleCache().equals(UsageTermCollection.humanGroupLabel)) {
273
							for (DefinedTerm term : listOfTerms) {
274
								if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(modifier.getTitleCache()))) {
275
									termsToAdd.add(modifier);
276
								} else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(modifier.getTitleCache()))) {
277
									termsToAdd.add(modifier);
278
								}
279
							}
280
							
281
						}
282
					}
283
				}
284
			}
285
		} else {
286
			return null;
287
		}
288
		
289
		return termsToAdd;
290
	}
291

    
292
	
293
	/** {@inheritDoc} */
294
	@Override
295
	public void handleEvent(Object eventSource) {
296
		if (eventSource == combo_UseCategory) {
297
			if (combo_UseCategory.getSelection() != null) {
298
				boolean isChanged = false;
299
				boolean isUseCategoryChanged = false;
300
				if (!getEntity().getStateData().isEmpty()) {
301
					for (StateData useCategoryStateDataCheck : getEntity().getStateData()) {
302
						Map<Language, LanguageString> modText = useCategoryStateDataCheck.getModifyingText();
303
						if(modText.get(CdmStore.getDefaultLanguage()) != null && modText.get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useCategoryVocabularyLabel)) {
304
							if(!useCategoryStateDataCheck.getState().getTitleCache().equals(combo_UseCategory.getSelection().getTitleCache())) {
305
								isUseCategoryChanged = true;
306
							}
307
							
308
						}
309
					}
310
					ListIterator<StateData> itrExistingStates = getEntity().getStateData().listIterator();
311
					while(itrExistingStates.hasNext()) {
312
						StateData existingStateData = itrExistingStates.next();
313
						Map<Language, LanguageString> modifyingText = existingStateData
314
								.getModifyingText();
315
						if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
316
							if (modifyingText.get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useCategoryVocabularyLabel)) {
317
								isChanged = true;
318
								if(!existingStateData.getState().getTitleCache().equals(combo_UseCategory.getSelection().getTitleCache())) {
319
									itrExistingStates.remove();
320
									StateData stateData = StateData.NewInstance(combo_UseCategory.getSelection());
321
									stateData.setState(combo_UseCategory.getSelection());
322
									stateData.putModifyingText(CdmStore.getDefaultLanguage(),UsageTermCollection.useCategoryVocabularyLabel);
323
									itrExistingStates.add(stateData);
324
									
325
								}
326
							} else if (modifyingText.get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useSubCategoryVocabularyLabel) && isUseCategoryChanged == true) {
327
								itrExistingStates.remove();
328
							}
329
						}
330
					}
331
				}
332
				
333
				
334
				if (isChanged == false) {
335
					StateData stateData = StateData
336
							.NewInstance(combo_UseCategory.getSelection());
337
					stateData.setState(combo_UseCategory.getSelection());
338
					stateData.putModifyingText(CdmStore.getDefaultLanguage(), UsageTermCollection.useCategoryVocabularyLabel);
339
					getEntity().addStateData(stateData);
340
				}
341
				
342
				combo_UseSubCategory.setEnabled(true);
343
	
344
			}
345
			else {
346
				if (!getEntity().getStateData().isEmpty()) {
347
					Iterator<StateData> itr = getEntity().getStateData().iterator();
348
					while(itr.hasNext()) {
349
						StateData stateToRemove = itr.next();
350
						itr.remove();
351
					}
352
					List<State> termsSubCategory = new ArrayList<State>();
353
					State emptyState = State.NewInstance();
354
					termsSubCategory.add(emptyState);
355
					combo_UseSubCategory.setTerms(termsSubCategory);
356
					combo_UseSubCategory.setEnabled(false);
357
				}
358
			}
359
		}
360
			
361
		if (eventSource == combo_UseSubCategory) {
362
			if (combo_UseSubCategory.getSelection() != null) {
363
				boolean isChanged = false;
364
				if (!getEntity().getStateData().isEmpty()) {
365
					ListIterator<StateData> itrExistingStates = getEntity().getStateData().listIterator();
366
					while(itrExistingStates.hasNext()) {
367
						StateData existingStateData = itrExistingStates.next();
368
						Map<Language, LanguageString> modifyingText = existingStateData
369
								.getModifyingText();
370
						if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
371
							if (modifyingText.get(CdmStore.getDefaultLanguage()).getText().equals(UsageTermCollection.useSubCategoryVocabularyLabel)) {
372
								isChanged = true;
373
								if(!existingStateData.getState().getTitleCache().equals(combo_UseSubCategory.getSelection().getTitleCache())) {
374
									itrExistingStates.remove();
375
									StateData stateData = StateData.NewInstance(combo_UseSubCategory.getSelection());
376
									stateData.setState(combo_UseSubCategory.getSelection());
377
									stateData.putModifyingText(CdmStore.getDefaultLanguage(),UsageTermCollection.useSubCategoryVocabularyLabel);
378
									itrExistingStates.add(stateData);
379
								}
380
							}
381
						}
382
					}
383
				}
384
				
385
				if (isChanged == false){
386
					StateData stateData = StateData
387
							.NewInstance(combo_UseSubCategory.getSelection());
388
					stateData.setState(combo_UseSubCategory.getSelection());
389
					stateData.putModifyingText(CdmStore.getDefaultLanguage(), UsageTermCollection.useSubCategoryVocabularyLabel);
390
					getEntity().addStateData(stateData);
391
				}
392
	
393
			} else {
394
				if (!getEntity().getStateData().isEmpty()) {
395
					Iterator<StateData> itrStateData = getEntity().getStateData().iterator();
396
					while(itrStateData.hasNext()) {
397
						StateData existingStateData = itrStateData.next();
398
						Map<Language, LanguageString> modifyingText = existingStateData
399
								.getModifyingText();
400

    
401
						if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
402
							if (modifyingText.get(CdmStore.getDefaultLanguage()).getText() == UsageTermCollection.useSubCategoryVocabularyLabel) {
403
								itrStateData.remove();
404
							}
405
						}
406
					}
407
				}
408
			}
409
		}
410
		if (eventSource == combo_PlantPart) {
411
			if (combo_PlantPart.getSelection() != null) {
412
				Iterator<DefinedTerm> itrExistingModifiers = getEntity().getModifiers().iterator();
413
				while (itrExistingModifiers.hasNext()) {
414
					DefinedTerm modifier = itrExistingModifiers.next();
415
					if(GetVocabularyType(modifier, UsageTermCollection.plantPartLabel)) {
416
						itrExistingModifiers.remove();
417
					}
418
						
419
				}	
420
				DefinedTerm plantPart = combo_PlantPart.getSelection();
421
				getEntity().addModifier(plantPart);
422
			} else {
423
				Set<DefinedTerm> modifiers = getEntity().getModifiers();
424
				if(!modifiers.isEmpty()) {
425
					Iterator<DefinedTerm> itr = modifiers.iterator();
426
					while (itr.hasNext()) {
427
						DefinedTerm currentMod = itr.next();
428
						if(GetVocabularyType(currentMod, UsageTermCollection.plantPartLabel)) {
429
							itr.remove();
430
						}
431
					}
432
				}
433
				
434
			}
435
		}
436
		if (eventSource == combo_Country) {
437
			if (combo_Country.getSelection() != null) {
438
				Iterator<DefinedTerm> itrExistingModifiers = getEntity().getModifiers().iterator();
439
				while (itrExistingModifiers.hasNext()) {
440
					DefinedTerm modifier = itrExistingModifiers.next();
441
					if(GetVocabularyType(modifier, UsageTermCollection.countryLabel)) {
442
						itrExistingModifiers.remove();
443
					}
444
						
445
				}
446
				DefinedTerm country = combo_Country.getSelection();
447
				getEntity().addModifier(country);
448
			} else {
449
				Set<DefinedTerm> modifiers = getEntity().getModifiers();
450
				if(!modifiers.isEmpty()) {
451
					Iterator<DefinedTerm> itr = modifiers.iterator();
452
					while (itr.hasNext()) {
453
						DefinedTerm currentMod = itr.next();
454
						if(GetVocabularyType(currentMod, UsageTermCollection.countryLabel)) {
455
							itr.remove();
456
						}
457
					}
458
				}
459
			}
460
		}
461
		if (eventSource == combo_HumanGroup) {
462
			if (combo_HumanGroup.getSelection() != null) {
463
				boolean isHumanGroupChanged = true;
464
				for (DefinedTerm modToCheck: getEntity().getModifiers()) {
465
					if(modToCheck.equals(combo_HumanGroup.getSelection()) && (GetVocabularyType(modToCheck, UsageTermCollection.humanGroupLabel))) {
466
						isHumanGroupChanged = false;
467
				}
468
				
469
					
470
				}
471
				Iterator<DefinedTerm> itrExistingModifiers = getEntity().getModifiers().iterator();
472
				while (itrExistingModifiers.hasNext()) {
473
					DefinedTerm modifier = itrExistingModifiers.next();
474
					if((GetVocabularyType(modifier, UsageTermCollection.humanGroupLabel) || GetVocabularyType(modifier, UsageTermCollection.ethnicGroupLabel)) && isHumanGroupChanged) {
475
						itrExistingModifiers.remove();
476
					}
477
						
478
				}	
479
				if(isHumanGroupChanged){
480
					DefinedTerm humanGroup = combo_HumanGroup.getSelection();
481
					getEntity().addModifier(humanGroup);
482
				}
483
				combo_EthnicGroup.setEnabled(true);
484
			} else {
485
				Set<DefinedTerm> modifiers = getEntity().getModifiers();
486
				if(!modifiers.isEmpty()) {
487
					Iterator<DefinedTerm> itr = modifiers.iterator();
488
					while (itr.hasNext()) {
489
						DefinedTerm currentMod = itr.next();
490
						if(GetVocabularyType(currentMod, UsageTermCollection.humanGroupLabel) || GetVocabularyType(currentMod, UsageTermCollection.ethnicGroupLabel)) {
491
							itr.remove();
492
						}
493
					}
494
				}
495
				List<DefinedTerm> emptyListToResetComboBox = new ArrayList<DefinedTerm>();
496
				
497
//				DefinedTerm emptyMod = DefinedTerm.NewInstance();
498
				DefinedTerm emptyMod = null;
499
				
500
				
501
				emptyListToResetComboBox.add(emptyMod);
502
				combo_EthnicGroup.setTerms(emptyListToResetComboBox);
503
				combo_EthnicGroup.setEnabled(false);
504
				
505
			}
506
		}
507
		if (eventSource == combo_EthnicGroup) {
508
			if (combo_EthnicGroup.getSelection() != null) {
509
				Iterator<DefinedTerm> itrExistingModifiers = getEntity().getModifiers().iterator();
510
					while (itrExistingModifiers.hasNext()) {
511
						DefinedTerm modifier = itrExistingModifiers.next();
512
						if(GetVocabularyType(modifier, combo_HumanGroup.getSelection().getTitleCache())) {
513
							itrExistingModifiers.remove();
514
						}
515
						
516
					}	
517
					DefinedTerm ethnicGroup = combo_EthnicGroup.getSelection();
518
					getEntity().addModifier(ethnicGroup);
519
			} else {
520
				Set<DefinedTerm> modifiers = getEntity().getModifiers();
521
				if(!modifiers.isEmpty()) {
522
					
523
					Iterator<DefinedTerm> itr = modifiers.iterator();
524
					while (itr.hasNext()) {
525
						DefinedTerm currentMod = itr.next();
526
						if(GetVocabularyType(currentMod, UsageTermCollection.ethnicGroupLabel)) {
527
							itr.remove();
528
						}
529
					}
530
					
531
				}
532
			}
533
		}
534
	}
535
	
536
	
537

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

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

    
565
	/** {@inheritDoc} */
566
	@Override
567
	public void widgetSelected(SelectionEvent e) {
568
		Object eventSource = e.getSource();
569
		for (Object object: combo_UseCategory.getControls()) {
570
			if (object == eventSource) {
571
				State selectedUseCategory = combo_UseCategory.getSelection();
572
				if (selectedUseCategory != null) {
573
					combo_UseSubCategory.setTerms(setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false),selectedUseCategory));
574
				
575
					if (!getEntity().getStateData().isEmpty()) {
576
						Iterator<StateData> itrExistingState = getEntity().getStateData().iterator();
577
						while(itrExistingState.hasNext()) {
578
							StateData existingStateData = (StateData) itrExistingState.next();
579
							Map<Language, LanguageString> modifyingText = existingStateData.getModifyingText();
580
							if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
581
								if (modifyingText.get(CdmStore.getDefaultLanguage())
582
										.getText().equals(UsageTermCollection.useSubCategoryVocabularyLabel)) {
583
									combo_UseSubCategory.setSelection(stateSelection(UsageTermCollection.useSubCategoryVocabularyLabel));
584
								}
585
							}
586
						}
587
					}
588
				}
589
			}
590
		}
591
		for (Object object: combo_HumanGroup.getControls()) {
592
			if (object == eventSource) {
593
				DefinedTerm selectedHumanGroup = combo_HumanGroup.getSelection();
594
				if (selectedHumanGroup != null) {
595
					combo_EthnicGroup.setTerms(setEthnicGroupComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), selectedHumanGroup));
596
					if (!getEntity().getModifiers().isEmpty()) {
597
						Iterator<DefinedTerm> iterModifiers = getEntity().getModifiers().iterator();
598
						while (iterModifiers.hasNext()) {
599
							DefinedTerm existingModifier = iterModifiers.next();
600
							if(GetVocabularyType(existingModifier, UsageTermCollection.ethnicGroupLabel)) {
601
								combo_EthnicGroup.setSelection(modifierSelection(UsageTermCollection.ethnicGroupLabel));
602
							}
603
						}
604
					}
605
					
606
				}
607
			}
608
		}
609
	}
610

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

    
616
	}
617

    
618
}
(1-1/2)