]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - DeleteNode.java
4141375ce9281ac1d8c37ae222fd2254aa19fdcb
1 package org
.argeo
.eclipse
.ui
.jcr
.commands
;
3 import java
.util
.Iterator
;
6 import javax
.jcr
.RepositoryException
;
8 import org
.argeo
.ArgeoException
;
9 import org
.argeo
.eclipse
.ui
.ErrorFeedback
;
10 import org
.argeo
.eclipse
.ui
.jcr
.views
.AbstractJcrBrowser
;
11 import org
.eclipse
.core
.commands
.AbstractHandler
;
12 import org
.eclipse
.core
.commands
.ExecutionEvent
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.eclipse
.jface
.viewers
.ISelection
;
15 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
16 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
18 /** Deletes the selected nodes */
19 public class DeleteNode
extends AbstractHandler
{
20 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
21 ISelection selection
= HandlerUtil
.getActiveWorkbenchWindow(event
)
22 .getActivePage().getSelection();
23 AbstractJcrBrowser view
= (AbstractJcrBrowser
) HandlerUtil
24 .getActiveWorkbenchWindow(event
).getActivePage()
25 .findView(HandlerUtil
.getActivePartId(event
));
27 if (selection
!= null && selection
instanceof IStructuredSelection
) {
28 Iterator
<?
> it
= ((IStructuredSelection
) selection
).iterator();
32 while (it
.hasNext()) {
34 if (obj
instanceof Node
) {
35 Node node
= (Node
) obj
;
36 Node parentNode
= node
.getParent();
38 node
.getSession().save();
39 ancestor
= getOlder(ancestor
, parentNode
);
43 view
.nodeRemoved(ancestor
);
44 } catch (Exception e
) {
45 ErrorFeedback
.show("Cannot delete node " + obj
, e
);
51 private Node
getOlder(Node A
, Node B
) {
55 return B
== null ?
null : B
;
56 // Todo enhanced this method
58 return A
.getDepth() <= B
.getDepth() ? A
: B
;
59 } catch (RepositoryException re
) {
60 throw new ArgeoException("Cannot find ancestor", re
);