Project

General

Profile

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

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

    
45
    private ICdmFormElement parentFormElement;
46

    
47
    protected RepresentationElement element_Representation;
48

    
49
    private TermComboElement<DefinedTerm> comboStructuralModifier;
50

    
51
    private CheckboxElement supportsQuantitativeData;
52

    
53
    private CheckboxElement supportsCategoricalData;
54

    
55
    private StateVocabularyCollectionSection sectionStateVocabularies;
56

    
57
    private MeasurementUnitCollectionSection sectionMeasurementUnits;
58

    
59
    private StatisticalMeasureCollectionSection sectionStatisticalMeasures;
60

    
61
    private RecommendedModifierVocabulariesCollectionSection sectionModifierVocabularies;
62

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

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

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

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

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

    
100
            sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(getConversationHolder(),
101
                    parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, entity.getClass().getCanonicalName(), true));
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, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, entity.getClass().getCanonicalName(), true));
108
            sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
109
            sectionModifierVocabularies.setEntity(getEntity());
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
}
(1-1/12)