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.ArrayList;
|
12
|
import java.util.Collections;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.eclipse.swt.SWT;
|
17
|
import org.eclipse.swt.events.SelectionListener;
|
18
|
import org.eclipse.swt.graphics.Color;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
21
|
import eu.etaxonomy.cdm.model.description.Feature;
|
22
|
import eu.etaxonomy.cdm.model.description.FeatureState;
|
23
|
import eu.etaxonomy.cdm.model.description.State;
|
24
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
25
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
26
|
import eu.etaxonomy.cdm.model.term.TermType;
|
27
|
import eu.etaxonomy.cdm.persistence.dto.FeatureStateDto;
|
28
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29
|
import eu.etaxonomy.taxeditor.store.TermManager;
|
30
|
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
|
31
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
32
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
33
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
34
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
|
35
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
36
|
|
37
|
/**
|
38
|
* @author pplitzner
|
39
|
* @since Aug 16, 2019
|
40
|
*
|
41
|
*/
|
42
|
public abstract class AbstractApplicableElementForDto extends AbstractEntityCollectionElement<FeatureStateDto> {
|
43
|
|
44
|
protected TermComboElement<State> comboState;
|
45
|
protected EntitySelectionElement<Feature> selectFeature;
|
46
|
|
47
|
|
48
|
public AbstractApplicableElementForDto(CdmFormFactory formFactory, AbstractFormSection section, FeatureStateDto entity,
|
49
|
SelectionListener removeListener, Color backgroundColor, int style) {
|
50
|
super(formFactory, section, entity, removeListener, backgroundColor, style);
|
51
|
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
public void createControls(ICdmFormElement element, int style) {
|
56
|
selectFeature = formFactory.createSelectionElement(Feature.class, element, "Feature", null, EntitySelectionElement.DELETABLE, SWT.NONE);
|
57
|
comboState = formFactory.createDefinedTermComboElement(Collections.EMPTY_LIST, element, getComboLabel(), null, style);
|
58
|
setFeatureState();
|
59
|
}
|
60
|
|
61
|
private void setFeatureState() {
|
62
|
Feature feature = (Feature)CdmStore.getService(ITermService.class).load(entity.getFeature().getUuid());
|
63
|
selectFeature.setEntity(feature);
|
64
|
List<UUID> termList = new ArrayList<>();
|
65
|
termList.add(entity.getState().getUuid());
|
66
|
List<State> terms = CdmStore.getTermManager().getTerms(termList, TermType.State);
|
67
|
if (terms.size() == 1){
|
68
|
comboState.setSelection(terms.get(0));
|
69
|
}
|
70
|
|
71
|
}
|
72
|
|
73
|
protected abstract String getComboLabel();
|
74
|
|
75
|
@Override
|
76
|
public void setEntity(FeatureStateDto entity) {
|
77
|
this.entity = entity;
|
78
|
if (selectFeature != null){
|
79
|
setFeatureState();
|
80
|
}
|
81
|
}
|
82
|
|
83
|
@Override
|
84
|
public void handleEvent(Object eventSource) {
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
public void setEnabled(boolean enabled){
|
89
|
super.setEnabled(enabled);
|
90
|
this.comboState.setEnabled(false);
|
91
|
this.selectFeature.setEnabled(false);
|
92
|
}
|
93
|
}
|