]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/DeleteWorkspace.java
676a921c02bc503ea980c9ab68d87269f1d82074
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / commands / DeleteWorkspace.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.client.ui.dist.commands;
17
18 import javax.jcr.Node;
19 import javax.jcr.NodeIterator;
20 import javax.jcr.Repository;
21 import javax.jcr.RepositoryException;
22 import javax.jcr.Session;
23 import javax.jcr.nodetype.NodeType;
24
25 import org.argeo.jcr.JcrUtils;
26 import org.argeo.slc.SlcException;
27 import org.argeo.slc.client.ui.dist.DistPlugin;
28 import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
29 import org.eclipse.core.commands.AbstractHandler;
30 import org.eclipse.core.commands.ExecutionEvent;
31 import org.eclipse.core.commands.ExecutionException;
32 import org.eclipse.jface.dialogs.MessageDialog;
33
34 /**
35 * Delete chosen workspace in the current repository.
36 */
37
38 public class DeleteWorkspace extends AbstractHandler {
39 // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
40
41 public final static String ID = DistPlugin.ID + ".deleteWorkspace";
42 public final static String PARAM_WORKSPACE_NAME = DistPlugin.ID
43 + ".workspaceName";
44 public final static String DEFAULT_LABEL = "Delete";
45 public final static String DEFAULT_ICON_PATH = "icons/removeItem.gif";
46
47 /* DEPENDENCY INJECTION */
48 private Repository repository;
49
50 public Object execute(ExecutionEvent event) throws ExecutionException {
51
52 String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
53
54 String msg = "Your are about to completely delete workspace ["
55 + workspaceName + "].\n Do you really want to proceed ?";
56
57 boolean result = MessageDialog.openConfirm(DistPlugin.getDefault()
58 .getWorkbench().getDisplay().getActiveShell(),
59 "Confirm workspace deletion", msg);
60
61 if (result) {
62 // msg =
63 // "There is no possible turning back, are your REALLY sure you want to proceed ?";
64 msg = "WARNING: \nCurrent Jackrabbit version used does "
65 + "not support workspace management.\n"
66 + "Thus, the workspace will only be cleaned so "
67 + "that you can launch fetch process again.\n\n"
68 + "Do you still want to proceed ?";
69 result = MessageDialog.openConfirm(DistPlugin.getDefault()
70 .getWorkbench().getDisplay().getActiveShell(),
71 "Confirm workspace deletion", msg);
72 }
73
74 if (result) {
75 Session session = null;
76 try {
77 session = repository.login(workspaceName);
78 // TODO use this with a newer version of Jackrabbit
79 // Workspace wsp = session.getWorkspace();
80 // wsp.deleteWorkspace(workspaceName);
81
82 NodeIterator nit = session.getRootNode().getNodes();
83 while (nit.hasNext()) {
84 Node node = nit.nextNode();
85 if (node.isNodeType(NodeType.NT_FOLDER)
86 || node.isNodeType(NodeType.NT_UNSTRUCTURED)) {
87 // String path = node.getPath();
88 node.remove();
89 session.save();
90 }
91 }
92 CommandHelpers.callCommand(RefreshDistributionsView.ID);
93 } catch (RepositoryException re) {
94 throw new SlcException(
95 "Unexpected error while deleting workspace ["
96 + workspaceName + "].", re);
97 } finally {
98 JcrUtils.logoutQuietly(session);
99 }
100 }
101 return null;
102 }
103
104 /* DEPENDENCY INJECTION */
105 public void setRepository(Repository repository) {
106 this.repository = repository;
107 }
108 }