diff options
| author | Jonathan Bauer | 2015-08-17 16:10:52 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2015-08-17 16:10:52 +0200 |
| commit | ed54aa15d8229df1ebc113c62a070bb519d6318b (patch) | |
| tree | a93f1083837c52dd2f1c4faeff9625393bd537e5 /dozentenmodul/src/main/java | |
| parent | Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff) | |
| parent | [client] Now also correctly sorting lecture list. (diff) | |
| download | tutor-module-ed54aa15d8229df1ebc113c62a070bb519d6318b.tar.gz tutor-module-ed54aa15d8229df1ebc113c62a070bb519d6318b.tar.xz tutor-module-ed54aa15d8229df1ebc113c62a070bb519d6318b.zip | |
Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1
Diffstat (limited to 'dozentenmodul/src/main/java')
3 files changed, 68 insertions, 46 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java index a7a32fc6..302f0fba 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java @@ -14,10 +14,10 @@ import org.openslx.dozmod.util.FormatHelper; public class ImageTable extends ListTable<ImageSummaryRead> { private static String[] columnNames = { "Name", "OS", "Besitzer", "Letztes Update", "Größe", "Version", - "Vorlage" }; + "Vorlage" }; private static Class<?>[] columnClasses = { String.class, String.class, String.class, String.class, - String.class, String.class, Boolean.class }; + String.class, String.class, Boolean.class }; public ImageTable() { super(columnNames, columnClasses, new Comparator<ImageSummaryRead>() { @@ -32,35 +32,33 @@ public class ImageTable extends ListTable<ImageSummaryRead> { return o1.imageBaseId.compareTo(o2.imageBaseId); } }); - - this.setDefaultRenderer(Object.class, new ImageTableRenderer()); + this.setDefaultRenderer(Object.class, new ImageTableRenderer()); // --------- set comparators for different columns ------------------------------ - // first column doesn't have to be set, because standart comparator already compares strings - // second column, compares the os + // first column doesn't have to be set, because standard comparator already compares strings + // second column, compares the OS getRowSorter().setComparator(1, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { - String os1 = FormatHelper.osName(MetaDataCache.getOsById(o1)); - String os2 = FormatHelper.osName(MetaDataCache.getOsById(o2)); - return os1.compareTo(os2); + String os1 = FormatHelper.osName(MetaDataCache.getOsById(o1)); + String os2 = FormatHelper.osName(MetaDataCache.getOsById(o2)); + return os1.compareTo(os2); } }); // third column compares the owner getRowSorter().setComparator(2, new Comparator<String>() { @Override public int compare(String o1, String o2) { - String user1 = FormatHelper.userName(UserCache.find(o1)); - String user2 = FormatHelper.userName(UserCache.find(o2)); - return user1.compareTo(user2); + String user1 = FormatHelper.userName(UserCache.find(o1)); + String user2 = FormatHelper.userName(UserCache.find(o2)); + return user1.compareTo(user2); } }); - // fourth and fifth column are both longs (last update and size), so they can use same comparator Comparator<Long> longCmparator = new Comparator<Long>() { @Override public int compare(Long o1, Long o2) { - return o1.compareTo(o2); + return o1.compareTo(o2); } }; getRowSorter().setComparator(3, longCmparator); @@ -70,7 +68,7 @@ public class ImageTable extends ListTable<ImageSummaryRead> { getRowSorter().setComparator(6, new Comparator<Boolean>() { @Override public int compare(Boolean o1, Boolean o2) { - return o1.compareTo(o2); + return o1.compareTo(o2); } }); // --------- end of comparators ------------------------------------------------- @@ -119,7 +117,7 @@ class ImageTableRenderer extends TableRenderer { value = value == null ? "-" : value; if( column > 6 || column < 0) throw new IndexOutOfBoundsException(); - + super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); return this; } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureTable.java index 9e8e9d42..c5ec11e7 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureTable.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureTable.java @@ -1,22 +1,46 @@ package org.openslx.dozmod.gui.control.table; +import java.awt.Component; +import java.util.Comparator; + +import javax.swing.JTable; + import org.openslx.bwlp.thrift.iface.LectureSummary; import org.openslx.dozmod.thrift.UserCache; import org.openslx.dozmod.util.FormatHelper; @SuppressWarnings("serial") public class LectureTable extends ListTable<LectureSummary> { - + private static String[] columnNames = { "Name", "Besitzer", "Startzeit", "Endzeit" }; private static Class<?>[] columnClasses = { String.class, String.class, String.class, String.class }; - + public LectureTable() { super(columnNames, columnClasses); - - // sort with correct time and not lexicographic - getRowSorter().setComparator(2, timeComparator); - getRowSorter().setComparator(3, timeComparator); + this.setDefaultRenderer(Object.class, new LectureTableRenderer()); + + // --------- set comparators for different columns ------------------------------ + // first column doesn't have to be set, because standard comparator already compares strings + // second column compares the owner + getRowSorter().setComparator(1, new Comparator<String>() { + @Override + public int compare(String o1, String o2) { + String user1 = FormatHelper.userName(UserCache.find(o1)); + String user2 = FormatHelper.userName(UserCache.find(o2)); + return user1.compareTo(user2); + } + }); + // third and fourth column are both longs (last update and size), so they can use same comparator + Comparator<Long> longCmparator = new Comparator<Long>() { + @Override + public int compare(Long o1, Long o2) { + return o1.compareTo(o2); + } + }; + getRowSorter().setComparator(2, longCmparator); + getRowSorter().setComparator(3, longCmparator); + // --------- end of comparators ------------------------------------------------- } @Override @@ -25,12 +49,33 @@ public class LectureTable extends ListTable<LectureSummary> { if (columnIndex == 0) return row.getLectureName(); if (columnIndex == 1) - return FormatHelper.userName(UserCache.find(row.getOwnerId())); + return row.getOwnerId(); if (columnIndex == 2) - return FormatHelper.longDate(row.getStartTime()); + return row.getStartTime(); if (columnIndex == 3) - return FormatHelper.longDate(row.getEndTime()); + return row.getEndTime(); throw new IndexOutOfBoundsException(); } +} +/** + * This renderer formats the given value to a readable string for the table cell, depending on the column + */ +@SuppressWarnings("serial") +class LectureTableRenderer extends TableRenderer { + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, + boolean hasFocus, int row, int column) { + if (column == 1) + value = FormatHelper.userName(UserCache.find((String) value)); + if (column == 2) + value = FormatHelper.longDate((Long) value); + if (column == 3) + value = FormatHelper.longDate((Long) value); + if( column > 3 || column < 0) + throw new IndexOutOfBoundsException(); + + super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + return this; + } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java index 09bf1e00..a23a52ef 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java @@ -1,12 +1,8 @@ package org.openslx.dozmod.gui.control.table; import java.awt.Component; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Comparator; -import java.util.Date; import java.util.List; import javax.swing.JTable; @@ -33,8 +29,6 @@ public abstract class ListTable<T> extends JTable { private final TableColumnAdjuster adjuster; - protected final Comparator<Object> timeComparator; - private final Comparator<T> itemComparator; public ListTable(String[] columnNames) { @@ -68,21 +62,6 @@ public abstract class ListTable<T> extends JTable { this.setRowSelectionAllowed(true); this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - // for sorting time columns according to time and not lexicographic - timeComparator = new Comparator<Object>() { - @Override - public int compare(Object o1, Object o2) { - DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); - try { - Date date1 = df.parse((String) o1); - Date date2 = df.parse((String) o2); - return date1.compareTo(date2); - } catch (ParseException e) { - LOGGER.error("Couldn't compare dates to sort table rows: ", e); - } - return 0; - } - }; } protected abstract Object getValueAtInternal(int rowIndex, int columnIndex); |
