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 --- .../pdfover/gui/composites/ErrorComposite.java | 111 +++++++++++++++++++-- 1 file changed, 105 insertions(+), 6 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ErrorComposite.java') 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 } - } -- cgit v1.2.3