summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LecturePermissionTable.java
blob: 9d8bd2a326b210c3696a996b3a1fb71adf78c471 (plain) (blame)
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
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;
		}

	}

}