diff options
author | Simon Rettberg | 2015-10-02 15:59:17 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-10-02 15:59:17 +0200 |
commit | a3f643c4544a986dc4e808ada28089b0dbab9846 (patch) | |
tree | 0e27ef775d13b96dfb2351950f06d84e1e0da52b /dozentenmodul/src/main/java/org/openslx/dozmod | |
parent | [server] Tweaks/fixes to file transfers (diff) | |
download | tutor-module-a3f643c4544a986dc4e808ada28089b0dbab9846.tar.gz tutor-module-a3f643c4544a986dc4e808ada28089b0dbab9846.tar.xz tutor-module-a3f643c4544a986dc4e808ada28089b0dbab9846.zip |
[client] Fix several issues with the new upload scheme
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod')
8 files changed, 109 insertions, 55 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java index 83fbb212..a05ab370 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java @@ -179,7 +179,7 @@ public class AsyncHashGenerator extends Thread { */ private boolean submitHashes() { synchronized (blockHashes) { - if (uploadToken == null) // No token yet, cannot submit + if (uploadToken == null || blockHashes.isEmpty()) // No token yet, cannot submit, or empty list return true; try { ThriftManager.getSatClient().updateBlockHashes(uploadToken, blockHashes); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/TransferTask.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/TransferTask.java index 056e5f71..dbc42b16 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/TransferTask.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/TransferTask.java @@ -53,12 +53,14 @@ public abstract class TransferTask implements Runnable { while (!isCancelled && !Thread.interrupted()) { TransferEvent event = getTransferEvent(); if (event != null) { - fireEvent(event); - if (event.state == TransferState.ERROR) { - break; - } if (event.state == TransferState.FINISHED) { isComplete = true; + } + if (event.state == TransferState.ERROR) { + isCancelled = true; + } + fireEvent(event); + if (event.state == TransferState.ERROR || event.state == TransferState.FINISHED) { break; } } @@ -96,8 +98,8 @@ public abstract class TransferTask implements Runnable { private void fireEvent(TransferEvent event) { synchronized (listeners) { - for (TransferEventListener listener : listeners) { - listener.update(event); + for (int i = listeners.size() - 1; i >= 0; --i) { + listeners.get(i).update(event); } } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java index 04f6c14a..a80cf2b9 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java @@ -10,6 +10,7 @@ import java.awt.geom.Rectangle2D; import javax.swing.JPanel; +import org.openslx.dozmod.gui.Gui; import org.openslx.thrifthelper.TransferStatusWrapper; @SuppressWarnings("serial") @@ -23,6 +24,7 @@ public class BlockProgressBar extends JPanel { public BlockProgressBar(byte[] blocks) { super(); + setPreferredSize(Gui.getScaledDimension(100, 32)); setupListeners(); // 0 = complete, 1 = missing, 2 = uploading, 3 = queued for copying, 4 = copying, 5 = hashing blockColors[0] = Color.BLACK; @@ -77,7 +79,7 @@ public class BlockProgressBar extends JPanel { final int width = getWidth(); final int height = getHeight(); final float complete = blocks.getComplete(); - final int doneWidth = (int)((float)width * complete); + final int doneWidth = (int) ((float) width * complete); g.setColor(Color.BLUE); g.fillRect(0, 0, doneWidth, height); g.setColor(Color.WHITE); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageUpdateWizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageUpdateWizard.java index dc526f12..2c2b0b3b 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageUpdateWizard.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageUpdateWizard.java @@ -13,7 +13,6 @@ import org.openslx.dozmod.gui.wizard.page.ImageUploadPage; import org.openslx.dozmod.gui.wizard.page.ImageUploadSummaryPage; import org.openslx.dozmod.state.UploadWizardState; import org.openslx.dozmod.thrift.ThriftActions; -import org.openslx.dozmod.thrift.ThriftError; import org.openslx.dozmod.thrift.UploadInitiator.GotUploadTokenCallback; import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; @@ -35,29 +34,29 @@ public class ImageUpdateWizard extends Wizard implements UiFeedback { @Override protected boolean wantFinish() { - try { - ThriftActions.updateImageVersion(state.upload.getToken(), new ImageVersionWrite( - state.isRestricted)); - } catch (TException e) { - ThriftError.showMessage(null, LOGGER, e, "Serverseitiger Fehler beim Speichern der Image-Daten."); - return false; - } - state.upload.startUpload(new GotUploadTokenCallback() { + QuickTimer.scheduleOnce(new Task() { @Override public void fire() { - // push version data - try { - ThriftActions.updateImageVersion(state.upload.getToken(), new ImageVersionWrite( - state.isRestricted)); - } catch (TException e) { - if (state.isRestricted) { - Gui.showMessageBox(null, "Unerwarteter Fehler beim Setzen der Option" - + " 'Enthält lizenzpflichtige Software' für diese Virtuelle Maschine.", - MessageType.WARNING, LOGGER, e); + state.upload.startUpload(new GotUploadTokenCallback() { + @Override + public void fire() { + // push version data + try { + ThriftActions.updateImageVersion(state.upload.getToken(), new ImageVersionWrite( + state.isRestricted)); + } catch (TException e) { + if (state.isRestricted) { + Gui.showMessageBox( + null, + "Unerwarteter Fehler beim Setzen der Option" + + " 'Enthält lizenzpflichtige Software' für diese Virtuelle Maschine.", + MessageType.WARNING, LOGGER, e); + } + } } - } + }); } - }); + }, 500); return true; } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/Wizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/Wizard.java index ebf82642..72a7618c 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/Wizard.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/Wizard.java @@ -4,17 +4,23 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; +import java.awt.Graphics2D; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.awt.image.BufferedImage; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.Icon; +import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; @@ -37,6 +43,7 @@ public abstract class Wizard extends JDialog { private final JPanel contentPanel; private int currentPage = -1; private boolean needsLayout = true; + private boolean isCancelled = false; private final JButton btnPrev; private final JButton btnNext; @@ -170,12 +177,36 @@ public abstract class Wizard extends JDialog { pageDesc = ""; titleLabel.setText(pageTitle); messageLabel.setText(pageDesc); - messageLabel.setIcon(page.getMessageIcon()); // TODO: Scale + messageLabel.setIcon(getScaledIcon(page.getMessageIcon())); messageLabel.setForeground(page.getMessageColor()); messageLabel.validate(); setTitle(getWindowTitle() + " - " + pageTitle); } + private static final Map<Icon, ImageIcon> iconCache = new HashMap<>(); + + private Icon getScaledIcon(Icon icon) { + if (icon == null) + return null; + ImageIcon cached = iconCache.get(icon); + if (cached != null && cached.getIconHeight() == messageLabel.getHeight()) + return cached; + // Generate? + float iHeight = icon.getIconHeight(); + float tHeight = messageLabel.getHeight(); + if (iHeight <= tHeight) + return icon; // Small enough + // Scale down: + BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), + BufferedImage.TYPE_INT_ARGB_PRE); + Graphics2D g = image.createGraphics(); + icon.paintIcon(messageLabel, g, 0, 0); + ImageIcon scaledIcon = new ImageIcon(image.getScaledInstance( + (int) (icon.getIconWidth() * (tHeight / iHeight)), (int) (tHeight), 0)); + iconCache.put(icon, scaledIcon); + return scaledIcon; + } + public abstract String getWindowTitle(); protected final void addPage(WizardPage page) { @@ -211,10 +242,25 @@ public abstract class Wizard extends JDialog { } } + /** + * Returns whether the page currently shown is the summary page. + * + * @return whether the page currently shown is the summary page. + */ protected final boolean isSummaryPage() { return isPostFinish; } + /** + * Returns true if the wizard was cancelled. Mostly useful in onPageLeave to + * distinguish what's happening. + * + * @return true if the wizard was cancelled. + */ + public final boolean isCancelled() { + return isCancelled; + } + protected final void doNext() { if (isPostFinish || !btnNext.isEnabled()) return; @@ -235,6 +281,7 @@ public abstract class Wizard extends JDialog { protected final void doCancel() { if (onCancelRequest()) { + isCancelled = true; if (currentPage != -1) { getPage(currentPage).onPageLeave(); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/WizardPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/WizardPage.java index 9c5044f4..fc1da67f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/WizardPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/WizardPage.java @@ -22,7 +22,7 @@ public abstract class WizardPage extends JPanel { private boolean isComplete = false; - private final Wizard wizard; + protected final Wizard wizard; /** * Whether the user is allowed to go back to this page once they clicked diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageUploadSummaryPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageUploadSummaryPageLayout.java index 930d5e16..1fecf841 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageUploadSummaryPageLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageUploadSummaryPageLayout.java @@ -22,12 +22,13 @@ public class ImageUploadSummaryPageLayout extends WizardPage { GridManager grid = new GridManager(this, 1); progressBar = new BlockProgressBar(null); + progressBar.setMinimumSize(progressBar.getPreferredSize()); grid.add(progressBar).expand(true, false).fill(true, false); grid.nextRow(); - + grid.add(Box.createVerticalStrut(16)); grid.nextRow(); - + infoText = new JLabel(); grid.add(infoText).expand(true, false).fill(true, false); grid.nextRow(); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadSummaryPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadSummaryPage.java index 8c7d653d..ef96d234 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadSummaryPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadSummaryPage.java @@ -29,10 +29,10 @@ public class ImageUploadSummaryPage extends ImageUploadSummaryPageLayout { return; if (event.progress != null) { progressBar.setStatus(event.progress); - if (event.state == TransferState.FINISHED) { - updateInfoText(null); - state.upload.getUploadTask().removeListener(uploadListener); - } + } + if (event.state == TransferState.FINISHED) { + updateInfoText(null); + state.upload.getUploadTask().removeListener(uploadListener); } } }; @@ -70,31 +70,31 @@ public class ImageUploadSummaryPage extends ImageUploadSummaryPageLayout { return; } else { switch (initState) { - case ERROR: - text = "Die Initialisierung des Uploads auf den Server ist fehlgeschlagen." - + " Sie können versuchen, den Vorgang erneut zu starten." - + " Falls das Problem weiterhin besteht," - + " kontaktieren Sie den bwLehrpool-Support Ihrer Einrichtung."; - if (state.upload.getErrorMessage() != null) { - text += "<br><br>Weitere Informationen:<br>" + state.upload.getErrorMessage(); - } - break; case REQUESTING: text = "Der Upload-Vorgang wird mit dem Server ausgehandelt..."; break; + case WAITING_FOR_SLOT: + text = "Der Server ist zur Zeit überlastet, da zu viele Uploads gleichzeitig laufen." + + " Es wird gewartet, bis der Server wieder Kapazitäten frei hat." + + " Bitte schließen Sie dieses Fenster nicht."; + break; + case UPLOAD_STARTING: + text = "Die Verbindung zur Übertragung der VM wird aufgebaut..."; + break; case UPLOAD_STARTED: text = "Der Upload Ihrer Virtuellen Maschine wurde gestartet." + " Wenn Sie möchten, können Sie diesen Assistenten schließen," + " und die Anwendung weiterverwenden." + " Die Übertragung läuft dabei im Hintergrund weiter."; break; - case UPLOAD_STARTING: - text = "Die Verbindung zur Übertragung der VM wird aufgebaut..."; - break; - case WAITING_FOR_SLOT: - text = "Der Server ist zur Zeit überlastet, da zu viele Uploads gleichzeitig laufen." - + " Es wird gewartet, bis der Server wieder Kapazitäten frei hat." - + " Bitte schließen Sie dieses Fenster nicht."; + case ERROR: + text = "Die Initialisierung des Uploads auf den Server ist fehlgeschlagen." + + " Sie können versuchen, den Vorgang erneut zu starten." + + " Falls das Problem weiterhin besteht," + + " kontaktieren Sie den bwLehrpool-Support Ihrer Einrichtung."; + if (state.upload.getErrorMessage() != null) { + text += "<br><br>Weitere Informationen:<br>" + state.upload.getErrorMessage(); + } break; default: return; @@ -105,7 +105,9 @@ public class ImageUploadSummaryPage extends ImageUploadSummaryPageLayout { @Override public void run() { infoText.setText("<html><body style ='width:100%'>" + t + "</body></html>"); - setPageComplete(initState == UploadInitState.UPLOAD_STARTED); + if (initState == UploadInitState.UPLOAD_STARTED) { + setPageComplete(true); + } } }); } @@ -121,7 +123,8 @@ public class ImageUploadSummaryPage extends ImageUploadSummaryPageLayout { if (pageIsVisible) return; pageIsVisible = true; - QuickTimer.scheduleAtFixedDelay(updateHelpText, 1, 3000); + updateInfoText(UploadInitState.REQUESTING); + QuickTimer.scheduleAtFixedDelay(updateHelpText, 500, 3000); } @Override @@ -130,7 +133,7 @@ public class ImageUploadSummaryPage extends ImageUploadSummaryPageLayout { return; pageIsVisible = false; state.upload.getUploadTask().removeListener(uploadListener); - if (!state.upload.getUploadTask().isCanceled()) { + if (!wizard.isCancelled() && !state.upload.getUploadTask().isCanceled()) { MainWindow.addUpload(state); } } |