1
|
/**
|
2
|
* Copyright (C) 2015 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.navigation.key.polytomous.handler;
|
10
|
|
11
|
import org.eclipse.core.commands.AbstractHandler;
|
12
|
import org.eclipse.core.commands.ExecutionEvent;
|
13
|
import org.eclipse.core.commands.ExecutionException;
|
14
|
import org.eclipse.core.runtime.IProgressMonitor;
|
15
|
import org.eclipse.core.runtime.IStatus;
|
16
|
import org.eclipse.core.runtime.Status;
|
17
|
import org.eclipse.core.runtime.jobs.Job;
|
18
|
import org.eclipse.jface.viewers.ISelection;
|
19
|
import org.eclipse.jface.viewers.StructuredSelection;
|
20
|
import org.eclipse.swt.widgets.Display;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
23
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
24
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
25
|
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
|
26
|
import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewLabels;
|
27
|
import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewPart;
|
28
|
|
29
|
/**
|
30
|
* @author cmathew
|
31
|
* @date 29 Jun 2015
|
32
|
*
|
33
|
*/
|
34
|
public class RemotingEditPolytomousKeyNodesHandler extends AbstractHandler {
|
35
|
|
36
|
/* (non-Javadoc)
|
37
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
38
|
*/
|
39
|
@Override
|
40
|
public Object execute(final ExecutionEvent event) throws ExecutionException {
|
41
|
PolytomousKeyViewPart view = (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false);
|
42
|
|
43
|
ISelection selection = view.getSite().getSelectionProvider().getSelection();
|
44
|
if(selection instanceof StructuredSelection){
|
45
|
|
46
|
final StructuredSelection structuredSelection = (StructuredSelection) selection;
|
47
|
|
48
|
Job job = new Job("Opening Polytomous Keys"){
|
49
|
|
50
|
@Override
|
51
|
protected IStatus run(IProgressMonitor monitor) {
|
52
|
monitor.beginTask("Opening Polytomous Keys", structuredSelection.size());
|
53
|
|
54
|
for(final Object selectedObject : structuredSelection.toArray()){
|
55
|
if(selectedObject instanceof PolytomousKey){
|
56
|
|
57
|
Display.getDefault().asyncExec(new Runnable(){
|
58
|
|
59
|
@Override
|
60
|
public void run() {
|
61
|
try {
|
62
|
PolytomousKey key = (PolytomousKey) selectedObject;
|
63
|
EditorUtil.openPolytomousKey(key.getUuid());
|
64
|
} catch(Exception ex) {
|
65
|
MessagingUtils.warningDialog(PolytomousKeyViewLabels.ERROR_OPENING_KEY_EDITOR_MESSAGE,
|
66
|
event.getTrigger(),
|
67
|
ex.getLocalizedMessage());
|
68
|
ex.printStackTrace();
|
69
|
}
|
70
|
}
|
71
|
|
72
|
});
|
73
|
monitor.worked(1);
|
74
|
}
|
75
|
}
|
76
|
monitor.done();
|
77
|
return Status.OK_STATUS;
|
78
|
}
|
79
|
|
80
|
};
|
81
|
|
82
|
job.setPriority(Job.SHORT);
|
83
|
job.schedule();
|
84
|
|
85
|
}
|
86
|
return null;
|
87
|
}
|
88
|
|
89
|
}
|