Project

General

Profile

« Previous | Next » 

Revision 593915d2

Added by Patrick Plitzner over 4 years ago

ref #8475 First (unstable) implementation of FeatureState details

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/OnlyApplicableIfCollectionElement.java
11 11
import org.eclipse.swt.events.SelectionListener;
12 12
import org.eclipse.swt.graphics.Color;
13 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;
14
import eu.etaxonomy.cdm.model.description.FeatureState;
18 15
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
19 16
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
21
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
22 17

  
23 18
/**
24 19
 * @author pplitzner
25 20
 * @date Apr 27, 2015
26 21
 *
27 22
 */
28
public class OnlyApplicableIfCollectionElement extends AbstractEntityCollectionElement<State> {
23
public class OnlyApplicableIfCollectionElement extends AbstractApplicableElement {
29 24

  
30
    private TermComboElement<State> comboState;
31

  
32
    public OnlyApplicableIfCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, State entity,
33
            SelectionListener removeListener, Color backgroundColor, int style) {
25
    public OnlyApplicableIfCollectionElement(CdmFormFactory formFactory, AbstractFormSection section,
26
            FeatureState entity, SelectionListener removeListener, Color backgroundColor, int style) {
34 27
        super(formFactory, section, entity, removeListener, backgroundColor, style);
35

  
36 28
    }
37 29

  
38 30
    @Override
39
    public void createControls(ICdmFormElement element, int style) {
40
        comboState = formFactory.createDefinedTermComboElement(TermType.State, element, "Only applicable if", null, style);
31
    protected String getComboLabel() {
32
        return "Only applicable if";
41 33
    }
42 34

  
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 OnlyApplicableIfEntityCollectionSection){
56
                OnlyApplicableIfEntityCollectionSection parentElement = (OnlyApplicableIfEntityCollectionSection) getParentElement();
57
                TermNode node = parentElement.getEntity();
58
                node.removeApplicableState(entity);
59
                State state = comboState.getSelection();
60
                node.addApplicableState(state);
61
                entity = state;
62
                parentElement.removeElementAndUpdate(null);
63
            }
64
        }
65
    }
66 35

  
67 36
}

Also available in: Unified diff