Project

General

Profile

Download (2.63 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 java.util.List;
14

    
15
import org.eclipse.core.commands.AbstractHandler;
16
import org.eclipse.core.commands.ExecutionEvent;
17
import org.eclipse.core.commands.ExecutionException;
18
import org.eclipse.core.commands.IHandler;
19
import org.eclipse.core.commands.operations.IUndoContext;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Status;
23
import org.eclipse.core.runtime.jobs.Job;
24

    
25
import org.eclipse.swt.widgets.Display;
26

    
27

    
28
import eu.etaxonomy.cdm.model.description.PolytomousKey;
29
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
30
import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewPart;
31
import eu.etaxonomy.taxeditor.navigation.key.polytomous.operation.RefreshNodesOperation;
32
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
33

    
34

    
35
/**
36
 * <p>RefreshPolytomousKeyNodesHandler class, which refreshes each key node in the polytomous key navigation view</p>
37
 *
38
 * @author c.mathew
39
 * @created Jan 17 2013
40
 * @version 1.0
41
 */
42
public class RefreshPolytomousKeyNodesHandler extends AbstractHandler implements IHandler {
43

    
44
	@Override
45
	public Object execute(ExecutionEvent event) throws ExecutionException {
46
		final PolytomousKeyViewPart view = (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false);
47
		final List<PolytomousKey> keys = view.getKeys();
48
		
49
		final String label = "Refresh Polytomous Key Nodes";
50
		
51
		final IUndoContext undoContext = NavigationUtil.getUndoContext();
52
		if (keys.size() > 0) {
53
			Job job = new Job("Refreshing Polytomous Key Nodes"){
54
													
55
					@Override
56
					protected IStatus run(IProgressMonitor monitor) {
57
						monitor.beginTask("Refreshing Polytomous Key Nodes", keys.size());
58
						
59
						
60
							for (final PolytomousKey key : keys) {					
61
								if(key.getRoot() != null) {
62

    
63
									Display.getDefault().asyncExec(new Runnable(){
64

    
65
										@Override
66
										public void run() {								    
67
											AbstractPostOperation operation = new RefreshNodesOperation(label, undoContext, key, view);
68
											NavigationUtil.executeOperation(operation);
69
										}
70

    
71
									});
72
									monitor.worked(1);
73
								}
74
							}
75
							monitor.done();
76
							return Status.OK_STATUS;
77
						}
78

    
79
					};
80

    
81
					job.setPriority(Job.SHORT);
82
					job.schedule();
83

    
84
				}
85
				return null;
86
			}
87
		}
88

    
(5-5/5)