root / src / gr / grnet / pithos / web / client / PermissionsAddDialog.java @ b75210b5
History | View | Annotate | Download (5.8 kB)
1 | a57faaf0 | Christos Stathis | /*
|
---|---|---|---|
2 | 63366925 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 63366925 | Christos Stathis | *
|
4 | 63366925 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 63366925 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 63366925 | Christos Stathis | * conditions are met:
|
7 | 63366925 | Christos Stathis | *
|
8 | 63366925 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 63366925 | Christos Stathis | * disclaimer.
|
11 | 63366925 | Christos Stathis | *
|
12 | 63366925 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 63366925 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 63366925 | Christos Stathis | * provided with the distribution.
|
16 | 63366925 | Christos Stathis | *
|
17 | 63366925 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 63366925 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 63366925 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 63366925 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 63366925 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 63366925 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 63366925 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 63366925 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 63366925 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 63366925 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 63366925 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 63366925 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 63366925 | Christos Stathis | *
|
30 | 63366925 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 63366925 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 63366925 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 63366925 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | a57faaf0 | Christos Stathis | */
|
35 | a57faaf0 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | a57faaf0 | Christos Stathis | |
37 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.Group; |
38 | a57faaf0 | Christos Stathis | |
39 | a57faaf0 | Christos Stathis | import java.util.List; |
40 | a57faaf0 | Christos Stathis | |
41 | a57faaf0 | Christos Stathis | import com.google.gwt.dom.client.NativeEvent; |
42 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
43 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
44 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.KeyCodes; |
45 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Event.NativePreviewEvent; |
46 | 4420a247 | Christos Stathis | import com.google.gwt.user.client.ui.Anchor; |
47 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.Button; |
48 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.CheckBox; |
49 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.DialogBox; |
50 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.FlexTable; |
51 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
52 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.ListBox; |
53 | ebead1b5 | Christos Stathis | import com.google.gwt.user.client.ui.TextBox; |
54 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
55 | a57faaf0 | Christos Stathis | |
56 | a57faaf0 | Christos Stathis | public class PermissionsAddDialog extends DialogBox { |
57 | a57faaf0 | Christos Stathis | |
58 | d5c6298f | Christos Stathis | private TextBox userBox = new TextBox(); |
59 | a57faaf0 | Christos Stathis | |
60 | a57faaf0 | Christos Stathis | private ListBox groupBox = new ListBox(); |
61 | a57faaf0 | Christos Stathis | |
62 | a57faaf0 | Christos Stathis | private CheckBox read = new CheckBox(); |
63 | a57faaf0 | Christos Stathis | |
64 | a57faaf0 | Christos Stathis | private CheckBox write = new CheckBox(); |
65 | a57faaf0 | Christos Stathis | |
66 | d5c6298f | Christos Stathis | private PermissionsList permList;
|
67 | a57faaf0 | Christos Stathis | |
68 | a57faaf0 | Christos Stathis | boolean userAdd;
|
69 | a57faaf0 | Christos Stathis | |
70 | a7c43f26 | Christos Stathis | private Pithos app;
|
71 | a7c43f26 | Christos Stathis | |
72 | d5c6298f | Christos Stathis | public PermissionsAddDialog(Pithos _app, List<Group> _groups, PermissionsList _permList, boolean _userAdd) { |
73 | a7c43f26 | Christos Stathis | app = _app; |
74 | a57faaf0 | Christos Stathis | userAdd = _userAdd; |
75 | a57faaf0 | Christos Stathis | permList = _permList; |
76 | a57faaf0 | Christos Stathis | |
77 | 4420a247 | Christos Stathis | Anchor close = new Anchor();
|
78 | 4420a247 | Christos Stathis | close.addStyleName("close");
|
79 | 4420a247 | Christos Stathis | close.addClickHandler(new ClickHandler() {
|
80 | 4420a247 | Christos Stathis | |
81 | 4420a247 | Christos Stathis | @Override
|
82 | 4420a247 | Christos Stathis | public void onClick(ClickEvent event) { |
83 | 4420a247 | Christos Stathis | hide(); |
84 | 4420a247 | Christos Stathis | } |
85 | 4420a247 | Christos Stathis | }); |
86 | 4420a247 | Christos Stathis | setText("Add permission");
|
87 | 4420a247 | Christos Stathis | setStyleName("pithos-DialogBox");
|
88 | 4420a247 | Christos Stathis | |
89 | d5c6298f | Christos Stathis | final VerticalPanel panel = new VerticalPanel(); |
90 | 4420a247 | Christos Stathis | panel.add(close); |
91 | 4420a247 | Christos Stathis | |
92 | 4420a247 | Christos Stathis | VerticalPanel inner = new VerticalPanel();
|
93 | 4420a247 | Christos Stathis | inner.addStyleName("inner");
|
94 | d5c6298f | Christos Stathis | |
95 | d5c6298f | Christos Stathis | final FlexTable permTable = new FlexTable(); |
96 | d5c6298f | Christos Stathis | permTable.setText(0, 0, "Users/Groups"); |
97 | d5c6298f | Christos Stathis | permTable.setText(0, 1, "Read"); |
98 | d5c6298f | Christos Stathis | permTable.setText(0, 2, "Write"); |
99 | d5c6298f | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
100 | d5c6298f | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels"); |
101 | d5c6298f | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels"); |
102 | d5c6298f | Christos Stathis | |
103 | d5c6298f | Christos Stathis | if (userAdd) {
|
104 | d5c6298f | Christos Stathis | permTable.setWidget(1, 0, userBox); |
105 | d5c6298f | Christos Stathis | } |
106 | d5c6298f | Christos Stathis | else {
|
107 | d5c6298f | Christos Stathis | for (Group group : _groups) |
108 | d5c6298f | Christos Stathis | groupBox.addItem(group.getName(), group.getName()); |
109 | d5c6298f | Christos Stathis | permTable.setWidget(1, 0, groupBox); |
110 | d5c6298f | Christos Stathis | } |
111 | d5c6298f | Christos Stathis | |
112 | d5c6298f | Christos Stathis | permTable.setWidget(1, 1, read); |
113 | d5c6298f | Christos Stathis | permTable.setWidget(1, 2, write); |
114 | d5c6298f | Christos Stathis | |
115 | d5c6298f | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); |
116 | d5c6298f | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER); |
117 | d5c6298f | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(1, 2, HasHorizontalAlignment.ALIGN_CENTER); |
118 | 4420a247 | Christos Stathis | inner.add(permTable); |
119 | d5c6298f | Christos Stathis | |
120 | d5c6298f | Christos Stathis | final Button ok = new Button("OK", new ClickHandler() { |
121 | d5c6298f | Christos Stathis | @Override
|
122 | ebead1b5 | Christos Stathis | public void onClick(ClickEvent event) { |
123 | d5c6298f | Christos Stathis | addPermission(); |
124 | d5c6298f | Christos Stathis | hide(); |
125 | d5c6298f | Christos Stathis | } |
126 | d5c6298f | Christos Stathis | }); |
127 | d5c6298f | Christos Stathis | |
128 | 4420a247 | Christos Stathis | ok.addStyleName("button");
|
129 | 4420a247 | Christos Stathis | inner.add(ok); |
130 | d5c6298f | Christos Stathis | |
131 | 4420a247 | Christos Stathis | panel.add(inner); |
132 | 4420a247 | Christos Stathis | panel.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
133 | 4420a247 | Christos Stathis | |
134 | d5c6298f | Christos Stathis | setWidget(panel); |
135 | a57faaf0 | Christos Stathis | } |
136 | a57faaf0 | Christos Stathis | |
137 | 7811b9d1 | Christos Stathis | protected void addPermission() { |
138 | d5c6298f | Christos Stathis | String selected = null; |
139 | a57faaf0 | Christos Stathis | if (userAdd) {
|
140 | d5c6298f | Christos Stathis | selected = userBox.getText(); |
141 | a57faaf0 | Christos Stathis | } else {
|
142 | d5c6298f | Christos Stathis | String groupName = groupBox.getValue(groupBox.getSelectedIndex());
|
143 | d5c6298f | Christos Stathis | selected = app.getUsername() + ":" + groupName;
|
144 | a57faaf0 | Christos Stathis | } |
145 | d5c6298f | Christos Stathis | if (permList.getPermissions().get(selected) != null) { |
146 | ecf95c9e | Christos Stathis | return;
|
147 | d5c6298f | Christos Stathis | } |
148 | a57faaf0 | Christos Stathis | boolean readValue = read.getValue();
|
149 | a57faaf0 | Christos Stathis | boolean writeValue = write.getValue();
|
150 | a57faaf0 | Christos Stathis | |
151 | d5c6298f | Christos Stathis | permList.addPermission(selected, readValue, writeValue); |
152 | a57faaf0 | Christos Stathis | } |
153 | a57faaf0 | Christos Stathis | |
154 | a57faaf0 | Christos Stathis | @Override
|
155 | a57faaf0 | Christos Stathis | protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
156 | a57faaf0 | Christos Stathis | super.onPreviewNativeEvent(preview);
|
157 | a57faaf0 | Christos Stathis | |
158 | a57faaf0 | Christos Stathis | NativeEvent evt = preview.getNativeEvent(); |
159 | a57faaf0 | Christos Stathis | if (evt.getType().equals("keydown")) |
160 | a57faaf0 | Christos Stathis | // Use the popup's key preview hooks to close the dialog when either
|
161 | a57faaf0 | Christos Stathis | // enter or escape is pressed.
|
162 | a57faaf0 | Christos Stathis | switch (evt.getKeyCode()) {
|
163 | a57faaf0 | Christos Stathis | case KeyCodes.KEY_ENTER:
|
164 | a57faaf0 | Christos Stathis | addPermission(); |
165 | a57faaf0 | Christos Stathis | hide(); |
166 | a57faaf0 | Christos Stathis | break;
|
167 | a57faaf0 | Christos Stathis | case KeyCodes.KEY_ESCAPE:
|
168 | a57faaf0 | Christos Stathis | hide(); |
169 | a57faaf0 | Christos Stathis | break;
|
170 | a57faaf0 | Christos Stathis | } |
171 | a57faaf0 | Christos Stathis | } |
172 | a57faaf0 | Christos Stathis | |
173 | a57faaf0 | Christos Stathis | |
174 | a57faaf0 | Christos Stathis | @Override
|
175 | a57faaf0 | Christos Stathis | public void center() { |
176 | a57faaf0 | Christos Stathis | super.center();
|
177 | a57faaf0 | Christos Stathis | if (userAdd)
|
178 | d5c6298f | Christos Stathis | userBox.setFocus(true);
|
179 | a57faaf0 | Christos Stathis | } |
180 | a57faaf0 | Christos Stathis | } |