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
.Credentials
;
19 import javax
.jcr
.Node
;
20 import javax
.jcr
.NodeIterator
;
21 import javax
.jcr
.Repository
;
22 import javax
.jcr
.RepositoryException
;
23 import javax
.jcr
.Session
;
24 import javax
.jcr
.nodetype
.NodeType
;
26 import org
.argeo
.jcr
.JcrUtils
;
27 import org
.argeo
.slc
.SlcException
;
28 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
29 import org
.argeo
.slc
.client
.ui
.dist
.utils
.CommandHelpers
;
30 import org
.argeo
.slc
.client
.ui
.dist
.views
.DistributionsView
;
31 import org
.argeo
.slc
.client
.ui
.dist
.views
.DistributionsView
.DistributionViewSelectedElement
;
32 import org
.eclipse
.core
.commands
.AbstractHandler
;
33 import org
.eclipse
.core
.commands
.ExecutionEvent
;
34 import org
.eclipse
.core
.commands
.ExecutionException
;
35 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
36 import org
.eclipse
.ui
.IWorkbenchPart
;
37 import org
.eclipse
.ui
.IWorkbenchWindow
;
40 * Delete chosen workspace in the current repository.
43 public class DeleteWorkspace
extends AbstractHandler
{
44 // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
46 public final static String ID
= DistPlugin
.ID
+ ".deleteWorkspace";
47 public final static String DEFAULT_LABEL
= "Clear";
48 public final static String DEFAULT_ICON_PATH
= "icons/removeItem.gif";
50 private Repository repository
;
51 private Credentials credentials
;
53 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
55 String workspaceName
= "";
57 IWorkbenchWindow iww
= DistPlugin
.getDefault().getWorkbench()
58 .getActiveWorkbenchWindow();
59 IWorkbenchPart view
= iww
.getActivePage().getActivePart();
60 if (view
instanceof DistributionsView
) {
61 DistributionViewSelectedElement dvse
= ((DistributionsView
) view
)
62 .getSelectedElement();
63 if (dvse
!= null && (dvse
.isWorkspace
)) {
64 repository
= dvse
.repository
;
65 credentials
= dvse
.credentials
;
66 workspaceName
= dvse
.wkspName
;
70 if (repository
== null)
73 String msg
= "Your are about to completely delete workspace ["
74 + workspaceName
+ "].\n Do you really want to proceed ?";
75 boolean result
= MessageDialog
.openConfirm(DistPlugin
.getDefault()
76 .getWorkbench().getDisplay().getActiveShell(),
77 "Confirm workspace deletion", msg
);
81 // "There is no possible turning back, are your REALLY sure you want to proceed ?";
82 msg
= "WARNING: \nCurrent Jackrabbit version used does "
83 + "not support workspace management.\n"
84 + "Thus, the workspace will only be cleaned so "
85 + "that you can launch fetch process again.\n\n"
86 + "Do you still want to proceed ?";
87 result
= MessageDialog
.openConfirm(DistPlugin
.getDefault()
88 .getWorkbench().getDisplay().getActiveShell(),
89 "Confirm workspace deletion", msg
);
93 Session session
= null;
95 session
= repository
.login(credentials
, workspaceName
);
96 // TODO use this with a newer version of Jackrabbit
97 // Workspace wsp = session.getWorkspace();
98 // wsp.deleteWorkspace(workspaceName);
100 NodeIterator nit
= session
.getRootNode().getNodes();
101 while (nit
.hasNext()) {
102 Node node
= nit
.nextNode();
103 if (node
.isNodeType(NodeType
.NT_FOLDER
)
104 || node
.isNodeType(NodeType
.NT_UNSTRUCTURED
)) {
105 // String path = node.getPath();
110 CommandHelpers
.callCommand(RefreshDistributionsView
.ID
);
111 } catch (RepositoryException re
) {
112 throw new SlcException(
113 "Unexpected error while deleting workspace ["
114 + workspaceName
+ "].", re
);
116 JcrUtils
.logoutQuietly(session
);