Project

General

Profile

Download (5.32 KB) Statistics
| Branch: | Tag: | Revision:
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.DerivedUnitFacadeConfigurator;
17
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
18
import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
19
import eu.etaxonomy.taxeditor.model.AbstractUtility;
20
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
21
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
22
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
23
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
24
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
25

    
26
/**
27
 * <p>DerivedUnitFacadeDetailElement class.</p>
28
 *
29
 * @author n.hoffmann
30
 * @created Jun 17, 2010
31
 * @version 1.0
32
 */
33
public class DerivedUnitFacadeDetailElement extends AbstractCdmDetailElement<DerivedUnitBase> {
34

    
35
	private DerivedUnitFacade facade;
36

    
37
	private final DerivedUnitFacadeConfigurator configurator;
38

    
39
	private GeneralDetailSection section_general;
40
	private GatheringEventDetailSection section_gatheringEvent;
41
	private DerivedUnitBaseDetailSection section_derivedUnitBase;
42
	private FieldObservationDetailSection section_fieldObservation;
43

    
44
	/**
45
	 * <p>Constructor for DerivedUnitFacadeDetailElement.</p>
46
	 *
47
	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
48
	 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
49
	 */
50
	public DerivedUnitFacadeDetailElement(CdmFormFactory formFactory,
51
			ICdmFormElement formElement) {
52
		super(formFactory, formElement);
53
		configurator = DerivedUnitFacadeConfigurator.NewInstance();
54
		configurator.setMoveDerivedUnitMediaToGallery(true);
55
		configurator.setMoveFieldObjectMediaToGallery(true);
56
	}
57

    
58
	/** {@inheritDoc} */
59
	@Override
60
	public void setEntity(DerivedUnitBase entity) {
61
		super.setEntity(entity);
62
		try {
63
			facade = DerivedUnitFacade.NewInstance(entity, configurator);
64

    
65
			section_general.setEntity(facade);
66
			section_derivedUnitBase.setEntity(facade);
67
			section_gatheringEvent.setEntity(facade);
68
			section_fieldObservation.setEntity(facade);
69

    
70
		} catch (DerivedUnitFacadeNotSupportedException e) {
71
			AbstractUtility.errorDialog("Error", this, "SpecimenFacadeNotSupportedException while inititating SpecimenFacade", e);
72
		}
73
	}
74

    
75
	/** {@inheritDoc} */
76
	@Override
77
	public void removeElements() {
78
		super.removeElements();
79
		if(section_general != null){
80
			removeControl(section_general);
81
			section_general.dispose();
82
			section_general = null;
83
		}
84
		if(section_derivedUnitBase != null){
85
			removeControl(section_derivedUnitBase);
86
			section_derivedUnitBase.dispose();
87
			section_derivedUnitBase = null;
88
		}
89
		if(section_gatheringEvent != null){
90
			removeControl(section_gatheringEvent);
91
			section_gatheringEvent.dispose();
92
			section_gatheringEvent = null;
93
		}
94
		if(section_fieldObservation != null){
95
			removeControl(section_fieldObservation);
96
			section_fieldObservation.dispose();
97
			section_fieldObservation = null;
98
		}
99
	}
100

    
101
	/** {@inheritDoc} */
102
	@Override
103
	public DerivedUnitBase getEntity() {
104
		throw new IllegalArgumentException("Should not be called");
105
	}
106

    
107
	/**
108
	 * <p>Getter for the field <code>facade</code>.</p>
109
	 *
110
	 * @return a {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade} object.
111
	 */
112
	public DerivedUnitFacade getFacade(){
113
		return facade;
114
	}
115

    
116
	/** {@inheritDoc} */
117
	@Override
118
	protected void createControls(ICdmFormElement formElement,
119
			DerivedUnitBase entity, int style) {
120

    
121
		section_general = formFactory.createGeneralDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
122
		section_general.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
123
		addControl(section_general);
124
		addElement(section_general);
125

    
126
		section_gatheringEvent = formFactory.createGatheringEventDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
127
		section_gatheringEvent.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
128
		addControl(section_gatheringEvent);
129
		addElement(section_gatheringEvent);
130

    
131
		section_fieldObservation = formFactory.createFieldObservationDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
132
		section_fieldObservation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
133
		addControl(section_fieldObservation);
134
		addElement(section_fieldObservation);
135

    
136
		section_derivedUnitBase = formFactory.createDerivedUnitBaseDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
137
		section_derivedUnitBase.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
138
		addControl(section_derivedUnitBase);
139
		addElement(section_derivedUnitBase);
140
	}
141

    
142
	/** {@inheritDoc} */
143
	@Override
144
	public void handleEvent(Object eventSource) {
145
		if(eventSource == section_derivedUnitBase || eventSource == section_gatheringEvent || eventSource == section_fieldObservation){
146
			if(getParentElement() instanceof AbstractCdmDetailSection) {
147
                ((AbstractCdmDetailSection) getParentElement()).updateTitle();
148
            }
149
		}
150
	}
151
}
(10-10/29)