2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.cms
.ui
.workbench
.internal
.jcr
.commands
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
21 import org
.argeo
.cms
.ui
.workbench
.WorkbenchUiPlugin
;
22 import org
.argeo
.cms
.ui
.workbench
.internal
.jcr
.model
.SingleJcrNodeElem
;
23 import org
.argeo
.cms
.ui
.workbench
.internal
.jcr
.model
.WorkspaceElem
;
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
;
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
.PLUGIN_ID
42 /* DEPENDENCY INJECTION */
43 private UserAdmin userAdmin
;
45 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
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;
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();
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
);
72 } catch (RepositoryException re
) {
73 throw new EclipseUiException("Unable to retrieve "
74 + "path or JCR session to add privilege on "
78 ErrorFeedback
.show("Cannot add privileges");
83 /* DEPENDENCY INJECTION */
84 public void setUserAdmin(UserAdmin userAdmin
) {
85 this.userAdmin
= userAdmin
;