Project

General

Profile

Download (2.36 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 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

    
11
package eu.etaxonomy.taxeditor.navigation.key.polytomous.handler;
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.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.core.runtime.jobs.Job;
20
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.StructuredSelection;
22
import org.eclipse.swt.widgets.Display;
23

    
24
import eu.etaxonomy.cdm.model.description.PolytomousKey;
25
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
26
import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewPart;
27

    
28
/**
29
 * @author n.hoffmann
30
 * @created Dec 3, 2010
31
 * @version 1.0
32
 */
33
public class EditPolytomousKeyNodesHandler extends AbstractHandler {
34

    
35
	/* (non-Javadoc)
36
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
37
	 */
38
	@Override
39
	public Object execute(ExecutionEvent event) throws ExecutionException {
40
		PolytomousKeyViewPart view = (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false);
41
		
42
		ISelection selection = view.getSite().getSelectionProvider().getSelection(); 
43
		if(selection instanceof StructuredSelection){
44
		   
45
			final StructuredSelection structuredSelection = (StructuredSelection) selection;
46
			
47
			Job job = new Job("Opening Polytomous Keys"){
48

    
49
				@Override
50
				protected IStatus run(IProgressMonitor monitor) {
51
					monitor.beginTask("Opening Polytomous Keys", structuredSelection.size());
52
					
53
					for(final Object selectedObject : structuredSelection.toArray()){
54
						if(selectedObject instanceof PolytomousKey){
55
							
56
							Display.getDefault().asyncExec(new Runnable(){
57

    
58
								@Override
59
								public void run() {								    
60
									NavigationUtil.openEditor((PolytomousKey) selectedObject);
61
								}
62
								
63
							});
64
							monitor.worked(1);
65
						}
66
					}
67
					monitor.done();
68
					return Status.OK_STATUS;
69
				}
70
				
71
			};
72
			
73
			job.setPriority(Job.SHORT);
74
			job.schedule();			
75
			
76
		}
77
		return null;
78
	}
79

    
80
}
(2-2/3)