]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/CreateWorkspace.java
Add the ability to remove a JCR privilege from a given node
[lgpl/argeo-commons.git] / org.argeo.eclipse.ui.workbench / src / org / argeo / eclipse / ui / workbench / commands / CreateWorkspace.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.eclipse.ui.workbench.commands;
17
18 import java.util.Arrays;
19
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.internal.jcr.model.RepositoryElem;
24 import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
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;
31
32 /** Create a new JCR workspace */
33 public class CreateWorkspace extends AbstractHandler {
34
35 public final static String ID = WorkbenchUiPlugin.ID + ".addFolderNode";
36
37 public Object execute(ExecutionEvent event) throws ExecutionException {
38
39 ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
40 .getActivePage().getSelection();
41
42 JcrBrowserView view = (JcrBrowserView) HandlerUtil
43 .getActiveWorkbenchWindow(event).getActivePage()
44 .findView(HandlerUtil.getActivePartId(event));
45
46 if (selection != null && !selection.isEmpty()
47 && selection instanceof IStructuredSelection) {
48 Object obj = ((IStructuredSelection) selection).getFirstElement();
49 if (!(obj instanceof RepositoryElem))
50 return null;
51
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.");
60 } else {
61 repositoryNode.createWorkspace(workspaceName);
62 view.nodeAdded(repositoryNode);
63 }
64 }
65 } else {
66 ErrorFeedback.show("Cannot create workspace");
67 }
68 return null;
69 }
70 }