Project

General

Profile

Download (2.55 KB) Statistics
| Branch: | Tag: | Revision:
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
import org.eclipse.ui.PlatformUI;
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
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
28

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

    
36
    protected static final String OPENING_POLYTOMOUS_KEYS = Messages.EditPolytomousKeyNodesHandler_OPEN_KEYS;
37

    
38
    /* (non-Javadoc)
39
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
40
	 */
41
	@Override
42
	public Object execute(ExecutionEvent event) throws ExecutionException {
43
		PolytomousKeyViewPart view = (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false);
44

    
45
		ISelection selection = view.getSite().getSelectionProvider().getSelection();
46
		if(selection instanceof StructuredSelection){
47

    
48
			final StructuredSelection structuredSelection = (StructuredSelection) selection;
49

    
50
			Job job = new Job(OPENING_POLYTOMOUS_KEYS){
51

    
52
				@Override
53
				protected IStatus run(IProgressMonitor monitor) {
54
					monitor.beginTask(OPENING_POLYTOMOUS_KEYS, structuredSelection.size());
55

    
56
					for(final Object selectedObject : structuredSelection.toArray()){
57
						if(selectedObject instanceof PolytomousKey){
58

    
59
							Display.getDefault().asyncExec(new Runnable(){
60

    
61
								@Override
62
								public void run() {
63
									NavigationUtil.openEditor((PolytomousKey) selectedObject, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
64
								}
65

    
66
							});
67
							monitor.worked(1);
68
						}
69
					}
70
					monitor.done();
71
					return Status.OK_STATUS;
72
				}
73

    
74
			};
75

    
76
			job.setPriority(Job.SHORT);
77
			job.schedule();
78

    
79
		}
80
		return null;
81
	}
82

    
83
}
(2-2/8)