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
31 public class PointElement
extends AbstractCdmFormElement
implements
32 IEntityElement
<Point
>, ISelectable
{
36 private final TextWithLabelElement text_latitude
;
37 private final TextWithLabelElement text_longitude
;
38 private final NumberWithLabelElement number_errorRadius
;
39 private final TermComboElement
<ReferenceSystem
> combo_referenceSystem
;
41 private final TextWithLabelElement text_latitudeParsed
;
43 private final TextWithLabelElement text_longitudeParsed
;
47 * Constructor for PointElement.
51 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
54 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
57 * a {@link eu.etaxonomy.cdm.model.location.Point} object.
61 public PointElement(CdmFormFactory formFactory
,
62 ICdmFormElement formElement
, Point point
, final int style
) {
63 super(formFactory
, formElement
);
65 formFactory
.addPropertyChangeListener(this);
67 text_latitude
= formFactory
.createTextWithLabelElement(formElement
,
68 "Latitude", null, style
);
69 text_latitudeParsed
= formFactory
.createTextWithLabelElement(
70 formElement
, "", null, style
);
71 text_latitudeParsed
.setEnabled(false);
72 text_longitude
= formFactory
.createTextWithLabelElement(formElement
,
73 "Longitude", null, style
);
74 text_longitudeParsed
= formFactory
.createTextWithLabelElement(
75 formElement
, "", null, style
);
76 text_longitudeParsed
.setEnabled(false);
77 number_errorRadius
= formFactory
.createNumberTextWithLabelElement(
78 formElement
, "Error Radius (m)", null, style
);
79 combo_referenceSystem
= formFactory
.createDefinedTermComboElement(TermType
.ReferenceSystem
,
80 formElement
, "Reference System", null, style
);
89 * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
90 * .eclipse.jface.util.PropertyChangeEvent)
94 public void propertyChange(PropertyChangeEvent event
) {
99 boolean propagate
= false;
101 Object eventSource
= event
.getSource();
102 if (eventSource
== text_latitude
) {
104 if (StringUtils
.isBlank(text_latitude
.getText())){
105 getPoint().setLatitudeByParsing(null);
106 text_latitudeParsed
.setText(null);
108 .setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
110 getPoint().setLatitudeByParsing(text_latitude
.getText());
111 text_latitudeParsed
.setText(point
.getLatitudeSexagesimal()
114 .setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
117 } catch (ParseException e
) {
119 .setBackground(getColor(Resources
.COLOR_PARSE_ERROR
));
121 } else if (eventSource
== text_longitude
) {
123 if (StringUtils
.isBlank(text_longitude
.getText())){
124 getPoint().setLongitudeByParsing(null);
125 text_longitudeParsed
.setText(null);
127 .setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
129 getPoint().setLongitudeByParsing(text_longitude
.getText());
130 text_longitudeParsed
.setText(point
.getLongitudeSexagesimal()
133 .setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
136 } catch (ParseException e
) {
138 .setBackground(getColor(Resources
.COLOR_PARSE_ERROR
));
140 } else if (eventSource
== number_errorRadius
) {
141 getPoint().setErrorRadius(number_errorRadius
.getInteger());
143 } else if (eventSource
== combo_referenceSystem
) {
144 getPoint().setReferenceSystem(combo_referenceSystem
.getSelection());
149 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event
));
155 public Point
getEntity() {
165 * a {@link eu.etaxonomy.cdm.model.location.Point} object.
167 public void setEntity(Point point
) {
173 * Setter for the field <code>point</code>.
179 public void setPoint(Point point
) {
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 number_errorRadius
.setNumber(point
.getErrorRadius());
191 combo_referenceSystem
.setSelection(point
.getReferenceSystem());
197 * Getter for the field <code>point</code>.
202 public Point
getPoint() {
204 point
= Point
.NewInstance();
211 public void setSelected(boolean selected
) {
212 setBackground(selected ? SELECTED
: getPersistentBackground());