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 java.util.EnumSet;
|
12
|
|
13
|
import org.eclipse.swt.events.SelectionListener;
|
14
|
import org.eclipse.swt.graphics.Color;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
17
|
import eu.etaxonomy.cdm.model.term.TermType;
|
18
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
19
|
import eu.etaxonomy.cdm.persistence.dto.FeatureDto;
|
20
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
21
|
import eu.etaxonomy.taxeditor.ui.combo.VocabularyComboElement;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
25
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
|
26
|
|
27
|
/**
|
28
|
* @author pplitzner
|
29
|
* @date Apr 27, 2015
|
30
|
*/
|
31
|
public class StateVocabularyDtoCollectionElement<T extends DefinedTermBase<T>>
|
32
|
extends AbstractEntityCollectionElement<TermVocabularyDto> {
|
33
|
|
34
|
private VocabularyComboElement<T, TermVocabulary<T>> comboStateVocabulary;
|
35
|
|
36
|
public StateVocabularyDtoCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, TermVocabularyDto entity,
|
37
|
SelectionListener removeListener, Color backgroundColor, int style) {
|
38
|
super(formFactory, section, entity, removeListener, backgroundColor, style);
|
39
|
}
|
40
|
|
41
|
@Override
|
42
|
public void createControls(ICdmFormElement element, int style) {
|
43
|
//for now we allow State and Structure here
|
44
|
comboStateVocabulary = formFactory.createVocabularyDtoComboElement(EnumSet.of(TermType.State, TermType.Structure), "State vocabulary", null, element, style);
|
45
|
if (entity != null){
|
46
|
setEntity(entity);
|
47
|
}
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
public void setEntity(TermVocabularyDto entity) {
|
52
|
this.entity = entity;
|
53
|
if(comboStateVocabulary != null){
|
54
|
comboStateVocabulary.setSelectionDto(entity);
|
55
|
comboStateVocabulary.removeEmptyElement();
|
56
|
}
|
57
|
}
|
58
|
|
59
|
@Override
|
60
|
public void handleEvent(Object eventSource) {
|
61
|
if(eventSource==comboStateVocabulary && comboStateVocabulary.getSelection()!=null){
|
62
|
if(getParentElement() instanceof StateVocabularyDtoCollectionSection){
|
63
|
StateVocabularyDtoCollectionSection parentElement = (StateVocabularyDtoCollectionSection) getParentElement();
|
64
|
FeatureDto feature = parentElement.getEntity();
|
65
|
TermVocabularyDto remove = null;
|
66
|
for (TermVocabularyDto voc: feature.getSupportedCategoricalEnumerations()){
|
67
|
if (voc.getUuid().equals(getEntity().getUuid())){
|
68
|
remove = voc;
|
69
|
break;
|
70
|
}
|
71
|
}
|
72
|
feature.getSupportedCategoricalEnumerations().remove(remove);
|
73
|
TermVocabulary<T> vocabulary = comboStateVocabulary.getSelection();
|
74
|
TermVocabularyDto dto = new TermVocabularyDto(vocabulary.getUuid(), vocabulary.getRepresentations(), vocabulary.getTermType(), vocabulary.getTitleCache(), vocabulary.isAllowDuplicates(), vocabulary.isOrderRelevant(), vocabulary.isFlat());
|
75
|
feature.getSupportedCategoricalEnumerations().add(dto);
|
76
|
entity = dto;
|
77
|
//update the parent section to re-set the listeners to the persisted measurement unit
|
78
|
parentElement.removeElementAndUpdate(null);
|
79
|
}
|
80
|
}
|
81
|
}
|
82
|
}
|