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