1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.ui.section.description;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
|
17
|
import org.eclipse.swt.events.SelectionListener;
|
18
|
import org.eclipse.ui.forms.widgets.ExpandableComposite;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
21
|
import eu.etaxonomy.cdm.model.common.TermType;
|
22
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
23
|
import eu.etaxonomy.cdm.model.description.State;
|
24
|
import eu.etaxonomy.cdm.model.description.StateData;
|
25
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26
|
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
31
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
|
33
|
|
34
|
/**
|
35
|
* <p>StateDataElement class.</p>
|
36
|
*
|
37
|
* @author n.hoffmann
|
38
|
* @created Sep 15, 2010
|
39
|
* @version 1.0
|
40
|
*/
|
41
|
public class StateDataElement extends AbstractEntityCollectionElement<StateData> {
|
42
|
|
43
|
private TermComboElement<State> combo_state;
|
44
|
private ModifierSection section_modifiers;
|
45
|
private TextWithLabelElement text_modifyingText;
|
46
|
|
47
|
/**
|
48
|
* <p>Constructor for StateDataElement.</p>
|
49
|
*
|
50
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
51
|
* @param section a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
|
52
|
* @param entity a {@link eu.etaxonomy.cdm.model.description.StateData} object.
|
53
|
* @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
|
54
|
* @param style a int.
|
55
|
*/
|
56
|
public StateDataElement(CdmFormFactory formFactory,
|
57
|
AbstractFormSection section, StateData entity,
|
58
|
SelectionListener removeListener, int style) {
|
59
|
super(formFactory, section, entity, removeListener, null, style);
|
60
|
}
|
61
|
|
62
|
/** {@inheritDoc} */
|
63
|
@Override
|
64
|
public void setEntity(StateData entity) {
|
65
|
this.entity = entity;
|
66
|
List<State> stateTerms = new ArrayList<State>();
|
67
|
Set<TermVocabulary<State>> stateVocabularies = getEntity().getCategoricalData().getFeature().getSupportedCategoricalEnumerations();
|
68
|
for (TermVocabulary<State> termVocabulary : stateVocabularies) {
|
69
|
stateTerms.addAll(termVocabulary.getTerms());
|
70
|
}
|
71
|
combo_state.setTerms(stateTerms);
|
72
|
combo_state.setSelection(entity.getState());
|
73
|
section_modifiers.setEntity(entity);
|
74
|
section_modifiers.setExpanded(!entity.getModifiers().isEmpty());
|
75
|
if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
|
76
|
text_modifyingText.setText(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()).getText());
|
77
|
}
|
78
|
if(getEntity().getId()>0){
|
79
|
combo_state.removeEmptyElement();
|
80
|
}
|
81
|
}
|
82
|
|
83
|
/** {@inheritDoc} */
|
84
|
@Override
|
85
|
public void createControls(ICdmFormElement element, int style) {
|
86
|
combo_state = formFactory.createDefinedTermComboElement(TermType.State, element, "State", null, style);
|
87
|
section_modifiers = formFactory.createModifierSection(getConversationHolder(), element, ExpandableComposite.TWISTIE|ExpandableComposite.EXPANDED);
|
88
|
section_modifiers.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
89
|
text_modifyingText = formFactory.createTextWithLabelElement(element, "Modifying Text", null, style);
|
90
|
}
|
91
|
|
92
|
/** {@inheritDoc} */
|
93
|
@Override
|
94
|
public void handleEvent(Object eventSource) {
|
95
|
if(eventSource == combo_state){
|
96
|
getEntity().setState(combo_state.getSelection());
|
97
|
combo_state.removeEmptyElement();
|
98
|
}
|
99
|
if(eventSource == text_modifyingText){
|
100
|
getEntity().putModifyingText(LanguageString.NewInstance(text_modifyingText.getText(), CdmStore.getDefaultLanguage()));
|
101
|
}
|
102
|
}
|
103
|
}
|