]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/ChooseRightsPage.java
Clean and comments.
[lgpl/argeo-commons.git] / org.argeo.eclipse.ui.workbench / src / org / argeo / eclipse / ui / workbench / jcr / internal / parts / 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.eclipse.ui.workbench.jcr.internal.parts;
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 private static final long serialVersionUID = 8084431378762283920L;
33
34 // This page widget
35 private Text groupNameTxt;
36 private Combo authorizationCmb;
37
38 // USABLE SHORTCUTS
39 protected final static String[] validAuthType = { Privilege.JCR_READ,
40 Privilege.JCR_WRITE, Privilege.JCR_ALL };
41
42 public ChooseRightsPage(String path) {
43 super("Main");
44 setTitle("Add privilege to " + path);
45 }
46
47 public void createControl(Composite parent) {
48 // specify subject
49 Composite composite = new Composite(parent, SWT.NONE);
50 composite.setLayout(new GridLayout(2, false));
51 Label lbl = new Label(composite, SWT.LEAD);
52 lbl.setText("Group or user name (no blank, no special chars)");
53 lbl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
54 groupNameTxt = new Text(composite, SWT.LEAD | SWT.BORDER);
55 groupNameTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
56 false));
57 if (groupNameTxt != null)
58 groupNameTxt.addModifyListener(this);
59
60 // Choose rigths
61 new Label(composite, SWT.NONE).setText("Choose corresponding rights");
62 authorizationCmb = new Combo(composite, SWT.BORDER | SWT.V_SCROLL);
63 authorizationCmb.setItems(validAuthType);
64 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
65 authorizationCmb.setLayoutData(gd);
66
67 authorizationCmb.select(0);
68
69 // Compulsory
70 setControl(composite);
71 }
72
73 protected String getGroupName() {
74 return groupNameTxt.getText();
75 }
76
77 protected String getAuthTypeStr() {
78 return authorizationCmb.getItem(authorizationCmb.getSelectionIndex());
79 }
80
81 public void modifyText(ModifyEvent event) {
82 String message = checkComplete();
83 if (message != null)
84 setMessage(message, WizardPage.ERROR);
85 else {
86 setMessage("Complete", WizardPage.INFORMATION);
87 setPageComplete(true);
88 }
89 }
90
91 /** @return error message or null if complete */
92 protected String checkComplete() {
93 String groupStr = groupNameTxt.getText();
94 if (groupStr == null || "".equals(groupStr))
95 return "Please enter the name of the corresponding group.";
96 // Remove regexp check for the time being.
97 // else if (!match(groupStr))
98 // return
99 // "Please use only alphanumerical chars for the short technical name.";
100 return null;
101 }
102 }