2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.newWizard
;
11 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
12 import eu
.etaxonomy
.cdm
.facade
.DerivedUnitFacade
;
13 import eu
.etaxonomy
.cdm
.facade
.DerivedUnitFacadeNotSupportedException
;
14 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
15 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
16 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
17 import eu
.etaxonomy
.cdm
.model
.occurrence
.MediaSpecimen
;
18 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
19 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
20 import eu
.etaxonomy
.taxeditor
.model
.IDerivedUnitFacadePart
;
21 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
22 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
23 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.DerivedUnitBaseWizardPage
;
24 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.DerivedUnitGeneralWizardPage
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.FieldUnitGeneralWizardPage
;
26 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.FieldUnitWizardPage
;
27 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.GatheringEventWizardPage
;
28 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.MediaSpecimenGeneralWizardPage
;
32 * @created Jun 16, 2010
34 public class NewDerivedUnitBaseWizard
35 extends AbstractNewEntityWizard
<SpecimenOrObservationBase
>
36 implements IDerivedUnitFacadePart
{
38 private SpecimenOrObservationType specOrObsType
= null;
40 public NewDerivedUnitBaseWizard() {
44 public NewDerivedUnitBaseWizard(SpecimenOrObservationType specOrObsType
) {
46 this.specOrObsType
= specOrObsType
;
50 public void addPages() {
51 DerivedUnitFacade facade
= null;
53 if(getEntity() instanceof DerivedUnit
) {
55 if (getEntity() instanceof MediaSpecimen
) {
56 addPage(new MediaSpecimenGeneralWizardPage(formFactory
, (MediaSpecimen
)getEntity()));
57 // addPage(new GatheringEventWizardPage(formFactory, facade));
58 // addPage(new FieldUnitWizardPage(formFactory, facade));
59 // addPage(new DerivedUnitBaseWizardPage(formFactory, facade));
61 facade
= DerivedUnitFacade
.NewInstance((DerivedUnit
)getEntity(), PreferencesUtil
.getDerivedUnitConfigurator());
62 addPage(new DerivedUnitGeneralWizardPage(formFactory
, facade
));
63 addPage(new GatheringEventWizardPage(formFactory
, facade
));
64 addPage(new FieldUnitWizardPage(formFactory
, facade
));
65 addPage(new DerivedUnitBaseWizardPage(formFactory
, facade
));
68 else if(getEntity() instanceof FieldUnit
){
69 facade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.FieldUnit
, (FieldUnit
)getEntity(), PreferencesUtil
.getDerivedUnitConfigurator());
70 addPage(new FieldUnitGeneralWizardPage(formFactory
, facade
));
71 addPage(new GatheringEventWizardPage(formFactory
, facade
));
72 addPage(new FieldUnitWizardPage(formFactory
, facade
));
74 } catch (DerivedUnitFacadeNotSupportedException e
) {
75 // we should never get here
76 throw new IllegalStateException();
81 protected SpecimenOrObservationBase
<?
> createNewEntity() {
82 if (specOrObsType
== null) {
83 return DerivedUnit
.NewInstance(SpecimenOrObservationType
.PreservedSpecimen
);
85 if (SpecimenOrObservationType
.Media
.equals(specOrObsType
)
86 || ((specOrObsType
.getKindOf() != null) && specOrObsType
.getKindOf().equals(SpecimenOrObservationType
.Media
))) {
87 MediaSpecimen mediaSpecimen
= MediaSpecimen
.NewInstance(specOrObsType
);
88 //a MediaSpecimen with no media attached does not make sense. Hence, we add one
89 mediaSpecimen
.setMediaSpecimen(Media
.NewInstance());
91 } else if (specOrObsType
.equals(SpecimenOrObservationType
.FieldUnit
)) {
92 return FieldUnit
.NewInstance();
94 return DerivedUnit
.NewInstance(specOrObsType
);
100 protected void saveEntity() {
101 setEntity(CdmStore
.getService(IOccurrenceService
.class).merge(getEntity()));
105 protected String
getEntityName() {