Project

General

Profile

Download (4.4 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
package eu.etaxonomy.taxeditor.ui.section.description;
10

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

    
15
import org.eclipse.swt.events.SelectionListener;
16

    
17
import eu.etaxonomy.cdm.model.common.LanguageString;
18
import eu.etaxonomy.cdm.model.description.StateData;
19
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
20
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
21
import eu.etaxonomy.cdm.model.term.TermType;
22
import eu.etaxonomy.cdm.model.term.TermVocabulary;
23
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25
import eu.etaxonomy.taxeditor.store.StoreUtil;
26
import eu.etaxonomy.taxeditor.ui.combo.term.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
 * @author n.hoffmann
36
 * @created Sep 15, 2010
37
 */
38
public class StateDataElement extends AbstractEntityCollectionElement<StateData> {
39

    
40
	private TermComboElement<DefinedTermBase<?>> combo_state;
41
	private ModifierSection section_modifiers;
42
	private TextWithLabelElement text_modifyingText;
43

    
44
	public StateDataElement(CdmFormFactory formFactory,
45
			AbstractFormSection<?> section, StateData entity,
46
			SelectionListener removeListener, int style) {
47
		super(formFactory, section, entity, removeListener, null, style);
48
	}
49

    
50
	@Override
51
	public void setEntity(StateData entity) {
52
		this.entity = entity;
53
		if (combo_state != null){
54

    
55
			combo_state.setSelection(entity.getState());
56
			if (section_modifiers != null){
57
	    		section_modifiers.setEntity(entity);
58
	    		section_modifiers.setExpanded(!entity.getModifiers().isEmpty());
59
			}
60
			if(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()) != null && text_modifyingText != null) {
61
	            text_modifyingText.setText(getEntity().getModifyingText().get(CdmStore.getDefaultLanguage()).getText());
62
	        }
63
			if(getEntity().getId()>0){
64
			    combo_state.removeEmptyElement();
65
			}
66
		}
67
	}
68

    
69
	@Override
70
	public void createControls(ICdmFormElement element, int style) {
71
		if (getEntity() != null){
72
			List<DefinedTermBase<?>> stateTerms = new ArrayList<>();
73
			Set<TermVocabulary<?>> stateVocabularies = getEntity().getCategoricalData().getFeature().getSupportedCategoricalEnumerations();
74
			for (TermVocabulary<?> termVocabulary : stateVocabularies) {
75
			    stateTerms.addAll((Set)termVocabulary.getTerms());
76
	        }
77
			combo_state = formFactory.createDefinedTermComboElement(stateTerms, element, "State", null, style);
78
		}else{
79
			combo_state = formFactory.createDefinedTermComboElement(TermType.State, element, "State", null, style);
80
		}
81
//		combo_state.setTermComparator(new DefaultTermComparator<State>());
82
		if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowModifier.getKey())){
83
		    section_modifiers = formFactory.createModifierSection(element, StoreUtil.getSectionStyle(ModifierSection.class, StateData.class.getCanonicalName(), true));
84
		    section_modifiers.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
85
		}
86
		if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowModifierFreeText.getKey())){
87
		    text_modifyingText = formFactory.createTextWithLabelElement(element, "Modifying Text", null, style);
88
		}
89
		if (entity != null){
90
			setEntity(entity);
91
		}
92

    
93
	}
94

    
95
	@Override
96
	public void handleEvent(Object eventSource) {
97
		if(eventSource == combo_state){
98
			getEntity().setState(combo_state.getSelection());
99
			combo_state.removeEmptyElement();
100
		}
101
		if(eventSource == text_modifyingText){
102
			getEntity().putModifyingText(LanguageString.NewInstance(text_modifyingText.getText(), CdmStore.getDefaultLanguage()));
103
		}
104
	}
105

    
106
	@Override
107
    public void setEnabled(boolean enable){
108
		if (combo_state != null){
109
			combo_state.setEnabled(enable);
110
		}
111
	    if (section_modifiers != null){
112
	    	section_modifiers.setEnabled(enable);
113
	    }
114
	    if (text_modifyingText != null){
115
	    	text_modifyingText.setEnabled(enable);
116
	    }
117
	    super.setEnabled(enable);
118
	}
119
}
(23-23/26)