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.client;
21 import gr.ebs.gss.client.FilePropertiesDialog.Images;
22 import gr.ebs.gss.client.commands.GetUserCommand;
23 import gr.ebs.gss.client.rest.resource.PermissionHolder;
25 import java.util.HashSet;
28 import com.google.gwt.event.dom.client.ClickEvent;
29 import com.google.gwt.event.dom.client.ClickHandler;
30 import com.google.gwt.user.client.ui.AbstractImagePrototype;
31 import com.google.gwt.user.client.ui.CheckBox;
32 import com.google.gwt.user.client.ui.Composite;
33 import com.google.gwt.user.client.ui.FlexTable;
34 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
35 import com.google.gwt.user.client.ui.PushButton;
36 import com.google.gwt.user.client.ui.VerticalPanel;
43 public class PermissionsList extends Composite {
46 int permissionCount=-1;
47 Set<PermissionHolder> permissions = null;
49 final VerticalPanel permPanel = new VerticalPanel();
50 final FlexTable permTable = new FlexTable();
52 PermissionHolder toRemove = null;
53 private boolean hasChanges = false;
54 private boolean hasAddition = false;
56 public PermissionsList(final Images theImages, Set<PermissionHolder> thePermissions, String anOwner){
59 permissions = new HashSet<PermissionHolder>();
60 permissions.addAll(thePermissions);
61 permTable.setText(0, 0, "Users/Groups");
62 permTable.setText(0, 1, "Read");
63 permTable.setText(0, 2, "Write");
64 permTable.setText(0, 3, "Modify Access");
65 permTable.setText(0, 4, "");
66 permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels");
67 permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels");
68 permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels");
69 permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels");
70 permPanel.add(permTable);
71 permPanel.addStyleName("gss-TabPanelBottom");
72 initWidget(permPanel);
76 public boolean hasChanges(){
77 return hasChanges || hasAddition;
81 public void updateTable(){
84 permissions.remove(toRemove);
87 for(final PermissionHolder dto : permissions){
89 PushButton removeButton = new PushButton(AbstractImagePrototype.create(images.delete()).createImage(), new ClickHandler() {
91 public void onClick(ClickEvent event) {
98 if(dto.getUser() !=null)
99 if(dto.getUser()!=null && dto.getUser().equals(owner)){
100 permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + " Owner</span>");
101 removeButton.setVisible(false);
104 if(GSS.get().findUserFullName(dto.getUser()) == null){
105 GetUserCommand guc = new GetUserCommand(dto.getUser());
107 GSS.get().putUserToMap(dto.getUser(), dto.getUser());
109 permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + " "+ GSS.get().findUserFullName(dto.getUser()) +"</span>");
111 else if(dto.getGroup() != null)
112 permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permGroup()).getHTML() + " "+dto.getGroup()+"</span>");
113 CheckBox read = new CheckBox();
114 read.setValue(dto.isRead());
115 CheckBox write = new CheckBox();
116 write.setValue(dto.isWrite());
117 CheckBox modify = new CheckBox();
118 modify.setValue(dto.isModifyACL());
119 if (dto.getUser()!=null && dto.getUser().equals(owner)) {
120 read.setEnabled(false);
121 write.setEnabled(false);
122 modify.setEnabled(false);
124 permTable.setWidget(i, 1, read);
125 permTable.setWidget(i, 2, write);
126 permTable.setWidget(i, 3, modify);
127 permTable.setWidget(i, 4, removeButton);
128 permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels");
129 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
130 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
131 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
134 for(; i<permTable.getRowCount(); i++)
135 permTable.removeRow(i);
140 public void updatePermissionsAccordingToInput(){
142 for(PermissionHolder dto : permissions){
143 /*if(dto.getId() == null)
145 CheckBox r = (CheckBox) permTable.getWidget(i, 1);
146 CheckBox w = (CheckBox) permTable.getWidget(i, 2);
147 CheckBox m = (CheckBox) permTable.getWidget(i, 3);
148 if(dto.isRead() != r.getValue() || dto.isWrite() != w.getValue() || dto.isModifyACL() != m.getValue())
150 dto.setRead(r.getValue());
151 dto.setWrite(w.getValue());
152 dto.setModifyACL(m.getValue());
159 * Retrieve the permissions.
161 * @return the permissions
163 public Set<PermissionHolder> getPermissions() {
167 public void addPermission(PermissionHolder permission){
168 permissions.add(permission);