]> git.argeo.org Git - lgpl/argeo-commons.git/blob - AddPrivileges.java
684fea65539981c2e2e20d25a7a248c813707c45
[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
36 /** Open a dialog to change rights on the selected node. */
37 public class AddPrivileges extends AbstractHandler {
38 public final static String ID = WorkbenchUiPlugin.ID + ".addPrivileges";
39
40 public Object execute(ExecutionEvent event) throws ExecutionException {
41
42 ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
43 .getActivePage().getSelection();
44 if (selection != null && !selection.isEmpty()
45 && selection instanceof IStructuredSelection) {
46 Object obj = ((IStructuredSelection) selection).getFirstElement();
47 TreeParent treeParentNode = null;
48 Node jcrParentNode = null;
49
50 if (obj instanceof SingleJcrNodeElem) {
51 treeParentNode = (TreeParent) obj;
52 jcrParentNode = ((SingleJcrNodeElem) treeParentNode).getNode();
53 } else if (obj instanceof WorkspaceElem) {
54 treeParentNode = (TreeParent) obj;
55 jcrParentNode = ((WorkspaceElem) treeParentNode).getRootNode();
56 } else
57 return null;
58
59 try {
60 ChangeRightsWizard wizard = new ChangeRightsWizard(
61 jcrParentNode.getSession(), jcrParentNode.getPath());
62 WizardDialog dialog = new WizardDialog(
63 HandlerUtil.getActiveShell(event), wizard);
64 dialog.open();
65 return null;
66 } catch (RepositoryException re) {
67 throw new ArgeoException(
68 "Unexpected error while creating the new workspace.",
69 re);
70 }
71 } else {
72 ErrorFeedback.show("Cannot add privileges");
73 }
74 return null;
75 }
76 }