2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.feature
;
11 import org
.eclipse
.swt
.SWT
;
12 import org
.eclipse
.swt
.widgets
.Label
;
13 import org
.eclipse
.swt
.widgets
.Text
;
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
.TermNode
;
20 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
21 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.TermBasePropertyTester
;
22 import eu
.etaxonomy
.taxeditor
.model
.ColorResources
;
23 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
24 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
25 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
26 import eu
.etaxonomy
.taxeditor
.ui
.combo
.term
.TermComboElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
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
;
44 public class CharacterNodeDetailElement
extends AbstractCdmDetailElement
<TermNode
<Character
>> {
46 private ICdmFormElement parentFormElement
;
48 protected RepresentationElement element_Representation
;
50 private TermComboElement
<DefinedTerm
> comboStructuralModifier
;
52 private CheckboxElement supportsQuantitativeData
;
54 private CheckboxElement supportsCategoricalData
;
56 private StateVocabularyCollectionSection sectionStateVocabularies
;
58 private MeasurementUnitCollectionSection sectionMeasurementUnits
;
60 private StatisticalMeasureCollectionSection sectionStatisticalMeasures
;
62 private RecommendedModifierVocabulariesCollectionSection sectionModifierVocabularies
;
64 private InapplicableIfEntityCollectionSectionForNode sectionInapplicableIf
;
65 private OnlyApplicableIfEntityCollectionSectionForNode sectionOnlyApplicableIf
;
67 public CharacterNodeDetailElement(CdmFormFactory formFactory
,
68 ICdmFormElement formElement
) {
69 super(formFactory
, formElement
);
73 protected void createControls(ICdmFormElement formElement
, TermNode
<Character
> entity
, int style
) {
74 this.parentFormElement
= formElement
;
75 element_Representation
= formFactory
.createTranslatableRepresentationElement(formElement
, entity
.getTerm().getPreferredRepresentation(CdmStore
.getDefaultLanguage()),entity
.getTerm(), 100, style
, true);
77 createText(formElement
, "Structure", getStructureText(entity
.getTerm()));
78 createText(formElement
, "Property", getPropertyText(entity
.getTerm()));
80 comboStructuralModifier
= formFactory
.createDefinedTermComboElement(TermType
.StructureModifier
, formElement
, "Structural Modifier", entity
.getTerm().getStructureModifier(), style
);
82 supportsQuantitativeData
= formFactory
.createCheckbox(formElement
, "Supports Quantitative Data", entity
.getTerm().isSupportsQuantitativeData(), style
);
83 supportsCategoricalData
= formFactory
.createCheckbox(formElement
, "Supports Categorical Data", entity
.getTerm().isSupportsCategoricalData(), style
);
85 if (supportsCategoricalData
.getSelection()) {
86 sectionStateVocabularies
= formFactory
.createStateVocabulariesSection(getConversationHolder(),
87 parentFormElement
, StoreUtil
.getSectionStyle(StateVocabularyCollectionSection
.class, entity
.getClass().getCanonicalName(), true));
88 sectionStateVocabularies
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
89 sectionStateVocabularies
.setEntity(entity
.getTerm());
91 if (supportsQuantitativeData
.getSelection()) {
92 sectionMeasurementUnits
= formFactory
.createMeasurementUnitCollectionSection(getConversationHolder(),
93 parentFormElement
, StoreUtil
.getSectionStyle(MeasurementUnitCollectionSection
.class, entity
.getClass().getCanonicalName(), true));
94 sectionMeasurementUnits
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
95 sectionMeasurementUnits
.setEntity(entity
.getTerm());
97 sectionStatisticalMeasures
= formFactory
.createStatisticalMeasureCollectionSection(getConversationHolder(),
98 parentFormElement
, StoreUtil
.getSectionStyle(StatisticalMeasureCollectionSection
.class, entity
.getClass().getCanonicalName(), true));
99 sectionStatisticalMeasures
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
100 sectionStatisticalMeasures
.setEntity(entity
.getTerm());
102 if (supportsCategoricalData
.getSelection() || supportsQuantitativeData
.getSelection()) {
103 sectionModifierVocabularies
= formFactory
.createRecommendedModifierVocabulariesCollectionSection(
104 getConversationHolder(), parentFormElement
, StoreUtil
.getSectionStyle(RecommendedModifierVocabulariesCollectionSection
.class, entity
.getClass().getCanonicalName(), true));
105 sectionModifierVocabularies
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
106 sectionModifierVocabularies
.setEntity(entity
.getTerm());
110 sectionInapplicableIf
= formFactory
.createInapplicableIfEntityCollectionSectionForNode(getConversationHolder(),
111 formElement
, StoreUtil
.getSectionStyle(InapplicableIfEntityCollectionSection
.class, entity
.getTerm().getClass().getCanonicalName()));
112 sectionInapplicableIf
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
113 sectionInapplicableIf
.setEntity(getEntity());
114 sectionOnlyApplicableIf
= formFactory
.createOnlyApplicableIfEntityCollectionSectionForNode(getConversationHolder(),
115 formElement
, StoreUtil
.getSectionStyle(OnlyApplicableIfEntityCollectionSection
.class, entity
.getTerm().getClass().getCanonicalName()));
116 sectionOnlyApplicableIf
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
117 sectionOnlyApplicableIf
.setEntity(entity
);
120 public static void createText(ICdmFormElement formElement
, String label
, String path
) {
121 Label labelText
= new Label(formElement
.getLayoutComposite(), SWT
.NONE
);
122 labelText
.setText(label
);
123 Text text
= new Text(formElement
.getLayoutComposite(), SWT
.WRAP
);
125 text
.setEditable(false);
126 text
.setLayoutData(LayoutConstants
.FILL());
127 text
.setForeground(ColorResources
.getColor(Resources
.BLACK
));
130 public static String
getPropertyText(Character entity
) {
131 return entity
.getProperty()!=null?StoreUtil
.getPath(entity
.getProperty()):"[no property]";
134 public static String
getStructureText(Character entity
) {
135 return entity
.getStructure()!=null?StoreUtil
.getPath(entity
.getStructure()):"[no structure]";
139 public void setEntity(TermNode
<Character
> entity
) {
140 super.setEntity(entity
);
141 setEnabled(TermBasePropertyTester
.isModifiable(entity
));
145 public void handleEvent(Object eventSource
) {
146 if(eventSource
== comboStructuralModifier
){
147 getEntity().getTerm().setStructureModifier(comboStructuralModifier
.getSelection());
149 if(eventSource
== supportsQuantitativeData
|| eventSource
== supportsCategoricalData
){
150 //if any type is selected disable supportsTextData
151 getEntity().getTerm().setSupportsTextData(false);
153 if(eventSource
== supportsQuantitativeData
){
154 getEntity().getTerm().setSupportsQuantitativeData(supportsQuantitativeData
.getSelection());
155 if(supportsQuantitativeData
.getSelection()){
156 activateQuantitativeWidgets();
159 removeQuantitativeWidgets();
161 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
163 else if(eventSource
== supportsCategoricalData
){
164 getEntity().getTerm().setSupportsCategoricalData(supportsCategoricalData
.getSelection());
165 if (supportsCategoricalData
.getSelection()) {
166 activateCategoricalWidgets();
169 removeCategoricalWidgets();
171 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
173 else if (eventSource
== element_Representation
) {
174 Representation selectedRepresentation
= element_Representation
.getSelectedRepresentation();
175 if(selectedRepresentation
!=null){
176 Language representationLanguage
= selectedRepresentation
.getLanguage();
177 if(representationLanguage
==null){
178 representationLanguage
= Language
.getDefaultLanguage();
180 getEntity().getTerm().setLabel(selectedRepresentation
.getLabel(), representationLanguage
);
181 getEntity().getTerm().getRepresentation(representationLanguage
).setAbbreviatedLabel(selectedRepresentation
.getAbbreviatedLabel());
182 getEntity().getTerm().getRepresentation(representationLanguage
).setText(selectedRepresentation
.getDescription());
184 getEntity().getTerm().setTitleCache(null);
188 private void activateQuantitativeWidgets(){
189 //disable categorical widgets
190 supportsCategoricalData
.setSelection(false);
191 getEntity().getTerm().setSupportsCategoricalData(false);
192 removeCategoricalWidgets();
195 sectionMeasurementUnits
= formFactory
.createMeasurementUnitCollectionSection(getConversationHolder(),
196 parentFormElement
, StoreUtil
.getSectionStyle(MeasurementUnitCollectionSection
.class, getEntity().getClass().getCanonicalName(), true));
197 sectionMeasurementUnits
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
198 sectionMeasurementUnits
.setEntity(getEntity().getTerm());
200 //statistical measures
201 sectionStatisticalMeasures
= formFactory
.createStatisticalMeasureCollectionSection(
202 getConversationHolder(), parentFormElement
, StoreUtil
.getSectionStyle(StatisticalMeasureCollectionSection
.class, getEntity().getClass().getCanonicalName(), true));
203 sectionStatisticalMeasures
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
204 sectionStatisticalMeasures
.setEntity(getEntity().getTerm());
207 sectionModifierVocabularies
= formFactory
.createRecommendedModifierVocabulariesCollectionSection(
208 getConversationHolder(), parentFormElement
, StoreUtil
.getSectionStyle(RecommendedModifierVocabulariesCollectionSection
.class, getEntity().getClass().getCanonicalName(), true));
209 sectionModifierVocabularies
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
210 sectionModifierVocabularies
.setEntity(getEntity().getTerm());
213 private void removeQuantitativeWidgets(){
214 if(sectionMeasurementUnits
!=null){
215 removeElementsAndControls(sectionMeasurementUnits
);
216 removeElementsAndControls(sectionStatisticalMeasures
);
217 removeElementsAndControls(sectionModifierVocabularies
);
221 private void activateCategoricalWidgets(){
222 //disable quantitative widgeets
223 supportsQuantitativeData
.setSelection(false);
224 getEntity().getTerm().setSupportsQuantitativeData(false);
225 removeQuantitativeWidgets();
228 sectionStateVocabularies
= formFactory
.createStateVocabulariesSection(getConversationHolder(),
229 parentFormElement
, StoreUtil
.getSectionStyle(StateVocabularyCollectionSection
.class, getEntity().getClass().getCanonicalName(), true));
230 sectionStateVocabularies
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
231 sectionStateVocabularies
.setEntity(getEntity().getTerm());
234 sectionModifierVocabularies
= formFactory
.createRecommendedModifierVocabulariesCollectionSection(
235 getConversationHolder(), parentFormElement
, StoreUtil
.getSectionStyle(RecommendedModifierVocabulariesCollectionSection
.class, getEntity().getClass().getCanonicalName(), true));
236 sectionModifierVocabularies
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
237 sectionModifierVocabularies
.setEntity(getEntity().getTerm());
240 private void removeCategoricalWidgets(){
241 if(sectionStateVocabularies
!=null){
242 removeElementsAndControls(sectionStateVocabularies
);
243 removeElementsAndControls(sectionModifierVocabularies
);