3 * Copyright (C) 2013 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
;
12 import org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.widgets
.Composite
;
14 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
15 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
16 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
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
.CdmFormFactory
;
22 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.NumberWithLabelElementComposite
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelComposite
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElementComposite
;
32 public class GatheringEventDetailElementComposite
extends AbstractCdmDetailElementComposite
<DerivedUnitFacade
> {
36 // private CollectingAreasDetailSection section_collectingAreas;
37 private final NumberWithLabelElementComposite absoluteElevationError
;
38 private final NumberWithLabelElementComposite number_absoluteElevationMinimum
;
39 private final NumberWithLabelElementComposite number_absoluteElevationMaximum
;
40 private final TextWithLabelComposite collectingMethod
;
41 private final NumberWithLabelElementComposite number_distanceToGround
;
42 private final NumberWithLabelElementComposite number_distanceToWaterSurface
;
43 private final TextWithLabelComposite gatheringEventDescription
;
47 * Constructor for GatheringEventDetailElement.
51 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
54 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
57 public GatheringEventDetailElementComposite(Composite parent
, FormToolkit formFactory
, ICdmFormElement parentFormElement
, int style
) {
58 super(parent
, formFactory
, parentFormElement
, style
);
59 TableWrapLayout tableWrapLayout
= (TableWrapLayout
) getLayout();
60 tableWrapLayout
.numColumns
= 1;
62 absoluteElevationError
= CdmFormFactory
.createNumberWithLabelElementComposite(this, getFormFactory(), this, "Elevation Error", new Float(0), SWT
.NONE
);
63 TableWrapData twd_absoluteElevationError
= new TableWrapData(TableWrapData
.LEFT
, TableWrapData
.TOP
, 1, 1);
64 twd_absoluteElevationError
.grabHorizontal
= true;
65 absoluteElevationError
.setLayoutData(twd_absoluteElevationError
);
66 getFormFactory().adapt(absoluteElevationError
);
67 getFormFactory().paintBordersFor(absoluteElevationError
);
69 number_absoluteElevationMinimum
= CdmFormFactory
.createNumberWithLabelElementComposite(this, getFormFactory(), this, "Elevation Minimum (m)", new Float(0), SWT
.NONE
);
70 TableWrapData twd_number_absoluteElevationMinimum
= new TableWrapData(TableWrapData
.LEFT
, TableWrapData
.TOP
, 1, 1);
71 twd_number_absoluteElevationMinimum
.grabHorizontal
= true;
72 number_absoluteElevationMinimum
.setLayoutData(twd_number_absoluteElevationMinimum
);
73 formFactory
.paintBordersFor(number_absoluteElevationMinimum
);
75 number_absoluteElevationMaximum
= CdmFormFactory
.createNumberWithLabelElementComposite(this, getFormFactory(), parentFormElement
, "Elevation Maximum (m)", new Float(0), SWT
.NONE
);
76 TableWrapData twd_numberWithLabelElementComposite
= new TableWrapData(TableWrapData
.LEFT
, TableWrapData
.TOP
, 1, 1);
77 twd_numberWithLabelElementComposite
.grabVertical
= true;
78 twd_numberWithLabelElementComposite
.grabHorizontal
= true;
79 number_absoluteElevationMaximum
.setLayoutData(twd_numberWithLabelElementComposite
);
80 formFactory
.paintBordersFor(number_absoluteElevationMaximum
);
82 collectingMethod
= CdmFormFactory
.createTextWithLabelComposite(this, getFormFactory(), this, "Collecting Method", "", (Integer
) null, SWT
.NONE
);
83 TableWrapData twd_collectingMethod
= new TableWrapData(TableWrapData
.LEFT
, TableWrapData
.TOP
, 1, 1);
84 twd_collectingMethod
.grabHorizontal
= true;
85 collectingMethod
.setLayoutData(twd_collectingMethod
);
86 getFormFactory().adapt(collectingMethod
);
87 getFormFactory().paintBordersFor(collectingMethod
);
89 number_distanceToGround
= CdmFormFactory
.createNumberWithLabelElementComposite(this, getFormFactory(), parentFormElement
, "Distance To Ground (m)", new Float(0), SWT
.NONE
);
90 formFactory
.paintBordersFor(number_distanceToGround
);
92 number_distanceToWaterSurface
= CdmFormFactory
.createNumberWithLabelElementComposite(this, getFormFactory(), parentFormElement
, "Distance To Water Surface (m)", new Float(0), SWT
.NONE
);
93 formFactory
.paintBordersFor(number_distanceToWaterSurface
);
95 gatheringEventDescription
= CdmFormFactory
.createTextWithLabelComposite(this, getFormFactory(), this, "Gathering Event Description", "", (Integer
) null, SWT
.NONE
);
96 TableWrapData twd_gatheringEventDescription
= new TableWrapData(TableWrapData
.LEFT
, TableWrapData
.TOP
, 1, 1);
97 twd_gatheringEventDescription
.grabHorizontal
= true;
98 gatheringEventDescription
.setLayoutData(twd_gatheringEventDescription
);
99 getFormFactory().adapt(gatheringEventDescription
);
100 getFormFactory().paintBordersFor(gatheringEventDescription
);
106 protected void createControls(ICdmFormElement formElement
, DerivedUnitFacade entity
, int style
) {
108 absoluteElevationError
.setText(String
.valueOf(entity
.getAbsoluteElevation()));
109 number_absoluteElevationMinimum
.setText(String
.valueOf(entity
.getAbsoluteElevationMinimum()));
110 number_absoluteElevationMaximum
.setText(String
.valueOf(entity
.getAbsoluteElevationMaximum()));
111 collectingMethod
.setText(entity
.getCollectingMethod());
112 number_distanceToGround
.setText(String
.valueOf(entity
.getDistanceToGround()));
113 number_distanceToWaterSurface
.setText(String
.valueOf(entity
.getDistanceToWaterSurface()));
114 gatheringEventDescription
.setText(entity
.getGatheringEventDescription());
117 // number_absoluteElevationError = formFactory.createIntegerTextWithLabelElement(formElement, "Elevation Error", entity.getAbsoluteElevationError(), style);
118 // number_absoluteElevationMinimum = formFactory.createIntegerTextWithLabelElement(formElement, "Elevation Minimum (m)", entity.getAbsoluteElevationMinimum(), style);
119 // number_absoluteElevationMaximum = formFactory.createIntegerTextWithLabelElement(formElement, "Elevation Maximum (m)", entity.getAbsoluteElevationMaximum(), style);
121 // text_collectingMethod = formFactory.createTextWithLabelElement(formElement, "Collecting Method", entity.getCollectingMethod(), style);
123 // number_distanceToGround = formFactory.createIntegerTextWithLabelElement(formElement, "Distance To Ground (m)", entity.getDistanceToGround(), style);
124 // number_distanceToWaterSurface = formFactory.createIntegerTextWithLabelElement(formElement, "Distance To Water Surface (m)", entity.getDistanceToWaterSurface(), style);
126 // text_gatheringEventDescription = formFactory.createTextWithLabelElement(formElement, "Gathering Event Description", entity.getGatheringEventDescription(), style);
128 // section_collectingAreas = formFactory.createCollectingAreasDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
129 // section_collectingAreas.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
130 // section_collectingAreas.setEntity(entity);
135 public void handleEvent(Object eventSource
) {
136 if (eventSource
== absoluteElevationError
) {
137 getEntity().setAbsoluteElevationError(absoluteElevationError
.getInteger());
138 } else if (eventSource
== number_absoluteElevationMinimum
) {
140 getEntity().setAbsoluteElevationRange(number_absoluteElevationMinimum
.getInteger(), number_absoluteElevationMaximum
.getInteger());
141 number_absoluteElevationMinimum
.setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
142 } catch (IllegalArgumentException e
) {
143 number_absoluteElevationMinimum
.setBackground(getColor(Resources
.COLOR_PARSE_ERROR
));
144 AbstractUtility
.warn(getClass(), e
.getLocalizedMessage());
146 } else if (eventSource
== number_absoluteElevationMaximum
) {
148 getEntity().setAbsoluteElevationRange(number_absoluteElevationMinimum
.getInteger(), number_absoluteElevationMaximum
.getInteger());
149 number_absoluteElevationMaximum
.setBackground(getColor(Resources
.COLOR_COMPOSITE_BACKGROUND
));
150 } catch (IllegalArgumentException e
) {
151 number_absoluteElevationMaximum
.setBackground(getColor(Resources
.COLOR_PARSE_ERROR
));
152 AbstractUtility
.warn(getClass(), e
.getLocalizedMessage());
154 } else if (eventSource
== getCollectingMethod()) {
155 getEntity().setCollectingMethod(getCollectingMethod().getText());
156 } else if (eventSource
== number_distanceToGround
) {
157 getEntity().setDistanceToGround(number_distanceToGround
.getInteger());
158 } else if (eventSource
== number_distanceToWaterSurface
) {
159 getEntity().setDistanceToWaterSurface(number_distanceToWaterSurface
.getInteger());
160 } else if (eventSource
== getGatheringEventDescription()) {
161 getEntity().setGatheringEventDescription(getGatheringEventDescription().getText());
164 public TextWithLabelComposite
getGatheringEventDescription() {
165 return gatheringEventDescription
;
167 public TextWithLabelComposite
getCollectingMethod() {
168 return collectingMethod
;