X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=eclipse%2Fplugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fcommands%2FUpdateModule.java;fp=eclipse%2Fplugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fcommands%2FUpdateModule.java;h=0000000000000000000000000000000000000000;hb=651d33e13bfa9a7b46464be412023ee747e612e8;hp=225bd4177070b9c2e9670581862acb4478f1b34c;hpb=868102c0f0220e12eca836b6ec9b3a2b9a3441e4;p=gpl%2Fargeo-slc.git 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 deleted file mode 100644 index 225bd4177..000000000 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/UpdateModule.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.slc.client.ui.commands; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import javax.jcr.Node; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.BasicNameVersion; -import org.argeo.slc.NameVersion; -import org.argeo.slc.SlcException; -import org.argeo.slc.deploy.ModulesManager; -import org.argeo.slc.jcr.SlcNames; -import org.argeo.slc.jcr.SlcTypes; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.handlers.HandlerUtil; - -/** Deletes one or many results */ -public class UpdateModule extends AbstractHandler { - private final static Log log = LogFactory.getLog(UpdateModule.class); - - private ModulesManager modulesManager; - - public Object execute(ExecutionEvent event) throws ExecutionException { - 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; - } - - private class UpdateJob extends Job { - private final IStructuredSelection selection; - - public UpdateJob(ISelection selection) { - super("Update modules"); - this.selection = ((IStructuredSelection) selection); - } - - @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; - } - - if (!nodes.containsKey(executionModuleNode.getPath())) - nodes.put(executionModuleNode.getPath(), - executionModuleNode); - } - } - - 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; - } - } - - @Override - protected void canceling() { - getThread().interrupt(); - super.canceling(); - } - - } - - public void setModulesManager(ModulesManager modulesManager) { - this.modulesManager = modulesManager; - } - -}