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 org
.eclipse
.core
.runtime
.IStatus
;
14 import org
.eclipse
.jface
.wizard
.Wizard
;
15 import org
.eclipse
.jface
.wizard
.WizardDialog
;
16 import org
.eclipse
.swt
.events
.SelectionEvent
;
17 import org
.eclipse
.swt
.events
.SelectionListener
;
19 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
20 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeNotSupportedException
;
21 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
23 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
24 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
25 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.User
;
27 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
28 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
29 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
30 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
31 import eu
.etaxonomy
.taxeditor
.model
.TextHelper
;
32 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
33 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
34 import eu
.etaxonomy
.taxeditor
.ui
.campanula
.compatibility
.IEntitySelectionElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
36 import eu
.etaxonomy
.taxeditor
.ui
.section
.agent
.InstitutionWizardPage
;
37 import eu
.etaxonomy
.taxeditor
.ui
.section
.agent
.PersonWizardPage
;
38 import eu
.etaxonomy
.taxeditor
.ui
.section
.agent
.TeamWizardPage
;
39 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.NonViralNameWizardPage
;
40 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.CollectionWizardPage
;
41 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.DerivedUnitBaseWizardPage
;
42 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.FieldObservationWizardPage
;
43 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.GatheringEventWizardPage
;
44 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.GeneralWizardPage
;
45 import eu
.etaxonomy
.taxeditor
.ui
.section
.reference
.ReferenceWizardPage
;
46 import eu
.etaxonomy
.taxeditor
.ui
.section
.user
.UserDetailWizardPage
;
50 * EditFromSelectionWizard class.
54 * @created Jun 1, 2010
57 public class EditFromSelectionWizard
extends Wizard
implements
60 private final IEntitySelectionElement selectionElement
;
64 * Constructor for EditFromSelectionWizard.
67 * @param selectionElement
69 * {@link eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement}
72 public EditFromSelectionWizard(IEntitySelectionElement selectionElement
) {
73 this.selectionElement
= selectionElement
;
74 this.setWindowTitle(String
.format("Edit %s", TextHelper
.deproxyClassName(selectionElement
.getEntity().getClass())));
79 public void addPages() {
81 CdmFormFactory formFactory
= selectionElement
.getFormFactory();
82 ICdmBase entity
= (ICdmBase
) HibernateProxyHelper
83 .deproxy(selectionElement
.getEntity());
85 if (entity
instanceof Reference
) {
86 addPage(new ReferenceWizardPage(formFactory
,
87 selectionElement
.getConversationHolder(),
89 } else if (entity
instanceof Team
) {
90 addPage(new TeamWizardPage(formFactory
,
91 selectionElement
.getConversationHolder(), (Team
) entity
));
92 } else if (entity
instanceof Person
) {
93 addPage(new PersonWizardPage(formFactory
,
94 selectionElement
.getConversationHolder(), (Person
) entity
));
95 } else if (entity
instanceof NonViralName
) {
96 addPage(new NonViralNameWizardPage(formFactory
,
97 selectionElement
.getConversationHolder(),
98 (NonViralName
) entity
));
99 } else if (entity
instanceof DerivedUnit
) {
101 DerivedUnitFacade facade
;
103 facade
= DerivedUnitFacade
.NewInstance(
104 (DerivedUnit
) entity
,
105 PreferencesUtil
.getDerivedUnitConfigurator());
106 } catch (DerivedUnitFacadeNotSupportedException e
) {
107 // we should never get here
108 throw new IllegalStateException();
111 addPage(new GeneralWizardPage(formFactory
,
112 selectionElement
.getConversationHolder(), facade
));
113 addPage(new GatheringEventWizardPage(formFactory
,
114 selectionElement
.getConversationHolder(), facade
));
115 addPage(new FieldObservationWizardPage(formFactory
,
116 selectionElement
.getConversationHolder(), facade
));
117 addPage(new DerivedUnitBaseWizardPage(formFactory
,
118 selectionElement
.getConversationHolder(), facade
));
119 } else if (entity
instanceof Collection
) {
120 addPage(new CollectionWizardPage(formFactory
,
121 selectionElement
.getConversationHolder(),
122 (Collection
) entity
));
123 } else if (entity
instanceof Institution
) {
124 addPage(new InstitutionWizardPage(formFactory
,
125 selectionElement
.getConversationHolder(),
126 (Institution
) entity
));
127 } else if (entity
instanceof User
) {
128 addPage(new UserDetailWizardPage(formFactory
,
129 selectionElement
.getConversationHolder(),
132 StoreUtil
.warningDialog("Missing interface", this,
133 "No detail element for current selection");
141 * @see org.eclipse.jface.wizard.Wizard#performFinish()
145 public boolean performFinish() {
151 public void widgetSelected(SelectionEvent e
) {
152 WizardDialog dialog
= new WizardDialog(selectionElement
.getShell(),
154 if (dialog
.open() == IStatus
.OK
) {
155 selectionElement
.updateFromWizard();
161 public void widgetDefaultSelected(SelectionEvent e
) {