]>
git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/DeleteResult.java
2 * Copyright (C) 2007-2012 Mathieu Baudier
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.
17 package org
.argeo
.slc
.client
.ui
.commands
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Iterator
;
21 import java
.util
.List
;
23 import javax
.jcr
.Node
;
24 import javax
.jcr
.RepositoryException
;
25 import javax
.jcr
.Session
;
27 import org
.argeo
.eclipse
.ui
.ErrorFeedback
;
28 import org
.argeo
.slc
.client
.ui
.model
.ResultFolder
;
29 import org
.argeo
.slc
.client
.ui
.model
.ResultParentUtils
;
30 import org
.argeo
.slc
.client
.ui
.model
.SingleResultNode
;
31 import org
.argeo
.slc
.jcr
.SlcNames
;
32 import org
.eclipse
.core
.commands
.AbstractHandler
;
33 import org
.eclipse
.core
.commands
.ExecutionEvent
;
34 import org
.eclipse
.core
.commands
.ExecutionException
;
35 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
36 import org
.eclipse
.core
.runtime
.IStatus
;
37 import org
.eclipse
.core
.runtime
.Status
;
38 import org
.eclipse
.core
.runtime
.jobs
.Job
;
39 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
40 import org
.eclipse
.jface
.viewers
.ISelection
;
41 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
42 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
44 /** Deletes one or many results */
45 public class DeleteResult
extends AbstractHandler
{
46 /* DEPENDENCY INJECTION */
47 private Session session
;
49 public Object
execute(final ExecutionEvent event
) throws ExecutionException
{
50 final ISelection selection
= HandlerUtil
51 .getActiveWorkbenchWindow(event
).getActivePage().getSelection();
53 if (!MessageDialog
.openConfirm(HandlerUtil
.getActiveShell(event
),
55 "Are you sure that you want to delete these results?"))
58 Job job
= new Job("Delete results") {
60 protected IStatus
run(IProgressMonitor monitor
) {
62 && selection
instanceof IStructuredSelection
) {
63 List
<String
> nodes
= new ArrayList
<String
>();
64 Iterator
<?
> it
= ((IStructuredSelection
) selection
)
68 while (it
.hasNext()) {
70 if (obj
instanceof ResultFolder
) {
71 Node node
= ((ResultFolder
) obj
).getNode();
72 nodes
.add(node
.getPath());
73 } else if (obj
instanceof SingleResultNode
) {
74 Node node
= ((SingleResultNode
) obj
).getNode();
75 nodes
.add(node
.getPath());
78 } catch (RepositoryException e
) {
79 ErrorFeedback
.show("Cannot list nodes", e
);
82 monitor
.beginTask("Delete results", nodes
.size());
85 for (final String path
: nodes
) {
86 if (session
.itemExists(path
)) {
87 node
= session
.getNode(path
);
88 Node parent
= node
.getParent();
90 ResultParentUtils
.updateStatusOnRemoval(parent
);
95 } catch (RepositoryException e
) {
96 ErrorFeedback
.show("Cannot delete node " + node
, e
);
100 return Status
.OK_STATUS
;
109 /* DEPENDENCY INJECTION */
110 public void setSession(Session session
) {
111 this.session
= session
;