Project

General

Profile

« Previous | Next » 

Revision cf3d9f76

Added by Patrick Plitzner over 4 years ago

ref #8475 Create FeatureState in wizard dialog

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/feature/AbstractApplicableElement.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.ui.section.feature;
10 10

  
11
import java.util.ArrayList;
12 11
import java.util.Collections;
13
import java.util.List;
14
import java.util.Set;
15 12

  
16 13
import org.eclipse.swt.SWT;
17 14
import org.eclipse.swt.events.SelectionListener;
......
20 17
import eu.etaxonomy.cdm.model.description.Feature;
21 18
import eu.etaxonomy.cdm.model.description.FeatureState;
22 19
import eu.etaxonomy.cdm.model.description.State;
23
import eu.etaxonomy.cdm.model.term.TermNode;
24
import eu.etaxonomy.cdm.model.term.TermVocabulary;
25 20
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
26 21
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
27 22
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
......
50 45
        selectFeature = formFactory.createSelectionElement(Feature.class, element, "Feature", null, EntitySelectionElement.SELECTABLE, SWT.NONE);
51 46
        comboState = formFactory.createDefinedTermComboElement(Collections.EMPTY_LIST, element, getComboLabel(), null, style);
52 47
        comboState.setEnabled(false);
48
        selectFeature.setEnabled(false);
53 49
    }
54 50

  
55 51
    protected abstract String getComboLabel();
......
57 53
    @Override
58 54
    public void setEntity(FeatureState entity) {
59 55
        this.entity = entity;
60
        Feature feature = entity.getFeature();
61
        selectFeature.setEntity(feature);
62
        if(feature!=null){
63
            updateCombo(feature);
64
        }
65
    }
66

  
67
    private void updateCombo(Feature feature){
68
        comboState.setEnabled(true);
69
        List<State> stateTerms = new ArrayList<State>();
70
        Set<TermVocabulary<State>> stateVocabularies = feature.getSupportedCategoricalEnumerations();
71
        for (TermVocabulary<State> termVocabulary : stateVocabularies) {
72
            stateTerms.addAll(termVocabulary.getTerms());
73
        }
74
        comboState.setTerms(stateTerms);
56
        selectFeature.setEntity(entity.getFeature());
75 57
        comboState.setSelection(entity.getState());
76
        if(getEntity().getId()>0){
77
            comboState.removeEmptyElement();
78
        }
79 58
    }
80 59

  
81 60
    @Override
82 61
    public void handleEvent(Object eventSource) {
83
        if(eventSource==selectFeature){
84
            Feature feature = selectFeature.getSelection();
85
            entity.setFeature(feature);
86
            updateCombo(feature);
87
        }
88
        else if(eventSource==comboState && comboState.getSelection()!=null){
89
            if(getParentElement() instanceof OnlyApplicableIfEntityCollectionSection){
90
                OnlyApplicableIfEntityCollectionSection parentElement = (OnlyApplicableIfEntityCollectionSection) getParentElement();
91
                TermNode node = parentElement.getEntity();
92
                node.removeApplicableState(entity);
93
                State state = comboState.getSelection();
94
                entity.setState(state);
95
                node.addApplicableState(entity);
96
                parentElement.removeElementAndUpdate(null);
97
            }
98
        }
99 62
    }
100 63
}

Also available in: Unified diff