- completely removed EntityDetailType enum and all its uses
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / DerivedUnitBaseDetailElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 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
11 package eu.etaxonomy.taxeditor.ui.section.occurrence;
12
13 import org.eclipse.ui.forms.widgets.ExpandableComposite;
14
15 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
16 import eu.etaxonomy.cdm.api.facade.MethodNotSupportedByDerivedUnitTypeException;
17 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
18 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
19 import eu.etaxonomy.taxeditor.model.AbstractUtility;
20 import eu.etaxonomy.taxeditor.store.CdmStore;
21 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
22 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
25 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
26 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
27 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
28
29 /**
30 * <p>
31 * DerivedUnitBaseDetailElement class.
32 * </p>
33 *
34 * @author n.hoffmann
35 * @created Jun 24, 2010
36 * @version 1.0
37 */
38 public class DerivedUnitBaseDetailElement extends
39 AbstractCdmDetailElement<DerivedUnitFacade> {
40
41 private TextWithLabelElement text_derivedUnitDefinitions;
42
43 private TextWithLabelElement text_barcode;
44
45 private TextWithLabelElement text_catalogNumber;
46
47 private EntitySelectionElement<TaxonNameBase> selection_storedUnder;
48
49 private TextWithLabelElement text_exsicatum;
50
51 private TermComboElement<PreservationMethod> combo_preservationMethod;
52
53 private SpecimenCollectionDetailSection section_duplicates;
54
55 private SourceCollectionDetailSection section_source;
56
57 /**
58 * <p>
59 * Constructor for DerivedUnitBaseDetailElement.
60 * </p>
61 *
62 * @param formFactory
63 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
64 * object.
65 * @param formElement
66 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
67 * object.
68 */
69 public DerivedUnitBaseDetailElement(CdmFormFactory formFactory,
70 ICdmFormElement formElement) {
71 super(formFactory, formElement);
72 }
73
74 /** {@inheritDoc} */
75 @Override
76 protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
77 // Disable for now
78 // text_derivedUnitDefinitions =
79 // formFactory.createTextWithLabelElement(formElement,
80 // "Specimen Definition",
81 // facade.getDerivedUnitDefinition(CdmStore.getDefaultLanguage()),
82 // style);
83 text_barcode = formFactory.createTextWithLabelElement(formElement, "Barcode", entity.getBarcode(), style);
84 text_catalogNumber = formFactory.createTextWithLabelElement(formElement, "Catalog Number", entity.getCatalogNumber(), style);
85
86 try {
87 combo_preservationMethod = formFactory.createTermComboElement(PreservationMethod.class, formElement, "Preservation Method", entity.getPreservationMethod(), style);
88 } catch (MethodNotSupportedByDerivedUnitTypeException e) {
89 // we ignore this
90 AbstractUtility.info(e.getMessage());
91 }
92 selection_storedUnder = formFactory.createSelectionElement(TaxonNameBase.class, getConversationHolder(), formElement, "Stored Under", entity.getStoredUnder(), EntitySelectionElement.ALL, style);
93
94 try {
95 text_exsicatum = formFactory.createTextWithLabelElement(formElement, "Exsiccatum", entity.getExsiccatum(), style);
96 } catch (MethodNotSupportedByDerivedUnitTypeException e) {
97 // we ignore this
98 AbstractUtility.info(e.getMessage());
99 }
100
101 section_duplicates = formFactory.createSpecimenCollectionDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
102 section_duplicates.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
103 section_duplicates.setEntity(entity);
104
105 section_source = formFactory.createSourceCollectionDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
106 section_source.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
107 section_source.setEntity(entity);
108 }
109
110 /** {@inheritDoc} */
111 @Override
112 public void handleEvent(Object eventSource) {
113 if (eventSource == text_derivedUnitDefinitions) {
114 getEntity().addDerivedUnitDefinition(
115 text_derivedUnitDefinitions.getText(),
116 CdmStore.getDefaultLanguage());
117 } else if (eventSource == text_barcode) {
118 getEntity().setBarcode(text_barcode.getText());
119 } else if (eventSource == text_catalogNumber) {
120 getEntity().setCatalogNumber(text_catalogNumber.getText());
121 } else if (eventSource == combo_preservationMethod) {
122 try {
123 getEntity().setPreservationMethod(
124 combo_preservationMethod.getSelection());
125 } catch (MethodNotSupportedByDerivedUnitTypeException e) {
126 AbstractUtility
127 .errorDialog(
128 "MethodNotSupportedByDerivedUnitTypeException",
129 this,
130 "MethodNotSupportedByDerivedUnitTypeException when trying to set preservation method for derive unit",
131 e);
132 }
133 } else if (eventSource == selection_storedUnder) {
134 getEntity().setStoredUnder(selection_storedUnder.getEntity());
135 } else if (eventSource == text_exsicatum) {
136 try {
137 getEntity().setExsiccatum(text_exsicatum.getText());
138 } catch (Exception e) {
139 AbstractUtility.error(this.getClass(), e);
140 }
141 }
142 }
143 }