Project

General

Profile

Download (11.1 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

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

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

    
43
    private ICdmFormElement parentFormElement;
44

    
45
    protected RepresentationElement element_Representation;
46

    
47
    private TermComboElement<DefinedTerm> comboStructuralModifier;
48

    
49
    private CheckboxElement supportsQuantitativeData;
50

    
51
    private CheckboxElement supportsCategoricalData;
52

    
53
    private StateVocabularyCollectionSection sectionStateVocabularies;
54

    
55
    private MeasurementUnitCollectionSection sectionMeasurementUnits;
56

    
57
    private StatisticalMeasureCollectionSection sectionStatisticalMeasures;
58

    
59
    private RecommendedModifierVocabulariesCollectionSection sectionModifierVocabularies;
60

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

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

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

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

    
86
        if (supportsCategoricalData.getSelection()) {
87
            sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
88
                    parentFormElement, StoreUtil.getSectionStyle(StateVocabularyCollectionSection.class, entity.getClass().getCanonicalName(), true));
89
            sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
90
            sectionStateVocabularies.setEntity(entity);
91
        }
92
        if (supportsQuantitativeData.getSelection()) {
93
            sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
94
                    parentFormElement, StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, entity.getClass().getCanonicalName(), true));
95
            sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
96
            sectionMeasurementUnits.setEntity(entity);
97

    
98
            sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(getConversationHolder(),
99
                    parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, entity.getClass().getCanonicalName(), true));
100
            sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
101
            sectionStatisticalMeasures.setEntity(entity);
102
        }
103
        if (supportsCategoricalData.getSelection() || supportsQuantitativeData.getSelection()) {
104
            sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
105
                    getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, entity.getClass().getCanonicalName(), true));
106
            sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
107
            sectionModifierVocabularies.setEntity(entity);
108
        }
109

    
110
    }
111

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

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

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

    
168
	    //measurement units
169
	    sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
170
	            parentFormElement, StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
171
	    sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
172
	    sectionMeasurementUnits.setEntity(getEntity());
173

    
174
	    //statistical measures
175
	    sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(
176
	            getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
177
	    sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
178
	    sectionStatisticalMeasures.setEntity(getEntity());
179

    
180
	    //modifiers
181
	    sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
182
	            getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
183
	    sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
184
	    sectionModifierVocabularies.setEntity(getEntity());
185
	}
186

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

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

    
201
	    //states
202
	    sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
203
                parentFormElement, StoreUtil.getSectionStyle(StateVocabularyCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
204
        sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
205
        sectionStateVocabularies.setEntity(getEntity());
206

    
207
        //modifiers
208
        sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
209
                getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
210
        sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
211
        sectionModifierVocabularies.setEntity(getEntity());
212
	}
213

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

    
221
}
(2-2/17)