2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.client
.ui
.dist
.commands
;
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
;
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
;
36 * Delete chosen workspace in the current repository.
39 public class DeleteWorkspace
extends AbstractHandler
{
40 private static final Log log
= LogFactory
.getLog(DeleteWorkspace
.class);
42 public final static String ID
= DistPlugin
.ID
+ ".deleteWorkspace";
43 public final static String PARAM_WORKSPACE_NAME
= DistPlugin
.ID
45 public final static String DEFAULT_LABEL
= "Delete";
46 public final static String DEFAULT_ICON_PATH
= "icons/removeItem.gif";
48 /* DEPENDENCY INJECTION */
49 private Repository repository
;
51 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
53 // MessageDialog.openWarning(DistPlugin.getDefault()
54 // .getWorkbench().getDisplay().getActiveShell(),
55 // "WARNING", "Not yet implemented");
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 ?";
62 boolean result
= MessageDialog
.openConfirm(DistPlugin
.getDefault()
63 .getWorkbench().getDisplay().getActiveShell(),
64 "Confirm workspace clear", msg
);
66 Session session
= null;
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();
77 if (log
.isDebugEnabled())
78 log
.debug("Cleared " + path
+ " in "
82 CommandHelpers
.callCommand(RefreshDistributionsView
.ID
);
83 } catch (RepositoryException re
) {
84 throw new ArgeoException(
85 "Unexpected error while deleting workspace ["
86 + workspaceName
+ "].", re
);
95 /* DEPENDENCY INJECTION */
96 public void setRepository(Repository repository
) {
97 this.repository
= repository
;