]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddPrivileges.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 / 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.eclipse.ui.workbench.commands;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20
21 import org.argeo.ArgeoException;
22 import org.argeo.eclipse.ui.TreeParent;
23 import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
24 import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
25 import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
26 import org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem;
27 import org.argeo.eclipse.ui.workbench.internal.jcr.parts.AddPrivilegeWizard;
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 import org.osgi.service.useradmin.UserAdmin;
36
37 /** Open a dialog to add privileges on the selected node to a chosen group */
38 public class AddPrivileges extends AbstractHandler {
39 public final static String ID = WorkbenchUiPlugin.ID + ".addPrivileges";
40
41 /* DEPENDENCY INJECTION */
42 private UserAdmin userAdmin;
43
44 public Object execute(ExecutionEvent event) throws ExecutionException {
45
46 ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
47 .getActivePage().getSelection();
48 if (selection != null && !selection.isEmpty()
49 && selection instanceof IStructuredSelection) {
50 Object obj = ((IStructuredSelection) selection).getFirstElement();
51 TreeParent treeParentNode = null;
52 Node jcrParentNode = null;
53
54 if (obj instanceof SingleJcrNodeElem) {
55 treeParentNode = (TreeParent) obj;
56 jcrParentNode = ((SingleJcrNodeElem) treeParentNode).getNode();
57 } else if (obj instanceof WorkspaceElem) {
58 treeParentNode = (TreeParent) obj;
59 jcrParentNode = ((WorkspaceElem) treeParentNode).getRootNode();
60 } else
61 return null;
62
63 try {
64 String targetPath = jcrParentNode.getPath();
65 AddPrivilegeWizard wizard = new AddPrivilegeWizard(
66 jcrParentNode.getSession(), targetPath, userAdmin);
67 WizardDialog dialog = new WizardDialog(
68 HandlerUtil.getActiveShell(event), wizard);
69 dialog.open();
70 return null;
71 } catch (RepositoryException re) {
72 throw new ArgeoException("Unable to retrieve "
73 + "path or JCR session to add privilege on "
74 + jcrParentNode, re);
75 }
76 } else {
77 ErrorFeedback.show("Cannot add privileges");
78 }
79 return null;
80 }
81
82 /* DEPENDENCY INJECTION */
83 public void setUserAdmin(UserAdmin userAdmin) {
84 this.userAdmin = userAdmin;
85 }
86 }