summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-04-29 12:05:43 +0200
committerSimon Rettberg2019-04-29 12:05:43 +0200
commitc92c01893c7553410dd29420aca8267b8a1d48ed (patch)
tree9a1444edcee2b54fda0368fe75b029d4649b4f8e
parent[server] Reword log message (diff)
downloadtutor-module-c92c01893c7553410dd29420aca8267b8a1d48ed.tar.gz
tutor-module-c92c01893c7553410dd29420aca8267b8a1d48ed.tar.xz
tutor-module-c92c01893c7553410dd29420aca8267b8a1d48ed.zip
[client] Cancel transfers when exiting app
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java12
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java39
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/DownloadPanel.java8
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UploadPanel.java9
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/QuitNotification.java7
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java10
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageUpdateWizard.java10
7 files changed, 84 insertions, 11 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java
index 29f74459..1407204d 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java
@@ -15,6 +15,7 @@ import org.openslx.filetransfer.Transfer;
import org.openslx.filetransfer.WantRangeCallback;
import org.openslx.filetransfer.util.ChunkList;
import org.openslx.filetransfer.util.FileChunk;
+import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.Util;
/**
@@ -154,6 +155,17 @@ public class DownloadTask extends TransferTask {
}
}
+
+ @Override
+ public void cancel() {
+ super.cancel();
+ if (downloadToken != null) {
+ try {
+ ThriftManager.getSatClient().cancelDownload(downloadToken);
+ } catch (Exception e) {
+ }
+ }
+ }
@Override
protected void cleanup() {
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
index 11b02f58..70270ff0 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
@@ -1,6 +1,8 @@
package org.openslx.dozmod.gui;
import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.Window;
@@ -50,6 +52,7 @@ import org.openslx.dozmod.gui.helper.CompositePage;
import org.openslx.dozmod.gui.helper.DebugWindow;
import org.openslx.dozmod.gui.helper.GridManager;
import org.openslx.dozmod.gui.helper.MessageType;
+import org.openslx.dozmod.gui.helper.QuitNotification;
import org.openslx.dozmod.gui.helper.UiFeedback;
import org.openslx.dozmod.gui.window.CheckUpdateWindow;
import org.openslx.dozmod.gui.window.ConfigWindow;
@@ -65,9 +68,9 @@ import org.openslx.dozmod.thrift.GuiErrorCallback;
import org.openslx.dozmod.thrift.Session;
import org.openslx.dozmod.thrift.ThriftActions;
import org.openslx.dozmod.util.ClientVersion;
-import org.openslx.dozmod.util.FormatHelper;
import org.openslx.dozmod.util.DesktopEnvironment;
import org.openslx.dozmod.util.DesktopEnvironment.Link;
+import org.openslx.dozmod.util.FormatHelper;
import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
@@ -303,30 +306,52 @@ public abstract class MainWindow {
* confirmation.
*/
protected static void askApplicationQuit() {
- boolean open = false;
+ boolean keepOpen = false;
for (ActivityPanel activity : activities) {
if (activity.wantConfirmQuit()) {
- open = true;
+ keepOpen = true;
break;
}
}
- if (!open) {
- Window[] windows = Window.getWindows();
+ Window[] windows = null;
+ if (!keepOpen) {
+ windows = Window.getWindows();
for (Window window : windows) {
if (window.isVisible() && window instanceof UiFeedback
&& ((UiFeedback) window).wantConfirmQuit()) {
- open = true;
+ keepOpen = true;
break;
}
}
}
- if (!open
+ if (!keepOpen
|| Gui.showMessageBox(mainWindow, "Möchten Sie das Programm wirklich beenden?",
MessageType.QUESTION_YESNO, null, null)) {
+ if (windows == null) {
+ windows = Window.getWindows();
+ }
+ for (Window window : windows) {
+ sendQuitEvent(window);
+ }
Gui.exit(0);
}
isQuitQuestionOpen = false;
}
+
+ private static void sendQuitEvent(Container c) {
+ if (c instanceof QuitNotification) {
+ ((QuitNotification) c).onApplicationQuit();
+ }
+ Component[] components;
+ synchronized (c.getTreeLock()) {
+ components = c.getComponents();
+ }
+ for (Component component : components) {
+ if (component instanceof Container) {
+ sendQuitEvent((Container) component);
+ }
+ }
+ }
/**
* Register a page that can be displayed in the main window.
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/DownloadPanel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/DownloadPanel.java
index adf1554d..a9631097 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/DownloadPanel.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/DownloadPanel.java
@@ -10,10 +10,11 @@ import org.openslx.dozmod.filetransfer.DownloadTask;
import org.openslx.dozmod.filetransfer.TransferEvent;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.MessageType;
+import org.openslx.dozmod.gui.helper.QuitNotification;
import org.openslx.dozmod.util.DesktopEnvironment;
@SuppressWarnings("serial")
-public class DownloadPanel extends TransferPanel implements ActionListener {
+public class DownloadPanel extends TransferPanel implements ActionListener, QuitNotification {
private final DownloadPanel panel = this;
@@ -56,4 +57,9 @@ public class DownloadPanel extends TransferPanel implements ActionListener {
}
}
+ @Override
+ public void onApplicationQuit() {
+ download.cancel();
+ }
+
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UploadPanel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UploadPanel.java
index df396b55..bc24758a 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UploadPanel.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UploadPanel.java
@@ -14,6 +14,7 @@ import org.openslx.bwlp.thrift.iface.TInvalidTokenException;
import org.openslx.bwlp.thrift.iface.UploadOptions;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.MessageType;
+import org.openslx.dozmod.gui.helper.QuitNotification;
import org.openslx.dozmod.state.UploadWizardState;
import org.openslx.dozmod.thrift.Session;
import org.openslx.dozmod.thrift.UploadInitiator;
@@ -23,7 +24,7 @@ import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
@SuppressWarnings("serial")
-public class UploadPanel extends TransferPanel {
+public class UploadPanel extends TransferPanel implements QuitNotification {
private static final Logger LOGGER = Logger.getLogger(UploadPanel.class);
@@ -106,4 +107,10 @@ public class UploadPanel extends TransferPanel {
});
}
}
+
+ @Override
+ public void onApplicationQuit() {
+ // Application quit, tell server we cancel
+ state.cancelError();
+ }
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/QuitNotification.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/QuitNotification.java
new file mode 100644
index 00000000..50ce1745
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/QuitNotification.java
@@ -0,0 +1,7 @@
+package org.openslx.dozmod.gui.helper;
+
+public interface QuitNotification {
+
+ public void onApplicationQuit();
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java
index 82e0d53e..845c4e3f 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageCreationWizard.java
@@ -10,6 +10,7 @@ import org.openslx.bwlp.thrift.iface.ImageBaseWrite;
import org.openslx.bwlp.thrift.iface.ImageVersionWrite;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.MessageType;
+import org.openslx.dozmod.gui.helper.QuitNotification;
import org.openslx.dozmod.gui.helper.UiFeedback;
import org.openslx.dozmod.gui.wizard.page.ImageCustomPermissionPage;
import org.openslx.dozmod.gui.wizard.page.ImageMetaDataPage;
@@ -25,7 +26,7 @@ import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
@SuppressWarnings("serial")
-public class ImageCreationWizard extends Wizard implements UiFeedback {
+public class ImageCreationWizard extends Wizard implements UiFeedback, QuitNotification {
private final static Logger LOGGER = Logger.getLogger(ImageCreationWizard.class);
@@ -222,4 +223,11 @@ public class ImageCreationWizard extends Wizard implements UiFeedback {
public void escapePressed() {
doCancel();
}
+
+ @Override
+ public void onApplicationQuit() {
+ if (state != null && state.upload != null) {
+ state.upload.cancelError();
+ }
+ }
}
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 2f2d73d0..b7f5370c 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
@@ -8,6 +8,7 @@ import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.bwlp.thrift.iface.ImageVersionWrite;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.MessageType;
+import org.openslx.dozmod.gui.helper.QuitNotification;
import org.openslx.dozmod.gui.helper.UiFeedback;
import org.openslx.dozmod.gui.wizard.page.ImageUploadPage;
import org.openslx.dozmod.gui.wizard.page.ImageUploadSummaryPage;
@@ -18,7 +19,7 @@ import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
@SuppressWarnings("serial")
-public class ImageUpdateWizard extends Wizard implements UiFeedback {
+public class ImageUpdateWizard extends Wizard implements UiFeedback, QuitNotification {
private final static Logger LOGGER = Logger.getLogger(ImageCreationWizard.class);
private final UploadWizardState state = new UploadWizardState();
@@ -97,4 +98,11 @@ public class ImageUpdateWizard extends Wizard implements UiFeedback {
return "Neue VM-Version";
}
+ @Override
+ public void onApplicationQuit() {
+ if (state != null && state.upload != null) {
+ state.upload.cancelError();
+ }
+ }
+
}