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
.eclipse
.ui
.workbench
.commands
;
18 import java
.util
.Arrays
;
20 import org
.argeo
.eclipse
.ui
.dialogs
.ErrorFeedback
;
21 import org
.argeo
.eclipse
.ui
.dialogs
.SingleValue
;
22 import org
.argeo
.eclipse
.ui
.workbench
.WorkbenchUiPlugin
;
23 import org
.argeo
.eclipse
.ui
.workbench
.jcr
.JcrBrowserView
;
24 import org
.argeo
.eclipse
.ui
.workbench
.jcr
.internal
.model
.RepositoryElem
;
25 import org
.eclipse
.core
.commands
.AbstractHandler
;
26 import org
.eclipse
.core
.commands
.ExecutionEvent
;
27 import org
.eclipse
.core
.commands
.ExecutionException
;
28 import org
.eclipse
.jface
.viewers
.ISelection
;
29 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
30 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
32 /** Create a new JCR workspace */
33 public class CreateWorkspace
extends AbstractHandler
{
35 public final static String ID
= WorkbenchUiPlugin
.ID
+ ".addFolderNode";
37 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
39 ISelection selection
= HandlerUtil
.getActiveWorkbenchWindow(event
)
40 .getActivePage().getSelection();
42 JcrBrowserView view
= (JcrBrowserView
) HandlerUtil
43 .getActiveWorkbenchWindow(event
).getActivePage()
44 .findView(HandlerUtil
.getActivePartId(event
));
46 if (selection
!= null && !selection
.isEmpty()
47 && selection
instanceof IStructuredSelection
) {
48 Object obj
= ((IStructuredSelection
) selection
).getFirstElement();
49 if (!(obj
instanceof RepositoryElem
))
52 RepositoryElem repositoryNode
= (RepositoryElem
) obj
;
53 String workspaceName
= SingleValue
.ask("Workspace name",
54 "Enter workspace name");
55 if (workspaceName
!= null) {
56 if (Arrays
.asList(repositoryNode
.getAccessibleWorkspaceNames())
57 .contains(workspaceName
)) {
58 ErrorFeedback
.show("Workspace " + workspaceName
59 + " already exists.");
61 repositoryNode
.createWorkspace(workspaceName
);
62 view
.nodeAdded(repositoryNode
);
66 ErrorFeedback
.show("Cannot create workspace");