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
.common
.TermType
;
18 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
19 import eu
.etaxonomy
.cdm
.model
.location
.ReferenceSystem
;
20 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
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
.createDefinedTermComboElement(TermType
.ReferenceSystem
,
81 formElement
, "Reference System", null, style
);
90 * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
91 * .eclipse.jface.util.PropertyChangeEvent)
95 public void propertyChange(PropertyChangeEvent event
) {
100 boolean propagate
= false;
102 Object eventSource
= event
.getSource();
103 if (eventSource
== text_latitude
) {
105 getPoint().setLatitudeByParsing(text_latitude
.getText());
106 text_latitudeParsed
.setText(point
.getLatitudeSexagesimal()
109 .setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
111 } catch (ParseException e
) {
113 .setBackground(getColor(Resources
.COLOR_PARSE_ERROR
));
115 } else if (eventSource
== text_longitude
) {
117 getPoint().setLongitudeByParsing(text_longitude
.getText());
118 text_longitudeParsed
.setText(point
.getLongitudeSexagesimal()
121 .setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
123 } catch (ParseException e
) {
125 .setBackground(getColor(Resources
.COLOR_PARSE_ERROR
));
127 } else if (eventSource
== number_errorRadius
) {
128 getPoint().setErrorRadius(number_errorRadius
.getInteger());
130 } else if (eventSource
== combo_referenceSystem
) {
131 getPoint().setReferenceSystem(combo_referenceSystem
.getSelection());
136 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event
));
143 * @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity()
147 public Point
getEntity() {
157 * a {@link eu.etaxonomy.cdm.model.location.Point} object.
159 public void setEntity(Point point
) {
165 * Setter for the field <code>point</code>.
171 public void setPoint(Point point
) {
174 String latitude
= point
.getLatitudeSexagesimal() == null ?
""
175 : point
.getLatitudeSexagesimal().toString(false);
176 String longitude
= point
.getLongitudeSexagesimal() == null ?
""
177 : point
.getLongitudeSexagesimal().toString(false);
178 text_latitude
.setText(latitude
);
179 text_latitudeParsed
.setText(latitude
);
180 text_longitude
.setText(longitude
);
181 text_longitudeParsed
.setText(longitude
);
182 number_errorRadius
.setNumber(point
.getErrorRadius());
183 combo_referenceSystem
.setSelection(point
.getReferenceSystem());
189 * Getter for the field <code>point</code>.
194 public Point
getPoint() {
196 point
= Point
.NewInstance();
203 public void setSelected(boolean selected
) {
204 setBackground(selected ? SELECTED
: getPersistentBackground());