Project

General

Profile

Download (2.97 KB) Statistics
| Branch: | Tag: | Revision:
1 cab4c925 Patric Plitzner
/**
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.common.TermVocabulary;
16
import eu.etaxonomy.cdm.model.description.Feature;
17
import eu.etaxonomy.cdm.model.description.State;
18
import eu.etaxonomy.taxeditor.ui.combo.VocabularyComboElement;
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 StateVocabularyCollectionElement extends AbstractEntityCollectionElement<TermVocabulary<State>> {
30
31
32
    private VocabularyComboElement<State, TermVocabulary<State>> comboStateVocabulary;
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 StateVocabularyCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, TermVocabulary<State> entity,
44
            SelectionListener removeListener, Color backgroundColor, int style) {
45 d89cdff1 Patrick Plitzner
        super(formFactory, section, entity, removeListener, backgroundColor, style);
46 cab4c925 Patric Plitzner
47
    }
48
49
    @Override
50
    public void createControls(ICdmFormElement element, int style) {
51 b0d7867b Patric Plitzner
        comboStateVocabulary = formFactory.createVocabularyComboElement(TermType.State, "State vocabulary", null, element, style);
52 cab4c925 Patric Plitzner
    }
53
54
    @Override
55
    public void setEntity(TermVocabulary<State> entity) {
56
        this.entity = entity;
57
        if(entity.getId()!=0){
58
            comboStateVocabulary.setSelection(entity);
59 b0d7867b Patric Plitzner
            comboStateVocabulary.removeEmptyElement();
60 cab4c925 Patric Plitzner
        }
61
    }
62
63
    @Override
64
    public void handleEvent(Object eventSource) {
65
        if(eventSource==comboStateVocabulary && comboStateVocabulary.getSelection()!=null){
66
            if(getParentElement() instanceof StateVocabularyCollectionSection){
67 b0d7867b Patric Plitzner
                StateVocabularyCollectionSection parentElement = (StateVocabularyCollectionSection) getParentElement();
68
                Feature feature = parentElement.getEntity();
69 cab4c925 Patric Plitzner
                feature.removeSupportedCategoricalEnumeration(entity);
70
                TermVocabulary<State> vocabulary = comboStateVocabulary.getSelection();
71
                feature.addSupportedCategoricalEnumeration(vocabulary);
72
                entity = vocabulary;
73 b0d7867b Patric Plitzner
                //update the parent section to re-set the listeners to the persisted measurement unit
74
                parentElement.removeElementAndUpdate(null);
75 cab4c925 Patric Plitzner
            }
76
        }
77
    }
78
79
}