root / web_client / src / gr / grnet / pithos / web / client / PermissionsAddDialog.java @ 9fce5629
History | View | Annotate | Download (6.1 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2011 GRNET S.A. All rights reserved.
|
3 |
*
|
4 |
* Redistribution and use in source and binary forms, with or
|
5 |
* without modification, are permitted provided that the following
|
6 |
* conditions are met:
|
7 |
*
|
8 |
* 1. Redistributions of source code must retain the above
|
9 |
* copyright notice, this list of conditions and the following
|
10 |
* disclaimer.
|
11 |
*
|
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.
|
16 |
*
|
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.
|
29 |
*
|
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.
|
34 |
*/
|
35 |
package gr.grnet.pithos.web.client; |
36 |
|
37 |
import com.google.gwt.user.client.ui.TextBox; |
38 |
import gr.grnet.pithos.web.client.foldertree.Group; |
39 |
|
40 |
import java.util.List; |
41 |
|
42 |
import com.google.gwt.dom.client.NativeEvent; |
43 |
import com.google.gwt.event.dom.client.ClickEvent; |
44 |
import com.google.gwt.event.dom.client.ClickHandler; |
45 |
import com.google.gwt.event.dom.client.KeyCodes; |
46 |
import com.google.gwt.user.client.Event.NativePreviewEvent; |
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.HorizontalPanel; |
53 |
import com.google.gwt.user.client.ui.ListBox; |
54 |
import com.google.gwt.user.client.ui.VerticalPanel; |
55 |
|
56 |
public class PermissionsAddDialog extends DialogBox { |
57 |
|
58 |
private TextBox userBox = new TextBox(); |
59 |
|
60 |
private ListBox groupBox = new ListBox(); |
61 |
|
62 |
private CheckBox read = new CheckBox(); |
63 |
|
64 |
private CheckBox write = new CheckBox(); |
65 |
|
66 |
private PermissionsList permList;
|
67 |
|
68 |
boolean userAdd;
|
69 |
|
70 |
private Pithos app;
|
71 |
|
72 |
public PermissionsAddDialog(Pithos _app, List<Group> _groups, PermissionsList _permList, boolean _userAdd) { |
73 |
app = _app; |
74 |
userAdd = _userAdd; |
75 |
permList = _permList; |
76 |
|
77 |
final VerticalPanel panel = new VerticalPanel(); |
78 |
|
79 |
final FlexTable permTable = new FlexTable(); |
80 |
permTable.setText(0, 0, "Users/Groups"); |
81 |
permTable.setText(0, 1, "Read"); |
82 |
permTable.setText(0, 2, "Write"); |
83 |
permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
84 |
permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels"); |
85 |
permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels"); |
86 |
|
87 |
if (userAdd) {
|
88 |
permTable.setWidget(1, 0, userBox); |
89 |
} |
90 |
else {
|
91 |
for (Group group : _groups) |
92 |
groupBox.addItem(group.getName(), group.getName()); |
93 |
permTable.setWidget(1, 0, groupBox); |
94 |
} |
95 |
|
96 |
permTable.setWidget(1, 1, read); |
97 |
permTable.setWidget(1, 2, write); |
98 |
|
99 |
permTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); |
100 |
permTable.getFlexCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER); |
101 |
permTable.getFlexCellFormatter().setHorizontalAlignment(1, 2, HasHorizontalAlignment.ALIGN_CENTER); |
102 |
panel.add(permTable); |
103 |
|
104 |
final HorizontalPanel buttons = new HorizontalPanel(); |
105 |
final Button ok = new Button("OK", new ClickHandler() { |
106 |
@Override
|
107 |
public void onClick(ClickEvent event) { |
108 |
addPermission(); |
109 |
hide(); |
110 |
} |
111 |
}); |
112 |
buttons.add(ok); |
113 |
buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); |
114 |
// Create the 'Cancel' button, along with a listener that hides the
|
115 |
// dialog
|
116 |
// when the button is clicked.
|
117 |
final Button cancel = new Button("Cancel", new ClickHandler() { |
118 |
@Override
|
119 |
public void onClick(ClickEvent event) { |
120 |
hide(); |
121 |
} |
122 |
}); |
123 |
buttons.add(cancel); |
124 |
buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); |
125 |
buttons.setSpacing(8);
|
126 |
buttons.addStyleName("pithos-TabPanelBottom");
|
127 |
|
128 |
panel.add(buttons); |
129 |
panel.addStyleName("pithos-TabPanelBottom");
|
130 |
|
131 |
setWidget(panel); |
132 |
} |
133 |
|
134 |
private void addPermission() { |
135 |
String selected = null; |
136 |
if (userAdd) {
|
137 |
selected = userBox.getText(); |
138 |
} else {
|
139 |
String groupName = groupBox.getValue(groupBox.getSelectedIndex());
|
140 |
selected = app.getUsername() + ":" + groupName;
|
141 |
} |
142 |
if (permList.getPermissions().get(selected) != null) { |
143 |
app.displayError((userAdd ? "User " : "Group ") + "already has access to the resource"); |
144 |
return;
|
145 |
} |
146 |
boolean readValue = read.getValue();
|
147 |
boolean writeValue = write.getValue();
|
148 |
|
149 |
permList.addPermission(selected, readValue, writeValue); |
150 |
} |
151 |
|
152 |
@Override
|
153 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
154 |
super.onPreviewNativeEvent(preview);
|
155 |
|
156 |
NativeEvent evt = preview.getNativeEvent(); |
157 |
if (evt.getType().equals("keydown")) |
158 |
// Use the popup's key preview hooks to close the dialog when either
|
159 |
// enter or escape is pressed.
|
160 |
switch (evt.getKeyCode()) {
|
161 |
case KeyCodes.KEY_ENTER:
|
162 |
addPermission(); |
163 |
hide(); |
164 |
break;
|
165 |
case KeyCodes.KEY_ESCAPE:
|
166 |
hide(); |
167 |
break;
|
168 |
} |
169 |
} |
170 |
|
171 |
|
172 |
@Override
|
173 |
public void center() { |
174 |
super.center();
|
175 |
if (userAdd)
|
176 |
userBox.setFocus(true);
|
177 |
} |
178 |
} |