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

import java.util.Comparator;

import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.dozmod.thrift.MetaDataCache;
import org.openslx.dozmod.thrift.UserCache;
import org.openslx.dozmod.util.FormatHelper;

@SuppressWarnings("serial")
public class ImageTable extends ListTable<ImageSummaryRead> {

	private static String[] columnNames = { "Name", "OS", "Besitzer", "Letztes Update", "Größe", "Version",
			"Vorlage" };

	private static Class<?>[] columnClasses = { String.class, String.class, String.class, String.class,
			String.class, String.class, Boolean.class };

	public ImageTable() {
		super(columnNames, columnClasses, new Comparator<ImageSummaryRead>() {
			@Override
			public int compare(ImageSummaryRead o1, ImageSummaryRead o2) {
				if (o1 == null && o2 == null)
					return 0;
				if (o1 == null)
					return 1;
				if (o2 == null)
					return -1;
				return o1.imageBaseId.compareTo(o2.imageBaseId);
			}
		});

		// sort with correct time and not lexicographic
		getRowSorter().setComparator(3, timeComparator);
	}

	@Override
	protected Object getValueAtInternal(int rowIndex, int columnIndex) {
		ImageSummaryRead row = getModelRow(rowIndex);
		if (columnIndex == 0)
			return row.getImageName();
		if (columnIndex == 1)
			return FormatHelper.osName(MetaDataCache.getOsById(row.getOsId()));
		if (columnIndex == 2)
			return FormatHelper.userName(UserCache.find(row.getOwnerId()));
		if (columnIndex == 3)
			return FormatHelper.longDate(row.getUpdateTime());
		if (columnIndex == 4)
			return row.getLatestVersionId() == null ? "-" : FormatHelper.bytes(row.getFileSize(), false);
		if (columnIndex == 5)
			return row.getLatestVersionId() == null ? "-" : row.getLatestVersionId();
		if (columnIndex == 6)
			return row.isTemplate;
		throw new IndexOutOfBoundsException();
	}
}