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