Project

General

Profile

Download (3.61 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.Set;
14

    
15
import org.eclipse.swt.events.SelectionListener;
16
import org.eclipse.ui.forms.widgets.ExpandableComposite;
17

    
18
import eu.etaxonomy.cdm.model.common.TermType;
19
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
20
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
21
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
22
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
26
import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
27
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
28

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

    
39
	private NumberWithLabelElement number_value;
40
	private TermComboElement<StatisticalMeasure> combo_type;
41
	private ModifierSection section_modifiers;
42

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

    
58
	/** {@inheritDoc} */
59
	@Override
60
	public void setEntity(StatisticalMeasurementValue entity) {
61
		this.entity = entity;
62
		Set<StatisticalMeasure> statisiticalMeasures = getEntity().getQuantitativeData().getFeature().getRecommendedStatisticalMeasures();
63
        combo_type.setTerms(new ArrayList<StatisticalMeasure>(statisiticalMeasures));
64
		combo_type.setSelection(entity.getType());
65
		number_value.setNumber(entity.getValue());
66
		section_modifiers.setEntity(entity);
67
	}
68

    
69
	/** {@inheritDoc} */
70
	@Override
71
	public void createControls(ICdmFormElement element, int style) {
72
		number_value = formFactory.createNumberTextWithLabelElement(element, "Value", 0, style);
73
		combo_type = formFactory.createDefinedTermComboElement(TermType.StatisticalMeasure, element, "Statistical Measure", null, style);
74
		section_modifiers = formFactory.createModifierSection(getConversationHolder(), element, ExpandableComposite.TWISTIE);
75
		section_modifiers.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
76
	}
77

    
78
	/** {@inheritDoc} */
79
	@Override
80
	public void handleEvent(Object eventSource) {
81
		if(eventSource == number_value){
82
			Float floatNumber = number_value.getFloat();
83
			if(floatNumber==null){
84
			    String zero = "0.0";
85
                floatNumber = new Float(zero);
86
			    number_value.setText(zero);
87
			}
88
            getEntity().setValue(floatNumber);
89
		}
90
		else if(eventSource == combo_type){
91
			getEntity().setType(combo_type.getSelection());
92
			combo_type.removeEmptyElement();
93
		}
94
	}
95
}
(24-24/25)