From: Ben Soares Date: Tue, 7 Jul 2020 00:30:23 +0000 (+0100) Subject: JAL-3628 Fixed oddly worded and non-formatted error popups when saving fails X-Git-Tag: Release_2_11_1_1~13^2~26^2~6^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=09a0de25f29efc9f871ea2e878ea77c044c296e6;p=jalview.git JAL-3628 Fixed oddly worded and non-formatted error popups when saving fails --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 96cc7d9..df7f76a 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -377,7 +377,7 @@ label.example = Example label.example_param = Example: {0} label.select_file_format_before_saving = You must select a file format before saving! label.file_format_not_specified = File format not specified -label.couldnt_save_file = Couldn't save file: {0} +label.couldnt_save_file = Couldn''t save file: {0} label.error_saving_file = Error Saving File label.remove_from_default_list = Remove from default list? label.remove_user_defined_colour = Remove user defined colour @@ -1346,6 +1346,7 @@ label.backupfiles_confirm_save_file = Confirm save file label.backupfiles_confirm_save_file_backupfiles_roll_wrong = Something possibly went wrong with the backups of this file. label.backupfiles_confirm_save_new_saved_file_ok = The new saved file seems okay. label.backupfiles_confirm_save_new_saved_file_not_ok = The new saved file might not be okay. +label.continue_operation = Continue operation? label.backups = Backups label.backup = Backup label.backup_files = Backup Files diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index dfb8dd6..707f1ba 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1341,6 +1341,7 @@ label.backupfiles_confirm_save_file = Confirmar guardar archivo label.backupfiles_confirm_save_file_backupfiles_roll_wrong = Posiblemente algo está mal con los archivos de respaldos. label.backupfiles_confirm_save_new_saved_file_ok = El nuevo archivo guardado parece estar bien. label.backupfiles_confirm_save_new_saved_file_not_ok = El nuevo archivo guardado podría no estar bien. +label.continue_operation = ¿Continuar operación? label.backups = Respaldos label.backup = Respaldo label.backup_files = Archivos de respaldos diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 35d6aa3..bb3ea76 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -20,16 +20,6 @@ */ package jalview.bin; -import jalview.datamodel.PDBEntry; -import jalview.gui.UserDefinedColours; -import jalview.schemes.ColourSchemeLoader; -import jalview.schemes.ColourSchemes; -import jalview.schemes.UserColourScheme; -import jalview.structure.StructureImportSettings; -import jalview.urls.IdOrgSettings; -import jalview.util.ColorUtils; -import jalview.ws.sifts.SiftsSettings; - import java.awt.Color; import java.io.BufferedReader; import java.io.File; @@ -37,6 +27,8 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.StringWriter; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collections; @@ -52,6 +44,16 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; +import jalview.datamodel.PDBEntry; +import jalview.gui.UserDefinedColours; +import jalview.schemes.ColourSchemeLoader; +import jalview.schemes.ColourSchemes; +import jalview.schemes.UserColourScheme; +import jalview.structure.StructureImportSettings; +import jalview.urls.IdOrgSettings; +import jalview.util.ColorUtils; +import jalview.ws.sifts.SiftsSettings; + /** * Stores and retrieves Jalview Application Properties Lists and fields within * list entries are separated by '|' symbols unless otherwise stated (|) clauses @@ -435,8 +437,8 @@ public class Cache String jnlpVersion = System.getProperty("jalview.version"); - // jnlpVersion will be null if a latest version check for the channel needs to - // be done + // jnlpVersion will be null if a latest version check for the channel needs + // to be done // Dont do this check if running in headless mode if (jnlpVersion == null && getDefault("VERSION_CHECK", true) @@ -555,8 +557,8 @@ public class Cache new BuildDetails(codeVersion, null, codeInstallation); if (printV && reportVersion) { - System.out - .println("Jalview Version: " + codeVersion + codeInstallation); + System.out.println( + "Jalview Version: " + codeVersion + codeInstallation); } } @@ -1099,16 +1101,20 @@ public class Cache public static String getVersionDetailsForConsole() { StringBuilder sb = new StringBuilder(); - sb.append("Jalview Version: " + jalview.bin.Cache.getDefault("VERSION", "TEST")); + sb.append("Jalview Version: " + + jalview.bin.Cache.getDefault("VERSION", "TEST")); sb.append("\n"); sb.append("Jalview Installation: " + jalview.bin.Cache.getDefault("INSTALLATION", "unknown")); sb.append("\n"); - sb.append("Build Date: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")); + sb.append("Build Date: " + + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")); sb.append("\n"); sb.append("Java version: " + System.getProperty("java.version")); sb.append("\n"); - sb.append(System.getProperty("os.arch") + " " + System.getProperty("os.name") + " " + System.getProperty("os.version")); + sb.append(System.getProperty("os.arch") + " " + + System.getProperty("os.name") + " " + + System.getProperty("os.version")); sb.append("\n"); appendIfNotNull(sb, "Install4j version: ", System.getProperty("sys.install4jVersion"), "\n", null); @@ -1116,7 +1122,9 @@ public class Cache System.getProperty("installer_template_version"), "\n", null); appendIfNotNull(sb, "Launcher version: ", System.getProperty("launcher_version"), "\n", null); - if (jalview.bin.Cache.getDefault("VERSION", "TEST").equals("DEVELOPMENT")) { + if (jalview.bin.Cache.getDefault("VERSION", "TEST") + .equals("DEVELOPMENT")) + { appendIfNotNull(sb, "Getdown appdir: ", System.getProperty("getdownappdir"), "\n", null); appendIfNotNull(sb, "Java home: ", System.getProperty("java.home"), @@ -1135,4 +1143,12 @@ public class Cache // eg 'built from Source' or update channel return jalview.bin.Cache.getDefault("INSTALLATION", "unknown"); } + + public static String getStackTraceString(Throwable t) + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + t.printStackTrace(pw); + return sw.toString(); + } } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 79c67ac..99580ae 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1170,7 +1170,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, statusBar.setText(MessageManager.formatMessage( "label.successfully_saved_to_file_in_format", new Object[] - { fileName, format })); + { file, format })); } else @@ -1204,12 +1204,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, try { - Cache.log.debug("ALIGNFRAME setting PrintWriter"); - PrintWriter out = new PrintWriter( - new FileWriter(backupfiles.getTempFilePath())); + String tempFilePath = backupfiles.getTempFilePath(); + Cache.log.debug( + "ALIGNFRAME setting PrintWriter to " + tempFilePath); + PrintWriter out = new PrintWriter(new FileWriter(tempFilePath)); - Cache.log.debug("ALIGNFRAME about to write to temp file " - + backupfiles.getTempFilePath()); + Cache.log.debug( + "ALIGNFRAME about to write to temp file " + tempFilePath); out.print(output); Cache.log.debug("ALIGNFRAME about to close file"); @@ -1218,14 +1219,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, this.setTitle(file); statusBar.setText(MessageManager.formatMessage( "label.successfully_saved_to_file_in_format", new Object[] - { fileName, format.getName() })); + { file, format.getName() })); } catch (IOException e) { success = false; Cache.log.error( "ALIGNFRAME Something happened writing the temp file"); Cache.log.error(e.getMessage()); - Cache.log.debug(e.getStackTrace()); + Cache.log.debug(Cache.getStackTraceString(e)); } catch (Exception ex) { @@ -1233,7 +1234,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Cache.log.error( "ALIGNFRAME Something else happened writing the temp file"); Cache.log.error(ex.getMessage()); - Cache.log.debug(ex.getStackTrace()); + Cache.log.debug(Cache.getStackTraceString(ex)); } backupfiles.setWriteSuccess(success); @@ -1254,7 +1255,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { JvOptionPane.showInternalMessageDialog(this, MessageManager .formatMessage("label.couldnt_save_file", new Object[] - { fileName }), + { file }), MessageManager.getString("label.error_saving_file"), JvOptionPane.WARNING_MESSAGE); } diff --git a/src/jalview/io/BackupFiles.java b/src/jalview/io/BackupFiles.java index c41bd36..e943b23 100644 --- a/src/jalview/io/BackupFiles.java +++ b/src/jalview/io/BackupFiles.java @@ -152,11 +152,11 @@ public class BackupFiles Cache.log .error("Could not create temp file to save to (IOException)"); Cache.log.error(e.getMessage()); - Cache.log.debug(e.getStackTrace()); + Cache.log.debug(Cache.getStackTraceString(e)); } catch (Exception e) { Cache.log.error("Exception ctreating temp file for saving"); - Cache.log.debug(e.getStackTrace()); + Cache.log.debug(Cache.getStackTraceString(e)); } this.setTempFile(temp); } @@ -218,7 +218,7 @@ public class BackupFiles Cache.log.error( "IOException when getting Canonical Path of temp file '" + this.getTempFile().getName() + "'"); - Cache.log.debug(e.getStackTrace()); + Cache.log.debug(Cache.getStackTraceString(e)); } return path; } @@ -276,7 +276,7 @@ public class BackupFiles Cache.log.error( "Could not get canonical path for file '" + file + "'"); Cache.log.error(e.getMessage()); - Cache.log.debug(e.getStackTrace()); + Cache.log.debug(Cache.getStackTraceString(e)); return false; } String filename = file.getName(); @@ -416,7 +416,7 @@ public class BackupFiles Cache.log.error( "Error occurred, probably making new temp file for '" + fileToBeDeleted.getName() + "'"); - Cache.log.error(e.getStackTrace()); + Cache.log.error(Cache.getStackTraceString(e)); } // reset @@ -776,7 +776,6 @@ public class BackupFiles boolean okay = roll && rename; if (!okay) { - boolean yesno = false; StringBuilder messageSB = new StringBuilder(); messageSB.append(MessageManager.getString( "label.backupfiles_confirm_save_file_backupfiles_roll_wrong")); @@ -801,6 +800,12 @@ public class BackupFiles "label.backupfiles_confirm_save_new_saved_file_not_ok")); // "The new saved file might not be okay." } + if (messageSB.length() > 0) + { + messageSB.append("\n"); + } + messageSB + .append(MessageManager.getString("label.continue_operation")); int confirmButton = Platform.isHeadless() ? JvOptionPane.OK_OPTION : JvOptionPane.showConfirmDialog(Desktop.desktop, @@ -908,12 +913,12 @@ public class BackupFiles Cache.log.warn("Could not move file '" + oldPath.toString() + "' to '" + newPath.toString() + "'"); Cache.log.error(e.getMessage()); - Cache.log.debug(e.getStackTrace()); + Cache.log.debug(Cache.getStackTraceString(e)); ret = false; } catch (Exception e) { Cache.log.error(e.getMessage()); - Cache.log.debug(e.getStackTrace()); + Cache.log.debug(Cache.getStackTraceString(e)); ret = false; } return ret;