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.rest.resource.PermissionHolder;
24 import java.util.HashSet;
27 import com.google.gwt.event.dom.client.ClickEvent;
28 import com.google.gwt.event.dom.client.ClickHandler;
29 import com.google.gwt.user.client.ui.AbstractImagePrototype;
30 import com.google.gwt.user.client.ui.CheckBox;
31 import com.google.gwt.user.client.ui.Composite;
32 import com.google.gwt.user.client.ui.FlexTable;
33 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
34 import com.google.gwt.user.client.ui.PushButton;
35 import com.google.gwt.user.client.ui.VerticalPanel;
42 public class PermissionsList extends Composite {
45 int permissionCount=-1;
46 Set<PermissionHolder> permissions = null;
48 final VerticalPanel permPanel = new VerticalPanel();
49 final FlexTable permTable = new FlexTable();
51 PermissionHolder toRemove = null;
52 private boolean hasChanges = false;
53 private boolean hasAddition = false;
55 public PermissionsList(final Images theImages, Set<PermissionHolder> thePermissions, String anOwner){
58 permissions = new HashSet<PermissionHolder>();
59 permissions.addAll(thePermissions);
60 permTable.setText(0, 0, "Users/Groups");
61 permTable.setText(0, 1, "Read");
62 permTable.setText(0, 2, "Write");
63 permTable.setText(0, 3, "Modify Access");
64 permTable.setText(0, 4, "");
65 permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels");
66 permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels");
67 permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels");
68 permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels");
69 permPanel.add(permTable);
70 permPanel.addStyleName("gss-TabPanelBottom");
71 initWidget(permPanel);
75 public boolean hasChanges(){
76 return hasChanges || hasAddition;
80 public void updateTable(){
83 permissions.remove(toRemove);
86 for(final PermissionHolder dto : permissions){
88 PushButton removeButton = new PushButton(AbstractImagePrototype.create(images.delete()).createImage(), new ClickHandler() {
90 public void onClick(ClickEvent event) {
97 if(dto.getUser() !=null)
98 if(dto.getUser()!=null && dto.getUser().equals(owner)){
99 permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + " Owner</span>");
100 removeButton.setVisible(false);
103 permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + " "+ GSS.get().getUserFullName(dto.getUser()) +"</span>");
104 else if(dto.getGroup() != null)
105 permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permGroup()).getHTML() + " "+dto.getGroup()+"</span>");
106 CheckBox read = new CheckBox();
107 read.setValue(dto.isRead());
108 CheckBox write = new CheckBox();
109 write.setValue(dto.isWrite());
110 CheckBox modify = new CheckBox();
111 modify.setValue(dto.isModifyACL());
112 if (dto.getUser()!=null && dto.getUser().equals(owner)) {
113 read.setEnabled(false);
114 write.setEnabled(false);
115 modify.setEnabled(false);
117 permTable.setWidget(i, 1, read);
118 permTable.setWidget(i, 2, write);
119 permTable.setWidget(i, 3, modify);
120 permTable.setWidget(i, 4, removeButton);
121 permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels");
122 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
123 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
124 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
127 for(; i<permTable.getRowCount(); i++)
128 permTable.removeRow(i);
133 public void updatePermissionsAccordingToInput(){
135 for(PermissionHolder dto : permissions){
136 /*if(dto.getId() == null)
138 CheckBox r = (CheckBox) permTable.getWidget(i, 1);
139 CheckBox w = (CheckBox) permTable.getWidget(i, 2);
140 CheckBox m = (CheckBox) permTable.getWidget(i, 3);
141 if(dto.isRead() != r.getValue() || dto.isWrite() != w.getValue() || dto.isModifyACL() != m.getValue())
143 dto.setRead(r.getValue());
144 dto.setWrite(w.getValue());
145 dto.setModifyACL(m.getValue());
152 * Retrieve the permissions.
154 * @return the permissions
156 public Set<PermissionHolder> getPermissions() {
160 public void addPermission(PermissionHolder permission){
161 permissions.add(permission);