3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.element
;
13 import java
.text
.ParseException
;
15 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
17 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
18 import eu
.etaxonomy
.cdm
.model
.location
.ReferenceSystem
;
19 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
20 import eu
.etaxonomy
.taxeditor
.ui
.campanula
.compatibility
.ICdmFormElement
;
21 import eu
.etaxonomy
.taxeditor
.ui
.combo
.TermComboElement
;
29 * @created Oct 15, 2010
32 public class PointElement
extends AbstractCdmFormElement
implements
33 IEntityElement
<Point
>, ISelectable
{
37 private final TextWithLabelElement text_latitude
;
38 private final TextWithLabelElement text_longitude
;
39 private final NumberWithLabelElement number_errorRadius
;
40 private final TermComboElement
<ReferenceSystem
> combo_referenceSystem
;
42 private final TextWithLabelElement text_latitudeParsed
;
44 private final TextWithLabelElement text_longitudeParsed
;
48 * Constructor for PointElement.
52 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
55 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
58 * a {@link eu.etaxonomy.cdm.model.location.Point} object.
62 public PointElement(CdmFormFactory formFactory
,
63 ICdmFormElement formElement
, Point point
, final int style
) {
64 super(formFactory
, formElement
);
66 formFactory
.addPropertyChangeListener(this);
68 text_latitude
= formFactory
.createTextWithLabelElement(formElement
,
69 "Latitude", null, style
);
70 text_latitudeParsed
= formFactory
.createTextWithLabelElement(
71 formElement
, "", null, style
);
72 text_latitudeParsed
.setEnabled(false);
73 text_longitude
= formFactory
.createTextWithLabelElement(formElement
,
74 "Longitude", null, style
);
75 text_longitudeParsed
= formFactory
.createTextWithLabelElement(
76 formElement
, "", null, style
);
77 text_longitudeParsed
.setEnabled(false);
78 number_errorRadius
= formFactory
.createNumberTextWithLabelElement(
79 formElement
, "Error Radius (m)", null, style
);
80 combo_referenceSystem
= formFactory
81 .createTermComboElement(ReferenceSystem
.class,
82 formElement
, "Reference System", null, style
);
91 * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
92 * .eclipse.jface.util.PropertyChangeEvent)
96 public void propertyChange(PropertyChangeEvent event
) {
101 boolean propagate
= false;
103 Object eventSource
= event
.getSource();
104 if (eventSource
== text_latitude
) {
106 getPoint().setLatitudeByParsing(text_latitude
.getText());
107 text_latitudeParsed
.setText(point
.getLatitudeSexagesimal()
110 .setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
112 } catch (ParseException e
) {
114 .setBackground(getColor(Resources
.COLOR_PARSE_ERROR
));
116 } else if (eventSource
== text_longitude
) {
118 getPoint().setLongitudeByParsing(text_longitude
.getText());
119 text_longitudeParsed
.setText(point
.getLongitudeSexagesimal()
122 .setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
124 } catch (ParseException e
) {
126 .setBackground(getColor(Resources
.COLOR_PARSE_ERROR
));
128 } else if (eventSource
== number_errorRadius
) {
129 getPoint().setErrorRadius(number_errorRadius
.getInteger());
131 } else if (eventSource
== combo_referenceSystem
) {
132 getPoint().setReferenceSystem(combo_referenceSystem
.getSelection());
137 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event
));
144 * @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity()
148 public Point
getEntity() {
158 * a {@link eu.etaxonomy.cdm.model.location.Point} object.
160 public void setEntity(Point point
) {
166 * Setter for the field <code>point</code>.
172 public void setPoint(Point point
) {
175 String latitude
= point
.getLatitudeSexagesimal() == null ?
""
176 : point
.getLatitudeSexagesimal().toString(false);
177 String longitude
= point
.getLongitudeSexagesimal() == null ?
""
178 : point
.getLongitudeSexagesimal().toString(false);
179 text_latitude
.setText(latitude
);
180 text_latitudeParsed
.setText(latitude
);
181 text_longitude
.setText(longitude
);
182 text_longitudeParsed
.setText(longitude
);
183 number_errorRadius
.setNumber(point
.getErrorRadius());
184 combo_referenceSystem
.setSelection(point
.getReferenceSystem());
190 * Getter for the field <code>point</code>.
195 public Point
getPoint() {
197 point
= Point
.NewInstance();
204 public void setSelected(boolean selected
) {
205 setBackground(selected ? SELECTED
: getPersistentBackground());