- added measurement unit section to Feature DetailView (#4448)
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / vocabulary / FeatureDetailElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.ui.section.vocabulary;
11
12 import org.eclipse.ui.forms.widgets.ExpandableComposite;
13
14 import eu.etaxonomy.cdm.model.description.Feature;
15 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
16 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
17 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
18 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
19
20 /**
21 * @author l.morris
22 * @date 20 Dec 2011
23 *
24 */
25 public class FeatureDetailElement extends DefinedTermDetailElement<Feature> {
26
27 private ICdmFormElement parentFormElement;
28
29 private CheckboxElement supportsTextData;
30
31 private CheckboxElement supportsQuantitativeData;
32
33 private CheckboxElement supportsDistribution;
34
35 private CheckboxElement supportsIndividualAssociation;
36
37 private CheckboxElement supportsTaxonInteraction;
38
39 private CheckboxElement supportsCategoricalData;
40
41 private CheckboxElement supportsCommonTaxonName;
42
43 private StateVocabularyCollectionSection sectionStateVocabularies;
44
45 private MeasurementUnitCollectionSection sectionMeasurementUnits;
46
47 /**
48 * @param formFactory
49 * @param formElement
50 */
51 public FeatureDetailElement(CdmFormFactory formFactory,
52 ICdmFormElement formElement) {
53 super(formFactory, formElement);
54 }
55
56 /* (non-Javadoc)
57 * @see eu.etaxonomy.taxeditor.ui.section.vocabulary.AbstractTermBaseDetailElement#createControls(eu.etaxonomy.taxeditor.ui.element.ICdmFormElement, eu.etaxonomy.cdm.model.common.TermBase, int)
58 */
59 @Override
60 protected void createControls(ICdmFormElement formElement, Feature entity, int style) {
61 super.createControls(formElement, entity, style);
62 this.parentFormElement = formElement;
63 supportsTextData = formFactory.createCheckbox(formElement, "Supports Text Data", entity.isSupportsTextData(), style);
64 supportsQuantitativeData = formFactory.createCheckbox(formElement, "Supports Quantitive Data", entity.isSupportsQuantitativeData(), style);
65 supportsDistribution = formFactory.createCheckbox(formElement, "Supports Distribution", entity.isSupportsDistribution(), style);
66 supportsIndividualAssociation = formFactory.createCheckbox(formElement, "Supports Individual Association", entity.isSupportsIndividualAssociation(), style);
67 supportsTaxonInteraction = formFactory.createCheckbox(formElement, "Supports Taxon Interaction", entity.isSupportsTaxonInteraction(), style);
68 supportsCategoricalData = formFactory.createCheckbox(formElement, "Supports Categorical Data", entity.isSupportsCategoricalData(), style);
69 supportsCommonTaxonName = formFactory.createCheckbox(formElement, "Supports Common Taxon Name", entity.isSupportsCommonTaxonName(), style);
70
71 if(supportsCategoricalData.getSelection()){
72 sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
73 sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
74 sectionStateVocabularies.setEntity(getEntity());
75 }
76 if(supportsQuantitativeData.getSelection()){
77 sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
78 sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
79 sectionMeasurementUnits.setEntity(getEntity());
80 }
81 }
82
83 /* (non-Javadoc)
84 * @see eu.etaxonomy.taxeditor.ui.section.vocabulary.DefinedTermDetailElement#handleEvent(java.lang.Object)
85 */
86 @Override
87 public void handleEvent(Object eventSource) {
88 super.handleEvent(eventSource);
89 if(eventSource == supportsTextData){
90 getEntity().setSupportsTextData(supportsTextData.getSelection());
91 }
92 else if(eventSource == supportsQuantitativeData){
93 getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
94 if(supportsQuantitativeData.getSelection()){
95 sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
96 sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
97 sectionMeasurementUnits.setEntity(getEntity());
98 }
99 else{
100 if(sectionMeasurementUnits!=null){
101 removeElementsAndControls(sectionMeasurementUnits);
102 }
103 }
104 }
105 else if(eventSource == supportsDistribution){
106 getEntity().setSupportsDistribution(supportsDistribution.getSelection());
107 }
108 else if(eventSource == supportsIndividualAssociation){
109 getEntity().setSupportsIndividualAssociation(supportsIndividualAssociation.getSelection());
110 }
111 else if(eventSource == supportsTaxonInteraction){
112 getEntity().setSupportsTaxonInteraction(supportsTaxonInteraction.getSelection());
113 }
114 else if(eventSource == supportsCategoricalData){
115 getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
116 if(supportsCategoricalData.getSelection()){
117 sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
118 sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
119 sectionStateVocabularies.setEntity(getEntity());
120 }
121 else{
122 if(sectionStateVocabularies!=null){
123 removeElementsAndControls(sectionStateVocabularies);
124 }
125 }
126 }
127 else if(eventSource == supportsCommonTaxonName){
128 getEntity().setSupportsCommonTaxonName(supportsCommonTaxonName.getSelection());
129 }
130 }
131
132 }