]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - internal/parts/ChangeRightsWizard.java
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
.eclipse
.ui
.workbench
.jcr
.internal
.parts
;
18 import javax
.jcr
.RepositoryException
;
19 import javax
.jcr
.Session
;
20 import javax
.jcr
.security
.Privilege
;
22 import org
.argeo
.ArgeoException
;
23 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
24 import org
.argeo
.eclipse
.ui
.workbench
.users
.PickUpGroupDialog
;
25 import org
.argeo
.jcr
.JcrUtils
;
26 import org
.eclipse
.jface
.window
.Window
;
27 import org
.eclipse
.jface
.wizard
.Wizard
;
28 import org
.eclipse
.jface
.wizard
.WizardPage
;
29 import org
.eclipse
.swt
.SWT
;
30 import org
.eclipse
.swt
.events
.ModifyEvent
;
31 import org
.eclipse
.swt
.events
.ModifyListener
;
32 import org
.eclipse
.swt
.events
.SelectionAdapter
;
33 import org
.eclipse
.swt
.events
.SelectionEvent
;
34 import org
.eclipse
.swt
.layout
.GridData
;
35 import org
.eclipse
.swt
.layout
.GridLayout
;
36 import org
.eclipse
.swt
.widgets
.Combo
;
37 import org
.eclipse
.swt
.widgets
.Composite
;
38 import org
.eclipse
.swt
.widgets
.Label
;
39 import org
.eclipse
.swt
.widgets
.Link
;
40 import org
.eclipse
.swt
.widgets
.Text
;
41 import org
.osgi
.service
.useradmin
.UserAdmin
;
43 /** Add Jcr privileges to the chosen user group on a given node */
44 public class ChangeRightsWizard
extends Wizard
{
46 private UserAdmin userAdmin
;
47 private Session currentSession
;
51 private DefinePrivilegePage page
;
54 protected final static String
[] validAuthType
= { Privilege
.JCR_READ
,
55 Privilege
.JCR_WRITE
, Privilege
.JCR_ALL
};
57 public ChangeRightsWizard(Session currentSession
, String path
,
58 UserAdmin userAdmin
) {
60 this.userAdmin
= userAdmin
;
61 this.currentSession
= currentSession
;
66 public void addPages() {
68 page
= new DefinePrivilegePage(userAdmin
, path
);
70 } catch (Exception e
) {
71 throw new ArgeoException("Cannot add page to wizard ", e
);
76 public boolean performFinish() {
80 JcrUtils
.addPrivilege(currentSession
, path
, page
.getGroupName(),
81 page
.getAuthTypeStr());
82 } catch (RepositoryException re
) {
83 throw new ArgeoException(
84 "Unexpected error while setting privileges", re
);
89 private class DefinePrivilegePage
extends WizardPage
implements ModifyListener
{
90 private static final long serialVersionUID
= 8084431378762283920L;
93 final private UserAdmin userAdmin
;
96 private Text groupNameTxt
;
97 private Combo authorizationCmb
;
99 public DefinePrivilegePage(UserAdmin userAdmin
, String path
) {
101 this.userAdmin
= userAdmin
;
102 setTitle("Define the privilege to apply to " + path
);
105 public void createControl(Composite parent
) {
107 Composite composite
= new Composite(parent
, SWT
.NONE
);
108 composite
.setLayout(new GridLayout(3, false));
109 Label lbl
= new Label(composite
, SWT
.LEAD
);
110 lbl
.setText("Group name");
111 lbl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
112 groupNameTxt
= new Text(composite
, SWT
.LEAD
| SWT
.BORDER
);
113 groupNameTxt
.setLayoutData(EclipseUiUtils
.fillWidth());
114 if (groupNameTxt
!= null)
115 groupNameTxt
.addModifyListener(this);
117 Link pickUpLk
= new Link(composite
, SWT
.LEFT
);
118 pickUpLk
.setText(" <a>Pick up</a> ");
119 pickUpLk
.addSelectionListener(new SelectionAdapter() {
120 private static final long serialVersionUID
= 1L;
123 public void widgetSelected(SelectionEvent e
) {
124 PickUpGroupDialog dialog
= new PickUpGroupDialog(
125 getShell(), "Choose a group", userAdmin
);
126 if (dialog
.open() == Window
.OK
)
127 groupNameTxt
.setText(dialog
.getSelected());
133 new Label(composite
, SWT
.NONE
)
134 .setText("Choose corresponding rights");
135 authorizationCmb
= new Combo(composite
, SWT
.BORDER
| SWT
.V_SCROLL
);
136 authorizationCmb
.setItems(validAuthType
);
137 authorizationCmb
.setLayoutData(EclipseUiUtils
.fillWidth(2));
138 authorizationCmb
.select(0);
141 setControl(composite
);
144 protected String
getGroupName() {
145 return groupNameTxt
.getText();
148 protected String
getAuthTypeStr() {
149 return authorizationCmb
.getItem(authorizationCmb
150 .getSelectionIndex());
153 public void modifyText(ModifyEvent event
) {
154 String message
= checkComplete();
156 setMessage(message
, WizardPage
.ERROR
);
158 setMessage("Complete", WizardPage
.INFORMATION
);
159 setPageComplete(true);
163 /** @return error message or null if complete */
164 protected String
checkComplete() {
165 String groupStr
= groupNameTxt
.getText();
166 if (groupStr
== null || "".equals(groupStr
))
167 return "Please enter the name of the corresponding group.";