]> git.argeo.org Git - lgpl/argeo-commons.git/blob - AddPrivileges.java
49ed4378f8ca5959bdceb9bd060ac8ba7595c422
[lgpl/argeo-commons.git] / 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.jcr.internal.model.SingleJcrNodeElem;
26 import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
27 import org.argeo.eclipse.ui.workbench.jcr.internal.parts.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 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 ChangeRightsWizard wizard = new ChangeRightsWizard(
65 jcrParentNode.getSession(), jcrParentNode.getPath(),
66 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(
73 "Unexpected error while creating the new workspace.",
74 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 }