Project

General

Profile

Download (5.64 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.element;
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.cdm.model.location.ReferenceSystem;
19
import eu.etaxonomy.taxeditor.preference.Resources;
20
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
21
import eu.etaxonomy.taxeditor.ui.section.campanula.compatibility.ICdmFormElement;
22

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

    
35
	private Point point;
36

    
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;
41

    
42
	private final TextWithLabelElement text_latitudeParsed;
43

    
44
	private final TextWithLabelElement text_longitudeParsed;
45

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

    
66
		formFactory.addPropertyChangeListener(this);
67

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

    
84
		setPoint(point);
85
	}
86

    
87
	/*
88
	 * (non-Javadoc)
89
	 * 
90
	 * @see
91
	 * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
92
	 * .eclipse.jface.util.PropertyChangeEvent)
93
	 */
94
	/** {@inheritDoc} */
95
	@Override
96
	public void propertyChange(PropertyChangeEvent event) {
97
		if (event == null) {
98
			return;
99
		}
100

    
101
		boolean propagate = false;
102

    
103
		Object eventSource = event.getSource();
104
		if (eventSource == text_latitude) {
105
			try {
106
				getPoint().setLatitudeByParsing(text_latitude.getText());
107
				text_latitudeParsed.setText(point.getLatitudeSexagesimal()
108
						.toString(false));
109
				text_latitude
110
						.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
111
				propagate = true;
112
			} catch (ParseException e) {
113
				text_latitude
114
						.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
115
			}
116
		} else if (eventSource == text_longitude) {
117
			try {
118
				getPoint().setLongitudeByParsing(text_longitude.getText());
119
				text_longitudeParsed.setText(point.getLongitudeSexagesimal()
120
						.toString(false));
121
				text_longitude
122
						.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
123
				propagate = true;
124
			} catch (ParseException e) {
125
				text_longitude
126
						.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
127
			}
128
		} else if (eventSource == number_errorRadius) {
129
			getPoint().setErrorRadius(number_errorRadius.getInteger());
130
			propagate = true;
131
		} else if (eventSource == combo_referenceSystem) {
132
			getPoint().setReferenceSystem(combo_referenceSystem.getSelection());
133
			propagate = true;
134
		}
135

    
136
		if (propagate) {
137
			firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
138
		}
139
	}
140

    
141
	/*
142
	 * (non-Javadoc)
143
	 * 
144
	 * @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity()
145
	 */
146
	/** {@inheritDoc} */
147
	@Override
148
	public Point getEntity() {
149
		return getPoint();
150
	}
151

    
152
	/**
153
	 * <p>
154
	 * setEntity
155
	 * </p>
156
	 * 
157
	 * @param point
158
	 *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
159
	 */
160
	public void setEntity(Point point) {
161
		setPoint(point);
162
	}
163

    
164
	/**
165
	 * <p>
166
	 * Setter for the field <code>point</code>.
167
	 * </p>
168
	 * 
169
	 * @param point
170
	 *            the point to set
171
	 */
172
	public void setPoint(Point point) {
173
		this.point = point;
174
		if (point != null) {
175
			String latitude = point.getLatitudeSexagesimal() == null ? ""
176
					: point.getLatitudeSexagesimal().toString(false);
177
			String longitude = point.getLongitudeSexagesimal() == null ? ""
178
					: point.getLongitudeSexagesimal().toString(false);
179
			text_latitude.setText(latitude);
180
			text_latitudeParsed.setText(latitude);
181
			text_longitude.setText(longitude);
182
			text_longitudeParsed.setText(longitude);
183
			number_errorRadius.setInteger(point.getErrorRadius());
184
			combo_referenceSystem.setSelection(point.getReferenceSystem());
185
		}
186
	}
187

    
188
	/**
189
	 * <p>
190
	 * Getter for the field <code>point</code>.
191
	 * </p>
192
	 * 
193
	 * @return the point
194
	 */
195
	public Point getPoint() {
196
		if (point == null) {
197
			point = Point.NewInstance();
198
		}
199

    
200
		return point;
201
	}
202

    
203
	public void setSelected(boolean selected) {
204
		setBackground(selected ? SELECTED : getPersistentBackground());
205
	}
206
	
207
}
(28-28/35)