From 5f9def7c33845efcff91ec1edf7caae71fc4ed75 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Mon, 25 Aug 2014 17:50:08 +0200 Subject: Verhindere unerlaubtes zurückgehen auf vorige Seite während Up-DOwnloads --- .../src/gui/image/FTPCreateUploader_GUI.java | 90 ++++++++++++++++------ 1 file changed, 67 insertions(+), 23 deletions(-) (limited to 'Dozentenmodul/src/gui/image/FTPCreateUploader_GUI.java') diff --git a/Dozentenmodul/src/gui/image/FTPCreateUploader_GUI.java b/Dozentenmodul/src/gui/image/FTPCreateUploader_GUI.java index 2bea341d..291bc065 100644 --- a/Dozentenmodul/src/gui/image/FTPCreateUploader_GUI.java +++ b/Dozentenmodul/src/gui/image/FTPCreateUploader_GUI.java @@ -86,6 +86,7 @@ public class FTPCreateUploader_GUI extends JFrame implements JButton btnUploadStarten = new JButton("Upload auf Server starten"); JButton btnZurck = new JButton("Zur\u00FCck"); int progress = 0; // progress of upload + private boolean isCurrentlyLoading = false; // currently up or downloading file /** * Create the frame. @@ -98,7 +99,7 @@ public class FTPCreateUploader_GUI extends JFrame implements @Override public void windowClosing(WindowEvent arg0) { - + if (taskrun == true) { // check if user wants to quit. int choice = JOptionPane @@ -116,18 +117,15 @@ public class FTPCreateUploader_GUI extends JFrame implements } catch (TException e1) { // TODO Auto-generated catch block e1.printStackTrace(); - JOptionPane.showMessageDialog(null, e1.getCause() - + "\n" + e1.getStackTrace(), - "Debug-Message", JOptionPane.ERROR_MESSAGE); } task.cancel(true); con.closeThriftConnection(); System.exit(0); - }//end if choice + }// end if choice } else { - //no upload running, close window + // no upload running, close window System.exit(0); - }//end if taskrun + }// end if taskrun }// end window closing }); setResizable(false); @@ -185,12 +183,10 @@ public class FTPCreateUploader_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(); @@ -198,10 +194,10 @@ public class FTPCreateUploader_GUI extends JFrame implements // TODO Auto-generated catch block e2.printStackTrace(); } - + lblPath.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent arg0) { - if (lblPath.getText()==null) { + if (lblPath.getText() == null) { // wenn leer, dann upload button nicht freigeben btnUploadStarten.setEnabled(false); btnUploadStarten.setText("Bitte warten"); @@ -359,7 +355,13 @@ public class FTPCreateUploader_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 @@ -393,10 +395,38 @@ public class FTPCreateUploader_GUI extends JFrame implements btnZurck.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - dispose(); + // 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(); + + PermissionCreateImage_GUI m = new PermissionCreateImage_GUI(); + m.setVisible(true); - PermissionCreateImage_GUI m = new PermissionCreateImage_GUI(); - m.setVisible(true); + } + } else { + dispose(); + + PermissionCreateImage_GUI m = new PermissionCreateImage_GUI(); + m.setVisible(true); + } } }); btnZurck.setActionCommand("Cancel"); @@ -518,14 +548,15 @@ public class FTPCreateUploader_GUI extends JFrame implements // Button zum Fertigstellen freischalten, wenn 100% erreicht sind if (progress == 0 || progress == 100) { // not uploading currently - btnZurck.setEnabled(true); + // btnZurck.setEnabled(true); } else { // currently uploading, don't let user interact - btnZurck.setEnabled(false); + // btnZurck.setEnabled(false); } // Fertigstellen erlauben wenn upload abgeschlossen if (progress == 100) { + isCurrentlyLoading(); finishButton.setEnabled(true); } else { @@ -608,5 +639,18 @@ public class FTPCreateUploader_GUI extends JFrame implements } return true; - } -} \ No newline at end of file + }// end writeData() + + public boolean isCurrentlyLoading() { + isCurrentlyLoading = false; + + if (labelverbleibend.getText().equals("0")) { + isCurrentlyLoading = false; + } else { + isCurrentlyLoading = true; + } + System.out.println("isCurrentlyLoading"+isCurrentlyLoading); + return isCurrentlyLoading; + }// end isCurrentlyLoading() + +}// end class \ No newline at end of file -- cgit v1.2.3-55-g7522