1 package org
.argeo
.cms
.ui
.workbench
.internal
.jcr
.commands
;
3 import java
.util
.Arrays
;
5 import org
.argeo
.cms
.ui
.jcr
.model
.RepositoryElem
;
6 import org
.argeo
.cms
.ui
.workbench
.WorkbenchUiPlugin
;
7 import org
.argeo
.cms
.ui
.workbench
.jcr
.JcrBrowserView
;
8 import org
.argeo
.eclipse
.ui
.dialogs
.ErrorFeedback
;
9 import org
.argeo
.eclipse
.ui
.dialogs
.SingleValue
;
10 import org
.eclipse
.core
.commands
.AbstractHandler
;
11 import org
.eclipse
.core
.commands
.ExecutionEvent
;
12 import org
.eclipse
.core
.commands
.ExecutionException
;
13 import org
.eclipse
.jface
.viewers
.ISelection
;
14 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
15 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
17 /** Create a new JCR workspace */
18 public class CreateWorkspace
extends AbstractHandler
{
20 public final static String ID
= WorkbenchUiPlugin
.PLUGIN_ID
23 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
25 ISelection selection
= HandlerUtil
.getActiveWorkbenchWindow(event
)
26 .getActivePage().getSelection();
28 JcrBrowserView view
= (JcrBrowserView
) HandlerUtil
29 .getActiveWorkbenchWindow(event
).getActivePage()
30 .findView(HandlerUtil
.getActivePartId(event
));
32 if (selection
!= null && !selection
.isEmpty()
33 && selection
instanceof IStructuredSelection
) {
34 Object obj
= ((IStructuredSelection
) selection
).getFirstElement();
35 if (!(obj
instanceof RepositoryElem
))
38 RepositoryElem repositoryNode
= (RepositoryElem
) obj
;
39 String workspaceName
= SingleValue
.ask("Workspace name",
40 "Enter workspace name");
41 if (workspaceName
!= null) {
42 if (Arrays
.asList(repositoryNode
.getAccessibleWorkspaceNames())
43 .contains(workspaceName
)) {
44 ErrorFeedback
.show("Workspace " + workspaceName
45 + " already exists.");
47 repositoryNode
.createWorkspace(workspaceName
);
48 view
.nodeAdded(repositoryNode
);
52 ErrorFeedback
.show("Cannot create workspace");