]> 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
Update licence headers
[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.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.argeo.ArgeoException;
28 import org.argeo.slc.client.ui.dist.DistPlugin;
29 import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
30 import org.eclipse.core.commands.AbstractHandler;
31 import org.eclipse.core.commands.ExecutionEvent;
32 import org.eclipse.core.commands.ExecutionException;
33 import org.eclipse.jface.dialogs.MessageDialog;
34
35 /**
36 * Delete chosen workspace in the current repository.
37 */
38
39 public class DeleteWorkspace extends AbstractHandler {
40 private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
41
42 public final static String ID = DistPlugin.ID + ".deleteWorkspace";
43 public final static String PARAM_WORKSPACE_NAME = DistPlugin.ID
44 + ".workspaceName";
45 public final static String DEFAULT_LABEL = "Delete";
46 public final static String DEFAULT_ICON_PATH = "icons/removeItem.gif";
47
48 /* DEPENDENCY INJECTION */
49 private Repository repository;
50
51 public Object execute(ExecutionEvent event) throws ExecutionException {
52
53 // MessageDialog.openWarning(DistPlugin.getDefault()
54 // .getWorkbench().getDisplay().getActiveShell(),
55 // "WARNING", "Not yet implemented");
56 // return null;
57
58 String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
59 String msg = "Your are about to clear workspace [" + workspaceName
60 + "].\n Do you really want to proceed ?";
61
62 boolean result = MessageDialog.openConfirm(DistPlugin.getDefault()
63 .getWorkbench().getDisplay().getActiveShell(),
64 "Confirm workspace clear", msg);
65 if (result) {
66 Session session = null;
67 try {
68 session = repository.login(workspaceName);
69 NodeIterator nit = session.getRootNode().getNodes();
70 while (nit.hasNext()) {
71 Node node = nit.nextNode();
72 if (node.isNodeType(NodeType.NT_FOLDER)
73 || node.isNodeType(NodeType.NT_UNSTRUCTURED)) {
74 String path = node.getPath();
75 node.remove();
76 session.save();
77 if (log.isDebugEnabled())
78 log.debug("Cleared " + path + " in "
79 + workspaceName);
80 }
81 }
82 CommandHelpers.callCommand(RefreshDistributionsView.ID);
83 } catch (RepositoryException re) {
84 throw new ArgeoException(
85 "Unexpected error while deleting workspace ["
86 + workspaceName + "].", re);
87 } finally {
88 if (session != null)
89 session.logout();
90 }
91 }
92 return null;
93 }
94
95 /* DEPENDENCY INJECTION */
96 public void setRepository(Repository repository) {
97 this.repository = repository;
98 }
99 }