Project

General

Profile

Download (3.54 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.persistence.dto.FeatureDto;
18
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
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 RecommendedModifierDtoVocabulariesElement extends AbstractEntityCollectionElement<TermVocabularyDto> {
31

    
32

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

    
48
    }
49

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

    
58
    @Override
59
    public void setEntity(TermVocabularyDto entity) {
60
        this.entity = entity;
61
        if(comboStateVocabulary != null){
62
            comboStateVocabulary.setSelectionDto(entity);
63
            comboStateVocabulary.removeEmptyElement();
64
        }
65
    }
66

    
67

    
68
    @Override
69
    public void handleEvent(Object eventSource) {
70
        if(eventSource==comboStateVocabulary && comboStateVocabulary.getSelection()!=null){
71
            if(getParentElement() instanceof RecommendedModifierVocabulariesDtoCollectionSection){
72
                RecommendedModifierVocabulariesDtoCollectionSection parentElement = (RecommendedModifierVocabulariesDtoCollectionSection) getParentElement();
73
                FeatureDto feature = parentElement.getEntity();
74
                TermVocabularyDto remove = null;
75
                for (TermVocabularyDto voc: feature.getRecommendedModifierEnumeration()){
76
                    if (voc.getUuid().equals(getEntity().getUuid())){
77
                        remove = voc;
78
                        break;
79
                    }
80
                }
81
                feature.getRecommendedModifierEnumeration().remove(remove);
82
                TermVocabulary<DefinedTerm> vocabulary = comboStateVocabulary.getSelection();
83
                entity = TermVocabularyDto.fromVocabulary(vocabulary);
84
                feature.getRecommendedModifierEnumeration().add(entity);
85
                //update the parent section to re-set the listeners to the persisted measurement unit
86
//                parentElement.removeElementAndUpdate(null);
87
            }
88
        }
89
    }
90

    
91
}
(14-14/29)