]> git.argeo.org Git - lgpl/argeo-commons.git/blob - internal/parts/ChooseRightsPage.java
Prepare next development cycle
[lgpl/argeo-commons.git] / 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.argeo.eclipse.ui.EclipseUiUtils;
21 import org.argeo.eclipse.ui.workbench.users.PickUpGroupDialog;
22 import org.eclipse.jface.window.Window;
23 import org.eclipse.jface.wizard.WizardPage;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.events.ModifyEvent;
26 import org.eclipse.swt.events.ModifyListener;
27 import org.eclipse.swt.events.SelectionAdapter;
28 import org.eclipse.swt.events.SelectionEvent;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Combo;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Label;
34 import org.eclipse.swt.widgets.Link;
35 import org.eclipse.swt.widgets.Text;
36 import org.osgi.service.useradmin.UserAdmin;
37
38 /** Simple wizard page to choose a group and corresponding rights to assign */
39 public class ChooseRightsPage extends WizardPage implements ModifyListener {
40 private static final long serialVersionUID = 8084431378762283920L;
41
42 // Context
43 final private UserAdmin userAdmin;
44
45 // This page widget
46 private Text groupNameTxt;
47 private Combo authorizationCmb;
48
49 // USABLE SHORTCUTS
50 protected final static String[] validAuthType = { Privilege.JCR_READ,
51 Privilege.JCR_WRITE, Privilege.JCR_ALL };
52
53 public ChooseRightsPage(UserAdmin userAdmin, String path) {
54 super("Main");
55 this.userAdmin = userAdmin;
56 setTitle("Add privilege to " + path);
57 }
58
59 public void createControl(Composite parent) {
60 // specify subject
61 Composite composite = new Composite(parent, SWT.NONE);
62 composite.setLayout(new GridLayout(3, false));
63 Label lbl = new Label(composite, SWT.LEAD);
64 lbl.setText("Group name");
65 // lbl.setText("Group or user name (no blank, no special chars)");
66 lbl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
67 groupNameTxt = new Text(composite, SWT.LEAD | SWT.BORDER);
68 groupNameTxt.setLayoutData(EclipseUiUtils.fillWidth());
69 if (groupNameTxt != null)
70 groupNameTxt.addModifyListener(this);
71
72 Link pickUpLk = new Link(composite, SWT.LEFT);
73 pickUpLk.setText("<a>Pick up</a>");
74 pickUpLk.addSelectionListener(new SelectionAdapter() {
75 private static final long serialVersionUID = 1L;
76
77 @Override
78 public void widgetSelected(SelectionEvent e) {
79 PickUpGroupDialog dialog = new PickUpGroupDialog(getShell(),
80 "Choose a group", userAdmin);
81 if (dialog.open() == Window.OK)
82 groupNameTxt.setText(dialog.getSelected());
83 }
84
85 });
86
87 // Choose rigths
88 new Label(composite, SWT.NONE).setText("Choose corresponding rights");
89 authorizationCmb = new Combo(composite, SWT.BORDER | SWT.V_SCROLL);
90 authorizationCmb.setItems(validAuthType);
91 authorizationCmb.setLayoutData(EclipseUiUtils.fillWidth(2));
92 authorizationCmb.select(0);
93
94 // Compulsory
95 setControl(composite);
96 }
97
98 protected String getGroupName() {
99 return groupNameTxt.getText();
100 }
101
102 protected String getAuthTypeStr() {
103 return authorizationCmb.getItem(authorizationCmb.getSelectionIndex());
104 }
105
106 public void modifyText(ModifyEvent event) {
107 String message = checkComplete();
108 if (message != null)
109 setMessage(message, WizardPage.ERROR);
110 else {
111 setMessage("Complete", WizardPage.INFORMATION);
112 setPageComplete(true);
113 }
114 }
115
116 /** @return error message or null if complete */
117 protected String checkComplete() {
118 String groupStr = groupNameTxt.getText();
119 if (groupStr == null || "".equals(groupStr))
120 return "Please enter the name of the corresponding group.";
121 return null;
122 }
123 }