From 0708bf4d1e1a9046c82c221170b3dd3709e71141 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 18:57:50 +0000 Subject: Removed Error State and replaced it with ErrorDialog To get a stable user experience in case of an error. ErrorDialog was improved to let the user decide if he wants to retry an action. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@58 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../composites/AdvancedConfigurationComposite.java | 2 +- .../gui/composites/ConfigurationComposite.java | 44 ++++---- .../pdfover/gui/composites/ErrorComposite.java | 111 +++++++++++++++++++-- .../pdfover/gui/composites/OutputComposite.java | 2 +- .../composites/SimpleConfigurationComposite.java | 4 +- 5 files changed, 134 insertions(+), 29 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java index e3869105..11f0914d 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java @@ -273,7 +273,7 @@ public class AdvancedConfigurationComposite extends BaseConfigurationComposite { this.performBKUSelectionChanged(bkuvalue); } catch (Exception ex) { log.error("Failed to parse BKU value: " + selected, ex); //$NON-NLS-1$ - ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, "Invalid BKU selection. Please check.", ex); + ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, "Invalid BKU selection. Please check.", ex, false); dialog.open(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java index d95bb466..bb6d47a5 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java @@ -54,9 +54,9 @@ public class ConfigurationComposite extends StateComposite { */ private final class ConfigurationModeSelectionListener implements SelectionListener { - + /** - * Constructor + * Constructor */ public ConfigurationModeSelectionListener() { // Nothing to do @@ -117,13 +117,12 @@ public class ConfigurationComposite extends StateComposite { BaseConfigurationComposite configComposite; /** - * configuration container - * Keeps state for current configuration changes + * configuration container Keeps state for current configuration changes */ ConfigurationContainer configurationContainer = new ConfigurationContainerImpl(); /** - * The stack layout + * The stack layout */ StackLayout compositeStack = new StackLayout(); @@ -290,8 +289,7 @@ public class ConfigurationComposite extends StateComposite { this.configManipulator .setDefaultSignaturePosition(new SignaturePosition()); } else { - this.configManipulator - .setDefaultSignaturePosition(null); + this.configManipulator.setDefaultSignaturePosition(null); } this.configManipulator @@ -311,21 +309,29 @@ public class ConfigurationComposite extends StateComposite { getShell(), SWT.NONE, "Invalid settings are still present. Please check your input.", - e); + e, false); dialog.open(); return false; } - // Save current config to file - try { - this.configManipulator.saveCurrentConfiguration(); - } catch (IOException e) { - log.error("Failed to save configuration to file!", e); //$NON-NLS-1$ - ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, - "Failed to save configuration file!", e); - dialog.open(); - return false; - } - return true; + + boolean status = false; + boolean redo = false; + do { + // Save current config to file + try { + this.configManipulator.saveCurrentConfiguration(); + redo = false; + status = true; + } catch (IOException e) { + log.error("Failed to save configuration to file!", e); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, + "Failed to save configuration file!", e, true); + redo = dialog.open(); + + //return false; + } + } while (redo); + return status; } /** diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ErrorComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ErrorComposite.java index c85d046e..798ad7fb 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ErrorComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ErrorComposite.java @@ -45,12 +45,71 @@ public class ErrorComposite extends StateComposite { @Override public void widgetSelected(SelectionEvent e) { ErrorComposite.this.userOk = true; + ErrorComposite.this.shouldTryToRecover = false; + ErrorComposite.this.state.updateStateMachine(); + } + } + + /** + * + */ + private final class RetrySelectionListener extends SelectionAdapter { + /** + * Empty constructor + */ + public RetrySelectionListener() { + } + + @Override + public void widgetSelected(SelectionEvent e) { + ErrorComposite.this.userOk = true; + ErrorComposite.this.shouldTryToRecover = true; ErrorComposite.this.state.updateStateMachine(); } } boolean userOk = false; + boolean canTryToRecover = false; + + boolean shouldTryToRecover = false; + + /** + * Checks if we should try to recover form the error + * @return the shouldTryToRecover + */ + public boolean getShouldTryToRecover() { + return this.shouldTryToRecover; + } + + /** + * Gets try to recover + * @return can try to recover + */ + public boolean getCanTryToRecover() { + return this.canTryToRecover; + } + + /** + * Sets try to recover + * @param value + */ + public void setCanTryToRecover(boolean value) { + this.canTryToRecover = value; + + if(this.canTryToRecover) { + this.btn_ok.setVisible(false); + this.btn_retry.setVisible(true); + this.btn_cancel.setVisible(true); + this.lbl_title.setText("Recoverable error ocurred"); + } else { + this.btn_ok.setVisible(true); + this.btn_retry.setVisible(false); + this.btn_cancel.setVisible(false); + this.lbl_title.setText("Fatal error ocurred"); + } + } + /** * Checks if the user has clicked OK * @return whether the user has clicked OK @@ -61,6 +120,14 @@ public class ErrorComposite extends StateComposite { private Exception exception; private Label lbl_message; + + private Button btn_ok; + + private Button btn_retry; + + private Button btn_cancel; + + private Label lbl_title; /** @@ -87,21 +154,54 @@ public class ErrorComposite extends StateComposite { FormData fd_lbl_message = new FormData(); fd_lbl_message.left = new FormAttachment(10, 0); fd_lbl_message.right = new FormAttachment(90, 0); - fd_lbl_message.top = new FormAttachment(10, 0); + fd_lbl_message.top = new FormAttachment(15, 5); fd_lbl_message.bottom = new FormAttachment(80, 0); this.lbl_message.setLayoutData(fd_lbl_message); //lbl_message.setText(this.exception.getMessage()); - Button btn_ok = new Button(this, SWT.NATIVE | SWT.RESIZE); - btn_ok.setText("OK"); + this.btn_ok = new Button(this, SWT.NATIVE | SWT.RESIZE); + this.btn_ok.setText("OK"); // Point mobile_size = btn_mobile.computeSize(SWT.DEFAULT, SWT.DEFAULT); FormData fd_btn_ok = new FormData(); fd_btn_ok.left = new FormAttachment(45, 0); fd_btn_ok.right = new FormAttachment(55, 0); fd_btn_ok.top = new FormAttachment(85, 0); fd_btn_ok.bottom = new FormAttachment(95, 0); - btn_ok.setLayoutData(fd_btn_ok); - btn_ok.addSelectionListener(new OkSelectionListener()); + this.btn_ok.setLayoutData(fd_btn_ok); + this.btn_ok.addSelectionListener(new OkSelectionListener()); + + this.btn_retry = new Button(this, SWT.NATIVE | SWT.RESIZE); + this.btn_retry.setText("OK"); + // Point mobile_size = btn_mobile.computeSize(SWT.DEFAULT, SWT.DEFAULT); + FormData fd_btn_retry = new FormData(); + fd_btn_retry.left = new FormAttachment(30, 0); + fd_btn_retry.right = new FormAttachment(50, -5); + fd_btn_retry.top = new FormAttachment(85, 0); + fd_btn_retry.bottom = new FormAttachment(95, 0); + this.btn_retry.setLayoutData(fd_btn_retry); + this.btn_retry.addSelectionListener(new RetrySelectionListener()); + this.btn_retry.setVisible(false); + + this.btn_cancel = new Button(this, SWT.NATIVE | SWT.RESIZE); + this.btn_cancel.setText("Cancel"); + // Point mobile_size = btn_mobile.computeSize(SWT.DEFAULT, SWT.DEFAULT); + FormData fd_btn_cancel = new FormData(); + fd_btn_cancel.left = new FormAttachment(50, 5); + fd_btn_cancel.right = new FormAttachment(80, 0); + fd_btn_cancel.top = new FormAttachment(85, 0); + fd_btn_cancel.bottom = new FormAttachment(95, 0); + this.btn_cancel.setLayoutData(fd_btn_cancel); + this.btn_cancel.addSelectionListener(new OkSelectionListener()); + this.btn_cancel.setVisible(false); + + this.lbl_title = new Label(this, SWT.NONE); + FormData fd_lbl_title = new FormData(); + fd_lbl_title.left = new FormAttachment(10, 0); + fd_lbl_title.right = new FormAttachment(90, 0); + fd_lbl_title.top = new FormAttachment(0, 5); + fd_lbl_title.bottom = new FormAttachment(15, -5); + this.lbl_title.setLayoutData(fd_lbl_title); + this.lbl_title.setText(""); //$NON-NLS-1$ } @Override @@ -116,5 +216,4 @@ public class ErrorComposite extends StateComposite { public void doLayout() { // Nothing to do } - } 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 afa2a2e7..9cdabe23 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 @@ -118,7 +118,7 @@ public class OutputComposite extends StateComposite { } } else { log.error("OutputComposite:OpenSelectionListener:widgetSelected -> source is null!!"); //$NON-NLS-1$ - ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, "Failed to get signed document.", ""); + ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, "Failed to get signed document.", "", false); dialog.open(); } } catch (Exception ex) { diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java index a0977b9e..6bac14ec 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java @@ -226,7 +226,7 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { plainEmblemSetter(filename); } catch (Exception ex) { log.error("processEmblemChanged: ", ex); //$NON-NLS-1$ - ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, "Failed to load the emblem", ex); + ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, "Failed to load the emblem", ex, false); dialog.open(); } } @@ -728,7 +728,7 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { this.btnUseImage.setSelection(true); } catch (Exception e1) { log.error("Failed to load emblem: ", e1); //$NON-NLS-1$ - ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, "Failed to load emblem.", e1); + ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, "Failed to load emblem.", e1, false); dialog.open(); } } -- cgit v1.2.3