1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 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
|
|
11
|
package eu.etaxonomy.taxeditor.ui.forms;
|
12
|
|
13
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
14
|
import org.joda.time.Partial;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
17
|
|
18
|
/**
|
19
|
* <p>DateDetailSection class.</p>
|
20
|
*
|
21
|
* @author n.hoffmann
|
22
|
* @created Mar 31, 2010
|
23
|
* @version 1.0
|
24
|
*/
|
25
|
public class DateDetailSection extends AbstractFormSection<TimePeriod> {
|
26
|
|
27
|
private PartialElement partialElement_start;
|
28
|
private PartialElement partialElement_end;
|
29
|
|
30
|
/**
|
31
|
* <p>Constructor for DateDetailSection.</p>
|
32
|
*
|
33
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
|
34
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
|
35
|
* @param style a int.
|
36
|
*/
|
37
|
protected DateDetailSection(CdmFormFactory formFactory, ICdmFormElement parentElement,
|
38
|
int style) {
|
39
|
super(formFactory, null, parentElement, style);
|
40
|
this.setText("Date Details");
|
41
|
|
42
|
partialElement_start = formFactory.createPartialElement(this, "Start: ", null, style);
|
43
|
partialElement_end = formFactory.createPartialElement(this, "End: ", null, style);
|
44
|
|
45
|
formFactory.addPropertyChangeListener(this);
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* <p>Setter for the field <code>timePeriod</code>.</p>
|
50
|
*
|
51
|
* @param timePeriod a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
|
52
|
*/
|
53
|
public void setEntity(TimePeriod timePeriod) {
|
54
|
Partial start = timePeriod.getStart();
|
55
|
partialElement_start.setPartial(start);
|
56
|
Partial end = timePeriod.getEnd();
|
57
|
partialElement_end.setPartial(end);
|
58
|
|
59
|
super.setEntity(timePeriod);
|
60
|
}
|
61
|
|
62
|
/** {@inheritDoc} */
|
63
|
@Override
|
64
|
public void propertyChange(PropertyChangeEvent event) {
|
65
|
if(event == null){
|
66
|
return;
|
67
|
}
|
68
|
Object eventSource = event.getSource();
|
69
|
|
70
|
if(getElements().contains(eventSource)){
|
71
|
if(event instanceof CdmPropertyChangeEvent){
|
72
|
if(((CdmPropertyChangeEvent) event).hasException()){
|
73
|
handleException((CdmPropertyChangeEvent) event);
|
74
|
return;
|
75
|
}
|
76
|
}
|
77
|
handleEvent(eventSource);
|
78
|
}
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* @param event
|
83
|
*/
|
84
|
private void handleException(CdmPropertyChangeEvent event) {
|
85
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event.getException()));
|
86
|
}
|
87
|
|
88
|
private void handleEvent(Object eventSource){
|
89
|
if(eventSource == partialElement_start){
|
90
|
Partial start = partialElement_start.getPartial();
|
91
|
getEntity().setStart(start);
|
92
|
}else if(eventSource == partialElement_end){
|
93
|
Partial end = partialElement_end.getPartial();
|
94
|
getEntity().setEnd(end);
|
95
|
}
|
96
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
|
97
|
}
|
98
|
|
99
|
/* (non-Javadoc)
|
100
|
* @see eu.etaxonomy.taxeditor.forms.AbstractFormSection#dispose()
|
101
|
*/
|
102
|
/** {@inheritDoc} */
|
103
|
@Override
|
104
|
public void dispose() {
|
105
|
formFactory.removePropertyChangeListener(this);
|
106
|
super.dispose();
|
107
|
}
|
108
|
|
109
|
}
|