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