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