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.description;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.List;
|
16
|
import java.util.Set;
|
17
|
|
18
|
import org.eclipse.swt.events.SelectionListener;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
21
|
import eu.etaxonomy.cdm.model.common.TermType;
|
22
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
23
|
import eu.etaxonomy.cdm.model.description.StateData;
|
24
|
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
|
25
|
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
|
30
|
|
31
|
/**
|
32
|
* <p>ModifierElement class.</p>
|
33
|
*
|
34
|
* @author n.hoffmann
|
35
|
* @created Sep 15, 2010
|
36
|
* @version 1.0
|
37
|
*/
|
38
|
public class ModifierElement extends AbstractEntityCollectionElement<DefinedTerm> {
|
39
|
|
40
|
private TermComboElement<DefinedTerm> combo_modifier;
|
41
|
|
42
|
/**
|
43
|
* <p>Constructor for ModifierElement.</p>
|
44
|
*
|
45
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
46
|
* @param section a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
|
47
|
* @param entity a {@link eu.etaxonomy.cdm.model.description.Modifier} object.
|
48
|
* @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
|
49
|
* @param style a int.
|
50
|
*/
|
51
|
public ModifierElement(CdmFormFactory formFactory,
|
52
|
AbstractFormSection<?> section, DefinedTerm entity,
|
53
|
SelectionListener removeListener, int style) {
|
54
|
super(formFactory, section, entity, removeListener, null, style);
|
55
|
}
|
56
|
|
57
|
/** {@inheritDoc} */
|
58
|
@Override
|
59
|
public void setEntity(DefinedTerm entity) {
|
60
|
this.entity = entity;
|
61
|
if(getParentElement() instanceof ModifierSection){
|
62
|
ModifierSection parentSection = (ModifierSection) getParentElement();
|
63
|
List<DefinedTerm> modifierTerms = new ArrayList<DefinedTerm>();
|
64
|
Set<TermVocabulary<DefinedTerm>> recommendedModifierEnumeration = new HashSet<TermVocabulary<DefinedTerm>>();
|
65
|
if(parentSection.getEntity() instanceof StateData){
|
66
|
StateData stateData = (StateData) parentSection.getEntity();
|
67
|
recommendedModifierEnumeration = stateData.getCategoricalData().getFeature().getRecommendedModifierEnumeration();
|
68
|
}
|
69
|
if(parentSection.getEntity() instanceof StatisticalMeasurementValue){
|
70
|
StatisticalMeasurementValue statisticalMeasurementValue = (StatisticalMeasurementValue)parentSection.getEntity();
|
71
|
recommendedModifierEnumeration = statisticalMeasurementValue.getQuantitativeData().getFeature().getRecommendedModifierEnumeration();
|
72
|
}
|
73
|
for (TermVocabulary<DefinedTerm> termVocabulary : recommendedModifierEnumeration) {
|
74
|
modifierTerms.addAll(termVocabulary.getTerms());
|
75
|
}
|
76
|
combo_modifier.setTerms(modifierTerms);
|
77
|
}
|
78
|
if(entity.getId()>0){
|
79
|
combo_modifier.setSelection(entity);
|
80
|
combo_modifier.removeEmptyElement();
|
81
|
}
|
82
|
}
|
83
|
|
84
|
/** {@inheritDoc} */
|
85
|
@Override
|
86
|
public void createControls(ICdmFormElement element, int style) {
|
87
|
combo_modifier = formFactory.createDefinedTermComboElement(TermType.Modifier, element, "Modifier", getEntity(), style);
|
88
|
}
|
89
|
|
90
|
/** {@inheritDoc} */
|
91
|
@Override
|
92
|
public void handleEvent(Object eventSource) {
|
93
|
if(eventSource==combo_modifier && combo_modifier.getSelection()!=null){
|
94
|
combo_modifier.removeEmptyElement();
|
95
|
if(getParentElement() instanceof AbstractFormSection){
|
96
|
AbstractFormSection<?> parentSection = (AbstractFormSection<?>) getParentElement();
|
97
|
if(parentSection.getEntity() instanceof StateData){
|
98
|
StateData stateData = (StateData) parentSection.getEntity();
|
99
|
stateData.removeModifier(entity);
|
100
|
DefinedTerm term = combo_modifier.getSelection();
|
101
|
stateData.addModifier(term);
|
102
|
entity = term;
|
103
|
}
|
104
|
else if(parentSection.getEntity() instanceof StatisticalMeasurementValue){
|
105
|
StatisticalMeasurementValue parentEntity = (StatisticalMeasurementValue) parentSection.getEntity();
|
106
|
parentEntity.removeModifier(entity);
|
107
|
DefinedTerm term = combo_modifier.getSelection();
|
108
|
parentEntity.addModifier(term);
|
109
|
entity = term;
|
110
|
}
|
111
|
}
|
112
|
}
|
113
|
}
|
114
|
}
|