(no commit message)
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / NameTypeDesignationElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.ui.section.name;
12
13 import org.eclipse.swt.events.SelectionListener;
14
15 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
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.element.CdmFormFactory.SelectionType;
25 import eu.etaxonomy.taxeditor.ui.selection.NameSelectionElement;
26
27 /**
28 * <p>
29 * NameTypeDesignationElement class.
30 * </p>
31 *
32 * @author n.hoffmann
33 * @created May 17, 2010
34 * @version 1.0
35 */
36 public class NameTypeDesignationElement extends
37 AbstractTypeDesignationElement<NameTypeDesignation> {
38
39 private CheckboxElement checkbox_rejectedType;
40 private CheckboxElement checkbox_conservedType;
41 private NameSelectionElement selection_typeName;
42 private TermComboElement<NameTypeDesignationStatus> combo_typeStatus;
43
44 /**
45 * <p>
46 * Constructor for NameTypeDesignationElement.
47 * </p>
48 *
49 * @param formFactory
50 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
51 * object.
52 * @param section
53 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
54 * object.
55 * @param entity
56 * a {@link eu.etaxonomy.cdm.model.name.NameTypeDesignation}
57 * object.
58 * @param removeListener
59 * a {@link org.eclipse.swt.events.SelectionListener} object.
60 * @param style
61 * a int.
62 */
63 public NameTypeDesignationElement(CdmFormFactory formFactory,
64 AbstractFormSection section, NameTypeDesignation entity,
65 SelectionListener removeListener, int style) {
66 super(formFactory, section, entity, removeListener, style);
67 }
68
69 /** {@inheritDoc} */
70 @Override
71 public void createControls(ICdmFormElement formElement, int style) {
72
73 checkbox_rejectedType = formFactory.createCheckbox(formElement,
74 "Rejected Type", false, style);
75 checkbox_conservedType = formFactory.createCheckbox(formElement,
76 "Conserved Type", false, style);
77 selection_typeName = (NameSelectionElement) formFactory
78 .createSelectionElement(SelectionType.NAME,
79 getConversationHolder(), formElement, "Name", null,
80 NameSelectionElement.DEFAULT, style);
81 combo_typeStatus = formFactory.createTermComboElement(
82 NameTypeDesignationStatus.class, formElement,
83 "Designation Status", null, style);
84
85 super.createControls(formElement, style);
86 }
87
88 /** {@inheritDoc} */
89 @Override
90 public void setEntity(NameTypeDesignation entity) {
91 super.setEntity(entity);
92 checkbox_conservedType.setSelection(entity.isConservedType());
93 checkbox_rejectedType.setSelection(entity.isRejectedType());
94
95 selection_typeName.setEntity((TaxonNameBase) HibernateProxyHelper.deproxy(entity.getTypeName()));
96
97 combo_typeStatus.setSelection((NameTypeDesignationStatus) HibernateProxyHelper.deproxy(entity.getTypeStatus()));
98
99 checkbox_notDesignated.setSelection(entity.isNotDesignated());
100 }
101
102 /** {@inheritDoc} */
103 @Override
104 public void handleEvent(Object eventSource) {
105 if (eventSource == checkbox_conservedType) {
106 getEntity().setConservedType(checkbox_conservedType.getSelection());
107 } else if (eventSource == checkbox_rejectedType) {
108 getEntity().setRejectedType(checkbox_rejectedType.getSelection());
109 } else if (eventSource == selection_typeName) {
110 getEntity().setTypeName(selection_typeName.getEntity());
111 } else if (eventSource == combo_typeStatus) {
112 getEntity().setTypeStatus(combo_typeStatus.getSelection());
113 } else if (eventSource == checkbox_notDesignated) {
114 getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
115 } else if (eventSource == selection_reference) {
116 getEntity().setCitation(selection_reference.getSelection());
117 } else if (eventSource == text_referenceDetail) {
118 getEntity().setCitationMicroReference(
119 text_referenceDetail.getText());
120 } else if (eventSource == text_originaleNameString) {
121 getEntity().setOriginalNameString(
122 text_originaleNameString.getText());
123 }
124 }
125 }