1
|
package eu.etaxonomy.taxeditor.navigation.navigator.handler;
|
2
|
// $Id$
|
3
|
/**
|
4
|
* Copyright (C) 2007 EDIT
|
5
|
* European Distributed Institute of Taxonomy
|
6
|
* http://www.e-taxonomy.eu
|
7
|
*
|
8
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
9
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
10
|
*/
|
11
|
|
12
|
|
13
|
import org.eclipse.core.commands.AbstractHandler;
|
14
|
import org.eclipse.core.commands.ExecutionEvent;
|
15
|
import org.eclipse.core.commands.ExecutionException;
|
16
|
import org.eclipse.core.commands.IHandler;
|
17
|
import org.eclipse.core.runtime.IProgressMonitor;
|
18
|
import org.eclipse.core.runtime.IStatus;
|
19
|
import org.eclipse.core.runtime.Status;
|
20
|
import org.eclipse.core.runtime.jobs.Job;
|
21
|
import org.eclipse.jface.viewers.ISelection;
|
22
|
import org.eclipse.jface.viewers.StructuredSelection;
|
23
|
import org.eclipse.jface.wizard.WizardDialog;
|
24
|
import org.eclipse.swt.widgets.Display;
|
25
|
import org.eclipse.ui.handlers.HandlerUtil;
|
26
|
|
27
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
28
|
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
|
29
|
import eu.etaxonomy.taxeditor.newWizard.NewClassificationWizard;
|
30
|
|
31
|
/**
|
32
|
* <p>EditHandler class.</p>
|
33
|
*
|
34
|
* @author n.hoffmann
|
35
|
* @created May 12, 2010
|
36
|
* @version 1.0
|
37
|
*/
|
38
|
public class EditHandler extends AbstractHandler implements IHandler{
|
39
|
|
40
|
/* (non-Javadoc)
|
41
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
42
|
*/
|
43
|
/** {@inheritDoc} */
|
44
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
45
|
|
46
|
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
47
|
|
48
|
if(selection instanceof StructuredSelection){
|
49
|
final StructuredSelection structuredSelection = (StructuredSelection) selection;
|
50
|
|
51
|
if(structuredSelection.size() == 1 && structuredSelection.getFirstElement() instanceof Classification){
|
52
|
Classification classification = (Classification) structuredSelection.getFirstElement();
|
53
|
|
54
|
NewClassificationWizard classificationWizard = new NewClassificationWizard();
|
55
|
classificationWizard.init(null, null);
|
56
|
classificationWizard.setEntity(classification);
|
57
|
WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), classificationWizard);
|
58
|
dialog.open();
|
59
|
|
60
|
}
|
61
|
else{
|
62
|
|
63
|
Job job = new Job("Opening editor") {
|
64
|
|
65
|
@Override
|
66
|
protected IStatus run(IProgressMonitor monitor) {
|
67
|
for(final Object selectedObject : structuredSelection.toArray()){
|
68
|
|
69
|
Display.getDefault().asyncExec(new Runnable(){
|
70
|
|
71
|
public void run() {
|
72
|
NavigationUtil.openEditor(selectedObject);
|
73
|
}
|
74
|
|
75
|
});
|
76
|
}
|
77
|
return Status.OK_STATUS;
|
78
|
}
|
79
|
};
|
80
|
|
81
|
job.schedule();
|
82
|
}
|
83
|
}
|
84
|
|
85
|
return null;
|
86
|
}
|
87
|
}
|