Project

General

Profile

Download (2.46 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

    
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
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
27

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

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

    
37
    /* (non-Javadoc)
38
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
39
	 */
40
	@Override
41
	public Object execute(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
									NavigationUtil.openEditor((PolytomousKey) selectedObject);
63
								}
64

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

    
73
			};
74

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

    
78
		}
79
		return null;
80
	}
81

    
82
}
(2-2/8)