]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteArtifacts.java
Improve UI dist
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / commands / DeleteArtifacts.java
1 package org.argeo.slc.client.ui.dist.commands;
2
3 import java.util.Iterator;
4
5 import javax.jcr.Node;
6 import javax.jcr.RepositoryException;
7
8 import org.argeo.ArgeoException;
9 import org.argeo.slc.client.ui.dist.DistPlugin;
10 import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
11 import org.eclipse.core.commands.AbstractHandler;
12 import org.eclipse.core.commands.ExecutionEvent;
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.jface.dialogs.MessageDialog;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.ui.IEditorPart;
18 import org.eclipse.ui.IWorkbenchPart;
19
20 /**
21 * Delete chosen artifacts from the current workspace.
22 */
23
24 public class DeleteArtifacts extends AbstractHandler {
25 // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
26 public final static String ID = DistPlugin.ID + ".deleteArtifacts";
27 public final static String DEFAULT_LABEL = "Delete selected items";
28 public final static String DEFAULT_ICON_PATH = "icons/removeItem.gif";
29
30 public Object execute(ExecutionEvent event) throws ExecutionException {
31 try {
32 IWorkbenchPart activePart = DistPlugin.getDefault().getWorkbench()
33 .getActiveWorkbenchWindow().getActivePage().getActivePart();
34
35 if (activePart instanceof IEditorPart) {
36 ISelection selector = ((IEditorPart) activePart)
37 .getEditorSite().getSelectionProvider().getSelection();
38 if (selector != null
39 && selector instanceof IStructuredSelection) {
40 Iterator<?> it = ((IStructuredSelection) selector)
41 .iterator();
42
43 String msg = "Your are about to definitively remove the "
44 + ((IStructuredSelection) selector).size()
45 + " selected artifacts.\n"
46 + "Are you sure you want to proceed ?";
47
48 boolean result = MessageDialog.openConfirm(DistPlugin
49 .getDefault().getWorkbench().getDisplay()
50 .getActiveShell(), "Confirm Delete", msg);
51
52 if (result) {
53 while (it.hasNext()) {
54 Node node = (Node) it.next();
55 // we remove the artifactVersion, that is the parent
56 node.getParent().remove();
57 node.getSession().save();
58 }
59 }
60 }
61 }
62 CommandHelpers.callCommand(RefreshDistributionOverviewPage.ID);
63 } catch (RepositoryException re) {
64 throw new ArgeoException(
65 "Unexpected error while deleting artifacts.", re);
66 }
67 return null;
68 }
69 }