Project

General

Profile

Download (12.7 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.SWT;
12
import org.eclipse.swt.widgets.Label;
13
import org.eclipse.swt.widgets.Text;
14

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

    
38
/**
39
 *
40
 * @author pplitzner
41
 * @since Aug 19, 2019
42
 *
43
 */
44
public class CharacterNodeDetailElement extends AbstractCdmDetailElement<TermNode<Character>> {
45

    
46
    private ICdmFormElement parentFormElement;
47

    
48
    protected RepresentationElement element_Representation;
49

    
50
    private TermComboElement<DefinedTerm> comboStructuralModifier;
51

    
52
    private CheckboxElement supportsQuantitativeData;
53

    
54
    private CheckboxElement supportsCategoricalData;
55

    
56
    private StateVocabularyCollectionSection sectionStateVocabularies;
57

    
58
    private MeasurementUnitCollectionSection sectionMeasurementUnits;
59

    
60
    private StatisticalMeasureCollectionSection sectionStatisticalMeasures;
61

    
62
    private RecommendedModifierVocabulariesCollectionSection sectionModifierVocabularies;
63

    
64
    private InapplicableIfEntityCollectionSectionForNode sectionInapplicableIf;
65
    private OnlyApplicableIfEntityCollectionSectionForNode sectionOnlyApplicableIf;
66

    
67
	public CharacterNodeDetailElement(CdmFormFactory formFactory,
68
			ICdmFormElement formElement) {
69
		super(formFactory, formElement);
70
	}
71

    
72
	@Override
73
	protected void createControls(ICdmFormElement formElement, TermNode<Character> entity, int style) {
74
	    this.parentFormElement = formElement;
75
	    element_Representation = formFactory.createTranslatableRepresentationElement(formElement,  entity.getTerm().getPreferredRepresentation(CdmStore.getDefaultLanguage()),entity.getTerm(), 100, style, true);
76

    
77
	    createText(formElement, "Structure", getStructureText(entity.getTerm()));
78
	    createText(formElement, "Property", getPropertyText(entity.getTerm()));
79

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

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

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

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

    
109
        // applicability
110
        sectionInapplicableIf = formFactory.createInapplicableIfEntityCollectionSectionForNode(getConversationHolder(),
111
                formElement, StoreUtil.getSectionStyle(InapplicableIfEntityCollectionSection.class, entity.getTerm().getClass().getCanonicalName()));
112
        sectionInapplicableIf.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
113
        sectionInapplicableIf.setEntity(getEntity());
114
        sectionOnlyApplicableIf = formFactory.createOnlyApplicableIfEntityCollectionSectionForNode(getConversationHolder(),
115
                formElement, StoreUtil.getSectionStyle(OnlyApplicableIfEntityCollectionSection.class, entity.getTerm().getClass().getCanonicalName()));
116
        sectionOnlyApplicableIf.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
117
        sectionOnlyApplicableIf.setEntity(entity);
118
    }
119

    
120
    public static void createText(ICdmFormElement formElement, String label, String path) {
121
        Label labelText = new Label(formElement.getLayoutComposite(), SWT.NONE);
122
        labelText.setText(label);
123
        Text text = new Text(formElement.getLayoutComposite(), SWT.WRAP);
124
	    text.setText(path);
125
	    text.setEditable(false);
126
	    text.setLayoutData(LayoutConstants.FILL());
127
	    text.setForeground(ColorResources.getColor(Resources.BLACK));
128
    }
129

    
130
    public static String getPropertyText(Character entity) {
131
        return entity.getProperty()!=null?StoreUtil.getPath(entity.getProperty()):"[no property]";
132
    }
133

    
134
    public static String getStructureText(Character entity) {
135
        return entity.getStructure()!=null?StoreUtil.getPath(entity.getStructure()):"[no structure]";
136
    }
137

    
138
    @Override
139
    public void setEntity(TermNode<Character> entity) {
140
        super.setEntity(entity);
141
        setEnabled(TermBasePropertyTester.isModifiable(entity));
142
    }
143

    
144
	@Override
145
	public void handleEvent(Object eventSource) {
146
	    if(eventSource == comboStructuralModifier){
147
	        getEntity().getTerm().setStructureModifier(comboStructuralModifier.getSelection());
148
	    }
149
	    if(eventSource == supportsQuantitativeData || eventSource == supportsCategoricalData){
150
	        //if any type is selected disable supportsTextData
151
	        getEntity().getTerm().setSupportsTextData(false);
152
	    }
153
	    if(eventSource == supportsQuantitativeData){
154
	        getEntity().getTerm().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
155
	        if(supportsQuantitativeData.getSelection()){
156
	            activateQuantitativeWidgets();
157
	        }
158
	        else{
159
	            removeQuantitativeWidgets();
160
	        }
161
            StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
162
	    }
163
	    else if(eventSource == supportsCategoricalData){
164
	        getEntity().getTerm().setSupportsCategoricalData(supportsCategoricalData.getSelection());
165
            if (supportsCategoricalData.getSelection()) {
166
                activateCategoricalWidgets();
167
            }
168
	        else{
169
	            removeCategoricalWidgets();
170
	        }
171
            StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
172
	    }
173
	    else if (eventSource == element_Representation) {
174
            Representation selectedRepresentation = element_Representation.getSelectedRepresentation();
175
            if(selectedRepresentation!=null){
176
                Language representationLanguage = selectedRepresentation.getLanguage();
177
                if(representationLanguage==null){
178
                    representationLanguage = Language.getDefaultLanguage();
179
                }
180
                getEntity().getTerm().setLabel(selectedRepresentation.getLabel(),  representationLanguage);
181
                getEntity().getTerm().getRepresentation(representationLanguage).setAbbreviatedLabel(selectedRepresentation.getAbbreviatedLabel());
182
                getEntity().getTerm().getRepresentation(representationLanguage).setText(selectedRepresentation.getDescription());
183
            }
184
            getEntity().getTerm().setTitleCache(null);
185
        }
186
	}
187

    
188
	private void activateQuantitativeWidgets(){
189
	    //disable categorical widgets
190
	    supportsCategoricalData.setSelection(false);
191
	    getEntity().getTerm().setSupportsCategoricalData(false);
192
	    removeCategoricalWidgets();
193

    
194
	    //measurement units
195
	    sectionMeasurementUnits = formFactory.createMeasurementUnitCollectionSection(getConversationHolder(),
196
	            parentFormElement, StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
197
	    sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
198
	    sectionMeasurementUnits.setEntity(getEntity().getTerm());
199

    
200
	    //statistical measures
201
	    sectionStatisticalMeasures = formFactory.createStatisticalMeasureCollectionSection(
202
	            getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
203
	    sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
204
	    sectionStatisticalMeasures.setEntity(getEntity().getTerm());
205

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

    
213
	private void removeQuantitativeWidgets(){
214
	    if(sectionMeasurementUnits!=null){
215
	        removeElementsAndControls(sectionMeasurementUnits);
216
	        removeElementsAndControls(sectionStatisticalMeasures);
217
	        removeElementsAndControls(sectionModifierVocabularies);
218
	    }
219
	}
220

    
221
	private void activateCategoricalWidgets(){
222
	    //disable quantitative widgeets
223
	    supportsQuantitativeData.setSelection(false);
224
	    getEntity().getTerm().setSupportsQuantitativeData(false);
225
	    removeQuantitativeWidgets();
226

    
227
	    //states
228
	    sectionStateVocabularies = formFactory.createStateVocabulariesSection(getConversationHolder(),
229
                parentFormElement, StoreUtil.getSectionStyle(StateVocabularyCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
230
        sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
231
        sectionStateVocabularies.setEntity(getEntity().getTerm());
232

    
233
        //modifiers
234
        sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesCollectionSection(
235
                getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
236
        sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
237
        sectionModifierVocabularies.setEntity(getEntity().getTerm());
238
	}
239

    
240
	private void removeCategoricalWidgets(){
241
	    if(sectionStateVocabularies!=null){
242
	        removeElementsAndControls(sectionStateVocabularies);
243
	        removeElementsAndControls(sectionModifierVocabularies);
244
	    }
245
	}
246

    
247
}
(4-4/21)