- quick-fix for DerivateView: always create a FieldUnit when creating a DerivedUnitF...
[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.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;
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 facade = getFacade();
48 try {
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
53 }
54 } catch (DerivedUnitFacadeNotSupportedException e) {
55 // w should never get here
56 throw new IllegalStateException();
57 }
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));
62
63 }
64
65 /**
66 * @return
67 */
68 private DerivedUnitFacade getFacade() {
69 try {
70 if(getEntity() != null) {
71 return DerivedUnitFacade.NewInstance(getEntity(), PreferencesUtil.getDerivedUnitConfigurator());
72 }
73 } catch (DerivedUnitFacadeNotSupportedException e) {
74 // w should never get here
75 throw new IllegalStateException();
76 }
77 return null;
78 }
79
80 /* (non-Javadoc)
81 * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#createNewEntity()
82 */
83 /** {@inheritDoc} */
84 @Override
85 protected DerivedUnit createNewEntity() {
86 if(specOrObsType == null) {
87 return DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
88 } else {
89 if(SpecimenOrObservationType.Media.equals(specOrObsType) ||
90 ((specOrObsType.getKindOf() != null) &&
91 specOrObsType.getKindOf().equals(SpecimenOrObservationType.Media))) {
92 return MediaSpecimen.NewInstance(SpecimenOrObservationType.Media);
93 } else {
94 return DerivedUnit.NewInstance(specOrObsType);
95 }
96 }
97 }
98
99 /* (non-Javadoc)
100 * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#saveEntity()
101 */
102 /** {@inheritDoc} */
103 @Override
104 protected void saveEntity() {
105 CdmStore.getService(IOccurrenceService.class).saveOrUpdate(getEntity());
106 }
107
108 @Override
109 protected String getEntityName() {
110 return "Specimen";
111 }
112
113
114 }