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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
package org.openslx.dozmod.gui.control.table;
import java.util.Comparator;
import javax.swing.Icon;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.I18n;
import org.openslx.dozmod.thrift.Sorters;
import org.openslx.dozmod.thrift.cache.MetaDataCache;
import org.openslx.dozmod.thrift.cache.UserCache;
import org.openslx.dozmod.util.FormatHelper;
public class ImageTable extends ListTable<ImageSummaryRead> {
/**
* Version for serialization.
*/
private static final long serialVersionUID = 832005911201385063L;
public static final ListTableColumn COL_TEMPLATE = new ListTableColumn(
I18n.CONTROL.getString("ImageTable.ListTableColumn.template.colName"), Boolean.class);
public static final ListTableColumn COL_USABLE = new ListTableColumn(
I18n.CONTROL.getString("ImageTable.ListTableColumn.usable.colName"), Boolean.class);
public static final ListTableColumn COL_SIZE = new ListTableColumn(
I18n.CONTROL.getString("ImageTable.ListTableColumn.size.colName"), Long.class);
public static final ListTableColumn COL_LASTCHANGE = new ListTableColumn(
I18n.CONTROL.getString("ImageTable.ListTableColumn.lastChange.colName"), Long.class);
public static final ListTableColumn COL_EXPIRING = new ListTableColumn(
I18n.CONTROL.getString("ImageTable.ListTableColumn.expiring.colName"), Long.class);
public static final ListTableColumn COL_OWNER = new ListTableColumn(
I18n.CONTROL.getString("ImageTable.ListTableColumn.owner.colName"), Sorters.userNameById);
public static final ListTableColumn COL_OS = new ListTableColumn(
I18n.CONTROL.getString("ImageTable.ListTableColumn.OS.colName"), Integer.class, Sorters.osNameById);
public static final ListTableColumn COL_NAME = new ListTableColumn(
I18n.CONTROL.getString("ImageTable.ListTableColumn.name.colName"));
public static final ListTableColumn COL_HYPERVISOR = new ListTableColumn(
I18n.CONTROL.getString("ImageTable.ListTableColumn.hypervisor.colName"), Icon.class);
public static final ListTableColumn COL_VERSIONCOUNT = new ListTableColumn(
I18n.CONTROL.getString("ImageTable.ListTableColumn.versionCount.colName"), Integer.class);
public static final ListTableColumn COL_TOTALSIZE = new ListTableColumn(
I18n.CONTROL.getString("ImageTable.ListTableColumn.totalSize.colName"), Long.class);
public ImageTable() {
super(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);
}
}, COL_NAME, COL_OS, COL_OWNER, COL_LASTCHANGE, COL_EXPIRING, COL_SIZE, COL_USABLE, COL_TEMPLATE, COL_HYPERVISOR,
COL_VERSIONCOUNT, COL_TOTALSIZE);
}
// return the right value of our image (row) depending on given column
@Override
protected Object getValueAtInternal(ImageSummaryRead row, ListTableColumn column) {
if (column == COL_NAME)
return row.getImageName();
if (column == COL_OS)
return row.getOsId();
if (column == COL_OWNER)
return row.getOwnerId();
if (column == COL_LASTCHANGE)
return row.getUpdateTime();
if (column == COL_EXPIRING)
return row.getExpireTime();
if (column == COL_SIZE)
return row.getFileSize();
if (column == COL_USABLE)
return row.isIsValid();
if (column == COL_TEMPLATE)
return row.isIsTemplate();
if (column == COL_HYPERVISOR)
return row.getVirtId();
if (column == COL_VERSIONCOUNT)
return row.getVersionCount();
if (column == COL_TOTALSIZE)
return row.getFileSizeSum();
throw new IndexOutOfBoundsException();
}
@Override
public Object modelValueToDisplayFormat(Object value, ListTableColumn column) {
if (column == COL_NAME || column == COL_USABLE || column == COL_TEMPLATE || column == COL_VERSIONCOUNT)
return value;
if (column == COL_OS)
return FormatHelper.osName(MetaDataCache.getOsById((int) value, true));
if (column == COL_OWNER)
return FormatHelper.userName(UserCache.find((String) value));
if (column == COL_LASTCHANGE || column == COL_EXPIRING)
return FormatHelper.shortDate((long) value);
if (column == COL_SIZE || column == COL_TOTALSIZE)
return FormatHelper.bytes((long) value, false);
if (column == COL_HYPERVISOR)
return Gui.getScaledIconResource("/img/" + value + "-icon.png", "Virtualizer Icon", getRowHeight(), this);
throw new IndexOutOfBoundsException();
}
}
|