summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod
diff options
context:
space:
mode:
authorSimon Rettberg2015-08-19 15:26:09 +0200
committerSimon Rettberg2015-08-19 15:26:09 +0200
commite1316b46c190a3e2ad6b1b04ec6fbd103c4d5146 (patch)
tree5cd46e5fc1d1a6e598cc60b0931fc9ef98f6fbeb /dozentenmodul/src/main/java/org/openslx/dozmod
parent[client] F5 = refresh in lecture and image list (diff)
downloadtutor-module-e1316b46c190a3e2ad6b1b04ec6fbd103c4d5146.tar.gz
tutor-module-e1316b46c190a3e2ad6b1b04ec6fbd103c4d5146.tar.xz
tutor-module-e1316b46c190a3e2ad6b1b04ec6fbd103c4d5146.zip
[client] Clean up sorting logic of image and lecture table
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java52
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureTable.java23
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Sorters.java51
3 files changed, 68 insertions, 58 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 4d561cfc..1af86c41 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
@@ -6,6 +6,7 @@ import java.util.Comparator;
import javax.swing.JTable;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
+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;
@@ -14,10 +15,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 };
+ private static Class<?>[] columnClasses = { String.class, String.class, String.class, Long.class,
+ Long.class, String.class, Boolean.class };
public ImageTable() {
super(columnNames, columnClasses, new Comparator<ImageSummaryRead>() {
@@ -37,40 +38,12 @@ public class ImageTable extends ListTable<ImageSummaryRead> {
// --------- set comparators for different columns ------------------------------
// 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);
- }
- });
+ getRowSorter().setComparator(1, Sorters.osNameById);
// 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);
- }
- });
- // 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);
- }
- };
- getRowSorter().setComparator(3, longCmparator);
- getRowSorter().setComparator(4, longCmparator);
+ getRowSorter().setComparator(2, Sorters.userNameById);
+ // fourth and fifth column are both longs (last update and size), use default
// sixth column (version id) is string again, doesn't have to be set
- // seventh column is template
- getRowSorter().setComparator(6, new Comparator<Boolean>() {
- @Override
- public int compare(Boolean o1, Boolean o2) {
- return o1.compareTo(o2);
- }
- });
+ // seventh column is boolean, use deafult
// --------- end of comparators -------------------------------------------------
}
@@ -97,7 +70,8 @@ public class ImageTable extends ListTable<ImageSummaryRead> {
}
/**
- * This renderer formats the given value to a readable string for the table cell, depending on the column
+ * This renderer formats the given value to a readable string for the table
+ * cell, depending on the column
*/
@SuppressWarnings("serial")
class ImageTableRenderer extends TableRenderer {
@@ -108,14 +82,14 @@ class ImageTableRenderer extends TableRenderer {
value = "-";
// column 0, 5 and 6 don't have to be changed ( already string/ checkbox)
if (column == 1)
- value = FormatHelper.osName(MetaDataCache.getOsById((int)value));
+ value = FormatHelper.osName(MetaDataCache.getOsById((int) value));
if (column == 2)
value = FormatHelper.userName(UserCache.find((String) value));
if (column == 3)
- value = FormatHelper.longDate((long) value);
+ value = FormatHelper.shortDate((long) value);
if (column == 4)
value = FormatHelper.bytes((long) value, false);
- if( column > 6 || column < 0)
+ if (column > 6 || column < 0)
throw new IndexOutOfBoundsException();
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
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 32adc2c8..ae29304a 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,11 +1,11 @@
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.Sorters;
import org.openslx.dozmod.thrift.cache.UserCache;
import org.openslx.dozmod.util.FormatHelper;
@@ -13,7 +13,7 @@ import org.openslx.dozmod.util.FormatHelper;
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 };
+ private static Class<?>[] columnClasses = { String.class, String.class, Long.class, Long.class };
public LectureTable() {
@@ -23,23 +23,8 @@ public class LectureTable extends ListTable<LectureSummary> {
// --------- 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);
+ getRowSorter().setComparator(1, Sorters.userNameById);
+ // third and fourth column are both longs (last update and size), use default comparator
// --------- end of comparators -------------------------------------------------
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Sorters.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Sorters.java
new file mode 100644
index 00000000..8a0559f2
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Sorters.java
@@ -0,0 +1,51 @@
+package org.openslx.dozmod.thrift;
+
+import java.util.Comparator;
+
+import org.openslx.bwlp.thrift.iface.OperatingSystem;
+import org.openslx.bwlp.thrift.iface.UserInfo;
+import org.openslx.dozmod.thrift.cache.MetaDataCache;
+import org.openslx.dozmod.thrift.cache.UserCache;
+import org.openslx.dozmod.util.FormatHelper;
+
+/**
+ * Collection of comparators targeted at sorting different objects in a
+ * human-suitable way (e.g. sort users by their display name)
+ */
+public class Sorters {
+
+ public static final Comparator<UserInfo> userName = new Comparator<UserInfo>() {
+ @Override
+ public int compare(UserInfo o1, UserInfo o2) {
+ return FormatHelper.userName(o1).compareTo(FormatHelper.userName(o2));
+ }
+ };
+
+ public static final Comparator<String> userNameById = new Comparator<String>() {
+ @Override
+ public int compare(String o1, String o2) {
+ return userName.compare(UserCache.find(o1), UserCache.find(o2));
+ }
+ };
+
+ public static final Comparator<OperatingSystem> osName = new Comparator<OperatingSystem>() {
+ @Override
+ public int compare(OperatingSystem o1, OperatingSystem o2) {
+ return FormatHelper.osName(o1).compareTo(FormatHelper.osName(o2));
+ }
+ };
+
+ public static final Comparator<Integer> osNameById = new Comparator<Integer>() {
+ @Override
+ public int compare(Integer o1, Integer o2) {
+ if (o1 == null) {
+ o1 = 0;
+ }
+ if (o2 == null) {
+ o2 = 0;
+ }
+ return osName.compare(MetaDataCache.getOsById(o1), MetaDataCache.getOsById(o2));
+ }
+ };
+
+}