Moved all logging and dialog functionality to the new class MessagingUtils.
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / derivedUnit / PreservedSpecimenDetailElement.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.derivedUnit;
12
13 import org.eclipse.ui.forms.widgets.ExpandableComposite;
14
15 import eu.etaxonomy.cdm.model.common.DefinedTerm;
16 import eu.etaxonomy.cdm.model.common.TermType;
17 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
18 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
19 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
20 import eu.etaxonomy.taxeditor.model.MessagingUtils;
21 import eu.etaxonomy.taxeditor.store.CdmStore;
22 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
23 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
26 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
27 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
28 import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenCollectionDetailSection;
29 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
30
31 /**
32 * <p>
33 * DerivedUnitBaseDetailElement class.
34 * </p>
35 *
36 * @author n.hoffmann
37 * @created Jun 24, 2010
38 * @version 1.0
39 */
40 public class PreservedSpecimenDetailElement extends
41 AbstractCdmDetailElement<DerivedUnit> {
42
43 private TextWithLabelElement text_derivedUnitDefinitions;
44
45 private TextWithLabelElement text_barcode;
46
47 private TextWithLabelElement text_catalogNumber;
48
49 private EntitySelectionElement<TaxonNameBase> selection_storedUnder;
50
51 private TextWithLabelElement text_exsicatum;
52
53 private TermComboElement<DefinedTerm> combo_preservationMethod;
54
55 private SpecimenCollectionDetailSection section_duplicates;
56
57 private PreservedSpecimenSourceCollectionDetailSection section_source;
58
59 /**
60 * <p>
61 * Constructor for DerivedUnitBaseDetailElement.
62 * </p>
63 *
64 * @param formFactory
65 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
66 * object.
67 * @param formElement
68 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
69 * object.
70 */
71 public PreservedSpecimenDetailElement(CdmFormFactory formFactory,
72 ICdmFormElement formElement) {
73 super(formFactory, formElement);
74 }
75
76 /** {@inheritDoc} */
77 @Override
78 protected void createControls(ICdmFormElement formElement, DerivedUnit entity, int style) {
79 // Disable for now
80 // text_derivedUnitDefinitions =
81 // formFactory.createTextWithLabelElement(formElement,
82 // "Specimen Definition",
83 // facade.getDerivedUnitDefinition(CdmStore.getDefaultLanguage()),
84 // style);
85 text_barcode = formFactory.createTextWithLabelElement(formElement, "Barcode", entity.getBarcode(), style);
86 text_catalogNumber = formFactory.createTextWithLabelElement(formElement, "Catalog Number", entity.getCatalogNumber(), style);
87
88
89 PreservationMethod preservationMethod = entity.getPreservation();
90 combo_preservationMethod = formFactory.createDefinedTermComboElement(TermType.MaterialOrMethod, formElement, "Preservation Method", preservationMethod==null?null:preservationMethod.getDefinedMaterialOrMethod(), style);
91 selection_storedUnder = formFactory.createSelectionElement(TaxonNameBase.class, getConversationHolder(), formElement, "Stored Under", entity.getStoredUnder(), EntitySelectionElement.ALL, style);
92
93 text_exsicatum = formFactory.createTextWithLabelElement(formElement, "Exsiccatum", entity.getExsiccatum(), style);
94
95 section_source = formFactory.createPreservedSpecimenSourceCollectionDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
96 section_source.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
97 section_source.setEntity(entity);
98 }
99
100 /** {@inheritDoc} */
101 @Override
102 public void handleEvent(Object eventSource) {
103 if (eventSource == text_derivedUnitDefinitions) {
104 getEntity().putDefinition(CdmStore.getDefaultLanguage(), text_derivedUnitDefinitions.getText());
105 } else if (eventSource == text_barcode) {
106 getEntity().setBarcode(text_barcode.getText());
107 } else if (eventSource == text_catalogNumber) {
108 getEntity().setCatalogNumber(text_catalogNumber.getText());
109 } else if (eventSource == combo_preservationMethod) {
110 PreservationMethod preservationMethod = getEntity().getPreservation();
111 if(preservationMethod!=null){
112 preservationMethod.setDefinedMaterialOrMethod(combo_preservationMethod.getSelection());
113 }
114 } else if (eventSource == selection_storedUnder) {
115 getEntity().setStoredUnder(selection_storedUnder.getEntity());
116 } else if (eventSource == text_exsicatum) {
117 try {
118 getEntity().setExsiccatum(text_exsicatum.getText());
119 } catch (Exception e) {
120 MessagingUtils.error(this.getClass(), e);
121 }
122 }
123 }
124 }