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
|
package eu.etaxonomy.taxeditor.ui.section.name;
|
10
|
|
11
|
import java.util.List;
|
12
|
|
13
|
import org.eclipse.swt.events.SelectionListener;
|
14
|
|
15
|
import eu.etaxonomy.cdm.compare.name.TypeDesignationStatusComparator;
|
16
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
17
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
18
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
19
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
20
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
21
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
22
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
23
|
import eu.etaxonomy.cdm.model.reference.NamedSource;
|
24
|
import eu.etaxonomy.cdm.model.term.TermType;
|
25
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
26
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
27
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
28
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29
|
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
31
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
32
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
33
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
34
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
35
|
|
36
|
/**
|
37
|
* @author n.hoffmann
|
38
|
* @created May 17, 2010
|
39
|
*/
|
40
|
public class SpecimenTypeDesignationElement extends
|
41
|
AbstractTypeDesignationElement<SpecimenTypeDesignation> {
|
42
|
|
43
|
private TermComboElement<SpecimenTypeDesignationStatus> combo_typeStatus;
|
44
|
private EntitySelectionElement<DerivedUnit> selection_typeSpecimen;
|
45
|
private TextWithLabelElement text_specimenTypeText;
|
46
|
|
47
|
public SpecimenTypeDesignationElement(CdmFormFactory formFactory,
|
48
|
AbstractFormSection section, SpecimenTypeDesignation entity,
|
49
|
SelectionListener removeListener, int style) {
|
50
|
super(formFactory, section, entity, removeListener, style);
|
51
|
}
|
52
|
|
53
|
@Override
|
54
|
public void createControls(ICdmFormElement formElement, int style) {
|
55
|
selection_typeSpecimen = formFactory
|
56
|
.createSelectionElement(DerivedUnit.class,
|
57
|
formElement, "Specimen", null,
|
58
|
EntitySelectionElement.ALL, style);
|
59
|
String availableTypes = PreferencesUtil.getStringValue(PreferencePredicate.SpecimenTypeDesignationStatus.getKey());
|
60
|
List<SpecimenTypeDesignationStatus> relTypes = CdmStore.getTermManager().createTermListFromString(availableTypes, TermType.SpecimenTypeDesignationStatus);
|
61
|
// combo_typeStatus = formFactory.createDefinedTermComboElement(TermType.SpecimenTypeDesignationStatus,
|
62
|
// formElement, "Designation Status", null, style, new TypeDesignationStatusComparator<SpecimenTypeDesignationStatus>());
|
63
|
combo_typeStatus = formFactory.createDefinedTermComboElement(relTypes, formElement, "Designation Status", null,style, new TypeDesignationStatusComparator<SpecimenTypeDesignationStatus>());
|
64
|
|
65
|
super.createControls(formElement, style);
|
66
|
setEntity(entity);
|
67
|
}
|
68
|
|
69
|
@Override
|
70
|
public void setEntity(SpecimenTypeDesignation entity) {
|
71
|
super.setEntity(entity);
|
72
|
if (selection_typeSpecimen != null){
|
73
|
if (entity.getTypeSpecimen() != null){
|
74
|
selection_typeSpecimen.setEntity(entity.getTypeSpecimen());
|
75
|
}else{
|
76
|
selection_typeSpecimen.setEntity(entity.getTypeSpecimen());
|
77
|
}
|
78
|
|
79
|
SpecimenTypeDesignationStatus typeStatus = HibernateProxyHelper
|
80
|
.deproxy(entity.getTypeStatus(), SpecimenTypeDesignationStatus.class);
|
81
|
combo_typeStatus.setSelection(typeStatus);
|
82
|
|
83
|
checkbox_notDesignated.setSelection(entity.isNotDesignated());
|
84
|
}
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
public void handleEvent(Object eventSource) {
|
89
|
super.handleEvent(eventSource);
|
90
|
if (eventSource == combo_typeStatus) {
|
91
|
|
92
|
if ((combo_typeStatus.getSelection() == null && entity.getCitation() != null) || ( entity.getTypeStatus() != null && getEntity().getTypeStatus().hasDesignationSource() && !combo_typeStatus.getSelection().hasDesignationSource() && 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
|
}
|
99
|
getEntity().setTypeStatus(combo_typeStatus.getSelection());
|
100
|
if (entity.hasDesignationSource()){
|
101
|
NamedSource source = NamedSource.NewPrimarySourceInstance(null, null);
|
102
|
entity.setDesignationSource(source);
|
103
|
}
|
104
|
setEntity(entity);
|
105
|
|
106
|
}
|
107
|
// TODO remove this once specimens are correctly implemented
|
108
|
else if (eventSource == text_specimenTypeText) {
|
109
|
// TODO this is a simple workaround to enter type specimen as text
|
110
|
// strings
|
111
|
if (getEntity().getTypeSpecimen() == null) {
|
112
|
DerivedUnit typeSpecimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
113
|
getEntity().setTypeSpecimen(typeSpecimen);
|
114
|
}
|
115
|
getEntity().getTypeSpecimen().setTitleCache(
|
116
|
text_specimenTypeText.getText());
|
117
|
} else if (eventSource == selection_typeSpecimen) {
|
118
|
getEntity().setTypeSpecimen(selection_typeSpecimen.getSelection());
|
119
|
} else if (eventSource == checkbox_notDesignated) {
|
120
|
getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
|
121
|
}
|
122
|
// else if (eventSource == selection_reference) {
|
123
|
// getEntity().setCitation(selection_reference.getSelection());
|
124
|
// } else if (eventSource == text_referenceDetail) {
|
125
|
// getEntity().setCitationMicroReference(
|
126
|
// text_referenceDetail.getText());
|
127
|
// }
|
128
|
}
|
129
|
}
|