Merge branch 'develop' into remoting-4.0
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / key / polytomous / handler / RemotingEditPolytomousKeyNodesHandler.java
1 // $Id$
2 /**
3 * Copyright (C) 2015 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 package eu.etaxonomy.taxeditor.navigation.key.polytomous.handler;
11
12 import org.eclipse.core.commands.AbstractHandler;
13 import org.eclipse.core.commands.ExecutionEvent;
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.core.runtime.jobs.Job;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.StructuredSelection;
21 import org.eclipse.swt.widgets.Display;
22
23 import eu.etaxonomy.cdm.model.description.PolytomousKey;
24 import eu.etaxonomy.taxeditor.editor.EditorUtil;
25 import eu.etaxonomy.taxeditor.model.MessagingUtils;
26 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
27 import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewLabels;
28 import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewPart;
29
30 /**
31 * @author cmathew
32 * @date 29 Jun 2015
33 *
34 */
35 public class RemotingEditPolytomousKeyNodesHandler extends AbstractHandler {
36
37 /* (non-Javadoc)
38 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
39 */
40 @Override
41 public Object execute(final ExecutionEvent event) throws ExecutionException {
42 PolytomousKeyViewPart view = (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false);
43
44 ISelection selection = view.getSite().getSelectionProvider().getSelection();
45 if(selection instanceof StructuredSelection){
46
47 final StructuredSelection structuredSelection = (StructuredSelection) selection;
48
49 Job job = new Job("Opening Polytomous Keys"){
50
51 @Override
52 protected IStatus run(IProgressMonitor monitor) {
53 monitor.beginTask("Opening Polytomous Keys", structuredSelection.size());
54
55 for(final Object selectedObject : structuredSelection.toArray()){
56 if(selectedObject instanceof PolytomousKey){
57
58 Display.getDefault().asyncExec(new Runnable(){
59
60 @Override
61 public void run() {
62 try {
63 PolytomousKey key = (PolytomousKey) selectedObject;
64 EditorUtil.openPolytomousKey(key.getUuid());
65 } catch(Exception ex) {
66 MessagingUtils.warningDialog(PolytomousKeyViewLabels.ERROR_OPENING_KEY_EDITOR_MESSAGE,
67 event.getTrigger(),
68 ex.getLocalizedMessage());
69 ex.printStackTrace();
70 }
71 }
72
73 });
74 monitor.worked(1);
75 }
76 }
77 monitor.done();
78 return Status.OK_STATUS;
79 }
80
81 };
82
83 job.setPriority(Job.SHORT);
84 job.schedule();
85
86 }
87 return null;
88 }
89
90 }