Project

General

Profile

Download (22.7 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.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.Modifier;
27
import eu.etaxonomy.cdm.model.description.State;
28
import eu.etaxonomy.cdm.model.description.StateData;
29
import eu.etaxonomy.taxeditor.editor.UsageTermCollection;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31
import eu.etaxonomy.taxeditor.store.TermStore;
32
import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
33
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
34
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
35
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
36

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

    
48
	private static final Logger logger = Logger
49
			.getLogger(UseRecordDetailElement.class);
50

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

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

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

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

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

    
114
	}
115

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

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

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

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

    
200
	}
201

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

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

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

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

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

    
556
	/** {@inheritDoc} */
557
	@Override
558
	public void setEntity(CategoricalData entity) {
559
		super.setEntity(entity);
560
	}
561

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

    
608
	/** {@inheritDoc} */
609
	@Override
610
	public void widgetDefaultSelected(SelectionEvent e) {
611
		// TODO Auto-generated method stub
612

    
613
	}
614

    
615
}
(1-1/2)