Project

General

Profile

Download (2.97 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 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
package eu.etaxonomy.taxeditor.ui.section.vocabulary;
10

    
11
import org.eclipse.swt.events.SelectionListener;
12
import org.eclipse.swt.graphics.Color;
13

    
14
import eu.etaxonomy.cdm.model.common.TermType;
15
import eu.etaxonomy.cdm.model.description.Feature;
16
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
17
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
18
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
19
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
21
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
22

    
23
/**
24
 * @author pplitzner
25
 * @date Apr 27, 2015
26
 *
27
 */
28
public class StatisticalMeasureCollectionElement extends AbstractEntityCollectionElement<StatisticalMeasure> {
29

    
30

    
31
    private TermComboElement<StatisticalMeasure> comboStatisticalMeasure;
32

    
33
    /**
34
     * @param formFactory
35
     * @param section
36
     * @param entity
37
     * @param removeListener
38
     * @param isChoosableEntity
39
     * @param backgroundColor
40
     * @param style
41
     */
42
    public StatisticalMeasureCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, StatisticalMeasure entity,
43
            SelectionListener removeListener, Color backgroundColor, int style) {
44
        super(formFactory, section, entity, removeListener, backgroundColor, style);
45

    
46
    }
47

    
48
    @Override
49
    public void createControls(ICdmFormElement element, int style) {
50
        comboStatisticalMeasure = formFactory.createDefinedTermComboElement(TermType.StatisticalMeasure, element, "Statistical measure", null, style);
51
    }
52

    
53
    @Override
54
    public void setEntity(StatisticalMeasure entity) {
55
        this.entity = entity;
56
        if(entity.getId()!=0){
57
            comboStatisticalMeasure.setSelection(entity);
58
            comboStatisticalMeasure.removeEmptyElement();
59
        }
60
    }
61

    
62
    @Override
63
    public void handleEvent(Object eventSource) {
64
        if(eventSource==comboStatisticalMeasure && comboStatisticalMeasure.getSelection()!=null){
65
            if(getParentElement() instanceof StatisticalMeasureCollectionSection){
66
                StatisticalMeasureCollectionSection parentElement = (StatisticalMeasureCollectionSection) getParentElement();
67
                Feature feature = parentElement.getEntity();
68
                feature.removeRecommendedStatisticalMeasure(entity);
69
                StatisticalMeasure statisticalMeasure = comboStatisticalMeasure.getSelection();
70
                feature.addRecommendedStatisticalMeasure(statisticalMeasure);
71
                entity = statisticalMeasure;
72
                //update the parent section to re-set the listeners to the persisted measurement unit
73
                parentElement.removeElementAndUpdate(null);
74
            }
75
        }
76
    }
77

    
78
}
(15-15/19)