summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-05-29 17:56:36 +0200
committerSimon Rettberg2015-05-29 17:56:36 +0200
commit605857a1ef614964d73ea83e0561d1bfb06e611b (patch)
treeae968412f038b1a53d07bf83ab8f7fdf808750d1 /dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java
parent[server] Added some TODOs (diff)
downloadtutor-module-605857a1ef614964d73ea83e0561d1bfb06e611b.tar.gz
tutor-module-605857a1ef614964d73ea83e0561d1bfb06e611b.tar.xz
tutor-module-605857a1ef614964d73ea83e0561d1bfb06e611b.zip
[client] Compiles again, but is broken....
Diffstat (limited to 'dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java')
-rw-r--r--dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java84
1 files changed, 23 insertions, 61 deletions
diff --git a/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java b/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java
index f92d6a5c..c4b79d0d 100644
--- a/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java
+++ b/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java
@@ -35,10 +35,11 @@ import models.person;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
-import org.openslx.sat.thrift.iface.User;
+import org.openslx.sat.thrift.iface.TransferInformation;
import org.openslx.thrifthelper.ThriftManager;
import util.GuiManager;
+import util.MessageType;
import util.OpenLinks;
import config.Config;
import ftp.DownloadTask;
@@ -52,11 +53,8 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC
private final JPanel contentPanel = new JPanel();
private JLabel lblPath;
private JLabel lblDownSpeed;
- private User user;
private JProgressBar progressBar;
private String host = SessionData.serverAdress;
- private int port = 21;
- private String downloadFile = "";
private DownloadTask task;
private JLabel lblFertig;
private JLabel lblFilesize;
@@ -73,9 +71,8 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC
private JButton btnMainMenu = new JButton("Hauptmenü");
private JButton btnDownloadStoppen = new JButton("Download abbrechen");
private JLabel lblAnleitung;
- private boolean isCurrentlyLoading = false; // currently up or downloading
- // file
private boolean isAborted = false; // down- or upload was manually aborted
+ private TransferInformation transferInfo = null;
public static final String HELP_MESSAGE = "<html><div align=\"center\">"
+ "Hier können Sie Images herunterladen.<br />"
+ "Klicken Sie anschließend auf \"Zurück\" oder \"Hauptmenü\", um zu Ihrer vorherigen Auswahl oder zum Menü zurückzugelangen.<br />"
@@ -92,32 +89,18 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC
public void internalFrameClosing(InternalFrameEvent arg0) {
if (taskrun == true) {
// check if user wants to quit.
- int choice = JOptionPane
- .showOptionDialog(
- null,
- "Aktuell ist ein Download aktiv. Wollen Sie diesen Abbrechen und das Programm beenden?",
- "Upload aktiv", JOptionPane.YES_NO_CANCEL_OPTION,
- JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
+ int choice = JOptionPane.showOptionDialog(
+ null,
+ "Aktuell ist ein Download aktiv. Wollen Sie diesen Abbrechen und das Programm beenden?",
+ "Upload aktiv", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
+ null, options, options[1]);
// 0=beenden, 1=abbrechen
if (choice == 0) {
try {
- ThriftManager.getSatClient().DeleteFtpUser(user.userName, SessionData.authToken);
- try {
- ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken);
- } catch (TException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- try {
- ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken);
- } catch (TException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
+ ThriftManager.getSatClient().cancelDownload(transferInfo.token);
+ ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken);
} catch (TException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
}
task.cancel(true);
@@ -324,11 +307,8 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC
isAborted = true; // set flag
try {
- ThriftManager.getSatClient().DeleteFtpUser(user.userName, SessionData.authToken);
- LOGGER.info("Deleted FTP user.");
+ ThriftManager.getSatClient().cancelDownload(transferInfo.token);
} catch (TException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
}
task.cancel(true);
resetValues();
@@ -360,11 +340,8 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC
if (choice == 0) {
task.cancel(true);
try {
- ThriftManager.getSatClient().DeleteFtpUser(user.userName,
- SessionData.authToken);
+ ThriftManager.getSatClient().cancelDownload(transferInfo.token);
} catch (TException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
}
// go back one page
GuiManager.show(new SearchImage_GUI());
@@ -401,26 +378,18 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC
isAborted = false;
progressBar.setValue(0);
- btnDownloadStarten.setEnabled(false); // verhindert schnellen zweiten
- // Klick
+ btnDownloadStarten.setEnabled(false); // verhindert schnellen zweiten Klick
btnDownloadStarten.setText("Bitte warten");
try {
- user = ThriftManager.getSatClient().getFtpUser(SessionData.authToken);
-
- downloadFile = user.path
- + "/"
- + ThriftManager.getSatClient().getPathOfImage(Image.ImageId,
- Image.Version, SessionData.authToken);
-
+ transferInfo = ThriftManager.getSatClient().requestDownload(SessionData.authToken, Image.ImageId);
} catch (TException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- JOptionPane.showMessageDialog(null, e.getCause() + "\n" + e.getStackTrace(), "Debug-Message",
- JOptionPane.ERROR_MESSAGE);
+ transferInfo = null;
+ GuiManager.showMessageBox("Satellit verweigert den Download", MessageType.ERROR, LOGGER, e);
+ return;
}
- task = new DownloadTask(host, port, user.userName, user.password, downloadFile, lblPath.getText()
- .trim());
+ task = new DownloadTask(host, transferInfo.plainPort, transferInfo.token, lblPath.getText(),
+ Image.Filesize);
task.addPropertyChangeListener(this);
task.execute();
taskrun = true;
@@ -462,8 +431,8 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC
lblFertig.setText((bytesread / 1024 / 1024) + " MB");
lblVerbleibend.setText(((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) + " MB");
- lblZeit.setText(String
- .valueOf(((((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60) + 1)
+ lblZeit.setText(String.valueOf(
+ ((((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60) + 1)
.substring(
0,
String.valueOf(
@@ -480,15 +449,8 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyC
}// end if
}// end propertyChange
- public boolean isCurrentlyLoading() {
- isCurrentlyLoading = false;
-
- if (lblVerbleibend.getText().trim().equals("0 MB") || lblVerbleibend.getText().trim().equals("0")) {
- isCurrentlyLoading = false;
- } else {
- isCurrentlyLoading = true;
- }
- return isCurrentlyLoading;
+ private boolean isCurrentlyLoading() {
+ return task != null && !task.isDone();
}// end isCurrentlyLoading()
public void resetValues() {