]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddPrivileges.java
fix a typo in the resulting file.
[lgpl/argeo-commons.git] / server / plugins / org.argeo.jcr.ui.explorer / src / main / java / org / argeo / jcr / ui / explorer / commands / AddPrivileges.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.jcr.ui.explorer.commands;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20
21 import org.argeo.ArgeoException;
22 import org.argeo.eclipse.ui.ErrorFeedback;
23 import org.argeo.eclipse.ui.TreeParent;
24 import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
25 import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
26 import org.argeo.jcr.ui.explorer.model.WorkspaceElem;
27 import org.argeo.jcr.ui.explorer.wizards.ChangeRightsWizard;
28 import org.eclipse.core.commands.AbstractHandler;
29 import org.eclipse.core.commands.ExecutionEvent;
30 import org.eclipse.core.commands.ExecutionException;
31 import org.eclipse.jface.viewers.ISelection;
32 import org.eclipse.jface.viewers.IStructuredSelection;
33 import org.eclipse.jface.wizard.WizardDialog;
34 import org.eclipse.ui.handlers.HandlerUtil;
35
36 /**
37 * Open a dialog to change rights on the selected node.
38 */
39
40 public class AddPrivileges extends AbstractHandler {
41 public final static String ID = JcrExplorerPlugin.ID + ".addPrivileges";
42
43 public Object execute(ExecutionEvent event) throws ExecutionException {
44
45 ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
46 .getActivePage().getSelection();
47 if (selection != null && !selection.isEmpty()
48 && selection instanceof IStructuredSelection) {
49 Object obj = ((IStructuredSelection) selection).getFirstElement();
50 TreeParent treeParentNode = null;
51 Node jcrParentNode = null;
52
53 if (obj instanceof SingleJcrNodeElem) {
54 treeParentNode = (TreeParent) obj;
55 jcrParentNode = ((SingleJcrNodeElem) treeParentNode).getNode();
56 } else if (obj instanceof WorkspaceElem) {
57 treeParentNode = (TreeParent) obj;
58 jcrParentNode = ((WorkspaceElem) treeParentNode).getRootNode();
59 } else
60 return null;
61
62 try {
63 ChangeRightsWizard wizard = new ChangeRightsWizard(
64 jcrParentNode.getSession(), jcrParentNode.getPath());
65 WizardDialog dialog = new WizardDialog(
66 HandlerUtil.getActiveShell(event), wizard);
67 dialog.open();
68 return null;
69 } catch (RepositoryException re) {
70 throw new ArgeoException(
71 "Unexpected error while creating the new workspace.",
72 re);
73 }
74 } else {
75 ErrorFeedback.show("Cannot add privileges");
76 }
77 return null;
78 }
79 }