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.SWT;
|
12
|
import org.eclipse.swt.widgets.Label;
|
13
|
import org.eclipse.swt.widgets.Text;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.common.Language;
|
16
|
import eu.etaxonomy.cdm.model.description.Character;
|
17
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
18
|
import eu.etaxonomy.cdm.model.term.Representation;
|
19
|
import eu.etaxonomy.cdm.model.term.TermType;
|
20
|
import eu.etaxonomy.taxeditor.editor.definedterm.TermBasePropertyTester;
|
21
|
import eu.etaxonomy.taxeditor.model.ColorResources;
|
22
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
23
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
24
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
25
|
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.RemovableTextElement;
|
31
|
import eu.etaxonomy.taxeditor.ui.element.RepresentationElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
33
|
import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
|
34
|
import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesCollectionSection;
|
35
|
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionSection;
|
36
|
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StatisticalMeasureCollectionSection;
|
37
|
|
38
|
/**
|
39
|
*
|
40
|
* @author pplitzner
|
41
|
* @since Dec 21, 2017
|
42
|
*
|
43
|
*/
|
44
|
public class CharacterDetailElement extends AbstractCdmDetailElement<Character> {
|
45
|
|
46
|
private ICdmFormElement parentFormElement;
|
47
|
|
48
|
protected RepresentationElement element_Representation;
|
49
|
|
50
|
private TermComboElement<DefinedTerm> comboStructuralModifier;
|
51
|
|
52
|
private CheckboxElement supportsQuantitativeData;
|
53
|
|
54
|
private CheckboxElement supportsCategoricalData;
|
55
|
|
56
|
private StateVocabularyCollectionSection sectionStateVocabularies;
|
57
|
|
58
|
private MeasurementUnitCollectionSection sectionMeasurementUnits;
|
59
|
|
60
|
private StatisticalMeasureCollectionSection sectionStatisticalMeasures;
|
61
|
|
62
|
private RecommendedModifierVocabulariesCollectionSection sectionModifierVocabularies;
|
63
|
private Label labelText_structure;
|
64
|
private Text text_structure;
|
65
|
|
66
|
private Label labelText_property;
|
67
|
private Text text_property;
|
68
|
|
69
|
private RemovableTextElement ratioTo;
|
70
|
// private Label labelText_ratioTo;
|
71
|
// private Text text_ratioTo;
|
72
|
// private Button button_remove;
|
73
|
|
74
|
|
75
|
// private TextWithLabelElement text_structure;
|
76
|
// private TextWithLabelElement text_property;
|
77
|
|
78
|
|
79
|
public CharacterDetailElement(CdmFormFactory formFactory,
|
80
|
ICdmFormElement formElement) {
|
81
|
super(formFactory, formElement);
|
82
|
}
|
83
|
|
84
|
@Override
|
85
|
protected void createControls(ICdmFormElement formElement, Character entity, int style) {
|
86
|
this.parentFormElement = formElement;
|
87
|
element_Representation = formFactory.createTranslatableRepresentationElement(formElement, entity.getPreferredRepresentation(CdmStore.getDefaultLanguage()),entity, 100, style, true);
|
88
|
if (labelText_property != null){
|
89
|
labelText_structure.dispose();
|
90
|
}
|
91
|
labelText_structure = new Label(formElement.getLayoutComposite(), SWT.NONE);
|
92
|
labelText_structure.setText("Structure");
|
93
|
if (text_structure != null){
|
94
|
text_structure.dispose();
|
95
|
}
|
96
|
text_structure = new Text(formElement.getLayoutComposite(), SWT.WRAP);
|
97
|
text_structure.setText( CharacterNodeDetailElement.getStructureText(entity));
|
98
|
text_structure.setEditable(false);
|
99
|
text_structure.setLayoutData(LayoutConstants.FILL());
|
100
|
text_structure.setForeground(ColorResources.getColor(Resources.BLACK));
|
101
|
if (labelText_property != null){
|
102
|
labelText_property.dispose();
|
103
|
}
|
104
|
labelText_property = new Label(formElement.getLayoutComposite(), SWT.NONE);
|
105
|
labelText_property.setText("Property");
|
106
|
if (text_property != null){
|
107
|
text_property.dispose();
|
108
|
}
|
109
|
text_property = new Text(formElement.getLayoutComposite(), SWT.WRAP);
|
110
|
text_property.setEditable(false);
|
111
|
text_property.setText( CharacterNodeDetailElement.getPropertyText(entity));
|
112
|
text_property.setLayoutData(LayoutConstants.FILL());
|
113
|
text_property.setForeground(ColorResources.getColor(Resources.BLACK));
|
114
|
|
115
|
comboStructuralModifier = formFactory.createDefinedTermComboElement(TermType.StructureModifier, formElement, "Structural Modifier", entity.getStructureModifier(), style);
|
116
|
|
117
|
ratioTo = formFactory.createRemovableTextField(formElement, "Ratio to", CharacterNodeDetailElement.getRatioToText(entity), style);
|
118
|
|
119
|
supportsQuantitativeData = formFactory.createCheckbox(formElement, "Supports Quantitative Data", entity.isSupportsQuantitativeData(), style);
|
120
|
supportsCategoricalData = formFactory.createCheckbox(formElement, "Supports Categorical Data", entity.isSupportsCategoricalData(), style);
|
121
|
|
122
|
if (supportsCategoricalData.getSelection()) {
|
123
|
sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
|
124
|
parentFormElement, StoreUtil.getSectionStyle(StateVocabularyCollectionSection.class, entity.getClass().getCanonicalName(), true));
|
125
|
sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
126
|
sectionStateVocabularies.setEntity(entity);
|
127
|
}
|
128
|
if (supportsQuantitativeData.getSelection()) {
|
129
|
sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
|
130
|
parentFormElement, StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, entity.getClass().getCanonicalName(), true));
|
131
|
sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
132
|
sectionMeasurementUnits.setEntity(entity);
|
133
|
|
134
|
sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(getConversationHolder(),
|
135
|
parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, entity.getClass().getCanonicalName(), true));
|
136
|
sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
137
|
sectionStatisticalMeasures.setEntity(entity);
|
138
|
}
|
139
|
if (supportsCategoricalData.getSelection() || supportsQuantitativeData.getSelection()) {
|
140
|
sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
|
141
|
getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, entity.getClass().getCanonicalName(), true));
|
142
|
sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
143
|
sectionModifierVocabularies.setEntity(entity);
|
144
|
}
|
145
|
|
146
|
|
147
|
}
|
148
|
// public void createText(ICdmFormElement formElement, String label, String path) {
|
149
|
// labelText = new Label(formElement.getLayoutComposite(), SWT.NONE);
|
150
|
// labelText.setText(label);
|
151
|
// Text text = new Text(formElement.getLayoutComposite(), SWT.WRAP);
|
152
|
// text.setText(path);
|
153
|
// text.setEditable(false);
|
154
|
// text.setLayoutData(LayoutConstants.FILL());
|
155
|
// text.setForeground(ColorResources.getColor(Resources.BLACK));
|
156
|
// }
|
157
|
|
158
|
@Override
|
159
|
public void setEntity(Character entity) {
|
160
|
super.setEntity(entity);
|
161
|
setEnabled(TermBasePropertyTester.isModifiable(entity));
|
162
|
}
|
163
|
|
164
|
@Override
|
165
|
public void handleEvent(Object eventSource) {
|
166
|
if(eventSource == comboStructuralModifier){
|
167
|
getEntity().setStructureModifier(comboStructuralModifier.getSelection());
|
168
|
}
|
169
|
if(eventSource == ratioTo){
|
170
|
if (!ratioTo.isState()){
|
171
|
getEntity().setRatioToStructure(null);
|
172
|
}
|
173
|
}
|
174
|
|
175
|
// if(eventSource == supportsQuantitativeData || eventSource == supportsCategoricalData){
|
176
|
// //if any type is selected disable supportsTextData
|
177
|
// getEntity().setSupportsTextData(false);
|
178
|
// }
|
179
|
if(eventSource == supportsQuantitativeData){
|
180
|
getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
|
181
|
if(supportsQuantitativeData.getSelection()){
|
182
|
activateQuantitativeWidgets();
|
183
|
}
|
184
|
else{
|
185
|
removeQuantitativeWidgets();
|
186
|
}
|
187
|
StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
|
188
|
}
|
189
|
else if(eventSource == supportsCategoricalData){
|
190
|
getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
|
191
|
if (supportsCategoricalData.getSelection()) {
|
192
|
activateCategoricalWidgets();
|
193
|
}
|
194
|
else{
|
195
|
removeCategoricalWidgets();
|
196
|
}
|
197
|
StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
|
198
|
}
|
199
|
else if (eventSource == element_Representation) {
|
200
|
Representation selectedRepresentation = element_Representation.getSelectedRepresentation();
|
201
|
if(selectedRepresentation!=null){
|
202
|
Language representationLanguage = selectedRepresentation.getLanguage();
|
203
|
if(representationLanguage==null){
|
204
|
representationLanguage = Language.getDefaultLanguage();
|
205
|
}
|
206
|
getEntity().setLabel(selectedRepresentation.getLabel(), representationLanguage);
|
207
|
getEntity().getRepresentation(representationLanguage).setAbbreviatedLabel(selectedRepresentation.getAbbreviatedLabel());
|
208
|
getEntity().getRepresentation(representationLanguage).setText(selectedRepresentation.getDescription());
|
209
|
}
|
210
|
getEntity().setTitleCache(null);
|
211
|
}
|
212
|
}
|
213
|
|
214
|
private void activateQuantitativeWidgets(){
|
215
|
//disable categorical widgets
|
216
|
supportsCategoricalData.setSelection(false);
|
217
|
getEntity().setSupportsCategoricalData(false);
|
218
|
removeCategoricalWidgets();
|
219
|
|
220
|
//measurement units
|
221
|
sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
|
222
|
parentFormElement, StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
|
223
|
sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
224
|
sectionMeasurementUnits.setEntity(getEntity());
|
225
|
|
226
|
//statistical measures
|
227
|
sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(
|
228
|
getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
|
229
|
sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
230
|
sectionStatisticalMeasures.setEntity(getEntity());
|
231
|
|
232
|
//modifiers
|
233
|
sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
|
234
|
getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
|
235
|
sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
236
|
sectionModifierVocabularies.setEntity(getEntity());
|
237
|
}
|
238
|
|
239
|
private void removeQuantitativeWidgets(){
|
240
|
if(sectionMeasurementUnits!=null){
|
241
|
removeElementsAndControls(sectionMeasurementUnits);
|
242
|
removeElementsAndControls(sectionStatisticalMeasures);
|
243
|
removeElementsAndControls(sectionModifierVocabularies);
|
244
|
}
|
245
|
}
|
246
|
|
247
|
private void activateCategoricalWidgets(){
|
248
|
//disable quantitative widgeets
|
249
|
supportsQuantitativeData.setSelection(false);
|
250
|
getEntity().setSupportsQuantitativeData(false);
|
251
|
removeQuantitativeWidgets();
|
252
|
|
253
|
//states
|
254
|
sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
|
255
|
parentFormElement, StoreUtil.getSectionStyle(StateVocabularyCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
|
256
|
sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
257
|
sectionStateVocabularies.setEntity(getEntity());
|
258
|
|
259
|
//modifiers
|
260
|
sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
|
261
|
getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
|
262
|
sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
263
|
sectionModifierVocabularies.setEntity(getEntity());
|
264
|
}
|
265
|
|
266
|
private void removeCategoricalWidgets(){
|
267
|
if(sectionStateVocabularies!=null){
|
268
|
removeElementsAndControls(sectionStateVocabularies);
|
269
|
removeElementsAndControls(sectionModifierVocabularies);
|
270
|
}
|
271
|
}
|
272
|
|
273
|
}
|