From 544a8b733317fdc4e59ce5330c2d4c8cc4ffbba5 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Tue, 26 Aug 2014 09:32:59 +0200 Subject: Alle Abfragen und Abbrüche für während Up/Downloads implementiert --- .../src/gui/image/FTPEditUploader_GUI.java | 105 +++++++++++++-------- 1 file changed, 64 insertions(+), 41 deletions(-) (limited to 'Dozentenmodul/src/gui/image/FTPEditUploader_GUI.java') diff --git a/Dozentenmodul/src/gui/image/FTPEditUploader_GUI.java b/Dozentenmodul/src/gui/image/FTPEditUploader_GUI.java index 12a5d6bb..a58001a8 100644 --- a/Dozentenmodul/src/gui/image/FTPEditUploader_GUI.java +++ b/Dozentenmodul/src/gui/image/FTPEditUploader_GUI.java @@ -88,7 +88,8 @@ public class FTPEditUploader_GUI extends JFrame implements JButton btnSpeicherortAuswhlen = new JButton("Image ausw\u00E4hlen"); JButton finishButton = new JButton("Fertigstellen"); JButton btnZurck = new JButton("Zur\u00FCck"); - private boolean isCurrentlyLoading = false; // currently up or downloading file + private boolean isCurrentlyLoading = false; // currently up or downloading + // file /** * Create the frame. @@ -100,6 +101,7 @@ public class FTPEditUploader_GUI extends JFrame implements addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { + if (taskrun == true) { // check if user wants to quit. int choice = JOptionPane @@ -112,9 +114,7 @@ public class FTPEditUploader_GUI extends JFrame implements options, options[1]); // 0=beenden, 1=abbrechen if (choice == 0) { - try { - client.DeleteFtpUser(user.userName); } catch (TException e1) { // TODO Auto-generated catch block @@ -124,8 +124,8 @@ public class FTPEditUploader_GUI extends JFrame implements con.closeThriftConnection(); System.exit(0); }// end if choice - }else { - //no upload running, close window + } else { + // no upload running, close window System.exit(0); }// end if taskrun }// end window closing @@ -164,7 +164,8 @@ public class FTPEditUploader_GUI extends JFrame implements "C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\bwLehrpoolSuite\\config.ini")); - fc = new JFileChooser(ini.get("main", "Letzter Uploadpfad",String.class)); + fc = new JFileChooser(ini.get("main", + "Letzter Uploadpfad", String.class)); } catch (InvalidFileFormatException e2) { // TODO Auto-generated catch block e2.printStackTrace(); @@ -172,7 +173,7 @@ public class FTPEditUploader_GUI extends JFrame implements // TODO Auto-generated catch block e2.printStackTrace(); } - + fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.showOpenDialog(getParent()); @@ -197,12 +198,10 @@ public class FTPEditUploader_GUI extends JFrame implements lblPath = new JLabel(""); try { - Wini ini = new Wini( - new File( - "C:\\Users\\" - + System.getProperty("user.name") - + "\\AppData\\Roaming\\bwLehrpoolSuite\\config.ini")); - lblPath.setText(ini.get("main", "Letzter Uploadpfad",String.class)); + Wini ini = new Wini(new File("C:\\Users\\" + + System.getProperty("user.name") + + "\\AppData\\Roaming\\bwLehrpoolSuite\\config.ini")); + lblPath.setText(ini.get("main", "Letzter Uploadpfad", String.class)); } catch (InvalidFileFormatException e2) { // TODO Auto-generated catch block e2.printStackTrace(); @@ -216,8 +215,8 @@ public class FTPEditUploader_GUI extends JFrame implements // wenn leer, dann upload button nicht freigeben btnUploadStarten.setEnabled(false); btnUploadStarten.setText("Bitte warten"); - } else { - // wenn leer, dann upload button nicht freigeben + } else if (lblPath.getText().endsWith(".vmdk")) { + // wenn leer, dann upload button freigeben btnUploadStarten.setEnabled(true); btnUploadStarten.setText("Upload auf Server starten"); } @@ -365,7 +364,13 @@ public class FTPEditUploader_GUI extends JFrame implements "C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\bwLehrpoolSuite\\config.ini")); - ini.put("main", "Letzter Uploadpfad", lblPath.getText().substring(0, lblPath.getText().lastIndexOf("\\"))); + ini.put("main", + "Letzter Uploadpfad", + lblPath.getText() + .substring( + 0, + lblPath.getText() + .lastIndexOf("\\"))); ini.store(); } catch (InvalidFileFormatException e2) { // TODO Auto-generated catch block @@ -399,12 +404,38 @@ public class FTPEditUploader_GUI extends JFrame implements }); btnZurck.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - - // - dispose(); - PermissionEditImage_GUI ei = new PermissionEditImage_GUI(); - ei.setVisible(true); - } + + // check if loading file or not + if (isCurrentlyLoading() == true) { + int choice = JOptionPane + .showOptionDialog( + null, + "Nicht abgeschlossene Uploads werden beendet. Trotzdem zurück gehen?", + "Warnung", + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE, null, + options, options[1]); + // 0=beenden, 1=abbrechen + if (choice == 0) { + try { + client.DeleteFtpUser(user.userName); + } catch (TException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + task.cancel(true); + // not loading files, go back one page + dispose(); + PermissionEditImage_GUI ei = new PermissionEditImage_GUI(); + ei.setVisible(true); + + }// end if coice + } else { + dispose(); + PermissionEditImage_GUI ei = new PermissionEditImage_GUI(); + ei.setVisible(true); + }// end else + }// end action }); btnZurck.setActionCommand("Cancel"); @@ -516,25 +547,17 @@ public class FTPEditUploader_GUI extends JFrame implements } public void propertyChange(PropertyChangeEvent arg0) { + // set progressbar if ("progress" == arg0.getPropertyName()) { progress = (Integer) arg0.getNewValue(); progressBar.setValue(progress); + } - // Button zum Fertigstellen freischalten, wenn 100% erreicht sind - if (progress == 100) { - // not uploading currently - btnZurck.setEnabled(true); - } else { - // currently uploading, don't let user interact - btnZurck.setEnabled(false); - } - - // Fertigstellen erlauben wenn upload abgeschlossen - if (progress == 100) { - finishButton.setEnabled(true); - } else { - finishButton.setEnabled(false); - } + // Fertigstellen erlauben wenn upload abgeschlossen + if (isCurrentlyLoading() == true) { + finishButton.setEnabled(false); + } else { + finishButton.setEnabled(true); } if ("speed" == arg0.getPropertyName()) { @@ -611,16 +634,16 @@ public class FTPEditUploader_GUI extends JFrame implements return true; } - + public boolean isCurrentlyLoading() { isCurrentlyLoading = false; - if (labelverbleibend.getText().equals("0")) { + if (labelverbleibend.getText().equals("0 MB") || labelverbleibend.getText().equals("0")) { isCurrentlyLoading = false; } else { isCurrentlyLoading = true; } - System.out.println("isCurrentlyLoading"+isCurrentlyLoading); return isCurrentlyLoading; }// end isCurrentlyLoading() -} \ No newline at end of file + +}// end class \ No newline at end of file -- cgit v1.2.3-55-g7522