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