summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageVersionTable.java
blob: f69d3c471618f869670d7b40eb38deb226850ccd (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
package org.openslx.dozmod.gui.control.table;

import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.dozmod.thrift.cache.UserCache;
import org.openslx.dozmod.util.FormatHelper;

@SuppressWarnings("serial")
public class ImageVersionTable extends ListTable<ImageVersionDetails> {

	public static final ListTableColumn COL_CREATED = new ListTableColumn("Erstellungszeitpunkt", Long.class);
	public static final ListTableColumn COL_EXPIRING = new ListTableColumn("Ablaufszeitpunkt", Long.class);
	public static final ListTableColumn COL_UPLOADER = new ListTableColumn("Ersteller");
	public static final ListTableColumn COL_VALID = new ListTableColumn("Verwendbar", Boolean.class);
	public static final ListTableColumn COL_SIZE = new ListTableColumn("Größe", Long.class);
	public static final ListTableColumn COL_ID = new ListTableColumn("Interne ID");

	public ImageVersionTable() {
		super(COL_CREATED, COL_EXPIRING, COL_UPLOADER, COL_VALID, COL_SIZE, COL_ID);
	}

	@Override
	protected Object getValueAtInternal(ImageVersionDetails row, ListTableColumn column) {
		if (column == COL_CREATED)
			return row.getCreateTime();
		if (column == COL_EXPIRING)
			return row.getExpireTime();
		if (column == COL_UPLOADER)
			return row.getUploaderId();
		if (column == COL_VALID)
			return row.isValid;
		if (column == COL_SIZE)
			return row.getFileSize();
		if (column == COL_ID)
			return row.getVersionId();
		throw new IndexOutOfBoundsException();
	}

	@Override
	public Object modelValueToDisplayFormat(Object value, ListTableColumn column) {
		if (column == COL_VALID || column == COL_ID)
			return value;
		if (column == COL_CREATED)
			return FormatHelper.longDate((long) value);
		if (column == COL_EXPIRING)
			return FormatHelper.daysTil((long) value);
		if (column == COL_UPLOADER)
			return FormatHelper.userName(UserCache.find((String) value));
		if (column == COL_SIZE)
			return FormatHelper.bytes((long) value, false);
		throw new IndexOutOfBoundsException();
	}
}