1 |
4afeb896
|
n.hoffmann
|
/**
|
2 |
a4f8f0b3
|
n.hoffmann
|
* Copyright (C) 2007 EDIT
|
3 |
865bf5e0
|
Patric Plitzner
|
* European Distributed Institute of Taxonomy
|
4 |
a4f8f0b3
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
865bf5e0
|
Patric Plitzner
|
*
|
6 |
a4f8f0b3
|
n.hoffmann
|
* 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 |
4afeb896
|
n.hoffmann
|
|
10 |
78222507
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.ui.element;
|
11 |
4afeb896
|
n.hoffmann
|
|
12 |
|
|
import java.text.ParseException;
|
13 |
|
|
|
14 |
61e07907
|
Katja Luther
|
import org.apache.commons.lang.StringUtils;
|
15 |
4afeb896
|
n.hoffmann
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
16 |
|
|
|
17 |
b9dc6bb1
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.term.TermType;
|
18 |
4afeb896
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.location.Point;
|
19 |
b9a0d300
|
l.morris
|
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
|
20 |
9a0f58cd
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
21 |
b9a0d300
|
l.morris
|
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
|
22 |
4afeb896
|
n.hoffmann
|
|
23 |
|
|
/**
|
24 |
a4f8f0b3
|
n.hoffmann
|
* <p>
|
25 |
|
|
* PointElement class.
|
26 |
|
|
* </p>
|
27 |
865bf5e0
|
Patric Plitzner
|
*
|
28 |
4afeb896
|
n.hoffmann
|
* @author n.hoffmann
|
29 |
|
|
* @created Oct 15, 2010
|
30 |
|
|
*/
|
31 |
a4f8f0b3
|
n.hoffmann
|
public class PointElement extends AbstractCdmFormElement implements
|
32 |
0c52f39c
|
n.hoffmann
|
IEntityElement<Point>, ISelectable {
|
33 |
4afeb896
|
n.hoffmann
|
|
34 |
|
|
private Point point;
|
35 |
a4f8f0b3
|
n.hoffmann
|
|
36 |
|
|
private final TextWithLabelElement text_latitude;
|
37 |
|
|
private final TextWithLabelElement text_longitude;
|
38 |
|
|
private final NumberWithLabelElement number_errorRadius;
|
39 |
b9a0d300
|
l.morris
|
private final TermComboElement<ReferenceSystem> combo_referenceSystem;
|
40 |
a4f8f0b3
|
n.hoffmann
|
|
41 |
|
|
private final TextWithLabelElement text_latitudeParsed;
|
42 |
|
|
|
43 |
|
|
private final TextWithLabelElement text_longitudeParsed;
|
44 |
|
|
|
45 |
4afeb896
|
n.hoffmann
|
/**
|
46 |
a4f8f0b3
|
n.hoffmann
|
* <p>
|
47 |
|
|
* Constructor for PointElement.
|
48 |
|
|
* </p>
|
49 |
865bf5e0
|
Patric Plitzner
|
*
|
50 |
a4f8f0b3
|
n.hoffmann
|
* @param formFactory
|
51 |
78222507
|
n.hoffmann
|
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
|
52 |
a4f8f0b3
|
n.hoffmann
|
* object.
|
53 |
|
|
* @param formElement
|
54 |
78222507
|
n.hoffmann
|
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
|
55 |
a4f8f0b3
|
n.hoffmann
|
* object.
|
56 |
|
|
* @param point
|
57 |
|
|
* a {@link eu.etaxonomy.cdm.model.location.Point} object.
|
58 |
|
|
* @param style
|
59 |
|
|
* a int.
|
60 |
4afeb896
|
n.hoffmann
|
*/
|
61 |
a4f8f0b3
|
n.hoffmann
|
public PointElement(CdmFormFactory formFactory,
|
62 |
|
|
ICdmFormElement formElement, Point point, final int style) {
|
63 |
4afeb896
|
n.hoffmann
|
super(formFactory, formElement);
|
64 |
a4f8f0b3
|
n.hoffmann
|
|
65 |
4afeb896
|
n.hoffmann
|
formFactory.addPropertyChangeListener(this);
|
66 |
a4f8f0b3
|
n.hoffmann
|
|
67 |
|
|
text_latitude = formFactory.createTextWithLabelElement(formElement,
|
68 |
865bf5e0
|
Patric Plitzner
|
"Latitude", null, style);
|
69 |
a4f8f0b3
|
n.hoffmann
|
text_latitudeParsed = formFactory.createTextWithLabelElement(
|
70 |
|
|
formElement, "", null, style);
|
71 |
|
|
text_latitudeParsed.setEnabled(false);
|
72 |
|
|
text_longitude = formFactory.createTextWithLabelElement(formElement,
|
73 |
865bf5e0
|
Patric Plitzner
|
"Longitude", null, style);
|
74 |
a4f8f0b3
|
n.hoffmann
|
text_longitudeParsed = formFactory.createTextWithLabelElement(
|
75 |
|
|
formElement, "", null, style);
|
76 |
|
|
text_longitudeParsed.setEnabled(false);
|
77 |
d2d8e95d
|
Cherian Mathew
|
number_errorRadius = formFactory.createNumberTextWithLabelElement(
|
78 |
a4f8f0b3
|
n.hoffmann
|
formElement, "Error Radius (m)", null, style);
|
79 |
ccc7ac6f
|
Patric Plitzner
|
combo_referenceSystem = formFactory.createDefinedTermComboElement(TermType.ReferenceSystem,
|
80 |
a4f8f0b3
|
n.hoffmann
|
formElement, "Reference System", null, style);
|
81 |
|
|
|
82 |
4afeb896
|
n.hoffmann
|
setPoint(point);
|
83 |
|
|
}
|
84 |
|
|
|
85 |
a4f8f0b3
|
n.hoffmann
|
/*
|
86 |
|
|
* (non-Javadoc)
|
87 |
865bf5e0
|
Patric Plitzner
|
*
|
88 |
a4f8f0b3
|
n.hoffmann
|
* @see
|
89 |
|
|
* eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
|
90 |
|
|
* .eclipse.jface.util.PropertyChangeEvent)
|
91 |
4afeb896
|
n.hoffmann
|
*/
|
92 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
93 |
4afeb896
|
n.hoffmann
|
@Override
|
94 |
|
|
public void propertyChange(PropertyChangeEvent event) {
|
95 |
a4f8f0b3
|
n.hoffmann
|
if (event == null) {
|
96 |
4afeb896
|
n.hoffmann
|
return;
|
97 |
|
|
}
|
98 |
a4f8f0b3
|
n.hoffmann
|
|
99 |
9a0f58cd
|
n.hoffmann
|
boolean propagate = false;
|
100 |
a4f8f0b3
|
n.hoffmann
|
|
101 |
4afeb896
|
n.hoffmann
|
Object eventSource = event.getSource();
|
102 |
a4f8f0b3
|
n.hoffmann
|
if (eventSource == text_latitude) {
|
103 |
4afeb896
|
n.hoffmann
|
try {
|
104 |
61e07907
|
Katja Luther
|
if (StringUtils.isBlank(text_latitude.getText())){
|
105 |
|
|
getPoint().setLatitudeByParsing(null);
|
106 |
|
|
text_latitudeParsed.setText(null);
|
107 |
|
|
text_latitude
|
108 |
|
|
.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
|
109 |
|
|
}else{
|
110 |
|
|
getPoint().setLatitudeByParsing(text_latitude.getText());
|
111 |
|
|
text_latitudeParsed.setText(point.getLatitudeSexagesimal()
|
112 |
|
|
.toString(false));
|
113 |
|
|
text_latitude
|
114 |
|
|
.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
|
115 |
|
|
}
|
116 |
9a0f58cd
|
n.hoffmann
|
propagate = true;
|
117 |
4afeb896
|
n.hoffmann
|
} catch (ParseException e) {
|
118 |
a4f8f0b3
|
n.hoffmann
|
text_latitude
|
119 |
|
|
.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
|
120 |
4afeb896
|
n.hoffmann
|
}
|
121 |
a4f8f0b3
|
n.hoffmann
|
} else if (eventSource == text_longitude) {
|
122 |
4afeb896
|
n.hoffmann
|
try {
|
123 |
61e07907
|
Katja Luther
|
if (StringUtils.isBlank(text_longitude.getText())){
|
124 |
|
|
getPoint().setLongitudeByParsing(null);
|
125 |
|
|
text_longitudeParsed.setText(null);
|
126 |
|
|
text_longitude
|
127 |
|
|
.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
|
128 |
|
|
}else{
|
129 |
|
|
getPoint().setLongitudeByParsing(text_longitude.getText());
|
130 |
|
|
text_longitudeParsed.setText(point.getLongitudeSexagesimal()
|
131 |
|
|
.toString(false));
|
132 |
|
|
text_longitude
|
133 |
|
|
.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
|
134 |
|
|
}
|
135 |
9a0f58cd
|
n.hoffmann
|
propagate = true;
|
136 |
4afeb896
|
n.hoffmann
|
} catch (ParseException e) {
|
137 |
a4f8f0b3
|
n.hoffmann
|
text_longitude
|
138 |
|
|
.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
|
139 |
4afeb896
|
n.hoffmann
|
}
|
140 |
a4f8f0b3
|
n.hoffmann
|
} else if (eventSource == number_errorRadius) {
|
141 |
9a0f58cd
|
n.hoffmann
|
getPoint().setErrorRadius(number_errorRadius.getInteger());
|
142 |
|
|
propagate = true;
|
143 |
a4f8f0b3
|
n.hoffmann
|
} else if (eventSource == combo_referenceSystem) {
|
144 |
9a0f58cd
|
n.hoffmann
|
getPoint().setReferenceSystem(combo_referenceSystem.getSelection());
|
145 |
|
|
propagate = true;
|
146 |
a4f8f0b3
|
n.hoffmann
|
}
|
147 |
|
|
|
148 |
|
|
if (propagate) {
|
149 |
9a0f58cd
|
n.hoffmann
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
|
150 |
|
|
}
|
151 |
4afeb896
|
n.hoffmann
|
}
|
152 |
|
|
|
153 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
154 |
4afeb896
|
n.hoffmann
|
@Override
|
155 |
|
|
public Point getEntity() {
|
156 |
|
|
return getPoint();
|
157 |
|
|
}
|
158 |
|
|
|
159 |
3be6ef3e
|
n.hoffmann
|
/**
|
160 |
a4f8f0b3
|
n.hoffmann
|
* <p>
|
161 |
|
|
* setEntity
|
162 |
|
|
* </p>
|
163 |
865bf5e0
|
Patric Plitzner
|
*
|
164 |
a4f8f0b3
|
n.hoffmann
|
* @param point
|
165 |
|
|
* a {@link eu.etaxonomy.cdm.model.location.Point} object.
|
166 |
3be6ef3e
|
n.hoffmann
|
*/
|
167 |
a4f8f0b3
|
n.hoffmann
|
public void setEntity(Point point) {
|
168 |
4afeb896
|
n.hoffmann
|
setPoint(point);
|
169 |
|
|
}
|
170 |
a4f8f0b3
|
n.hoffmann
|
|
171 |
4afeb896
|
n.hoffmann
|
/**
|
172 |
a4f8f0b3
|
n.hoffmann
|
* <p>
|
173 |
|
|
* Setter for the field <code>point</code>.
|
174 |
|
|
* </p>
|
175 |
865bf5e0
|
Patric Plitzner
|
*
|
176 |
a4f8f0b3
|
n.hoffmann
|
* @param point
|
177 |
|
|
* the point to set
|
178 |
4afeb896
|
n.hoffmann
|
*/
|
179 |
|
|
public void setPoint(Point point) {
|
180 |
|
|
this.point = point;
|
181 |
a4f8f0b3
|
n.hoffmann
|
if (point != null) {
|
182 |
|
|
String latitude = point.getLatitudeSexagesimal() == null ? ""
|
183 |
|
|
: point.getLatitudeSexagesimal().toString(false);
|
184 |
|
|
String longitude = point.getLongitudeSexagesimal() == null ? ""
|
185 |
|
|
: point.getLongitudeSexagesimal().toString(false);
|
186 |
|
|
text_latitude.setText(latitude);
|
187 |
|
|
text_latitudeParsed.setText(latitude);
|
188 |
|
|
text_longitude.setText(longitude);
|
189 |
|
|
text_longitudeParsed.setText(longitude);
|
190 |
d2d8e95d
|
Cherian Mathew
|
number_errorRadius.setNumber(point.getErrorRadius());
|
191 |
1d9ed6ce
|
n.hoffmann
|
combo_referenceSystem.setSelection(point.getReferenceSystem());
|
192 |
|
|
}
|
193 |
4afeb896
|
n.hoffmann
|
}
|
194 |
|
|
|
195 |
|
|
/**
|
196 |
a4f8f0b3
|
n.hoffmann
|
* <p>
|
197 |
|
|
* Getter for the field <code>point</code>.
|
198 |
|
|
* </p>
|
199 |
865bf5e0
|
Patric Plitzner
|
*
|
200 |
4afeb896
|
n.hoffmann
|
* @return the point
|
201 |
|
|
*/
|
202 |
|
|
public Point getPoint() {
|
203 |
a4f8f0b3
|
n.hoffmann
|
if (point == null) {
|
204 |
9a0f58cd
|
n.hoffmann
|
point = Point.NewInstance();
|
205 |
|
|
}
|
206 |
a4f8f0b3
|
n.hoffmann
|
|
207 |
4afeb896
|
n.hoffmann
|
return point;
|
208 |
|
|
}
|
209 |
|
|
|
210 |
865bf5e0
|
Patric Plitzner
|
@Override
|
211 |
|
|
public void setSelected(boolean selected) {
|
212 |
0c52f39c
|
n.hoffmann
|
setBackground(selected ? SELECTED : getPersistentBackground());
|
213 |
|
|
}
|
214 |
865bf5e0
|
Patric Plitzner
|
|
215 |
4afeb896
|
n.hoffmann
|
}
|