Project

General

Profile

Download (4.63 KB) Statistics
| Branch: | Tag: | Revision:
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

    
10
package eu.etaxonomy.taxeditor.ui.section.description;
11

    
12
import java.util.ArrayList;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Set;
16

    
17
import org.eclipse.swt.events.SelectionListener;
18

    
19
import eu.etaxonomy.cdm.model.common.DefinedTerm;
20
import eu.etaxonomy.cdm.model.common.TermType;
21
import eu.etaxonomy.cdm.model.common.TermVocabulary;
22
import eu.etaxonomy.cdm.model.description.StateData;
23
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
24
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
25
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
26
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
27
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
28
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
29

    
30
/**
31
 * <p>ModifierElement class.</p>
32
 *
33
 * @author n.hoffmann
34
 * @created Sep 15, 2010
35
 * @version 1.0
36
 */
37
public class ModifierElement extends AbstractEntityCollectionElement<DefinedTerm> {
38

    
39
	private TermComboElement<DefinedTerm> combo_modifier;
40

    
41
	/**
42
	 * <p>Constructor for ModifierElement.</p>
43
	 *
44
	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
45
	 * @param section a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
46
	 * @param entity a {@link eu.etaxonomy.cdm.model.description.Modifier} object.
47
	 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
48
	 * @param style a int.
49
	 */
50
	public ModifierElement(CdmFormFactory formFactory,
51
			AbstractFormSection<?> section, DefinedTerm entity,
52
			SelectionListener removeListener, int style) {
53
		super(formFactory, section, entity, removeListener, null, style);
54
	}
55

    
56
	/** {@inheritDoc} */
57
	@Override
58
	public void setEntity(DefinedTerm entity) {
59
		this.entity = entity;
60
		if(getParentElement() instanceof ModifierSection){
61
		    ModifierSection parentSection = (ModifierSection) getParentElement();
62
		    List<DefinedTerm> modifierTerms = new ArrayList<DefinedTerm>();
63
            Set<TermVocabulary<DefinedTerm>> recommendedModifierEnumeration = new HashSet<TermVocabulary<DefinedTerm>>();
64
		    if(parentSection.getEntity() instanceof StateData){
65
		        StateData stateData = (StateData) parentSection.getEntity();
66
		        recommendedModifierEnumeration = stateData.getCategoricalData().getFeature().getRecommendedModifierEnumeration();
67
		    }
68
		    if(parentSection.getEntity() instanceof StatisticalMeasurementValue){
69
		        StatisticalMeasurementValue statisticalMeasurementValue = (StatisticalMeasurementValue)parentSection.getEntity();
70
		        recommendedModifierEnumeration = statisticalMeasurementValue.getQuantitativeData().getFeature().getRecommendedModifierEnumeration();
71
		    }
72
		    for (TermVocabulary<DefinedTerm> termVocabulary : recommendedModifierEnumeration) {
73
		        modifierTerms.addAll(termVocabulary.getTerms());
74
		    }
75
		    combo_modifier.setTerms(modifierTerms);
76
		}
77
        if(entity!=null && entity.getId()>0){
78
            combo_modifier.setSelection(entity);
79
            combo_modifier.removeEmptyElement();
80
        }
81
	}
82

    
83
	/** {@inheritDoc} */
84
	@Override
85
	public void createControls(ICdmFormElement element, int style) {
86
		combo_modifier = formFactory.createDefinedTermComboElement(TermType.Modifier, element, "Modifier", getEntity(), style);
87
	}
88

    
89
	/** {@inheritDoc} */
90
	@Override
91
	public void handleEvent(Object eventSource) {
92
	    if(eventSource==combo_modifier && combo_modifier.getSelection()!=null){
93
	        combo_modifier.removeEmptyElement();
94
	        if(getParentElement() instanceof AbstractFormSection){
95
	            AbstractFormSection<?> parentSection = (AbstractFormSection<?>) getParentElement();
96
	            if(parentSection.getEntity() instanceof StateData){
97
	                StateData stateData = (StateData) parentSection.getEntity();
98
	                stateData.removeModifier(entity);
99
	                DefinedTerm term = combo_modifier.getSelection();
100
	                stateData.addModifier(term);
101
	                entity = term;
102
	            }
103
	            else if(parentSection.getEntity() instanceof StatisticalMeasurementValue){
104
	                StatisticalMeasurementValue parentEntity = (StatisticalMeasurementValue) parentSection.getEntity();
105
	                parentEntity.removeModifier(entity);
106
	                DefinedTerm term = combo_modifier.getSelection();
107
	                parentEntity.addModifier(term);
108
	                entity = term;
109
	            }
110
	        }
111
	    }
112
	}
113
}
(15-15/25)