summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java
diff options
context:
space:
mode:
authortkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 19:29:08 +0000
committertkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 19:29:08 +0000
commit3c204ab19773fff240beb4f66a2098afc8ca4397 (patch)
treed7edb07a15a4103c24fba45eaec28e8a21108d7a /pdf-over-gui/src/main/java
parent9400f7509c97db2706f8d36f816b7719c11fcb4d (diff)
downloadmocca-3c204ab19773fff240beb4f66a2098afc8ca4397.tar.gz
mocca-3c204ab19773fff240beb4f66a2098afc8ca4397.tar.bz2
mocca-3c204ab19773fff240beb4f66a2098afc8ca4397.zip
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
Diffstat (limited to 'pdf-over-gui/src/main/java')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java47
1 files changed, 34 insertions, 13 deletions
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;
}