root / src / gr / ebs / gss / client / PermissionsList.java @ a60ea262
History | View | Annotate | Download (5.4 kB)
1 | 14ad7326 | pastith | /*
|
---|---|---|---|
2 | 14ad7326 | pastith | * Copyright 2008, 2009 Electronic Business Systems Ltd.
|
3 | 14ad7326 | pastith | *
|
4 | 14ad7326 | pastith | * This file is part of GSS.
|
5 | 14ad7326 | pastith | *
|
6 | 14ad7326 | pastith | * GSS is free software: you can redistribute it and/or modify
|
7 | 14ad7326 | pastith | * it under the terms of the GNU General Public License as published by
|
8 | 14ad7326 | pastith | * the Free Software Foundation, either version 3 of the License, or
|
9 | 14ad7326 | pastith | * (at your option) any later version.
|
10 | 14ad7326 | pastith | *
|
11 | 14ad7326 | pastith | * GSS is distributed in the hope that it will be useful,
|
12 | 14ad7326 | pastith | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 14ad7326 | pastith | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 14ad7326 | pastith | * GNU General Public License for more details.
|
15 | 14ad7326 | pastith | *
|
16 | 14ad7326 | pastith | * You should have received a copy of the GNU General Public License
|
17 | 14ad7326 | pastith | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | 14ad7326 | pastith | */
|
19 | 14ad7326 | pastith | package gr.ebs.gss.client; |
20 | 14ad7326 | pastith | |
21 | 14ad7326 | pastith | import gr.ebs.gss.client.FilePropertiesDialog.Images; |
22 | a52ea5e4 | pastith | import gr.ebs.gss.client.rest.resource.PermissionHolder; |
23 | 14ad7326 | pastith | |
24 | a52ea5e4 | pastith | import java.util.HashSet; |
25 | 14ad7326 | pastith | import java.util.Set; |
26 | 14ad7326 | pastith | |
27 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.event.dom.client.ClickEvent; |
28 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.event.dom.client.ClickHandler; |
29 | afd3a0ef | Giannis Koutsoubos | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
30 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.CheckBox; |
31 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.Composite; |
32 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.FlexTable; |
33 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
34 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.PushButton; |
35 | 14ad7326 | pastith | import com.google.gwt.user.client.ui.VerticalPanel; |
36 | 14ad7326 | pastith | |
37 | 14ad7326 | pastith | |
38 | 14ad7326 | pastith | /**
|
39 | 14ad7326 | pastith | * @author kman
|
40 | 14ad7326 | pastith | *
|
41 | 14ad7326 | pastith | */
|
42 | 14ad7326 | pastith | public class PermissionsList extends Composite { |
43 | 14ad7326 | pastith | |
44 | 14ad7326 | pastith | int selectedRow = -1; |
45 | 14ad7326 | pastith | int permissionCount=-1; |
46 | a52ea5e4 | pastith | Set<PermissionHolder> permissions = null; |
47 | 14ad7326 | pastith | final Images images;
|
48 | 14ad7326 | pastith | final VerticalPanel permPanel = new VerticalPanel(); |
49 | 14ad7326 | pastith | final FlexTable permTable = new FlexTable(); |
50 | a52ea5e4 | pastith | final String owner; |
51 | a52ea5e4 | pastith | PermissionHolder toRemove = null;
|
52 | 14ad7326 | pastith | private boolean hasChanges = false; |
53 | 409e932c | koutsoub | private boolean hasAddition = false; |
54 | 14ad7326 | pastith | |
55 | aa07a34b | Panagiotis Astithas | public PermissionsList(final Images theImages, Set<PermissionHolder> thePermissions, String anOwner){ |
56 | aa07a34b | Panagiotis Astithas | images = theImages; |
57 | aa07a34b | Panagiotis Astithas | owner = anOwner; |
58 | aa07a34b | Panagiotis Astithas | permissions = new HashSet<PermissionHolder>(); |
59 | aa07a34b | Panagiotis Astithas | permissions.addAll(thePermissions); |
60 | 14ad7326 | pastith | permTable.setText(0, 0, "Users/Groups"); |
61 | 14ad7326 | pastith | permTable.setText(0, 1, "Read"); |
62 | 14ad7326 | pastith | permTable.setText(0, 2, "Write"); |
63 | b4771f6a | fstamatelopoulos | permTable.setText(0, 3, "Modify Access"); |
64 | 14ad7326 | pastith | permTable.setText(0, 4, ""); |
65 | 14ad7326 | pastith | permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
66 | 14ad7326 | pastith | permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels"); |
67 | 14ad7326 | pastith | permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels"); |
68 | 14ad7326 | pastith | permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels"); |
69 | 14ad7326 | pastith | permPanel.add(permTable); |
70 | 5c6b2883 | Panagiotis Astithas | permPanel.addStyleName("gss-TabPanelBottom");
|
71 | 14ad7326 | pastith | initWidget(permPanel); |
72 | 14ad7326 | pastith | updateTable(); |
73 | 14ad7326 | pastith | } |
74 | 14ad7326 | pastith | |
75 | 14ad7326 | pastith | public boolean hasChanges(){ |
76 | 409e932c | koutsoub | return hasChanges || hasAddition;
|
77 | 14ad7326 | pastith | } |
78 | 14ad7326 | pastith | |
79 | 14ad7326 | pastith | |
80 | 14ad7326 | pastith | public void updateTable(){ |
81 | 14ad7326 | pastith | int i=1; |
82 | 14ad7326 | pastith | if(toRemove != null){ |
83 | 14ad7326 | pastith | permissions.remove(toRemove); |
84 | 14ad7326 | pastith | toRemove = null;
|
85 | 14ad7326 | pastith | } |
86 | a52ea5e4 | pastith | for(final PermissionHolder dto : permissions){ |
87 | 14ad7326 | pastith | |
88 | afd3a0ef | Giannis Koutsoubos | PushButton removeButton = new PushButton(AbstractImagePrototype.create(images.delete()).createImage(), new ClickHandler() { |
89 | afd3a0ef | Giannis Koutsoubos | @Override
|
90 | afd3a0ef | Giannis Koutsoubos | public void onClick(ClickEvent event) { |
91 | 14ad7326 | pastith | toRemove = dto; |
92 | 14ad7326 | pastith | updateTable(); |
93 | 14ad7326 | pastith | hasChanges = true;
|
94 | 14ad7326 | pastith | } |
95 | 14ad7326 | pastith | }); |
96 | 4bf05cad | Natasa Kapravelou | |
97 | 14ad7326 | pastith | if(dto.getUser() !=null) |
98 | a52ea5e4 | pastith | if(dto.getUser()!=null && dto.getUser().equals(owner)){ |
99 | afd3a0ef | Giannis Koutsoubos | permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + " Owner</span>"); |
100 | 14ad7326 | pastith | removeButton.setVisible(false);
|
101 | 14ad7326 | pastith | } |
102 | 4bf05cad | Natasa Kapravelou | else
|
103 | 4bf05cad | Natasa Kapravelou | permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + " "+ GSS.get().getUserFullName(dto.getUser()) +"</span>"); |
104 | 14ad7326 | pastith | else if(dto.getGroup() != null) |
105 | afd3a0ef | Giannis Koutsoubos | permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permGroup()).getHTML() + " "+dto.getGroup()+"</span>"); |
106 | 14ad7326 | pastith | CheckBox read = new CheckBox();
|
107 | afd3a0ef | Giannis Koutsoubos | read.setValue(dto.isRead()); |
108 | 14ad7326 | pastith | CheckBox write = new CheckBox();
|
109 | afd3a0ef | Giannis Koutsoubos | write.setValue(dto.isWrite()); |
110 | 14ad7326 | pastith | CheckBox modify = new CheckBox();
|
111 | afd3a0ef | Giannis Koutsoubos | modify.setValue(dto.isModifyACL()); |
112 | d805967a | droutsis | if (dto.getUser()!=null && dto.getUser().equals(owner)) { |
113 | d805967a | droutsis | read.setEnabled(false);
|
114 | d805967a | droutsis | write.setEnabled(false);
|
115 | d805967a | droutsis | modify.setEnabled(false);
|
116 | d805967a | droutsis | } |
117 | 14ad7326 | pastith | permTable.setWidget(i, 1, read);
|
118 | 14ad7326 | pastith | permTable.setWidget(i, 2, write);
|
119 | 14ad7326 | pastith | permTable.setWidget(i, 3, modify);
|
120 | 14ad7326 | pastith | permTable.setWidget(i, 4, removeButton);
|
121 | 14ad7326 | pastith | permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels"); |
122 | 14ad7326 | pastith | permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
|
123 | 14ad7326 | pastith | permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
|
124 | 14ad7326 | pastith | permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
|
125 | 14ad7326 | pastith | i++; |
126 | 14ad7326 | pastith | } |
127 | 14ad7326 | pastith | for(; i<permTable.getRowCount(); i++)
|
128 | 14ad7326 | pastith | permTable.removeRow(i); |
129 | 14ad7326 | pastith | hasChanges = false;
|
130 | 14ad7326 | pastith | |
131 | 14ad7326 | pastith | } |
132 | 14ad7326 | pastith | |
133 | 14ad7326 | pastith | public void updatePermissionsAccordingToInput(){ |
134 | 14ad7326 | pastith | int i=1; |
135 | a52ea5e4 | pastith | for(PermissionHolder dto : permissions){
|
136 | a52ea5e4 | pastith | /*if(dto.getId() == null)
|
137 | a52ea5e4 | pastith | hasChanges =true;*/
|
138 | 14ad7326 | pastith | CheckBox r = (CheckBox) permTable.getWidget(i, 1);
|
139 | 14ad7326 | pastith | CheckBox w = (CheckBox) permTable.getWidget(i, 2);
|
140 | 14ad7326 | pastith | CheckBox m = (CheckBox) permTable.getWidget(i, 3);
|
141 | afd3a0ef | Giannis Koutsoubos | if(dto.isRead() != r.getValue() || dto.isWrite() != w.getValue() || dto.isModifyACL() != m.getValue())
|
142 | 14ad7326 | pastith | hasChanges = true;
|
143 | afd3a0ef | Giannis Koutsoubos | dto.setRead(r.getValue()); |
144 | afd3a0ef | Giannis Koutsoubos | dto.setWrite(w.getValue()); |
145 | afd3a0ef | Giannis Koutsoubos | dto.setModifyACL(m.getValue()); |
146 | 14ad7326 | pastith | i++; |
147 | 14ad7326 | pastith | } |
148 | 14ad7326 | pastith | } |
149 | 14ad7326 | pastith | |
150 | 14ad7326 | pastith | |
151 | a52ea5e4 | pastith | /**
|
152 | a52ea5e4 | pastith | * Retrieve the permissions.
|
153 | a52ea5e4 | pastith | *
|
154 | a52ea5e4 | pastith | * @return the permissions
|
155 | a52ea5e4 | pastith | */
|
156 | a52ea5e4 | pastith | public Set<PermissionHolder> getPermissions() { |
157 | a52ea5e4 | pastith | return permissions;
|
158 | a52ea5e4 | pastith | } |
159 | a52ea5e4 | pastith | |
160 | 409e932c | koutsoub | public void addPermission(PermissionHolder permission){ |
161 | 409e932c | koutsoub | permissions.add(permission); |
162 | 409e932c | koutsoub | hasAddition = true;
|
163 | 409e932c | koutsoub | } |
164 | a52ea5e4 | pastith | |
165 | a52ea5e4 | pastith | |
166 | 14ad7326 | pastith | } |