summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2015-08-19 16:40:43 +0200
committerJonathan Bauer2015-08-19 16:40:43 +0200
commitb58efadff5ff441c1869adeebb28b5f37cfabadb (patch)
treea89a89a3835d9726da6c0fdf7ada6ba06b0bc14f
parent[client] refactored TransferHelper to ThriftActions (diff)
parent[client] Clean up sorting logic of image and lecture table (diff)
downloadtutor-module-b58efadff5ff441c1869adeebb28b5f37cfabadb.tar.gz
tutor-module-b58efadff5ff441c1869adeebb28b5f37cfabadb.tar.xz
tutor-module-b58efadff5ff441c1869adeebb28b5f37cfabadb.zip
Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1
-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/gui/window/ImageListWindow.java66
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java20
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Sorters.java51
5 files changed, 127 insertions, 85 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/gui/window/ImageListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
index d06c6717..8265f701 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
@@ -3,6 +3,8 @@ package org.openslx.dozmod.gui.window;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
@@ -41,7 +43,7 @@ import org.openslx.util.QuickTimer.Task;
/**
*
* @author Jonathan Bauer
- *
+ *
*/
@SuppressWarnings("serial")
public class ImageListWindow extends ImageListWindowLayout implements DownloadCallback {
@@ -107,7 +109,7 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
performImageDownload(imageTable.getSelectedItem());
}
if (e.getSource().equals(popupItemDelete)) {
-
+
}
}
});
@@ -129,6 +131,15 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
}
});
+ imageTable.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if (e.getKeyCode() == KeyEvent.VK_F5) {
+ refreshList(true, 1);
+ }
+ }
+ });
+
imageTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -139,7 +150,7 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
ImageDetailsWindow.open((JFrame) SwingUtilities.getWindowAncestor(me),
image.getImageBaseId(), new ImageUpdatedCallback() {
public void updated() {
- refreshList(true);
+ refreshList(true, 100);
}
});
}
@@ -177,7 +188,7 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
@Override
public void actionPerformed(ActionEvent e) {
new ImageWizard(SwingUtilities.getWindowAncestor(me)).setVisible(true);
- refreshList(true);
+ refreshList(true, 100);
}
});
newLectureButton.addActionListener(new ActionListener() {
@@ -209,10 +220,11 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
updateAvailableOptions(null);
}
- /********************************************************************************
+
+ /********************************************************************************
+ *
+ * General GUI and table helpers
*
- * General GUI and table helpers
- *
********************************************************************************/
/**
@@ -220,7 +232,7 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
*
* @param forceRefresh true to force a refresh, false to use the cached list
*/
- private void refreshList(final boolean forceRefresh) {
+ private void refreshList(final boolean forceRefresh, int delay) {
QuickTimer.scheduleOnce(new Task() {
@Override
public void fire() {
@@ -232,12 +244,12 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
}
});
}
- }, 1000);
- // TODO do this periodically with a large interval, say 10s?
+ }, delay);
}
/**
- * Helper to return the selected image from the table or show an error to the user if none is selected
+ * Helper to return the selected image from the table or show an error to
+ * the user if none is selected
*
* @return the image selected in the table, null if there is no selection
*/
@@ -336,10 +348,11 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
popupItemNewLecture.setEnabled(link);
popupItemDelete.setEnabled(admin);
}
- /********************************************************************************
+
+ /********************************************************************************
+ *
+ * Helpers triggering the actual actions
*
- * Helpers triggering the actual actions
- *
********************************************************************************/
/**
@@ -365,15 +378,19 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
ThriftActions.initDownload(JOptionPane.getFrameForComponent(this), image.latestVersionId,
image.imageName, image.virtId, image.fileSize, this);
}
+
/**
- * Callback when download initialized
+ * Callback when download initialized
*
* @param success true if downloading, false otherwise
*/
@Override
public void downloadInitialized(boolean success) {
- refreshList(!success);
+ if (!success) {
+ refreshList(true, 1000);
+ }
}
+
/**
* Deletes the latest version of the given image if it has one
*
@@ -390,6 +407,7 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
QuickTimer.scheduleOnce(new Task() {
boolean success = false;
Exception error = null;
+
@Override
public void fire() {
try {
@@ -410,22 +428,26 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
}
});
}
+
/**
* Async callback when image was deleted
*
- * @param success true if the latest image version was deleted, false otherwise
+ * @param success true if the latest image version was deleted, false
+ * otherwise
*/
public void deletedLatestVersion(boolean success, Exception e) {
if (e != null) {
Gui.showMessageBox(me, "Fehler", MessageType.ERROR, LOGGER, e);
}
- refreshList(success);
+ if (success) {
+ refreshList(true, 1000);
+ }
}
- /********************************************************************************
+ /********************************************************************************
+ *
+ * CompositePage abstract methods implementation
*
- * CompositePage abstract methods implementation
- *
********************************************************************************/
@Override
public boolean requestHide() {
@@ -434,6 +456,6 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
@Override
public void requestShow() {
- refreshList(false);
+ refreshList(false, 1);
}
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java
index 82f1abd5..6d80aecb 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java
@@ -3,6 +3,8 @@ package org.openslx.dozmod.gui.window;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
@@ -25,11 +27,10 @@ import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.window.layout.LectureListWindowLayout;
import org.openslx.dozmod.thrift.Session;
import org.openslx.dozmod.thrift.cache.LectureCache;
-import org.openslx.dozmod.thrift.cache.UserCache;
-import org.openslx.dozmod.util.FormatHelper;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
+@SuppressWarnings("serial")
public class LectureListWindow extends LectureListWindowLayout {
private final static Logger LOGGER = Logger.getLogger(LectureListWindow.class);
@@ -75,6 +76,15 @@ public class LectureListWindow extends LectureListWindowLayout {
}
});
+ lectureTable.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if (e.getKeyCode() == KeyEvent.VK_F5) {
+ refreshList(true);
+ }
+ }
+ });
+
newButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -170,11 +180,11 @@ public class LectureListWindow extends LectureListWindowLayout {
}
}
- private void refreshList() {
+ private void refreshList(final boolean force) {
QuickTimer.scheduleOnce(new Task() {
@Override
public void fire() {
- final List<LectureSummary> lectureList = LectureCache.get(false);
+ final List<LectureSummary> lectureList = LectureCache.get(force);
Gui.asyncExec(new Runnable() {
@Override
public void run() {
@@ -192,7 +202,7 @@ public class LectureListWindow extends LectureListWindowLayout {
@Override
public void requestShow() {
- refreshList();
+ refreshList(false);
}
}
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));
+ }
+ };
+
+}