From: Mathieu Baudier Date: Wed, 28 Mar 2012 16:14:59 +0000 (+0000) Subject: Make module operations interruptible X-Git-Tag: argeo-slc-2.1.7~753 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=8908d07cc1fd6ac0a274c460bbd40652816ca054;p=gpl%2Fargeo-slc.git Make module operations interruptible git-svn-id: https://svn.argeo.org/slc/trunk@5266 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/UpdateModule.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/UpdateModule.java index 960e2b941..225bd4177 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/UpdateModule.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/UpdateModule.java @@ -50,61 +50,74 @@ public class UpdateModule extends AbstractHandler { final ISelection selection = HandlerUtil .getActiveWorkbenchWindow(event).getActivePage().getSelection(); if (selection != null && selection instanceof IStructuredSelection) { + UpdateJob job = new UpdateJob(selection); + job.setUser(true); + job.schedule(); + } + return null; + } - Job job = new Job("Update modules") { + private class UpdateJob extends Job { + private final IStructuredSelection selection; - @Override - protected IStatus run(IProgressMonitor monitor) { - Iterator it = ((IStructuredSelection) selection) - .iterator(); - Object obj = null; - try { - Map nodes = new HashMap(); - nodes: while (it.hasNext()) { - obj = it.next(); - if (obj instanceof Node) { - Node node = (Node) obj; - Node executionModuleNode = null; - while (executionModuleNode == null) { - if (node.isNodeType(SlcTypes.SLC_EXECUTION_MODULE)) { - executionModuleNode = node; - } - node = node.getParent(); - if (node.getPath().equals("/"))// root - continue nodes; - } + public UpdateJob(ISelection selection) { + super("Update modules"); + this.selection = ((IStructuredSelection) selection); + } - if (!nodes.containsKey(executionModuleNode - .getPath())) - nodes.put(executionModuleNode.getPath(), - executionModuleNode); + @Override + protected IStatus run(IProgressMonitor monitor) { + Iterator it = selection.iterator(); + Object obj = null; + try { + Map nodes = new HashMap(); + nodes: while (it.hasNext()) { + obj = it.next(); + if (obj instanceof Node) { + Node node = (Node) obj; + Node executionModuleNode = null; + while (executionModuleNode == null) { + if (node.isNodeType(SlcTypes.SLC_EXECUTION_MODULE)) { + executionModuleNode = node; } + node = node.getParent(); + if (node.getPath().equals("/"))// root + continue nodes; } - monitor.beginTask("Update modules", nodes.size()); - for (Node executionModuleNode : nodes.values()) { - monitor.subTask("Update " - + executionModuleNode.getName()); - NameVersion nameVersion = new BasicNameVersion( - executionModuleNode.getProperty( - SlcNames.SLC_NAME).getString(), - executionModuleNode.getProperty( - SlcNames.SLC_VERSION).getString()); - modulesManager.upgrade(nameVersion); - monitor.worked(1); - log.info("Module " + nameVersion + " updated"); - } - return Status.OK_STATUS; - } catch (Exception e) { - throw new SlcException("Cannot update module " + obj, e); - // return Status.CANCEL_STATUS; + if (!nodes.containsKey(executionModuleNode.getPath())) + nodes.put(executionModuleNode.getPath(), + executionModuleNode); } } - }; - job.setUser(true); - job.schedule(); + + monitor.beginTask("Update modules", nodes.size()); + for (Node executionModuleNode : nodes.values()) { + monitor.subTask("Update " + executionModuleNode.getName()); + NameVersion nameVersion = new BasicNameVersion( + executionModuleNode.getProperty(SlcNames.SLC_NAME) + .getString(), executionModuleNode + .getProperty(SlcNames.SLC_VERSION) + .getString()); + modulesManager.upgrade(nameVersion); + monitor.worked(1); + log.info("Module " + nameVersion + " updated"); + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; + } + return Status.OK_STATUS; + } catch (Exception e) { + throw new SlcException("Cannot update module " + obj, e); + // return Status.CANCEL_STATUS; + } } - return null; + + @Override + protected void canceling() { + getThread().interrupt(); + super.canceling(); + } + } public void setModulesManager(ModulesManager modulesManager) { diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrExecutionModulesView.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrExecutionModulesView.java index c5b4cbadc..1f87c98fd 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrExecutionModulesView.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrExecutionModulesView.java @@ -371,6 +371,11 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes, monitor.worked(1); return Status.OK_STATUS; } + + protected void canceling() { + getThread().interrupt(); + super.canceling(); + } }; } else { job = new Job("Start " + nameVersion) { @@ -380,6 +385,11 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes, monitor.worked(1); return Status.OK_STATUS; } + + protected void canceling() { + getThread().interrupt(); + super.canceling(); + } }; } job.setUser(true);