package org.openslx.dozmod.gui.control.table; import java.util.Comparator; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.dozmod.thrift.Sorters; import org.openslx.dozmod.thrift.cache.MetaDataCache; import org.openslx.dozmod.thrift.cache.OrganizationCache; import org.openslx.dozmod.thrift.cache.UserCache; import org.openslx.dozmod.util.FormatHelper; @SuppressWarnings("serial") public class ImagePublishedTable extends ListTable { // public static final ListTableColumn COL_TEMPLATE = new ListTableColumn("Vorlage", Boolean.class); // public static final ListTableColumn COL_USABLE = new ListTableColumn("Verwendbar", Boolean.class); // public static final ListTableColumn COL_SIZE = new ListTableColumn("Größe", Long.class); // public static final ListTableColumn COL_LASTCHANGE = new ListTableColumn("Geändert", Long.class); public static final ListTableColumn COL_NAME = new ListTableColumn("Name"); public static final ListTableColumn COL_OS = new ListTableColumn("OS", Integer.class, Sorters.osNameById); public static final ListTableColumn COL_OWNER = new ListTableColumn("Besitzer", Sorters.userNameById); public static final ListTableColumn COL_UPLOADER = new ListTableColumn("Hochgeladen von", Sorters.userNameById); public static final ListTableColumn COL_ORG = new ListTableColumn("Organisation"); public ImagePublishedTable() { super(new Comparator() { @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_UPLOADER, COL_ORG); //, COL_LASTCHANGE, COL_SIZE, COL_USABLE, COL_TEMPLATE); } // 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_UPLOADER) return row.getUploaderId(); if (column == COL_ORG) { UserInfo user = UserCache.find(row.getOwnerId()); if (user != null) return user.getOrganizationId(); return null; } throw new IndexOutOfBoundsException(); } @Override public Object modelValueToDisplayFormat(Object value, ListTableColumn column) { if (column == COL_NAME) return value; if (column == COL_OS) return FormatHelper.osName(MetaDataCache.getOsById((int) value, true)); if (column == COL_OWNER || column == COL_UPLOADER) return FormatHelper.userName(UserCache.find((String) value)); if (column == COL_ORG) { return FormatHelper.orgName(OrganizationCache.find((String) value)); } throw new IndexOutOfBoundsException(); } }