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