-// $Id$
-/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-
-package eu.etaxonomy.taxeditor.ui.section.occurrence;
-
-import org.eclipse.ui.forms.widgets.ExpandableComposite;
-
-import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
-import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator;
-import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
-import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
-
-/**
- * <p>DerivedUnitFacadeDetailElement class.</p>
- *
- * @author n.hoffmann
- * @created Jun 17, 2010
- * @version 1.0
- */
-public class DerivedUnitFacadeDetailElement extends AbstractCdmDetailElement<DerivedUnit> {
-
- private DerivedUnitFacade facade;
-
- private final DerivedUnitFacadeConfigurator configurator;
-
- private DerivedUnitGeneralDetailSection section_general;
- private GatheringEventDetailSection section_gatheringEvent;
- private DerivedUnitBaseDetailSection section_derivedUnitBase;
- private FieldUnitDetailSection section_fieldUnit;
-
- /**
- * <p>Constructor for DerivedUnitFacadeDetailElement.</p>
- *
- * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
- * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
- */
- public DerivedUnitFacadeDetailElement(CdmFormFactory formFactory,
- ICdmFormElement formElement) {
- super(formFactory, formElement);
- configurator = DerivedUnitFacadeConfigurator.NewInstance();
- configurator.setMoveDerivedUnitMediaToGallery(true);
- configurator.setMoveFieldObjectMediaToGallery(true);
- }
-
- /** {@inheritDoc} */
- @Override
- public void setEntity(DerivedUnit entity) {
- super.setEntity(entity);
- try {
- facade = DerivedUnitFacade.NewInstance(entity, configurator);
-
- section_general.setEntity(facade);
- section_derivedUnitBase.setEntity(facade);
- section_gatheringEvent.setEntity(facade);
- section_fieldUnit.setEntity(facade);
-
- } catch (DerivedUnitFacadeNotSupportedException e) {
- MessagingUtils.messageDialog("Error", this, "SpecimenFacadeNotSupportedException while inititating SpecimenFacade", e);
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public void removeElements() {
- super.removeElements();
- if(section_general != null){
- removeControl(section_general);
- section_general.dispose();
- section_general = null;
- }
- if(section_derivedUnitBase != null){
- removeControl(section_derivedUnitBase);
- section_derivedUnitBase.dispose();
- section_derivedUnitBase = null;
- }
- if(section_gatheringEvent != null){
- removeControl(section_gatheringEvent);
- section_gatheringEvent.dispose();
- section_gatheringEvent = null;
- }
- if(section_fieldUnit != null){
- removeControl(section_fieldUnit);
- section_fieldUnit.dispose();
- section_fieldUnit = null;
- }
- }
-
- /** {@inheritDoc} */
- @Override
- public DerivedUnit getEntity() {
- throw new IllegalArgumentException("Should not be called");
- }
-
- /**
- * <p>Getter for the field <code>facade</code>.</p>
- *
- * @return a {@link eu.etaxonomy.cdm.api.facade.DerivedUnitFacade} object.
- */
- public DerivedUnitFacade getFacade(){
- return facade;
- }
-
- /** {@inheritDoc} */
- @Override
- protected void createControls(ICdmFormElement formElement,
- DerivedUnit entity, int style) {
-
- section_general = formFactory.createDerivedUnitGeneralDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
- section_general.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
- addControl(section_general);
- addElement(section_general);
-
- section_gatheringEvent = formFactory.createGatheringEventDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
- section_gatheringEvent.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
- addControl(section_gatheringEvent);
- addElement(section_gatheringEvent);
-
- section_fieldUnit = formFactory.createFieldUnitDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
- section_fieldUnit.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
- addControl(section_fieldUnit);
- addElement(section_fieldUnit);
-
- section_derivedUnitBase = formFactory.createDerivedUnitBaseDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
- section_derivedUnitBase.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
- addControl(section_derivedUnitBase);
- addElement(section_derivedUnitBase);
- }
-
- /** {@inheritDoc} */
- @Override
- public void handleEvent(Object eventSource) {
- if(eventSource == section_derivedUnitBase || eventSource == section_gatheringEvent || eventSource == section_fieldUnit){
- if(getParentElement() instanceof AbstractCdmDetailSection) {
- ((AbstractCdmDetailSection) getParentElement()).updateTitle();
- }
- }
- }
-}