]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - jcr/commands/DeleteNode.java
1 package org
.argeo
.eclipse
.ui
.jcr
.commands
;
3 import java
.util
.Iterator
;
6 import javax
.jcr
.RepositoryException
;
8 import org
.apache
.commons
.logging
.Log
;
9 import org
.apache
.commons
.logging
.LogFactory
;
10 import org
.argeo
.ArgeoException
;
11 import org
.argeo
.eclipse
.ui
.dialogs
.Error
;
12 import org
.argeo
.eclipse
.ui
.jcr
.views
.AbstractJcrBrowser
;
13 import org
.eclipse
.core
.commands
.AbstractHandler
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.jface
.viewers
.ISelection
;
17 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
18 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
20 /** Deletes the selected nodes */
21 public class DeleteNode
extends AbstractHandler
{
22 private final static Log log
= LogFactory
.getLog(DeleteNode
.class);
24 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
25 ISelection selection
= HandlerUtil
.getActiveWorkbenchWindow(event
)
26 .getActivePage().getSelection();
27 AbstractJcrBrowser view
= (AbstractJcrBrowser
) HandlerUtil
28 .getActiveWorkbenchWindow(event
).getActivePage()
29 .findView(HandlerUtil
.getActivePartId(event
));
31 if (selection
!= null && selection
instanceof IStructuredSelection
) {
32 Iterator
<?
> it
= ((IStructuredSelection
) selection
).iterator();
36 while (it
.hasNext()) {
38 if (obj
instanceof Node
) {
39 Node node
= (Node
) obj
;
40 Node parentNode
= node
.getParent();
42 node
.getSession().save();
43 ancestor
= getOlder(ancestor
, parentNode
);
47 view
.nodeRemoved(ancestor
);
48 } catch (Exception e
) {
49 Error
.show("Cannot delete node " + obj
, e
);
55 private Node
getOlder(Node A
, Node B
) {
59 return B
== null ?
null : B
;
60 // Todo enhanced this method
62 return A
.getDepth() <= B
.getDepth() ? A
: B
;
63 } catch (RepositoryException re
) {
64 throw new ArgeoException("Cannot find ancestor", re
);