Project

General

Profile

Download (8.18 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.feature;
10

    
11
import org.eclipse.swt.widgets.Label;
12
import org.eclipse.ui.forms.widgets.ExpandableComposite;
13

    
14
import eu.etaxonomy.cdm.model.description.Character;
15
import eu.etaxonomy.taxeditor.model.ColorResources;
16
import eu.etaxonomy.taxeditor.preference.Resources;
17
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
18
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
19
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
20
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
21
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
22
import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
23
import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesCollectionSection;
24
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionSection;
25
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StatisticalMeasureCollectionSection;
26

    
27
/**
28
 *
29
 * @author pplitzner
30
 * @since Dec 21, 2017
31
 *
32
 */
33
public class CharacterDetailElement extends AbstractCdmDetailElement<Character> {
34

    
35
    private ICdmFormElement parentFormElement;
36

    
37
    private CheckboxElement supportsQuantitativeData;
38

    
39
    private CheckboxElement supportsCategoricalData;
40

    
41
    private StateVocabularyCollectionSection sectionStateVocabularies;
42

    
43
    private MeasurementUnitCollectionSection sectionMeasurementUnits;
44

    
45
    private StatisticalMeasureCollectionSection sectionStatisticalMeasures;
46

    
47
    private RecommendedModifierVocabulariesCollectionSection sectionModifierVocabularies;
48

    
49
	public CharacterDetailElement(CdmFormFactory formFactory,
50
			ICdmFormElement formElement) {
51
		super(formFactory, formElement);
52
	}
53

    
54
	@Override
55
	protected void createControls(ICdmFormElement formElement, Character entity, int style) {
56
	    this.parentFormElement = formElement;
57
	    Label lblStructure = new Label(formElement.getLayoutComposite(), style);
58
	    lblStructure.setText("Structure");
59
	    Label lblStructureText = new Label(formElement.getLayoutComposite(), style);
60
	    lblStructureText.setText(entity.getStructure().getFeature().getLabel());
61
	    lblStructureText.setForeground(ColorResources.getColor(Resources.BLACK));
62
	    Label lblProperty = new Label(formElement.getLayoutComposite(), style);
63
	    lblProperty.setText("Property");
64
	    Label lblPropertyText = new Label(formElement.getLayoutComposite(), style);
65
	    lblPropertyText.setForeground(ColorResources.getColor(Resources.BLACK));
66
	    lblPropertyText.setText(entity.getProperty().getFeature().getLabel());
67
	    supportsQuantitativeData = formFactory.createCheckbox(formElement, "Supports Quantitative Data", entity.isSupportsQuantitativeData(), style);
68
	    supportsCategoricalData = formFactory.createCheckbox(formElement, "Supports Categorical Data", entity.isSupportsCategoricalData(), style);
69

    
70
        if (supportsCategoricalData.getSelection()) {
71
            sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
72
                    parentFormElement, ExpandableComposite.TWISTIE);
73
            sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
74
            sectionStateVocabularies.setEntity(getEntity());
75

    
76
        }
77
        if (supportsQuantitativeData.getSelection()) {
78
            sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
79
                    parentFormElement, ExpandableComposite.TWISTIE);
80
            sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
81
            sectionMeasurementUnits.setEntity(getEntity());
82

    
83
            sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(getConversationHolder(),
84
                    parentFormElement, ExpandableComposite.TWISTIE);
85
            sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
86
            sectionStatisticalMeasures.setEntity(getEntity());
87
        }
88
        if (supportsCategoricalData.getSelection() || supportsQuantitativeData.getSelection()) {
89
            sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
90
                    getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE
91
                           );
92
            sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
93
            sectionModifierVocabularies.setEntity(getEntity());
94
        }
95
    }
96

    
97
	@Override
98
	public void handleEvent(Object eventSource) {
99
	    if(eventSource == supportsQuantitativeData || eventSource == supportsCategoricalData){
100
	        //if any type is selected disable supportsTextData
101
	        getEntity().setSupportsTextData(false);
102
	    }
103
	    if(eventSource == supportsQuantitativeData){
104
	        getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
105
	        if(supportsQuantitativeData.getSelection()){
106
	            activateQuantitativeWidgets();
107
	        }
108
	        else{
109
	            removeQuantitativeWidgets();
110
	        }
111
	    }
112
	    else if(eventSource == supportsCategoricalData){
113
	        getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
114
            if (supportsCategoricalData.getSelection()) {
115
                activateCategoricalWidgets();
116
            }
117
	        else{
118
	            removeCategoricalWidgets();
119
	        }
120
	    }
121
	}
122

    
123
	private void activateQuantitativeWidgets(){
124
	    //disable categorical widgets
125
	    supportsCategoricalData.setSelection(false);
126
	    getEntity().setSupportsCategoricalData(false);
127
	    removeCategoricalWidgets();
128

    
129
	    //measurement units
130
	    sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
131
	            parentFormElement, ExpandableComposite.TWISTIE);
132
	    sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
133
	    sectionMeasurementUnits.setEntity(getEntity());
134

    
135
	    //statistical measures
136
	    sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(
137
	            getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
138
	    sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
139
	    sectionStatisticalMeasures.setEntity(getEntity());
140

    
141
	    //modifiers
142
	    sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
143
	            getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
144
	    sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
145
	    sectionModifierVocabularies.setEntity(getEntity());
146
	}
147

    
148
	private void removeQuantitativeWidgets(){
149
	    if(sectionMeasurementUnits!=null){
150
	        removeElementsAndControls(sectionMeasurementUnits);
151
	        removeElementsAndControls(sectionStatisticalMeasures);
152
	        removeElementsAndControls(sectionModifierVocabularies);
153
	    }
154
	}
155

    
156
	private void activateCategoricalWidgets(){
157
	    //disable quantitative widgeets
158
	    supportsQuantitativeData.setSelection(false);
159
	    getEntity().setSupportsQuantitativeData(false);
160
	    removeQuantitativeWidgets();
161

    
162
	    //states
163
	    sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
164
                parentFormElement, ExpandableComposite.TWISTIE);
165
        sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
166
        sectionStateVocabularies.setEntity(getEntity());
167

    
168
        //modifiers
169
        sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
170
                getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
171
        sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
172
        sectionModifierVocabularies.setEntity(getEntity());
173
	}
174

    
175
	private void removeCategoricalWidgets(){
176
	    if(sectionStateVocabularies!=null){
177
	        removeElementsAndControls(sectionStateVocabularies);
178
	        removeElementsAndControls(sectionModifierVocabularies);
179
	    }
180
	}
181

    
182
}
(1-1/12)