]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteWorkspace.java
Clear workspace instead of deleting it
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / commands / DeleteWorkspace.java
1 package org.argeo.slc.client.ui.dist.commands;
2
3 import javax.jcr.Node;
4 import javax.jcr.NodeIterator;
5 import javax.jcr.Repository;
6 import javax.jcr.RepositoryException;
7 import javax.jcr.Session;
8 import javax.jcr.nodetype.NodeType;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.argeo.ArgeoException;
13 import org.argeo.slc.client.ui.dist.DistPlugin;
14 import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
15 import org.eclipse.core.commands.AbstractHandler;
16 import org.eclipse.core.commands.ExecutionEvent;
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.jface.dialogs.MessageDialog;
19
20 /**
21 * Delete chosen workspace in the current repository.
22 */
23
24 public class DeleteWorkspace extends AbstractHandler {
25 private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
26
27 public final static String ID = DistPlugin.ID + ".deleteWorkspace";
28 public final static String PARAM_WORKSPACE_NAME = DistPlugin.ID
29 + ".workspaceName";
30 public final static String DEFAULT_LABEL = "Delete";
31 public final static String DEFAULT_ICON_PATH = "icons/removeItem.gif";
32
33 /* DEPENDENCY INJECTION */
34 private Repository repository;
35
36 public Object execute(ExecutionEvent event) throws ExecutionException {
37
38 // MessageDialog.openWarning(DistPlugin.getDefault()
39 // .getWorkbench().getDisplay().getActiveShell(),
40 // "WARNING", "Not yet implemented");
41 // return null;
42
43 String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
44 String msg = "Your are about to clear workspace [" + workspaceName
45 + "].\n Do you really want to proceed ?";
46
47 boolean result = MessageDialog.openConfirm(DistPlugin.getDefault()
48 .getWorkbench().getDisplay().getActiveShell(),
49 "Confirm workspace clear", msg);
50 if (result) {
51 Session session = null;
52 try {
53 session = repository.login(workspaceName);
54 NodeIterator nit = session.getRootNode().getNodes();
55 while (nit.hasNext()) {
56 Node node = nit.nextNode();
57 if (node.isNodeType(NodeType.NT_FOLDER)
58 || node.isNodeType(NodeType.NT_UNSTRUCTURED)) {
59 String path = node.getPath();
60 node.remove();
61 session.save();
62 if (log.isDebugEnabled())
63 log.debug("Cleared " + path + " in "
64 + workspaceName);
65 }
66 }
67 CommandHelpers.callCommand(RefreshDistributionsView.ID);
68 } catch (RepositoryException re) {
69 throw new ArgeoException(
70 "Unexpected error while deleting workspace ["
71 + workspaceName + "].", re);
72 } finally {
73 if (session != null)
74 session.logout();
75 }
76 }
77 return null;
78 }
79
80 /* DEPENDENCY INJECTION */
81 public void setRepository(Repository repository) {
82 this.repository = repository;
83 }
84 }