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