root / web_client / src / gr / grnet / pithos / web / client / PermissionsList.java @ 9fce5629
History | View | Annotate | Download (6.6 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 gr.grnet.pithos.web.client.FilePropertiesDialog.Images; |
38 |
import gr.grnet.pithos.web.client.rest.GetCommand; |
39 |
import gr.grnet.pithos.web.client.rest.resource.PermissionHolder; |
40 |
import gr.grnet.pithos.web.client.rest.resource.UserResource; |
41 |
import gr.grnet.pithos.web.client.rest.resource.UserSearchResource; |
42 |
|
43 |
import java.util.HashMap; |
44 |
import java.util.HashSet; |
45 |
import java.util.Map; |
46 |
import java.util.Set; |
47 |
|
48 |
import com.google.gwt.event.dom.client.ClickEvent; |
49 |
import com.google.gwt.event.dom.client.ClickHandler; |
50 |
import com.google.gwt.user.client.DeferredCommand; |
51 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
52 |
import com.google.gwt.user.client.ui.CheckBox; |
53 |
import com.google.gwt.user.client.ui.Composite; |
54 |
import com.google.gwt.user.client.ui.FlexTable; |
55 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
56 |
import com.google.gwt.user.client.ui.PushButton; |
57 |
import com.google.gwt.user.client.ui.VerticalPanel; |
58 |
|
59 |
|
60 |
public class PermissionsList extends Composite { |
61 |
|
62 |
int selectedRow = -1; |
63 |
|
64 |
int permissionCount = -1; |
65 |
|
66 |
Map<String, Boolean[]> permissions = null; |
67 |
|
68 |
final Images images;
|
69 |
|
70 |
final VerticalPanel permPanel = new VerticalPanel(); |
71 |
|
72 |
final FlexTable permTable = new FlexTable(); |
73 |
|
74 |
final String owner; |
75 |
|
76 |
private boolean hasChanges = false; |
77 |
|
78 |
private boolean hasAddition = false; |
79 |
|
80 |
private Pithos app;
|
81 |
|
82 |
public PermissionsList(Pithos _app, final Images theImages, Map<String, Boolean[]> thePermissions, String anOwner){ |
83 |
app = _app; |
84 |
images = theImages; |
85 |
owner = anOwner; |
86 |
permissions = new HashMap<String, Boolean[]>(thePermissions); |
87 |
permTable.setText(0, 0, "Users/Groups"); |
88 |
permTable.setText(0, 1, "Read"); |
89 |
permTable.setText(0, 2, "Write"); |
90 |
permTable.setText(0, 3, ""); |
91 |
permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
92 |
permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels"); |
93 |
permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels"); |
94 |
permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels"); |
95 |
permPanel.add(permTable); |
96 |
permPanel.addStyleName("pithos-TabPanelBottom");
|
97 |
initWidget(permPanel); |
98 |
updatePermissionTable(); |
99 |
} |
100 |
|
101 |
public boolean hasChanges(){ |
102 |
return hasChanges || hasAddition;
|
103 |
} |
104 |
|
105 |
public void updatePermissionsAccordingToInput(){ |
106 |
// int i=1;
|
107 |
// for(PermissionHolder dto : permissions){
|
108 |
// /*if(dto.getId() == null)
|
109 |
// hasChanges =true;*/
|
110 |
// CheckBox r = (CheckBox) permTable.getWidget(i, 1);
|
111 |
// CheckBox w = (CheckBox) permTable.getWidget(i, 2);
|
112 |
//
|
113 |
//
|
114 |
// if(dto.isRead() != r.getValue() || dto.isWrite() != w.getValue() || dto.isModifyACL() != m.getValue())
|
115 |
// hasChanges = true;
|
116 |
// dto.setRead(r.getValue());
|
117 |
// dto.setWrite(w.getValue());
|
118 |
// dto.setModifyACL(m.getValue());
|
119 |
// i++;
|
120 |
// }
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* Retrieve the permissions.
|
125 |
*
|
126 |
* @return the permissions
|
127 |
*/
|
128 |
public Map<String, Boolean[]> getPermissions() { |
129 |
return permissions;
|
130 |
} |
131 |
|
132 |
public void addPermission(String user, boolean read, boolean write){ |
133 |
permissions.put(user, new Boolean[] {Boolean.valueOf(read), Boolean.valueOf(write)}); |
134 |
hasAddition = true;
|
135 |
updatePermissionTable(); |
136 |
} |
137 |
|
138 |
/**
|
139 |
* Shows the permission table
|
140 |
*
|
141 |
*/
|
142 |
void updatePermissionTable(){
|
143 |
int i = 1; |
144 |
for (int j=1; j<permTable.getRowCount(); j++) |
145 |
permTable.removeRow(j); |
146 |
for(final String user : permissions.keySet()) { |
147 |
PushButton removeButton = new PushButton(AbstractImagePrototype.create(images.delete()).createImage(), new ClickHandler() { |
148 |
@Override
|
149 |
public void onClick(ClickEvent event) { |
150 |
permissions.remove(user); |
151 |
updatePermissionTable(); |
152 |
hasChanges = true;
|
153 |
} |
154 |
}); |
155 |
if (user.equals(owner)) {
|
156 |
permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + " Owner</span>"); |
157 |
removeButton.setVisible(false);
|
158 |
} |
159 |
else if (!user.contains(":")) //not a group |
160 |
permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + " " + user + "</span>"); |
161 |
else
|
162 |
permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permGroup()).getHTML() + " " + user.split(":")[1].trim() + "</span>"); |
163 |
|
164 |
Boolean[] userPerms = permissions.get(user); |
165 |
Boolean readP = userPerms[0]; |
166 |
Boolean writeP = userPerms[1]; |
167 |
|
168 |
CheckBox read = new CheckBox();
|
169 |
read.setValue(readP != null ? readP : false); |
170 |
|
171 |
CheckBox write = new CheckBox();
|
172 |
write.setValue(writeP != null ? writeP : false); |
173 |
|
174 |
permTable.setWidget(i, 1, read);
|
175 |
permTable.setWidget(i, 2, write);
|
176 |
permTable.setWidget(i, 3, removeButton);
|
177 |
permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels"); |
178 |
permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
|
179 |
permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
|
180 |
permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
|
181 |
i++; |
182 |
} |
183 |
hasChanges = false;
|
184 |
} |
185 |
} |