Project

General

Profile

Download (4.31 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.FieldUnit;
18
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
19
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
20
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
21
import eu.etaxonomy.taxeditor.model.IDerivedUnitFacadePart;
22
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseWizardPage;
25
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitGeneralWizardPage;
26
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitGeneralWizardPage;
27
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitWizardPage;
28
import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
29

    
30
/**
31
 * <p>NewDerivedUnitBaseWizard class.</p>
32
 *
33
 * @author n.hoffmann
34
 * @created Jun 16, 2010
35
 * @version 1.0
36
 */
37
public class NewDerivedUnitBaseWizard extends AbstractNewEntityWizard<SpecimenOrObservationBase> implements IDerivedUnitFacadePart{
38
	private SpecimenOrObservationType specOrObsType = null;
39

    
40
	public NewDerivedUnitBaseWizard() {
41
		super();
42
	}
43

    
44
	public NewDerivedUnitBaseWizard(SpecimenOrObservationType specOrObsType) {
45
		super();
46
		this.specOrObsType = specOrObsType;
47
	}
48
	/** {@inheritDoc} */
49
	@Override
50
	public void addPages() {
51
	    DerivedUnitFacade facade = null;
52
	    try {
53
	        if(getEntity() instanceof DerivedUnit) {
54
	            facade = DerivedUnitFacade.NewInstance((DerivedUnit)getEntity(), PreferencesUtil.getDerivedUnitConfigurator());
55
	            addPage(new DerivedUnitGeneralWizardPage(formFactory, getConversationHolder(), facade));
56
	            addPage(new GatheringEventWizardPage(formFactory, getConversationHolder(), facade));
57
	            addPage(new FieldUnitWizardPage(formFactory, getConversationHolder(), facade));
58
	            addPage(new DerivedUnitBaseWizardPage(formFactory, getConversationHolder(), facade));
59
	        }
60
	        else if(getEntity() instanceof FieldUnit){
61
	            facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit, (FieldUnit)getEntity(), PreferencesUtil.getDerivedUnitConfigurator());
62
	            addPage(new FieldUnitGeneralWizardPage(formFactory, getConversationHolder(), facade));
63
	            addPage(new GatheringEventWizardPage(formFactory, getConversationHolder(), facade));
64
	            addPage(new FieldUnitWizardPage(formFactory, getConversationHolder(), facade));
65
	        }
66
	    } catch (DerivedUnitFacadeNotSupportedException e) {
67
	        // we should never get here
68
	        throw new IllegalStateException();
69
	    }
70
	}
71

    
72
    /*
73
     * (non-Javadoc)
74
     *
75
     * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#
76
     * createNewEntity()
77
     */
78
    /** {@inheritDoc} */
79
    @Override
80
    protected SpecimenOrObservationBase createNewEntity() {
81
        if (specOrObsType == null) {
82
            return DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
83
        } else {
84
            if (SpecimenOrObservationType.Media.equals(specOrObsType)
85
                    || ((specOrObsType.getKindOf() != null) && specOrObsType.getKindOf().equals(SpecimenOrObservationType.Media))) {
86
	            return MediaSpecimen.NewInstance(specOrObsType);
87
            } else if (specOrObsType.equals(SpecimenOrObservationType.FieldUnit)) {
88
                return FieldUnit.NewInstance();
89
            } else {
90
                return DerivedUnit.NewInstance(specOrObsType);
91
            }
92
        }
93
    }
94

    
95
	/* (non-Javadoc)
96
	 * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#saveEntity()
97
	 */
98
	/** {@inheritDoc} */
99
	@Override
100
	protected void saveEntity() {
101
		CdmStore.getService(IOccurrenceService.class).saveOrUpdate(getEntity());
102
	}
103

    
104
	@Override
105
	protected String getEntityName() {
106
		return "Specimen";
107
	}
108

    
109

    
110
}
(9-9/23)