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.ui.selection;
|
12
|
|
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;
|
18
|
|
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.DerivedUnitBase;
|
30
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
31
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
32
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
33
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
34
|
import eu.etaxonomy.taxeditor.ui.section.agent.InstitutionWizardPage;
|
35
|
import eu.etaxonomy.taxeditor.ui.section.agent.PersonWizardPage;
|
36
|
import eu.etaxonomy.taxeditor.ui.section.agent.TeamWizardPage;
|
37
|
import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameWizardPage;
|
38
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.CollectionWizardPage;
|
39
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseWizardPage;
|
40
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationWizardPage;
|
41
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
|
42
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.GeneralWizardPage;
|
43
|
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceWizardPage;
|
44
|
import eu.etaxonomy.taxeditor.ui.section.user.UserDetailWizardPage;
|
45
|
|
46
|
/**
|
47
|
* <p>
|
48
|
* EditFromSelectionWizard class.
|
49
|
* </p>
|
50
|
*
|
51
|
* @author n.hoffmann
|
52
|
* @created Jun 1, 2010
|
53
|
* @version 1.0
|
54
|
*/
|
55
|
public class EditFromSelectionWizard extends Wizard implements
|
56
|
SelectionListener {
|
57
|
|
58
|
private final AbstractSelectionElement selectionElement;
|
59
|
|
60
|
/**
|
61
|
* <p>
|
62
|
* Constructor for EditFromSelectionWizard.
|
63
|
* </p>
|
64
|
*
|
65
|
* @param selectionElement
|
66
|
* a
|
67
|
* {@link eu.etaxonomy.taxeditor.ui.selection.AbstractSelectionElement}
|
68
|
* object.
|
69
|
*/
|
70
|
public EditFromSelectionWizard(AbstractSelectionElement selectionElement) {
|
71
|
this.selectionElement = selectionElement;
|
72
|
this.setWindowTitle("Edit Entity");
|
73
|
}
|
74
|
|
75
|
/** {@inheritDoc} */
|
76
|
@Override
|
77
|
public void addPages() {
|
78
|
|
79
|
CdmFormFactory formFactory = selectionElement.getFormFactory();
|
80
|
ICdmBase entity = (ICdmBase) HibernateProxyHelper
|
81
|
.deproxy(selectionElement.getEntity());
|
82
|
|
83
|
if (entity instanceof Reference) {
|
84
|
addPage(new ReferenceWizardPage(formFactory,
|
85
|
selectionElement.getConversationHolder(),
|
86
|
(Reference) entity));
|
87
|
} else if (entity instanceof Team) {
|
88
|
addPage(new TeamWizardPage(formFactory,
|
89
|
selectionElement.getConversationHolder(), (Team) entity));
|
90
|
} else if (entity instanceof Person) {
|
91
|
addPage(new PersonWizardPage(formFactory,
|
92
|
selectionElement.getConversationHolder(), (Person) entity));
|
93
|
} else if (entity instanceof NonViralName) {
|
94
|
addPage(new NonViralNameWizardPage(formFactory,
|
95
|
selectionElement.getConversationHolder(),
|
96
|
(NonViralName) entity));
|
97
|
} else if (entity instanceof DerivedUnitBase) {
|
98
|
|
99
|
DerivedUnitFacade facade;
|
100
|
try {
|
101
|
facade = DerivedUnitFacade.NewInstance(
|
102
|
(DerivedUnitBase) entity,
|
103
|
PreferencesUtil.getDerivedUnitConfigurator());
|
104
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
105
|
// we should never get here
|
106
|
throw new IllegalStateException();
|
107
|
}
|
108
|
|
109
|
addPage(new GeneralWizardPage(formFactory,
|
110
|
selectionElement.getConversationHolder(), facade));
|
111
|
addPage(new GatheringEventWizardPage(formFactory,
|
112
|
selectionElement.getConversationHolder(), facade));
|
113
|
addPage(new FieldObservationWizardPage(formFactory,
|
114
|
selectionElement.getConversationHolder(), facade));
|
115
|
addPage(new DerivedUnitBaseWizardPage(formFactory,
|
116
|
selectionElement.getConversationHolder(), facade));
|
117
|
} else if (entity instanceof Collection) {
|
118
|
addPage(new CollectionWizardPage(formFactory,
|
119
|
selectionElement.getConversationHolder(),
|
120
|
(Collection) entity));
|
121
|
} else if (entity instanceof Institution) {
|
122
|
addPage(new InstitutionWizardPage(formFactory,
|
123
|
selectionElement.getConversationHolder(),
|
124
|
(Institution) entity));
|
125
|
} else if (entity instanceof User) {
|
126
|
addPage(new UserDetailWizardPage(formFactory,
|
127
|
selectionElement.getConversationHolder(),
|
128
|
(User) entity));
|
129
|
} else {
|
130
|
StoreUtil.warningDialog("Missing interface", this,
|
131
|
"No detail element for current selection");
|
132
|
}
|
133
|
|
134
|
}
|
135
|
|
136
|
/*
|
137
|
* (non-Javadoc)
|
138
|
*
|
139
|
* @see org.eclipse.jface.wizard.Wizard#performFinish()
|
140
|
*/
|
141
|
/** {@inheritDoc} */
|
142
|
@Override
|
143
|
public boolean performFinish() {
|
144
|
return true;
|
145
|
}
|
146
|
|
147
|
/** {@inheritDoc} */
|
148
|
@Override
|
149
|
public void widgetSelected(SelectionEvent e) {
|
150
|
WizardDialog dialog = new WizardDialog(selectionElement.getShell(),
|
151
|
this);
|
152
|
if (dialog.open() == IStatus.OK) {
|
153
|
selectionElement.updateFromWizard();
|
154
|
}
|
155
|
}
|
156
|
|
157
|
/** {@inheritDoc} */
|
158
|
@Override
|
159
|
public void widgetDefaultSelected(SelectionEvent e) {
|
160
|
}
|
161
|
}
|