Project

General

Profile

Download (10.4 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.common.Language;
15
import eu.etaxonomy.cdm.model.description.Character;
16
import eu.etaxonomy.cdm.model.term.DefinedTerm;
17
import eu.etaxonomy.cdm.model.term.Representation;
18
import eu.etaxonomy.cdm.model.term.TermType;
19
import eu.etaxonomy.taxeditor.editor.definedterm.TermBasePropertyTester;
20
import eu.etaxonomy.taxeditor.model.ColorResources;
21
import eu.etaxonomy.taxeditor.preference.Resources;
22
import eu.etaxonomy.taxeditor.store.CdmStore;
23
import eu.etaxonomy.taxeditor.store.StoreUtil;
24
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
25
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
27
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
28
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
29
import eu.etaxonomy.taxeditor.ui.element.RepresentationElement;
30
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
31
import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
32
import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesCollectionSection;
33
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionSection;
34
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StatisticalMeasureCollectionSection;
35

    
36
/**
37
 *
38
 * @author pplitzner
39
 * @since Dec 21, 2017
40
 *
41
 */
42
public class CharacterDetailElement extends AbstractCdmDetailElement<Character> {
43

    
44
    private ICdmFormElement parentFormElement;
45

    
46
    protected RepresentationElement element_Representation;
47

    
48
    private TermComboElement<DefinedTerm> comboStructuralModifier;
49

    
50
    private CheckboxElement supportsQuantitativeData;
51

    
52
    private CheckboxElement supportsCategoricalData;
53

    
54
    private StateVocabularyCollectionSection sectionStateVocabularies;
55

    
56
    private MeasurementUnitCollectionSection sectionMeasurementUnits;
57

    
58
    private StatisticalMeasureCollectionSection sectionStatisticalMeasures;
59

    
60
    private RecommendedModifierVocabulariesCollectionSection sectionModifierVocabularies;
61

    
62
	public CharacterDetailElement(CdmFormFactory formFactory,
63
			ICdmFormElement formElement) {
64
		super(formFactory, formElement);
65
	}
66

    
67
	@Override
68
	protected void createControls(ICdmFormElement formElement, Character entity, int style) {
69
	    this.parentFormElement = formElement;
70
	    element_Representation = formFactory.createTranslatableRepresentationElement(formElement,  getEntity().getPreferredRepresentation(CdmStore.getDefaultLanguage()),getEntity(), 100, style, true);
71
	    Label lblStructure = new Label(formElement.getLayoutComposite(), style);
72
	    lblStructure.setText("Structure");
73
	    Label lblStructureText = new Label(formElement.getLayoutComposite(), style);
74
	    lblStructureText.setText(entity.getStructure().getTerm().getLabel());
75
	    lblStructureText.setForeground(ColorResources.getColor(Resources.BLACK));
76
	    Label lblProperty = new Label(formElement.getLayoutComposite(), style);
77
	    lblProperty.setText("Property");
78
	    Label lblPropertyText = new Label(formElement.getLayoutComposite(), style);
79
	    lblPropertyText.setForeground(ColorResources.getColor(Resources.BLACK));
80
	    lblPropertyText.setText(entity.getProperty().getTerm().getLabel());
81

    
82
        comboStructuralModifier = formFactory.createDefinedTermComboElement(TermType.StructureModifier, formElement, "Structural Modifier", entity.getStructureModifier(), style);
83

    
84
	    supportsQuantitativeData = formFactory.createCheckbox(formElement, "Supports Quantitative Data", entity.isSupportsQuantitativeData(), style);
85
	    supportsCategoricalData = formFactory.createCheckbox(formElement, "Supports Categorical Data", entity.isSupportsCategoricalData(), style);
86

    
87
        if (supportsCategoricalData.getSelection()) {
88
            sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
89
                    parentFormElement, ExpandableComposite.TWISTIE);
90
            sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
91
            sectionStateVocabularies.setEntity(getEntity());
92

    
93
        }
94
        if (supportsQuantitativeData.getSelection()) {
95
            sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
96
                    parentFormElement, ExpandableComposite.TWISTIE);
97
            sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
98
            sectionMeasurementUnits.setEntity(getEntity());
99

    
100
            sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(getConversationHolder(),
101
                    parentFormElement, ExpandableComposite.TWISTIE);
102
            sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
103
            sectionStatisticalMeasures.setEntity(getEntity());
104
        }
105
        if (supportsCategoricalData.getSelection() || supportsQuantitativeData.getSelection()) {
106
            sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
107
                    getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE
108
                           );
109
            sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
110
            sectionModifierVocabularies.setEntity(getEntity());
111
        }
112
    }
113

    
114
    @Override
115
    public void setEntity(Character entity) {
116
        super.setEntity(entity);
117
        setEnabled(TermBasePropertyTester.isModifiable(entity));
118
    }
119

    
120
	@Override
121
	public void handleEvent(Object eventSource) {
122
	    if(eventSource == comboStructuralModifier){
123
	        getEntity().setStructureModifier(comboStructuralModifier.getSelection());
124
	    }
125
	    if(eventSource == supportsQuantitativeData || eventSource == supportsCategoricalData){
126
	        //if any type is selected disable supportsTextData
127
	        getEntity().setSupportsTextData(false);
128
	    }
129
	    if(eventSource == supportsQuantitativeData){
130
	        getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
131
	        if(supportsQuantitativeData.getSelection()){
132
	            activateQuantitativeWidgets();
133
	        }
134
	        else{
135
	            removeQuantitativeWidgets();
136
	        }
137
            StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
138
	    }
139
	    else if(eventSource == supportsCategoricalData){
140
	        getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
141
            if (supportsCategoricalData.getSelection()) {
142
                activateCategoricalWidgets();
143
            }
144
	        else{
145
	            removeCategoricalWidgets();
146
	        }
147
            StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
148
	    }
149
	    else if (eventSource == element_Representation) {
150
            Representation selectedRepresentation = element_Representation.getSelectedRepresentation();
151
            if(selectedRepresentation!=null){
152
                Language representationLanguage = selectedRepresentation.getLanguage();
153
                if(representationLanguage==null){
154
                    representationLanguage = Language.getDefaultLanguage();
155
                }
156
                getEntity().setLabel(selectedRepresentation.getLabel(),  representationLanguage);
157
                getEntity().getRepresentation(representationLanguage).setAbbreviatedLabel(selectedRepresentation.getAbbreviatedLabel());
158
                getEntity().getRepresentation(representationLanguage).setText(selectedRepresentation.getDescription());
159
            }
160
            getEntity().setTitleCache(null);
161
        }
162
	}
163

    
164
	private void activateQuantitativeWidgets(){
165
	    //disable categorical widgets
166
	    supportsCategoricalData.setSelection(false);
167
	    getEntity().setSupportsCategoricalData(false);
168
	    removeCategoricalWidgets();
169

    
170
	    //measurement units
171
	    sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
172
	            parentFormElement, ExpandableComposite.TWISTIE);
173
	    sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
174
	    sectionMeasurementUnits.setEntity(getEntity());
175

    
176
	    //statistical measures
177
	    sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(
178
	            getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
179
	    sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
180
	    sectionStatisticalMeasures.setEntity(getEntity());
181

    
182
	    //modifiers
183
	    sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
184
	            getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
185
	    sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
186
	    sectionModifierVocabularies.setEntity(getEntity());
187
	}
188

    
189
	private void removeQuantitativeWidgets(){
190
	    if(sectionMeasurementUnits!=null){
191
	        removeElementsAndControls(sectionMeasurementUnits);
192
	        removeElementsAndControls(sectionStatisticalMeasures);
193
	        removeElementsAndControls(sectionModifierVocabularies);
194
	    }
195
	}
196

    
197
	private void activateCategoricalWidgets(){
198
	    //disable quantitative widgeets
199
	    supportsQuantitativeData.setSelection(false);
200
	    getEntity().setSupportsQuantitativeData(false);
201
	    removeQuantitativeWidgets();
202

    
203
	    //states
204
	    sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
205
                parentFormElement, ExpandableComposite.TWISTIE);
206
        sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
207
        sectionStateVocabularies.setEntity(getEntity());
208

    
209
        //modifiers
210
        sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
211
                getConversationHolder(), parentFormElement, ExpandableComposite.TWISTIE);
212
        sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
213
        sectionModifierVocabularies.setEntity(getEntity());
214
	}
215

    
216
	private void removeCategoricalWidgets(){
217
	    if(sectionStateVocabularies!=null){
218
	        removeElementsAndControls(sectionStateVocabularies);
219
	        removeElementsAndControls(sectionModifierVocabularies);
220
	    }
221
	}
222

    
223
}
(1-1/12)