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
.Repository
;
20 import javax
.jcr
.RepositoryException
;
21 import javax
.jcr
.Session
;
23 import org
.apache
.commons
.logging
.Log
;
24 import org
.apache
.commons
.logging
.LogFactory
;
25 import org
.argeo
.ArgeoException
;
26 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
27 import org
.argeo
.slc
.client
.ui
.dist
.utils
.CommandHelpers
;
28 import org
.argeo
.slc
.repo
.RepoUtils
;
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
.InputDialog
;
33 import org
.eclipse
.ui
.IWorkbenchWindow
;
36 * Create a copy of the chosen workspace in the current repository.
39 public class CopyWorkspace
extends AbstractHandler
{
40 private static final Log log
= LogFactory
.getLog(CopyWorkspace
.class);
41 public final static String ID
= DistPlugin
.ID
+ ".copyWorkspace";
42 public final static String PARAM_WORKSPACE_NAME
= DistPlugin
.ID
44 public final static String DEFAULT_LABEL
= "Duplicate";
45 public final static String DEFAULT_ICON_PATH
= "icons/addItem.gif";
47 /* DEPENDENCY INJECTION */
48 private Repository repository
;
50 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
51 String srcWorkspaceName
= event
.getParameter(PARAM_WORKSPACE_NAME
);
53 if (log
.isTraceEnabled())
54 log
.debug("WORKSPACE " + srcWorkspaceName
+ " About to be copied");
56 // MessageDialog.openWarning(DistPlugin.getDefault()
57 // .getWorkbench().getDisplay().getActiveShell(),
58 // "WARNING", "Not yet implemented");
61 IWorkbenchWindow iww
= DistPlugin
.getDefault().getWorkbench()
62 .getActiveWorkbenchWindow();
63 InputDialog inputDialog
= new InputDialog(iww
.getShell(),
64 "New copy of the current workspace",
65 "Choose a name for the workspace to create", "", null);
67 String newWorkspaceName
= inputDialog
.getValue();
68 Session srcSession
= null;
69 Session newSession
= null;
71 srcSession
= repository
.login(srcWorkspaceName
);
73 // Create the workspace
74 srcSession
.getWorkspace().createWorkspace(newWorkspaceName
);
75 Node srcRootNode
= srcSession
.getRootNode();
76 // log in the newly created workspace
77 newSession
= repository
.login(newWorkspaceName
);
79 Node newRootNode
= newSession
.getRootNode();
80 RepoUtils
.copy(srcRootNode
, newRootNode
);
83 CommandHelpers
.callCommand(RefreshDistributionsView
.ID
);
84 } catch (RepositoryException re
) {
85 throw new ArgeoException(
86 "Unexpected error while creating the new workspace.", re
);
88 if (srcSession
!= null)
90 if (newSession
!= null)
96 /* DEPENDENCY INJECTION */
97 public void setRepository(Repository repository
) {
98 this.repository
= repository
;