blob: 9d8bd2a326b210c3696a996b3a1fb71adf78c471 (
plain) (
tree)
|
|
package org.openslx.dozmod.gui.control.table;
import org.openslx.bwlp.thrift.iface.LecturePermissions;
import org.openslx.dozmod.gui.control.table.LecturePermissionTable.UserLecturePermissions;
import org.openslx.dozmod.thrift.cache.UserCache;
import org.openslx.dozmod.util.FormatHelper;
@SuppressWarnings("serial")
public class LecturePermissionTable extends ListTable<UserLecturePermissions> {
public static final ListTableColumn COL_USER = new ListTableColumn("Benutzer");
public static final ListTableColumn COL_EDIT = new ListTableColumn("Bearbeiten", Boolean.class);
public static final ListTableColumn COL_ADMIN = new ListTableColumn("Admin", Boolean.class);
public LecturePermissionTable() {
super(COL_USER, COL_EDIT, COL_ADMIN);
}
@Override
protected Object getValueAtInternal(UserLecturePermissions row, ListTableColumn column) {
if (column == COL_USER)
return FormatHelper.userName(UserCache.find(row.userId));
if (column == COL_EDIT)
return row.permissions.edit;
if (column == COL_ADMIN)
return row.permissions.admin;
throw new IndexOutOfBoundsException();
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
// TODO actual permission checks
return columnIndex != 0;
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
// aValue must be boolean
if (!(aValue instanceof Boolean))
return;
UserLecturePermissions row = getViewRow(rowIndex);
if (columnIndex == 1)
row.permissions.edit = (boolean) aValue;
if (columnIndex == 2)
row.permissions.admin = (boolean) aValue;
return;
}
/**
* Helper class for linking UserIds to permissions of an image.
*/
public static class UserLecturePermissions {
public final String userId;
public final LecturePermissions permissions;
public UserLecturePermissions(String userId, LecturePermissions permission) {
this.userId = userId;
this.permissions = permission;
}
}
}
|