e935aa3a72729bf0da0a53d2a2ad972a867e3718
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / campanula / detailViews / fieldObservation / GatheringEventDetailsElementController.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.campanula.detailViews.fieldObservation;
11
12 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
13 import eu.etaxonomy.taxeditor.model.AbstractUtility;
14 import eu.etaxonomy.taxeditor.preference.Resources;
15 import eu.etaxonomy.taxeditor.ui.campanula.basicFields.NumberFieldController;
16 import eu.etaxonomy.taxeditor.ui.campanula.basicFields.TextFieldController;
17 import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
18 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
19 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
20
21 /**
22 * @author pplitzner
23 * @date 14.08.2013
24 *
25 */
26 public class GatheringEventDetailsElementController extends AbstractCdmDetailElement<DerivedUnitFacade> {
27
28 private GatheringEventDetailsElement gatheringEventDetailsElement;
29
30 private NumberFieldController number_absoluteElevationError;
31
32 private NumberFieldController number_absoluteElevationMinimum;
33
34 private NumberFieldController number_absoluteElevationMaximum;
35
36 private TextFieldController text_collectingMethod;
37
38 private NumberFieldController number_distanceToGround;
39
40 private NumberFieldController number_distanceToWaterSurface;
41
42 private TextFieldController text_gatheringEventDescription;
43
44 // private CollectingAreasDetailSection section_collectingAreas;
45
46 /**
47 * <p>
48 * Constructor for GatheringEventDetailElement.
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 */
58 public GatheringEventDetailsElementController(GatheringEventDetailsElement gatheringEventDetailsElement, CdmFormFactory formFactory, ICdmFormElement formElement) {
59 super(formFactory, formElement);
60 this.gatheringEventDetailsElement = gatheringEventDetailsElement;
61 }
62
63 /** {@inheritDoc} */
64 @Override
65 protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
66
67 number_absoluteElevationError = new NumberFieldController(gatheringEventDetailsElement.getTextElevationError(), formFactory, this, (Integer)null);
68 number_absoluteElevationMinimum = new NumberFieldController(gatheringEventDetailsElement.getText_ElevationMinimum(), formFactory, this, (Integer)null);
69 number_absoluteElevationMaximum = new NumberFieldController(gatheringEventDetailsElement.getText_ElevationMaximum(), formFactory, this, (Integer)null);
70 text_collectingMethod = new TextFieldController(gatheringEventDetailsElement.getText_CollectingMethod(), formFactory, this, null, null);
71 number_distanceToGround = new NumberFieldController(gatheringEventDetailsElement.getText_DistanceToGround(), formFactory, this, (Integer)null);
72 number_distanceToWaterSurface = new NumberFieldController(gatheringEventDetailsElement.getText_DistanceToWaterSurface(), formFactory, this, (Integer)null);
73 text_gatheringEventDescription = new TextFieldController(gatheringEventDetailsElement.getText_GatheringEventDescription(), formFactory, this, null, null);
74 // section_collectingAreas = formFactory.createCollectingAreasDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
75 // section_collectingAreas.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
76 // section_collectingAreas.setEntity(entity);
77 }
78
79 /** {@inheritDoc} */
80 @Override
81 public void handleEvent(Object eventSource) {
82 if (eventSource == number_absoluteElevationError) {
83 getEntity().setAbsoluteElevationError(number_absoluteElevationError.getInteger());
84 } else if (eventSource == number_absoluteElevationMinimum) {
85 try {
86 getEntity().setAbsoluteElevationRange(number_absoluteElevationMinimum.getInteger(), number_absoluteElevationMaximum.getInteger());
87 number_absoluteElevationMinimum.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
88 } catch (IllegalArgumentException e) {
89 number_absoluteElevationMinimum.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
90 AbstractUtility.warn(getClass(), e.getLocalizedMessage());
91 }
92 } else if (eventSource == number_absoluteElevationMaximum) {
93 try {
94 getEntity().setAbsoluteElevationRange(number_absoluteElevationMinimum.getInteger(), number_absoluteElevationMaximum.getInteger());
95 number_absoluteElevationMaximum.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
96 } catch (IllegalArgumentException e) {
97 number_absoluteElevationMaximum.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
98 AbstractUtility.warn(getClass(), e.getLocalizedMessage());
99 }
100 } else if (eventSource == text_collectingMethod) {
101 getEntity().setCollectingMethod(text_collectingMethod.getText());
102 } else if (eventSource == number_distanceToGround) {
103 getEntity().setDistanceToGround(number_distanceToGround.getInteger());
104 } else if (eventSource == number_distanceToWaterSurface) {
105 getEntity().setDistanceToWaterSurface(number_distanceToWaterSurface.getInteger());
106 } else if (eventSource == text_gatheringEventDescription) {
107 getEntity().setGatheringEventDescription(text_gatheringEventDescription.getText());
108 }
109 }
110 }