1
|
/**
|
2
|
* Copyright (C) 2009 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.widgets.Label;
|
12
|
import org.eclipse.ui.forms.widgets.ExpandableComposite;
|
13
|
|
14
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
15
|
import eu.etaxonomy.cdm.model.common.Language;
|
16
|
import eu.etaxonomy.cdm.model.term.Representation;
|
17
|
import eu.etaxonomy.cdm.model.term.TermType;
|
18
|
import eu.etaxonomy.cdm.model.description.Character;
|
19
|
import eu.etaxonomy.taxeditor.editor.definedterm.TermBasePropertyTester;
|
20
|
import eu.etaxonomy.taxeditor.model.ColorResources;
|
21
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
22
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
23
|
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
25
|
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.RepresentationElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
|
31
|
import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesCollectionSection;
|
32
|
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionSection;
|
33
|
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StatisticalMeasureCollectionSection;
|
34
|
|
35
|
/**
|
36
|
*
|
37
|
* @author pplitzner
|
38
|
* @since Dec 21, 2017
|
39
|
*
|
40
|
*/
|
41
|
public class CharacterDetailElement extends AbstractCdmDetailElement<Character> {
|
42
|
|
43
|
private ICdmFormElement parentFormElement;
|
44
|
|
45
|
protected RepresentationElement element_Representation;
|
46
|
|
47
|
private TermComboElement<DefinedTerm> comboStructuralModifier;
|
48
|
|
49
|
private CheckboxElement supportsQuantitativeData;
|
50
|
|
51
|
private CheckboxElement supportsCategoricalData;
|
52
|
|
53
|
private StateVocabularyCollectionSection sectionStateVocabularies;
|
54
|
|
55
|
private MeasurementUnitCollectionSection sectionMeasurementUnits;
|
56
|
|
57
|
private StatisticalMeasureCollectionSection sectionStatisticalMeasures;
|
58
|
|
59
|
private RecommendedModifierVocabulariesCollectionSection sectionModifierVocabularies;
|
60
|
|
61
|
public CharacterDetailElement(CdmFormFactory formFactory,
|
62
|
ICdmFormElement formElement) {
|
63
|
super(formFactory, formElement);
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
protected void createControls(ICdmFormElement formElement, Character entity, int style) {
|
68
|
this.parentFormElement = formElement;
|
69
|
element_Representation = formFactory.createTranslatableRepresentationElement(formElement, getEntity().getPreferredRepresentation(CdmStore.getDefaultLanguage()),getEntity(), 100, style, true);
|
70
|
Label lblStructure = new Label(formElement.getLayoutComposite(), style);
|
71
|
lblStructure.setText("Structure");
|
72
|
Label lblStructureText = new Label(formElement.getLayoutComposite(), style);
|
73
|
lblStructureText.setText(entity.getStructure().getTerm().getLabel());
|
74
|
lblStructureText.setForeground(ColorResources.getColor(Resources.BLACK));
|
75
|
Label lblProperty = new Label(formElement.getLayoutComposite(), style);
|
76
|
lblProperty.setText("Property");
|
77
|
Label lblPropertyText = new Label(formElement.getLayoutComposite(), style);
|
78
|
lblPropertyText.setForeground(ColorResources.getColor(Resources.BLACK));
|
79
|
lblPropertyText.setText(entity.getProperty().getTerm().getLabel());
|
80
|
|
81
|
comboStructuralModifier = formFactory.createDefinedTermComboElement(TermType.StructureModifier, formElement, "Structural Modifier", entity.getStructureModifier(), style);
|
82
|
|
83
|
supportsQuantitativeData = formFactory.createCheckbox(formElement, "Supports Quantitative Data", entity.isSupportsQuantitativeData(), style);
|
84
|
supportsCategoricalData = formFactory.createCheckbox(formElement, "Supports Categorical Data", entity.isSupportsCategoricalData(), style);
|
85
|
|
86
|
if (supportsCategoricalData.getSelection()) {
|
87
|
sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
|
88
|
parentFormElement, ExpandableComposite.TWISTIE);
|
89
|
sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
90
|
sectionStateVocabularies.setEntity(getEntity());
|
91
|
|
92
|
}
|
93
|
if (supportsQuantitativeData.getSelection()) {
|
94
|
sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
|
95
|
parentFormElement, ExpandableComposite.TWISTIE);
|
96
|
sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
97
|
sectionMeasurementUnits.setEntity(getEntity());
|
98
|
|
99
|
sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(getConversationHolder(),
|
100
|
parentFormElement, ExpandableComposite.TWISTIE);
|
101
|
sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
102
|
sectionStatisticalMeasures.setEntity(getEntity());
|
103
|
}
|
104
|
if (supportsCategoricalData.getSelection() || supportsQuantitativeData.getSelection()) {
|
105
|
sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
|
106
|
getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE
|
107
|
);
|
108
|
sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
109
|
sectionModifierVocabularies.setEntity(getEntity());
|
110
|
}
|
111
|
}
|
112
|
|
113
|
@Override
|
114
|
public void setEntity(Character entity) {
|
115
|
super.setEntity(entity);
|
116
|
setEnabled(TermBasePropertyTester.isModifiable(entity));
|
117
|
}
|
118
|
|
119
|
@Override
|
120
|
public void handleEvent(Object eventSource) {
|
121
|
if(eventSource == comboStructuralModifier){
|
122
|
getEntity().setStructureModifier(comboStructuralModifier.getSelection());
|
123
|
}
|
124
|
if(eventSource == supportsQuantitativeData || eventSource == supportsCategoricalData){
|
125
|
//if any type is selected disable supportsTextData
|
126
|
getEntity().setSupportsTextData(false);
|
127
|
}
|
128
|
if(eventSource == supportsQuantitativeData){
|
129
|
getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
|
130
|
if(supportsQuantitativeData.getSelection()){
|
131
|
activateQuantitativeWidgets();
|
132
|
}
|
133
|
else{
|
134
|
removeQuantitativeWidgets();
|
135
|
}
|
136
|
}
|
137
|
else if(eventSource == supportsCategoricalData){
|
138
|
getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
|
139
|
if (supportsCategoricalData.getSelection()) {
|
140
|
activateCategoricalWidgets();
|
141
|
}
|
142
|
else{
|
143
|
removeCategoricalWidgets();
|
144
|
}
|
145
|
}
|
146
|
else if (eventSource == element_Representation) {
|
147
|
Representation selectedRepresentation = element_Representation.getSelectedRepresentation();
|
148
|
if(selectedRepresentation!=null){
|
149
|
Language representationLanguage = selectedRepresentation.getLanguage();
|
150
|
if(representationLanguage==null){
|
151
|
representationLanguage = Language.getDefaultLanguage();
|
152
|
}
|
153
|
getEntity().setLabel(selectedRepresentation.getLabel(), representationLanguage);
|
154
|
getEntity().getRepresentation(representationLanguage).setAbbreviatedLabel(selectedRepresentation.getAbbreviatedLabel());
|
155
|
getEntity().getRepresentation(representationLanguage).setText(selectedRepresentation.getDescription());
|
156
|
}
|
157
|
getEntity().setTitleCache(null);
|
158
|
}
|
159
|
}
|
160
|
|
161
|
private void activateQuantitativeWidgets(){
|
162
|
//disable categorical widgets
|
163
|
supportsCategoricalData.setSelection(false);
|
164
|
getEntity().setSupportsCategoricalData(false);
|
165
|
removeCategoricalWidgets();
|
166
|
|
167
|
//measurement units
|
168
|
sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
|
169
|
parentFormElement, ExpandableComposite.TWISTIE);
|
170
|
sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
171
|
sectionMeasurementUnits.setEntity(getEntity());
|
172
|
|
173
|
//statistical measures
|
174
|
sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(
|
175
|
getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
|
176
|
sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
177
|
sectionStatisticalMeasures.setEntity(getEntity());
|
178
|
|
179
|
//modifiers
|
180
|
sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
|
181
|
getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
|
182
|
sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
183
|
sectionModifierVocabularies.setEntity(getEntity());
|
184
|
}
|
185
|
|
186
|
private void removeQuantitativeWidgets(){
|
187
|
if(sectionMeasurementUnits!=null){
|
188
|
removeElementsAndControls(sectionMeasurementUnits);
|
189
|
removeElementsAndControls(sectionStatisticalMeasures);
|
190
|
removeElementsAndControls(sectionModifierVocabularies);
|
191
|
}
|
192
|
}
|
193
|
|
194
|
private void activateCategoricalWidgets(){
|
195
|
//disable quantitative widgeets
|
196
|
supportsQuantitativeData.setSelection(false);
|
197
|
getEntity().setSupportsQuantitativeData(false);
|
198
|
removeQuantitativeWidgets();
|
199
|
|
200
|
//states
|
201
|
sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
|
202
|
parentFormElement, ExpandableComposite.TWISTIE);
|
203
|
sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
204
|
sectionStateVocabularies.setEntity(getEntity());
|
205
|
|
206
|
//modifiers
|
207
|
sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
|
208
|
getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
|
209
|
sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
210
|
sectionModifierVocabularies.setEntity(getEntity());
|
211
|
}
|
212
|
|
213
|
private void removeCategoricalWidgets(){
|
214
|
if(sectionStateVocabularies!=null){
|
215
|
removeElementsAndControls(sectionStateVocabularies);
|
216
|
removeElementsAndControls(sectionModifierVocabularies);
|
217
|
}
|
218
|
}
|
219
|
|
220
|
}
|