1
|
/**
|
2
|
* Copyright (C) 2018 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.element;
|
10
|
|
11
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
12
|
import org.eclipse.swt.graphics.Color;
|
13
|
import org.eclipse.swt.widgets.Label;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
16
|
|
17
|
public abstract class TimePeriodElementBase<T extends TimePeriod>
|
18
|
extends AbstractRelevanceFormElement
|
19
|
implements ISelectable {
|
20
|
|
21
|
protected T timePeriod;
|
22
|
protected Label label;
|
23
|
protected DateDetailSection<T> section_dateDetails;
|
24
|
|
25
|
/**
|
26
|
* Constructor for TimePeriodElement.
|
27
|
*/
|
28
|
public TimePeriodElementBase(CdmFormFactory formFactory,
|
29
|
ICdmFormElement parentElement, String labelString,
|
30
|
T timePeriod, final int style) {
|
31
|
super(formFactory, parentElement);
|
32
|
label = formFactory.createLabel(getLayoutComposite(), labelString);
|
33
|
|
34
|
addControl(label);
|
35
|
|
36
|
section_dateDetails = createDateDetailSection();
|
37
|
addControl(section_dateDetails);
|
38
|
|
39
|
setTimePeriod(timePeriod);
|
40
|
|
41
|
formFactory.addPropertyChangeListener(this);
|
42
|
}
|
43
|
|
44
|
|
45
|
protected abstract DateDetailSection<T> createDateDetailSection();
|
46
|
|
47
|
public void setEntity(T timePeriod) {
|
48
|
setTimePeriod(timePeriod);
|
49
|
}
|
50
|
|
51
|
@Override
|
52
|
public void propertyChange(PropertyChangeEvent event) {
|
53
|
if (event == null) {
|
54
|
return;
|
55
|
}
|
56
|
Object eventSource = event.getSource();
|
57
|
|
58
|
if (getElements().contains(eventSource)) {
|
59
|
handleEvent(eventSource);
|
60
|
}
|
61
|
}
|
62
|
|
63
|
private void handleEvent(Object eventSource) {
|
64
|
if (eventSource == section_dateDetails) {
|
65
|
timePeriod = section_dateDetails.getEntity();
|
66
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
|
67
|
}
|
68
|
}
|
69
|
|
70
|
public void setTimePeriod(T timePeriod) {
|
71
|
this.timePeriod = timePeriod;
|
72
|
if (timePeriod != null) {
|
73
|
section_dateDetails.setEntity(timePeriod);
|
74
|
}
|
75
|
}
|
76
|
|
77
|
public T getTimePeriod() {
|
78
|
return timePeriod;
|
79
|
}
|
80
|
|
81
|
@Override
|
82
|
public void setBackground(Color color) {
|
83
|
label.setBackground(color);
|
84
|
section_dateDetails.setBackground(color);
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
public void setSelected(boolean selected) {
|
89
|
setBackground(selected ? SELECTED : getPersistentBackground());
|
90
|
}
|
91
|
|
92
|
public void setLabel(String string) {
|
93
|
label.setText(string);
|
94
|
}
|
95
|
|
96
|
@Override
|
97
|
public void updateCacheRelevance() {
|
98
|
if (section_dateDetails != null){
|
99
|
section_dateDetails.updateCacheRelevance();
|
100
|
}
|
101
|
}
|
102
|
|
103
|
@Override
|
104
|
public void addDependsOnCache(ToggleableTextElement cacheElement) {
|
105
|
if (section_dateDetails != null){
|
106
|
section_dateDetails.addDependsOnCache(cacheElement);
|
107
|
}
|
108
|
}
|
109
|
}
|