1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.slc.client.ui.dist.commands;
17
18 import java.util.Iterator;
19
20 import javax.jcr.Node;
21 import javax.jcr.RepositoryException;
22
23 import org.argeo.slc.SlcException;
24 import org.argeo.slc.SlcTypes;
25 import org.argeo.slc.client.ui.dist.DistPlugin;
26 import org.eclipse.core.commands.AbstractHandler;
27 import org.eclipse.core.commands.ExecutionEvent;
28 import org.eclipse.core.commands.ExecutionException;
29 import org.eclipse.jface.dialogs.MessageDialog;
30 import org.eclipse.jface.resource.ImageDescriptor;
31 import org.eclipse.jface.viewers.ISelection;
32 import org.eclipse.jface.viewers.IStructuredSelection;
33 import org.eclipse.ui.IEditorPart;
34 import org.eclipse.ui.IWorkbenchPart;
35 import org.eclipse.ui.handlers.HandlerUtil;
36
37
38 public class DeleteArtifacts extends AbstractHandler {
39
40
41 public final static String ID = DistPlugin.PLUGIN_ID + ".deleteArtifacts";
42 public final static String DEFAULT_LABEL = "Delete selected items";
43 public final static ImageDescriptor DEFAULT_ICON = DistPlugin
44 .getImageDescriptor("icons/removeItem.gif");
45
46 public Object execute(ExecutionEvent event) throws ExecutionException {
47 try {
48 IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
49
50 if (activePart instanceof IEditorPart) {
51 ISelection selector = ((IEditorPart) activePart)
52 .getEditorSite().getSelectionProvider().getSelection();
53 if (selector != null
54 && selector instanceof IStructuredSelection) {
55 Iterator<?> it = ((IStructuredSelection) selector)
56 .iterator();
57
58 String msg = "Your are about to definitively remove the "
59 + ((IStructuredSelection) selector).size()
60 + " selected artifacts.\n"
61 + "Are you sure you want to proceed?";
62
63 boolean result = MessageDialog.openConfirm(DistPlugin
64 .getDefault().getWorkbench().getDisplay()
65 .getActiveShell(), "Confirm Deletion", msg);
66
67 if (result) {
68 while (it.hasNext()) {
69 Node node = (Node) it.next();
70 if (node.isNodeType(SlcTypes.SLC_ARTIFACT)) {
71
72
73 node.getParent().remove();
74 node.getSession().save();
75 }
76 }
77 }
78 }
79 }
80
81 } catch (RepositoryException re) {
82 throw new SlcException(
83 "Unexpected error while deleting artifacts.", re);
84 }
85 return null;
86 }
87 }