+ InputDialog inputDialog = new InputDialog(HandlerUtil
+ .getActiveWorkbenchWindow(event).getShell(),
+ "New copy of workspace " + wkspName,
+ "Choose a name for the workspace to create", "", null);
+ int result = inputDialog.open();
+ if (result == Window.OK) {
+ String newWorkspaceName = inputDialog.getValue();
+
+ if (newWorkspaceName == null || newWorkspaceName.trim().equals("")
+ || newWorkspaceName.trim().equals(wkspName.trim())) {
+ ErrorDialog
+ .openError(HandlerUtil.getActiveShell(event),
+ "Non valid workspace name", newWorkspaceName
+ + " is not a valid workspace name.",
+ new Status(IStatus.ERROR, "not valid", 0,
+ "Error", null));
+ return null;
+ }
+ Job copyWkspJob = new CopyWkspJob(repositoryFactory, keyring,
+ nodeRepository, targetRepoPath, wkspName, newWorkspaceName,
+ HandlerUtil.getActiveWorkbenchWindow(event).getShell()
+ .getDisplay());
+ copyWkspJob.setUser(true);
+ copyWkspJob.schedule();
+ }
+
+ // Session nodeSession = null;
+ // Session srcSession = null;
+ // Session newSession = null;
+ // try {
+ // nodeSession = nodeRepository.login();
+ // Node repoNode = nodeSession.getNode(targetRepoPath);
+ // Repository repository = RepoUtils.getRepository(repositoryFactory,
+ // keyring, repoNode);
+ // Credentials credentials = RepoUtils.getRepositoryCredentials(
+ // keyring, repoNode);
+ //
+ // InputDialog inputDialog = new InputDialog(HandlerUtil
+ // .getActiveWorkbenchWindow(event).getShell(),
+ // "New copy of workspace " + wkspName,
+ // "Choose a name for the workspace to create", "", null);
+ // int result = inputDialog.open();
+ // if (result == Window.OK) {
+ // String newWorkspaceName = inputDialog.getValue();
+ // srcSession = repository.login(credentials, wkspName);
+ //
+ // // Create the workspace
+ // srcSession.getWorkspace().createWorkspace(newWorkspaceName);
+ // Node srcRootNode = srcSession.getRootNode();
+ // // log in the newly created workspace
+ // newSession = repository.login(credentials, newWorkspaceName);
+ // Node newRootNode = newSession.getRootNode();
+ // RepoUtils.copy(srcRootNode, newRootNode);
+ // newSession.save();
+ // JcrUtils.addPrivilege(newSession, "/", SlcConstants.ROLE_SLC,
+ // Privilege.JCR_ALL);
+ // CommandHelpers.callCommand(RefreshDistributionsView.ID);
+ // }
+ // } catch (RepositoryException re) {
+ // throw new ArgeoException(
+ // "Unexpected error while creating the new workspace.", re);
+ // } finally {
+ // JcrUtils.logoutQuietly(newSession);
+ // JcrUtils.logoutQuietly(srcSession);
+ // JcrUtils.logoutQuietly(nodeSession);
+ // }
+ return null;
+ }
+
+ private static class CopyWkspJob extends PrivilegedJob {
+
+ private RepositoryFactory repositoryFactory;
+ private Keyring keyring;
+ private Repository localRepository;
+ private String targetRepoPath;
+ private String srcWkspName;
+ private String targetWkspName;
+ private Display display;
+
+ public CopyWkspJob(RepositoryFactory repositoryFactory,
+ Keyring keyring, Repository localRepository,
+ String targetRepoPath, String srcWkspName,
+ String targetWkspName, Display display) {
+ super("Duplicate workspace");
+ this.repositoryFactory = repositoryFactory;
+ this.keyring = keyring;
+ this.localRepository = localRepository;
+ this.targetRepoPath = targetRepoPath;
+ this.srcWkspName = srcWkspName;
+ this.targetWkspName = targetWkspName;
+ this.display = display;
+ }
+
+ @Override
+ protected IStatus doRun(IProgressMonitor progressMonitor) {
+ long begin = System.currentTimeMillis();
+
+ ArgeoMonitor monitor = new EclipseArgeoMonitor(progressMonitor);
+ monitor.beginTask("Copy workspace", -1);
+ monitor.subTask("Copying nodes");
+
+ Session nodeSession = null;
+ Session srcSession = null;
+ Session newSession = null;
+ try {
+ nodeSession = localRepository.login();
+ Node repoNode = nodeSession.getNode(targetRepoPath);
+ Repository repository = RepoUtils.getRepository(
+ repositoryFactory, keyring, repoNode);
+ Credentials credentials = RepoUtils.getRepositoryCredentials(
+ keyring, repoNode);
+
+ srcSession = repository.login(credentials, srcWkspName);