- moved OriginalLabel above sources #4776
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / description / StateDataElement.java
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 if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
75 text_modifyingText.setText(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()).getText());
76 }
77 }
78
79 /** {@inheritDoc} */
80 @Override
81 public void createControls(ICdmFormElement element, int style) {
82 combo_state = formFactory.createDefinedTermComboElement(TermType.State, element, "State", null, false, style);
83 section_modifiers = formFactory.createModifierSection(getConversationHolder(), element, ExpandableComposite.TWISTIE);
84 section_modifiers.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
85 text_modifyingText = formFactory.createTextWithLabelElement(element, "Modifying Text", null, style);
86 }
87
88 /** {@inheritDoc} */
89 @Override
90 public void handleEvent(Object eventSource) {
91 if(eventSource == combo_state){
92 getEntity().setState(combo_state.getSelection());
93 }
94 if(eventSource == text_modifyingText){
95 getEntity().putModifyingText(LanguageString.NewInstance(text_modifyingText.getText(), CdmStore.getDefaultLanguage()));
96 }
97 }
98 }