merging in latest changes from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / DerivedUnitFacadeDetailElement.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.Section;
14
15 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
16 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator;
17 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
18 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
19 import eu.etaxonomy.taxeditor.store.StoreUtil;
20 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
21 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
22 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType;
23 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
24 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
25 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
26
27 /**
28 * <p>DerivedUnitFacadeDetailElement class.</p>
29 *
30 * @author n.hoffmann
31 * @created Jun 17, 2010
32 * @version 1.0
33 */
34 public class DerivedUnitFacadeDetailElement extends AbstractCdmDetailElement<DerivedUnitBase> {
35
36 private DerivedUnitFacade facade;
37
38 private DerivedUnitFacadeConfigurator configurator;
39
40 private GeneralDetailSection section_general;
41 private GatheringEventDetailSection section_gatheringEvent;
42 private DerivedUnitBaseDetailSection section_derivedUnitBase;
43 private FieldObservationDetailSection section_fieldObservation;
44
45 /**
46 * <p>Constructor for DerivedUnitFacadeDetailElement.</p>
47 *
48 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
49 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
50 */
51 public DerivedUnitFacadeDetailElement(CdmFormFactory formFactory,
52 ICdmFormElement formElement) {
53 super(formFactory, formElement);
54 configurator = DerivedUnitFacadeConfigurator.NewInstance();
55 configurator.setMoveDerivedUnitMediaToGallery(true);
56 configurator.setMoveFieldObjectMediaToGallery(true);
57 }
58
59 /** {@inheritDoc} */
60 @Override
61 public void setEntity(DerivedUnitBase entity) {
62 super.setEntity(entity);
63 try {
64 facade = DerivedUnitFacade.NewInstance(entity, configurator);
65
66 section_general.setEntity(facade);
67 section_derivedUnitBase.setEntity(facade);
68 section_gatheringEvent.setEntity(facade);
69 section_fieldObservation.setEntity(facade);
70
71 } catch (DerivedUnitFacadeNotSupportedException e) {
72 StoreUtil.errorDialog("Error", this, "SpecimenFacadeNotSupportedException while inititating SpecimenFacade", e);
73 }
74 }
75
76 /** {@inheritDoc} */
77 @Override
78 public void removeElements() {
79 super.removeElements();
80 if(section_general != null){
81 removeControl(section_general);
82 section_general.dispose();
83 section_general = null;
84 }
85 if(section_derivedUnitBase != null){
86 removeControl(section_derivedUnitBase);
87 section_derivedUnitBase.dispose();
88 section_derivedUnitBase = null;
89 }
90 if(section_gatheringEvent != null){
91 removeControl(section_gatheringEvent);
92 section_gatheringEvent.dispose();
93 section_gatheringEvent = null;
94 }
95 if(section_fieldObservation != null){
96 removeControl(section_fieldObservation);
97 section_fieldObservation.dispose();
98 section_fieldObservation = null;
99 }
100 }
101
102 /** {@inheritDoc} */
103 @Override
104 public DerivedUnitBase getEntity() {
105 throw new IllegalArgumentException("Should not be called");
106 }
107
108 /**
109 * <p>Getter for the field <code>facade</code>.</p>
110 *
111 * @return a {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade} object.
112 */
113 public DerivedUnitFacade getFacade(){
114 return facade;
115 }
116
117 /** {@inheritDoc} */
118 @Override
119 protected void createControls(ICdmFormElement formElement,
120 DerivedUnitBase entity, int style) {
121
122 section_general = (GeneralDetailSection) formFactory.createCdmDetailSection(DetailType.DERIVED_UNIT_GENERAL, getConversationHolder(), formElement, null, Section.TWISTIE | Section.EXPANDED);
123 section_general.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
124 addControl(section_general);
125 addElement(section_general);
126
127 section_gatheringEvent = (GatheringEventDetailSection) formFactory.createCdmDetailSection(DetailType.GATHERING_EVENT, getConversationHolder(), formElement, null, Section.TWISTIE);
128 section_gatheringEvent.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
129 addControl(section_gatheringEvent);
130 addElement(section_gatheringEvent);
131
132 section_fieldObservation = (FieldObservationDetailSection) formFactory.createCdmDetailSection(DetailType.FIELD_OBSERVATION, getConversationHolder(), formElement, null, Section.TWISTIE);
133 section_fieldObservation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
134 addControl(section_fieldObservation);
135 addElement(section_fieldObservation);
136
137 section_derivedUnitBase = (DerivedUnitBaseDetailSection) formFactory.createCdmDetailSection(DetailType.DERIVED_UNIT, getConversationHolder(), formElement, null, Section.TWISTIE);
138 section_derivedUnitBase.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
139 addControl(section_derivedUnitBase);
140 addElement(section_derivedUnitBase);
141 }
142
143 /** {@inheritDoc} */
144 @Override
145 public void handleEvent(Object eventSource) {
146 if(eventSource == section_derivedUnitBase || eventSource == section_gatheringEvent || eventSource == section_fieldObservation){
147 if(getParentElement() instanceof AbstractCdmDetailSection)
148 ((AbstractCdmDetailSection) getParentElement()).updateTitle();
149 }
150 }
151 }