]> git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/commands/DeleteArtifacts.java
Merge remote-tracking branch 'origin/master' into testing
[gpl/argeo-slc.git] / legacy / org.argeo.slc.client.ui.dist / src / 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.slc.SlcException;
9 import org.argeo.slc.SlcTypes;
10 import org.argeo.slc.client.ui.dist.DistPlugin;
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.resource.ImageDescriptor;
16 import org.eclipse.jface.viewers.ISelection;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.ui.IEditorPart;
19 import org.eclipse.ui.IWorkbenchPart;
20 import org.eclipse.ui.handlers.HandlerUtil;
21
22 /** Delete chosen artifacts from the current workspace */
23 public class DeleteArtifacts extends AbstractHandler {
24 // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
25
26 public final static String ID = DistPlugin.PLUGIN_ID + ".deleteArtifacts";
27 public final static String DEFAULT_LABEL = "Delete selected items";
28 public final static ImageDescriptor DEFAULT_ICON = DistPlugin
29 .getImageDescriptor("icons/removeItem.gif");
30
31 public Object execute(ExecutionEvent event) throws ExecutionException {
32 try {
33 IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
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 Deletion", msg);
51
52 if (result) {
53 while (it.hasNext()) {
54 Node node = (Node) it.next();
55 if (node.isNodeType(SlcTypes.SLC_ARTIFACT)) {
56 // we remove the artifactVersion, that is the
57 // parent
58 node.getParent().remove();
59 node.getSession().save();
60 }
61 }
62 }
63 }
64 }
65 // CommandHelpers.callCommand(RefreshDistributionOverviewPage.ID);
66 } catch (RepositoryException re) {
67 throw new SlcException(
68 "Unexpected error while deleting artifacts.", re);
69 }
70 return null;
71 }
72 }