Project

General

Profile

Download (14.8 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.jface.util.PropertyChangeEvent;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.widgets.Label;
14
import org.eclipse.swt.widgets.Text;
15

    
16
import eu.etaxonomy.cdm.model.common.Language;
17
import eu.etaxonomy.cdm.model.description.Character;
18
import eu.etaxonomy.cdm.model.term.DefinedTerm;
19
import eu.etaxonomy.cdm.model.term.Representation;
20
import eu.etaxonomy.cdm.model.term.TermType;
21
import eu.etaxonomy.cdm.persistence.dto.CharacterDto;
22
import eu.etaxonomy.cdm.persistence.dto.FeatureDto;
23
import eu.etaxonomy.cdm.persistence.dto.TermDto;
24
import eu.etaxonomy.taxeditor.editor.definedterm.TermBasePropertyTester;
25
import eu.etaxonomy.taxeditor.event.EventUtility;
26
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
27
import eu.etaxonomy.taxeditor.model.ColorResources;
28
import eu.etaxonomy.taxeditor.preference.Resources;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30
import eu.etaxonomy.taxeditor.store.StoreUtil;
31
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
32
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
33
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
34
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
35
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
36
import eu.etaxonomy.taxeditor.ui.element.RepresentationElement;
37
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
38
import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
39
import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitDtoCollectionSection;
40
import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesCollectionSection;
41
import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesDtoCollectionSection;
42
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionSection;
43
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyDtoCollectionSection;
44
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StatisticalMeasureCollectionSection;
45
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StatisticalMeasureDtoCollectionSection;
46

    
47
/**
48
 *
49
 * @author pplitzner
50
 * @since Dec 21, 2017
51
 *
52
 */
53
public class CharacterDtoDetailElement extends AbstractCdmDetailElement<CharacterDto> {
54

    
55
    private ICdmFormElement parentFormElement;
56

    
57
    protected RepresentationElement element_Representation;
58

    
59
    private TermComboElement<DefinedTerm> comboStructuralModifier;
60

    
61
    private CheckboxElement supportsQuantitativeData;
62

    
63
    private CheckboxElement supportsCategoricalData;
64

    
65
    private StateVocabularyDtoCollectionSection sectionStateVocabularies;
66

    
67
    private MeasurementUnitDtoCollectionSection sectionMeasurementUnits;
68

    
69
    private StatisticalMeasureDtoCollectionSection sectionStatisticalMeasures;
70

    
71
    private RecommendedModifierVocabulariesDtoCollectionSection sectionModifierVocabularies;
72
    private Label labelText_structure;
73
    private Text text_structure;
74

    
75
    private Label labelText_property;
76
    private Text text_property;
77

    
78
    private Label labelText_ratioTo;
79
    private Text text_ratioTo;
80
//    private TextWithLabelElement text_structure;
81
//    private TextWithLabelElement text_property;
82

    
83

    
84
	public CharacterDtoDetailElement(CdmFormFactory formFactory,
85
			ICdmFormElement formElement) {
86
		super(formFactory, formElement);
87
	}
88

    
89
	@Override
90
	protected void createControls(ICdmFormElement formElement, CharacterDto entity, int style) {
91
	    this.parentFormElement = formElement;
92

    
93
	    element_Representation = formFactory.createTranslatableRepresentationElementDto(formElement,  entity.getPreferredRepresentation(CdmStore.getDefaultLanguage()),entity, 100, style, true);
94
	    if (labelText_property != null){
95
	        labelText_structure.dispose();
96
	    }
97
	    labelText_structure = new Label(formElement.getLayoutComposite(), SWT.NONE);
98
	    labelText_structure.setText("Structure");
99
	    if (text_structure != null){
100
	        text_structure.dispose();
101
	    }
102
	    text_structure = new Text(formElement.getLayoutComposite(), SWT.WRAP);
103
        text_structure.setText( entity.getStructure().getPath());
104
        text_structure.setEditable(false);
105
        text_structure.setLayoutData(LayoutConstants.FILL());
106
        text_structure.setForeground(ColorResources.getColor(Resources.BLACK));
107
        if (labelText_property != null){
108
            labelText_property.dispose();
109
        }
110
        labelText_property =  new Label(formElement.getLayoutComposite(), SWT.NONE);
111
	    labelText_property.setText("Property");
112
	    if (text_property != null){
113
	        text_property.dispose();
114
	    }
115
	    text_property = new Text(formElement.getLayoutComposite(), SWT.WRAP);
116
	    text_property.setEditable(false);
117
	    text_property.setText(entity.getProperty().getPath());
118
	    text_property.setLayoutData(LayoutConstants.FILL());
119
	    text_property.setForeground(ColorResources.getColor(Resources.BLACK));
120

    
121
        comboStructuralModifier = formFactory.createDefinedTermComboElementDto(TermType.StructureModifier, formElement, "Structural Modifier", entity.getStructureModifier(), style);
122

    
123
        if (labelText_ratioTo != null){
124
            labelText_ratioTo.dispose();
125
        }
126
        labelText_ratioTo =  new Label(formElement.getLayoutComposite(), SWT.NONE);
127
        labelText_ratioTo.setText("Ratio to");
128
        if (text_ratioTo != null){
129
            text_ratioTo.dispose();
130
        }
131
        text_ratioTo = new Text(formElement.getLayoutComposite(), SWT.WRAP);
132
        text_ratioTo.setEditable(false);
133
        if (entity.getRatioTo() != null){
134
            text_ratioTo.setText(entity.getRatioTo().getPath());
135
        }
136
        text_ratioTo.setLayoutData(LayoutConstants.FILL());
137
        text_ratioTo.setForeground(ColorResources.getColor(Resources.BLACK));
138

    
139
	    supportsQuantitativeData = formFactory.createCheckbox(formElement, "Supports Quantitative Data", ((FeatureDto) entity).isSupportsQuantitativeData(), style);
140
	    supportsCategoricalData = formFactory.createCheckbox(formElement, "Supports Categorical Data", ((FeatureDto) entity).isSupportsCategoricalData(), style);
141

    
142
        if (supportsCategoricalData.getSelection()) {
143
            sectionStateVocabularies = formFactory.createStateVocabulariesDtoSection(getConversationHolder(),
144
                    parentFormElement, StoreUtil.getSectionStyle(StateVocabularyCollectionSection.class, entity.getClass().getCanonicalName(), true));
145
            sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
146
            sectionStateVocabularies.setEntity((entity));
147
        }
148
        if (supportsQuantitativeData.getSelection()) {
149
            sectionMeasurementUnits = formFactory.createMeasurementUnitDtoCollectionSection(getConversationHolder(),
150
                    parentFormElement, StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, entity.getClass().getCanonicalName(), true));
151
            sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
152
            sectionMeasurementUnits.setEntity((entity));
153

    
154
            sectionStatisticalMeasures = formFactory.createStatisticalMeasureDtoCollectionSection(getConversationHolder(),
155
                    parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, entity.getClass().getCanonicalName(), true));
156
            sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
157
            sectionStatisticalMeasures.setEntity((entity));
158
        }
159
        if (supportsCategoricalData.getSelection() || supportsQuantitativeData.getSelection()) {
160
            sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesDtoCollectionSection(
161
                    getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, entity.getClass().getCanonicalName(), true));
162
            sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
163
            sectionModifierVocabularies.setEntity((entity));
164
        }
165

    
166
    }
167

    
168
	public String getPropertyText() {
169
        return getEntity().getProperty()!=null?getEntity().getProperty().getPath():"[no property]";
170
    }
171

    
172
    public String getStructureText(Character entity) {
173
        return entity.getStructure()!=null?entity.getStructure().getPath():"[no structure]";
174
    }
175
//	public void createText(ICdmFormElement formElement, String label, String path) {
176
//	    labelText = new Label(formElement.getLayoutComposite(), SWT.NONE);
177
//        labelText.setText(label);
178
//        Text text = new Text(formElement.getLayoutComposite(), SWT.WRAP);
179
//        text.setText(path);
180
//        text.setEditable(false);
181
//        text.setLayoutData(LayoutConstants.FILL());
182
//        text.setForeground(ColorResources.getColor(Resources.BLACK));
183
//    }
184

    
185
    @Override
186
    public void setEntity(CharacterDto entity) {
187
        super.setEntity(entity);
188
        setEnabled(TermBasePropertyTester.isModifiable(entity));
189
    }
190

    
191
	@Override
192
	public void handleEvent(Object eventSource) {
193
	    if(eventSource == comboStructuralModifier){
194
	        getEntity().setStructureModifier(TermDto.fromTerm(comboStructuralModifier.getSelection()));
195
	    }
196
//	    if(eventSource == supportsQuantitativeData || eventSource == supportsCategoricalData){
197
//	        //if any type is selected disable supportsTextData
198
//	        getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
199
//	        getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
200
//	    }
201
	    if(eventSource == supportsQuantitativeData){
202
	        getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
203
	        getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
204
	        if(supportsQuantitativeData.getSelection()){
205
	            activateQuantitativeWidgets();
206
	        }
207
	        else{
208
	            removeQuantitativeWidgets();
209
	        }
210
            StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
211
	    }
212
	    else if(eventSource == supportsCategoricalData){
213
	        getEntity().setSupportsCategoricalData(supportsCategoricalData.getSelection());
214
	        getEntity().setSupportsQuantitativeData(supportsQuantitativeData.getSelection());
215
            if (supportsCategoricalData.getSelection()) {
216
                activateCategoricalWidgets();
217
            }
218
	        else{
219
	            removeCategoricalWidgets();
220
	        }
221
            StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
222
	    }
223
	    else if (eventSource == element_Representation) {
224
            Representation selectedRepresentation = element_Representation.getSelectedRepresentation();
225
            if(selectedRepresentation!=null){
226
                Language representationLanguage = selectedRepresentation.getLanguage();
227
                if(representationLanguage==null){
228
                    representationLanguage = Language.getDefaultLanguage();
229
                }
230
//                TODO:handle representations correctly
231
//                getEntity().setLabel(selectedRepresentation.getLabel(),  representationLanguage);
232
//                getEntity().getRepresentation(representationLanguage).setAbbreviatedLabel(selectedRepresentation.getAbbreviatedLabel());
233
//                getEntity().getRepresentation(representationLanguage).setText(selectedRepresentation.getDescription());
234
            }
235
//            getEntity().setTitleCache(null);
236
        }
237
	}
238

    
239
	private void activateQuantitativeWidgets(){
240
	    //disable categorical widgets
241
	    supportsCategoricalData.setSelection(false);
242
	    getEntity().setSupportsCategoricalData(false);
243
	    removeCategoricalWidgets();
244

    
245
	    //measurement units
246
	    sectionMeasurementUnits = formFactory.createMeasurementUnitDtoCollectionSection(getConversationHolder(),
247
	            parentFormElement, StoreUtil.getSectionStyle(MeasurementUnitCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
248
	    sectionMeasurementUnits.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
249
	    sectionMeasurementUnits.setEntity((getEntity()));
250

    
251
	    //statistical measures
252
	    sectionStatisticalMeasures = formFactory.createStatisticalMeasureDtoCollectionSection(
253
	            getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(StatisticalMeasureCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
254
	    sectionStatisticalMeasures.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
255
	    sectionStatisticalMeasures.setEntity((getEntity()));
256

    
257
	    //modifiers
258
	    sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesDtoCollectionSection(
259
	            getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
260
	    sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
261
	    sectionModifierVocabularies.setEntity((getEntity()));
262
	}
263

    
264
	private void removeQuantitativeWidgets(){
265
	    if(sectionMeasurementUnits!=null){
266
	        removeElementsAndControls(sectionMeasurementUnits);
267
	        removeElementsAndControls(sectionStatisticalMeasures);
268
	        removeElementsAndControls(sectionModifierVocabularies);
269
	    }
270
	}
271

    
272
	private void activateCategoricalWidgets(){
273
	    //disable quantitative widgeets
274
	    supportsQuantitativeData.setSelection(false);
275
	    getEntity().setSupportsQuantitativeData(false);
276
	    removeQuantitativeWidgets();
277

    
278
	    //states
279
	    sectionStateVocabularies = formFactory.createStateVocabulariesDtoSection(getConversationHolder(),
280
                parentFormElement, StoreUtil.getSectionStyle(StateVocabularyCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
281
        sectionStateVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
282
        sectionStateVocabularies.setEntity((getEntity()));
283

    
284
        //modifiers
285
        sectionModifierVocabularies = formFactory.createRecommendedModifierVocabulariesDtoCollectionSection(
286
                getConversationHolder(), parentFormElement, StoreUtil.getSectionStyle(RecommendedModifierVocabulariesCollectionSection.class, getEntity().getClass().getCanonicalName(), true));
287
        sectionModifierVocabularies.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
288
        sectionModifierVocabularies.setEntity((getEntity()));
289
	}
290

    
291
	private void removeCategoricalWidgets(){
292
	    if(sectionStateVocabularies!=null){
293
	        removeElementsAndControls(sectionStateVocabularies);
294
	        removeElementsAndControls(sectionModifierVocabularies);
295
	    }
296
	}
297

    
298
	@Override
299
    public void propertyChange(PropertyChangeEvent event) {
300
	    EventUtility.postEvent(WorkbenchEventConstants.ADD_SAVE_CANDIDATE, getEntity());
301
	    super.propertyChange(event);
302

    
303
	}
304

    
305
}
(4-4/25)