ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / key / polytomous / handler / EditPolytomousKeyNodesHandler.java
1 /**
2 * Copyright (C) 2007 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
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.navigation.NavigationUtil;
25 import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewPart;
26
27 /**
28 * @author n.hoffmann
29 * @created Dec 3, 2010
30 * @version 1.0
31 */
32 public class EditPolytomousKeyNodesHandler extends AbstractHandler {
33
34 /* (non-Javadoc)
35 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
36 */
37 @Override
38 public Object execute(ExecutionEvent event) throws ExecutionException {
39 PolytomousKeyViewPart view = (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false);
40
41 ISelection selection = view.getSite().getSelectionProvider().getSelection();
42 if(selection instanceof StructuredSelection){
43
44 final StructuredSelection structuredSelection = (StructuredSelection) selection;
45
46 Job job = new Job("Opening Polytomous Keys"){
47
48 @Override
49 protected IStatus run(IProgressMonitor monitor) {
50 monitor.beginTask("Opening Polytomous Keys", structuredSelection.size());
51
52 for(final Object selectedObject : structuredSelection.toArray()){
53 if(selectedObject instanceof PolytomousKey){
54
55 Display.getDefault().asyncExec(new Runnable(){
56
57 @Override
58 public void run() {
59 NavigationUtil.openEditor((PolytomousKey) selectedObject);
60 }
61
62 });
63 monitor.worked(1);
64 }
65 }
66 monitor.done();
67 return Status.OK_STATUS;
68 }
69
70 };
71
72 job.setPriority(Job.SHORT);
73 job.schedule();
74
75 }
76 return null;
77 }
78
79 }