2 * Copyright 2011-2012 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * The views and conclusions contained in the software and
31 * documentation are those of the authors and should not be
32 * interpreted as representing official policies, either expressed
33 * or implied, of GRNET S.A.
35 package gr.grnet.pithos.web.client;
37 import gr.grnet.pithos.web.client.grouptree.Group;
39 import java.util.List;
41 import com.google.gwt.dom.client.NativeEvent;
42 import com.google.gwt.event.dom.client.ClickEvent;
43 import com.google.gwt.event.dom.client.ClickHandler;
44 import com.google.gwt.event.dom.client.KeyCodes;
45 import com.google.gwt.user.client.Event.NativePreviewEvent;
46 import com.google.gwt.user.client.ui.Anchor;
47 import com.google.gwt.user.client.ui.Button;
48 import com.google.gwt.user.client.ui.CheckBox;
49 import com.google.gwt.user.client.ui.DialogBox;
50 import com.google.gwt.user.client.ui.FlexTable;
51 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
52 import com.google.gwt.user.client.ui.ListBox;
53 import com.google.gwt.user.client.ui.RadioButton;
54 import com.google.gwt.user.client.ui.TextBox;
55 import com.google.gwt.user.client.ui.VerticalPanel;
57 public class PermissionsAddDialog extends DialogBox {
59 private TextBox userBox = new TextBox();
61 private ListBox groupBox = new ListBox();
63 private RadioButton read = new RadioButton("permissions");
65 private RadioButton write = new RadioButton("permissions");
67 private PermissionsList permList;
73 public PermissionsAddDialog(Pithos _app, List<Group> _groups, PermissionsList _permList, boolean _userAdd) {
78 Anchor close = new Anchor();
79 close.addStyleName("close");
80 close.addClickHandler(new ClickHandler() {
83 public void onClick(ClickEvent event) {
87 setText("Add permission");
88 setStyleName("pithos-DialogBox");
90 final VerticalPanel panel = new VerticalPanel();
93 VerticalPanel inner = new VerticalPanel();
94 inner.addStyleName("inner");
96 final FlexTable permTable = new FlexTable();
97 permTable.setText(0, 0, "Users/Groups");
98 permTable.setText(0, 1, "Read Only");
99 permTable.setText(0, 2, "Read/Write");
100 permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels");
101 permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels");
102 permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels");
105 permTable.setWidget(1, 0, userBox);
108 for (Group group : _groups)
109 groupBox.addItem(group.getName(), group.getName());
110 permTable.setWidget(1, 0, groupBox);
114 permTable.setWidget(1, 1, read);
115 permTable.setWidget(1, 2, write);
117 permTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
118 permTable.getFlexCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER);
119 permTable.getFlexCellFormatter().setHorizontalAlignment(1, 2, HasHorizontalAlignment.ALIGN_CENTER);
120 inner.add(permTable);
122 final Button ok = new Button("OK", new ClickHandler() {
124 public void onClick(ClickEvent event) {
130 ok.addStyleName("button");
134 panel.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
139 protected void addPermission() {
140 String selected = null;
142 selected = userBox.getText();
143 } else if (groupBox.getSelectedIndex() > -1) {
144 String groupName = groupBox.getValue(groupBox.getSelectedIndex());
145 selected = app.getUsername() + ":" + groupName;
147 if (permList.getPermissions().get(selected) != null) {
150 if (selected == null || selected.length() == 0 || selected.equals(app.getUsername() + ":")) {
151 app.displayError("You have to select o username or group");
154 boolean readValue = read.getValue();
155 boolean writeValue = write.getValue();
157 permList.addPermission(selected, readValue, writeValue);
161 protected void onPreviewNativeEvent(NativePreviewEvent preview) {
162 super.onPreviewNativeEvent(preview);
164 NativeEvent evt = preview.getNativeEvent();
165 if (evt.getType().equals("keydown"))
166 // Use the popup's key preview hooks to close the dialog when either
167 // enter or escape is pressed.
168 switch (evt.getKeyCode()) {
169 case KeyCodes.KEY_ENTER:
173 case KeyCodes.KEY_ESCAPE:
181 public void center() {
184 userBox.setFocus(true);