]> 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
Fixed RPMs.
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / commands / DeleteArtifacts.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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.ArgeoException;
24 import org.argeo.slc.client.ui.dist.DistPlugin;
25 import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
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.viewers.ISelection;
31 import org.eclipse.jface.viewers.IStructuredSelection;
32 import org.eclipse.ui.IEditorPart;
33 import org.eclipse.ui.IWorkbenchPart;
34
35 /**
36 * Delete chosen artifacts from the current workspace.
37 */
38
39 public class DeleteArtifacts extends AbstractHandler {
40 // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
41 public final static String ID = DistPlugin.ID + ".deleteArtifacts";
42 public final static String DEFAULT_LABEL = "Delete selected items";
43 public final static String DEFAULT_ICON_PATH = "icons/removeItem.gif";
44
45 public Object execute(ExecutionEvent event) throws ExecutionException {
46 try {
47 IWorkbenchPart activePart = DistPlugin.getDefault().getWorkbench()
48 .getActiveWorkbenchWindow().getActivePage().getActivePart();
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 Delete", msg);
66
67 if (result) {
68 while (it.hasNext()) {
69 Node node = (Node) it.next();
70 // we remove the artifactVersion, that is the parent
71 node.getParent().remove();
72 node.getSession().save();
73 }
74 }
75 }
76 }
77 CommandHelpers.callCommand(RefreshDistributionOverviewPage.ID);
78 } catch (RepositoryException re) {
79 throw new ArgeoException(
80 "Unexpected error while deleting artifacts.", re);
81 }
82 return null;
83 }
84 }