set nom illeg. as default in nomenclatural status type combo box
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / NomenclaturalStatusElement.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.taxeditor.ui.section.name;
11
12 import org.eclipse.swt.events.SelectionListener;
13
14 import eu.etaxonomy.cdm.api.service.IVocabularyService;
15 import eu.etaxonomy.cdm.model.common.TermVocabulary;
16 import eu.etaxonomy.cdm.model.common.VocabularyEnum;
17 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
18 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
19 import eu.etaxonomy.taxeditor.store.CdmStore;
20 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
21 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
22 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24 import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
25 import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
26 import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
27 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
28 import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractReferencedEntityElement;
29
30 /**
31 * @author n.hoffmann
32 * @created Nov 5, 2009
33 * @version 1.0
34 */
35 public class NomenclaturalStatusElement extends AbstractReferencedEntityElement<NomenclaturalStatus> implements IEntityElement<NomenclaturalStatus>, ISelectableElement{
36
37 private TermComboElement<NomenclaturalStatusType> nomenclaturalStatusTypeCombo;
38
39 private TextWithLabelElement ruleConsideredText;
40
41 private final SelectionArbitrator selectionArbitrator;
42
43 public NomenclaturalStatusElement(CdmFormFactory cdmFormFactory, AbstractFormSection formElement,
44 NomenclaturalStatus element, SelectionListener removeListener, int style) {
45 super(cdmFormFactory, formElement, element, removeListener, style);
46 selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this);
47 }
48
49 /** {@inheritDoc} */
50 @Override
51 public void createControls(ICdmFormElement element, int style) {
52 TermVocabulary vocabulary = CdmStore.getService(IVocabularyService.class).find(VocabularyEnum.NomenclaturalStatusType.getUuid());
53 nomenclaturalStatusTypeCombo = formFactory.createDefinedTermComboElement(vocabulary, this, "Nomenclatural Status Type", null,false, style, true);
54 ruleConsideredText = formFactory.createTextWithLabelElement(this, "Rule Considered", "", style);
55
56 super.createControls(element, style);
57 if (vocabulary.getTerms().contains(NomenclaturalStatusType.ILLEGITIMATE())){
58 nomenclaturalStatusTypeCombo.setSelection(NomenclaturalStatusType.ILLEGITIMATE());
59 }
60 }
61
62 /** {@inheritDoc} */
63 @Override
64 public void setEntity(NomenclaturalStatus entity) {
65 super.setEntity(entity);
66 nomenclaturalStatusTypeCombo.setSelection(entity.getType());
67 ruleConsideredText.setText(entity.getRuleConsidered());
68 }
69
70 /**
71 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
72 *
73 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
74 */
75 @Override
76 public SelectionArbitrator getSelectionArbitrator() {
77 return selectionArbitrator;
78 }
79
80 /** {@inheritDoc} */
81 @Override
82 public void handleEvent(Object eventSource) {
83 if(eventSource == nomenclaturalStatusTypeCombo){
84 getEntity().setType(nomenclaturalStatusTypeCombo.getSelection());
85 }
86 else if(eventSource == ruleConsideredText){
87 getEntity().setRuleConsidered(ruleConsideredText.getText());
88 }
89 else if(eventSource == selection_reference){
90 getEntity().setCitation(selection_reference.getSelection());
91 }
92 else if(eventSource == text_referenceDetail){
93 getEntity().setCitationMicroReference(text_referenceDetail.getText());
94 }
95 }
96 }