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