1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.cms.ui.workbench.internal.jcr.commands;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20
21 import org.argeo.cms.ui.jcr.model.SingleJcrNodeElem;
22 import org.argeo.cms.ui.jcr.model.WorkspaceElem;
23 import org.argeo.cms.ui.workbench.WorkbenchUiPlugin;
24 import org.argeo.cms.ui.workbench.internal.jcr.parts.AddPrivilegeWizard;
25 import org.argeo.eclipse.ui.EclipseUiException;
26 import org.argeo.eclipse.ui.TreeParent;
27 import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
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
38 public class AddPrivileges extends AbstractHandler {
39 public final static String ID = WorkbenchUiPlugin.PLUGIN_ID
40 + ".addPrivileges";
41
42
43 private UserAdmin userAdmin;
44
45 public Object execute(ExecutionEvent event) throws ExecutionException {
46
47 ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
48 .getActivePage().getSelection();
49 if (selection != null && !selection.isEmpty()
50 && selection instanceof IStructuredSelection) {
51 Object obj = ((IStructuredSelection) selection).getFirstElement();
52 TreeParent treeParentNode = null;
53 Node jcrParentNode = null;
54
55 if (obj instanceof SingleJcrNodeElem) {
56 treeParentNode = (TreeParent) obj;
57 jcrParentNode = ((SingleJcrNodeElem) treeParentNode).getNode();
58 } else if (obj instanceof WorkspaceElem) {
59 treeParentNode = (TreeParent) obj;
60 jcrParentNode = ((WorkspaceElem) treeParentNode).getRootNode();
61 } else
62 return null;
63
64 try {
65 String targetPath = jcrParentNode.getPath();
66 AddPrivilegeWizard wizard = new AddPrivilegeWizard(
67 jcrParentNode.getSession(), targetPath, userAdmin);
68 WizardDialog dialog = new WizardDialog(
69 HandlerUtil.getActiveShell(event), wizard);
70 dialog.open();
71 return null;
72 } catch (RepositoryException re) {
73 throw new EclipseUiException("Unable to retrieve "
74 + "path or JCR session to add privilege on "
75 + jcrParentNode, re);
76 }
77 } else {
78 ErrorFeedback.show("Cannot add privileges");
79 }
80 return null;
81 }
82
83
84 public void setUserAdmin(UserAdmin userAdmin) {
85 this.userAdmin = userAdmin;
86 }
87 }