]> git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/wizards/ChooseRightsPage.java
Merge remote-tracking branch 'origin/master' into testing
[gpl/argeo-slc.git] / legacy / org.argeo.slc.client.ui.dist / src / org / argeo / slc / client / ui / dist / wizards / ChooseRightsPage.java
1 package org.argeo.slc.client.ui.dist.wizards;
2
3 import javax.jcr.security.Privilege;
4
5 import org.eclipse.jface.wizard.WizardPage;
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.events.ModifyEvent;
8 import org.eclipse.swt.events.ModifyListener;
9 import org.eclipse.swt.layout.GridData;
10 import org.eclipse.swt.layout.GridLayout;
11 import org.eclipse.swt.widgets.Combo;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.Label;
14 import org.eclipse.swt.widgets.Text;
15
16 public class ChooseRightsPage extends WizardPage implements ModifyListener {
17 private static final long serialVersionUID = 3016024222014878781L;
18
19 // This page widget
20 private Text groupNameTxt;
21 private Combo authorizationCmb;
22
23 // Define acceptable chars for the technical name
24 // private static Pattern p = Pattern.compile("^[A-Za-z0-9]+$");
25
26 // USABLE SHORTCUTS
27 protected final static String[] validAuthType = { Privilege.JCR_READ,
28 Privilege.JCR_WRITE, Privilege.JCR_ALL };
29
30 public ChooseRightsPage() {
31 super("Main");
32 setTitle("Manage authorizations on the current workspace");
33 }
34
35 public void createControl(Composite parent) {
36 // specify subject
37 Composite composite = new Composite(parent, SWT.NONE);
38 composite.setLayout(new GridLayout(2, false));
39 Label lbl = new Label(composite, SWT.LEAD);
40 lbl.setText("Group or user name (no blank, no special chars)");
41 lbl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
42 groupNameTxt = new Text(composite, SWT.LEAD | SWT.BORDER);
43 groupNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
44 false));
45 if (groupNameTxt != null)
46 groupNameTxt.addModifyListener(this);
47
48 // Choose rigths
49 new Label(composite, SWT.NONE).setText("Choose corresponding rights");
50 authorizationCmb = new Combo(composite, SWT.BORDER | SWT.V_SCROLL);
51 authorizationCmb.setItems(validAuthType);
52 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
53 authorizationCmb.setLayoutData(gd);
54
55 authorizationCmb.select(0);
56
57 // Compulsory
58 setControl(composite);
59 }
60
61 protected String getGroupName() {
62 return groupNameTxt.getText();
63 }
64
65 protected String getAuthTypeStr() {
66 return authorizationCmb.getItem(authorizationCmb.getSelectionIndex());
67 }
68
69 // private static boolean match(String s) {
70 // return p.matcher(s).matches();
71 // }
72
73 public void modifyText(ModifyEvent event) {
74 String message = checkComplete();
75 if (message != null)
76 setMessage(message, WizardPage.ERROR);
77 else {
78 setMessage("Complete", WizardPage.INFORMATION);
79 setPageComplete(true);
80 }
81 }
82
83 /** @return error message or null if complete */
84 protected String checkComplete() {
85 String groupStr = groupNameTxt.getText();
86 if (groupStr == null || "".equals(groupStr))
87 return "Please enter the name of the corresponding group.";
88 // Remove regexp check for the time being.
89 // else if (!match(groupStr))
90 // return
91 // "Please use only alphanumerical chars for the short technical name.";
92 return null;
93 }
94 }