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
|
import org.eclipse.ui.IEditorPart;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
21
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
|
22
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
23
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
24
|
import eu.etaxonomy.cdm.model.agent.Person;
|
25
|
import eu.etaxonomy.cdm.model.agent.Team;
|
26
|
import eu.etaxonomy.cdm.model.common.ICdmBase;
|
27
|
import eu.etaxonomy.cdm.model.common.User;
|
28
|
import eu.etaxonomy.cdm.model.molecular.Amplification;
|
29
|
import eu.etaxonomy.cdm.model.molecular.Primer;
|
30
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
31
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
32
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
33
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
34
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
35
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
36
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
37
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
38
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
39
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
40
|
import eu.etaxonomy.taxeditor.model.TextHelper;
|
41
|
import eu.etaxonomy.taxeditor.newWizard.AmplificationGeneralWizardPage;
|
42
|
import eu.etaxonomy.taxeditor.newWizard.PrimerWizardPage;
|
43
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
44
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
45
|
import eu.etaxonomy.taxeditor.ui.section.agent.InstitutionWizardPage;
|
46
|
import eu.etaxonomy.taxeditor.ui.section.agent.PersonWizardPage;
|
47
|
import eu.etaxonomy.taxeditor.ui.section.agent.TeamWizardPage;
|
48
|
import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameWizardPage;
|
49
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.CollectionWizardPage;
|
50
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseWizardPage;
|
51
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitGeneralWizardPage;
|
52
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitWizardPage;
|
53
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
|
54
|
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceWizardPage;
|
55
|
import eu.etaxonomy.taxeditor.ui.section.user.UserDetailWizardPage;
|
56
|
|
57
|
/**
|
58
|
* <p>
|
59
|
* EditFromSelectionWizard class.
|
60
|
* </p>
|
61
|
*
|
62
|
* @author n.hoffmann
|
63
|
* @created Jun 1, 2010
|
64
|
* @version 1.0
|
65
|
*/
|
66
|
public class EditFromSelectionWizard extends Wizard implements
|
67
|
SelectionListener {
|
68
|
|
69
|
private final EntitySelectionElement selectionElement;
|
70
|
|
71
|
/**
|
72
|
* <p>
|
73
|
* Constructor for EditFromSelectionWizard.
|
74
|
* </p>
|
75
|
*
|
76
|
* @param selectionElement
|
77
|
* a
|
78
|
* {@link eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement}
|
79
|
* object.
|
80
|
*/
|
81
|
public EditFromSelectionWizard(EntitySelectionElement selectionElement) {
|
82
|
this.selectionElement = selectionElement;
|
83
|
this.setWindowTitle(String.format("Edit %s", TextHelper.deproxyClassName(selectionElement.getEntity().getClass())));
|
84
|
}
|
85
|
|
86
|
/** {@inheritDoc} */
|
87
|
@Override
|
88
|
public void addPages() {
|
89
|
|
90
|
CdmFormFactory formFactory = selectionElement.getFormFactory();
|
91
|
ICdmBase entity = (ICdmBase) HibernateProxyHelper
|
92
|
.deproxy(selectionElement.getEntity());
|
93
|
|
94
|
if (entity instanceof Reference) {
|
95
|
addPage(new ReferenceWizardPage(formFactory,
|
96
|
selectionElement.getConversationHolder(),
|
97
|
(Reference) entity));
|
98
|
} else if (entity instanceof Team) {
|
99
|
addPage(new TeamWizardPage(formFactory,
|
100
|
selectionElement.getConversationHolder(), (Team) entity));
|
101
|
} else if (entity instanceof Person) {
|
102
|
addPage(new PersonWizardPage(formFactory,
|
103
|
selectionElement.getConversationHolder(), (Person) entity));
|
104
|
} else if (entity instanceof NonViralName) {
|
105
|
addPage(new NonViralNameWizardPage(formFactory,
|
106
|
selectionElement.getConversationHolder(),
|
107
|
(NonViralName) entity));
|
108
|
} else if (entity instanceof SpecimenOrObservationBase) {
|
109
|
|
110
|
DerivedUnitFacade facade;
|
111
|
try {
|
112
|
if(((SpecimenOrObservationBase) entity).isInstanceOf(DerivedUnit.class)){
|
113
|
facade = DerivedUnitFacade.NewInstance(
|
114
|
HibernateProxyHelper.deproxy(entity, DerivedUnit.class),
|
115
|
PreferencesUtil.getDerivedUnitConfigurator());
|
116
|
}
|
117
|
else {
|
118
|
facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit,
|
119
|
HibernateProxyHelper.deproxy(entity, FieldUnit.class),
|
120
|
PreferencesUtil.getDerivedUnitConfigurator());
|
121
|
}
|
122
|
|
123
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
124
|
// we should never get here
|
125
|
throw new IllegalStateException();
|
126
|
}
|
127
|
|
128
|
addPage(new DerivedUnitGeneralWizardPage(formFactory,
|
129
|
selectionElement.getConversationHolder(), facade));
|
130
|
addPage(new GatheringEventWizardPage(formFactory,
|
131
|
selectionElement.getConversationHolder(), facade));
|
132
|
addPage(new FieldUnitWizardPage(formFactory,
|
133
|
selectionElement.getConversationHolder(), facade));
|
134
|
if(facade.innerDerivedUnit()!=null){
|
135
|
addPage(new DerivedUnitBaseWizardPage(formFactory,
|
136
|
selectionElement.getConversationHolder(), facade));
|
137
|
}
|
138
|
} else if (entity instanceof Collection) {
|
139
|
addPage(new CollectionWizardPage(formFactory,
|
140
|
selectionElement.getConversationHolder(),
|
141
|
(Collection) entity));
|
142
|
} else if (entity instanceof Institution) {
|
143
|
addPage(new InstitutionWizardPage(formFactory,
|
144
|
selectionElement.getConversationHolder(),
|
145
|
(Institution) entity));
|
146
|
} else if (entity instanceof User) {
|
147
|
addPage(new UserDetailWizardPage(formFactory,
|
148
|
selectionElement.getConversationHolder(),
|
149
|
(User) entity));
|
150
|
} else if (entity instanceof Primer) {
|
151
|
addPage(new PrimerWizardPage(formFactory,
|
152
|
selectionElement.getConversationHolder(),
|
153
|
(Primer) entity));
|
154
|
} else if (entity instanceof Amplification) {
|
155
|
addPage(new AmplificationGeneralWizardPage(formFactory,
|
156
|
selectionElement.getConversationHolder(),
|
157
|
(Amplification) entity));
|
158
|
} else {
|
159
|
MessagingUtils.warningDialog("Missing interface", this,
|
160
|
"No detail element for current selection");
|
161
|
}
|
162
|
|
163
|
}
|
164
|
|
165
|
/*
|
166
|
* (non-Javadoc)
|
167
|
*
|
168
|
* @see org.eclipse.jface.wizard.Wizard#performFinish()
|
169
|
*/
|
170
|
/** {@inheritDoc} */
|
171
|
@Override
|
172
|
public boolean performFinish() {
|
173
|
IEditorPart activeEditor = AbstractUtility.getActiveEditor();
|
174
|
/*
|
175
|
* forceDirty() for cases when one or more EditFromSelectionWizards are
|
176
|
* opened cascadingly to trigger the save button. Otherwise the dirty
|
177
|
* state would not be set and the user will have no feedback that he/she
|
178
|
* actually still has ounsaved changes. This is necessary because
|
179
|
* editing in these wizards is done on clones of the CDM entities which
|
180
|
* are merged back with the original when pressing "Finish"
|
181
|
*/
|
182
|
if (activeEditor instanceof IDirtyMarkable){
|
183
|
((IDirtyMarkable) activeEditor).forceDirty();
|
184
|
}
|
185
|
return true;
|
186
|
}
|
187
|
|
188
|
/** {@inheritDoc} */
|
189
|
@Override
|
190
|
public void widgetSelected(SelectionEvent e) {
|
191
|
WizardDialog dialog = new WizardDialog(selectionElement.getShell(),
|
192
|
this);
|
193
|
if (dialog.open() == IStatus.OK) {
|
194
|
selectionElement.updateFromWizard();
|
195
|
}
|
196
|
}
|
197
|
|
198
|
/** {@inheritDoc} */
|
199
|
@Override
|
200
|
public void widgetDefaultSelected(SelectionEvent e) {
|
201
|
}
|
202
|
}
|