]>
git.argeo.org Git - gpl/argeo-slc.git/blob - DeleteResult.java
5e4636870dcb1f02886f5e4773980b18dc8dfc7b
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
.ResultParent
;
30 import org
.argeo
.slc
.client
.ui
.model
.ResultParentUtils
;
31 import org
.argeo
.slc
.client
.ui
.model
.SingleResultNode
;
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();
54 StringBuffer buf
= new StringBuffer("");
55 Iterator
<?
> lst
= ((IStructuredSelection
) selection
).iterator();
56 while (lst
.hasNext()) {
57 Object obj
= lst
.next();
58 if (obj
instanceof ResultParent
) {
59 ResultParent rp
= ((ResultParent
) obj
);
60 buf
.append(rp
.getName()).append(", ");
65 String msg
= "Nothing to delete";
66 // remove last separator
67 if (buf
.lastIndexOf(", ") > -1) {
68 msg
= "Do you want to delete following objects: "
69 + buf
.substring(0, buf
.lastIndexOf(", ")) + "?";
71 Boolean ok
= MessageDialog
.openConfirm(
72 HandlerUtil
.getActiveShell(event
), "Confirm deletion", msg
);
77 Job job
= new Job("Delete results") {
79 protected IStatus
run(IProgressMonitor monitor
) {
81 && selection
instanceof IStructuredSelection
) {
82 List
<String
> nodes
= new ArrayList
<String
>();
83 Iterator
<?
> it
= ((IStructuredSelection
) selection
)
87 while (it
.hasNext()) {
89 if (obj
instanceof ResultFolder
) {
90 Node node
= ((ResultFolder
) obj
).getNode();
91 nodes
.add(node
.getPath());
92 } else if (obj
instanceof SingleResultNode
) {
93 Node node
= ((SingleResultNode
) obj
).getNode();
94 nodes
.add(node
.getPath());
97 } catch (RepositoryException e
) {
98 ErrorFeedback
.show("Cannot list nodes", e
);
101 monitor
.beginTask("Delete results", nodes
.size());
104 for (final String path
: nodes
) {
105 if (session
.itemExists(path
)) {
106 node
= session
.getNode(path
);
107 Node parent
= node
.getParent();
109 ResultParentUtils
.updateStatusOnRemoval(parent
);
114 } catch (RepositoryException e
) {
115 ErrorFeedback
.show("Cannot delete node " + node
, e
);
119 return Status
.OK_STATUS
;
128 /* DEPENDENCY INJECTION */
129 public void setSession(Session session
) {
130 this.session
= session
;