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.
10 package eu
.etaxonomy
.taxeditor
.ui
.selection
;
12 import java
.util
.Collections
;
13 import java
.util
.List
;
16 import org
.eclipse
.core
.runtime
.IStatus
;
17 import org
.eclipse
.jface
.wizard
.Wizard
;
18 import org
.eclipse
.jface
.wizard
.WizardDialog
;
19 import org
.eclipse
.swt
.events
.SelectionEvent
;
20 import org
.eclipse
.swt
.events
.SelectionListener
;
22 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
23 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeNotSupportedException
;
24 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
25 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
26 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
27 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
28 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
29 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
30 import eu
.etaxonomy
.cdm
.model
.common
.User
;
31 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
32 import eu
.etaxonomy
.cdm
.model
.molecular
.Amplification
;
33 import eu
.etaxonomy
.cdm
.model
.molecular
.Primer
;
34 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
35 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
36 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
37 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
38 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
39 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
40 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
41 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
42 import eu
.etaxonomy
.taxeditor
.model
.TextHelper
;
43 import eu
.etaxonomy
.taxeditor
.newWizard
.AmplificationGeneralWizardPage
;
44 import eu
.etaxonomy
.taxeditor
.newWizard
.PolytomousKeyWizardPage
;
45 import eu
.etaxonomy
.taxeditor
.newWizard
.PrimerWizardPage
;
46 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
47 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySession
;
48 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
49 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
50 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
51 import eu
.etaxonomy
.taxeditor
.ui
.section
.agent
.InstitutionWizardPage
;
52 import eu
.etaxonomy
.taxeditor
.ui
.section
.agent
.PersonWizardPage
;
53 import eu
.etaxonomy
.taxeditor
.ui
.section
.agent
.TeamWizardPage
;
54 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.NonViralNameWizardPage
;
55 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.CollectionWizardPage
;
56 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.DerivedUnitBaseWizardPage
;
57 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.DerivedUnitGeneralWizardPage
;
58 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.FieldUnitWizardPage
;
59 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.GatheringEventWizardPage
;
60 import eu
.etaxonomy
.taxeditor
.ui
.section
.reference
.ReferenceWizardPage
;
61 import eu
.etaxonomy
.taxeditor
.ui
.section
.user
.UserDetailWizardPage
;
65 * @created Jun 1, 2010
68 public class EditFromSelectionWizard
extends Wizard
implements
69 SelectionListener
, ICdmEntitySessionEnabled
{
71 private ICdmEntitySession cdmEntitySession
;
72 private ICdmEntitySession previousCdmEntitySession
;
73 private final EntitySelectionElement selectionElement
;
74 private CdmBase rootElement
;
76 public EditFromSelectionWizard(EntitySelectionElement selectionElement
) {
77 if (CdmStore
.isActive()) {
78 previousCdmEntitySession
= CdmStore
.getCurrentSessionManager().getActiveSession();
79 cdmEntitySession
= CdmStore
.getCurrentSessionManager().newSession(this, true);
80 cdmEntitySession
.bind();
82 this.selectionElement
= selectionElement
;
83 this.setWindowTitle(String
.format("Edit %s", TextHelper
.deproxyClassName(selectionElement
.getEntity().getClass())));
88 public void addPages() {
90 CdmFormFactory formFactory
= selectionElement
.getFormFactory();
91 CdmBase entity
= HibernateProxyHelper
92 .deproxy(selectionElement
.getEntity());
93 //check if entity has already been persisted
94 if(entity
.getId()==0){
98 IService
<CdmBase
> service
= CdmStore
.getService(entity
);
99 rootElement
= service
.load(entity
.getUuid());
101 if (rootElement
.isInstanceOf(Reference
.class)) {
102 addPage(new ReferenceWizardPage(formFactory
,
103 selectionElement
.getConversationHolder(),
104 (HibernateProxyHelper
.deproxy(rootElement
, Reference
.class))));
105 } else if (rootElement
.isInstanceOf(Team
.class) && selectionElement
instanceof EntitySelectionElementWithAbbreviatedTitle
<?
>) {
106 addPage(new TeamWizardPage(formFactory
,
107 selectionElement
.getConversationHolder(), HibernateProxyHelper
.deproxy(rootElement
, Team
.class), true));
108 } else if (rootElement
.isInstanceOf(Team
.class) && !(selectionElement
instanceof EntitySelectionElementWithAbbreviatedTitle
<?
>)) {
109 addPage(new TeamWizardPage(formFactory
,
110 selectionElement
.getConversationHolder(), HibernateProxyHelper
.deproxy(rootElement
, Team
.class), false));
111 } else if (rootElement
.isInstanceOf(Person
.class)) {
112 addPage(new PersonWizardPage(formFactory
,
113 selectionElement
.getConversationHolder(), HibernateProxyHelper
.deproxy(rootElement
, Person
.class)));
114 } else if (rootElement
.isInstanceOf(NonViralName
.class)) {
115 addPage(new NonViralNameWizardPage(formFactory
,
116 selectionElement
.getConversationHolder(),
117 HibernateProxyHelper
.deproxy(rootElement
, NonViralName
.class)));
118 } else if (rootElement
.isInstanceOf(SpecimenOrObservationBase
.class)) {
120 DerivedUnitFacade facade
;
122 if(rootElement
.isInstanceOf(DerivedUnit
.class)){
123 facade
= DerivedUnitFacade
.NewInstance(
124 HibernateProxyHelper
.deproxy(rootElement
, DerivedUnit
.class),
125 PreferencesUtil
.getDerivedUnitConfigurator());
128 facade
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.FieldUnit
,
129 HibernateProxyHelper
.deproxy(rootElement
, FieldUnit
.class),
130 PreferencesUtil
.getDerivedUnitConfigurator());
133 } catch (DerivedUnitFacadeNotSupportedException e
) {
134 // we should never get here
135 throw new IllegalStateException();
138 addPage(new DerivedUnitGeneralWizardPage(formFactory
,
139 selectionElement
.getConversationHolder(), facade
));
140 addPage(new GatheringEventWizardPage(formFactory
,
141 selectionElement
.getConversationHolder(), facade
));
142 addPage(new FieldUnitWizardPage(formFactory
,
143 selectionElement
.getConversationHolder(), facade
));
144 if(facade
.innerDerivedUnit()!=null){
145 addPage(new DerivedUnitBaseWizardPage(formFactory
,
146 selectionElement
.getConversationHolder(), facade
));
148 } else if (rootElement
.isInstanceOf(Collection
.class)) {
149 addPage(new CollectionWizardPage(formFactory
,
150 selectionElement
.getConversationHolder(),
151 HibernateProxyHelper
.deproxy(rootElement
, Collection
.class)));
152 } else if (rootElement
instanceof Institution
) {
153 addPage(new InstitutionWizardPage(formFactory
,
154 selectionElement
.getConversationHolder(),
155 HibernateProxyHelper
.deproxy(rootElement
, Institution
.class)));
156 } else if (rootElement
instanceof User
) {
157 addPage(new UserDetailWizardPage(formFactory
,
158 selectionElement
.getConversationHolder(),
159 HibernateProxyHelper
.deproxy(rootElement
, User
.class)));
160 } else if (rootElement
instanceof Primer
) {
161 addPage(new PrimerWizardPage(formFactory
,
162 selectionElement
.getConversationHolder(),
163 HibernateProxyHelper
.deproxy(rootElement
, Primer
.class)));
164 } else if (rootElement
instanceof Amplification
) {
165 addPage(new AmplificationGeneralWizardPage(formFactory
,
166 selectionElement
.getConversationHolder(),
167 HibernateProxyHelper
.deproxy(rootElement
, Amplification
.class)));
168 } else if (rootElement
instanceof PolytomousKey
) {
169 addPage(new PolytomousKeyWizardPage(formFactory
,
170 selectionElement
.getConversationHolder(),
171 HibernateProxyHelper
.deproxy(rootElement
, PolytomousKey
.class)));
173 MessagingUtils
.warningDialog("Missing interface", this,
174 "No detail element for current selection");
181 public boolean performFinish() {
182 IService
<CdmBase
> service
= CdmStore
.getService(rootElement
);
183 if(rootElement
.getId()!=0){
184 service
.merge(rootElement
, true);
187 rootElement
= service
.save(rootElement
);
189 if(previousCdmEntitySession
!=null){
190 selectionElement
.setEntity(previousCdmEntitySession
.load(rootElement
, true));
198 public void widgetSelected(SelectionEvent e
) {
199 WizardDialog dialog
= new WizardDialog(selectionElement
.getShell(),
201 if (dialog
.open() == IStatus
.OK
) {
202 selectionElement
.updateFromWizard();
208 public void widgetDefaultSelected(SelectionEvent e
) {
212 public void dispose() {
214 if(cdmEntitySession
!= null) {
215 cdmEntitySession
.dispose();
217 if(previousCdmEntitySession
!=null){
218 previousCdmEntitySession
.bind();
223 public ICdmEntitySession
getCdmEntitySession() {
224 return cdmEntitySession
;
228 public java
.util
.Collection
<CdmBase
> getRootEntities() {
229 return Collections
.singleton(rootElement
);
233 public Map
<Object
, List
<String
>> getPropertyPathsMap() {