root / src / gr / grnet / pithos / web / client / PermissionsAddDialog.java @ 7260b946
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 | d5c6298f | Christos Stathis | import com.google.gwt.user.client.ui.TextBox; |
38 | 4baffab1 | Christos Stathis | |
39 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.Group; |
40 | a57faaf0 | Christos Stathis | |
41 | a57faaf0 | Christos Stathis | import java.util.List; |
42 | a57faaf0 | Christos Stathis | |
43 | a57faaf0 | Christos Stathis | import com.google.gwt.dom.client.NativeEvent; |
44 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
45 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
46 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.KeyCodes; |
47 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Event.NativePreviewEvent; |
48 | 4420a247 | Christos Stathis | import com.google.gwt.user.client.ui.Anchor; |
49 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.Button; |
50 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.CheckBox; |
51 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.DialogBox; |
52 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.FlexTable; |
53 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
54 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalPanel; |
55 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.ListBox; |
56 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
57 | a57faaf0 | Christos Stathis | |
58 | a57faaf0 | Christos Stathis | public class PermissionsAddDialog extends DialogBox { |
59 | a57faaf0 | Christos Stathis | |
60 | d5c6298f | Christos Stathis | private TextBox userBox = new TextBox(); |
61 | a57faaf0 | Christos Stathis | |
62 | a57faaf0 | Christos Stathis | private ListBox groupBox = new ListBox(); |
63 | a57faaf0 | Christos Stathis | |
64 | a57faaf0 | Christos Stathis | private CheckBox read = new CheckBox(); |
65 | a57faaf0 | Christos Stathis | |
66 | a57faaf0 | Christos Stathis | private CheckBox write = new CheckBox(); |
67 | a57faaf0 | Christos Stathis | |
68 | d5c6298f | Christos Stathis | private PermissionsList permList;
|
69 | a57faaf0 | Christos Stathis | |
70 | a57faaf0 | Christos Stathis | boolean userAdd;
|
71 | a57faaf0 | Christos Stathis | |
72 | a7c43f26 | Christos Stathis | private Pithos app;
|
73 | a7c43f26 | Christos Stathis | |
74 | d5c6298f | Christos Stathis | public PermissionsAddDialog(Pithos _app, List<Group> _groups, PermissionsList _permList, boolean _userAdd) { |
75 | a7c43f26 | Christos Stathis | app = _app; |
76 | a57faaf0 | Christos Stathis | userAdd = _userAdd; |
77 | a57faaf0 | Christos Stathis | permList = _permList; |
78 | a57faaf0 | Christos Stathis | |
79 | 4420a247 | Christos Stathis | Anchor close = new Anchor();
|
80 | 4420a247 | Christos Stathis | close.addStyleName("close");
|
81 | 4420a247 | Christos Stathis | close.addClickHandler(new ClickHandler() {
|
82 | 4420a247 | Christos Stathis | |
83 | 4420a247 | Christos Stathis | @Override
|
84 | 4420a247 | Christos Stathis | public void onClick(ClickEvent event) { |
85 | 4420a247 | Christos Stathis | hide(); |
86 | 4420a247 | Christos Stathis | } |
87 | 4420a247 | Christos Stathis | }); |
88 | 4420a247 | Christos Stathis | setText("Add permission");
|
89 | 4420a247 | Christos Stathis | setStyleName("pithos-DialogBox");
|
90 | 4420a247 | Christos Stathis | |
91 | d5c6298f | Christos Stathis | final VerticalPanel panel = new VerticalPanel(); |
92 | 4420a247 | Christos Stathis | panel.add(close); |
93 | 4420a247 | Christos Stathis | |
94 | 4420a247 | Christos Stathis | VerticalPanel inner = new VerticalPanel();
|
95 | 4420a247 | Christos Stathis | inner.addStyleName("inner");
|
96 | d5c6298f | Christos Stathis | |
97 | d5c6298f | Christos Stathis | final FlexTable permTable = new FlexTable(); |
98 | d5c6298f | Christos Stathis | permTable.setText(0, 0, "Users/Groups"); |
99 | d5c6298f | Christos Stathis | permTable.setText(0, 1, "Read"); |
100 | d5c6298f | Christos Stathis | permTable.setText(0, 2, "Write"); |
101 | d5c6298f | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
102 | d5c6298f | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels"); |
103 | d5c6298f | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels"); |
104 | d5c6298f | Christos Stathis | |
105 | d5c6298f | Christos Stathis | if (userAdd) {
|
106 | d5c6298f | Christos Stathis | permTable.setWidget(1, 0, userBox); |
107 | d5c6298f | Christos Stathis | } |
108 | d5c6298f | Christos Stathis | else {
|
109 | d5c6298f | Christos Stathis | for (Group group : _groups) |
110 | d5c6298f | Christos Stathis | groupBox.addItem(group.getName(), group.getName()); |
111 | d5c6298f | Christos Stathis | permTable.setWidget(1, 0, groupBox); |
112 | d5c6298f | Christos Stathis | } |
113 | d5c6298f | Christos Stathis | |
114 | d5c6298f | Christos Stathis | permTable.setWidget(1, 1, read); |
115 | d5c6298f | Christos Stathis | permTable.setWidget(1, 2, write); |
116 | d5c6298f | Christos Stathis | |
117 | d5c6298f | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); |
118 | d5c6298f | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER); |
119 | d5c6298f | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(1, 2, HasHorizontalAlignment.ALIGN_CENTER); |
120 | 4420a247 | Christos Stathis | inner.add(permTable); |
121 | d5c6298f | Christos Stathis | |
122 | d5c6298f | Christos Stathis | final Button ok = new Button("OK", new ClickHandler() { |
123 | d5c6298f | Christos Stathis | @Override
|
124 | 7811b9d1 | Christos Stathis | public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
125 | d5c6298f | Christos Stathis | addPermission(); |
126 | d5c6298f | Christos Stathis | hide(); |
127 | d5c6298f | Christos Stathis | } |
128 | d5c6298f | Christos Stathis | }); |
129 | d5c6298f | Christos Stathis | |
130 | 4420a247 | Christos Stathis | ok.addStyleName("button");
|
131 | 4420a247 | Christos Stathis | inner.add(ok); |
132 | d5c6298f | Christos Stathis | |
133 | 4420a247 | Christos Stathis | panel.add(inner); |
134 | 4420a247 | Christos Stathis | panel.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
135 | 4420a247 | Christos Stathis | |
136 | d5c6298f | Christos Stathis | setWidget(panel); |
137 | a57faaf0 | Christos Stathis | } |
138 | a57faaf0 | Christos Stathis | |
139 | 7811b9d1 | Christos Stathis | protected void addPermission() { |
140 | d5c6298f | Christos Stathis | String selected = null; |
141 | a57faaf0 | Christos Stathis | if (userAdd) {
|
142 | d5c6298f | Christos Stathis | selected = userBox.getText(); |
143 | a57faaf0 | Christos Stathis | } else {
|
144 | d5c6298f | Christos Stathis | String groupName = groupBox.getValue(groupBox.getSelectedIndex());
|
145 | d5c6298f | Christos Stathis | selected = app.getUsername() + ":" + groupName;
|
146 | a57faaf0 | Christos Stathis | } |
147 | d5c6298f | Christos Stathis | if (permList.getPermissions().get(selected) != null) { |
148 | ecf95c9e | Christos Stathis | return;
|
149 | d5c6298f | Christos Stathis | } |
150 | a57faaf0 | Christos Stathis | boolean readValue = read.getValue();
|
151 | a57faaf0 | Christos Stathis | boolean writeValue = write.getValue();
|
152 | a57faaf0 | Christos Stathis | |
153 | d5c6298f | Christos Stathis | permList.addPermission(selected, readValue, writeValue); |
154 | a57faaf0 | Christos Stathis | } |
155 | a57faaf0 | Christos Stathis | |
156 | a57faaf0 | Christos Stathis | @Override
|
157 | a57faaf0 | Christos Stathis | protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
158 | a57faaf0 | Christos Stathis | super.onPreviewNativeEvent(preview);
|
159 | a57faaf0 | Christos Stathis | |
160 | a57faaf0 | Christos Stathis | NativeEvent evt = preview.getNativeEvent(); |
161 | a57faaf0 | Christos Stathis | if (evt.getType().equals("keydown")) |
162 | a57faaf0 | Christos Stathis | // Use the popup's key preview hooks to close the dialog when either
|
163 | a57faaf0 | Christos Stathis | // enter or escape is pressed.
|
164 | a57faaf0 | Christos Stathis | switch (evt.getKeyCode()) {
|
165 | a57faaf0 | Christos Stathis | case KeyCodes.KEY_ENTER:
|
166 | a57faaf0 | Christos Stathis | addPermission(); |
167 | a57faaf0 | Christos Stathis | hide(); |
168 | a57faaf0 | Christos Stathis | break;
|
169 | a57faaf0 | Christos Stathis | case KeyCodes.KEY_ESCAPE:
|
170 | a57faaf0 | Christos Stathis | hide(); |
171 | a57faaf0 | Christos Stathis | break;
|
172 | a57faaf0 | Christos Stathis | } |
173 | a57faaf0 | Christos Stathis | } |
174 | a57faaf0 | Christos Stathis | |
175 | a57faaf0 | Christos Stathis | |
176 | a57faaf0 | Christos Stathis | @Override
|
177 | a57faaf0 | Christos Stathis | public void center() { |
178 | a57faaf0 | Christos Stathis | super.center();
|
179 | a57faaf0 | Christos Stathis | if (userAdd)
|
180 | d5c6298f | Christos Stathis | userBox.setFocus(true);
|
181 | a57faaf0 | Christos Stathis | } |
182 | a57faaf0 | Christos Stathis | } |