3 * Copyright (C) 2007 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.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
;
13 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
15 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
16 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
17 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
18 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
19 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
20 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
21 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
22 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
23 import eu
.etaxonomy
.taxeditor
.ui
.combo
.EnumComboElement
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.GatheringEventUnitElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.LanguageStringWithLabelElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.MinMaxTextSection
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.NumberWithLabelElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.PointElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.TimePeriodElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.ToggleableTextElement
;
36 import eu
.etaxonomy
.taxeditor
.ui
.element
.UriWithLabelElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
38 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
42 * @created Dec 16, 2010
45 public class DerivedUnitGeneralDetailElement
extends
46 AbstractCdmDetailElement
<DerivedUnitFacade
> {
48 boolean showOnlyDerivedUnitData
= false;
49 //TODO: flag to disable specimen type dropdown (#5244)
50 boolean showSpecimenType
= true;
52 private ToggleableTextElement toggleableText_titleCache
;
53 private EnumComboElement
<SpecimenOrObservationType
> combo_specorobstype
;
54 private EntitySelectionElement
<NamedArea
> selection_country
;
55 private CollectingAreasDetailSection section_collectingAreas
;
56 private LanguageStringWithLabelElement languageText_locality
;
57 private PointElement element_point
;
58 private NumberWithLabelElement number_elevation
;
59 private TimePeriodElement element_date
;
60 private EntitySelectionElement
<AgentBase
> selection_collector
;
61 private TextWithLabelElement text_collectingNumber
;
62 private EntitySelectionElement
<Collection
> selection_collection
;
63 private TextWithLabelElement text_accessionNumber
;
64 private GatheringEventUnitElement element_elevation
;
65 private UriWithLabelElement uriPreferredStableUri
;
66 private CheckboxElement checkIsPublish
;
69 public DerivedUnitGeneralDetailElement(CdmFormFactory formFactory
,
70 ICdmFormElement formElement
) {
71 super(formFactory
, formElement
);
75 protected void createControls(ICdmFormElement formElement
,
76 DerivedUnitFacade entity
, int style
) {
77 toggleableText_titleCache
= formFactory
.createToggleableTextField(
78 formElement
, "Title Cache", entity
.getTitleCache(),
79 entity
.isProtectedTitleCache(), style
);
80 //TODO for DerivateEditor do not use facade anymore to avoid this special case handling #4539
81 if(showOnlyDerivedUnitData
){
82 toggleableText_titleCache
.setEnabled(false);
85 combo_specorobstype
= formFactory
.createEnumComboElement(SpecimenOrObservationType
.class, formElement
, style
);
86 combo_specorobstype
.setSelection(entity
.getType());
87 combo_specorobstype
.setEnabled(showSpecimenType
);
88 selection_country
= formFactory
.createSelectionElement(NamedArea
.class, getConversationHolder(),
89 formElement
, "Country",
90 entity
.getCountry(), EntitySelectionElement
.NOTHING
, style
);
92 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION
)){
93 section_collectingAreas
= formFactory
.createCollectingAreasDetailSection(getConversationHolder(), formElement
, ExpandableComposite
.TWISTIE
);
94 section_collectingAreas
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
95 section_collectingAreas
.setEntity(entity
);
97 languageText_locality
= formFactory
98 .createLanguageStringWithLabelElement(formElement
, "Locality",
99 entity
.getLocality(), style
);
100 element_point
= formFactory
.createPointElement(formElement
,
101 entity
.getExactLocation(), style
);
102 element_elevation
= formFactory
.createGatheringEventUnitElement(
103 formElement
, "Elevation : ", entity
, MinMaxTextSection
.UnitType
.ELEVATION
, style
);
105 element_date
= formFactory
.createTimePeriodElement(formElement
, "Date",
106 entity
.getGatheringPeriod(), style
);
107 selection_collector
= formFactory
108 .createSelectionElement(AgentBase
.class,
109 getConversationHolder(), formElement
, "Collector",
110 entity
.getCollector(), EntitySelectionElement
.ALL
,
112 text_collectingNumber
= formFactory
.createTextWithLabelElement(formElement
,
113 "Collecting number", entity
.getFieldNumber(), style
);
115 selection_collection
= formFactory
116 .createSelectionElement(Collection
.class,
117 getConversationHolder(), formElement
, "Collection",
118 entity
.getCollection(),
119 EntitySelectionElement
.ALL
, style
);
120 text_accessionNumber
= formFactory
.createTextWithLabelElement(
121 formElement
, "Accession Number", entity
.getAccessionNumber(),
123 uriPreferredStableUri
= formFactory
.createUriWithLabelElement(formElement
, "Pref. Stable URI", entity
.getPreferredStableUri(), style
);
124 checkIsPublish
= formFactory
.createCheckbox(formElement
, "Publish", entity
.isPublish(), style
);
129 public void handleEvent(Object eventSource
) {
130 if (eventSource
== toggleableText_titleCache
) {
131 getEntity().setTitleCache(toggleableText_titleCache
.getText(),
132 toggleableText_titleCache
.getState());
133 } else if (eventSource
== selection_country
) {
134 getEntity().setCountry(selection_country
.getSelection());
135 } else if (eventSource
== languageText_locality
) {
136 LanguageString locality
= languageText_locality
.getLanguageString();
137 getEntity().setLocality(locality
);
138 } else if (eventSource
== element_point
) {
139 getEntity().setExactLocation(element_point
.getPoint());
140 } else if (eventSource
== number_elevation
) {
141 getEntity().setAbsoluteElevation(number_elevation
.getInteger());
142 } else if (eventSource
== element_date
) {
143 getEntity().setGatheringPeriod(element_date
.getTimePeriod());
144 } else if (eventSource
== selection_collector
) {
145 getEntity().setCollector(selection_collector
.getSelection());
146 } else if (eventSource
== text_collectingNumber
) {
147 getEntity().setFieldNumber(text_collectingNumber
.getText());
149 else if (eventSource
== selection_collection
) {
150 getEntity().setCollection(selection_collection
.getSelection());
151 } else if (eventSource
== text_accessionNumber
) {
152 getEntity().setAccessionNumber(text_accessionNumber
.getText());
153 } else if (eventSource
== combo_specorobstype
) {
154 getEntity().setType(combo_specorobstype
.getSelection());
155 } else if (eventSource
== uriPreferredStableUri
) {
156 getEntity().setPreferredStableUri(uriPreferredStableUri
.parseText());
157 } else if (eventSource
== checkIsPublish
) {
158 getEntity().innerDerivedUnit().setPublish(checkIsPublish
.getSelection());
161 if (eventSource
!= toggleableText_titleCache
) {
162 toggleableText_titleCache
.setText(getEntity().getTitleCache());
166 public void setShowOnlyDerivedUnitData(boolean showOnlyDerivedUnitData
) {
167 this.showOnlyDerivedUnitData
= showOnlyDerivedUnitData
;
170 public void setShowSpecimenType(boolean showSpecimenType
) {
171 this.showSpecimenType
= showSpecimenType
;