1 package org
.argeo
.slc
.akb
.ui
.commands
;
4 import javax
.jcr
.Repository
;
5 import javax
.jcr
.RepositoryException
;
6 import javax
.jcr
.Session
;
8 import org
.argeo
.jcr
.JcrUtils
;
9 import org
.argeo
.slc
.akb
.AkbException
;
10 import org
.argeo
.slc
.akb
.AkbTypes
;
11 import org
.argeo
.slc
.akb
.ui
.AkbUiPlugin
;
12 import org
.argeo
.slc
.akb
.ui
.editors
.AkbNodeEditorInput
;
13 import org
.argeo
.slc
.akb
.utils
.AkbJcrUtils
;
14 import org
.eclipse
.core
.commands
.AbstractHandler
;
15 import org
.eclipse
.core
.commands
.ExecutionEvent
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
18 import org
.eclipse
.ui
.IEditorPart
;
19 import org
.eclipse
.ui
.IWorkbenchPage
;
20 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
23 * Deletes one or more akb nodes also closing the corresponding editors if
26 public class DeleteAkbNodes
extends AbstractHandler
{
27 public final static String ID
= AkbUiPlugin
.PLUGIN_ID
+ ".deleteAkbNodes";
29 /* DEPENDENCY INJECTION */
30 private Repository repository
;
32 public final static String PARAM_NODE_JCR_ID
= "param.nodeJcrId";
34 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
36 String nodeJcrId
= event
.getParameter(PARAM_NODE_JCR_ID
);
38 Session session
= null;
40 session
= repository
.login();
42 // caches current Page
43 IWorkbenchPage currentPage
= HandlerUtil
.getActiveWorkbenchWindow(
44 event
).getActivePage();
46 session
= repository
.login();
49 if (nodeJcrId
!= null)
50 node
= session
.getNodeByIdentifier(nodeJcrId
);
52 // We must be in a template or on the root of an env instance to
54 Node template
= node
.isNodeType(AkbTypes
.AKB_ENV
) ? node
55 : AkbJcrUtils
.getCurrentTemplate(node
);
58 Boolean ok
= MessageDialog
.openConfirm(
59 HandlerUtil
.getActiveShell(event
), "Confirm deletion",
60 "Do you want to delete this item?");
63 IEditorPart currPart
= currentPage
64 .findEditor(new AkbNodeEditorInput(template
65 .getIdentifier(), nodeJcrId
));
67 currentPage
.closeEditor(currPart
, false);
73 } catch (RepositoryException e
) {
74 throw new AkbException("JCR error while deleting node" + nodeJcrId
77 JcrUtils
.logoutQuietly(session
);
82 /* DEPENDENCY INJECTION */
83 public void setRepository(Repository repository
) {
84 this.repository
= repository
;