Project

General

Profile

Download (3.16 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.term.DefinedTerm;
15
import eu.etaxonomy.cdm.model.term.TermType;
16
import eu.etaxonomy.cdm.model.term.TermVocabulary;
17
import eu.etaxonomy.cdm.model.description.Feature;
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 RecommendedModifierVocabulariesElement extends AbstractEntityCollectionElement<TermVocabulary<DefinedTerm>> {
30

    
31

    
32
    private VocabularyComboElement<DefinedTerm, TermVocabulary<DefinedTerm>> 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 RecommendedModifierVocabulariesElement(CdmFormFactory formFactory, AbstractFormSection section, TermVocabulary<DefinedTerm> entity,
44
            SelectionListener removeListener, Color backgroundColor, int style) {
45
        super(formFactory, section, entity, removeListener, backgroundColor, style);
46

    
47
    }
48

    
49
    @Override
50
    public void createControls(ICdmFormElement element, int style) {
51
        comboStateVocabulary = formFactory.createVocabularyComboElement(TermType.Modifier, "Modifier Vocabulary", null, element, style);
52
        if (entity != null){
53
        	setEntity(entity);
54
        }
55
    }
56

    
57
    @Override
58
    public void setEntity(TermVocabulary<DefinedTerm> entity) {
59
        this.entity = entity;
60
        if(entity.getId()!=0 && comboStateVocabulary != null){
61
            comboStateVocabulary.setSelection(entity);
62
            comboStateVocabulary.removeEmptyElement();
63
        }
64
    }
65

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

    
82
}
(17-17/29)