Project

General

Profile

Download (5.85 KB) Statistics
| Branch: | Tag: | Revision:
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.singlesource.ui.forms.NumberWithLabelElementFacade;
20
import eu.etaxonomy.taxeditor.singlesource.ui.forms.TextWithLabelElementFacade;
21
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType;
22
import eu.etaxonomy.taxeditor.ui.term.ReferenceSystemComboElement;
23

    
24
/**
25
 * <p>
26
 * PointElement class.
27
 * </p>
28
 * 
29
 * @author n.hoffmann
30
 * @created Oct 15, 2010
31
 * @version 1.0
32
 */
33
public class PointElement extends AbstractCdmFormElement implements
34
		IEntityElement<Point> {
35

    
36
	private Point point;
37

    
38
	private final TextWithLabelElementFacade text_latitude;
39
	private final TextWithLabelElementFacade text_longitude;
40
	private final NumberWithLabelElementFacade number_errorRadius;
41
	private final ReferenceSystemComboElement combo_referenceSystem;
42

    
43
	private final TextWithLabelElementFacade text_latitudeParsed;
44

    
45
	private final TextWithLabelElementFacade text_longitudeParsed;
46

    
47
	/**
48
	 * <p>
49
	 * Constructor for PointElement.
50
	 * </p>
51
	 * 
52
	 * @param formFactory
53
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
54
	 *            object.
55
	 * @param formElement
56
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
57
	 *            object.
58
	 * @param point
59
	 *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
60
	 * @param style
61
	 *            a int.
62
	 */
63
	public PointElement(CdmFormFactory formFactory,
64
			ICdmFormElement formElement, Point point, final int style) {
65
		super(formFactory, formElement);
66

    
67
		formFactory.addPropertyChangeListener(this);
68

    
69
		text_latitude = formFactory.createTextWithLabelElement(formElement,
70
				"Latitude (hexagesimal)", null, style);
71
		text_latitudeParsed = formFactory.createTextWithLabelElement(
72
				formElement, "", null, style);
73
		text_latitudeParsed.setEnabled(false);
74
		text_longitude = formFactory.createTextWithLabelElement(formElement,
75
				"Longitude (hexagesimal)", null, style);
76
		text_longitudeParsed = formFactory.createTextWithLabelElement(
77
				formElement, "", null, style);
78
		text_longitudeParsed.setEnabled(false);
79
		number_errorRadius = formFactory.createIntegerTextWithLabelElement(
80
				formElement, "Error Radius (m)", null, style);
81
		combo_referenceSystem = (ReferenceSystemComboElement) formFactory
82
				.createTermComboElement(TermComboType.REFERENCE_SYSTEM,
83
						formElement, "Reference System", null, style);
84

    
85
		setPoint(point);
86
	}
87

    
88
	/*
89
	 * (non-Javadoc)
90
	 * 
91
	 * @see eu.etaxonomy.taxeditor.forms.ISelectable#setSelected(boolean)
92
	 */
93
	/** {@inheritDoc} */
94
	@Override
95
	public void setSelected(boolean selected) {
96

    
97
	}
98

    
99
	/*
100
	 * (non-Javadoc)
101
	 * 
102
	 * @see
103
	 * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
104
	 * .eclipse.jface.util.PropertyChangeEvent)
105
	 */
106
	/** {@inheritDoc} */
107
	@Override
108
	public void propertyChange(PropertyChangeEvent event) {
109
		if (event == null) {
110
			return;
111
		}
112

    
113
		boolean propagate = false;
114

    
115
		Object eventSource = event.getSource();
116
		if (eventSource == text_latitude) {
117
			try {
118
				getPoint().setLatitudeByParsing(text_latitude.getText());
119
				text_latitudeParsed.setText(point.getLatitudeSexagesimal()
120
						.toString(false));
121
				text_latitude
122
						.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
123
				propagate = true;
124
			} catch (ParseException e) {
125
				text_latitude
126
						.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
127
			}
128
		} else if (eventSource == text_longitude) {
129
			try {
130
				getPoint().setLongitudeByParsing(text_longitude.getText());
131
				text_longitudeParsed.setText(point.getLongitudeSexagesimal()
132
						.toString(false));
133
				text_longitude
134
						.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
135
				propagate = true;
136
			} catch (ParseException e) {
137
				text_longitude
138
						.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
139
			}
140
		} else if (eventSource == number_errorRadius) {
141
			getPoint().setErrorRadius(number_errorRadius.getInteger());
142
			propagate = true;
143
		} else if (eventSource == combo_referenceSystem) {
144
			getPoint().setReferenceSystem(combo_referenceSystem.getSelection());
145
			propagate = true;
146
		}
147

    
148
		if (propagate) {
149
			firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
150
		}
151
	}
152

    
153
	/*
154
	 * (non-Javadoc)
155
	 * 
156
	 * @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity()
157
	 */
158
	/** {@inheritDoc} */
159
	@Override
160
	public Point getEntity() {
161
		return getPoint();
162
	}
163

    
164
	/**
165
	 * <p>
166
	 * setEntity
167
	 * </p>
168
	 * 
169
	 * @param point
170
	 *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
171
	 */
172
	public void setEntity(Point point) {
173
		setPoint(point);
174
	}
175

    
176
	/**
177
	 * <p>
178
	 * Setter for the field <code>point</code>.
179
	 * </p>
180
	 * 
181
	 * @param point
182
	 *            the point to set
183
	 */
184
	public void setPoint(Point point) {
185
		this.point = point;
186
		if (point != null) {
187
			String latitude = point.getLatitudeSexagesimal() == null ? ""
188
					: point.getLatitudeSexagesimal().toString(false);
189
			String longitude = point.getLongitudeSexagesimal() == null ? ""
190
					: point.getLongitudeSexagesimal().toString(false);
191
			text_latitude.setText(latitude);
192
			text_latitudeParsed.setText(latitude);
193
			text_longitude.setText(longitude);
194
			text_longitudeParsed.setText(longitude);
195
			number_errorRadius.setInteger(point.getErrorRadius());
196
			combo_referenceSystem.setSelection(point.getReferenceSystem());
197
		}
198
	}
199

    
200
	/**
201
	 * <p>
202
	 * Getter for the field <code>point</code>.
203
	 * </p>
204
	 * 
205
	 * @return the point
206
	 */
207
	public Point getPoint() {
208
		if (point == null) {
209
			point = Point.NewInstance();
210
		}
211

    
212
		return point;
213
	}
214

    
215
}
(28-28/35)