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
.vocabulary
;
11 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
13 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
14 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
15 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
16 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
17 import eu
.etaxonomy
.taxeditor
.ui
.element
.FloatWithLabelElement
;
18 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
19 import eu
.etaxonomy
.taxeditor
.ui
.element
.LabelElement
;
20 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
26 public class FeatureDetailElement
extends DefinedTermDetailElement
<Feature
> {
28 private ICdmFormElement parentFormElement
;
30 private CheckboxElement supportsTextData
;
32 private CheckboxElement supportsQuantitativeData
;
34 private CheckboxElement supportsDistribution
;
36 private CheckboxElement supportsIndividualAssociation
;
38 private CheckboxElement supportsTaxonInteraction
;
40 private CheckboxElement supportsCategoricalData
;
42 private CheckboxElement supportsCommonTaxonName
;
44 private CheckboxElement supportsTemporalData
;
46 private RecommendedStateCollectionSection sectionStateVocabularies
;
48 private MeasurementUnitCollectionSection sectionMeasurementUnits
;
50 private StatisticalMeasureCollectionSection sectionStatisticalMeasures
;
52 private RecommendedModifierCollectionsCollectionSection sectionModifierVocabularies
;
53 private CheckboxElement availableForTaxon
;
54 private CheckboxElement availableForTaxonName
;
55 private CheckboxElement availableForSpecimenOrObservation
;
57 private FloatWithLabelElement maxPerDataset
;
58 private FloatWithLabelElement maxStates
;
60 public FeatureDetailElement(CdmFormFactory formFactory
,
61 ICdmFormElement formElement
) {
62 super(formFactory
, formElement
);
66 protected void createControls(ICdmFormElement formElement
, Feature entity
, int style
) {
67 super.createControls(formElement
, entity
, style
);
68 this.parentFormElement
= formElement
;
71 LabelElement supportsLabel
= formFactory
.createLabel(formElement
, "Supports");
72 supportsLabel
.setBold();
73 supportsTextData
= formFactory
.createCheckbox(formElement
, "Text Data", entity
.isSupportsTextData(), style
);
74 supportsCategoricalData
= formFactory
.createCheckbox(formElement
, "Categorical Data", entity
.isSupportsCategoricalData(), style
);
75 supportsQuantitativeData
= formFactory
.createCheckbox(formElement
, "Quantitative Data", entity
.isSupportsQuantitativeData(), style
);
76 supportsDistribution
= formFactory
.createCheckbox(formElement
, "Distribution", entity
.isSupportsDistribution(), style
);
77 supportsIndividualAssociation
= formFactory
.createCheckbox(formElement
, "Individual Association", entity
.isSupportsIndividualAssociation(), style
);
78 supportsTaxonInteraction
= formFactory
.createCheckbox(formElement
, "Taxon Interaction", entity
.isSupportsTaxonInteraction(), style
);
79 supportsCommonTaxonName
= formFactory
.createCheckbox(formElement
, "Common Taxon Name", entity
.isSupportsCommonTaxonName(), style
);
80 supportsTemporalData
= formFactory
.createCheckbox(formElement
, "Temporal Data", entity
.isSupportsTemporalData(), style
);
83 if (supportsCategoricalData
.getSelection()) {
84 maxStates
= formFactory
.createFloatTextWithLabelElement(formElement
, "Max n states", entity
.getMaxStates(), style
);
85 sectionStateVocabularies
= formFactory
.createStateVocabulariesSection(
86 parentFormElement
, StoreUtil
.getSectionStyle(RecommendedStateCollectionSection
.class, getEntity().getClass().getCanonicalName()));
87 sectionStateVocabularies
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
88 sectionStateVocabularies
.setEntity(getEntity());
92 if (supportsQuantitativeData
.getSelection()) {
93 sectionMeasurementUnits
= formFactory
.createMeasurementUnitCollectionSection(
94 parentFormElement
, StoreUtil
.getSectionStyle(MeasurementUnitCollectionSection
.class, getEntity().getClass().getCanonicalName()));
95 sectionMeasurementUnits
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
96 sectionMeasurementUnits
.setEntity(getEntity());
98 sectionStatisticalMeasures
= formFactory
.createStatisticalMeasureCollectionSection(
99 parentFormElement
, StoreUtil
.getSectionStyle(StatisticalMeasureCollectionSection
.class, getEntity().getClass().getCanonicalName()));
100 sectionStatisticalMeasures
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
101 sectionStatisticalMeasures
.setEntity(getEntity());
105 if (supportsCategoricalData
.getSelection() || supportsQuantitativeData
.getSelection()) {
106 sectionModifierVocabularies
= formFactory
.createRecommendedModifierVocabulariesCollectionSection(
107 parentFormElement
, StoreUtil
.getSectionStyle(RecommendedModifierCollectionsCollectionSection
.class, getEntity().getClass().getCanonicalName()));
108 sectionModifierVocabularies
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
109 sectionModifierVocabularies
.setEntity(getEntity());
112 LabelElement noLabel
= formFactory
.createLabel(formElement
, "");
114 TableWrapData data
= LayoutConstants
.FILL_HORIZONTALLY(2, 1);
116 noLabel
.setLayout(data
);
118 LabelElement availableLabel
= formFactory
.createLabel(formElement
, "Available for");
119 availableLabel
.setBold();
121 availableForTaxon
= formFactory
.createCheckbox(formElement
, "Taxon", entity
.isAvailableForTaxon(), style
);
122 availableForTaxonName
= formFactory
.createCheckbox(formElement
, "Taxon Name", entity
.isAvailableForTaxonName(), style
);
123 availableForSpecimenOrObservation
= formFactory
.createCheckbox(formElement
, "Occurrence", entity
.isAvailableForOccurrence(), style
);
124 LabelElement noLabel2
= formFactory
.createLabel(formElement
, "");
125 data
= LayoutConstants
.FILL_HORIZONTALLY(2, 1);
127 noLabel2
.setLayout(data
);
128 maxPerDataset
= formFactory
.createFloatTextWithLabelElement(formElement
, "Max n per dataset", entity
.getMaxPerDataset(), style
);
129 //maxPerDataset.setTextLimit(1);
133 public void handleEvent(Object eventSource
) {
134 super.handleEvent(eventSource
);
135 if(eventSource
== supportsTextData
){
136 getEntity().setSupportsTextData(supportsTextData
.getSelection());
138 if(eventSource
== supportsQuantitativeData
){
139 getEntity().setSupportsQuantitativeData(supportsQuantitativeData
.getSelection());
140 if(supportsQuantitativeData
.getSelection()){
141 activateQuantitativeWidgets();
144 removeQuantitativeWidgets();
146 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
148 else if(eventSource
== supportsCategoricalData
){
149 getEntity().setSupportsCategoricalData(supportsCategoricalData
.getSelection());
150 if (supportsCategoricalData
.getSelection()) {
151 activateCategoricalWidgets();
154 removeCategoricalWidgets();
156 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
158 else if(eventSource
== supportsDistribution
){
159 getEntity().setSupportsDistribution(supportsDistribution
.getSelection());
161 else if(eventSource
== supportsIndividualAssociation
){
162 getEntity().setSupportsIndividualAssociation(supportsIndividualAssociation
.getSelection());
164 else if(eventSource
== supportsTaxonInteraction
){
165 getEntity().setSupportsTaxonInteraction(supportsTaxonInteraction
.getSelection());
167 else if(eventSource
== supportsCommonTaxonName
){
168 getEntity().setSupportsCommonTaxonName(supportsCommonTaxonName
.getSelection());
170 else if(eventSource
== supportsTemporalData
){
171 getEntity().setSupportsTemporalData(supportsTemporalData
.getSelection());
173 else if(eventSource
== availableForSpecimenOrObservation
){
174 getEntity().setAvailableForOccurrence(availableForSpecimenOrObservation
.getSelection());
176 else if(eventSource
== availableForTaxon
){
177 getEntity().setAvailableForTaxon(availableForTaxon
.getSelection());
179 else if(eventSource
== availableForTaxonName
){
180 getEntity().setAvailableForTaxonName(availableForTaxonName
.getSelection());
182 else if(eventSource
== maxPerDataset
){
183 getEntity().setMaxPerDataset(maxPerDataset
.getInteger());
185 else if(eventSource
== maxStates
){
186 getEntity().setMaxStates(maxStates
.getInteger());
188 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
191 private void activateQuantitativeWidgets(){
192 //disable categorical widgets
193 supportsCategoricalData
.setSelection(false);
194 getEntity().setSupportsCategoricalData(false);
195 removeCategoricalWidgets();
198 sectionMeasurementUnits
= formFactory
.createMeasurementUnitCollectionSection(parentFormElement
,
199 StoreUtil
.getSectionStyle(MeasurementUnitCollectionSection
.class, getEntity().getClass().getCanonicalName()));
200 sectionMeasurementUnits
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
201 sectionMeasurementUnits
.setEntity(getEntity());
203 //statistical measures
204 sectionStatisticalMeasures
= formFactory
.createStatisticalMeasureCollectionSection(
205 parentFormElement
,StoreUtil
.getSectionStyle(StatisticalMeasureCollectionSection
.class, getEntity().getClass().getCanonicalName()));
206 sectionStatisticalMeasures
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
207 sectionStatisticalMeasures
.setEntity(getEntity());
210 sectionModifierVocabularies
= formFactory
.createRecommendedModifierVocabulariesCollectionSection(
211 parentFormElement
, StoreUtil
.getSectionStyle(RecommendedModifierCollectionsCollectionSection
.class, getEntity().getClass().getCanonicalName()));
212 sectionModifierVocabularies
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
213 sectionModifierVocabularies
.setEntity(getEntity());
216 private void removeQuantitativeWidgets(){
217 if(sectionMeasurementUnits
!=null){
218 removeElementsAndControls(sectionMeasurementUnits
);
219 removeElementsAndControls(sectionStatisticalMeasures
);
220 removeElementsAndControls(sectionModifierVocabularies
);
224 private void activateCategoricalWidgets(){
225 //disable quantitative widgeets
226 supportsQuantitativeData
.setSelection(false);
227 getEntity().setSupportsQuantitativeData(false);
228 removeQuantitativeWidgets();
230 maxStates
= formFactory
.createFloatTextWithLabelElement(parentFormElement
, "Max n states", getEntity().getMaxStates(), StoreUtil
.getSectionStyle(RecommendedStateCollectionSection
.class, getEntity().getClass().getCanonicalName()));
232 sectionStateVocabularies
= formFactory
.createStateVocabulariesSection(
233 parentFormElement
, StoreUtil
.getSectionStyle(RecommendedStateCollectionSection
.class, getEntity().getClass().getCanonicalName()), getEntity().getMaxStates());
234 sectionStateVocabularies
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
235 sectionStateVocabularies
.setEntity(getEntity());
239 sectionModifierVocabularies
= formFactory
.createRecommendedModifierVocabulariesCollectionSection(
240 parentFormElement
, StoreUtil
.getSectionStyle(RecommendedModifierCollectionsCollectionSection
.class, getEntity().getClass().getCanonicalName()));
241 sectionModifierVocabularies
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
242 sectionModifierVocabularies
.setEntity(getEntity());
245 private void removeCategoricalWidgets(){
246 if(sectionStateVocabularies
!=null){
247 removeElementsAndControls(maxStates
);
248 removeElementsAndControls(sectionStateVocabularies
);
249 removeElementsAndControls(sectionModifierVocabularies
);