Project

General

Profile

Download (2.41 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.feature;
10

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

    
14
import eu.etaxonomy.cdm.model.description.State;
15
import eu.etaxonomy.cdm.model.term.TermNode;
16
import eu.etaxonomy.cdm.model.term.TermType;
17
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
18
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
19
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
21
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
22

    
23
/**
24
 * @author pplitzner
25
 * @date Apr 27, 2015
26
 *
27
 */
28
public class InapplicableIfCollectionElement extends AbstractEntityCollectionElement<State> {
29

    
30
    private TermComboElement<State> comboState;
31

    
32
    public InapplicableIfCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, State entity,
33
            SelectionListener removeListener, Color backgroundColor, int style) {
34
        super(formFactory, section, entity, removeListener, backgroundColor, style);
35

    
36
    }
37

    
38
    @Override
39
    public void createControls(ICdmFormElement element, int style) {
40
        comboState = formFactory.createDefinedTermComboElement(TermType.State, element, "Inapplicable if", null, style);
41
    }
42

    
43
    @Override
44
    public void setEntity(State entity) {
45
        this.entity = entity;
46
        if(entity.getId()!=0){
47
            comboState.setSelection(entity);
48
            comboState.removeEmptyElement();
49
        }
50
    }
51

    
52
    @Override
53
    public void handleEvent(Object eventSource) {
54
        if(eventSource==comboState && comboState.getSelection()!=null){
55
            if(getParentElement() instanceof InapplicableIfEntityCollectionSection){
56
                InapplicableIfEntityCollectionSection parentElement = (InapplicableIfEntityCollectionSection) getParentElement();
57
                TermNode node = parentElement.getEntity();
58
                node.removeInapplicableState(entity);
59
                State state = comboState.getSelection();
60
                node.addInapplicableState(state);
61
                entity = state;
62
                parentElement.removeElementAndUpdate(null);
63
            }
64
        }
65
    }
66

    
67
}
(9-9/12)