Project

General

Profile

Download (8.07 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
	    removeCategoricalWidgets();
127

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

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

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

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

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

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

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

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

    
180
}
(1-1/12)