X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=plugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fcommands%2FDeleteResult.java;fp=plugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fcommands%2FDeleteResult.java;h=0000000000000000000000000000000000000000;hb=3529ae56c3bafe8c21e7014d54788ea6fb86f73e;hp=5e4636870dcb1f02886f5e4773980b18dc8dfc7b;hpb=c43f562dc12dd967f3a4eea3f9f0368259a00afa;p=gpl%2Fargeo-slc.git diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/DeleteResult.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/DeleteResult.java deleted file mode 100644 index 5e4636870..000000000 --- a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/DeleteResult.java +++ /dev/null @@ -1,132 +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.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.jcr.Node; -import javax.jcr.RepositoryException; -import javax.jcr.Session; - -import org.argeo.eclipse.ui.ErrorFeedback; -import org.argeo.slc.client.ui.model.ResultFolder; -import org.argeo.slc.client.ui.model.ResultParent; -import org.argeo.slc.client.ui.model.ResultParentUtils; -import org.argeo.slc.client.ui.model.SingleResultNode; -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.dialogs.MessageDialog; -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 DeleteResult extends AbstractHandler { - /* DEPENDENCY INJECTION */ - private Session session; - - public Object execute(final ExecutionEvent event) throws ExecutionException { - final ISelection selection = HandlerUtil - .getActiveWorkbenchWindow(event).getActivePage().getSelection(); - - // confirmation - StringBuffer buf = new StringBuffer(""); - Iterator lst = ((IStructuredSelection) selection).iterator(); - while (lst.hasNext()) { - Object obj = lst.next(); - if (obj instanceof ResultParent) { - ResultParent rp = ((ResultParent) obj); - buf.append(rp.getName()).append(", "); - } - - } - - String msg = "Nothing to delete"; - // remove last separator - if (buf.lastIndexOf(", ") > -1) { - msg = "Do you want to delete following objects: " - + buf.substring(0, buf.lastIndexOf(", ")) + "?"; - } - Boolean ok = MessageDialog.openConfirm( - HandlerUtil.getActiveShell(event), "Confirm deletion", msg); - - if (!ok) - return null; - - Job job = new Job("Delete results") { - @Override - protected IStatus run(IProgressMonitor monitor) { - if (selection != null - && selection instanceof IStructuredSelection) { - List nodes = new ArrayList(); - Iterator it = ((IStructuredSelection) selection) - .iterator(); - Object obj = null; - try { - while (it.hasNext()) { - obj = it.next(); - if (obj instanceof ResultFolder) { - Node node = ((ResultFolder) obj).getNode(); - nodes.add(node.getPath()); - } else if (obj instanceof SingleResultNode) { - Node node = ((SingleResultNode) obj).getNode(); - nodes.add(node.getPath()); - } - } - } catch (RepositoryException e) { - ErrorFeedback.show("Cannot list nodes", e); - return null; - } - monitor.beginTask("Delete results", nodes.size()); - Node node = null; - try { - for (final String path : nodes) { - if (session.itemExists(path)) { - node = session.getNode(path); - Node parent = node.getParent(); - node.remove(); - ResultParentUtils.updateStatusOnRemoval(parent); - } - monitor.worked(1); - } - session.save(); - } catch (RepositoryException e) { - ErrorFeedback.show("Cannot delete node " + node, e); - } - monitor.done(); - } - return Status.OK_STATUS; - } - - }; - job.setUser(true); - job.schedule(); - return null; - } - - /* DEPENDENCY INJECTION */ - public void setSession(Session session) { - this.session = session; - } -}