1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.wizard;
|
5
|
|
6
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
7
|
import org.eclipse.jface.viewers.StructuredSelection;
|
8
|
import org.eclipse.jface.wizard.Wizard;
|
9
|
import org.eclipse.ui.INewWizard;
|
10
|
import org.eclipse.ui.IWorkbench;
|
11
|
|
12
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
13
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
14
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
15
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
16
|
import eu.etaxonomy.cdm.model.taxon.ITreeNode;
|
17
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
18
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
19
|
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
|
20
|
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
|
21
|
import eu.etaxonomy.taxeditor.operations.AbstractPostOperation;
|
22
|
import eu.etaxonomy.taxeditor.operations.CreateTaxonNodeOperation;
|
23
|
import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;
|
24
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
25
|
|
26
|
/**
|
27
|
* <p>NewTaxonNodeWizard class.</p>
|
28
|
*
|
29
|
* @author n.hoffmann
|
30
|
* @created Sep 15, 2009
|
31
|
* @version 1.0
|
32
|
*/
|
33
|
public class NewTaxonNodeWizard extends Wizard implements INewWizard, IPostOperationEnabled, IConversationEnabled {
|
34
|
|
35
|
private NewTaxonNodeWizardPage page;
|
36
|
|
37
|
private IStructuredSelection selection;
|
38
|
|
39
|
private TaxonNode generatedTaxonNode;
|
40
|
|
41
|
private boolean openEmptyEditor = false;
|
42
|
|
43
|
private ConversationHolder conversation;
|
44
|
|
45
|
/**
|
46
|
* <p>Constructor for NewTaxonNodeWizard.</p>
|
47
|
*/
|
48
|
public NewTaxonNodeWizard() {
|
49
|
this.setWindowTitle("New Entity");
|
50
|
conversation = CdmStore.createConversation();
|
51
|
selection = getNavigatorSelection();
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* Retrieve the current selection from taxon navigator
|
56
|
*
|
57
|
* @return
|
58
|
*/
|
59
|
private IStructuredSelection getNavigatorSelection() {
|
60
|
StructuredSelection selection = null;
|
61
|
TaxonNavigator navigator = NavigationUtil.getNavigator(false);
|
62
|
|
63
|
if(navigator != null){
|
64
|
selection = (StructuredSelection) navigator.getCommonViewer().getSelection();
|
65
|
}
|
66
|
|
67
|
return selection;
|
68
|
}
|
69
|
|
70
|
private ITreeNode getSelectedTreeNode(){
|
71
|
if(selection != null){
|
72
|
Object selectedObject = selection.getFirstElement();
|
73
|
if(selectedObject instanceof ITreeNode){
|
74
|
ITreeNode treeNode = (ITreeNode) selectedObject;
|
75
|
|
76
|
if(treeNode instanceof Classification){
|
77
|
return CdmStore.getClassificationService().load(treeNode.getUuid());
|
78
|
}
|
79
|
else if(treeNode instanceof TaxonNode){
|
80
|
return CdmStore.getTaxonNodeService().load(treeNode.getUuid());
|
81
|
}
|
82
|
}
|
83
|
}
|
84
|
return null;
|
85
|
}
|
86
|
|
87
|
|
88
|
/** {@inheritDoc} */
|
89
|
@Override
|
90
|
public boolean performFinish() {
|
91
|
if(page.getTaxon() == null || page.getTaxon().getName().getFullTitleCache().length() == 0){
|
92
|
openEmptyEditor = true;
|
93
|
}else{
|
94
|
AbstractPostOperation operation = new CreateTaxonNodeOperation("Create Taxon",
|
95
|
NavigationUtil.getUndoContext(), page.getParentTreeNode(), page.getTaxon(), this, this);
|
96
|
NavigationUtil.executeOperation(operation);
|
97
|
}
|
98
|
return true;
|
99
|
}
|
100
|
|
101
|
/* (non-Javadoc)
|
102
|
* @see org.eclipse.jface.wizard.Wizard#addPages()
|
103
|
*/
|
104
|
/** {@inheritDoc} */
|
105
|
@Override
|
106
|
public void addPages() {
|
107
|
super.addPages();
|
108
|
|
109
|
page = new NewTaxonNodeWizardPage(getConversationHolder(), getSelectedTreeNode());
|
110
|
|
111
|
addPage(page);
|
112
|
}
|
113
|
|
114
|
/** {@inheritDoc} */
|
115
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
116
|
// workbench is not used at the moment
|
117
|
this.selection = selection;
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* <p>openInEditor</p>
|
122
|
*
|
123
|
* @return a boolean.
|
124
|
*/
|
125
|
public boolean openInEditor(){
|
126
|
return page.openInEditor();
|
127
|
}
|
128
|
|
129
|
/**
|
130
|
* <p>openEmpty</p>
|
131
|
*
|
132
|
* @return a boolean.
|
133
|
*/
|
134
|
public boolean openEmpty(){
|
135
|
return openInEditor() && openEmptyEditor;
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* <p>getTaxonNode</p>
|
140
|
*
|
141
|
* @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
|
142
|
*/
|
143
|
public TaxonNode getTaxonNode(){
|
144
|
return generatedTaxonNode;
|
145
|
}
|
146
|
|
147
|
/**
|
148
|
* <p>getParent</p>
|
149
|
*
|
150
|
* @return a {@link eu.etaxonomy.cdm.model.taxon.ITreeNode} object.
|
151
|
*/
|
152
|
public ITreeNode getParent(){
|
153
|
return page.getParentTreeNode();
|
154
|
}
|
155
|
|
156
|
/* (non-Javadoc)
|
157
|
* @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
|
158
|
*/
|
159
|
/** {@inheritDoc} */
|
160
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
161
|
generatedTaxonNode = (TaxonNode) objectAffectedByOperation;
|
162
|
|
163
|
NavigationUtil.selectInNavigator(generatedTaxonNode, generatedTaxonNode.getParent());
|
164
|
|
165
|
return true;
|
166
|
}
|
167
|
|
168
|
/**
|
169
|
* <p>onComplete</p>
|
170
|
*
|
171
|
* @return a boolean.
|
172
|
*/
|
173
|
public boolean onComplete() {
|
174
|
return true;
|
175
|
}
|
176
|
|
177
|
/* (non-Javadoc)
|
178
|
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
179
|
*/
|
180
|
/** {@inheritDoc} */
|
181
|
@Override
|
182
|
public void update(CdmDataChangeMap changeEvents) {}
|
183
|
|
184
|
/* (non-Javadoc)
|
185
|
* @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
|
186
|
*/
|
187
|
/** {@inheritDoc} */
|
188
|
@Override
|
189
|
public ConversationHolder getConversationHolder() {
|
190
|
return conversation;
|
191
|
}
|
192
|
|
193
|
|
194
|
// private static final Logger logger = Logger.getLogger(NewTaxonNodeWizard.class);
|
195
|
// private TaxonNodeWizardPage page;
|
196
|
//
|
197
|
// /**
|
198
|
// * @param configuration
|
199
|
// */
|
200
|
// public NewTaxonNodeWizard() {
|
201
|
// }
|
202
|
//
|
203
|
// /* (non-Javadoc)
|
204
|
// * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#performFinish()
|
205
|
// */
|
206
|
// @Override
|
207
|
// public boolean performFinish() {
|
208
|
// return super.performFinish();
|
209
|
// }
|
210
|
//
|
211
|
// /* (non-Javadoc)
|
212
|
// * @see org.eclipse.jface.wizard.Wizard#addPages()
|
213
|
// */
|
214
|
// @Override
|
215
|
// public void addPages() {
|
216
|
// page = new TaxonNodeWizardPage(formFactory, getConversationHolder(), (ITreeNode) selection.getFirstElement());
|
217
|
// addPage(page);
|
218
|
// }
|
219
|
//
|
220
|
// /* (non-Javadoc)
|
221
|
// * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#getEntity()
|
222
|
// */
|
223
|
// @Override
|
224
|
// public ITreeNode getEntity() {
|
225
|
// return getDetailElement().getParentTreeNode();
|
226
|
// }
|
227
|
//
|
228
|
// /* (non-Javadoc)
|
229
|
// * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#saveEntity()
|
230
|
// */
|
231
|
// @Override
|
232
|
// protected void saveEntity() {
|
233
|
// getEntity().addChildTaxon(getDetailElement().getTaxon(), getEntity().getReference(), getEntity().getMicroReference(), null);
|
234
|
// }
|
235
|
//
|
236
|
// /* (non-Javadoc)
|
237
|
// * @see eu.etaxonomy.taxeditor.editor.newWizard.AbstractNewEntityWizard#createNewEntity()
|
238
|
// */
|
239
|
// @Override
|
240
|
// protected TaxonNode createNewEntity() {
|
241
|
// return null;
|
242
|
// }
|
243
|
//
|
244
|
// /**
|
245
|
// * @return
|
246
|
// */
|
247
|
// public TaxonNodeDetailElement getDetailElement() {
|
248
|
// return (TaxonNodeDetailElement) page.getDetailElement();
|
249
|
// }
|
250
|
|
251
|
}
|