Project

General

Profile

Download (3.93 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.taxeditor.ui.section.description;
11

    
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.Set;
15

    
16
import org.eclipse.swt.events.SelectionListener;
17
import org.eclipse.ui.forms.widgets.ExpandableComposite;
18

    
19
import eu.etaxonomy.cdm.model.common.LanguageString;
20
import eu.etaxonomy.cdm.model.common.TermType;
21
import eu.etaxonomy.cdm.model.common.TermVocabulary;
22
import eu.etaxonomy.cdm.model.description.State;
23
import eu.etaxonomy.cdm.model.description.StateData;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
26
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
27
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
28
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
29
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
30
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
31
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
32

    
33
/**
34
 * <p>StateDataElement class.</p>
35
 *
36
 * @author n.hoffmann
37
 * @created Sep 15, 2010
38
 * @version 1.0
39
 */
40
public class StateDataElement extends AbstractEntityCollectionElement<StateData> {
41

    
42
	private TermComboElement<State> combo_state;
43
	private ModifierSection section_modifiers;
44
	private TextWithLabelElement text_modifyingText;
45

    
46
	/**
47
	 * <p>Constructor for StateDataElement.</p>
48
	 *
49
	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
50
	 * @param section a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
51
	 * @param entity a {@link eu.etaxonomy.cdm.model.description.StateData} object.
52
	 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
53
	 * @param style a int.
54
	 */
55
	public StateDataElement(CdmFormFactory formFactory,
56
			AbstractFormSection section, StateData entity,
57
			SelectionListener removeListener, int style) {
58
		super(formFactory, section, entity, removeListener, null, style);
59
	}
60

    
61
	/** {@inheritDoc} */
62
	@Override
63
	public void setEntity(StateData entity) {
64
		this.entity = entity;
65
		List<State> stateTerms = new ArrayList<State>();
66
		Set<TermVocabulary<State>> stateVocabularies = getEntity().getCategoricalData().getFeature().getSupportedCategoricalEnumerations();
67
		for (TermVocabulary<State> termVocabulary : stateVocabularies) {
68
		    stateTerms.addAll(termVocabulary.getTerms());
69
        }
70
		combo_state.setTerms(stateTerms);
71
		combo_state.setSelection(entity.getState());
72
		section_modifiers.setEntity(entity);
73
		section_modifiers.setExpanded(!entity.getModifiers().isEmpty());
74
		if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null) {
75
            text_modifyingText.setText(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()).getText());
76
        }
77
		if(getEntity().getId()>0){
78
		    combo_state.removeEmptyElement();
79
		}
80
	}
81

    
82
	/** {@inheritDoc} */
83
	@Override
84
	public void createControls(ICdmFormElement element, int style) {
85
		combo_state = formFactory.createDefinedTermComboElement(TermType.State, element, "State", null, style);
86
		section_modifiers = formFactory.createModifierSection(getConversationHolder(), element, ExpandableComposite.TWISTIE|ExpandableComposite.EXPANDED);
87
		section_modifiers.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
88
		text_modifyingText = formFactory.createTextWithLabelElement(element, "Modifying Text", null, style);
89
	}
90

    
91
	/** {@inheritDoc} */
92
	@Override
93
	public void handleEvent(Object eventSource) {
94
		if(eventSource == combo_state){
95
			getEntity().setState(combo_state.getSelection());
96
			combo_state.removeEmptyElement();
97
		}
98
		if(eventSource == text_modifyingText){
99
			getEntity().putModifyingText(LanguageString.NewInstance(text_modifyingText.getText(), CdmStore.getDefaultLanguage()));
100
		}
101
	}
102
}
(22-22/25)