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

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

public class ImageVersionTable extends ListTable<ImageVersionDetails> {

	/**
	 * Version for serialization.
	 */
	private static final long serialVersionUID = -2532188492722932492L;

	public static final ListTableColumn COL_CREATED = new ListTableColumn(
			I18n.CONTROL.getString("ImageVersionTable.ListTableColumn.created.colName"), Long.class);
	public static final ListTableColumn COL_EXPIRING = new ListTableColumn(
			I18n.CONTROL.getString("ImageVersionTable.ListTableColumn.expiring.colName"), Long.class);
	public static final ListTableColumn COL_UPLOADER = new ListTableColumn(
			I18n.CONTROL.getString("ImageVersionTable.ListTableColumn.uploader.colName"));
	public static final ListTableColumn COL_VALID = new ListTableColumn(
			I18n.CONTROL.getString("ImageVersionTable.ListTableColumn.valid.colName"), Boolean.class);
	public static final ListTableColumn COL_SIZE = new ListTableColumn(
			I18n.CONTROL.getString("ImageVersionTable.ListTableColumn.size.colName"), Long.class);
	public static final ListTableColumn COL_ID = new ListTableColumn(
			I18n.CONTROL.getString("ImageVersionTable.ListTableColumn.ID.colName"));

	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();
	}
}