1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package org.openslx.dozmod.gui.control.table;
import org.openslx.bwlp.thrift.iface.ImagePermissions;
import org.openslx.dozmod.gui.control.table.ImagePermissionTable.UserImagePermissions;
import org.openslx.dozmod.thrift.cache.UserCache;
import org.openslx.dozmod.util.FormatHelper;
@SuppressWarnings("serial")
public class ImagePermissionTable extends ListTable<UserImagePermissions> {
public static final ListTableColumn COL_USER = new ListTableColumn("Benutzer");
public static final ListTableColumn COL_LINK = new ListTableColumn("Verlinken", Boolean.class);
public static final ListTableColumn COL_DOWNLOAD = new ListTableColumn("Download", Boolean.class);
public static final ListTableColumn COL_EDIT = new ListTableColumn("Bearbeiten", Boolean.class);
public static final ListTableColumn COL_ADMIN = new ListTableColumn("Admin", Boolean.class);
public ImagePermissionTable() {
super(COL_USER, COL_LINK, COL_DOWNLOAD, COL_EDIT, COL_ADMIN);
}
@Override
protected Object getValueAtInternal(UserImagePermissions row, ListTableColumn column) {
if (column == COL_USER)
return FormatHelper.userName(UserCache.find(row.userId));
if (column == COL_LINK)
return row.permissions.link;
if (column == COL_DOWNLOAD)
return row.permissions.download;
if (column == COL_EDIT)
return row.permissions.edit;
if (column == COL_ADMIN)
return row.permissions.admin;
throw new IndexOutOfBoundsException();
}
@Override
public boolean isCellEditable(int row, int col) {
// TODO actual permission checks
return col != 0;
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
// aValue must be boolean
if (!(aValue instanceof Boolean))
return;
// TODO convert index to model index
UserImagePermissions row = getViewRow(rowIndex);
if (columnIndex == 1)
row.permissions.link = (boolean) aValue;
if (columnIndex == 2)
row.permissions.download = (boolean) aValue;
if (columnIndex == 3)
row.permissions.edit = (boolean) aValue;
if (columnIndex == 4)
row.permissions.admin = (boolean) aValue;
return;
}
/**
* Helper class for linking UserIds to permissions of an image.
*/
public static class UserImagePermissions {
public final String userId;
public final ImagePermissions permissions;
public UserImagePermissions(String userId, ImagePermissions permission) {
this.userId = userId;
this.permissions = permission;
}
}
}
|