Project

General

Profile

Download (3.62 KB) Statistics
| Branch: | Tag: | Revision:
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.Set;
15

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

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

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

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

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

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

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

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