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.user.client.ui.CheckBox;
28 import com.google.gwt.user.client.ui.ClickListener;
29 import com.google.gwt.user.client.ui.Composite;
30 import com.google.gwt.user.client.ui.FlexTable;
31 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
32 import com.google.gwt.user.client.ui.PushButton;
33 import com.google.gwt.user.client.ui.VerticalPanel;
34 import com.google.gwt.user.client.ui.Widget;
41 public class PermissionsList extends Composite {
44 int permissionCount=-1;
45 Set<PermissionHolder> permissions = null;
47 final VerticalPanel permPanel = new VerticalPanel();
48 final FlexTable permTable = new FlexTable();
50 PermissionHolder toRemove = null;
51 private boolean hasChanges = false;
52 private boolean hasAddition = false;
54 public PermissionsList(final Images images, Set<PermissionHolder> permissions, String owner){
57 this.permissions = new HashSet<PermissionHolder>();
58 this.permissions.addAll(permissions);
59 permTable.setText(0, 0, "Users/Groups");
60 permTable.setText(0, 1, "Read");
61 permTable.setText(0, 2, "Write");
62 permTable.setText(0, 3, "Modify Access");
63 permTable.setText(0, 4, "");
64 permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels");
65 permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels");
66 permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels");
67 permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels");
68 permPanel.add(permTable);
69 permPanel.addStyleName("gwt-TabPanelBottom");
70 initWidget(permPanel);
74 public boolean hasChanges(){
75 return hasChanges || hasAddition;
79 public void updateTable(){
82 permissions.remove(toRemove);
85 for(final PermissionHolder dto : permissions){
87 PushButton removeButton = new PushButton(images.delete().createImage(), new ClickListener() {
89 public void onClick(Widget sender) {
96 if(dto.getUser() !=null)
97 if(dto.getUser()!=null && dto.getUser().equals(owner)){
98 permTable.setHTML(i, 0, "<span>" + images.permUser().getHTML() + " Owner</span>");
99 removeButton.setVisible(false);
102 permTable.setHTML(i, 0, "<span>" + images.permUser().getHTML() + " "+dto.getUser()+"</span>");
103 else if(dto.getGroup() != null)
104 permTable.setHTML(i, 0, "<span>" + images.permGroup().getHTML() + " "+dto.getGroup()+"</span>");
105 CheckBox read = new CheckBox();
106 read.setChecked(dto.isRead());
107 CheckBox write = new CheckBox();
108 write.setChecked(dto.isWrite());
109 CheckBox modify = new CheckBox();
110 modify.setChecked(dto.isModifyACL());
111 permTable.setWidget(i, 1, read);
112 permTable.setWidget(i, 2, write);
113 permTable.setWidget(i, 3, modify);
114 permTable.setWidget(i, 4, removeButton);
115 permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels");
116 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
117 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
118 permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
121 for(; i<permTable.getRowCount(); i++)
122 permTable.removeRow(i);
127 public void updatePermissionsAccordingToInput(){
129 for(PermissionHolder dto : permissions){
130 /*if(dto.getId() == null)
132 CheckBox r = (CheckBox) permTable.getWidget(i, 1);
133 CheckBox w = (CheckBox) permTable.getWidget(i, 2);
134 CheckBox m = (CheckBox) permTable.getWidget(i, 3);
135 if(dto.isRead() != r.isChecked() || dto.isWrite() != w.isChecked() || dto.isModifyACL() != m.isChecked())
137 dto.setRead(r.isChecked());
138 dto.setWrite(w.isChecked());
139 dto.setModifyACL(m.isChecked());
146 * Retrieve the permissions.
148 * @return the permissions
150 public Set<PermissionHolder> getPermissions() {
154 public void addPermission(PermissionHolder permission){
155 permissions.add(permission);