Fixed a missing addControl() method call in TimePeriod element. Reverting half done...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / forms / PointElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.ui.forms;
12
13 import java.text.ParseException;
14
15 import org.eclipse.jface.util.PropertyChangeEvent;
16
17 import eu.etaxonomy.cdm.model.location.Point;
18 import eu.etaxonomy.taxeditor.preference.Resources;
19 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType;
20 import eu.etaxonomy.taxeditor.ui.term.ReferenceSystemComboElement;
21
22 /**
23 * <p>PointElement class.</p>
24 *
25 * @author n.hoffmann
26 * @created Oct 15, 2010
27 * @version 1.0
28 */
29 public class PointElement extends AbstractCdmFormElement implements IEntityElement<Point>{
30
31 private Point point;
32
33 private ReferenceSystemComboElement combo_referenceSystem;
34 private TextWithLabelElement text_latitude;
35 private TextWithLabelElement text_longitude;
36 private NumberWithLabelElement number_errorRadius;
37
38 /**
39 * <p>Constructor for PointElement.</p>
40 *
41 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
42 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
43 * @param point a {@link eu.etaxonomy.cdm.model.location.Point} object.
44 * @param style a int.
45 */
46 public PointElement(CdmFormFactory formFactory, ICdmFormElement formElement, Point point, final int style) {
47 super(formFactory, formElement);
48
49 formFactory.addPropertyChangeListener(this);
50
51 text_latitude = formFactory.createTextWithLabelElement(formElement, "Latitude (hexagesimal)", null, style);
52 text_longitude = formFactory.createTextWithLabelElement(formElement, "Longitude (hexagesimal)", null, style);
53 number_errorRadius = formFactory.createIntegerTextWithLabelElement(formElement, "Error Radius (m)", null, style);
54 combo_referenceSystem = (ReferenceSystemComboElement) formFactory.createTermComboElement(TermComboType.REFERENCE_SYSTEM, formElement, "Reference System", null, style);
55
56 setPoint(point);
57 }
58
59 /* (non-Javadoc)
60 * @see eu.etaxonomy.taxeditor.forms.ISelectable#setSelected(boolean)
61 */
62 /** {@inheritDoc} */
63 @Override
64 public void setSelected(boolean selected) {
65
66 }
67
68 /* (non-Javadoc)
69 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
70 */
71 /** {@inheritDoc} */
72 @Override
73 public void propertyChange(PropertyChangeEvent event) {
74 if(event == null){
75 return;
76 }
77
78 boolean propagate = false;
79
80 Object eventSource = event.getSource();
81 if(eventSource == text_latitude){
82 try {
83 getPoint().setLatitudeByParsing(text_latitude.getText());
84 text_latitude.setText(point.getLatitudeSexagesimal().toString(false));
85 text_latitude.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
86 propagate = true;
87 } catch (ParseException e) {
88 text_latitude.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
89 }
90 }
91 else if(eventSource == text_longitude){
92 try {
93 getPoint().setLongitudeByParsing(text_longitude.getText());
94 text_longitude.setText(point.getLongitudeSexagesimal().toString(false));
95 text_longitude.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
96 propagate = true;
97 } catch (ParseException e) {
98 text_latitude.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
99 }
100 }
101 else if(eventSource == number_errorRadius){
102 getPoint().setErrorRadius(number_errorRadius.getInteger());
103 propagate = true;
104 }
105 else if(eventSource == combo_referenceSystem){
106 getPoint().setReferenceSystem(combo_referenceSystem.getSelection());
107 propagate = true;
108 }
109
110 if(propagate){
111 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
112 }
113 }
114
115 /* (non-Javadoc)
116 * @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity()
117 */
118 /** {@inheritDoc} */
119 @Override
120 public Point getEntity() {
121 return getPoint();
122 }
123
124 /**
125 * <p>setEntity</p>
126 *
127 * @param point a {@link eu.etaxonomy.cdm.model.location.Point} object.
128 */
129 public void setEntity(Point point){
130 setPoint(point);
131 }
132
133 /**
134 * <p>Setter for the field <code>point</code>.</p>
135 *
136 * @param point the point to set
137 */
138 public void setPoint(Point point) {
139 this.point = point;
140 if(point != null){
141 text_latitude.setText(point.getLatitudeSexagesimal() == null ? "" : point.getLatitudeSexagesimal().toString(false));
142 text_longitude.setText(point.getLongitudeSexagesimal() == null ? "" : point.getLongitudeSexagesimal().toString(false));
143 number_errorRadius.setInteger(point.getErrorRadius());
144 combo_referenceSystem.setSelection(point.getReferenceSystem());
145 }
146 }
147
148 /**
149 * <p>Getter for the field <code>point</code>.</p>
150 *
151 * @return the point
152 */
153 public Point getPoint() {
154 if(point == null){
155 point = Point.NewInstance();
156 }
157
158 return point;
159 }
160
161 }