Project

General

Profile

Download (3.3 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.newWizard;
12

    
13
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
14
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
15
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
16
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
17
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
18
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
19
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseWizardPage;
22
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationWizardPage;
23
import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
24
import eu.etaxonomy.taxeditor.ui.section.occurrence.GeneralWizardPage;
25

    
26
/**
27
 * <p>NewDerivedUnitBaseWizard class.</p>
28
 *
29
 * @author n.hoffmann
30
 * @created Jun 16, 2010
31
 * @version 1.0
32
 */
33
public class NewDerivedUnitBaseWizard extends AbstractNewEntityWizard<DerivedUnit> {
34
	private SpecimenOrObservationType specOrObsType = null;
35

    
36
	public NewDerivedUnitBaseWizard() {
37
		super();
38
	}
39

    
40
	public NewDerivedUnitBaseWizard(SpecimenOrObservationType specOrObsType) {
41
		super();
42
		this.specOrObsType = specOrObsType;
43
	}
44
	/** {@inheritDoc} */
45
	@Override
46
    public void addPages() {
47
        DerivedUnitFacade derivedUnitFacade = null;
48
        try {
49
            if (getEntity() != null) {
50
                derivedUnitFacade = DerivedUnitFacade.NewInstance(getEntity(), PreferencesUtil.getDerivedUnitConfigurator());
51
            }
52
        } catch (DerivedUnitFacadeNotSupportedException e) {
53
            // we should never get here
54
            throw new IllegalStateException();
55
        }
56
        addPage(new GeneralWizardPage(formFactory, getConversationHolder(), derivedUnitFacade));
57
        addPage(new GatheringEventWizardPage(formFactory, getConversationHolder(), derivedUnitFacade));
58
        addPage(new FieldObservationWizardPage(formFactory, getConversationHolder(), derivedUnitFacade));
59
        addPage(new DerivedUnitBaseWizardPage(formFactory, getConversationHolder(), derivedUnitFacade));
60

    
61
    }
62

    
63
	/* (non-Javadoc)
64
	 * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#createNewEntity()
65
	 */
66
	/** {@inheritDoc} */
67
	@Override
68
	protected DerivedUnit createNewEntity() {
69
		if(specOrObsType == null) {
70
			return DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
71
		} else {
72
			if(SpecimenOrObservationType.Media.equals(specOrObsType) ||
73
					((specOrObsType.getKindOf() != null) &&
74
					specOrObsType.getKindOf().equals(SpecimenOrObservationType.Media))) {
75
				return MediaSpecimen.NewInstance(SpecimenOrObservationType.Media);
76
			} else {
77
				return DerivedUnit.NewInstance(specOrObsType);
78
			}
79
		}
80
	}
81

    
82
	/* (non-Javadoc)
83
	 * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#saveEntity()
84
	 */
85
	/** {@inheritDoc} */
86
	@Override
87
	protected void saveEntity() {
88
		CdmStore.getService(IOccurrenceService.class).saveOrUpdate(getEntity());
89
	}
90

    
91
	@Override
92
	protected String getEntityName() {
93
		return "Specimen";
94
	}
95

    
96

    
97
}
(5-5/17)