Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / NameTypeDesignationElement.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.hibernate.HibernateProxyHelper;
15 import eu.etaxonomy.cdm.model.common.TermType;
16 import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
17 import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
18 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
19 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
20 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
21 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
22 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
23 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
25
26 /**
27 *
28 * @author n.hoffmann
29 * @created May 17, 2010
30 * @version 1.0
31 */
32 public class NameTypeDesignationElement extends
33 AbstractTypeDesignationElement<NameTypeDesignation> {
34
35 private CheckboxElement checkbox_rejectedType;
36 private CheckboxElement checkbox_conservedType;
37 private EntitySelectionElement<TaxonNameBase> selection_typeName;
38 private TermComboElement<NameTypeDesignationStatus> combo_typeStatus;
39
40 public NameTypeDesignationElement(CdmFormFactory formFactory,
41 AbstractFormSection section, NameTypeDesignation entity,
42 SelectionListener removeListener, int style) {
43 super(formFactory, section, entity, removeListener, style);
44 }
45
46 /** {@inheritDoc} */
47 @Override
48 public void createControls(ICdmFormElement formElement, int style) {
49
50 checkbox_rejectedType = formFactory.createCheckbox(formElement,
51 "Rejected Type", false, style);
52 checkbox_conservedType = formFactory.createCheckbox(formElement,
53 "Conserved Type", false, style);
54 selection_typeName = formFactory
55 .createSelectionElement(TaxonNameBase.class,
56 getConversationHolder(), formElement, "Name", null,
57 EntitySelectionElement.ALL, style);
58 combo_typeStatus = formFactory.createDefinedTermComboElement(TermType.NameTypeDesignationStatus, formElement,
59 "Designation Status", null, style);
60
61 super.createControls(formElement, style);
62 }
63
64 /** {@inheritDoc} */
65 @Override
66 public void setEntity(NameTypeDesignation entity) {
67 super.setEntity(entity);
68 checkbox_conservedType.setSelection(entity.isConservedType());
69 checkbox_rejectedType.setSelection(entity.isRejectedType());
70
71 selection_typeName.setEntity((TaxonNameBase) HibernateProxyHelper.deproxy(entity.getTypeName()));
72
73 combo_typeStatus.setSelection(HibernateProxyHelper.deproxy(entity.getTypeStatus(), NameTypeDesignationStatus.class));
74
75 checkbox_notDesignated.setSelection(entity.isNotDesignated());
76 }
77
78 /** {@inheritDoc} */
79 @Override
80 public void handleEvent(Object eventSource) {
81 if (eventSource == checkbox_conservedType) {
82 getEntity().setConservedType(checkbox_conservedType.getSelection());
83 } else if (eventSource == checkbox_rejectedType) {
84 getEntity().setRejectedType(checkbox_rejectedType.getSelection());
85 } else if (eventSource == selection_typeName) {
86 getEntity().setTypeName(selection_typeName.getEntity());
87 } else if (eventSource == combo_typeStatus) {
88 getEntity().setTypeStatus(combo_typeStatus.getSelection());
89 } else if (eventSource == checkbox_notDesignated) {
90 getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
91 } else if (eventSource == selection_reference) {
92 getEntity().setCitation(selection_reference.getSelection());
93 } else if (eventSource == text_referenceDetail) {
94 getEntity().setCitationMicroReference(
95 text_referenceDetail.getText());
96 }
97 }
98 }