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