Project

General

Profile

Download (11.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

    
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.TermNode;
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,  entity.getPreferredRepresentation(CdmStore.getDefaultLanguage()),entity, 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(getPath(entity.getStructure()));
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(getPath(entity.getProperty()));
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, StoreUtil.getSectionStyle(StateVocabularyCollectionSection.class, entity.getClass().getCanonicalName(), true));
90
            sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
91
            sectionStateVocabularies.setEntity(entity);
92
        }
93
        if (supportsQuantitativeData.getSelection()) {
94
            sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
95
                    parentFormElement, StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, entity.getClass().getCanonicalName(), true));
96
            sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
97
            sectionMeasurementUnits.setEntity(entity);
98

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

    
111
    }
112

    
113
	private String getPath(TermNode node){
114
	    String path = node.getTerm().getLabel();
115
	    TermNode parent = node.getParent();
116
	    while(parent != null && parent.getTerm()!=null){
117
	        path = parent.getTerm().getLabel() + "/" + path;
118
	        parent = parent.getParent();
119
	    }
120
	    return path;
121
	}
122

    
123
    @Override
124
    public void setEntity(Character entity) {
125
        super.setEntity(entity);
126
        setEnabled(TermBasePropertyTester.isModifiable(entity));
127
    }
128

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

    
173
	private void activateQuantitativeWidgets(){
174
	    //disable categorical widgets
175
	    supportsCategoricalData.setSelection(false);
176
	    getEntity().setSupportsCategoricalData(false);
177
	    removeCategoricalWidgets();
178

    
179
	    //measurement units
180
	    sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
181
	            parentFormElement, StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
182
	    sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
183
	    sectionMeasurementUnits.setEntity(getEntity());
184

    
185
	    //statistical measures
186
	    sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(
187
	            getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
188
	    sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
189
	    sectionStatisticalMeasures.setEntity(getEntity());
190

    
191
	    //modifiers
192
	    sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
193
	            getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
194
	    sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
195
	    sectionModifierVocabularies.setEntity(getEntity());
196
	}
197

    
198
	private void removeQuantitativeWidgets(){
199
	    if(sectionMeasurementUnits!=null){
200
	        removeElementsAndControls(sectionMeasurementUnits);
201
	        removeElementsAndControls(sectionStatisticalMeasures);
202
	        removeElementsAndControls(sectionModifierVocabularies);
203
	    }
204
	}
205

    
206
	private void activateCategoricalWidgets(){
207
	    //disable quantitative widgeets
208
	    supportsQuantitativeData.setSelection(false);
209
	    getEntity().setSupportsQuantitativeData(false);
210
	    removeQuantitativeWidgets();
211

    
212
	    //states
213
	    sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
214
                parentFormElement, StoreUtil.getSectionStyle(StateVocabularyCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
215
        sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
216
        sectionStateVocabularies.setEntity(getEntity());
217

    
218
        //modifiers
219
        sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
220
                getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
221
        sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
222
        sectionModifierVocabularies.setEntity(getEntity());
223
	}
224

    
225
	private void removeCategoricalWidgets(){
226
	    if(sectionStateVocabularies!=null){
227
	        removeElementsAndControls(sectionStateVocabularies);
228
	        removeElementsAndControls(sectionModifierVocabularies);
229
	    }
230
	}
231

    
232
}
(2-2/17)