Project

General

Profile

Download (2.32 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 EditHandler 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
			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
}
(2-2/2)