merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / newWizard / NewDerivedUnitBaseWizard.java
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.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
29 /**
30 * <p>NewDerivedUnitBaseWizard class.</p>
31 *
32 * @author n.hoffmann
33 * @created Jun 16, 2010
34 * @version 1.0
35 */
36 public class NewDerivedUnitBaseWizard extends AbstractNewEntityWizard<SpecimenOrObservationBase> {
37 private SpecimenOrObservationType specOrObsType = null;
38
39 public NewDerivedUnitBaseWizard() {
40 super();
41 }
42
43 public NewDerivedUnitBaseWizard(SpecimenOrObservationType specOrObsType) {
44 super();
45 this.specOrObsType = specOrObsType;
46 }
47 /** {@inheritDoc} */
48 @Override
49 public void addPages() {
50 DerivedUnitFacade facade = null;
51 try {
52 if(getEntity() instanceof DerivedUnit) {
53 facade = DerivedUnitFacade.NewInstance((DerivedUnit)getEntity(), PreferencesUtil.getDerivedUnitConfigurator());
54 facade.getFieldUnit(true); //TODO: this is a temporary solution for the Campanula project as
55 //this ALWAYS needs a FieldUnit as root of the hierarchy
56
57 addPage(new DerivedUnitGeneralWizardPage(formFactory, getConversationHolder(), facade));
58 addPage(new GatheringEventWizardPage(formFactory, getConversationHolder(), facade));
59 addPage(new FieldUnitWizardPage(formFactory, getConversationHolder(), facade));
60 addPage(new DerivedUnitBaseWizardPage(formFactory, getConversationHolder(), facade));
61 }
62 else if(getEntity() instanceof FieldUnit){
63 facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit, (FieldUnit)getEntity(), PreferencesUtil.getDerivedUnitConfigurator());
64 addPage(new FieldUnitGeneralWizardPage(formFactory, getConversationHolder(), facade));
65 addPage(new GatheringEventWizardPage(formFactory, getConversationHolder(), facade));
66 addPage(new FieldUnitWizardPage(formFactory, getConversationHolder(), facade));
67 }
68 } catch (DerivedUnitFacadeNotSupportedException e) {
69 // we should never get here
70 throw new IllegalStateException();
71 }
72 }
73
74 /*
75 * (non-Javadoc)
76 *
77 * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#
78 * createNewEntity()
79 */
80 /** {@inheritDoc} */
81 @Override
82 protected SpecimenOrObservationBase createNewEntity() {
83 if (specOrObsType == null) {
84 return DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
85 } else {
86 if (SpecimenOrObservationType.Media.equals(specOrObsType)
87 || ((specOrObsType.getKindOf() != null) && specOrObsType.getKindOf().equals(SpecimenOrObservationType.Media))) {
88 return MediaSpecimen.NewInstance(specOrObsType);
89 } else if (specOrObsType.equals(SpecimenOrObservationType.FieldUnit)) {
90 return FieldUnit.NewInstance();
91 } else {
92 return DerivedUnit.NewInstance(specOrObsType);
93 }
94 }
95 }
96
97 /* (non-Javadoc)
98 * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#saveEntity()
99 */
100 /** {@inheritDoc} */
101 @Override
102 protected void saveEntity() {
103 CdmStore.getService(IOccurrenceService.class).saveOrUpdate(getEntity());
104 }
105
106 @Override
107 protected String getEntityName() {
108 return "Specimen";
109 }
110
111
112 }