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.Feature;
|
15
|
import eu.etaxonomy.cdm.model.description.State;
|
16
|
import eu.etaxonomy.cdm.model.term.TermNode;
|
17
|
import eu.etaxonomy.cdm.model.term.TermType;
|
18
|
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
|
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 OnlyApplicableIfCollectionElement extends AbstractEntityCollectionElement<State> {
|
30
|
|
31
|
private TermComboElement<State> comboState;
|
32
|
|
33
|
public OnlyApplicableIfCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, State entity,
|
34
|
SelectionListener removeListener, Color backgroundColor, int style) {
|
35
|
super(formFactory, section, entity, removeListener, backgroundColor, style);
|
36
|
|
37
|
}
|
38
|
|
39
|
@Override
|
40
|
public void createControls(ICdmFormElement element, int style) {
|
41
|
comboState = formFactory.createDefinedTermComboElement(TermType.State, element, "Only applicable if", null, style);
|
42
|
}
|
43
|
|
44
|
@Override
|
45
|
public void setEntity(State entity) {
|
46
|
this.entity = entity;
|
47
|
if(entity.getId()!=0){
|
48
|
comboState.setSelection(entity);
|
49
|
comboState.removeEmptyElement();
|
50
|
}
|
51
|
}
|
52
|
|
53
|
@Override
|
54
|
public void handleEvent(Object eventSource) {
|
55
|
if(eventSource==comboState && comboState.getSelection()!=null){
|
56
|
if(getParentElement() instanceof OnlyApplicableIfEntityCollectionSection){
|
57
|
OnlyApplicableIfEntityCollectionSection parentElement = (OnlyApplicableIfEntityCollectionSection) getParentElement();
|
58
|
TermNode<Feature> node = parentElement.getEntity();
|
59
|
node.removeApplicableState(entity);
|
60
|
State state = comboState.getSelection();
|
61
|
node.addApplicableState(state);
|
62
|
entity = state;
|
63
|
parentElement.removeElementAndUpdate(null);
|
64
|
}
|
65
|
}
|
66
|
}
|
67
|
|
68
|
}
|