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.occurrence;
|
10
|
|
11
|
import org.eclipse.swt.events.SelectionListener;
|
12
|
|
13
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
14
|
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
|
15
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
16
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
17
|
import eu.etaxonomy.cdm.model.term.TermType;
|
18
|
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
|
19
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
20
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
|
25
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
26
|
|
27
|
/**
|
28
|
* @author n.hoffmann
|
29
|
* @created Oct 13, 2010
|
30
|
*/
|
31
|
public class DeterminationEventDetailElement
|
32
|
extends AbstractEventDetailElement<DeterminationEvent>
|
33
|
implements ISelectableElement{
|
34
|
|
35
|
private SelectionArbitrator selectionArbitrator;
|
36
|
|
37
|
private TermComboElement<DefinedTerm> combo_determinationModifier;
|
38
|
private CheckboxElement checkbox_preferredFlag;
|
39
|
private EntitySelectionElement<TaxonBase> selection_taxonBase;
|
40
|
private EntitySelectionElement<TaxonName> selectionTaxonNameBase;
|
41
|
|
42
|
// private TODO a set of references
|
43
|
|
44
|
public DeterminationEventDetailElement(CdmFormFactory formFactory,
|
45
|
AbstractFormSection<?> section, DeterminationEvent entity,
|
46
|
SelectionListener removeListener, int style) {
|
47
|
super(formFactory, section, entity, removeListener, style);
|
48
|
if (formFactory.getSelectionProvider() != null) {
|
49
|
selectionArbitrator = formFactory.createSelectionArbitrator(this);
|
50
|
}
|
51
|
}
|
52
|
|
53
|
@Override
|
54
|
public void setEntity(DeterminationEvent entity) {
|
55
|
this.entity = entity;
|
56
|
if (combo_determinationModifier != null){
|
57
|
combo_determinationModifier.setSelection(entity.getModifier());
|
58
|
selection_taxonBase.setEntity(entity.getTaxon());
|
59
|
selectionTaxonNameBase.setEntity(entity.getTaxonName());
|
60
|
}
|
61
|
super.setEntity(entity);
|
62
|
}
|
63
|
|
64
|
@Override
|
65
|
public void createControls(ICdmFormElement element, int style) {
|
66
|
selectionTaxonNameBase = formFactory
|
67
|
.createSelectionElement(TaxonName.class,
|
68
|
element, "Taxon Name", null,
|
69
|
EntitySelectionElement.ALL, style);
|
70
|
selection_taxonBase = formFactory
|
71
|
.createSelectionElement(TaxonBase.class,
|
72
|
element, "Taxon", null,
|
73
|
EntitySelectionElement.ALL, style);
|
74
|
|
75
|
// TODO set of references
|
76
|
|
77
|
super.createControls(element, style);
|
78
|
|
79
|
element_timePeriod.setLabel("Determined When");
|
80
|
selection_agent.setLabel("Determined by");
|
81
|
|
82
|
|
83
|
combo_determinationModifier = formFactory.createDefinedTermComboElement(TermType.DeterminationModifier,
|
84
|
element, "Modifier", null, style);
|
85
|
if (entity != null){
|
86
|
combo_determinationModifier.setSelection(entity.getModifier());
|
87
|
selection_taxonBase.setEntity(entity.getTaxon());
|
88
|
selectionTaxonNameBase.setEntity(entity.getTaxonName());
|
89
|
}
|
90
|
}
|
91
|
|
92
|
@Override
|
93
|
public void handleEvent(Object eventSource) {
|
94
|
if (eventSource == combo_determinationModifier) {
|
95
|
getEntity().setModifier(combo_determinationModifier.getSelection());
|
96
|
} else if (eventSource == checkbox_preferredFlag) {
|
97
|
getEntity().setPreferredFlag(checkbox_preferredFlag.getSelection());
|
98
|
} else if (eventSource == selectionTaxonNameBase) {
|
99
|
TaxonName name = selectionTaxonNameBase.getSelection();
|
100
|
getEntity().setTaxonName(name);
|
101
|
//empty taxon field if name was deleted
|
102
|
//or does not belong the taxon
|
103
|
TaxonBase<?> taxonBase = selection_taxonBase.getEntity();
|
104
|
if(name==null ||
|
105
|
(taxonBase!=null && taxonBase.getName()!=null
|
106
|
&& !taxonBase.getName().equals(name))){
|
107
|
selection_taxonBase.setEntity(null);
|
108
|
getEntity().setTaxon(null);
|
109
|
}
|
110
|
} else if (eventSource == selection_taxonBase) {
|
111
|
TaxonBase<?> taxon = selection_taxonBase.getSelection();
|
112
|
getEntity().setTaxon(taxon);
|
113
|
if(taxon!=null){
|
114
|
getEntity().setTaxonName(taxon.getName());
|
115
|
selectionTaxonNameBase.setEntity(taxon.getName());
|
116
|
}
|
117
|
}
|
118
|
// else if(eventSource == TODO set of references){
|
119
|
//
|
120
|
// }
|
121
|
else if (eventSource == selection_agent) {
|
122
|
getEntity().setDeterminer(selection_agent.getSelection());
|
123
|
} else if (eventSource == text_description) {
|
124
|
getEntity().setDescription(text_description.getText());
|
125
|
} else if (eventSource == element_timePeriod) {
|
126
|
getEntity().setTimeperiod(element_timePeriod.getTimePeriod());
|
127
|
}
|
128
|
}
|
129
|
|
130
|
@Override
|
131
|
public SelectionArbitrator getSelectionArbitrator() {
|
132
|
return selectionArbitrator;
|
133
|
}
|
134
|
}
|