X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=eclipse%2Fplugins%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Fcommands%2FDeleteWorkspace.java;fp=eclipse%2Fplugins%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Fcommands%2FDeleteWorkspace.java;h=4c77c806eef5b873dfcce638fba272bf5f12fcb9;hb=a753fd2278254345bc114cf146a034ad8d3df7aa;hp=b1a3632b418271660ace2d6661a21d1bf53077bc;hpb=e17bf1fb99c25bfb23dd2e68262550a49d71d1ac;p=gpl%2Fargeo-slc.git diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteWorkspace.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteWorkspace.java index b1a3632b4..4c77c806e 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteWorkspace.java +++ b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteWorkspace.java @@ -1,8 +1,17 @@ package org.argeo.slc.client.ui.dist.commands; +import javax.jcr.Node; +import javax.jcr.NodeIterator; import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.nodetype.NodeType; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.ArgeoException; import org.argeo.slc.client.ui.dist.DistPlugin; +import org.argeo.slc.client.ui.dist.utils.CommandHelpers; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; @@ -13,7 +22,8 @@ import org.eclipse.jface.dialogs.MessageDialog; */ public class DeleteWorkspace extends AbstractHandler { - // private static final Log log = LogFactory.getLog(DeleteWorkspace.class); + private static final Log log = LogFactory.getLog(DeleteWorkspace.class); + public final static String ID = DistPlugin.ID + ".deleteWorkspace"; public final static String PARAM_WORKSPACE_NAME = DistPlugin.ID + ".workspaceName"; @@ -24,35 +34,47 @@ public class DeleteWorkspace extends AbstractHandler { private Repository repository; public Object execute(ExecutionEvent event) throws ExecutionException { - - MessageDialog.openWarning(DistPlugin.getDefault() + + // MessageDialog.openWarning(DistPlugin.getDefault() + // .getWorkbench().getDisplay().getActiveShell(), + // "WARNING", "Not yet implemented"); + // return null; + + String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME); + String msg = "Your are about to clear workspace [" + workspaceName + + "].\n Do you really want to proceed ?"; + + boolean result = MessageDialog.openConfirm(DistPlugin.getDefault() .getWorkbench().getDisplay().getActiveShell(), - "WARNING", "Not yet implemented"); + "Confirm workspace clear", msg); + if (result) { + Session session = null; + try { + session = repository.login(workspaceName); + NodeIterator nit = session.getRootNode().getNodes(); + while (nit.hasNext()) { + Node node = nit.nextNode(); + if (node.isNodeType(NodeType.NT_FOLDER) + || node.isNodeType(NodeType.NT_UNSTRUCTURED)) { + String path = node.getPath(); + node.remove(); + session.save(); + if (log.isDebugEnabled()) + log.debug("Cleared " + path + " in " + + workspaceName); + } + } + CommandHelpers.callCommand(RefreshDistributionsView.ID); + } catch (RepositoryException re) { + throw new ArgeoException( + "Unexpected error while deleting workspace [" + + workspaceName + "].", re); + } finally { + if (session != null) + session.logout(); + } + } return null; - -// String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME); -// String msg = "Your are about to definitively delete this workspace [" -// + workspaceName + "].\n Do you really want to proceed ?"; - -// boolean result = MessageDialog.openConfirm(DistPlugin.getDefault() -// .getWorkbench().getDisplay().getActiveShell(), -// "Confirm deletion", msg); -// if (result) { -// Session session = null; -// try { -// session = repository.login(); -// session.getWorkspace().deleteWorkspace(workspaceName); -// CommandHelpers.callCommand(RefreshDistributionsView.ID); -// } catch (RepositoryException re) { -// throw new ArgeoException( -// "Unexpected error while deleting workspace [" -// + workspaceName + "].", re); -// } finally { -// if (session != null) -// session.logout(); -// } -// } -// return null; } /* DEPENDENCY INJECTION */