2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * 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.
10 package eu
.etaxonomy
.taxeditor
.ui
.element
;
12 import java
.text
.ParseException
;
14 import org
.apache
.commons
.lang
.StringUtils
;
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 if (StringUtils
.isBlank(text_latitude
.getText())){
106 getPoint().setLatitudeByParsing(null);
107 text_latitudeParsed
.setText(null);
109 .setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
111 getPoint().setLatitudeByParsing(text_latitude
.getText());
112 text_latitudeParsed
.setText(point
.getLatitudeSexagesimal()
115 .setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
118 } catch (ParseException e
) {
120 .setBackground(getColor(Resources
.COLOR_PARSE_ERROR
));
122 } else if (eventSource
== text_longitude
) {
124 if (StringUtils
.isBlank(text_longitude
.getText())){
125 getPoint().setLongitudeByParsing(null);
126 text_longitudeParsed
.setText(null);
128 .setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
130 getPoint().setLongitudeByParsing(text_longitude
.getText());
131 text_longitudeParsed
.setText(point
.getLongitudeSexagesimal()
134 .setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
137 } catch (ParseException e
) {
139 .setBackground(getColor(Resources
.COLOR_PARSE_ERROR
));
141 } else if (eventSource
== number_errorRadius
) {
142 getPoint().setErrorRadius(number_errorRadius
.getInteger());
144 } else if (eventSource
== combo_referenceSystem
) {
145 getPoint().setReferenceSystem(combo_referenceSystem
.getSelection());
150 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event
));
157 * @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity()
161 public Point
getEntity() {
171 * a {@link eu.etaxonomy.cdm.model.location.Point} object.
173 public void setEntity(Point point
) {
179 * Setter for the field <code>point</code>.
185 public void setPoint(Point point
) {
188 String latitude
= point
.getLatitudeSexagesimal() == null ?
""
189 : point
.getLatitudeSexagesimal().toString(false);
190 String longitude
= point
.getLongitudeSexagesimal() == null ?
""
191 : point
.getLongitudeSexagesimal().toString(false);
192 text_latitude
.setText(latitude
);
193 text_latitudeParsed
.setText(latitude
);
194 text_longitude
.setText(longitude
);
195 text_longitudeParsed
.setText(longitude
);
196 number_errorRadius
.setNumber(point
.getErrorRadius());
197 combo_referenceSystem
.setSelection(point
.getReferenceSystem());
203 * Getter for the field <code>point</code>.
208 public Point
getPoint() {
210 point
= Point
.NewInstance();
217 public void setSelected(boolean selected
) {
218 setBackground(selected ? SELECTED
: getPersistentBackground());