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.description.StatisticalMeasure;
|
15
|
import eu.etaxonomy.cdm.model.term.TermType;
|
16
|
import eu.etaxonomy.cdm.persistence.dto.FeatureDto;
|
17
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
18
|
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
|
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 StatisticalMeasureDtoCollectionElement extends AbstractEntityCollectionElement<TermDto> {
|
30
|
|
31
|
|
32
|
private TermComboElement<StatisticalMeasure> comboStatisticalMeasure;
|
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 StatisticalMeasureDtoCollectionElement(CdmFormFactory formFactory, AbstractFormSection section, TermDto entity,
|
44
|
SelectionListener removeListener, Color backgroundColor, int style) {
|
45
|
super(formFactory, section, entity, removeListener, backgroundColor, style);
|
46
|
|
47
|
}
|
48
|
|
49
|
@Override
|
50
|
public void createControls(ICdmFormElement element, int style) {
|
51
|
comboStatisticalMeasure = formFactory.createDefinedTermComboElementDto(TermType.StatisticalMeasure, element, "Statistical measure", null, style);
|
52
|
if (entity != null){
|
53
|
setEntity(entity);
|
54
|
}
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public void setEntity(TermDto entity) {
|
59
|
this.entity = entity;
|
60
|
if(comboStatisticalMeasure != null){
|
61
|
comboStatisticalMeasure.setSelectionDto(entity);
|
62
|
comboStatisticalMeasure.removeEmptyElement();
|
63
|
}
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
public void handleEvent(Object eventSource) {
|
68
|
if(eventSource==comboStatisticalMeasure && comboStatisticalMeasure.getSelection()!=null){
|
69
|
if(getParentElement() instanceof StatisticalMeasureDtoCollectionSection){
|
70
|
StatisticalMeasureDtoCollectionSection parentElement = (StatisticalMeasureDtoCollectionSection) getParentElement();
|
71
|
FeatureDto feature = parentElement.getEntity();
|
72
|
TermDto remove = null;
|
73
|
for (TermDto unit: feature.getRecommendedStatisticalMeasures()){
|
74
|
if (unit.getUuid().equals(getEntity().getUuid())){
|
75
|
remove =unit;
|
76
|
break;
|
77
|
}
|
78
|
}
|
79
|
feature.getRecommendedStatisticalMeasures().remove(remove);
|
80
|
StatisticalMeasure statisticalMeasure = comboStatisticalMeasure.getSelection();
|
81
|
entity = TermDto.fromTerm(statisticalMeasure);
|
82
|
feature.getRecommendedStatisticalMeasures().add(entity);
|
83
|
|
84
|
//update the parent section to re-set the listeners to the persisted measurement unit
|
85
|
// parentElement.removeElementAndUpdate(null);
|
86
|
}
|
87
|
}
|
88
|
}
|
89
|
|
90
|
}
|