import org.argeo.jcr.JcrUtils;
import org.argeo.slc.akb.AkbException;
+import org.argeo.slc.akb.AkbTypes;
import org.argeo.slc.akb.ui.AkbUiPlugin;
import org.argeo.slc.akb.ui.editors.AkbNodeEditorInput;
+import org.argeo.slc.akb.utils.AkbJcrUtils;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.handlers.HandlerUtil;
public final static String PARAM_NODE_JCR_ID = "param.nodeJcrId";
- // public final static String PARAM_NODE_TYPE = "param.nodeType";
-
public Object execute(ExecutionEvent event) throws ExecutionException {
- // String nodeType = event.getParameter(PARAM_NODE_TYPE);
String nodeJcrId = event.getParameter(PARAM_NODE_JCR_ID);
Session session = null;
try {
+ session = repository.login();
+
// caches current Page
IWorkbenchPage currentPage = HandlerUtil.getActiveWorkbenchWindow(
event).getActivePage();
if (nodeJcrId != null)
node = session.getNodeByIdentifier(nodeJcrId);
- // no node has been found or created, return silently
- if (node == null)
- return null;
+ // We must be in a template or on the root of an env instance to
+ // delete nodes.
+ Node template = node.isNodeType(AkbTypes.AKB_ENV) ? node
+ : AkbJcrUtils.getCurrentTemplate(node);
+
+ if (node != null) {
+ Boolean ok = MessageDialog.openConfirm(
+ HandlerUtil.getActiveShell(event), "Confirm deletion",
+ "Do you want to delete this item?");
+
+ if (ok) {
+ IEditorPart currPart = currentPage
+ .findEditor(new AkbNodeEditorInput(template
+ .getIdentifier(), nodeJcrId));
+ if (currPart != null)
+ currentPage.closeEditor(currPart, false);
- IEditorPart currPart = currentPage
- .findEditor(new AkbNodeEditorInput(nodeJcrId));
- if (currPart != null)
- currPart.dispose();
+ node.remove();
+ session.save();
+ }
+ }
} catch (RepositoryException e) {
throw new AkbException("JCR error while deleting node" + nodeJcrId
+ " editor", e);