- refactored naming of modifier section #4448
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / description / StateModifierElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2015 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 package eu.etaxonomy.taxeditor.ui.section.description;
11
12 import org.eclipse.swt.events.SelectionListener;
13 import org.eclipse.swt.graphics.Color;
14
15 import eu.etaxonomy.cdm.model.common.DefinedTerm;
16 import eu.etaxonomy.cdm.model.common.TermType;
17 import eu.etaxonomy.cdm.model.common.TermVocabulary;
18 import eu.etaxonomy.cdm.model.description.Feature;
19 import eu.etaxonomy.taxeditor.ui.combo.VocabularyComboElement;
20 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
21 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
22 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
23 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
24 import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesCollectionSection;
25
26 /**
27 * @author pplitzner
28 * @date Apr 27, 2015
29 *
30 */
31 public class StateModifierElement extends AbstractEntityCollectionElement<TermVocabulary<DefinedTerm>> {
32
33
34 private VocabularyComboElement<DefinedTerm, TermVocabulary<DefinedTerm>> comboStateVocabulary;
35
36 /**
37 * @param formFactory
38 * @param section
39 * @param entity
40 * @param removeListener
41 * @param isChoosableEntity
42 * @param backgroundColor
43 * @param style
44 */
45 public StateModifierElement(CdmFormFactory formFactory, AbstractFormSection section, TermVocabulary<DefinedTerm> entity,
46 SelectionListener removeListener, Color backgroundColor, int style) {
47 super(formFactory, section, entity, removeListener, false, backgroundColor, style);
48
49 }
50
51 @Override
52 public void createControls(ICdmFormElement element, int style) {
53 comboStateVocabulary = formFactory.createVocabularyComboElement(TermType.Modifier, "State modifiers", null, element, style);
54 }
55
56 @Override
57 public void setEntity(TermVocabulary<DefinedTerm> entity) {
58 this.entity = entity;
59 if(entity.getId()!=0){
60 comboStateVocabulary.setSelection(entity);
61 }
62 }
63
64 @Override
65 public void handleEvent(Object eventSource) {
66 if(eventSource==comboStateVocabulary && comboStateVocabulary.getSelection()!=null){
67 if(getParentElement() instanceof RecommendedModifierVocabulariesCollectionSection){
68 Feature feature = ((RecommendedModifierVocabulariesCollectionSection) getParentElement()).getEntity();
69 feature.removeRecommendedModifierEnumeration(entity);
70 TermVocabulary<DefinedTerm> vocabulary = comboStateVocabulary.getSelection();
71 feature.addRecommendedModifierEnumeration(vocabulary);
72 entity = vocabulary;
73 }
74 }
75 }
76
77 }