]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.akb.ui/src/main/java/org/argeo/slc/akb/ui/commands/DeleteAkbNodes.java
Edit connector wizard
[gpl/argeo-slc.git] / plugins / org.argeo.slc.akb.ui / src / main / java / org / argeo / slc / akb / ui / commands / DeleteAkbNodes.java
1 package org.argeo.slc.akb.ui.commands;
2
3 import javax.jcr.Node;
4 import javax.jcr.Repository;
5 import javax.jcr.RepositoryException;
6 import javax.jcr.Session;
7
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;
21
22 /**
23 * Deletes one or more akb nodes also closing the corresponding editors if
24 * needed
25 */
26 public class DeleteAkbNodes extends AbstractHandler {
27 public final static String ID = AkbUiPlugin.PLUGIN_ID + ".deleteAkbNodes";
28
29 /* DEPENDENCY INJECTION */
30 private Repository repository;
31
32 public final static String PARAM_NODE_JCR_ID = "param.nodeJcrId";
33
34 public Object execute(ExecutionEvent event) throws ExecutionException {
35
36 String nodeJcrId = event.getParameter(PARAM_NODE_JCR_ID);
37
38 Session session = null;
39 try {
40 session = repository.login();
41
42 // caches current Page
43 IWorkbenchPage currentPage = HandlerUtil.getActiveWorkbenchWindow(
44 event).getActivePage();
45
46 session = repository.login();
47 Node node = null;
48
49 if (nodeJcrId != null)
50 node = session.getNodeByIdentifier(nodeJcrId);
51
52 // We must be in a template or on the root of an env instance to
53 // delete nodes.
54 Node template = node.isNodeType(AkbTypes.AKB_ENV) ? node
55 : AkbJcrUtils.getCurrentTemplate(node);
56
57 if (node != null) {
58 Boolean ok = MessageDialog.openConfirm(
59 HandlerUtil.getActiveShell(event), "Confirm deletion",
60 "Do you want to delete this item?");
61
62 if (ok) {
63 IEditorPart currPart = currentPage
64 .findEditor(new AkbNodeEditorInput(template
65 .getIdentifier(), nodeJcrId));
66 if (currPart != null)
67 currentPage.closeEditor(currPart, false);
68
69 node.remove();
70 session.save();
71 }
72 }
73 } catch (RepositoryException e) {
74 throw new AkbException("JCR error while deleting node" + nodeJcrId
75 + " editor", e);
76 } finally {
77 JcrUtils.logoutQuietly(session);
78 }
79 return null;
80 }
81
82 /* DEPENDENCY INJECTION */
83 public void setRepository(Repository repository) {
84 this.repository = repository;
85 }
86 }