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