From 8b48fab82405d9295f8f10ff7ef3db18124aff96 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 19 Aug 2015 14:08:35 +0200 Subject: [client] Delay refresh of image list only for certain events --- .../openslx/dozmod/gui/window/ImageListWindow.java | 55 +++++++++++++--------- 1 file changed, 33 insertions(+), 22 deletions(-) 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 1fc9d1ce..ba5f0cf7 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 @@ -41,7 +41,7 @@ import org.openslx.util.QuickTimer.Task; /** * * @author Jonathan Bauer - * + * */ @SuppressWarnings("serial") public class ImageListWindow extends ImageListWindowLayout implements DownloadCallback { @@ -107,7 +107,7 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa performImageDownload(imageTable.getSelectedItem()); } if (e.getSource().equals(popupItemDelete)) { - + } } }); @@ -139,7 +139,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 +177,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 +209,11 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa updateAvailableOptions(null); } - /******************************************************************************** + + /******************************************************************************** + * + * General GUI and table helpers * - * General GUI and table helpers - * ********************************************************************************/ /** @@ -220,7 +221,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 +233,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 +337,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 +367,19 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa TransferHelper.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 +396,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 +417,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 +445,6 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa @Override public void requestShow() { - refreshList(false); + refreshList(false, 1); } } -- cgit v1.2.3-55-g7522 From 4f8125514ab868074eef71a6cf3cb79738667745 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 19 Aug 2015 14:17:27 +0200 Subject: [client] F5 = refresh in lecture and image list --- .../openslx/dozmod/gui/window/ImageListWindow.java | 11 +++++++++++ .../openslx/dozmod/gui/window/LectureListWindow.java | 20 +++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) 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 ba5f0cf7..82a917eb 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; @@ -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) { 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 lectureList = LectureCache.get(false); + final List 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); } } -- cgit v1.2.3-55-g7522 From e1316b46c190a3e2ad6b1b04ec6fbd103c4d5146 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 19 Aug 2015 15:26:09 +0200 Subject: [client] Clean up sorting logic of image and lecture table --- .../dozmod/gui/control/table/ImageTable.java | 52 ++++++---------------- .../dozmod/gui/control/table/LectureTable.java | 23 ++-------- .../java/org/openslx/dozmod/thrift/Sorters.java | 51 +++++++++++++++++++++ 3 files changed, 68 insertions(+), 58 deletions(-) create mode 100644 dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Sorters.java 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 { 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() { @@ -37,40 +38,12 @@ public class ImageTable extends ListTable { // --------- 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() { - @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() { - @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 longCmparator = new Comparator() { - @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() { - @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 { } /** - * 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 { 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 { // --------- 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() { - @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 longCmparator = new Comparator() { - @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 userName = new Comparator() { + @Override + public int compare(UserInfo o1, UserInfo o2) { + return FormatHelper.userName(o1).compareTo(FormatHelper.userName(o2)); + } + }; + + public static final Comparator userNameById = new Comparator() { + @Override + public int compare(String o1, String o2) { + return userName.compare(UserCache.find(o1), UserCache.find(o2)); + } + }; + + public static final Comparator osName = new Comparator() { + @Override + public int compare(OperatingSystem o1, OperatingSystem o2) { + return FormatHelper.osName(o1).compareTo(FormatHelper.osName(o2)); + } + }; + + public static final Comparator osNameById = new Comparator() { + @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)); + } + }; + +} -- cgit v1.2.3-55-g7522