summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LecturePermissionTable.java
blob: 67a7e53d30ee99f0e2a3112613a47d5e016bf355 (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
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.UserCache;
import org.openslx.dozmod.util.FormatHelper;

@SuppressWarnings("serial")
public class LecturePermissionTable extends ListTable<UserLecturePermissions> {

	private static String[] columnNames = { "Benutzer", "Bearbeiten", "Admin" };

	public LecturePermissionTable() {
		super(columnNames);
	}

	@Override
	protected Object getValueAtInternal(int rowIndex, int columnIndex) {
		UserLecturePermissions row = get(rowIndex);
		if (columnIndex == 0)
			return FormatHelper.userName(UserCache.find(row.userId));
		if (columnIndex == 1)
			return row.permissions.edit;
		if (columnIndex == 2)
			return row.permissions.admin;
		throw new IndexOutOfBoundsException();
	}

	/**
	 * 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;
		}

	}

}