1 package org
.argeo
.slc
.client
.ui
.dist
.commands
;
3 import javax
.jcr
.Credentials
;
5 import javax
.jcr
.NodeIterator
;
6 import javax
.jcr
.Repository
;
7 import javax
.jcr
.RepositoryException
;
8 import javax
.jcr
.RepositoryFactory
;
9 import javax
.jcr
.Session
;
10 import javax
.jcr
.nodetype
.NodeType
;
12 import org
.argeo
.api
.security
.Keyring
;
13 import org
.argeo
.jcr
.JcrUtils
;
14 import org
.argeo
.slc
.SlcException
;
15 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
16 import org
.argeo
.slc
.client
.ui
.dist
.utils
.CommandHelpers
;
17 import org
.argeo
.slc
.repo
.RepoUtils
;
18 import org
.eclipse
.core
.commands
.AbstractHandler
;
19 import org
.eclipse
.core
.commands
.ExecutionEvent
;
20 import org
.eclipse
.core
.commands
.ExecutionException
;
21 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
22 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
25 * Delete chosen workspace in the current repository.
27 * Due to current version of JackRabbit, it only cleans it for the time being,
28 * removing all nodes of type {@code NodeType.NT_FOLDER} and
29 * {@code NodeType.NT_UNSTRUCTURED}
31 public class DeleteWorkspace
extends AbstractHandler
{
32 // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
34 public final static String ID
= DistPlugin
.PLUGIN_ID
+ ".deleteWorkspace";
35 public final static String DEFAULT_LABEL
= "Clear";
36 public final static ImageDescriptor DEFAULT_ICON
= DistPlugin
37 .getImageDescriptor("icons/removeItem.gif");
39 public final static String PARAM_WORKSPACE_NAME
= "workspaceName";
40 public final static String PARAM_TARGET_REPO_PATH
= "targetRepoPath";
42 // DEPENDENCY INJECTION
43 private RepositoryFactory repositoryFactory
;
44 private Keyring keyring
;
45 private Repository nodeRepository
;
47 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
49 String targetRepoPath
= event
.getParameter(PARAM_TARGET_REPO_PATH
);
50 String workspaceName
= event
.getParameter(PARAM_WORKSPACE_NAME
);
52 Session nodeSession
= null;
53 Session session
= null;
55 nodeSession
= nodeRepository
.login();
56 Node repoNode
= nodeSession
.getNode(targetRepoPath
);
57 Repository repository
= RepoUtils
.getRepository(repositoryFactory
,
59 Credentials credentials
= RepoUtils
.getRepositoryCredentials(
62 String msg
= "Your are about to completely delete workspace ["
63 + workspaceName
+ "].\n Do you really want to proceed?";
64 boolean result
= MessageDialog
.openConfirm(DistPlugin
.getDefault()
65 .getWorkbench().getDisplay().getActiveShell(),
66 "Confirm workspace deletion", msg
);
70 // "There is no possible turning back, are your REALLY sure you want to proceed ?";
71 msg
= "WARNING: \nCurrent Jackrabbit version used does "
72 + "not support workspace deletion.\n"
73 + "Thus, the workspace will only be cleaned so "
74 + "that you can launch fetch process again.\n\n"
75 + "Do you still want to proceed?";
76 result
= MessageDialog
.openConfirm(DistPlugin
.getDefault()
77 .getWorkbench().getDisplay().getActiveShell(),
78 "Confirm workspace deletion", msg
);
82 session
= repository
.login(credentials
, workspaceName
);
83 // TODO use this with a newer version of Jackrabbit
84 // Workspace wsp = session.getWorkspace();
85 // wsp.deleteWorkspace(workspaceName);
86 NodeIterator nit
= session
.getRootNode().getNodes();
87 while (nit
.hasNext()) {
88 Node node
= nit
.nextNode();
89 if (node
.isNodeType(NodeType
.NT_FOLDER
)
90 || node
.isNodeType(NodeType
.NT_UNSTRUCTURED
)) {
91 // String path = node.getPath();
96 CommandHelpers
.callCommand(RefreshDistributionsView
.ID
);
98 } catch (RepositoryException re
) {
99 throw new SlcException(
100 "Unexpected error while deleting workspace ["
101 + workspaceName
+ "].", re
);
103 JcrUtils
.logoutQuietly(session
);
104 JcrUtils
.logoutQuietly(nodeSession
);
109 /* DEPENDENCY INJECTION */
110 public void setNodeRepository(Repository nodeRepository
) {
111 this.nodeRepository
= nodeRepository
;
114 public void setRepositoryFactory(RepositoryFactory repositoryFactory
) {
115 this.repositoryFactory
= repositoryFactory
;
118 public void setKeyring(Keyring keyring
) {
119 this.keyring
= keyring
;