Committing changes to definedtermeditor after merge from branch
[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 org.eclipse.swt.events.SelectionListener;
14 import org.eclipse.ui.forms.widgets.Section;
15
16 import eu.etaxonomy.cdm.model.common.LanguageString;
17 import eu.etaxonomy.cdm.model.description.State;
18 import eu.etaxonomy.cdm.model.description.StateData;
19 import eu.etaxonomy.taxeditor.store.CdmStore;
20 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
21 import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
22 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
23 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EntityDetailType;
24 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
25 import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
26 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
27
28 /**
29 * <p>StateDataElement class.</p>
30 *
31 * @author n.hoffmann
32 * @created Sep 15, 2010
33 * @version 1.0
34 */
35 public class StateDataElement extends AbstractEntityCollectionElement<StateData> {
36
37 private TermComboElement<State> combo_state;
38 private ModifierSection section_modifiers;
39 private TextWithLabelElement text_modifyingText;
40
41 /**
42 * <p>Constructor for StateDataElement.</p>
43 *
44 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
45 * @param section a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection} object.
46 * @param entity a {@link eu.etaxonomy.cdm.model.description.StateData} object.
47 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
48 * @param style a int.
49 */
50 public StateDataElement(CdmFormFactory formFactory,
51 AbstractFormSection section, StateData entity,
52 SelectionListener removeListener, int style) {
53 super(formFactory, section, entity, removeListener, null, style);
54 }
55
56 /** {@inheritDoc} */
57 @Override
58 public void setEntity(StateData entity) {
59 this.entity = entity;
60 combo_state.setSelection(entity.getState());
61 section_modifiers.setEntity(entity);
62 if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null)
63 text_modifyingText.setText(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()).getText());
64 }
65
66 /** {@inheritDoc} */
67 @Override
68 public void createControls(ICdmFormElement element, int style) {
69 combo_state = formFactory.createTermComboElement(State.class, element, "State", null, style);
70 section_modifiers = (ModifierSection) formFactory.createEntityDetailSection(EntityDetailType.MODIFIER, getConversationHolder(), element, Section.TWISTIE);
71 section_modifiers.setLayoutData(CdmFormFactory.FILL_HORIZONTALLY(2, 1));
72 text_modifyingText = formFactory.createTextWithLabelElement(element, "Modifying Text", null, style);
73 }
74
75 /** {@inheritDoc} */
76 @Override
77 public void handleEvent(Object eventSource) {
78 if(eventSource == combo_state){
79 getEntity().setState(combo_state.getSelection());
80 }
81 if(eventSource == text_modifyingText){
82 getEntity().addModifyingText(LanguageString.NewInstance(text_modifyingText.getText(), CdmStore.getDefaultLanguage()));
83 }
84 }
85 }