Project

General

Profile

Download (9.5 KB) Statistics
| Branch: | Tag: | Revision:
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.ExpandableComposite;
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.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
    private StatisticalMeasureCollectionSection sectionStatisticalMeasures;
48

    
49
    private RecommendedModifierVocabulariesCollectionSection sectionModifierVocabularies;
50

    
51
    /**
52
	 * @param formFactory
53
	 * @param formElement
54
	 */
55
	public FeatureDetailElement(CdmFormFactory formFactory,
56
			ICdmFormElement formElement) {
57
		super(formFactory, formElement);
58
	}
59

    
60
	/* (non-Javadoc)
61
	 * @see eu.etaxonomy.taxeditor.ui.section.vocabulary.AbstractTermBaseDetailElement#createControls(eu.etaxonomy.taxeditor.ui.element.ICdmFormElement, eu.etaxonomy.cdm.model.term.TermBase, int)
62
	 */
63
	@Override
64
	protected void createControls(ICdmFormElement formElement, Feature entity, int style) {
65
	    super.createControls(formElement, entity, style);
66
	    this.parentFormElement = formElement;
67
	    supportsTextData = formFactory.createCheckbox(formElement, "Supports Text Data", entity.isSupportsTextData(), style);
68
	    supportsQuantitativeData = formFactory.createCheckbox(formElement, "Supports Quantitative Data", entity.isSupportsQuantitativeData(), style);
69
	    supportsDistribution = formFactory.createCheckbox(formElement, "Supports Distribution", entity.isSupportsDistribution(), style);
70
	    supportsIndividualAssociation = formFactory.createCheckbox(formElement, "Supports Individual Association", entity.isSupportsIndividualAssociation(), style);
71
	    supportsTaxonInteraction = formFactory.createCheckbox(formElement, "Supports Taxon Interaction", entity.isSupportsTaxonInteraction(), style);
72
	    supportsCategoricalData = formFactory.createCheckbox(formElement, "Supports Categorical Data", entity.isSupportsCategoricalData(), style);
73
	    supportsCommonTaxonName = formFactory.createCheckbox(formElement, "Supports Common Taxon Name", entity.isSupportsCommonTaxonName(), style);
74

    
75
        if (supportsCategoricalData.getSelection()) {
76
            sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
77
                    parentFormElement, ExpandableComposite.TWISTIE);
78
            sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
79
            sectionStateVocabularies.setEntity(getEntity());
80

    
81
        }
82
        if (supportsQuantitativeData.getSelection()) {
83
            sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
84
                    parentFormElement, ExpandableComposite.TWISTIE);
85
            sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
86
            sectionMeasurementUnits.setEntity(getEntity());
87

    
88
            sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(getConversationHolder(),
89
                    parentFormElement, ExpandableComposite.TWISTIE);
90
            sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
91
            sectionStatisticalMeasures.setEntity(getEntity());
92
        }
93
        if (supportsCategoricalData.getSelection() || supportsQuantitativeData.getSelection()) {
94
            sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
95
                    getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE
96
                           );
97
            sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
98
            sectionModifierVocabularies.setEntity(getEntity());
99
        }
100
    }
101

    
102
	/* (non-Javadoc)
103
	 * @see eu.etaxonomy.taxeditor.ui.section.vocabulary.DefinedTermDetailElement#handleEvent(java.lang.Object)
104
	 */
105
	@Override
106
	public void handleEvent(Object eventSource) {
107
	    super.handleEvent(eventSource);
108
	    if(eventSource == supportsTextData){
109
	        getEntity().setSupportsTextData(supportsTextData.getSelection());
110
	    }
111
	    if(eventSource == supportsQuantitativeData){
112
            getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
113
            if(supportsQuantitativeData.getSelection()){
114
                activateQuantitativeWidgets();
115
            }
116
            else{
117
                removeQuantitativeWidgets();
118
            }
119
            StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
120
        }
121
        else if(eventSource == supportsCategoricalData){
122
            getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
123
            if (supportsCategoricalData.getSelection()) {
124
                activateCategoricalWidgets();
125
            }
126
            else{
127
                removeCategoricalWidgets();
128
            }
129
            StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
130
        }
131
	    else if(eventSource == supportsDistribution){
132
	        getEntity().setSupportsDistribution(supportsDistribution.getSelection());
133
	    }
134
	    else if(eventSource == supportsIndividualAssociation){
135
	        getEntity().setSupportsIndividualAssociation(supportsIndividualAssociation.getSelection());
136
	    }
137
	    else if(eventSource == supportsTaxonInteraction){
138
	        getEntity().setSupportsTaxonInteraction(supportsTaxonInteraction.getSelection());
139
	    }
140
	    else if(eventSource == supportsCommonTaxonName){
141
	        getEntity().setSupportsCommonTaxonName(supportsCommonTaxonName.getSelection());
142
	    }
143
        StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
144
	}
145

    
146
	private void activateQuantitativeWidgets(){
147
        //disable categorical widgets
148
        supportsCategoricalData.setSelection(false);
149
        getEntity().setSupportsCategoricalData(false);
150
        removeCategoricalWidgets();
151

    
152
        //measurement units
153
        sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
154
                parentFormElement, ExpandableComposite.TWISTIE);
155
        sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
156
        sectionMeasurementUnits.setEntity(getEntity());
157

    
158
        //statistical measures
159
        sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(
160
                getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
161
        sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
162
        sectionStatisticalMeasures.setEntity(getEntity());
163

    
164
        //modifiers
165
        sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
166
                getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
167
        sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
168
        sectionModifierVocabularies.setEntity(getEntity());
169
    }
170

    
171
    private void removeQuantitativeWidgets(){
172
        if(sectionMeasurementUnits!=null){
173
            removeElementsAndControls(sectionMeasurementUnits);
174
            removeElementsAndControls(sectionStatisticalMeasures);
175
            removeElementsAndControls(sectionModifierVocabularies);
176
        }
177
    }
178

    
179
    private void activateCategoricalWidgets(){
180
        //disable quantitative widgeets
181
        supportsQuantitativeData.setSelection(false);
182
        getEntity().setSupportsQuantitativeData(false);
183
        removeQuantitativeWidgets();
184

    
185
        //states
186
        sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
187
                parentFormElement, ExpandableComposite.TWISTIE);
188
        sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
189
        sectionStateVocabularies.setEntity(getEntity());
190

    
191
        //modifiers
192
        sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
193
                getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
194
        sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
195
        sectionModifierVocabularies.setEntity(getEntity());
196
    }
197

    
198
    private void removeCategoricalWidgets(){
199
        if(sectionStateVocabularies!=null){
200
            removeElementsAndControls(sectionStateVocabularies);
201
            removeElementsAndControls(sectionModifierVocabularies);
202
        }
203
    }
204

    
205
}
(4-4/19)