Project

General

Profile

Download (4.08 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.math.BigDecimal;
13
import java.util.ArrayList;
14
import java.util.Set;
15

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

    
18
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
19
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
20
import eu.etaxonomy.cdm.model.term.TermType;
21
import eu.etaxonomy.taxeditor.store.StoreUtil;
22
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
23
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
24
import eu.etaxonomy.taxeditor.ui.element.BigDecimalWithLabelElement;
25
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
27
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
28
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
29
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
30

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

    
40
	private BigDecimalWithLabelElement 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
	@Override
60
	public void setEntity(StatisticalMeasurementValue entity) {
61
		this.entity = entity;
62
		if (combo_type != null){
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

    
71
	@Override
72
	public void createControls(ICdmFormElement element, int style) {
73
		number_value = formFactory.createBigDecimalTextWithLabelElement(element, "Value", 0, style);
74
		combo_type = formFactory.createDefinedTermComboElement(TermType.StatisticalMeasure, element, "Statistical Measure", null, style);
75
		section_modifiers = formFactory.createModifierSection(getConversationHolder(), element, StoreUtil.getSectionStyle(ModifierSection.class, StatisticalMeasurementValue.class.getCanonicalName()));
76
		section_modifiers.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
77
		if (entity != null){
78
			setEntity(entity);
79
		}
80
	}
81

    
82
	@Override
83
	public void handleEvent(Object eventSource) {
84
		if(eventSource == number_value){
85
			BigDecimal bigDecimalNumber = number_value.getBigDecimal();
86
//			if(bigDecimalNumber==null){
87
//			    String zero = "0.0";
88
//			    bigDecimalNumber = new BigDecimal(zero);
89
//			    number_value.setText(zero);
90
//			}
91
            getEntity().setValue(bigDecimalNumber);
92
		}
93
		else if(eventSource == combo_type){
94
			getEntity().setType(combo_type.getSelection());
95
			combo_type.removeEmptyElement();
96
		}
97
	}
98

    
99
//	@Override
100
//	public void setEnabled(boolean enabled) {
101
//		combo_type.setEnabled(enabled);
102
//		number_value.setEnabled(enabled);
103
//		section_modifiers.setEnabled(enabled);
104
//	}
105
//
106
//	@Override
107
//	public boolean isEnabled() {		
108
//		return combo_type.isEnabled();
109
//	}
110
}
(25-25/26)