root / src / gr / grnet / pithos / web / client / PermissionsList.java @ 39f6d7b0
History | View | Annotate | Download (7.5 kB)
1 | a57faaf0 | Christos Stathis | /*
|
---|---|---|---|
2 | cae2a8db | Christos Stathis | * Copyright 2011-2012 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 | 9326b841 | Christos Stathis | import gr.grnet.pithos.web.client.FilePermissionsDialog.Images; |
38 | a57faaf0 | Christos Stathis | |
39 | d5c6298f | Christos Stathis | import java.util.HashMap; |
40 | d5c6298f | Christos Stathis | import java.util.Map; |
41 | a57faaf0 | Christos Stathis | |
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 | 9326b841 | Christos Stathis | import com.google.gwt.event.logical.shared.ValueChangeEvent; |
45 | 9326b841 | Christos Stathis | import com.google.gwt.event.logical.shared.ValueChangeHandler; |
46 | 4d869bf1 | Christos Stathis | import com.google.gwt.user.client.Command; |
47 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
48 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.CheckBox; |
49 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.Composite; |
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.PushButton; |
53 | 4ded5310 | Christos Stathis | import com.google.gwt.user.client.ui.RadioButton; |
54 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
55 | a57faaf0 | Christos Stathis | |
56 | a57faaf0 | Christos Stathis | |
57 | a57faaf0 | Christos Stathis | public class PermissionsList extends Composite { |
58 | a57faaf0 | Christos Stathis | |
59 | d5c6298f | Christos Stathis | Map<String, Boolean[]> permissions = null; |
60 | a57faaf0 | Christos Stathis | |
61 | a57faaf0 | Christos Stathis | final Images images;
|
62 | a57faaf0 | Christos Stathis | |
63 | a57faaf0 | Christos Stathis | final VerticalPanel permPanel = new VerticalPanel(); |
64 | a57faaf0 | Christos Stathis | |
65 | a57faaf0 | Christos Stathis | final FlexTable permTable = new FlexTable(); |
66 | a57faaf0 | Christos Stathis | |
67 | a57faaf0 | Christos Stathis | final String owner; |
68 | a57faaf0 | Christos Stathis | |
69 | 7811b9d1 | Christos Stathis | protected boolean hasChanges = false; |
70 | a7c43f26 | Christos Stathis | |
71 | ecf95c9e | Christos Stathis | private boolean readonly = false; |
72 | 4d869bf1 | Christos Stathis | |
73 | 4d869bf1 | Christos Stathis | Command changePermissionsCallback; |
74 | a57faaf0 | Christos Stathis | |
75 | 4d869bf1 | Christos Stathis | public PermissionsList(final Images theImages, Map<String, Boolean[]> thePermissions, String theOwner, boolean inheritsPermissions, Command _changePermissionsCallback){ |
76 | 4d869bf1 | Christos Stathis | changePermissionsCallback = _changePermissionsCallback; |
77 | a57faaf0 | Christos Stathis | images = theImages; |
78 | ecf95c9e | Christos Stathis | owner = theOwner; |
79 | d5c6298f | Christos Stathis | permissions = new HashMap<String, Boolean[]>(thePermissions); |
80 | a57faaf0 | Christos Stathis | permTable.setText(0, 0, "Users/Groups"); |
81 | 4ded5310 | Christos Stathis | permTable.setText(0, 1, "Read Only"); |
82 | 4ded5310 | Christos Stathis | permTable.setText(0, 2, "Read/Write"); |
83 | d5c6298f | Christos Stathis | permTable.setText(0, 3, ""); |
84 | a57faaf0 | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
85 | a57faaf0 | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels"); |
86 | a57faaf0 | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels"); |
87 | a57faaf0 | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels"); |
88 | a57faaf0 | Christos Stathis | permPanel.add(permTable); |
89 | a57faaf0 | Christos Stathis | permPanel.addStyleName("pithos-TabPanelBottom");
|
90 | a57faaf0 | Christos Stathis | initWidget(permPanel); |
91 | d5c6298f | Christos Stathis | updatePermissionTable(); |
92 | a57faaf0 | Christos Stathis | } |
93 | a57faaf0 | Christos Stathis | |
94 | a57faaf0 | Christos Stathis | public boolean hasChanges(){ |
95 | ecf95c9e | Christos Stathis | return hasChanges;
|
96 | a57faaf0 | Christos Stathis | } |
97 | a57faaf0 | Christos Stathis | |
98 | a57faaf0 | Christos Stathis | /**
|
99 | a57faaf0 | Christos Stathis | * Retrieve the permissions.
|
100 | a57faaf0 | Christos Stathis | *
|
101 | a57faaf0 | Christos Stathis | * @return the permissions
|
102 | a57faaf0 | Christos Stathis | */
|
103 | d5c6298f | Christos Stathis | public Map<String, Boolean[]> getPermissions() { |
104 | a57faaf0 | Christos Stathis | return permissions;
|
105 | a57faaf0 | Christos Stathis | } |
106 | a57faaf0 | Christos Stathis | |
107 | d5c6298f | Christos Stathis | public void addPermission(String user, boolean read, boolean write){ |
108 | d5c6298f | Christos Stathis | permissions.put(user, new Boolean[] {Boolean.valueOf(read), Boolean.valueOf(write)}); |
109 | ecf95c9e | Christos Stathis | hasChanges = true;
|
110 | d5c6298f | Christos Stathis | updatePermissionTable(); |
111 | 4d869bf1 | Christos Stathis | if (changePermissionsCallback != null) |
112 | 4d869bf1 | Christos Stathis | changePermissionsCallback.execute(); |
113 | a57faaf0 | Christos Stathis | } |
114 | d5c6298f | Christos Stathis | |
115 | a57faaf0 | Christos Stathis | /**
|
116 | a57faaf0 | Christos Stathis | * Shows the permission table
|
117 | a57faaf0 | Christos Stathis | *
|
118 | a57faaf0 | Christos Stathis | */
|
119 | d5c6298f | Christos Stathis | void updatePermissionTable(){
|
120 | a57faaf0 | Christos Stathis | int i = 1; |
121 | d5c6298f | Christos Stathis | for (int j=1; j<permTable.getRowCount(); j++) |
122 | d5c6298f | Christos Stathis | permTable.removeRow(j); |
123 | d5c6298f | Christos Stathis | for(final String user : permissions.keySet()) { |
124 | ecf95c9e | Christos Stathis | if (!user.contains(":")) //not a group |
125 | d5c6298f | Christos Stathis | permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + " " + user + "</span>"); |
126 | d5c6298f | Christos Stathis | else
|
127 | d5c6298f | Christos Stathis | permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permGroup()).getHTML() + " " + user.split(":")[1].trim() + "</span>"); |
128 | ecf95c9e | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels"); |
129 | d5c6298f | Christos Stathis | |
130 | d5c6298f | Christos Stathis | Boolean[] userPerms = permissions.get(user); |
131 | d5c6298f | Christos Stathis | Boolean readP = userPerms[0]; |
132 | d5c6298f | Christos Stathis | Boolean writeP = userPerms[1]; |
133 | d5c6298f | Christos Stathis | |
134 | 4ded5310 | Christos Stathis | RadioButton read = new RadioButton("permissions" + i); |
135 | d5c6298f | Christos Stathis | read.setValue(readP != null ? readP : false); |
136 | ecf95c9e | Christos Stathis | permTable.setWidget(i, 1, read);
|
137 | ecf95c9e | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
|
138 | ecf95c9e | Christos Stathis | |
139 | 4ded5310 | Christos Stathis | RadioButton write = new RadioButton("permissions" + i); |
140 | ecf95c9e | Christos Stathis | write.setValue(writeP != null ? writeP : false); |
141 | ecf95c9e | Christos Stathis | permTable.setWidget(i, 2, write);
|
142 | ecf95c9e | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
|
143 | ecf95c9e | Christos Stathis | |
144 | ecf95c9e | Christos Stathis | if (!readonly) {
|
145 | ecf95c9e | Christos Stathis | read.addValueChangeHandler(new ValueChangeHandler<Boolean>() { |
146 | ecf95c9e | Christos Stathis | @Override
|
147 | ecf95c9e | Christos Stathis | public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) { |
148 | ecf95c9e | Christos Stathis | Boolean[] ps = permissions.get(user); |
149 | ecf95c9e | Christos Stathis | ps[0] = booleanValueChangeEvent.getValue();
|
150 | 4ded5310 | Christos Stathis | ps[1] = !booleanValueChangeEvent.getValue();
|
151 | 3ebb88f4 | Christos Stathis | hasChanges = true;
|
152 | 4d869bf1 | Christos Stathis | if (changePermissionsCallback != null) |
153 | 4d869bf1 | Christos Stathis | changePermissionsCallback.execute(); |
154 | ecf95c9e | Christos Stathis | } |
155 | ecf95c9e | Christos Stathis | }); |
156 | ecf95c9e | Christos Stathis | write.addValueChangeHandler(new ValueChangeHandler<Boolean>() { |
157 | ecf95c9e | Christos Stathis | @Override
|
158 | ecf95c9e | Christos Stathis | public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) { |
159 | ecf95c9e | Christos Stathis | Boolean[] ps = permissions.get(user); |
160 | 4ded5310 | Christos Stathis | ps[0] = !booleanValueChangeEvent.getValue();
|
161 | ecf95c9e | Christos Stathis | ps[1] = booleanValueChangeEvent.getValue();
|
162 | 3ebb88f4 | Christos Stathis | hasChanges = true;
|
163 | 4d869bf1 | Christos Stathis | if (changePermissionsCallback != null) |
164 | 4d869bf1 | Christos Stathis | changePermissionsCallback.execute(); |
165 | ecf95c9e | Christos Stathis | } |
166 | ecf95c9e | Christos Stathis | }); |
167 | ecf95c9e | Christos Stathis | PushButton removeButton = new PushButton(AbstractImagePrototype.create(images.delete()).createImage(), new ClickHandler() { |
168 | ecf95c9e | Christos Stathis | @Override
|
169 | ebead1b5 | Christos Stathis | public void onClick(ClickEvent event) { |
170 | ecf95c9e | Christos Stathis | permissions.remove(user); |
171 | ecf95c9e | Christos Stathis | updatePermissionTable(); |
172 | ecf95c9e | Christos Stathis | hasChanges = true;
|
173 | 4d869bf1 | Christos Stathis | if (changePermissionsCallback != null) |
174 | 4d869bf1 | Christos Stathis | changePermissionsCallback.execute(); |
175 | ecf95c9e | Christos Stathis | } |
176 | ecf95c9e | Christos Stathis | }); |
177 | ecf95c9e | Christos Stathis | permTable.setWidget(i, 3, removeButton);
|
178 | ecf95c9e | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
|
179 | ecf95c9e | Christos Stathis | } |
180 | ecf95c9e | Christos Stathis | else {
|
181 | ecf95c9e | Christos Stathis | read.setEnabled(false);
|
182 | ecf95c9e | Christos Stathis | write.setEnabled(false);
|
183 | ecf95c9e | Christos Stathis | } |
184 | d5c6298f | Christos Stathis | i++; |
185 | a57faaf0 | Christos Stathis | } |
186 | a57faaf0 | Christos Stathis | } |
187 | a57faaf0 | Christos Stathis | } |