44aff0cbd393aade7404871bb7da7996559420cd
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / GatheringEventDetailElementComposite.java
1 // $Id$
2 /**
3 * Copyright (C) 2013 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 package eu.etaxonomy.taxeditor.ui.section.occurrence;
11
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Label;
15 import org.eclipse.ui.forms.widgets.FormToolkit;
16 import org.eclipse.ui.forms.widgets.TableWrapData;
17
18 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
19 import eu.etaxonomy.taxeditor.model.AbstractUtility;
20 import eu.etaxonomy.taxeditor.preference.Resources;
21 import eu.etaxonomy.taxeditor.ui.element.CdmElementFactory;
22 import eu.etaxonomy.taxeditor.ui.element.CdmNumberField;
23 import eu.etaxonomy.taxeditor.ui.element.CdmTextField;
24 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElementComposite;
26
27 /**
28 * @author pplitzner
29 * @date 25.07.2013
30 *
31 */
32 public class GatheringEventDetailElementComposite extends AbstractCdmDetailElementComposite<DerivedUnitFacade> {
33
34
35
36 private final CdmNumberField absoluteElevationError;
37 private final CdmNumberField number_absoluteElevationMinimum;
38 private final CdmNumberField number_absoluteElevationMaximum;
39 private final CdmTextField collectingMethod;
40 private final CdmNumberField number_distanceToGround;
41 private final CdmNumberField number_distanceToWaterSurface;
42 private final CdmTextField gatheringEventDescription;
43 // private CollectingAreasDetailSection section_collectingAreas;
44
45 /**
46 * <p>
47 * Constructor for GatheringEventDetailElement.
48 * </p>
49 *
50 * @param formFactory
51 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
52 * object.
53 * @param formElement
54 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
55 * object.
56 */
57 public GatheringEventDetailElementComposite(Composite parent, FormToolkit formFactory, ICdmFormElement parentFormElement, int style) {
58 super(parent, formFactory, parentFormElement, style);
59
60 Label lblNewLabel_4 = new Label(this, SWT.NONE);
61 formFactory.adapt(lblNewLabel_4, true, true);
62 lblNewLabel_4.setText("Elevation Error");
63
64 absoluteElevationError = CdmElementFactory.createCdmNumberField(this, formFactory, this, (Integer) null, 0);
65 ((TableWrapData) absoluteElevationError.getMainControl().getLayoutData()).grabVertical = false;
66 TableWrapData twd_cdmNumberField = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
67 twd_cdmNumberField.grabHorizontal = true;
68 absoluteElevationError.setLayoutData(twd_cdmNumberField);
69 formFactory.adapt(absoluteElevationError);
70 formFactory.paintBordersFor(absoluteElevationError);
71
72 Label lblNewLabel_3 = new Label(this, SWT.NONE);
73 formFactory.adapt(lblNewLabel_3, true, true);
74 lblNewLabel_3.setText("Elevation Error Minumum (m)");
75
76 number_absoluteElevationMinimum = CdmElementFactory.createCdmNumberField(this, formFactory, this, (Integer) null, 0);
77 TableWrapData tableWrapData = (TableWrapData) number_absoluteElevationMinimum.getMainControl().getLayoutData();
78 tableWrapData.valign = TableWrapData.TOP;
79 tableWrapData.grabVertical = false;
80 TableWrapData twd_cdmNumberField_1 = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
81 twd_cdmNumberField_1.grabHorizontal = true;
82 number_absoluteElevationMinimum.setLayoutData(twd_cdmNumberField_1);
83 formFactory.paintBordersFor(number_absoluteElevationMinimum);
84
85 Label lblNewLabel_2 = new Label(this, SWT.NONE);
86 formFactory.adapt(lblNewLabel_2, true, true);
87 lblNewLabel_2.setText("Elevation Maximum (m)");
88
89 number_absoluteElevationMaximum = CdmElementFactory.createCdmNumberField(this, formFactory, this, (Integer) null, 0);
90 TableWrapData twd_cdmNumberField_2 = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
91 twd_cdmNumberField_2.grabHorizontal = true;
92 number_absoluteElevationMaximum.setLayoutData(twd_cdmNumberField_2);
93 formFactory.adapt(number_absoluteElevationMaximum);
94 formFactory.paintBordersFor(number_absoluteElevationMaximum);
95
96 Label lblTestLabel = new Label(this, SWT.NONE);
97 formFactory.adapt(lblTestLabel, true, true);
98 lblTestLabel.setText("Collecting Method");
99
100 collectingMethod = CdmElementFactory.createCdmTextField(this, formFactory, this, (String) null, (Integer) null, 0);
101 TableWrapData twd_cdmTextField_1 = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
102 twd_cdmTextField_1.grabHorizontal = true;
103 collectingMethod.setLayoutData(twd_cdmTextField_1);
104 formFactory.adapt(collectingMethod);
105 formFactory.paintBordersFor(collectingMethod);
106
107 Label lblNewLabel_5 = new Label(this, SWT.NONE);
108 formFactory.adapt(lblNewLabel_5, true, true);
109 lblNewLabel_5.setText("Distance To Ground (m)");
110
111 number_distanceToGround = CdmElementFactory.createCdmNumberField(this, formFactory, this, (Integer) null, 0);
112 TableWrapData twd_cdmNumberField_3 = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
113 twd_cdmNumberField_3.grabHorizontal = true;
114 number_distanceToGround.setLayoutData(twd_cdmNumberField_3);
115 formFactory.adapt(number_distanceToGround);
116 formFactory.paintBordersFor(number_distanceToGround);
117
118 Label lblNewLabel_6 = new Label(this, SWT.NONE);
119 formFactory.adapt(lblNewLabel_6, true, true);
120 lblNewLabel_6.setText("Distance To Water Surface");
121
122 number_distanceToWaterSurface = CdmElementFactory.createCdmNumberField(this, formFactory, this, (Integer) null, 0);
123 TableWrapData twd_cdmNumberField_4 = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
124 twd_cdmNumberField_4.grabHorizontal = true;
125 number_distanceToWaterSurface.setLayoutData(twd_cdmNumberField_4);
126 formFactory.adapt(number_distanceToWaterSurface);
127 formFactory.paintBordersFor(number_distanceToWaterSurface);
128
129 Label lblNewLabel = new Label(this, SWT.NONE);
130 formFactory.adapt(lblNewLabel, true, true);
131 lblNewLabel.setText("Gathering Event Description");
132
133 gatheringEventDescription = CdmElementFactory.createCdmTextField(this, formFactory, this, (String) null, (Integer) null, 0);
134 TableWrapData twd_cdmTextField_2 = new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP, 1, 1);
135 twd_cdmTextField_2.grabHorizontal = true;
136 gatheringEventDescription.setLayoutData(twd_cdmTextField_2);
137 formFactory.adapt(gatheringEventDescription);
138 formFactory.paintBordersFor(gatheringEventDescription);
139
140 }
141
142 /** {@inheritDoc} */
143 @Override
144 protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
145
146 absoluteElevationError.setText(String.valueOf(entity.getAbsoluteElevation()));
147 number_absoluteElevationMinimum.setText(String.valueOf(entity.getAbsoluteElevationMinimum()));
148 number_absoluteElevationMaximum.setText(String.valueOf(entity.getAbsoluteElevationMaximum()));
149 collectingMethod.setText(entity.getCollectingMethod());
150 number_distanceToGround.setText(String.valueOf(entity.getDistanceToGround()));
151 number_distanceToWaterSurface.setText(String.valueOf(entity.getDistanceToWaterSurface()));
152 gatheringEventDescription.setText(entity.getGatheringEventDescription());
153
154 // collectingArea
155 // number_absoluteElevationError = formFactory.createIntegerTextWithLabelElement(formElement, "Elevation Error", entity.getAbsoluteElevationError(), style);
156 // number_absoluteElevationMinimum = formFactory.createIntegerTextWithLabelElement(formElement, "Elevation Minimum (m)", entity.getAbsoluteElevationMinimum(), style);
157 // number_absoluteElevationMaximum = formFactory.createIntegerTextWithLabelElement(formElement, "Elevation Maximum (m)", entity.getAbsoluteElevationMaximum(), style);
158
159 // text_collectingMethod = formFactory.createTextWithLabelElement(formElement, "Collecting Method", entity.getCollectingMethod(), style);
160
161 // number_distanceToGround = formFactory.createIntegerTextWithLabelElement(formElement, "Distance To Ground (m)", entity.getDistanceToGround(), style);
162 // number_distanceToWaterSurface = formFactory.createIntegerTextWithLabelElement(formElement, "Distance To Water Surface (m)", entity.getDistanceToWaterSurface(), style);
163 // exactLocation
164 // text_gatheringEventDescription = formFactory.createTextWithLabelElement(formElement, "Gathering Event Description", entity.getGatheringEventDescription(), style);
165
166 // section_collectingAreas = formFactory.createCollectingAreasDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
167 // section_collectingAreas.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
168 // section_collectingAreas.setEntity(entity);
169 }
170
171 /** {@inheritDoc} */
172 @Override
173 public void handleEvent(Object eventSource) {
174 if (eventSource == absoluteElevationError) {
175 getEntity().setAbsoluteElevationError(absoluteElevationError.getInteger());
176 } else if (eventSource == number_absoluteElevationMinimum) {
177 try {
178 getEntity().setAbsoluteElevationRange(number_absoluteElevationMinimum.getInteger(), number_absoluteElevationMaximum.getInteger());
179 number_absoluteElevationMinimum.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
180 } catch (IllegalArgumentException e) {
181 number_absoluteElevationMinimum.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
182 AbstractUtility.warn(getClass(), e.getLocalizedMessage());
183 }
184 } else if (eventSource == number_absoluteElevationMaximum) {
185 try {
186 getEntity().setAbsoluteElevationRange(number_absoluteElevationMinimum.getInteger(), number_absoluteElevationMaximum.getInteger());
187 number_absoluteElevationMaximum.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
188 } catch (IllegalArgumentException e) {
189 number_absoluteElevationMaximum.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
190 AbstractUtility.warn(getClass(), e.getLocalizedMessage());
191 }
192 } else if (eventSource == collectingMethod) {
193 getEntity().setCollectingMethod(collectingMethod.getText());
194 } else if (eventSource == number_distanceToGround) {
195 getEntity().setDistanceToGround(number_distanceToGround.getInteger());
196 } else if (eventSource == number_distanceToWaterSurface) {
197 getEntity().setDistanceToWaterSurface(number_distanceToWaterSurface.getInteger());
198 } else if (eventSource == gatheringEventDescription) {
199 getEntity().setGatheringEventDescription(gatheringEventDescription.getText());
200 }
201 }
202 }