Revision 49a64920
Added by Cherian Mathew over 10 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java | ||
---|---|---|
17 | 17 |
import org.apache.log4j.Logger; |
18 | 18 |
import org.eclipse.swt.events.SelectionEvent; |
19 | 19 |
import org.eclipse.swt.events.SelectionListener; |
20 |
|
|
21 |
import eu.etaxonomy.cdm.model.common.DefinedTerm; |
|
20 | 22 |
import eu.etaxonomy.cdm.model.common.Language; |
21 | 23 |
import eu.etaxonomy.cdm.model.common.LanguageString; |
22 | 24 |
import eu.etaxonomy.cdm.model.common.Marker; |
23 | 25 |
import eu.etaxonomy.cdm.model.description.CategoricalData; |
24 |
import eu.etaxonomy.cdm.model.description.Modifier; |
|
25 | 26 |
import eu.etaxonomy.cdm.model.description.State; |
26 | 27 |
import eu.etaxonomy.cdm.model.description.StateData; |
27 | 28 |
import eu.etaxonomy.taxeditor.editor.UsageTermCollection; |
... | ... | |
48 | 49 |
|
49 | 50 |
private TermComboElement<State> combo_UseCategory; |
50 | 51 |
private TermComboElement<State> combo_UseSubCategory; |
51 |
private TermComboElement<Modifier> combo_PlantPart;
|
|
52 |
private TermComboElement<Modifier> combo_Country;
|
|
53 |
private TermComboElement<Modifier> combo_HumanGroup;
|
|
54 |
private TermComboElement<Modifier> combo_EthnicGroup;
|
|
52 |
private TermComboElement<DefinedTerm> combo_PlantPart;
|
|
53 |
private TermComboElement<DefinedTerm> combo_Country;
|
|
54 |
private TermComboElement<DefinedTerm> combo_HumanGroup;
|
|
55 |
private TermComboElement<DefinedTerm> combo_EthnicGroup;
|
|
55 | 56 |
|
56 | 57 |
public UseRecordDetailElement(CdmFormFactory formFactory, |
57 | 58 |
ICdmFormElement formElement) { |
... | ... | |
66 | 67 |
combo_UseCategory = formFactory.createTermComboElement(State.class, this, UsageTermCollection.useCategoryVocabularyLabel, null, style); |
67 | 68 |
combo_UseCategory.addSelectionListener(this); |
68 | 69 |
combo_UseSubCategory = formFactory.createTermComboElement(State.class, this, UsageTermCollection.useSubCategoryVocabularyLabel, null, style); |
69 |
combo_PlantPart = formFactory.createTermComboElement(Modifier.class, this, UsageTermCollection.plantPartLabel, null, style);
|
|
70 |
combo_HumanGroup = formFactory.createTermComboElement(Modifier.class, this, UsageTermCollection.humanGroupLabel, 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);
|
|
71 | 72 |
combo_HumanGroup.addSelectionListener(this); |
72 |
combo_EthnicGroup = formFactory.createTermComboElement(Modifier.class, this, UsageTermCollection.ethnicGroupLabel, null, style);
|
|
73 |
combo_Country = formFactory.createTermComboElement(Modifier.class, this, UsageTermCollection.countryLabel, null, style);
|
|
73 |
combo_EthnicGroup = formFactory.createTermComboElement(DefinedTerm.class, this, UsageTermCollection.ethnicGroupLabel, null, style);
|
|
74 |
combo_Country = formFactory.createTermComboElement(DefinedTerm.class, this, UsageTermCollection.countryLabel, null, style);
|
|
74 | 75 |
|
75 | 76 |
|
76 | 77 |
List<State> termsUseCategory = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false)); |
... | ... | |
88 | 89 |
combo_UseSubCategory.setEnabled(false); |
89 | 90 |
} |
90 | 91 |
|
91 |
List<Modifier> plantPartsToAdd = setModifierComboTerms(TermStore.getTerms(Modifier.class, null, false), UsageTermCollection.plantPartLabel);
|
|
92 |
List<DefinedTerm> plantPartsToAdd = setModifierComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), UsageTermCollection.plantPartLabel);
|
|
92 | 93 |
combo_PlantPart.setTerms(plantPartsToAdd); |
93 | 94 |
combo_PlantPart.setSelection(modifierSelection(UsageTermCollection.plantPartLabel)); |
94 | 95 |
|
95 |
List<Modifier> countriesToAdd = setModifierComboTerms(TermStore.getTerms(Modifier.class, null, false), UsageTermCollection.countryLabel);
|
|
96 |
List<DefinedTerm> countriesToAdd = setModifierComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), UsageTermCollection.countryLabel);
|
|
96 | 97 |
combo_Country.setTerms(countriesToAdd); |
97 | 98 |
combo_Country.setSelection(modifierSelection(UsageTermCollection.countryLabel)); |
98 | 99 |
|
99 |
List<Modifier> humanGroupToAdd = setModifierComboTerms(TermStore.getTerms(Modifier.class, null, false), UsageTermCollection.humanGroupLabel);
|
|
100 |
List<DefinedTerm> humanGroupToAdd = setModifierComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), UsageTermCollection.humanGroupLabel);
|
|
100 | 101 |
combo_HumanGroup.setTerms(humanGroupToAdd); |
101 | 102 |
combo_HumanGroup.setSelection(modifierSelection(UsageTermCollection.humanGroupLabel)); |
102 | 103 |
|
103 |
List<Modifier> ethnicGroupToAdd = setEthnicGroupComboTerms(TermStore.getTerms(Modifier.class, null, false), combo_HumanGroup.getSelection());
|
|
104 |
List<DefinedTerm> ethnicGroupToAdd = setEthnicGroupComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), combo_HumanGroup.getSelection());
|
|
104 | 105 |
if (ethnicGroupToAdd != null) { |
105 | 106 |
combo_EthnicGroup.setTerms(ethnicGroupToAdd); |
106 | 107 |
combo_EthnicGroup.setSelection(modifierSelection(UsageTermCollection.ethnicGroupLabel)); |
... | ... | |
116 | 117 |
* @param comboCategory |
117 | 118 |
* @return |
118 | 119 |
*/ |
119 |
private Modifier modifierSelection(String comboCategory) {
|
|
120 |
private DefinedTerm modifierSelection(String comboCategory) {
|
|
120 | 121 |
if(!getEntity().getModifiers().isEmpty()) { |
121 |
for (Modifier modifier : getEntity().getModifiers()) {
|
|
122 |
for (DefinedTerm modifier : getEntity().getModifiers()) {
|
|
122 | 123 |
if(GetVocabularyType(modifier, comboCategory)) { |
123 | 124 |
return modifier; |
124 | 125 |
} |
... | ... | |
161 | 162 |
* @param modType |
162 | 163 |
* @return |
163 | 164 |
*/ |
164 |
private List<Modifier> setModifierComboTerms(List<Modifier> listOfTerms, String modType) {
|
|
165 |
List<Modifier> termsToAdd = new ArrayList<Modifier>();
|
|
166 |
for (Modifier term : listOfTerms) {
|
|
165 |
private List<DefinedTerm> setModifierComboTerms(List<DefinedTerm> listOfTerms, String modType) {
|
|
166 |
List<DefinedTerm> termsToAdd = new ArrayList<DefinedTerm>();
|
|
167 |
for (DefinedTerm term : listOfTerms) {
|
|
167 | 168 |
|
168 | 169 |
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(modType))) { |
169 | 170 |
termsToAdd.add(term); |
... | ... | |
250 | 251 |
* @param selectedHumangroup |
251 | 252 |
* @return |
252 | 253 |
*/ |
253 |
private List<Modifier> setEthnicGroupComboTerms(List<Modifier> listOfTerms,
|
|
254 |
Modifier selectedHumangroup) {
|
|
255 |
List<Modifier> termsToAdd = new ArrayList<Modifier>();
|
|
254 |
private List<DefinedTerm> setEthnicGroupComboTerms(List<DefinedTerm> listOfTerms,
|
|
255 |
DefinedTerm selectedHumangroup) {
|
|
256 |
List<DefinedTerm> termsToAdd = new ArrayList<DefinedTerm>();
|
|
256 | 257 |
if (combo_HumanGroup.getSelection() != null) { |
257 |
for (Modifier term : listOfTerms) {
|
|
258 |
for (DefinedTerm term : listOfTerms) {
|
|
258 | 259 |
|
259 | 260 |
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(selectedHumangroup.getTitleCache()))) { |
260 | 261 |
termsToAdd.add(term); |
... | ... | |
265 | 266 |
} |
266 | 267 |
} |
267 | 268 |
else if (!getEntity().getModifiers().isEmpty()) { |
268 |
for (Modifier modifier : getEntity().getModifiers()) {
|
|
269 |
for (DefinedTerm modifier : getEntity().getModifiers()) {
|
|
269 | 270 |
if (modifier.getMarkers() != null) { |
270 | 271 |
for (Marker marker : modifier.getMarkers()) { |
271 | 272 |
if(marker.getMarkerType().getTitleCache().equals(UsageTermCollection.humanGroupLabel)) { |
272 |
for (Modifier term : listOfTerms) {
|
|
273 |
for (DefinedTerm term : listOfTerms) {
|
|
273 | 274 |
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(modifier.getTitleCache()))) { |
274 | 275 |
termsToAdd.add(modifier); |
275 | 276 |
} else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(modifier.getTitleCache()))) { |
... | ... | |
408 | 409 |
} |
409 | 410 |
if (eventSource == combo_PlantPart) { |
410 | 411 |
if (combo_PlantPart.getSelection() != null) { |
411 |
Iterator<Modifier> itrExistingModifiers = getEntity().getModifiers().iterator();
|
|
412 |
Iterator<DefinedTerm> itrExistingModifiers = getEntity().getModifiers().iterator();
|
|
412 | 413 |
while (itrExistingModifiers.hasNext()) { |
413 |
Modifier modifier = itrExistingModifiers.next();
|
|
414 |
DefinedTerm modifier = itrExistingModifiers.next();
|
|
414 | 415 |
if(GetVocabularyType(modifier, UsageTermCollection.plantPartLabel)) { |
415 | 416 |
itrExistingModifiers.remove(); |
416 | 417 |
} |
417 | 418 |
|
418 | 419 |
} |
419 |
Modifier plantPart = combo_PlantPart.getSelection();
|
|
420 |
DefinedTerm plantPart = combo_PlantPart.getSelection();
|
|
420 | 421 |
getEntity().addModifier(plantPart); |
421 | 422 |
} else { |
422 |
Set<Modifier> modifiers = getEntity().getModifiers();
|
|
423 |
Set<DefinedTerm> modifiers = getEntity().getModifiers();
|
|
423 | 424 |
if(!modifiers.isEmpty()) { |
424 |
Iterator<Modifier> itr = modifiers.iterator();
|
|
425 |
Iterator<DefinedTerm> itr = modifiers.iterator();
|
|
425 | 426 |
while (itr.hasNext()) { |
426 |
Modifier currentMod = itr.next();
|
|
427 |
DefinedTerm currentMod = itr.next();
|
|
427 | 428 |
if(GetVocabularyType(currentMod, UsageTermCollection.plantPartLabel)) { |
428 | 429 |
itr.remove(); |
429 | 430 |
} |
... | ... | |
434 | 435 |
} |
435 | 436 |
if (eventSource == combo_Country) { |
436 | 437 |
if (combo_Country.getSelection() != null) { |
437 |
Iterator<Modifier> itrExistingModifiers = getEntity().getModifiers().iterator();
|
|
438 |
Iterator<DefinedTerm> itrExistingModifiers = getEntity().getModifiers().iterator();
|
|
438 | 439 |
while (itrExistingModifiers.hasNext()) { |
439 |
Modifier modifier = itrExistingModifiers.next();
|
|
440 |
DefinedTerm modifier = itrExistingModifiers.next();
|
|
440 | 441 |
if(GetVocabularyType(modifier, UsageTermCollection.countryLabel)) { |
441 | 442 |
itrExistingModifiers.remove(); |
442 | 443 |
} |
443 | 444 |
|
444 | 445 |
} |
445 |
Modifier country = combo_Country.getSelection();
|
|
446 |
DefinedTerm country = combo_Country.getSelection();
|
|
446 | 447 |
getEntity().addModifier(country); |
447 | 448 |
} else { |
448 |
Set<Modifier> modifiers = getEntity().getModifiers();
|
|
449 |
Set<DefinedTerm> modifiers = getEntity().getModifiers();
|
|
449 | 450 |
if(!modifiers.isEmpty()) { |
450 |
Iterator<Modifier> itr = modifiers.iterator();
|
|
451 |
Iterator<DefinedTerm> itr = modifiers.iterator();
|
|
451 | 452 |
while (itr.hasNext()) { |
452 |
Modifier currentMod = itr.next();
|
|
453 |
DefinedTerm currentMod = itr.next();
|
|
453 | 454 |
if(GetVocabularyType(currentMod, UsageTermCollection.countryLabel)) { |
454 | 455 |
itr.remove(); |
455 | 456 |
} |
... | ... | |
460 | 461 |
if (eventSource == combo_HumanGroup) { |
461 | 462 |
if (combo_HumanGroup.getSelection() != null) { |
462 | 463 |
boolean isHumanGroupChanged = true; |
463 |
for (Modifier modToCheck: getEntity().getModifiers()) {
|
|
464 |
for (DefinedTerm modToCheck: getEntity().getModifiers()) {
|
|
464 | 465 |
if(modToCheck.equals(combo_HumanGroup.getSelection()) && (GetVocabularyType(modToCheck, UsageTermCollection.humanGroupLabel))) { |
465 | 466 |
isHumanGroupChanged = false; |
466 | 467 |
} |
467 | 468 |
|
468 | 469 |
|
469 | 470 |
} |
470 |
Iterator<Modifier> itrExistingModifiers = getEntity().getModifiers().iterator();
|
|
471 |
Iterator<DefinedTerm> itrExistingModifiers = getEntity().getModifiers().iterator();
|
|
471 | 472 |
while (itrExistingModifiers.hasNext()) { |
472 |
Modifier modifier = itrExistingModifiers.next();
|
|
473 |
DefinedTerm modifier = itrExistingModifiers.next();
|
|
473 | 474 |
if((GetVocabularyType(modifier, UsageTermCollection.humanGroupLabel) || GetVocabularyType(modifier, UsageTermCollection.ethnicGroupLabel)) && isHumanGroupChanged) { |
474 | 475 |
itrExistingModifiers.remove(); |
475 | 476 |
} |
476 | 477 |
|
477 | 478 |
} |
478 | 479 |
if(isHumanGroupChanged){ |
479 |
Modifier humanGroup = combo_HumanGroup.getSelection();
|
|
480 |
DefinedTerm humanGroup = combo_HumanGroup.getSelection();
|
|
480 | 481 |
getEntity().addModifier(humanGroup); |
481 | 482 |
} |
482 | 483 |
combo_EthnicGroup.setEnabled(true); |
483 | 484 |
} else { |
484 |
Set<Modifier> modifiers = getEntity().getModifiers();
|
|
485 |
Set<DefinedTerm> modifiers = getEntity().getModifiers();
|
|
485 | 486 |
if(!modifiers.isEmpty()) { |
486 |
Iterator<Modifier> itr = modifiers.iterator();
|
|
487 |
Iterator<DefinedTerm> itr = modifiers.iterator();
|
|
487 | 488 |
while (itr.hasNext()) { |
488 |
Modifier currentMod = itr.next();
|
|
489 |
DefinedTerm currentMod = itr.next();
|
|
489 | 490 |
if(GetVocabularyType(currentMod, UsageTermCollection.humanGroupLabel) || GetVocabularyType(currentMod, UsageTermCollection.ethnicGroupLabel)) { |
490 | 491 |
itr.remove(); |
491 | 492 |
} |
492 | 493 |
} |
493 | 494 |
} |
494 |
List<Modifier> emptyListToResetComboBox = new ArrayList<Modifier>();
|
|
495 |
Modifier emptyMod = Modifier.NewInstance();
|
|
495 |
List<DefinedTerm> emptyListToResetComboBox = new ArrayList<DefinedTerm>();
|
|
496 |
DefinedTerm emptyMod = DefinedTerm.NewInstance();
|
|
496 | 497 |
emptyListToResetComboBox.add(emptyMod); |
497 | 498 |
combo_EthnicGroup.setTerms(emptyListToResetComboBox); |
498 | 499 |
combo_EthnicGroup.setEnabled(false); |
... | ... | |
501 | 502 |
} |
502 | 503 |
if (eventSource == combo_EthnicGroup) { |
503 | 504 |
if (combo_EthnicGroup.getSelection() != null) { |
504 |
Iterator<Modifier> itrExistingModifiers = getEntity().getModifiers().iterator();
|
|
505 |
Iterator<DefinedTerm> itrExistingModifiers = getEntity().getModifiers().iterator();
|
|
505 | 506 |
while (itrExistingModifiers.hasNext()) { |
506 |
Modifier modifier = itrExistingModifiers.next();
|
|
507 |
DefinedTerm modifier = itrExistingModifiers.next();
|
|
507 | 508 |
if(GetVocabularyType(modifier, combo_HumanGroup.getSelection().getTitleCache())) { |
508 | 509 |
itrExistingModifiers.remove(); |
509 | 510 |
} |
510 | 511 |
|
511 | 512 |
} |
512 |
Modifier ethnicGroup = combo_EthnicGroup.getSelection();
|
|
513 |
DefinedTerm ethnicGroup = combo_EthnicGroup.getSelection();
|
|
513 | 514 |
getEntity().addModifier(ethnicGroup); |
514 | 515 |
} else { |
515 |
Set<Modifier> modifiers = getEntity().getModifiers();
|
|
516 |
Set<DefinedTerm> modifiers = getEntity().getModifiers();
|
|
516 | 517 |
if(!modifiers.isEmpty()) { |
517 | 518 |
|
518 |
Iterator<Modifier> itr = modifiers.iterator();
|
|
519 |
Iterator<DefinedTerm> itr = modifiers.iterator();
|
|
519 | 520 |
while (itr.hasNext()) { |
520 |
Modifier currentMod = itr.next();
|
|
521 |
DefinedTerm currentMod = itr.next();
|
|
521 | 522 |
if(GetVocabularyType(currentMod, UsageTermCollection.ethnicGroupLabel)) { |
522 | 523 |
itr.remove(); |
523 | 524 |
} |
... | ... | |
536 | 537 |
* @param vocabularyExpected |
537 | 538 |
* @return |
538 | 539 |
*/ |
539 |
private boolean GetVocabularyType(Modifier term, String vocabularyExpected) {
|
|
540 |
private boolean GetVocabularyType(DefinedTerm term, String vocabularyExpected) {
|
|
540 | 541 |
if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(vocabularyExpected))) { |
541 | 542 |
return true; |
542 | 543 |
} |
... | ... | |
585 | 586 |
} |
586 | 587 |
for (Object object: combo_HumanGroup.getControls()) { |
587 | 588 |
if (object == eventSource) { |
588 |
Modifier selectedHumanGroup = combo_HumanGroup.getSelection();
|
|
589 |
DefinedTerm selectedHumanGroup = combo_HumanGroup.getSelection();
|
|
589 | 590 |
if (selectedHumanGroup != null) { |
590 |
combo_EthnicGroup.setTerms(setEthnicGroupComboTerms(TermStore.getTerms(Modifier.class, null, false), selectedHumanGroup));
|
|
591 |
combo_EthnicGroup.setTerms(setEthnicGroupComboTerms(TermStore.getTerms(DefinedTerm.class, null, false), selectedHumanGroup));
|
|
591 | 592 |
if (!getEntity().getModifiers().isEmpty()) { |
592 |
Iterator<Modifier> iterModifiers = getEntity().getModifiers().iterator();
|
|
593 |
Iterator<DefinedTerm> iterModifiers = getEntity().getModifiers().iterator();
|
|
593 | 594 |
while (iterModifiers.hasNext()) { |
594 |
Modifier existingModifier = iterModifiers.next();
|
|
595 |
DefinedTerm existingModifier = iterModifiers.next();
|
|
595 | 596 |
if(GetVocabularyType(existingModifier, UsageTermCollection.ethnicGroupLabel)) { |
596 | 597 |
combo_EthnicGroup.setSelection(modifierSelection(UsageTermCollection.ethnicGroupLabel)); |
597 | 598 |
} |
Also available in: Unified diff
Aligning Editor with 3.3 model changes. First phase commit which updates only the classes.
Branch not compilable at the moment.