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
.jcr
.ui
.explorer
.commands
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
21 import org
.argeo
.ArgeoException
;
22 import org
.argeo
.eclipse
.ui
.ErrorFeedback
;
23 import org
.argeo
.eclipse
.ui
.TreeParent
;
24 import org
.argeo
.jcr
.ui
.explorer
.JcrExplorerPlugin
;
25 import org
.argeo
.jcr
.ui
.explorer
.model
.SingleJcrNodeElem
;
26 import org
.argeo
.jcr
.ui
.explorer
.model
.WorkspaceElem
;
27 import org
.argeo
.jcr
.ui
.explorer
.wizards
.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
;
37 * Open a dialog to change rights on the selected node.
40 public class AddPrivileges
extends AbstractHandler
{
41 public final static String ID
= JcrExplorerPlugin
.ID
+ ".addPrivileges";
43 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
45 ISelection selection
= HandlerUtil
.getActiveWorkbenchWindow(event
)
46 .getActivePage().getSelection();
47 if (selection
!= null && !selection
.isEmpty()
48 && selection
instanceof IStructuredSelection
) {
49 Object obj
= ((IStructuredSelection
) selection
).getFirstElement();
50 TreeParent treeParentNode
= null;
51 Node jcrParentNode
= null;
53 if (obj
instanceof SingleJcrNodeElem
) {
54 treeParentNode
= (TreeParent
) obj
;
55 jcrParentNode
= ((SingleJcrNodeElem
) treeParentNode
).getNode();
56 } else if (obj
instanceof WorkspaceElem
) {
57 treeParentNode
= (TreeParent
) obj
;
58 jcrParentNode
= ((WorkspaceElem
) treeParentNode
).getRootNode();
63 ChangeRightsWizard wizard
= new ChangeRightsWizard(
64 jcrParentNode
.getSession(), jcrParentNode
.getPath());
65 WizardDialog dialog
= new WizardDialog(
66 HandlerUtil
.getActiveShell(event
), wizard
);
69 } catch (RepositoryException re
) {
70 throw new ArgeoException(
71 "Unexpected error while creating the new workspace.",
75 ErrorFeedback
.show("Cannot add privileges");