AT: commiting latest changes to the Palm Use data extension
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / userecords / UseRecordDetailElement.java
1 package eu.etaxonomy.taxeditor.ui.section.userecords;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.Map;
6 import java.util.Set;
7 import java.util.UUID;
8
9 import org.apache.log4j.Logger;
10 import org.eclipse.swt.events.SelectionEvent;
11 import org.eclipse.swt.events.SelectionListener;
12 import org.eclipse.ui.forms.widgets.Section;
13
14 import eu.etaxonomy.cdm.api.service.IService;
15 import eu.etaxonomy.cdm.api.service.IVocabularyService;
16 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
17 import eu.etaxonomy.cdm.model.common.Language;
18 import eu.etaxonomy.cdm.model.common.LanguageString;
19 import eu.etaxonomy.cdm.model.common.Marker;
20 import eu.etaxonomy.cdm.model.common.MarkerType;
21 import eu.etaxonomy.cdm.model.common.TermVocabulary;
22 import eu.etaxonomy.cdm.model.description.CategoricalData;
23 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
24 import eu.etaxonomy.cdm.model.description.Modifier;
25 import eu.etaxonomy.cdm.model.description.State;
26 import eu.etaxonomy.cdm.model.description.StateData;
27 import eu.etaxonomy.cdm.remote.controller.VocabularyController;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29 import eu.etaxonomy.taxeditor.store.TermManager;
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.CheckboxElement;
34 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
35 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.EntityDetailType;
36 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
37 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailElement;
38 import eu.etaxonomy.taxeditor.ui.section.description.StateDataSection;
39 import eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement;
40
41 //public class UseRecordDetailElement extends AbstractDetailedDescriptionDetailElement<CategoricalData> {
42 public class UseRecordDetailElement extends
43 AbstractCdmDetailElement<CategoricalData> implements SelectionListener {
44
45 private static final Logger logger = Logger
46 .getLogger(DescriptionElementDetailElement.class);
47
48 // private CheckboxElement checkbox_orderRelevant;
49 private TermComboElement<State> combo_UseCategory;
50 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;
55 // private AbstractDetailedDescriptionDetailElement detailElement;
56
57 /*
58 * public UseRecordDetailElement(CdmFormFactory formFactory, ICdmFormElement
59 * formElement, CategoricalData entity, int style) { super(formFactory,
60 * formElement, entity, style); }
61 */
62 /*
63 * public UseRecordDetailElement(CdmFormFactory formFactory, ICdmFormElement
64 * formElement, int style) {
65 */
66 public UseRecordDetailElement(CdmFormFactory formFactory,
67 ICdmFormElement formElement) {
68 super(formFactory, formElement);
69 }
70
71 /** {@inheritDoc} */
72 @Override
73 protected void createControls(ICdmFormElement formElement,
74 CategoricalData entity, int style) {
75
76 // State state = State.NewInstance("Tato", "Toto", "Titi");
77 // checkbox_orderRelevant = formFactory.createCheckbox(formElement,
78 // "Order Relevant", entity.getOrderRelevant(), style);
79 combo_UseCategory = formFactory.createTermComboElement(State.class, this, "Use Category", null, style);
80 combo_UseCategory.addSelectionListener(this);
81 combo_UseSubCategory = formFactory.createTermComboElement(State.class, this, "Use SubCategory", null, style);
82 combo_Country = formFactory.createTermComboElement(Modifier.class, this, "Country", null, style);
83 combo_PlantPart = formFactory.createTermComboElement(Modifier.class, this, "Plant Part", null, style);
84 combo_HumanGroup = formFactory.createTermComboElement(Modifier.class, this, "Human Group", null, style);
85 combo_HumanGroup.addSelectionListener(this);
86 combo_EthnicGroup = formFactory.createTermComboElement(Modifier.class, this, "Ethnic Group", null, style);
87
88
89 List<State> termsUseCategory = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false));
90 combo_UseCategory.setTerms(termsUseCategory);
91 combo_UseCategory.setSelection(stateSelection("Use Category"));
92
93 List<State> termsSubCategory = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false), combo_UseCategory.getSelection());
94
95 if (termsSubCategory != null) {
96
97 combo_UseSubCategory.setTerms(termsSubCategory);
98 combo_UseSubCategory.setSelection(stateSelection("Use SubCategory"));
99 combo_UseSubCategory.setEnabled(true);
100 }
101 else {
102 combo_UseSubCategory.setEnabled(false);
103 }
104
105 List<Modifier> plantPartsToAdd = setModifierComboTerms(TermStore.getTerms(Modifier.class, null, false), "Plant Part");
106 combo_PlantPart.setTerms(plantPartsToAdd);
107 combo_PlantPart.setSelection(modifierSelection("Plant Part"));
108
109 List<Modifier> countriesToAdd = setModifierComboTerms(TermStore.getTerms(Modifier.class, null, false), "Country");
110 combo_Country.setTerms(countriesToAdd);
111 combo_Country.setSelection(modifierSelection("Country"));
112
113 List<Modifier> humanGroupToAdd = setModifierComboTerms(TermStore.getTerms(Modifier.class, null, false), "Human Group");
114 combo_HumanGroup.setTerms(humanGroupToAdd);
115 combo_HumanGroup.setSelection(modifierSelection("Human Group"));
116
117 List<Modifier> ethnicGroupToAdd = setEthnicGroupComboTerms(TermStore.getTerms(Modifier.class, null, false), combo_HumanGroup.getSelection());
118 if (ethnicGroupToAdd != null) {
119 combo_EthnicGroup.setTerms(ethnicGroupToAdd);
120 combo_EthnicGroup.setSelection(modifierSelection("Ethnic Group"));
121 combo_EthnicGroup.setEnabled(true);
122 } else {
123 combo_EthnicGroup.setEnabled(false);
124 }
125
126 }
127
128 private Modifier modifierSelection(String comboCategory) {
129 if(!getEntity().getModifiers().isEmpty()) {
130 for (Modifier modifier : getEntity().getModifiers()) {
131 if (modifier.getMarkers() != null) {
132 for (Marker marker : modifier.getMarkers()) {
133 if(marker.getMarkerType().getTitleCache().equals(comboCategory)) {
134 return modifier;
135 }
136 else {
137 return null;
138 }
139 }
140 }
141 else {
142 return null;
143 }
144
145 }
146 } else {
147 return null;
148 }
149 return null;
150
151 }
152
153 private State stateSelection(String comboCategory) {
154 if (!getEntity().getStates().isEmpty()) {
155 for (StateData statedata : getEntity().getStates()) {
156 if (statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
157 if(statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText() == comboCategory) {
158 if(statedata.getState() !=null) {
159 return statedata.getState();
160 }
161 }
162 }
163 }
164 }
165 else {
166 return null;
167 }
168 return null;
169
170 }
171
172 private List<Modifier> setModifierComboTerms(List<Modifier> listOfTerms, String modType) {
173 List<Modifier> termsToAdd = new ArrayList<Modifier>();
174 for (Modifier term : listOfTerms) {
175
176 if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(modType))) {
177 termsToAdd.add(term);
178 }
179 else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(modType))) {
180 termsToAdd.add(term);
181 }
182 }
183
184 return termsToAdd;
185 }
186
187 private Modifier plantPartSelection() {
188 /*if(!getEntity().getModifiers().isEmpty()) {
189 for (Modifier modifier : getEntity().getModifiers()) {
190 if (modifier.getMarkers() != null) {
191 for (Marker marker : modifier.getMarkers()) {
192 if(marker.getMarkerType().getTitleCache().equals("Plant Part")) {
193 return modifier;
194 }
195 else {
196 return null;
197 }
198 }
199 }
200 else {
201 return null;
202 }
203
204 }
205 } else {
206 return null;
207 }
208 return null;*/
209 //for testing purposes
210 int countMods = 0;
211 Modifier modiftoreturn = Modifier.NewInstance();
212 if (!getEntity().getModifiers().isEmpty()) {
213 for (Modifier modifier : getEntity().getModifiers()){
214 if(countMods == 0) {
215 modiftoreturn = modifier;
216 }
217 countMods++;
218 }
219 return modiftoreturn;
220 }
221 return null;
222
223 }
224
225 private Modifier countrySelection() {
226 /*if(!getEntity().getModifiers().isEmpty()) {
227 for (Modifier modifier : getEntity().getModifiers()) {
228 if (modifier.getMarkers() != null) {
229 for (Marker marker : modifier.getMarkers()) {
230 if(marker.getMarkerType().getTitleCache().equals("Country")) {
231 return modifier;
232 }
233 else {
234 return null;
235 }
236 }
237 }
238 else {
239 return null;
240 }
241
242 }
243 } else {
244 return null;
245 }
246 return null;*/
247 //for testing purposes
248 int countMods = 0;
249 Modifier modiftoreturn = Modifier.NewInstance();
250 if (!getEntity().getModifiers().isEmpty()) {
251 for (Modifier modifier : getEntity().getModifiers()){
252 if(countMods == 1) {
253 modiftoreturn = modifier;
254 }
255 countMods++;
256 }
257 return modiftoreturn;
258 }
259 return null;
260 }
261
262 private Modifier humanGroupSelection() {
263 /*if(!getEntity().getModifiers().isEmpty()) {
264 for (Modifier modifier : getEntity().getModifiers()) {
265 if (modifier.getMarkers() != null) {
266 for (Marker marker : modifier.getMarkers()) {
267 if(marker.getMarkerType().getTitleCache().equals("Human Group")) {
268 return modifier;
269 }
270 else {
271 return null;
272 }
273 }
274 }
275 else {
276 return null;
277 }
278
279 }
280 } else {
281 return null;
282 }
283 return null;*/
284 //for testing purposes
285 int countMods =0;
286 Modifier modiftoreturn = Modifier.NewInstance();
287 if (!getEntity().getModifiers().isEmpty()) {
288 for (Modifier modifier : getEntity().getModifiers()){
289 if (countMods == 2) {
290 modiftoreturn = modifier;
291 }
292 countMods++;
293 }
294 return modiftoreturn;
295 }
296 return null;
297 }
298
299 private Modifier ethnicGroupSelection() {
300 /*if(!getEntity().getModifiers().isEmpty()) {
301 for (Modifier modifier : getEntity().getModifiers()) {
302 if (modifier.getMarkers() != null) {
303 for (Marker marker : modifier.getMarkers()) {
304 if(marker.getMarkerType().getTitleCache().equals("Human Group")) {
305 return modifier;
306 }
307 else {
308 return null;
309 }
310 }
311 }
312 else {
313 return null;
314 }
315
316 }
317 } else {
318 return null;
319 }
320 return null;*/
321 //for testing purposes
322 int countMods =0;
323 Modifier modiftoreturn = Modifier.NewInstance();
324 if (!getEntity().getModifiers().isEmpty()) {
325 for (Modifier modifier : getEntity().getModifiers()){
326 if (countMods == 3) {
327 modiftoreturn = modifier;
328 }
329 countMods++;
330 }
331 return modiftoreturn;
332 }
333 return null;
334 }
335
336 private State useCategorySelection() {
337 /*if (!getEntity().getStates().isEmpty()) {
338 for (StateData statedata : getEntity().getStates()) {
339 if (statedata.getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
340 if(statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText() == "Use Category") {
341 if(statedata.getState() !=null) {
342 return statedata.getState();
343 }
344 }
345 }
346 }
347 }
348 else {
349 return null;
350 }
351 return null;*/
352 //for testing purposes
353 int countStates =0;
354 for (StateData state : getEntity().getStates()) {
355 if (countStates == 0) {
356 return state.getState();
357 }
358 countStates++;
359 }
360 return null;
361 }
362
363
364
365 private State useSubCategorySelection() {
366 /*if (!getEntity().getStates().isEmpty() && combo_UseCategory.getSelection() != null) {
367 for (StateData statedata : getEntity().getStates()) {
368 if (stateData.getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
369 if(statedata.getModifyingText().get(CdmStore.getDefaultLanguage()).getText() == "Use SubCategory") {
370 if(statedata.getState() !=null) {
371 return statedata.getState();
372 }
373
374 }
375 }
376 }
377 }
378 else {
379 return null;
380 }
381 return null;*/
382 //for testing purposes
383 int countStates =0;
384 for (StateData state : getEntity().getStates()) {
385 if ((countStates == 1)) {
386 return state.getState();
387 }
388 countStates++;
389 }
390 return null;
391
392 }
393
394
395
396
397 private List<Modifier> setPlantPartsComboTerms(List<Modifier> listOfTerms) {
398 List<Modifier> termsToAdd = new ArrayList<Modifier>();
399 for (Modifier term : listOfTerms) {
400
401 if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals("Plant Part"))) {
402 termsToAdd.add(term);
403 }
404 else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals("Plant Part"))) {
405 termsToAdd.add(term);
406 }
407 }
408
409 return termsToAdd;
410 }
411
412 private List<Modifier> setCountryComboTerms(List <Modifier> listOfTerms) {
413 List<Modifier> termsToAdd = new ArrayList<Modifier>();
414 for (Modifier term : listOfTerms) {
415
416 if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals("Country"))) {
417 termsToAdd.add(term);
418 }
419 else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals("Country"))) {
420 termsToAdd.add(term);
421 }
422 }
423
424 return termsToAdd;
425 }
426
427
428 private List<State> setUseCategoryComboTerms(List<State> listOfTerms) {
429 List<State> termsToAdd = new ArrayList<State>();
430 for (State term : listOfTerms) {
431
432 if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals("Use Category"))) {
433 termsToAdd.add(term);
434 }
435 else if ((term.getVocabulary() !=null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals("Use Category"))) {
436 termsToAdd.add(term);
437 }
438 }
439 return termsToAdd;
440
441 }
442
443 private List<State> setUseCategoryComboTerms(List<State> listOfTerms,
444 State selectedUseCategory) {
445 List<State> termsToAdd = new ArrayList<State>();
446 if (combo_UseCategory.getSelection() != null) {
447
448 for (State term : listOfTerms) {
449 if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(selectedUseCategory.getTitleCache()))) {
450 termsToAdd.add(term);
451 }
452 else if ((term.getVocabulary() !=null) && (term.getVocabulary().getTitleCache().equals(selectedUseCategory.getTitleCache()))) {
453 termsToAdd.add(term);
454 }
455
456 }
457 }
458 else if (!getEntity().getStates().isEmpty()) {
459 for (StateData stateData : getEntity().getStates()) {
460 if (stateData.getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
461 if ((stateData.getState() != null) && (stateData.getModifyingText().get(CdmStore.getDefaultLanguage()).getText() == "Use Category")) {
462 for (State term : listOfTerms) {
463 if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(stateData.getState().getTitleCache()))) {
464 termsToAdd.add(term);
465 } else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(stateData.getState().getTitleCache()))) {
466 termsToAdd.add(term);
467 }
468 }
469
470 }
471 }
472 }
473
474 }
475
476 else {
477 return null;
478 }
479
480 return termsToAdd;
481 }
482
483 private List<Modifier> setEthnicGroupComboTerms(List<Modifier> listOfTerms,
484 Modifier selectedHumangroup) {
485 List<Modifier> termsToAdd = new ArrayList<Modifier>();
486 if (combo_HumanGroup.getSelection() != null) {
487 for (Modifier term : listOfTerms) {
488
489 if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(selectedHumangroup.getTitleCache()))) {
490 termsToAdd.add(term);
491 }
492 else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(selectedHumangroup.getTitleCache()))) {
493 termsToAdd.add(term);
494 }
495 }
496 }
497 else if (!getEntity().getModifiers().isEmpty()) {
498 for (Modifier modifier : getEntity().getModifiers()) {
499 if (modifier.getMarkers() != null) {
500 for (Marker marker : modifier.getMarkers()) {
501 if(marker.getMarkerType().getTitleCache().equals("Human Group")) {
502 for (Modifier term : listOfTerms) {
503 if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals(modifier.getTitleCache()))) {
504 termsToAdd.add(modifier);
505 } else if ((term.getVocabulary() != null) && (term.getVocabulary().getTitleCache().equals(modifier.getTitleCache()))) {
506 termsToAdd.add(modifier);
507 }
508 }
509
510 }
511 }
512 }
513 }
514 } else {
515 return null;
516 }
517
518 return termsToAdd;
519 }
520
521
522 private List<Modifier> setHumanGroupComboTerms(List<Modifier> listOfTerms) {
523 List<Modifier> termsToAdd = new ArrayList<Modifier>();
524 for (Modifier term : listOfTerms) {
525
526 if ((term.getPartOf() != null) && (term.getPartOf().getTitleCache().equals("Human Group"))) {
527 termsToAdd.add(term);
528 }
529 else if ((term.getVocabulary() != null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals("Human Group"))) {
530 termsToAdd.add(term);
531 }
532 }
533
534 return termsToAdd;
535 }
536
537
538 /** {@inheritDoc} */
539 @Override
540 public void handleEvent(Object eventSource) {
541 /*
542 * if(eventSource == checkbox_orderRelevant){
543 * getEntity().setOrderRelevant(checkbox_orderRelevant.getSelection());
544 * }
545 */
546 if (eventSource == combo_UseCategory) {
547 if (combo_UseCategory.getSelection() != null) {
548 boolean isChanged = false;
549 if (!getEntity().getStates().isEmpty()) {
550 for (StateData existingStateData : getEntity().getStates()) {
551 Map<Language, LanguageString> modifyingText = existingStateData
552 .getModifyingText();
553
554 if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
555 if (modifyingText.get(CdmStore.getDefaultLanguage())
556 .getText() == "Use Category") {
557 getEntity().removeState(existingStateData);
558 StateData stateData = StateData.NewInstance(combo_UseCategory.getSelection());
559 stateData.setState(combo_UseCategory.getSelection());
560 //stateData.addModifyingText("Use Category", CdmStore.getDefaultLanguage());
561 stateData.putModifyingText(CdmStore.getDefaultLanguage(),"Use Category");
562 getEntity().addState(stateData);
563 isChanged = true;
564 }
565 /*else {
566 StateData stateData = StateData
567 .NewInstance(combo_UseCategory.getSelection());
568 stateData.setState(combo_UseCategory.getSelection());
569 //stateData.addModifyingText("Use Category", CdmStore.getDefaultLanguage());
570 stateData.putModifyingText(CdmStore.getDefaultLanguage(),"Use Category");
571 getEntity().addState(stateData);
572 }
573
574 } else {
575 StateData stateData = StateData
576 .NewInstance(combo_UseCategory.getSelection());
577 stateData.setState(combo_UseCategory.getSelection());
578 //stateData.addModifyingText("Use Category", CdmStore.getDefaultLanguage());
579 stateData.putModifyingText(CdmStore.getDefaultLanguage(), "Use Category");
580 getEntity().addState(stateData);
581 }*/
582 }
583 }
584 }
585
586
587 if (isChanged == false) {
588 StateData stateData = StateData
589 .NewInstance(combo_UseCategory.getSelection());
590 stateData.setState(combo_UseCategory.getSelection());
591 //stateData.addModifyingText("Use Category", CdmStore.getDefaultLanguage());
592 //LanguageString languageString = LanguageString.NewInstance("Use Category", CdmStore.getDefaultLanguage());
593 //IService object = (IService) CdmStore.getCurrentApplicationConfiguration().getBean(IService.class.getName());
594 //object.save(languageString);
595 stateData.putModifyingText(CdmStore.getDefaultLanguage(), "Use Category");
596 getEntity().addState(stateData);
597 }
598 combo_UseSubCategory.setEnabled(true);
599
600 }
601 }
602 if (eventSource == combo_UseSubCategory) {
603 if (combo_UseSubCategory.getSelection() != null) {
604 boolean isChanged = false;
605 if (!getEntity().getStates().isEmpty()) {
606 for (StateData existingStateData : getEntity().getStates()) {
607 Map<Language, LanguageString> modifyingText = existingStateData
608 .getModifyingText();
609
610 if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
611 if (modifyingText.get(CdmStore.getDefaultLanguage())
612 .getText() == "Use SubCategory") {
613 getEntity().removeState(existingStateData);
614 StateData stateData = StateData.NewInstance(combo_UseSubCategory.getSelection());
615 stateData.setState(combo_UseSubCategory.getSelection());
616 //stateData.addModifyingText("Use SubCategory", CdmStore.getDefaultLanguage());
617 stateData.putModifyingText(CdmStore.getDefaultLanguage(),"Use SubCategory");
618 getEntity().addState(stateData);
619 isChanged = true;
620 }
621 /*else {
622 StateData stateData = StateData
623 .NewInstance(combo_UseSubCategory.getSelection());
624 stateData.setState(combo_UseSubCategory.getSelection());
625 //stateData.addModifyingText("Use SubCategory", CdmStore.getDefaultLanguage());
626 stateData.putModifyingText(CdmStore.getDefaultLanguage(),"Use SubCategory");
627 getEntity().addState(stateData);
628 }
629
630 } else {
631 StateData stateData = StateData
632 .NewInstance(combo_UseSubCategory.getSelection());
633 stateData.setState(combo_UseSubCategory.getSelection());
634 //stateData.addModifyingText("Use SubCategory", CdmStore.getDefaultLanguage());
635 stateData.putModifyingText(CdmStore.getDefaultLanguage(), "Use SubCategory");
636 getEntity().addState(stateData);
637 }*/
638 }
639 }
640 }
641
642 if (isChanged == false){
643 StateData stateData = StateData
644 .NewInstance(combo_UseSubCategory.getSelection());
645 stateData.setState(combo_UseSubCategory.getSelection());
646 //stateData.addModifyingText("Use SubCategory", CdmStore.getDefaultLanguage());
647 //LanguageString languageString = LanguageString.NewInstance("Use SubCategory", CdmStore.getDefaultLanguage());
648 //IService object = (IService) CdmStore.getCurrentApplicationConfiguration().getBean(IService.class.getName());
649 //object.save(languageString);
650 //stateData.putModifyingText(languageString);
651 stateData.putModifyingText(CdmStore.getDefaultLanguage(), "Use SubCategory");
652 getEntity().addState(stateData);
653 }
654
655 }
656 }
657 if (eventSource == combo_PlantPart) {
658 if (combo_PlantPart.getSelection() != null) {
659 boolean isChanged = false;
660 MarkerType markerType = MarkerType.NewInstance("Plant Part", "Plant Part", null);
661 Set<Modifier> modifiers = getEntity().getModifiers();
662 if(!modifiers.isEmpty()) {
663 for (Modifier modifier : modifiers) {
664 if (modifier.getMarkers() != null) {
665 for (Marker marker : modifier.getMarkers()) {
666 if (marker.getMarkerType().getTitleCache().equals("Plant Part")) {
667 getEntity().removeModifier(modifier);
668 Modifier plantPart = combo_PlantPart.getSelection();
669 plantPart.addMarker(marker);
670 getEntity().addModifier(plantPart);
671 isChanged = true;
672 //getEntity().addModifier(combo_PlantPart.getSelection());
673 }
674 /*else {
675
676 Marker markerPlantPart = Marker.NewInstance(markerType, false);
677 Modifier plantPart = combo_PlantPart.getSelection();
678 plantPart.addMarker(markerPlantPart);
679 getEntity().addModifier(plantPart);
680 //getEntity().addModifier(combo_PlantPart.getSelection());
681 }*/
682
683
684 }
685
686 }
687 /*else {
688 //MarkerType markerType = MarkerType.NewInstance("Plant Part", "Plant Part", null);
689 Marker marker = Marker.NewInstance(markerType, false);
690 Modifier plantPart = combo_PlantPart.getSelection();
691 plantPart.addMarker(marker);
692 getEntity().addModifier(plantPart);
693 //getEntity().addModifier(combo_PlantPart.getSelection());
694 }*/
695
696 }
697 }
698 if(isChanged == false) {
699 //MarkerType markerType = MarkerType.NewInstance("Plant Part", "Plant Part", null);
700 Marker marker = Marker.NewInstance(markerType, false);
701 Modifier plantPart = combo_PlantPart.getSelection();
702 plantPart.addMarker(marker);
703 getEntity().addModifier(plantPart);
704 //getEntity().addModifier(combo_PlantPart.getSelection());
705 }
706 }
707 }
708 if (eventSource == combo_Country) {
709 if (combo_Country.getSelection() != null) {
710 boolean isChanged = false;
711 MarkerType markerType = MarkerType.NewInstance("Country", "Country", null);
712 Set<Modifier> modifiers = getEntity().getModifiers();
713 if(!modifiers.isEmpty()) {
714 for (Modifier modifier : modifiers) {
715 if (modifier.getMarkers() != null) {
716 for (Marker marker : modifier.getMarkers()) {
717 if (marker.getMarkerType().getTitleCache().equals("Country")) {
718 getEntity().removeModifier(modifier);
719 Modifier country = combo_Country.getSelection();
720 country.addMarker(marker);
721 getEntity().addModifier(country);
722 isChanged = true;
723 //getEntity().addModifier(combo_Country.getSelection());
724 }
725 /*else {
726
727 Marker markerCountry = Marker.NewInstance(markerType, false);
728 Modifier country = combo_Country.getSelection();
729 country.addMarker(markerCountry);
730 getEntity().addModifier(country);
731 //getEntity().addModifier(combo_Country.getSelection());
732 }*/
733
734
735 }
736
737 }
738 /*else {
739 //MarkerType markerType = MarkerType.NewInstance("Country", "Country", null);
740 Marker marker = Marker.NewInstance(markerType, false);
741 Modifier country = combo_Country.getSelection();
742 country.addMarker(marker);
743 getEntity().addModifier(country);
744 //getEntity().addModifier(combo_Country.getSelection());
745 }*/
746
747 }
748 }
749 if (isChanged == false) {
750 //MarkerType markerType = MarkerType.NewInstance("Country", "Country", null);
751 Marker marker = Marker.NewInstance(markerType, false);
752 Modifier country = combo_Country.getSelection();
753 country.addMarker(marker);
754 getEntity().addModifier(country);
755 //getEntity().addModifier(combo_Country.getSelection());
756 }
757 }
758 }
759 if (eventSource == combo_HumanGroup) {
760 if (combo_HumanGroup.getSelection() != null) {
761 boolean isChanged = false;
762 MarkerType markerType = MarkerType.NewInstance("Human Group", "Human Group", null);
763 Set<Modifier> modifiers = getEntity().getModifiers();
764 if(!modifiers.isEmpty()) {
765 for (Modifier modifier : modifiers) {
766 if (modifier.getMarkers() != null) {
767 for (Marker marker : modifier.getMarkers()) {
768 if (marker.getMarkerType().getTitleCache().equals("Human Group")) {
769 getEntity().removeModifier(modifier);
770 Modifier humanGroup = combo_HumanGroup.getSelection();
771 humanGroup.addMarker(marker);
772 getEntity().addModifier(humanGroup);
773 isChanged = true;
774 //getEntity().addModifier(combo_HumanGroup.getSelection());
775 }
776 /*else {
777
778 Marker markerHumanGroup = Marker.NewInstance(markerType, false);
779 Modifier humanGroup = combo_HumanGroup.getSelection();
780 humanGroup.addMarker(markerHumanGroup);
781 getEntity().addModifier(humanGroup);
782 //getEntity().addModifier(combo_HumanGroup.getSelection());
783 }*/
784
785
786 }
787
788 }
789 /*else {
790 //MarkerType markerType = MarkerType.NewInstance("Human Group", "Human Group", null);
791 Marker marker = Marker.NewInstance(markerType, false);
792 Modifier humanGroup = combo_HumanGroup.getSelection();
793 humanGroup.addMarker(marker);
794 getEntity().addModifier(humanGroup);
795 //getEntity().addModifier(combo_HumanGroup.getSelection());
796 }*/
797
798 }
799 }
800 if(isChanged == false){
801 //MarkerType markerType = MarkerType.NewInstance("Human Group", "Human Group", null);
802 Marker marker = Marker.NewInstance(markerType, false);
803 Modifier humanGroup = combo_HumanGroup.getSelection();
804 humanGroup.addMarker(marker);
805 getEntity().addModifier(humanGroup);
806 //getEntity().addModifier(combo_HumanGroup.getSelection());
807 }
808 }
809 combo_EthnicGroup.setEnabled(true);
810 }
811 if (eventSource == combo_EthnicGroup) {
812 if (combo_EthnicGroup.getSelection() != null) {
813 boolean isChanged = false;
814 MarkerType markerType = MarkerType.NewInstance("Ethnic Group", "Ethnic Group", null);
815 Set<Modifier> modifiers = getEntity().getModifiers();
816 if(!modifiers.isEmpty()) {
817 for (Modifier modifier : modifiers) {
818 if (modifier.getMarkers() != null) {
819 for (Marker marker : modifier.getMarkers()) {
820 if (marker.getMarkerType().getTitleCache().equals("Ethnic Group")) {
821 getEntity().removeModifier(modifier);
822 Modifier ethnicGroup = combo_EthnicGroup.getSelection();
823 ethnicGroup.addMarker(marker);
824 getEntity().addModifier(ethnicGroup);
825 isChanged = true;
826 //getEntity().addModifier(combo_EthnicGroup.getSelection());
827 }
828 /*else {
829
830 Marker markerEthnicGroup = Marker.NewInstance(markerType, false);
831 Modifier ethnicGroup = combo_EthnicGroup.getSelection();
832 ethnicGroup.addMarker(markerEthnicGroup);
833 getEntity().addModifier(ethnicGroup);
834 //getEntity().addModifier(combo_EthnicGroup.getSelection());
835 }*/
836
837
838 }
839
840 }
841 /*else {
842 //MarkerType markerType = MarkerType.NewInstance("Ethnic Group", "Ethnic Group", null);
843 Marker marker = Marker.NewInstance(markerType, false);
844 Modifier ethnicGroup = combo_EthnicGroup.getSelection();
845 ethnicGroup.addMarker(marker);
846 getEntity().addModifier(ethnicGroup);
847 //getEntity().addModifier(combo_EthnicGroup.getSelection());
848 }*/
849
850 }
851 }
852 if(isChanged == false) {
853 //MarkerType markerType = MarkerType.NewInstance("Ethnic Group", "Ethnic Group", null);
854 Marker marker = Marker.NewInstance(markerType, false);
855 Modifier ethnicGroup = combo_EthnicGroup.getSelection();
856 ethnicGroup.addMarker(marker);
857 getEntity().addModifier(ethnicGroup);
858 //getEntity().addModifier(combo_EthnicGroup.getSelection());
859 }
860 }
861 }
862 }
863
864
865
866 /** {@inheritDoc} */
867 @Override
868 public void setEntity(CategoricalData entity) {
869 // section_stateData.setEntity(entity);
870 super.setEntity(entity);
871 }
872
873 @Override
874 public void widgetSelected(SelectionEvent e) {
875 Object eventSource = e.getSource();
876 //This is causing an error on purpose fix the if statement below
877
878 //e.getselection();
879 //if(eventSource == combo_UseCategory.getControls()) {
880 for (Object object: combo_UseCategory.getControls()) {
881 if (object == eventSource) {
882 State selectedUseCategory = combo_UseCategory.getSelection();
883 if (selectedUseCategory != null) {
884 if (!getEntity().getStates().isEmpty()) {
885 for (StateData existingStateData : getEntity().getStates()) {
886 Map<Language, LanguageString> modifyingText = existingStateData
887 .getModifyingText();
888
889 if (modifyingText.get(CdmStore.getDefaultLanguage()) != null) {
890 if (modifyingText.get(CdmStore.getDefaultLanguage())
891 .getText() == "Use SubCategory") {
892 getEntity().removeState(existingStateData);
893 combo_UseSubCategory.setSelected(false);
894 combo_UseSubCategory.getSelection();
895 }
896 }
897 }
898 }
899
900 List<State> newSubCategories = setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false),selectedUseCategory);
901 combo_UseSubCategory.setTerms(newSubCategories);
902 State emptyState = State.NewInstance();
903 combo_UseSubCategory.setSelection(emptyState);
904 combo_UseSubCategory.setSelection(newSubCategories.get(0));
905 combo_UseSubCategory.setSelection(null);
906
907 combo_UseSubCategory.setTerms(newSubCategories);
908
909 }
910 }
911 }
912 for (Object object: combo_HumanGroup.getControls()) {
913 if (object == eventSource) {
914 Modifier selectedHumanGroup = combo_HumanGroup.getSelection();
915 if (selectedHumanGroup != null) {
916 combo_EthnicGroup.setTerms(setEthnicGroupComboTerms(TermStore.getTerms(Modifier.class, null, false), selectedHumanGroup));
917 }
918 }
919 }
920 /*
921 State selectedUseCategory = combo_UseCategory.getSelection();
922 if (selectedUseCategory != null) {
923 combo_UseSubCategory.setTerms(setUseCategoryComboTerms(TermStore.getTerms(State.class, null, false),selectedUseCategory));
924
925 }
926 //}
927 if (eventSource == combo_HumanGroup) {
928 Modifier selectedHumanGroup = combo_HumanGroup.getSelection();
929 if (selectedHumanGroup != null) {
930 combo_EthnicGroup.setTerms(setEthnicGroupComboTerms(TermStore.getTerms(Modifier.class, null, false), selectedHumanGroup));
931 }
932 }
933 */
934
935 }
936
937 @Override
938 public void widgetDefaultSelected(SelectionEvent e) {
939 // TODO Auto-generated method stub
940
941 }
942
943 }