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.common.TermVocabulary;
17
import eu.etaxonomy.cdm.model.description.Feature;
18
import eu.etaxonomy.cdm.model.description.State;
19
import eu.etaxonomy.taxeditor.ui.combo.VocabularyComboElement;
20
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
21
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
22
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
23
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
24

    
25
/**
26
 * @author pplitzner
27
 * @date Apr 27, 2015
28
 *
29
 */
30
public class StateVocabularyCollectionElement extends AbstractEntityCollectionElement<TermVocabulary<State>> {
31

    
32

    
33
    private VocabularyComboElement<State, TermVocabulary<State>> comboStateVocabulary;
34

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

    
48
    }
49

    
50
    @Override
51
    public void createControls(ICdmFormElement element, int style) {
52
        comboStateVocabulary = formFactory.createVocabularyComboElement(TermType.State, "State vocabulary", null, element, style);
53
    }
54

    
55
    @Override
56
    public void setEntity(TermVocabulary<State> entity) {
57
        this.entity = entity;
58
        if(entity.getId()!=0){
59
            comboStateVocabulary.setSelection(entity);
60
            comboStateVocabulary.removeEmptyElement();
61
        }
62
    }
63

    
64
    @Override
65
    public void handleEvent(Object eventSource) {
66
        if(eventSource==comboStateVocabulary && comboStateVocabulary.getSelection()!=null){
67
            if(getParentElement() instanceof StateVocabularyCollectionSection){
68
                StateVocabularyCollectionSection parentElement = (StateVocabularyCollectionSection) getParentElement();
69
                Feature feature = parentElement.getEntity();
70
                feature.removeSupportedCategoricalEnumeration(entity);
71
                TermVocabulary<State> vocabulary = comboStateVocabulary.getSelection();
72
                feature.addSupportedCategoricalEnumeration(vocabulary);
73
                entity = vocabulary;
74
                //update the parent section to re-set the listeners to the persisted measurement unit
75
                parentElement.removeElementAndUpdate(null);
76
            }
77
        }
78
    }
79

    
80
}
(12-12/17)