summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageTableModel.java
blob: 443bb4c621c31dd9720b7ff71502cf42be22cfc0 (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
64
65
66
67
68
69
package org.openslx.dozmod.gui.helper;

import java.util.List;

import javax.swing.table.AbstractTableModel;

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

public class ImageTableModel extends AbstractTableModel {

	private static final long serialVersionUID = 3335684645951493805L;
	protected String[] columnNames = new String[] {
		"Name", "OS", "Verantwortlicher", "Letztes Update", "Größe"
	};
	protected Class<?>[] columnClasses = new Class[] { 
			String.class, String.class, String.class, String.class, String.class
	};
	private List<ImageSummaryRead> items = null;

	public ImageSummaryRead get(int index) {
		return items.get(index);
	}
	public void setItems(List<ImageSummaryRead> items) {
		this.items = items;
		fireTableDataChanged();
	}
	@Override
	public int getColumnCount() {
		return columnNames.length;
	}

	public boolean isCellEditable(int row, int col)
    { return false; }
	
	@Override
	public int getRowCount() {
		if (items == null) {
			return 0;
		}
		return items.size();
	}
	public Class<?> getColumnClass(int c) {

        return columnClasses[c];
    }
	public String getColumnName(int c) {

        return columnNames[c];
    }
	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		ImageSummaryRead item = items.get(rowIndex);
		OperatingSystem os = MetaDataCache.getOsById(item.getOsId());
		UserInfo user = UserCache.find(item.getOwnerId());
		switch(columnIndex) {
		    case 0: return item.getImageName();
		    case 1: return os == null ? "Unknown" : os.getOsName();
		    case 2: return FormatHelper.userName(user);
		    case 3: return FormatHelper.shortDate(item.getUpdateTime());
		    case 4: return item.getCurrentVersionId() == null ? "-" : FormatHelper.bytes(item.getFileSize(), false);
		    default: return null;
		}
	}
}