2 * Copyright 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.admin.client.ui;
21 import gr.ebs.gss.admin.client.TwoAdmin;
22 import gr.ebs.gss.server.domain.dto.PermissionDTO;
24 import java.util.HashSet;
27 import com.google.gwt.core.client.GWT;
28 import com.google.gwt.event.dom.client.ClickEvent;
29 import com.google.gwt.event.dom.client.ClickHandler;
30 import com.google.gwt.http.client.URL;
31 import com.google.gwt.user.client.rpc.AsyncCallback;
32 import com.google.gwt.user.client.ui.Button;
33 import com.google.gwt.user.client.ui.CheckBox;
34 import com.google.gwt.user.client.ui.Composite;
35 import com.google.gwt.user.client.ui.FlexTable;
36 import com.google.gwt.user.client.ui.HTML;
37 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
38 import com.google.gwt.user.client.ui.VerticalPanel;
45 public class PermissionsList extends Composite {
48 int permissionCount=-1;
49 Set<PermissionDTO> permissions = null;
51 final VerticalPanel permPanel = new VerticalPanel();
52 final FlexTable permTable = new FlexTable();
54 PermissionDTO toRemove = null;
55 private boolean hasChanges = false;
56 private boolean hasAddition = false;
57 private boolean allowEditPermissions = false;
59 public PermissionsList(Set<PermissionDTO> thePermissions, String anOwner, boolean _allowEditPermissions){
61 permissions = new HashSet<PermissionDTO>();
62 permissions.addAll(thePermissions);
63 permTable.setText(0, 0, "Users/Groups");
64 permTable.setText(0, 1, "Read");
65 permTable.setText(0, 2, "Write");
66 permTable.setText(0, 3, "Modify Access");
67 permTable.setText(0, 4, "");
68 permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels");
69 permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels");
70 permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels");
71 permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels");
72 permPanel.add(permTable);
73 Button savePermissions = new Button("Save");
74 permPanel.add(savePermissions);
76 savePermissions.addClickHandler(new ClickHandler() {
79 public void onClick(ClickEvent event) {
80 updatePermissionsAccordingToInput();
82 TwoAdmin.get().getAdminService().setFilePermissions(uri,permissions, new AsyncCallback<Void>() {
85 public void onSuccess(Void result) {
91 public void onFailure(Throwable caught) {
92 GWT.log("Error fetching file", caught);
93 TwoAdmin.get().showErrorBox("Unable to Find File");
100 permPanel.addStyleName("gss-TabPanelBottom");
101 allowEditPermissions = _allowEditPermissions;
102 initWidget(permPanel);
106 public boolean hasChanges(){
107 return hasChanges || hasAddition;
111 permissions= new HashSet<PermissionDTO>();
115 public void update(Set<PermissionDTO> per, String aUri){
120 public void updateTable(){
122 if(toRemove != null){
123 permissions.remove(toRemove);
126 for(final PermissionDTO dto : permissions){
128 Button removeButton = new Button("remove", new ClickHandler() {
130 public void onClick(ClickEvent event) {
137 if(dto.getUser() !=null)
138 if(dto.getUser()!=null && dto.getUser().getUsername().equals(owner)){
139 permTable.setHTML(i, 0, "<span>" + " Owner</span>");
140 removeButton.setVisible(false);
143 HTML userLabel = new HTML("<a href='#'>"+dto.getUser().getUsername()+"</a></span>");
144 permTable.setWidget(i, 0, userLabel);
145 userLabel.addClickHandler(new ClickHandler() {
148 public void onClick(ClickEvent event) {
149 TwoAdmin.get().searchUsers("username:"+dto.getUser().getUsername());
154 else if(dto.getGroup() != null) {
155 //String user = GSS.get().getCurrentUserResource().getUsername();
156 String[] names = dto.getGroup().getName().split("/");
157 String name = URL.decodeComponent(names[names.length - 1]);
158 //String ownr = names.length>1 ? URL.decodeComponent(names[names.length - 3]) : user;
159 String groupName = name;
160 permTable.setHTML(i, 0, "<span>" + " "+groupName+"</span>");
162 CheckBox read = new CheckBox();
163 read.setValue(dto.getRead());
164 CheckBox write = new CheckBox();
165 write.setValue(dto.getWrite());
166 CheckBox modify = new CheckBox();
167 modify.setValue(dto.getModifyACL());
168 permTable.setWidget(i, 1, read);
169 permTable.setWidget(i, 2, write);
170 permTable.setWidget(i, 3, modify);
171 if (dto.getUser()!=null && dto.getUser().getUsername().equals(owner) || !allowEditPermissions) {
172 read.setEnabled(false);
173 write.setEnabled(false);
174 modify.setEnabled(false);
177 permTable.setWidget(i, 4, removeButton);
178 permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels");
179 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
180 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
181 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
184 for(; i<permTable.getRowCount(); i++)
185 permTable.removeRow(i);
190 public void updatePermissionsAccordingToInput(){
192 for(PermissionDTO dto : permissions){
193 /*if(dto.getId() == null)
195 CheckBox r = (CheckBox) permTable.getWidget(i, 1);
196 CheckBox w = (CheckBox) permTable.getWidget(i, 2);
197 CheckBox m = (CheckBox) permTable.getWidget(i, 3);
198 if(dto.getRead() != r.getValue() || dto.getWrite() != w.getValue() || dto.getModifyACL() != m.getValue())
200 dto.setRead(r.getValue());
201 dto.setWrite(w.getValue());
202 dto.setModifyACL(m.getValue());
209 * Retrieve the permissions.
211 * @return the permissions
213 public Set<PermissionDTO> getPermissions() {
217 public void addPermission(PermissionDTO permission){
218 permissions.add(permission);