]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - internal/parts/ChooseRightsPage.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
.security
.Privilege
;
20 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
21 import org
.argeo
.eclipse
.ui
.workbench
.users
.PickUpGroupDialog
;
22 import org
.eclipse
.jface
.window
.Window
;
23 import org
.eclipse
.jface
.wizard
.WizardPage
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.events
.ModifyEvent
;
26 import org
.eclipse
.swt
.events
.ModifyListener
;
27 import org
.eclipse
.swt
.events
.SelectionAdapter
;
28 import org
.eclipse
.swt
.events
.SelectionEvent
;
29 import org
.eclipse
.swt
.layout
.GridData
;
30 import org
.eclipse
.swt
.layout
.GridLayout
;
31 import org
.eclipse
.swt
.widgets
.Combo
;
32 import org
.eclipse
.swt
.widgets
.Composite
;
33 import org
.eclipse
.swt
.widgets
.Label
;
34 import org
.eclipse
.swt
.widgets
.Link
;
35 import org
.eclipse
.swt
.widgets
.Text
;
36 import org
.osgi
.service
.useradmin
.UserAdmin
;
38 /** Simple wizard page to choose a group and corresponding rights to assign */
39 public class ChooseRightsPage
extends WizardPage
implements ModifyListener
{
40 private static final long serialVersionUID
= 8084431378762283920L;
43 final private UserAdmin userAdmin
;
46 private Text groupNameTxt
;
47 private Combo authorizationCmb
;
50 protected final static String
[] validAuthType
= { Privilege
.JCR_READ
,
51 Privilege
.JCR_WRITE
, Privilege
.JCR_ALL
};
53 public ChooseRightsPage(UserAdmin userAdmin
, String path
) {
55 this.userAdmin
= userAdmin
;
56 setTitle("Add privilege to " + path
);
59 public void createControl(Composite parent
) {
61 Composite composite
= new Composite(parent
, SWT
.NONE
);
62 composite
.setLayout(new GridLayout(3, false));
63 Label lbl
= new Label(composite
, SWT
.LEAD
);
64 lbl
.setText("Group name");
65 // lbl.setText("Group or user name (no blank, no special chars)");
66 lbl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false));
67 groupNameTxt
= new Text(composite
, SWT
.LEAD
| SWT
.BORDER
);
68 groupNameTxt
.setLayoutData(EclipseUiUtils
.fillWidth());
69 if (groupNameTxt
!= null)
70 groupNameTxt
.addModifyListener(this);
72 Link pickUpLk
= new Link(composite
, SWT
.LEFT
);
73 pickUpLk
.setText("<a>Pick up</a>");
74 pickUpLk
.addSelectionListener(new SelectionAdapter() {
75 private static final long serialVersionUID
= 1L;
78 public void widgetSelected(SelectionEvent e
) {
79 PickUpGroupDialog dialog
= new PickUpGroupDialog(getShell(),
80 "Choose a group", userAdmin
);
81 if (dialog
.open() == Window
.OK
)
82 groupNameTxt
.setText(dialog
.getSelected());
88 new Label(composite
, SWT
.NONE
).setText("Choose corresponding rights");
89 authorizationCmb
= new Combo(composite
, SWT
.BORDER
| SWT
.V_SCROLL
);
90 authorizationCmb
.setItems(validAuthType
);
91 authorizationCmb
.setLayoutData(EclipseUiUtils
.fillWidth(2));
92 authorizationCmb
.select(0);
95 setControl(composite
);
98 protected String
getGroupName() {
99 return groupNameTxt
.getText();
102 protected String
getAuthTypeStr() {
103 return authorizationCmb
.getItem(authorizationCmb
.getSelectionIndex());
106 public void modifyText(ModifyEvent event
) {
107 String message
= checkComplete();
109 setMessage(message
, WizardPage
.ERROR
);
111 setMessage("Complete", WizardPage
.INFORMATION
);
112 setPageComplete(true);
116 /** @return error message or null if complete */
117 protected String
checkComplete() {
118 String groupStr
= groupNameTxt
.getText();
119 if (groupStr
== null || "".equals(groupStr
))
120 return "Please enter the name of the corresponding group.";