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