2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.client
.ui
.dist
.commands
;
18 import java
.util
.Iterator
;
20 import javax
.jcr
.Node
;
21 import javax
.jcr
.RepositoryException
;
23 import org
.argeo
.ArgeoException
;
24 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
25 import org
.argeo
.slc
.jcr
.SlcTypes
;
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
;
38 * Delete chosen artifacts from the current workspace.
40 public class DeleteArtifacts
extends AbstractHandler
{
41 // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
43 public final static String ID
= DistPlugin
.ID
+ ".deleteArtifacts";
44 public final static String DEFAULT_LABEL
= "Delete selected items";
45 public final static ImageDescriptor DEFAULT_ICON
= DistPlugin
46 .getImageDescriptor("icons/removeItem.gif");
48 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
50 IWorkbenchPart activePart
= HandlerUtil
.getActivePart(event
);
52 if (activePart
instanceof IEditorPart
) {
53 ISelection selector
= ((IEditorPart
) activePart
)
54 .getEditorSite().getSelectionProvider().getSelection();
56 && selector
instanceof IStructuredSelection
) {
57 Iterator
<?
> it
= ((IStructuredSelection
) selector
)
60 String msg
= "Your are about to definitively remove the "
61 + ((IStructuredSelection
) selector
).size()
62 + " selected artifacts.\n"
63 + "Are you sure you want to proceed?";
65 boolean result
= MessageDialog
.openConfirm(DistPlugin
66 .getDefault().getWorkbench().getDisplay()
67 .getActiveShell(), "Confirm Deletion", msg
);
70 while (it
.hasNext()) {
71 Node node
= (Node
) it
.next();
72 if (node
.isNodeType(SlcTypes
.SLC_ARTIFACT
)) {
73 // we remove the artifactVersion, that is the parent
74 node
.getParent().remove();
75 node
.getSession().save();
81 // CommandHelpers.callCommand(RefreshDistributionOverviewPage.ID);
82 } catch (RepositoryException re
) {
83 throw new ArgeoException(
84 "Unexpected error while deleting artifacts.", re
);