From 3c204ab19773fff240beb4f66a2098afc8ca4397 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:29:08 +0000 Subject: Display error message (and retry) when saving fails git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@345 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../pdfover/gui/composites/OutputComposite.java | 47 ++++++++++++++++------ 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java index 8c9e21c1..966a0708 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java @@ -44,6 +44,7 @@ import at.asit.pdfover.gui.Constants; import at.asit.pdfover.gui.controls.Dialog; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; import at.asit.pdfover.gui.controls.Dialog.ICON; +import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.workflow.states.State; import at.asit.pdfover.signator.DocumentSource; @@ -265,7 +266,7 @@ public class OutputComposite extends StateComposite { targetFile = new File(inputFolder, target); if (targetFile.exists()) { - Dialog dialog = new Dialog(this.getShell(), Messages.getString("common.warning"), //$NON-NLS-1$ + Dialog dialog = new Dialog(getShell(), Messages.getString("common.warning"), //$NON-NLS-1$ String.format(Messages.getString("output.file_ask_overwrite"), targetFile.getName()), //$NON-NLS-1$ BUTTONS.OK_CANCEL, ICON.QUESTION); if (dialog.open() == SWT.CANCEL) @@ -275,22 +276,42 @@ public class OutputComposite extends StateComposite { } DocumentSource source = this.getSignedDocument(); + boolean retry; - try { - FileOutputStream outstream = new FileOutputStream(targetFile); - outstream.write(source.getByteArray(), 0, - source.getByteArray().length); - outstream.close(); - } catch (FileNotFoundException e) { - log.debug("File not found", e); //$NON-NLS-1$ - return null; - } catch (IOException e) { - log.debug("IO Error", e); //$NON-NLS-1$ - return null; - } + do { + retry = false; + try { + FileOutputStream outstream = new FileOutputStream(targetFile); + outstream.write(source.getByteArray(), 0, + source.getByteArray().length); + outstream.close(); + } catch (FileNotFoundException e) { + log.error("File not found", e); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog(getShell(), + String.format(Messages.getString("output.save_failed"), //$NON-NLS-1$ + targetFile.getName(), e.getLocalizedMessage()), + BUTTONS.RETRY_CANCEL); + if (dialog.open() == SWT.CANCEL) + return null; + retry = true; + } catch (IOException e) { + log.error("IO Error", e); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog(getShell(), + String.format(Messages.getString("output.save_failed"), //$NON-NLS-1$ + targetFile.getName(), e.getLocalizedMessage()), + BUTTONS.RETRY_CANCEL); + if (dialog.open() == SWT.CANCEL) + return null; + retry = true; + } + } while (retry); if (!targetFile.exists()) + { + log.error("Tried to save file " + targetFile.getName() + //$NON-NLS-1$ + ", but it doesn't exist"); //$NON-NLS-1$ return null; + } return targetFile; } -- cgit v1.2.3