1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2013 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
|
package eu.etaxonomy.taxeditor.ui.campanula.basicFields;
|
11
|
|
12
|
import java.text.ParseException;
|
13
|
|
14
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.location.Point;
|
17
|
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
|
18
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
19
|
import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
|
20
|
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
|
24
|
|
25
|
/**
|
26
|
* @author pplitzner
|
27
|
* @date 15.08.2013
|
28
|
*
|
29
|
*/
|
30
|
public class PointFieldController extends AbstractCdmFormElement implements IEntityElement<Point> {
|
31
|
|
32
|
private Point point;
|
33
|
|
34
|
private final TextFieldController text_latitude;
|
35
|
private final TextFieldController text_longitude;
|
36
|
private final NumberFieldController number_errorRadius;
|
37
|
private final TermComboFieldController<ReferenceSystem> combo_referenceSystem;
|
38
|
|
39
|
private final TextFieldController text_latitudeParsed;
|
40
|
|
41
|
private final TextFieldController text_longitudeParsed;
|
42
|
|
43
|
/**
|
44
|
* <p>
|
45
|
* Constructor for PointElement.
|
46
|
* </p>
|
47
|
*
|
48
|
* @param formFactory
|
49
|
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
|
50
|
* object.
|
51
|
* @param formElement
|
52
|
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
|
53
|
* object.
|
54
|
* @param point
|
55
|
* a {@link eu.etaxonomy.cdm.model.location.Point} object.
|
56
|
* @param style
|
57
|
* a int.
|
58
|
*/
|
59
|
public PointFieldController(PointField pointField, CdmFormFactory formFactory, ICdmFormElement formElement, Point point, final int style) {
|
60
|
super(formFactory, formElement);
|
61
|
|
62
|
setPropertyChangeListeners(formFactory.getPropertyChangeListeners());
|
63
|
formFactory.addPropertyChangeListener(this);
|
64
|
|
65
|
text_latitude = new TextFieldController(pointField.getText_latitude(), getFormFactory(), formElement, null, style);
|
66
|
text_latitudeParsed = new TextFieldController(pointField.getText_latitudeParsed(), getFormFactory(), formElement, null, style);
|
67
|
text_longitude = new TextFieldController(pointField.getText_longitude(), getFormFactory(), formElement, null, style);
|
68
|
text_longitudeParsed = new TextFieldController(pointField.getText_longitudeParsed(), getFormFactory(), formElement, null, style);
|
69
|
number_errorRadius = new NumberFieldController(pointField.getNumber_errorRadius(), getFormFactory(), formElement, (Integer)null);
|
70
|
combo_referenceSystem = new TermComboFieldController<ReferenceSystem>(pointField.getCombo_referenceSystem(), getFormFactory(), formElement, ReferenceSystem.class, null, style);
|
71
|
|
72
|
setPoint(point);
|
73
|
}
|
74
|
|
75
|
/*
|
76
|
* (non-Javadoc)
|
77
|
*
|
78
|
* @see
|
79
|
* eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
|
80
|
* .eclipse.jface.util.PropertyChangeEvent)
|
81
|
*/
|
82
|
/** {@inheritDoc} */
|
83
|
@Override
|
84
|
public void propertyChange(PropertyChangeEvent event) {
|
85
|
if (event == null) {
|
86
|
return;
|
87
|
}
|
88
|
|
89
|
boolean propagate = false;
|
90
|
|
91
|
Object eventSource = event.getSource();
|
92
|
if (eventSource == text_latitude) {
|
93
|
try {
|
94
|
getPoint().setLatitudeByParsing(text_latitude.getText());
|
95
|
text_latitudeParsed.setText(point.getLatitudeSexagesimal().toString(false));
|
96
|
text_latitude.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
|
97
|
propagate = true;
|
98
|
} catch (ParseException e) {
|
99
|
text_latitude.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
|
100
|
}
|
101
|
} else if (eventSource == text_longitude) {
|
102
|
try {
|
103
|
getPoint().setLongitudeByParsing(text_longitude.getText());
|
104
|
text_longitudeParsed.setText(point.getLongitudeSexagesimal().toString(false));
|
105
|
text_longitude.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
|
106
|
propagate = true;
|
107
|
} catch (ParseException e) {
|
108
|
text_longitude.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
|
109
|
}
|
110
|
} else if (eventSource == number_errorRadius) {
|
111
|
getPoint().setErrorRadius(number_errorRadius.getInteger());
|
112
|
propagate = true;
|
113
|
} else if (eventSource == combo_referenceSystem) {
|
114
|
getPoint().setReferenceSystem(combo_referenceSystem.getSelection());
|
115
|
propagate = true;
|
116
|
}
|
117
|
|
118
|
if (propagate) {
|
119
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
|
120
|
}
|
121
|
}
|
122
|
|
123
|
/*
|
124
|
* (non-Javadoc)
|
125
|
*
|
126
|
* @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity()
|
127
|
*/
|
128
|
/** {@inheritDoc} */
|
129
|
@Override
|
130
|
public Point getEntity() {
|
131
|
return getPoint();
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* <p>
|
136
|
* setEntity
|
137
|
* </p>
|
138
|
*
|
139
|
* @param point
|
140
|
* a {@link eu.etaxonomy.cdm.model.location.Point} object.
|
141
|
*/
|
142
|
public void setEntity(Point point) {
|
143
|
setPoint(point);
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* <p>
|
148
|
* Setter for the field <code>point</code>.
|
149
|
* </p>
|
150
|
*
|
151
|
* @param point
|
152
|
* the point to set
|
153
|
*/
|
154
|
public void setPoint(Point point) {
|
155
|
this.point = point;
|
156
|
if (point != null) {
|
157
|
String latitude = point.getLatitudeSexagesimal() == null ? "" : point.getLatitudeSexagesimal().toString(false);
|
158
|
String longitude = point.getLongitudeSexagesimal() == null ? "" : point.getLongitudeSexagesimal().toString(false);
|
159
|
text_latitude.setText(latitude);
|
160
|
text_latitudeParsed.setText(latitude);
|
161
|
text_longitude.setText(longitude);
|
162
|
text_longitudeParsed.setText(longitude);
|
163
|
number_errorRadius.setInteger(point.getErrorRadius());
|
164
|
combo_referenceSystem.setSelection(point.getReferenceSystem());
|
165
|
}
|
166
|
}
|
167
|
|
168
|
/**
|
169
|
* <p>
|
170
|
* Getter for the field <code>point</code>.
|
171
|
* </p>
|
172
|
*
|
173
|
* @return the point
|
174
|
*/
|
175
|
public Point getPoint() {
|
176
|
if (point == null) {
|
177
|
point = Point.NewInstance();
|
178
|
}
|
179
|
|
180
|
return point;
|
181
|
}
|
182
|
|
183
|
@Override
|
184
|
public void setSelected(boolean selected) {
|
185
|
setBackground(selected ? SELECTED : getPersistentBackground());
|
186
|
}
|
187
|
}
|