Merge branch 'hotfix/5.44.1'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / vocabulary / FeatureDetailElement.java
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.vocabulary;
10
11 import org.eclipse.ui.forms.widgets.TableWrapData;
12
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;
21
22 /**
23 * @author l.morris
24 * @date 20 Dec 2011
25 */
26 public class FeatureDetailElement extends DefinedTermDetailElement<Feature> {
27
28 private ICdmFormElement parentFormElement;
29
30 private CheckboxElement supportsTextData;
31
32 private CheckboxElement supportsQuantitativeData;
33
34 private CheckboxElement supportsDistribution;
35
36 private CheckboxElement supportsIndividualAssociation;
37
38 private CheckboxElement supportsTaxonInteraction;
39
40 private CheckboxElement supportsCategoricalData;
41
42 private CheckboxElement supportsCommonTaxonName;
43
44 private CheckboxElement supportsTemporalData;
45
46 private RecommendedStateCollectionSection sectionStateVocabularies;
47
48 private MeasurementUnitCollectionSection sectionMeasurementUnits;
49
50 private StatisticalMeasureCollectionSection sectionStatisticalMeasures;
51
52 private RecommendedModifierCollectionsCollectionSection sectionModifierVocabularies;
53 private CheckboxElement availableForTaxon;
54 private CheckboxElement availableForTaxonName;
55 private CheckboxElement availableForSpecimenOrObservation;
56
57 private FloatWithLabelElement maxPerDataset;
58 private FloatWithLabelElement maxStates;
59
60 public FeatureDetailElement(CdmFormFactory formFactory,
61 ICdmFormElement formElement) {
62 super(formFactory, formElement);
63 }
64
65 @Override
66 protected void createControls(ICdmFormElement formElement, Feature entity, int style) {
67 super.createControls(formElement, entity, style);
68 this.parentFormElement = formElement;
69 //Layout
70
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);
81
82 //categorical data
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());
89 }
90
91 //quantitative data
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());
97
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());
102 }
103
104 //both
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());
110 }
111
112 LabelElement noLabel = formFactory.createLabel(formElement, "");
113
114 TableWrapData data = LayoutConstants.FILL_HORIZONTALLY(2, 1);
115 data.maxHeight = 3;
116 noLabel.setLayout(data);
117
118 LabelElement availableLabel = formFactory.createLabel(formElement, "Available for");
119 availableLabel.setBold();
120
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);
126 data.maxHeight = 3;
127 noLabel2.setLayout(data);
128 maxPerDataset = formFactory.createFloatTextWithLabelElement(formElement, "Max n per dataset", entity.getMaxPerDataset(), style);
129 //maxPerDataset.setTextLimit(1);
130 }
131
132 @Override
133 public void handleEvent(Object eventSource) {
134 super.handleEvent(eventSource);
135 if(eventSource == supportsTextData){
136 getEntity().setSupportsTextData(supportsTextData.getSelection());
137 }
138 if(eventSource == supportsQuantitativeData){
139 getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
140 if(supportsQuantitativeData.getSelection()){
141 activateQuantitativeWidgets();
142 }
143 else{
144 removeQuantitativeWidgets();
145 }
146 StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
147 }
148 else if(eventSource == supportsCategoricalData){
149 getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
150 if (supportsCategoricalData.getSelection()) {
151 activateCategoricalWidgets();
152 }
153 else{
154 removeCategoricalWidgets();
155 }
156 StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
157 }
158 else if(eventSource == supportsDistribution){
159 getEntity().setSupportsDistribution(supportsDistribution.getSelection());
160 }
161 else if(eventSource == supportsIndividualAssociation){
162 getEntity().setSupportsIndividualAssociation(supportsIndividualAssociation.getSelection());
163 }
164 else if(eventSource == supportsTaxonInteraction){
165 getEntity().setSupportsTaxonInteraction(supportsTaxonInteraction.getSelection());
166 }
167 else if(eventSource == supportsCommonTaxonName){
168 getEntity().setSupportsCommonTaxonName(supportsCommonTaxonName.getSelection());
169 }
170 else if(eventSource == supportsTemporalData){
171 getEntity().setSupportsTemporalData(supportsTemporalData.getSelection());
172 }
173 else if(eventSource == availableForSpecimenOrObservation){
174 getEntity().setAvailableForOccurrence(availableForSpecimenOrObservation.getSelection());
175 }
176 else if(eventSource == availableForTaxon){
177 getEntity().setAvailableForTaxon(availableForTaxon.getSelection());
178 }
179 else if(eventSource == availableForTaxonName){
180 getEntity().setAvailableForTaxonName(availableForTaxonName.getSelection());
181 }
182 else if(eventSource == maxPerDataset){
183 getEntity().setMaxPerDataset(maxPerDataset.getInteger());
184 }
185 else if(eventSource == maxStates){
186 getEntity().setMaxStates(maxStates.getInteger());
187 }
188 StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
189 }
190
191 private void activateQuantitativeWidgets(){
192 //disable categorical widgets
193 supportsCategoricalData.setSelection(false);
194 getEntity().setSupportsCategoricalData(false);
195 removeCategoricalWidgets();
196
197 //measurement units
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());
202
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());
208
209 //modifiers
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());
214 }
215
216 private void removeQuantitativeWidgets(){
217 if(sectionMeasurementUnits!=null){
218 removeElementsAndControls(sectionMeasurementUnits);
219 removeElementsAndControls(sectionStatisticalMeasures);
220 removeElementsAndControls(sectionModifierVocabularies);
221 }
222 }
223
224 private void activateCategoricalWidgets(){
225 //disable quantitative widgeets
226 supportsQuantitativeData.setSelection(false);
227 getEntity().setSupportsQuantitativeData(false);
228 removeQuantitativeWidgets();
229
230 maxStates = formFactory.createFloatTextWithLabelElement(parentFormElement, "Max n states", getEntity().getMaxStates(), StoreUtil.getSectionStyle(RecommendedStateCollectionSection.class, getEntity().getClass().getCanonicalName()));
231 //states
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());
236
237
238 //modifiers
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());
243 }
244
245 private void removeCategoricalWidgets(){
246 if(sectionStateVocabularies!=null){
247 removeElementsAndControls(maxStates);
248 removeElementsAndControls(sectionStateVocabularies);
249 removeElementsAndControls(sectionModifierVocabularies);
250 }
251 }
252 }