3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.newWizard
;
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
.FieldUnitWizardPage
;
23 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.GatheringEventWizardPage
;
24 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.GeneralWizardPage
;
27 * <p>NewDerivedUnitBaseWizard class.</p>
30 * @created Jun 16, 2010
33 public class NewDerivedUnitBaseWizard
extends AbstractNewEntityWizard
<DerivedUnit
> {
34 private SpecimenOrObservationType specOrObsType
= null;
36 public NewDerivedUnitBaseWizard() {
40 public NewDerivedUnitBaseWizard(SpecimenOrObservationType specOrObsType
) {
42 this.specOrObsType
= specOrObsType
;
46 public void addPages() {
47 DerivedUnitFacade facade
= getFacade();
49 if(getEntity() != null) {
50 facade
= DerivedUnitFacade
.NewInstance(getEntity(), PreferencesUtil
.getDerivedUnitConfigurator());
51 facade
.getFieldUnit(true); //TODO: this is a temporary solution for the Campanula project as
52 //this ALWAYS needs a FieldUnit as root of the hierarchy
54 } catch (DerivedUnitFacadeNotSupportedException e
) {
55 // w should never get here
56 throw new IllegalStateException();
58 addPage(new GeneralWizardPage(formFactory
, getConversationHolder(), facade
));
59 addPage(new GatheringEventWizardPage(formFactory
, getConversationHolder(), facade
));
60 addPage(new FieldUnitWizardPage(formFactory
, getConversationHolder(), facade
));
61 addPage(new DerivedUnitBaseWizardPage(formFactory
, getConversationHolder(), facade
));
68 private DerivedUnitFacade
getFacade() {
70 if(getEntity() != null) {
71 return DerivedUnitFacade
.NewInstance(getEntity(), PreferencesUtil
.getDerivedUnitConfigurator());
73 } catch (DerivedUnitFacadeNotSupportedException e
) {
74 // w should never get here
75 throw new IllegalStateException();
81 * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#createNewEntity()
85 protected DerivedUnit
createNewEntity() {
86 if(specOrObsType
== null) {
87 return DerivedUnit
.NewInstance(SpecimenOrObservationType
.PreservedSpecimen
);
89 if(SpecimenOrObservationType
.Media
.equals(specOrObsType
) ||
90 ((specOrObsType
.getKindOf() != null) &&
91 specOrObsType
.getKindOf().equals(SpecimenOrObservationType
.Media
))) {
92 return MediaSpecimen
.NewInstance(SpecimenOrObservationType
.Media
);
94 return DerivedUnit
.NewInstance(specOrObsType
);
100 * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#saveEntity()
104 protected void saveEntity() {
105 CdmStore
.getService(IOccurrenceService
.class).saveOrUpdate(getEntity());
109 protected String
getEntityName() {