3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
.description
;
13 import java
.util
.ArrayList
;
14 import java
.util
.HashSet
;
15 import java
.util
.List
;
18 import org
.eclipse
.swt
.events
.SelectionListener
;
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
;
32 * <p>ModifierElement class.</p>
35 * @created Sep 15, 2010
38 public class ModifierElement
extends AbstractEntityCollectionElement
<DefinedTerm
> {
40 private TermComboElement
<DefinedTerm
> combo_modifier
;
43 * <p>Constructor for ModifierElement.</p>
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.
51 public ModifierElement(CdmFormFactory formFactory
,
52 AbstractFormSection
<?
> section
, DefinedTerm entity
,
53 SelectionListener removeListener
, int style
) {
54 super(formFactory
, section
, entity
, removeListener
, null, style
);
59 public void setEntity(DefinedTerm 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();
69 if(parentSection
.getEntity() instanceof StatisticalMeasurementValue
){
70 StatisticalMeasurementValue statisticalMeasurementValue
= (StatisticalMeasurementValue
)parentSection
.getEntity();
71 recommendedModifierEnumeration
= statisticalMeasurementValue
.getQuantitativeData().getFeature().getRecommendedModifierEnumeration();
73 for (TermVocabulary
<DefinedTerm
> termVocabulary
: recommendedModifierEnumeration
) {
74 modifierTerms
.addAll(termVocabulary
.getTerms());
76 combo_modifier
.setTerms(modifierTerms
);
79 combo_modifier
.setSelection(entity
);
85 public void createControls(ICdmFormElement element
, int style
) {
86 combo_modifier
= formFactory
.createDefinedTermComboElement(TermType
.Modifier
, element
, "Modifier", getEntity(), false, style
);
91 public void handleEvent(Object eventSource
) {
92 if(eventSource
==combo_modifier
&& combo_modifier
.getSelection()!=null){
93 if(getParentElement() instanceof ModifierSection
){
94 ModifierSection parentSection
= (ModifierSection
) getParentElement();
95 if((parentSection
).getEntity() instanceof StateData
){
96 StateData stateData
= (StateData
) parentSection
.getEntity();
97 stateData
.removeModifier(entity
);
98 DefinedTerm term
= combo_modifier
.getSelection();
99 stateData
.addModifier(term
);