ref #9838: change order of ui element creation and setting entity in collection elements
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / feature / AbstractApplicableElement.java
1 /**
2 * Copyright (C) 2019 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 java.util.Collections;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.SelectionListener;
15 import org.eclipse.swt.graphics.Color;
16
17 import eu.etaxonomy.cdm.model.description.Feature;
18 import eu.etaxonomy.cdm.model.description.FeatureState;
19 import eu.etaxonomy.cdm.model.description.State;
20 import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
21 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
22 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
25 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
26
27 /**
28 * @author pplitzner
29 * @since Aug 16, 2019
30 *
31 */
32 public abstract class AbstractApplicableElement extends AbstractEntityCollectionElement<FeatureState> {
33
34 private TermComboElement<State> comboState;
35 private EntitySelectionElement<Feature> selectFeature;
36
37 public AbstractApplicableElement(CdmFormFactory formFactory, AbstractFormSection section, FeatureState entity,
38 SelectionListener removeListener, Color backgroundColor, int style) {
39 super(formFactory, section, entity, removeListener, backgroundColor, style);
40
41 }
42
43 @Override
44 public void createControls(ICdmFormElement element, int style) {
45 selectFeature = formFactory.createSelectionElement(Feature.class, element, "Feature", null, EntitySelectionElement.SELECTABLE, SWT.NONE);
46 comboState = formFactory.createDefinedTermComboElement(Collections.EMPTY_LIST, element, getComboLabel(), null, style);
47 comboState.setEnabled(false);
48 selectFeature.setEnabled(false);
49
50 selectFeature.setEntity(entity.getFeature());
51 comboState.setSelection(entity.getState());
52 }
53
54 protected abstract String getComboLabel();
55
56 @Override
57 public void setEntity(FeatureState entity) {
58 this.entity = entity;
59 if (selectFeature != null){
60 selectFeature.setEntity(entity.getFeature());
61 comboState.setSelection(entity.getState());
62 }
63 }
64
65 @Override
66 public void handleEvent(Object eventSource) {
67 }
68 }