]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - plugins/org.argeo.slc.akb.ui/src/main/java/org/argeo/slc/akb/ui/commands/DeleteAkbNodes.java
Fix environment editor
[gpl/argeo-slc.git] / plugins / org.argeo.slc.akb.ui / src / main / java / org / argeo / slc / akb / ui / commands / DeleteAkbNodes.java
index 9889ae00e22cb3e758e2992ae2b9b79ed6944eed..3a3e9a0a9e0804ba112e284f07467775bf93f2f5 100644 (file)
@@ -7,8 +7,10 @@ import javax.jcr.Session;
 
 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;
@@ -47,10 +49,10 @@ public class DeleteAkbNodes extends AbstractHandler {
                        if (nodeJcrId != null)
                                node = session.getNodeByIdentifier(nodeJcrId);
 
-                       IEditorPart currPart = currentPage
-                                       .findEditor(new AkbNodeEditorInput(nodeJcrId));
-                       if (currPart != null)
-                               currPart.dispose();
+                       // 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(
@@ -58,6 +60,12 @@ public class DeleteAkbNodes extends AbstractHandler {
                                                "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);
+
                                        node.remove();
                                        session.save();
                                }