Project

General

Profile

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

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

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

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

    
31

    
32
    private TermComboElement<StatisticalMeasure> comboStatisticalMeasure;
33

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

    
47
    }
48

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

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

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

    
79
}
(15-15/19)