diff options
author | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 19:10:00 +0000 |
---|---|---|
committer | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 19:10:00 +0000 |
commit | 782c82871bdea8d6091e9335823240af8e0f04d7 (patch) | |
tree | 03bdcb6ce04b7bd1022bfcbf2e091d95515e0ee9 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites | |
parent | 880f96c5fd18d760f85e6814cb77ca908c4d8dc4 (diff) | |
download | pdf-over-782c82871bdea8d6091e9335823240af8e0f04d7.tar.gz pdf-over-782c82871bdea8d6091e9335823240af8e0f04d7.tar.bz2 pdf-over-782c82871bdea8d6091e9335823240af8e0f04d7.zip |
+ ignore option for error dialog
+ resumeable exception for settings validation
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@168 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites')
5 files changed, 174 insertions, 80 deletions
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 72e047c4..05b16824 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 @@ -43,6 +43,9 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.Constants; import at.asit.pdfover.gui.Messages; import at.asit.pdfover.gui.controls.ErrorDialog; +import at.asit.pdfover.gui.controls.ErrorDialog.ERROR_BUTTONS; +import at.asit.pdfover.gui.exceptions.OutputfolderDontExistException; +import at.asit.pdfover.gui.exceptions.OutputfolderNotADirectoryException; import at.asit.pdfover.gui.workflow.ConfigurationContainer; import at.asit.pdfover.gui.workflow.states.State; import at.asit.pdfover.signator.BKUs; @@ -106,10 +109,14 @@ public class AdvancedConfigurationComposite extends BaseConfigurationComposite { FontData[] fD_btnAutomatischePositionierung = this.btnAutomatischePositionierung .getFont().getFontData(); - fD_btnAutomatischePositionierung[0].setHeight(Constants.TEXT_SIZE_BUTTON); + fD_btnAutomatischePositionierung[0] + .setHeight(Constants.TEXT_SIZE_BUTTON); this.btnAutomatischePositionierung.setFont(new Font(Display .getCurrent(), fD_btnAutomatischePositionierung[0])); + this.btnAutomatischePositionierung.setToolTipText(Messages + .getString("advanced_config.AutoPosition_ToolTip")); //$NON-NLS-1$ + this.btnAutomatischePositionierung .addSelectionListener(new SelectionAdapter() { @@ -225,6 +232,9 @@ public class AdvancedConfigurationComposite extends BaseConfigurationComposite { this.cmbBKUAuswahl.setLayoutData(fd_cmbBKUAuswahl); + this.cmbBKUAuswahl.setToolTipText(Messages + .getString("advanced_config.BKUSelection_ToolTip")); //$NON-NLS-1$ + this.cmbBKUAuswahl.addSelectionListener(new SelectionAdapter() { @Override @@ -294,6 +304,9 @@ public class AdvancedConfigurationComposite extends BaseConfigurationComposite { } }); + this.txtOutputFolder.setToolTipText(Messages + .getString("advanced_config.OutputFolder_ToolTip")); //$NON-NLS-1$ + Button btnBrowse = new Button(grpSpeicherort, SWT.NONE); fd_text.right = new FormAttachment(btnBrowse, -5); @@ -383,7 +396,8 @@ 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(), Messages.getString("error.InvalidBKU"), false); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog(getShell(), + Messages.getString("error.InvalidBKU"), ERROR_BUTTONS.OK); //$NON-NLS-1$ dialog.open(); } } @@ -451,19 +465,23 @@ public class AdvancedConfigurationComposite extends BaseConfigurationComposite { * () */ @Override - public void validateSettings() throws Exception { + public void validateSettings(int resumeIndex) throws Exception { String foldername = this.configurationContainer.getOutputFolder(); - if (foldername != null && !foldername.equals("")) { //$NON-NLS-1$ - File outputFolder = new File(foldername); - if (!outputFolder.exists()) { - throw new Exception(String.format(Messages.getString("exception.PathNotExist"), outputFolder.getAbsolutePath())); //$NON-NLS-1$ - } - - if (!outputFolder.isDirectory()) { - throw new Exception(String.format(Messages.getString("exception.PathNotDirectory"), outputFolder.getAbsolutePath())); //$NON-NLS-1$ - } + switch (resumeIndex) { + case 0: + if (foldername != null && !foldername.isEmpty()) { + File outputFolder = new File(foldername); + if (!outputFolder.exists()) { + throw new OutputfolderDontExistException(outputFolder, 1); + } + if (!outputFolder.isDirectory()) { + throw new OutputfolderNotADirectoryException(outputFolder); + } + } + // Fall through + case 1: } } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java index db3304d5..00e4ebb0 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java @@ -77,8 +77,15 @@ public abstract class BaseConfigurationComposite extends StateComposite { /** * Called before exit. - * The method validates every setting in the configuration before exit - * @throws Exception + * The method validates every setting in the configuration before exit + * + * There might be settings when the user can decide to ignore a validation exception + * (for example the Outputfolder validation) + * In this case, the validator throws a ResumableException, which includes the + * validator index to resume from (should the user choose to ignore the error) + * + * @param resumeFrom Resume from this validator index (initially 0) + * @throws Exception */ - public abstract void validateSettings() throws Exception; + public abstract void validateSettings(int resumeFrom) throws Exception; } 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 2b62d651..c170e5df 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 @@ -29,9 +29,11 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.Constants; import at.asit.pdfover.gui.Messages; import at.asit.pdfover.gui.controls.ErrorDialog; +import at.asit.pdfover.gui.controls.ErrorDialog.ERROR_BUTTONS; import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; import at.asit.pdfover.gui.exceptions.InvalidNumberException; import at.asit.pdfover.gui.exceptions.InvalidPortException; +import at.asit.pdfover.gui.exceptions.ResumeableException; import at.asit.pdfover.gui.workflow.ConfigManipulator; import at.asit.pdfover.gui.workflow.ConfigProvider; import at.asit.pdfover.gui.workflow.ConfigurationContainer; @@ -56,12 +58,12 @@ import org.eclipse.swt.layout.FormAttachment; * Composite for hosting configuration composites */ public class ConfigurationComposite extends StateComposite { - + /** * The PDF Signer used to produce signature block preview */ protected PDFSigner signer; - + /** * @return the signer */ @@ -70,7 +72,8 @@ public class ConfigurationComposite extends StateComposite { } /** - * @param signer the signer to set + * @param signer + * the signer to set */ public void setSigner(PDFSigner signer) { this.signer = signer; @@ -160,8 +163,9 @@ public class ConfigurationComposite extends StateComposite { .useAutoPositioning()); } - this.configurationContainer.setPlaceholderTransparency( - this.configProvider.getPlaceholderTransparency()); + this.configurationContainer + .setPlaceholderTransparency(this.configProvider + .getPlaceholderTransparency()); this.configurationContainer.setBKUSelection(this.configProvider .getDefaultBKU()); @@ -225,16 +229,17 @@ public class ConfigurationComposite extends StateComposite { TabItem simpleTabItem = new TabItem(tabFolder, SWT.NONE); simpleTabItem.setText(Messages.getString("config.Simple")); //$NON-NLS-1$ - ScrolledComposite simpleCompositeScr = new ScrolledComposite( - tabFolder, SWT.H_SCROLL | SWT.V_SCROLL); + ScrolledComposite simpleCompositeScr = new ScrolledComposite(tabFolder, + SWT.H_SCROLL | SWT.V_SCROLL); simpleTabItem.setControl(simpleCompositeScr); this.simpleConfigComposite = new SimpleConfigurationComposite( - simpleCompositeScr, SWT.NONE, state, this.configurationContainer); + simpleCompositeScr, SWT.NONE, state, + this.configurationContainer); simpleCompositeScr.setContent(this.simpleConfigComposite); simpleCompositeScr.setExpandHorizontal(true); simpleCompositeScr.setExpandVertical(true); - simpleCompositeScr.setMinSize( - this.simpleConfigComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + simpleCompositeScr.setMinSize(this.simpleConfigComposite.computeSize( + SWT.DEFAULT, SWT.DEFAULT)); TabItem advancedTabItem = new TabItem(tabFolder, SWT.NONE); advancedTabItem.setText(Messages.getString("config.Advanced")); //$NON-NLS-1$ @@ -243,12 +248,13 @@ public class ConfigurationComposite extends StateComposite { tabFolder, SWT.H_SCROLL | SWT.V_SCROLL); advancedTabItem.setControl(advancedCompositeScr); this.advancedConfigComposite = new AdvancedConfigurationComposite( - advancedCompositeScr, SWT.NONE, state, this.configurationContainer); + advancedCompositeScr, SWT.NONE, state, + this.configurationContainer); advancedCompositeScr.setContent(this.advancedConfigComposite); advancedCompositeScr.setExpandHorizontal(true); advancedCompositeScr.setExpandVertical(true); - advancedCompositeScr.setMinSize( - this.advancedConfigComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + advancedCompositeScr.setMinSize(this.advancedConfigComposite + .computeSize(SWT.DEFAULT, SWT.DEFAULT)); tabFolder.setSelection(simpleTabItem); @@ -270,8 +276,9 @@ public class ConfigurationComposite extends StateComposite { FontData[] fD_btnSpeichern = btnSpeichern.getFont().getFontData(); fD_btnSpeichern[0].setHeight(Constants.TEXT_SIZE_BUTTON); - btnSpeichern.setFont(new Font(Display.getCurrent(), fD_btnSpeichern[0])); - + btnSpeichern + .setFont(new Font(Display.getCurrent(), fD_btnSpeichern[0])); + Button btnAbbrechen = new Button(this, SWT.NONE); FormData fd_btnAbrechen = new FormData(); fd_btnAbrechen.right = new FormAttachment(btnSpeichern, -10); @@ -288,7 +295,8 @@ public class ConfigurationComposite extends StateComposite { FontData[] fD_btnAbbrechen = btnAbbrechen.getFont().getFontData(); fD_btnAbbrechen[0].setHeight(Constants.TEXT_SIZE_BUTTON); - btnAbbrechen.setFont(new Font(Display.getCurrent(), fD_btnAbbrechen[0])); + btnAbbrechen + .setFont(new Font(Display.getCurrent(), fD_btnAbbrechen[0])); FormData fd_composite = new FormData(); fd_composite.top = new FormAttachment(0, 5); @@ -300,53 +308,103 @@ public class ConfigurationComposite extends StateComposite { this.compositeStack.topControl = tabFolder; this.doLayout(); -} + } boolean storeConfiguration() { - + boolean status = false; + boolean redo = false; + int resumeIndex = 0; try { - this.simpleConfigComposite.validateSettings(); - this.advancedConfigComposite.validateSettings(); + do { + try { + this.simpleConfigComposite.validateSettings(resumeIndex); + + redo = false; + status = true; + } catch (ResumeableException e) { + log.error("Settings validation failed!", e); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog(getShell(), + e.getMessage(), ERROR_BUTTONS.ABORT_RETRY_IGNORE); + int rc = dialog.open(); + + redo = (rc == SWT.RETRY); + if (rc == SWT.IGNORE) + { + resumeIndex = e.getResumeIndex(); + redo = true; + } + } + } while (redo); - // Write current Configuration - this.configManipulator.setDefaultBKU(this.configurationContainer - .getBKUSelection()); - this.configManipulator - .setDefaultMobileNumber(this.configurationContainer - .getNumber()); - if (this.configurationContainer.getAutomaticPosition()) { - this.configManipulator - .setDefaultSignaturePosition(new SignaturePosition()); - } else { - this.configManipulator.setDefaultSignaturePosition(null); + if (!status) { + return false; } - this.configManipulator.setPlaceholderTransparency( - this.configurationContainer.getPlaceholderTransparency()); - - this.configManipulator - .setDefaultOutputFolder(this.configurationContainer - .getOutputFolder()); - - this.configManipulator.setProxyHost(this.configurationContainer - .getProxyHost()); - this.configManipulator.setProxyPort(this.configurationContainer - .getProxyPort()); - this.configManipulator.setDefaultEmblem(this.configurationContainer - .getEmblem()); - + status = false; + redo = false; + resumeIndex = 0; + + do { + try { + this.advancedConfigComposite.validateSettings(resumeIndex); + + redo = false; + status = true; + } catch (ResumeableException e) { + log.error("Settings validation failed!", e); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog(getShell(), + e.getMessage(), ERROR_BUTTONS.ABORT_RETRY_IGNORE); + int rc = dialog.open(); + + redo = (rc == SWT.RETRY); + if (rc == SWT.IGNORE) + { + resumeIndex = e.getResumeIndex(); + redo = true; + } + } + } while (redo); } catch (Exception e) { log.error("Settings validation failed!", e); //$NON-NLS-1$ - ErrorDialog dialog = new ErrorDialog( - getShell(), - e.getMessage(), - false); + ErrorDialog dialog = new ErrorDialog(getShell(), e.getMessage(), + ERROR_BUTTONS.OK); dialog.open(); return false; } - boolean status = false; - boolean redo = false; + if (!status) { + return false; + } + + // Write current Configuration + this.configManipulator.setDefaultBKU(this.configurationContainer + .getBKUSelection()); + this.configManipulator + .setDefaultMobileNumber(this.configurationContainer.getNumber()); + if (this.configurationContainer.getAutomaticPosition()) { + this.configManipulator + .setDefaultSignaturePosition(new SignaturePosition()); + } else { + this.configManipulator.setDefaultSignaturePosition(null); + } + + this.configManipulator + .setPlaceholderTransparency(this.configurationContainer + .getPlaceholderTransparency()); + + this.configManipulator + .setDefaultOutputFolder(this.configurationContainer + .getOutputFolder()); + + this.configManipulator.setProxyHost(this.configurationContainer + .getProxyHost()); + this.configManipulator.setProxyPort(this.configurationContainer + .getProxyPort()); + this.configManipulator.setDefaultEmblem(this.configurationContainer + .getEmblem()); + + status = false; + redo = false; do { // Save current config to file try { @@ -355,11 +413,12 @@ public class ConfigurationComposite extends StateComposite { status = true; } catch (IOException e) { log.error("Failed to save configuration to file!", e); //$NON-NLS-1$ - ErrorDialog dialog = new ErrorDialog(getShell(), - Messages.getString("error.FailedToSaveSettings"), true); //$NON-NLS-1$ - redo = dialog.open(); - - //return false; + ErrorDialog dialog = new ErrorDialog( + getShell(), + Messages.getString("error.FailedToSaveSettings"), ERROR_BUTTONS.RETRY_CANCEL); //$NON-NLS-1$ + redo = (dialog.open() == SWT.RETRY); + + // return false; } } while (redo); return status; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/DataSourceSelectComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/DataSourceSelectComposite.java index 8c3c1e25..17252457 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/DataSourceSelectComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/DataSourceSelectComposite.java @@ -151,7 +151,7 @@ public class DataSourceSelectComposite extends StateComposite { super(parent, style, state); this.activeBackground = Constants.MAINBAR_ACTIVE_BACK_LIGHT; - this.inactiveBackground = Constants.MAINBAR_INACTIVE_BACK; + this.inactiveBackground = this.getBackground();//Constants.MAINBAR_INACTIVE_BACK; this.inactiveBorder = Constants.MAINBAR_ACTIVE_BACK_LIGHT; this.activeBorder = Constants.MAINBAR_ACTIVE_BACK_DARK; this.backgroundColor = this.inactiveBackground; 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 f5fc34ce..6e707156 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 @@ -60,6 +60,7 @@ import at.asit.pdfover.gui.Constants; import at.asit.pdfover.gui.Messages; import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.controls.ErrorMarker; +import at.asit.pdfover.gui.controls.ErrorDialog.ERROR_BUTTONS; import at.asit.pdfover.gui.exceptions.InvalidNumberException; import at.asit.pdfover.gui.exceptions.InvalidPortException; import at.asit.pdfover.gui.utils.ImageConverter; @@ -125,6 +126,7 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { this.fd_txtMobileNumber.bottom = new FormAttachment(100); this.fd_txtMobileNumber.right = new FormAttachment(100, -42); this.txtMobileNumber.setLayoutData(this.fd_txtMobileNumber); + this.txtMobileNumber.setToolTipText(Messages.getString("simple_config.ExampleNumber_ToolTip")); //$NON-NLS-1$ this.txtMobileNumberErrorMarker = new ErrorMarker(composite_2, SWT.NATIVE, null, "", this.txtMobileNumber); //$NON-NLS-1$ @@ -407,7 +409,7 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { this.proxyHostErrorMarker.setLayoutData(fd_marker); this.proxyHostErrorMarker.setVisible(false); this.txtProxyHost.setLayoutData(fd_txtProxyHost); - + this.txtProxyHost.setToolTipText(Messages.getString("simple_config.ProxyHost_ToolTip")); //$NON-NLS-1$ this.txtProxyHost.setMessage(Messages .getString("simple_config.ProxyHostTemplate")); //$NON-NLS-1$ @@ -450,7 +452,8 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { this.fd_txtProxyPort.right = new FormAttachment(100, -42); this.fd_txtProxyPort.bottom = new FormAttachment(100); this.txtProxyPort.setLayoutData(this.fd_txtProxyPort); - + this.txtProxyPort.setToolTipText(Messages.getString("simple_config.ProxyPort_ToolTip")); //$NON-NLS-1$ + FontData[] fD_txtProxyPort = this.txtProxyPort.getFont().getFontData(); fD_txtProxyPort[0].setHeight(Constants.TEXT_SIZE_NORMAL); this.txtProxyPort.setFont(new Font(Display.getCurrent(), @@ -711,7 +714,7 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { } catch (Exception ex) { log.error("processEmblemChanged: ", ex); //$NON-NLS-1$ ErrorDialog dialog = new ErrorDialog(getShell(), - Messages.getString("error.FailedToLoadEmblem"), false); //$NON-NLS-1$ + Messages.getString("error.FailedToLoadEmblem"), ERROR_BUTTONS.OK); //$NON-NLS-1$ dialog.open(); } } @@ -865,7 +868,7 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { log.error("Failed to load emblem: ", e1); //$NON-NLS-1$ ErrorDialog dialog = new ErrorDialog( getShell(), - Messages.getString("error.FailedToLoadEmblem"), false); //$NON-NLS-1$ + Messages.getString("error.FailedToLoadEmblem"), ERROR_BUTTONS.OK); //$NON-NLS-1$ dialog.open(); } } @@ -892,10 +895,17 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { * () */ @Override - public void validateSettings() throws Exception { - this.plainMobileNumberSetter(); + public void validateSettings(int resumeFrom) throws Exception { + switch (resumeFrom) { + case 0: + this.plainMobileNumberSetter(); + // Fall through + case 1: + this.plainProxyHostSetter(); + // Fall through + case 2: + this.plainProxyPortSetter(); + } //this.plainEmblemSetter(this.emblemFile); - this.plainProxyHostSetter(); - this.plainProxyPortSetter(); } } |