ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / key / polytomous / handler / RefreshPolytomousKeyNodesHandler.java
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 java.util.List;
13
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.commands.IHandler;
18 import org.eclipse.core.commands.operations.IUndoContext;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.IStatus;
21 import org.eclipse.core.runtime.Status;
22 import org.eclipse.core.runtime.jobs.Job;
23
24 import org.eclipse.swt.widgets.Display;
25
26
27 import eu.etaxonomy.cdm.model.description.PolytomousKey;
28 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
29 import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewPart;
30 import eu.etaxonomy.taxeditor.navigation.key.polytomous.operation.RefreshNodesOperation;
31 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
32
33
34 /**
35 * <p>RefreshPolytomousKeyNodesHandler class, which refreshes each key node in the polytomous key navigation view</p>
36 *
37 * @author c.mathew
38 * @created Jan 17 2013
39 * @version 1.0
40 */
41 public class RefreshPolytomousKeyNodesHandler extends AbstractHandler implements IHandler {
42
43 @Override
44 public Object execute(ExecutionEvent event) throws ExecutionException {
45 final PolytomousKeyViewPart view = (PolytomousKeyViewPart) NavigationUtil.getView(PolytomousKeyViewPart.ID, false);
46 final List<PolytomousKey> keys = view.getKeys();
47
48 final String label = "Refresh Polytomous Key Nodes";
49
50 final IUndoContext undoContext = NavigationUtil.getUndoContext();
51 if (keys.size() > 0) {
52 Job job = new Job("Refreshing Polytomous Key Nodes"){
53
54 @Override
55 protected IStatus run(IProgressMonitor monitor) {
56 monitor.beginTask("Refreshing Polytomous Key Nodes", keys.size());
57
58
59 for (final PolytomousKey key : keys) {
60 if(key.getRoot() != null) {
61
62 Display.getDefault().asyncExec(new Runnable(){
63
64 @Override
65 public void run() {
66 AbstractPostOperation operation = new RefreshNodesOperation(label, undoContext, key, view);
67 NavigationUtil.executeOperation(operation);
68 }
69
70 });
71 monitor.worked(1);
72 }
73 }
74 monitor.done();
75 return Status.OK_STATUS;
76 }
77
78 };
79
80 job.setPriority(Job.SHORT);
81 job.schedule();
82
83 }
84 return null;
85 }
86 }
87