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.forms;
|
12
|
|
13
|
import java.text.ParseException;
|
14
|
|
15
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
16
|
import org.eclipse.swt.widgets.Text;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.location.Point;
|
19
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
20
|
import eu.etaxonomy.taxeditor.forms.CdmFormFactory.TermComboType;
|
21
|
import eu.etaxonomy.taxeditor.forms.term.ReferenceSystemComboElement;
|
22
|
|
23
|
/**
|
24
|
* <p>PointElement class.</p>
|
25
|
*
|
26
|
* @author n.hoffmann
|
27
|
* @created Oct 15, 2010
|
28
|
* @version 1.0
|
29
|
*/
|
30
|
public class PointElement extends AbstractCdmFormElement implements IEntityElement<Point>{
|
31
|
|
32
|
private Point point;
|
33
|
|
34
|
private ReferenceSystemComboElement combo_referenceSystem;
|
35
|
private TextWithLabelElement text_latitude;
|
36
|
private TextWithLabelElement text_longitude;
|
37
|
private NumberWithLabelElement number_errorRadius;
|
38
|
|
39
|
/**
|
40
|
* <p>Constructor for PointElement.</p>
|
41
|
*
|
42
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
|
43
|
* @param formElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
|
44
|
* @param point a {@link eu.etaxonomy.cdm.model.location.Point} object.
|
45
|
* @param style a int.
|
46
|
*/
|
47
|
public PointElement(CdmFormFactory formFactory, ICdmFormElement formElement, Point point, final int style) {
|
48
|
super(formFactory, formElement);
|
49
|
|
50
|
formFactory.addPropertyChangeListener(this);
|
51
|
|
52
|
text_latitude = formFactory.createTextWithLabelElement(formElement, "Latitude (hexagesimal)", null, style);
|
53
|
text_longitude = formFactory.createTextWithLabelElement(formElement, "Longitude (hexagesimal)", null, style);
|
54
|
number_errorRadius = formFactory.createIntegerTextWithLabelElement(formElement, "Error Radius (m)", null, style);
|
55
|
combo_referenceSystem = (ReferenceSystemComboElement) formFactory.createTermComboElement(TermComboType.REFERENCE_SYSTEM, formElement, "Reference System", null, style);
|
56
|
|
57
|
setPoint(point);
|
58
|
}
|
59
|
|
60
|
/* (non-Javadoc)
|
61
|
* @see eu.etaxonomy.taxeditor.forms.ISelectable#setSelected(boolean)
|
62
|
*/
|
63
|
/** {@inheritDoc} */
|
64
|
@Override
|
65
|
public void setSelected(boolean selected) {
|
66
|
|
67
|
}
|
68
|
|
69
|
/* (non-Javadoc)
|
70
|
* @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
|
71
|
*/
|
72
|
/** {@inheritDoc} */
|
73
|
@Override
|
74
|
public void propertyChange(PropertyChangeEvent event) {
|
75
|
if(event == null){
|
76
|
return;
|
77
|
}
|
78
|
|
79
|
Object eventSource = event.getSource();
|
80
|
if(eventSource == text_latitude){
|
81
|
try {
|
82
|
Text textField = (Text) text_latitude.getMainControl();
|
83
|
int caretPosition = textField.getCaretPosition();
|
84
|
point.setLatitudeByParsing(text_latitude.getText());
|
85
|
text_latitude.setText(point.getLatitudeSexagesimal().toString(false));
|
86
|
// textField.set
|
87
|
} catch (ParseException e) {
|
88
|
EditorUtil.error(getClass(), e);
|
89
|
}
|
90
|
}
|
91
|
else if(eventSource == text_longitude){
|
92
|
try {
|
93
|
point.setLongitudeByParsing(text_longitude.getText());
|
94
|
text_longitude.setText(point.getLongitudeSexagesimal().toString(false));
|
95
|
} catch (ParseException e) {
|
96
|
EditorUtil.error(getClass(), e);
|
97
|
}
|
98
|
}
|
99
|
else if(eventSource == number_errorRadius){
|
100
|
point.setErrorRadius(number_errorRadius.getInteger());
|
101
|
}
|
102
|
else if(eventSource == combo_referenceSystem){
|
103
|
point.setReferenceSystem(combo_referenceSystem.getSelection());
|
104
|
}
|
105
|
}
|
106
|
|
107
|
/* (non-Javadoc)
|
108
|
* @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity()
|
109
|
*/
|
110
|
/** {@inheritDoc} */
|
111
|
@Override
|
112
|
public Point getEntity() {
|
113
|
return getPoint();
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* <p>setEntity</p>
|
118
|
*
|
119
|
* @param point a {@link eu.etaxonomy.cdm.model.location.Point} object.
|
120
|
*/
|
121
|
public void setEntity(Point point){
|
122
|
setPoint(point);
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* <p>Setter for the field <code>point</code>.</p>
|
127
|
*
|
128
|
* @param point the point to set
|
129
|
*/
|
130
|
public void setPoint(Point point) {
|
131
|
this.point = point;
|
132
|
if(point != null){
|
133
|
text_latitude.setText(point.getLatitudeSexagesimal().toString(false));
|
134
|
text_longitude.setText(point.getLongitudeSexagesimal().toString(false));
|
135
|
number_errorRadius.setInteger(point.getErrorRadius());
|
136
|
combo_referenceSystem.setSelection(point.getReferenceSystem());
|
137
|
}
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* <p>Getter for the field <code>point</code>.</p>
|
142
|
*
|
143
|
* @return the point
|
144
|
*/
|
145
|
public Point getPoint() {
|
146
|
return point;
|
147
|
}
|
148
|
|
149
|
}
|