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