- // TODO : add an input validator
- InputDialog inputDialog = new InputDialog(iww.getShell(),
- "New workspace", "Choose a name for the workspace to create",
- "", null);
- inputDialog.open();
- String workspaceName = inputDialog.getValue();
- Session session = null;
- try {
- session = repository.login();
- session.getWorkspace().createWorkspace(workspaceName);
- CommandHelpers.callCommand(RefreshDistributionsView.ID);
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexpected error while creating the new workspace.", re);
- } finally {
- if (session != null)
- session.logout();
+ String prefix = "";
+
+ IWorkbenchPart view = iww.getActivePage().getActivePart();
+ if (view instanceof DistributionsView) {
+ DistributionViewSelectedElement dvse = ((DistributionsView) view)
+ .getSelectedElement();
+ if (dvse != null && (dvse.isRepository || dvse.isWorkspaceGroup)) {
+ repository = dvse.repository;
+ credentials = dvse.credentials;
+ prefix = dvse.wkspPrefix;
+ }
+ }
+
+ if (repository != null) {
+ // TODO : add an input validator
+ InputDialog inputDialog = new InputDialog(iww.getShell(),
+ "Workspace name?",
+ "Choose a name for the workspace to create", prefix + "-",
+ null);
+ int result = inputDialog.open();
+
+ String workspaceName = inputDialog.getValue();
+
+ // Canceled by user
+ if (result == Dialog.CANCEL || workspaceName == null
+ || "".equals(workspaceName.trim()))
+ return null;
+
+ Session session = null;
+ try {
+ session = repository.login(credentials);
+ session.getWorkspace().createWorkspace(workspaceName);
+ JcrUtils.logoutQuietly(session);
+ // init new workspace
+ session = repository.login(workspaceName);
+ JcrUtils.addPrivilege(session, "/", slcRole, Privilege.JCR_ALL);
+ CommandHelpers.callCommand(RefreshDistributionsView.ID);
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while creating the new workspace.",
+ re);
+ } finally {
+ JcrUtils.logoutQuietly(session);
+ }
+ if (log.isTraceEnabled())
+ log.trace("WORKSPACE " + workspaceName + " CREATED");