- created GatheringEventDetails element completely uncoupled to any controlling...
[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.widgets.Composite;
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.element.CdmFormFactory;
18 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
19 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElementComposite;
20 import eu.etaxonomy.taxeditor.ui.section.campanula.GatheringEventDetailsElement;
21 import eu.etaxonomy.taxeditor.ui.section.campanula.NumberFieldController;
22 import eu.etaxonomy.taxeditor.ui.section.campanula.TextFieldController;
23
24 /**
25 * @author pplitzner
26 * @date 25.07.2013
27 *
28 */
29 public class GatheringEventDetailElementComposite extends AbstractCdmDetailElementComposite<DerivedUnitFacade> {
30
31
32
33 private final NumberFieldController absoluteElevationError;
34 private final NumberFieldController number_absoluteElevationMinimum;
35 private final NumberFieldController number_absoluteElevationMaximum;
36 private final TextFieldController collectingMethod;
37 private final NumberFieldController number_distanceToGround;
38 private final NumberFieldController number_distanceToWaterSurface;
39 private final TextFieldController gatheringEventDescription;
40 private CollectingAreasDetailSection section_collectingAreas;
41
42 public GatheringEventDetailElementComposite(Composite parent, CdmFormFactory formFactory, ICdmFormElement parentFormElement, int style) {
43 this(parent, null, formFactory, parentFormElement, style);
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, GatheringEventDetailsElement controlledComposite, CdmFormFactory formFactory, ICdmFormElement parentFormElement, int style) {
58 super(parent, formFactory, parentFormElement, style);
59
60 absoluteElevationError = new NumberFieldController(getLayoutComposite(), controlledComposite.getTextElevationError(), formFactory, this, (Integer)null, 0);
61 number_absoluteElevationMinimum = new NumberFieldController(getLayoutComposite(), controlledComposite.getText_ElevationMinimum(), formFactory, this, (Integer)null, 0);
62 number_absoluteElevationMaximum = new NumberFieldController(getLayoutComposite(), controlledComposite.getText_ElevationMaximum(), formFactory, this, (Integer)null, 0);
63 collectingMethod = new TextFieldController(getLayoutComposite(), controlledComposite.getText_CollectingMethod(), formFactory, this, null, null, 0);
64 number_distanceToGround = new NumberFieldController(getLayoutComposite(), controlledComposite.getText_DistanceToGround(), formFactory, this, (Integer)null, 0);
65 number_distanceToWaterSurface = new NumberFieldController(getLayoutComposite(), controlledComposite.getText_DistanceToWaterSurface(), formFactory, this, (Integer)null, 0);
66 gatheringEventDescription = new TextFieldController(getLayoutComposite(), controlledComposite.getText_GatheringEventDescription(), formFactory, this, null, null, 0);
67 }
68
69 /** {@inheritDoc} */
70 @Override
71 protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
72
73 absoluteElevationError.setText(String.valueOf(entity.getAbsoluteElevation()));
74 number_absoluteElevationMinimum.setText(String.valueOf(entity.getAbsoluteElevationMinimum()));
75 number_absoluteElevationMaximum.setText(String.valueOf(entity.getAbsoluteElevationMaximum()));
76
77 collectingMethod.setText(entity.getCollectingMethod());
78
79 number_distanceToGround.setText(String.valueOf(entity.getDistanceToGround()));
80 number_distanceToWaterSurface.setText(String.valueOf(entity.getDistanceToWaterSurface()));
81 gatheringEventDescription.setText(entity.getGatheringEventDescription());
82
83 // section_collectingAreas = formFactory.createCollectingAreasDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
84 // section_collectingAreas.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
85 // section_collectingAreas.setEntity(entity);
86 }
87
88 /** {@inheritDoc} */
89 @Override
90 public void handleEvent(Object eventSource) {
91 if (eventSource == absoluteElevationError) {
92 getEntity().setAbsoluteElevationError(absoluteElevationError.getInteger());
93 } else if (eventSource == number_absoluteElevationMinimum) {
94 try {
95 getEntity().setAbsoluteElevationRange(number_absoluteElevationMinimum.getInteger(), number_absoluteElevationMaximum.getInteger());
96 number_absoluteElevationMinimum.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
97 } catch (IllegalArgumentException e) {
98 number_absoluteElevationMinimum.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
99 AbstractUtility.warn(getClass(), e.getLocalizedMessage());
100 }
101 } else if (eventSource == number_absoluteElevationMaximum) {
102 try {
103 getEntity().setAbsoluteElevationRange(number_absoluteElevationMinimum.getInteger(), number_absoluteElevationMaximum.getInteger());
104 number_absoluteElevationMaximum.setBackground(getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
105 } catch (IllegalArgumentException e) {
106 number_absoluteElevationMaximum.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
107 AbstractUtility.warn(getClass(), e.getLocalizedMessage());
108 }
109 } else if (eventSource == collectingMethod) {
110 getEntity().setCollectingMethod(collectingMethod.getText());
111 } else if (eventSource == number_distanceToGround) {
112 getEntity().setDistanceToGround(number_distanceToGround.getInteger());
113 } else if (eventSource == number_distanceToWaterSurface) {
114 getEntity().setDistanceToWaterSurface(number_distanceToWaterSurface.getInteger());
115 } else if (eventSource == gatheringEventDescription) {
116 getEntity().setGatheringEventDescription(gatheringEventDescription.getText());
117 }
118 }
119 }