2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
11 import org
.eclipse
.swt
.events
.SelectionListener
;
13 import eu
.etaxonomy
.cdm
.compare
.name
.TypeDesignationStatusComparator
;
14 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
15 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
16 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
17 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
18 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
19 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
20 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
21 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
22 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
23 import eu
.etaxonomy
.taxeditor
.ui
.combo
.term
.TermComboElement
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
32 * @created May 17, 2010
34 public class SpecimenTypeDesignationElement
extends
35 AbstractTypeDesignationElement
<SpecimenTypeDesignation
> {
37 private TermComboElement
<SpecimenTypeDesignationStatus
> combo_typeStatus
;
38 private EntitySelectionElement
<DerivedUnit
> selection_typeSpecimen
;
39 private TextWithLabelElement text_specimenTypeText
;
41 public SpecimenTypeDesignationElement(CdmFormFactory formFactory
,
42 AbstractFormSection section
, SpecimenTypeDesignation entity
,
43 SelectionListener removeListener
, int style
) {
44 super(formFactory
, section
, entity
, removeListener
, style
);
48 public void createControls(ICdmFormElement formElement
, int style
) {
49 selection_typeSpecimen
= formFactory
50 .createSelectionElement(DerivedUnit
.class,
51 formElement
, "Specimen", null,
52 EntitySelectionElement
.ALL
, style
);
53 combo_typeStatus
= formFactory
.createDefinedTermComboElement(TermType
.SpecimenTypeDesignationStatus
,
54 formElement
, "Designation Status", null, style
, new TypeDesignationStatusComparator
<SpecimenTypeDesignationStatus
>());
56 super.createControls(formElement
, style
);
60 public void setEntity(SpecimenTypeDesignation entity
) {
61 super.setEntity(entity
);
62 if (entity
.getTypeSpecimen() != null){
63 selection_typeSpecimen
.setEntity(entity
.getTypeSpecimen());
65 selection_typeSpecimen
.setEntity(entity
.getTypeSpecimen());
68 SpecimenTypeDesignationStatus typeStatus
= HibernateProxyHelper
69 .deproxy(entity
.getTypeStatus(), SpecimenTypeDesignationStatus
.class);
70 combo_typeStatus
.setSelection(typeStatus
);
72 checkbox_notDesignated
.setSelection(entity
.isNotDesignated());
76 public void handleEvent(Object eventSource
) {
77 super.handleEvent(eventSource
);
78 if (eventSource
== combo_typeStatus
) {
80 if ((combo_typeStatus
.getSelection() == null && entity
.getCitation() != null) || ( entity
.getTypeStatus() != null && getEntity().getTypeStatus().hasDesignationSource() && !combo_typeStatus
.getSelection().hasDesignationSource() && entity
.getCitation() != null)){
81 boolean ok
= MessagingUtils
.confirmDialog(Messages
.NameTypeDesignationElement_4
, Messages
.NameTypeDesignationElement_5
);
83 combo_typeStatus
.setSelection(entity
.getTypeStatus());
87 getEntity().setTypeStatus(combo_typeStatus
.getSelection());
88 if (entity
.hasDesignationSource()){
89 DescriptionElementSource source
= DescriptionElementSource
.NewPrimarySourceInstance(null, null);
90 entity
.setSource(source
);
95 // TODO remove this once specimens are correctly implemented
96 else if (eventSource
== text_specimenTypeText
) {
97 // TODO this is a simple workaround to enter type specimen as text
99 if (getEntity().getTypeSpecimen() == null) {
100 DerivedUnit typeSpecimen
= DerivedUnit
.NewInstance(SpecimenOrObservationType
.PreservedSpecimen
);
101 getEntity().setTypeSpecimen(typeSpecimen
);
103 getEntity().getTypeSpecimen().setTitleCache(
104 text_specimenTypeText
.getText());
105 } else if (eventSource
== selection_typeSpecimen
) {
106 getEntity().setTypeSpecimen(selection_typeSpecimen
.getSelection());
107 } else if (eventSource
== checkbox_notDesignated
) {
108 getEntity().setNotDesignated(checkbox_notDesignated
.getSelection());
110 // else if (eventSource == selection_reference) {
111 // getEntity().setCitation(selection_reference.getSelection());
112 // } else if (eventSource == text_referenceDetail) {
113 // getEntity().setCitationMicroReference(
114 // text_referenceDetail.getText());