Merge branch 'release/5.18.0'
[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.description.DescriptionElementSource;
16 import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
17 import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
18 import eu.etaxonomy.cdm.model.name.TaxonName;
19 import eu.etaxonomy.cdm.model.term.TermType;
20 import eu.etaxonomy.taxeditor.l10n.Messages;
21 import eu.etaxonomy.taxeditor.model.MessagingUtils;
22 import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
23 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
24 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
25 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
26 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
27 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
28
29 /**
30 *
31 * @author n.hoffmann
32 * @created May 17, 2010
33 * @version 1.0
34 */
35 public class NameTypeDesignationElement extends
36 AbstractTypeDesignationElement<NameTypeDesignation> {
37
38 private CheckboxElement checkbox_rejectedType;
39 private CheckboxElement checkbox_conservedType;
40 private EntitySelectionElement<TaxonName> selection_typeName;
41 private TermComboElement<NameTypeDesignationStatus> combo_typeStatus;
42
43 public NameTypeDesignationElement(CdmFormFactory formFactory,
44 AbstractFormSection section, NameTypeDesignation entity,
45 SelectionListener removeListener, int style) {
46 super(formFactory, section, entity, removeListener, style);
47 }
48
49 /** {@inheritDoc} */
50 @Override
51 public void createControls(ICdmFormElement formElement, int style) {
52
53 checkbox_rejectedType = formFactory.createCheckbox(formElement,
54 "Rejected Type", false, style); //$NON-NLS-1$
55 checkbox_conservedType = formFactory.createCheckbox(formElement,
56 "Conserved Type", false, style); //$NON-NLS-1$
57 selection_typeName = formFactory
58 .createSelectionElement(TaxonName.class,//getConversationHolder(),
59 formElement, "Name", null, //$NON-NLS-1$
60 EntitySelectionElement.ALL, style);
61 combo_typeStatus = formFactory.createDefinedTermComboElement(TermType.NameTypeDesignationStatus, formElement,
62 "Designation Status", null, style); //$NON-NLS-1$
63
64 super.createControls(formElement, style);
65 }
66
67 /** {@inheritDoc} */
68 @Override
69 public void setEntity(NameTypeDesignation entity) {
70 super.setEntity(entity);
71 checkbox_conservedType.setSelection(entity.isConservedType());
72 checkbox_rejectedType.setSelection(entity.isRejectedType());
73
74 selection_typeName.setEntity(HibernateProxyHelper.deproxy(entity.getTypeName()));
75
76 combo_typeStatus.setSelection(HibernateProxyHelper.deproxy(entity.getTypeStatus(), NameTypeDesignationStatus.class));
77
78 checkbox_notDesignated.setSelection(entity.isNotDesignated());
79
80 }
81
82 /** {@inheritDoc} */
83 @Override
84 public void handleEvent(Object eventSource) {
85 if (eventSource == checkbox_conservedType) {
86 getEntity().setConservedType(checkbox_conservedType.getSelection());
87 } else if (eventSource == checkbox_rejectedType) {
88 getEntity().setRejectedType(checkbox_rejectedType.getSelection());
89 } else if (eventSource == selection_typeName) {
90 getEntity().setTypeName(selection_typeName.getEntity());
91 } else if (eventSource == combo_typeStatus) {
92 if ((combo_typeStatus.getSelection() == null && entity.getCitation() != null)){
93 boolean ok = MessagingUtils.confirmDialog(Messages.NameTypeDesignationElement_4, Messages.NameTypeDesignationElement_5);
94 if (!ok){
95 combo_typeStatus.setSelection(entity.getTypeStatus());
96 return;
97 }
98 }else if ( entity.getTypeStatus() != null && getEntity().getTypeStatus().hasDesignationSource() && !combo_typeStatus.getSelection().hasDesignationSource() && entity.getCitation() != null){
99 boolean ok = MessagingUtils.confirmDialog(Messages.NameTypeDesignationElement_4, Messages.NameTypeDesignationElement_5);
100 if (!ok){
101 combo_typeStatus.setSelection(entity.getTypeStatus());
102 return;
103 }
104 }
105 getEntity().setTypeStatus(combo_typeStatus.getSelection());
106 if (getEntity().hasDesignationSource()){
107 DescriptionElementSource source = DescriptionElementSource.NewPrimarySourceInstance(null, null);
108 entity.setSource(source);
109 }
110
111 setEntity(entity);
112 } else if (eventSource == checkbox_notDesignated) {
113 getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
114 }
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 // }
121 }
122 }