diff options
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration')
4 files changed, 2794 insertions, 0 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java new file mode 100644 index 00000000..5898c062 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java @@ -0,0 +1,1116 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.composites.configuration; + +// Imports +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Scale; +import org.eclipse.swt.widgets.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.commons.Constants; +import at.asit.pdfover.commons.Profile; +import at.asit.pdfover.gui.composites.ConfigurationComposite; +import at.asit.pdfover.gui.controls.ErrorDialog; +import at.asit.pdfover.gui.controls.ErrorMarker; +import at.asit.pdfover.gui.controls.Dialog.BUTTONS; +import at.asit.pdfover.gui.exceptions.InvalidPortException; +import at.asit.pdfover.gui.exceptions.OutputfolderDoesntExistException; +import at.asit.pdfover.gui.exceptions.OutputfolderNotADirectoryException; +import at.asit.pdfover.commons.Messages; +import at.asit.pdfover.gui.workflow.config.ConfigManipulator; +import at.asit.pdfover.gui.workflow.config.ConfigurationContainer; +import at.asit.pdfover.gui.workflow.config.PersistentConfigProvider; +import at.asit.pdfover.gui.workflow.states.State; +import at.asit.pdfover.signator.BKUs; +import at.asit.pdfover.signator.SignaturePosition; + +/** + * Composite for advanced configuration + * + * Contains the simple configuration composite + */ +public class AdvancedConfigurationComposite extends BaseConfigurationComposite { + + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory.getLogger(AdvancedConfigurationComposite.class); + + private ConfigurationComposite configurationComposite; + + private Group grpSignatur; + private Group grpPlaceholder; + Button btnAutomatischePositionierung; + Button btnPdfACompat; + Button btnPlatzhalterVerwenden; + Button btnSignatureFieldsUsage; + Button btnEnablePlaceholderUsage; + private Label lblTransparenz; + private Label lblTransparenzLinks; + private Label lblTransparenzRechts; + Scale sclTransparenz; + + private Group grpBkuAuswahl; + Combo cmbBKUAuswahl; + List<String> bkuStrings; + Button btnKeystoreEnabled; + + private final Group grpSpeicherort; + private final Label lblDefaultOutputFolder; + Text txtOutputFolder; + private final Button btnBrowse; + private final Label lblSaveFilePostFix; + private final Text txtSaveFilePostFix; + + private final Group grpLocaleAuswahl; + Combo cmbLocaleAuswahl; + + private Group grpUpdateCheck; + Button btnUpdateCheck; + + private Group grpProxy; + private Label lblProxyHost; + private Text txtProxyHost; + private ErrorMarker proxyHostErrorMarker; + private Label lblProxyPort; + private Text txtProxyPort; + private ErrorMarker txtProxyPortErrorMarker; + FormData fd_txtProxyPort; + FormData fd_txtProxyPortErrorMarker; + + /** + * @param parent + * @param style + * @param state + * @param container + * @param config + */ + public AdvancedConfigurationComposite(Composite parent, int style, State state, ConfigurationContainer container, + ConfigurationComposite config) { + super(parent, style, state, container); + this.configurationComposite = config; + setLayout(new FormLayout()); + + this.grpSignatur = new Group(this, SWT.NONE); + FormLayout layout = new FormLayout(); + layout.marginHeight = 10; + layout.marginWidth = 5; + this.grpSignatur.setLayout(layout); + FormData fd_grpSignatur = new FormData(); + fd_grpSignatur.top = new FormAttachment(0, 5); + fd_grpSignatur.right = new FormAttachment(100, -5); + fd_grpSignatur.left = new FormAttachment(0, 5); + this.grpSignatur.setLayoutData(fd_grpSignatur); + + FontData[] fD_grpSignaturPosition = this.grpSignatur.getFont().getFontData(); + fD_grpSignaturPosition[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.grpSignatur.setFont(new Font(Display.getCurrent(), fD_grpSignaturPosition[0])); + + this.btnAutomatischePositionierung = new Button(this.grpSignatur, SWT.CHECK); + FormData fd_btnAutomatischePositionierung = new FormData(); + fd_btnAutomatischePositionierung.right = new FormAttachment(100, -5); + fd_btnAutomatischePositionierung.top = new FormAttachment(0); + fd_btnAutomatischePositionierung.left = new FormAttachment(0, 5); + this.btnAutomatischePositionierung.setLayoutData(fd_btnAutomatischePositionierung); + + FontData[] fD_btnAutomatischePositionierung = this.btnAutomatischePositionierung.getFont().getFontData(); + fD_btnAutomatischePositionierung[0].setHeight(Constants.TEXT_SIZE_BUTTON); + this.btnAutomatischePositionierung.setFont(new Font(Display.getCurrent(), fD_btnAutomatischePositionierung[0])); + + this.btnAutomatischePositionierung.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + AdvancedConfigurationComposite.this.performPositionSelection( + AdvancedConfigurationComposite.this.btnAutomatischePositionierung.getSelection()); + } + }); + + this.btnPdfACompat = new Button(this.grpSignatur, SWT.CHECK); + FormData fd_btnPdfACompat = new FormData(); + fd_btnPdfACompat.right = new FormAttachment(100, -5); + fd_btnPdfACompat.top = new FormAttachment(this.btnAutomatischePositionierung, 5); + fd_btnPdfACompat.left = new FormAttachment(0, 5); + this.btnPdfACompat.setLayoutData(fd_btnPdfACompat); + + FontData[] fD_btnPdfACompat = this.btnPdfACompat.getFont().getFontData(); + fD_btnPdfACompat[0].setHeight(Constants.TEXT_SIZE_BUTTON); + this.btnPdfACompat.setFont(new Font(Display.getCurrent(), fD_btnPdfACompat[0])); + + this.btnPdfACompat.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + AdvancedConfigurationComposite.this + .performPdfACompatSelection(AdvancedConfigurationComposite.this.btnPdfACompat.getSelection()); + } + }); + + this.lblTransparenz = new Label(this.grpSignatur, SWT.HORIZONTAL); + FormData fd_lblTransparenz = new FormData(); + fd_lblTransparenz.top = new FormAttachment(this.btnPdfACompat, 5); + fd_lblTransparenz.left = new FormAttachment(0, 5); + this.lblTransparenz.setLayoutData(fd_lblTransparenz); + + FontData[] fD_lblTransparenz = this.lblTransparenz.getFont().getFontData(); + fD_lblTransparenz[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.lblTransparenz.setFont(new Font(Display.getCurrent(), fD_lblTransparenz[0])); + + this.lblTransparenzLinks = new Label(this.grpSignatur, SWT.HORIZONTAL); + FormData fd_lblTransparenzLinks = new FormData(); + fd_lblTransparenzLinks.top = new FormAttachment(this.lblTransparenz, 5); + fd_lblTransparenzLinks.left = new FormAttachment(0, 15); + this.lblTransparenzLinks.setLayoutData(fd_lblTransparenzLinks); + + FontData[] fD_lblTransparenzLinks = this.lblTransparenzLinks.getFont().getFontData(); + fD_lblTransparenzLinks[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.lblTransparenzLinks.setFont(new Font(Display.getCurrent(), fD_lblTransparenzLinks[0])); + + this.lblTransparenzRechts = new Label(this.grpSignatur, SWT.HORIZONTAL); + FormData fd_lblTransparenzRechts = new FormData(); + fd_lblTransparenzRechts.top = new FormAttachment(this.lblTransparenz, 5); + fd_lblTransparenzRechts.right = new FormAttachment(100, -5); + this.lblTransparenzRechts.setLayoutData(fd_lblTransparenzRechts); + + FontData[] fD_lblTransparenzRechts = this.lblTransparenzRechts.getFont().getFontData(); + fD_lblTransparenzRechts[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.lblTransparenzRechts.setFont(new Font(Display.getCurrent(), fD_lblTransparenzRechts[0])); + + this.sclTransparenz = new Scale(this.grpSignatur, SWT.HORIZONTAL); + FormData fd_sldTransparenz = new FormData(); + fd_sldTransparenz.right = new FormAttachment(this.lblTransparenzRechts, -5); + fd_sldTransparenz.top = new FormAttachment(this.lblTransparenz, 5); + fd_sldTransparenz.left = new FormAttachment(this.lblTransparenzLinks, 5); + this.sclTransparenz.setLayoutData(fd_sldTransparenz); + this.sclTransparenz.setMinimum(0); + this.sclTransparenz.setMaximum(255); + this.sclTransparenz.setIncrement(1); + this.sclTransparenz.setPageIncrement(10); + this.sclTransparenz.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + performPlaceholderTransparency(AdvancedConfigurationComposite.this.sclTransparenz.getSelection()); + } + }); + + this.grpPlaceholder = new Group(this, SWT.NONE); + FormLayout layout_grpPlaceholder = new FormLayout(); + layout_grpPlaceholder.marginHeight = 10; + layout_grpPlaceholder.marginWidth = 5; + this.grpPlaceholder.setLayout(layout_grpPlaceholder); + + FormData fd_grpPlaceholder = new FormData(); + fd_grpPlaceholder.top = new FormAttachment(this.grpSignatur, 5); + fd_grpPlaceholder.right = new FormAttachment(100, -5); + fd_grpPlaceholder.left = new FormAttachment(0, 5); + this.grpPlaceholder.setLayoutData(fd_grpPlaceholder); + + FontData[] fD_grpPlaceholder = this.grpPlaceholder.getFont().getFontData(); + fD_grpPlaceholder[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.grpPlaceholder.setFont(new Font(Display.getCurrent(), fD_grpPlaceholder[0])); + + this.btnEnablePlaceholderUsage = new Button(this.grpPlaceholder, SWT.CHECK); + FormData fd_btnEnablePlaceholderUsage = new FormData(); + fd_btnEnablePlaceholderUsage.right = new FormAttachment(100, -5); + fd_btnEnablePlaceholderUsage.top = new FormAttachment(0, 5); + fd_btnEnablePlaceholderUsage.left = new FormAttachment(0, 5); + this.btnEnablePlaceholderUsage.setLayoutData(fd_btnEnablePlaceholderUsage); + + FontData[] fD_btnEnablePlaceholderUsage = this.btnEnablePlaceholderUsage.getFont().getFontData(); + fD_btnEnablePlaceholderUsage[0].setHeight(Constants.TEXT_SIZE_BUTTON); + this.btnEnablePlaceholderUsage.setFont(new Font(Display.getCurrent(), fD_btnEnablePlaceholderUsage[0])); + + this.btnEnablePlaceholderUsage.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + AdvancedConfigurationComposite.this.performEnableUsePlaceholder( + AdvancedConfigurationComposite.this.btnEnablePlaceholderUsage.getSelection()); + + } + }); + + this.btnPlatzhalterVerwenden = new Button(this.grpPlaceholder, SWT.RADIO); + FormData fd_btnPlatzhalterVerwenden = new FormData(); + fd_btnPlatzhalterVerwenden.right = new FormAttachment(100, -5); + fd_btnPlatzhalterVerwenden.top = new FormAttachment(this.btnEnablePlaceholderUsage, 5); + fd_btnPlatzhalterVerwenden.left = new FormAttachment(0, 5); + this.btnPlatzhalterVerwenden.setLayoutData(fd_btnPlatzhalterVerwenden); + + FontData[] fD_btnPlatzhalterVerwenden = this.btnPlatzhalterVerwenden.getFont().getFontData(); + fD_btnPlatzhalterVerwenden[0].setHeight(Constants.TEXT_SIZE_BUTTON); + this.btnPlatzhalterVerwenden.setFont(new Font(Display.getCurrent(), fD_btnPlatzhalterVerwenden[0])); + + this.btnPlatzhalterVerwenden.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + AdvancedConfigurationComposite.this.performUseMarkerSelection( + AdvancedConfigurationComposite.this.btnPlatzhalterVerwenden.getSelection()); + } + }); + + this.btnSignatureFieldsUsage = new Button(this.grpPlaceholder, SWT.RADIO); + FormData fd_btnSignatureFieldsUsage = new FormData(); + fd_btnSignatureFieldsUsage.right = new FormAttachment(100, -5); + fd_btnSignatureFieldsUsage.top = new FormAttachment(this.btnPlatzhalterVerwenden, 5); + fd_btnSignatureFieldsUsage.left = new FormAttachment(0, 5); + this.btnSignatureFieldsUsage.setLayoutData(fd_btnSignatureFieldsUsage); + + FontData[] fD_btnSignatureFieldsUsage = this.btnSignatureFieldsUsage.getFont().getFontData(); + fD_btnSignatureFieldsUsage[0].setHeight(Constants.TEXT_SIZE_BUTTON); + this.btnSignatureFieldsUsage.setFont(new Font(Display.getCurrent(), fD_btnSignatureFieldsUsage[0])); + + this.btnSignatureFieldsUsage.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + AdvancedConfigurationComposite.this.performUseSignatureFieldsSelection( + AdvancedConfigurationComposite.this.btnSignatureFieldsUsage.getSelection()); + } + }); + + this.grpBkuAuswahl = new Group(this, SWT.NONE); + layout = new FormLayout(); + layout.marginHeight = 10; + layout.marginWidth = 5; + this.grpBkuAuswahl.setLayout(layout); + FormData fd_grpBkuAuswahl = new FormData(); + fd_grpBkuAuswahl.top = new FormAttachment(this.grpPlaceholder, 5); + fd_grpBkuAuswahl.left = new FormAttachment(0, 5); + fd_grpBkuAuswahl.right = new FormAttachment(100, -5); + this.grpBkuAuswahl.setLayoutData(fd_grpBkuAuswahl); + + FontData[] fD_grpBkuAuswahl = this.grpBkuAuswahl.getFont().getFontData(); + fD_grpBkuAuswahl[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.grpBkuAuswahl.setFont(new Font(Display.getCurrent(), fD_grpBkuAuswahl[0])); + + this.cmbBKUAuswahl = new Combo(this.grpBkuAuswahl, SWT.READ_ONLY); + FormData fd_cmbBKUAuswahl = new FormData(); + fd_cmbBKUAuswahl.right = new FormAttachment(100, -5); + fd_cmbBKUAuswahl.top = new FormAttachment(0); + fd_cmbBKUAuswahl.left = new FormAttachment(0, 5); + this.cmbBKUAuswahl.setLayoutData(fd_cmbBKUAuswahl); + + FontData[] fD_cmbBKUAuswahl = this.cmbBKUAuswahl.getFont().getFontData(); + fD_cmbBKUAuswahl[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.cmbBKUAuswahl.setFont(new Font(Display.getCurrent(), fD_cmbBKUAuswahl[0])); + + int blen = BKUs.values().length; + this.bkuStrings = new ArrayList<>(blen); + for (int i = 0; i < blen; i++) { + String lookup = "BKU." + BKUs.values()[i].toString(); //$NON-NLS-1$ + String text = Messages.getString(lookup); + this.bkuStrings.add(text); + this.cmbBKUAuswahl.add(text); + } + this.cmbBKUAuswahl.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + int selectionIndex = getBKUElementIndex( + AdvancedConfigurationComposite.this.configurationContainer.getDefaultBKU()); + if (AdvancedConfigurationComposite.this.cmbBKUAuswahl.getSelectionIndex() != selectionIndex) { + selectionIndex = AdvancedConfigurationComposite.this.cmbBKUAuswahl.getSelectionIndex(); + performBKUSelectionChanged( + AdvancedConfigurationComposite.this.cmbBKUAuswahl.getItem(selectionIndex)); + } + } + }); + + this.btnKeystoreEnabled = new Button(this.grpBkuAuswahl, SWT.CHECK); + FormData fd_btnKeystoreEnabled = new FormData(); + fd_btnKeystoreEnabled.right = new FormAttachment(100, -5); + fd_btnKeystoreEnabled.top = new FormAttachment(this.cmbBKUAuswahl, 5); + fd_btnKeystoreEnabled.left = new FormAttachment(0, 5); + this.btnKeystoreEnabled.setLayoutData(fd_btnKeystoreEnabled); + + FontData[] fD_btnKeystoreEnabled = this.btnKeystoreEnabled.getFont().getFontData(); + fD_btnKeystoreEnabled[0].setHeight(Constants.TEXT_SIZE_BUTTON); + this.btnKeystoreEnabled.setFont(new Font(Display.getCurrent(), fD_btnKeystoreEnabled[0])); + + this.btnKeystoreEnabled.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + AdvancedConfigurationComposite.this.performKeystoreEnabledSelection( + AdvancedConfigurationComposite.this.btnKeystoreEnabled.getSelection()); + } + }); + + this.grpSpeicherort = new Group(this, SWT.NONE); + GridLayout gl_grpSpeicherort = new GridLayout(3, false); + grpSpeicherort.setLayout(gl_grpSpeicherort); + FormData fd_grpSpeicherort = new FormData(); + fd_grpSpeicherort.left = new FormAttachment(0,5); + fd_grpSpeicherort.top = new FormAttachment(this.grpBkuAuswahl, 5); + fd_grpSpeicherort.right = new FormAttachment(100, -5); + this.grpSpeicherort.setLayoutData(fd_grpSpeicherort); + + + FontData[] fD_grpSpeicherort = this.grpSpeicherort.getFont().getFontData(); + fD_grpSpeicherort[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.grpSpeicherort.setFont(new Font(Display.getCurrent(), fD_grpSpeicherort[0])); + + this.lblDefaultOutputFolder = new Label(this.grpSpeicherort, SWT.NONE); + + FontData[] fD_lblDefaultOutputFolder = this.lblDefaultOutputFolder.getFont().getFontData(); + fD_lblDefaultOutputFolder[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.lblDefaultOutputFolder.setFont(new Font(Display.getCurrent(), fD_lblDefaultOutputFolder[0])); + + this.txtOutputFolder = new Text(this.grpSpeicherort, SWT.BORDER); + GridData gd_txtOutputFolder = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); + txtOutputFolder.setLayoutData(gd_txtOutputFolder); + + FontData[] fD_txtOutputFolder = this.txtOutputFolder.getFont().getFontData(); + fD_txtOutputFolder[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.txtOutputFolder.setFont(new Font(Display.getCurrent(), fD_txtOutputFolder[0])); + + this.txtOutputFolder.addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + performOutputFolderChanged(AdvancedConfigurationComposite.this.txtOutputFolder.getText()); + } + }); + fD_txtOutputFolder[0].setHeight(Constants.TEXT_SIZE_NORMAL); + + this.btnBrowse = new Button(this.grpSpeicherort, SWT.NONE); + btnBrowse.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + + FontData[] fD_btnBrowse = this.btnBrowse.getFont().getFontData(); + fD_btnBrowse[0].setHeight(Constants.TEXT_SIZE_BUTTON); + this.btnBrowse.setFont(new Font(Display.getCurrent(), fD_btnBrowse[0])); + this.btnBrowse.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + DirectoryDialog dlg = new DirectoryDialog(AdvancedConfigurationComposite.this.getShell()); + + // Set the initial filter path according + // to anything they've selected or typed in + dlg.setFilterPath(AdvancedConfigurationComposite.this.txtOutputFolder.getText()); + + // Change the title bar text + dlg.setText(Messages.getString("advanced_config.OutputFolder.Dialog_Title")); //$NON-NLS-1$ + + // Customizable message displayed in the dialog + dlg.setMessage(Messages.getString("advanced_config.OutputFolder.Dialog")); //$NON-NLS-1$ + + // Calling open() will open and run the dialog. + // It will return the selected directory, or + // null if user cancels + String dir = dlg.open(); + if (dir != null) { + // Set the text box to the new selection + performOutputFolderChanged(dir); + } + } + }); + + this.lblSaveFilePostFix = new Label(this.grpSpeicherort, SWT.NONE); + lblSaveFilePostFix.setText(Messages.getString("AdvancedConfigurationComposite.lblSaveFilePostFix.text")); + + FontData[] fD_lblSaveFilePostFix = this.lblSaveFilePostFix.getFont().getFontData(); + fD_lblSaveFilePostFix[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.lblSaveFilePostFix.setFont(new Font(Display.getCurrent(), fD_lblSaveFilePostFix[0])); + + this.txtSaveFilePostFix = new Text(this.grpSpeicherort, SWT.BORDER); + GridData gd_txtSaveFilePostFix = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); + + txtSaveFilePostFix.setLayoutData(gd_txtSaveFilePostFix); + + FontData[] fD_txtPostFix = this.txtSaveFilePostFix.getFont().getFontData(); + fD_txtPostFix[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.txtSaveFilePostFix.setFont(new Font(Display.getCurrent(), fD_txtPostFix[0])); + + this.txtSaveFilePostFix.addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + performPostFixChanged(AdvancedConfigurationComposite.this.txtSaveFilePostFix.getText()); + } + }); + new Label(grpSpeicherort, SWT.NONE); + fD_lblSaveFilePostFix[0].setHeight(Constants.TEXT_SIZE_NORMAL); + fD_txtPostFix[0].setHeight(Constants.TEXT_SIZE_NORMAL); + + this.grpLocaleAuswahl = new Group(this, SWT.NONE); + FormLayout layout_grpLocaleAuswahl = new FormLayout(); + layout_grpLocaleAuswahl.marginHeight = 10; + layout_grpLocaleAuswahl.marginWidth = 5; + this.grpLocaleAuswahl.setLayout(layout_grpLocaleAuswahl); + FormData fd_grpLocaleAuswahl = new FormData(); + fd_grpLocaleAuswahl.top = new FormAttachment(grpSpeicherort, 5); + fd_grpLocaleAuswahl.left = new FormAttachment(0, 5); + fd_grpLocaleAuswahl.right = new FormAttachment(100, -5); + this.grpLocaleAuswahl.setLayoutData(fd_grpLocaleAuswahl); + + FontData[] fD_grpLocaleAuswahl = this.grpLocaleAuswahl.getFont().getFontData(); + fD_grpLocaleAuswahl[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.grpLocaleAuswahl.setFont(new Font(Display.getCurrent(), fD_grpLocaleAuswahl[0])); + + this.cmbLocaleAuswahl = new Combo(this.grpLocaleAuswahl, SWT.READ_ONLY); + FormData fd_cmbLocaleAuswahl = new FormData(); + fd_cmbLocaleAuswahl.right = new FormAttachment(100, -5); + fd_cmbLocaleAuswahl.top = new FormAttachment(0); + fd_cmbLocaleAuswahl.left = new FormAttachment(0, 5); + this.cmbLocaleAuswahl.setLayoutData(fd_cmbLocaleAuswahl); + + FontData[] fD_cmbLocaleAuswahl = this.cmbLocaleAuswahl.getFont().getFontData(); + fD_cmbLocaleAuswahl[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.cmbLocaleAuswahl.setFont(new Font(Display.getCurrent(), fD_cmbLocaleAuswahl[0])); + + String[] localeStrings = new String[Constants.SUPPORTED_LOCALES.length]; + for (int i = 0; i < Constants.SUPPORTED_LOCALES.length; ++i) { + localeStrings[i] = Constants.SUPPORTED_LOCALES[i].getDisplayLanguage(Constants.SUPPORTED_LOCALES[i]); + } + this.cmbLocaleAuswahl.setItems(localeStrings); + this.cmbLocaleAuswahl.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Locale currentLocale = AdvancedConfigurationComposite.this.configurationContainer.getLocale(); + Locale selectedLocale = Constants.SUPPORTED_LOCALES[AdvancedConfigurationComposite.this.cmbLocaleAuswahl + .getSelectionIndex()]; + if (!currentLocale.equals(selectedLocale)) { + performLocaleSelectionChanged(selectedLocale); + } + } + }); + + this.grpUpdateCheck = new Group(this, SWT.NONE); + FormLayout layout_grpUpdateCheck = new FormLayout(); + layout_grpUpdateCheck.marginHeight = 10; + layout_grpUpdateCheck.marginWidth = 5; + this.grpUpdateCheck.setLayout(layout_grpUpdateCheck); + FormData fd_grpUpdateCheck = new FormData(); + fd_grpUpdateCheck.top = new FormAttachment(this.grpLocaleAuswahl, 5); + fd_grpUpdateCheck.left = new FormAttachment(0, 5); + fd_grpUpdateCheck.right = new FormAttachment(100, -5); + this.grpUpdateCheck.setLayoutData(fd_grpUpdateCheck); + + FontData[] fD_grpUpdateCheck = this.grpUpdateCheck.getFont().getFontData(); + fD_grpUpdateCheck[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.grpUpdateCheck.setFont(new Font(Display.getCurrent(), fD_grpUpdateCheck[0])); + + this.btnUpdateCheck = new Button(this.grpUpdateCheck, SWT.CHECK); + FormData fd_btnUpdateCheck = new FormData(); + fd_btnUpdateCheck.right = new FormAttachment(100, -5); + fd_btnUpdateCheck.top = new FormAttachment(0); + fd_btnUpdateCheck.left = new FormAttachment(0, 5); + this.btnUpdateCheck.setLayoutData(fd_btnUpdateCheck); + + FontData[] fD_btnUpdateCheck = this.btnUpdateCheck.getFont().getFontData(); + fD_btnUpdateCheck[0].setHeight(Constants.TEXT_SIZE_BUTTON); + this.btnUpdateCheck.setFont(new Font(Display.getCurrent(), fD_btnUpdateCheck[0])); + + this.btnUpdateCheck.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + AdvancedConfigurationComposite.this + .performUpdateCheckSelection(AdvancedConfigurationComposite.this.btnUpdateCheck.getSelection()); + } + }); + + this.grpProxy = new Group(this, SWT.NONE); + FormData fd_grpProxy = new FormData(); + fd_grpProxy.right = new FormAttachment(100, -5); + fd_grpProxy.top = new FormAttachment(this.grpUpdateCheck, 5); + fd_grpProxy.left = new FormAttachment(0, 5); + this.grpProxy.setLayoutData(fd_grpProxy); + this.grpProxy.setLayout(new GridLayout(2, false)); + + FontData[] fD_grpProxy = this.grpProxy.getFont().getFontData(); + fD_grpProxy[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.grpProxy.setFont(new Font(Display.getCurrent(), fD_grpProxy[0])); + + this.lblProxyHost = new Label(this.grpProxy, SWT.NONE); + GridData gd_lblProxyHost = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_lblProxyHost.widthHint = 66; + this.lblProxyHost.setLayoutData(gd_lblProxyHost); + this.lblProxyHost.setBounds(0, 0, 57, 15); + + FontData[] fD_lblProxyHost = this.lblProxyHost.getFont().getFontData(); + fD_lblProxyHost[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.lblProxyHost.setFont(new Font(Display.getCurrent(), fD_lblProxyHost[0])); + + Composite compProxyHostContainer = new Composite(this.grpProxy, SWT.NONE); + compProxyHostContainer.setLayout(new FormLayout()); + compProxyHostContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + this.txtProxyHost = new Text(compProxyHostContainer, SWT.BORDER); + FormData fd_txtProxyHost = new FormData(); + fd_txtProxyHost.right = new FormAttachment(100, -42); + fd_txtProxyHost.top = new FormAttachment(0); + fd_txtProxyHost.left = new FormAttachment(0, 5); + + FontData[] fD_txtProxyHost = this.txtProxyHost.getFont().getFontData(); + fD_txtProxyHost[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.txtProxyHost.setFont(new Font(Display.getCurrent(), fD_txtProxyHost[0])); + + this.proxyHostErrorMarker = new ErrorMarker(compProxyHostContainer, SWT.NONE, ""); //$NON-NLS-1$ + + FormData fd_proxyHostErrorMarker = new FormData(); + fd_proxyHostErrorMarker.left = new FormAttachment(100, -32); + fd_proxyHostErrorMarker.right = new FormAttachment(100); + fd_proxyHostErrorMarker.top = new FormAttachment(0); + fd_proxyHostErrorMarker.bottom = new FormAttachment(0, 32); + + this.proxyHostErrorMarker.setLayoutData(fd_proxyHostErrorMarker); + this.proxyHostErrorMarker.setVisible(false); + this.txtProxyHost.setLayoutData(fd_txtProxyHost); + + this.txtProxyHost.addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + processProxyHostChanged(); + } + }); + + this.txtProxyHost.addTraverseListener(e -> { + if (e.detail == SWT.TRAVERSE_RETURN) { + processProxyHostChanged(); + } + }); + + this.lblProxyPort = new Label(this.grpProxy, SWT.NONE); + this.lblProxyPort.setBounds(0, 0, 57, 15); + + FontData[] fD_lblProxyPort = this.lblProxyPort.getFont().getFontData(); + fD_lblProxyPort[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.lblProxyPort.setFont(new Font(Display.getCurrent(), fD_lblProxyPort[0])); + + Composite compProxyPortContainer = new Composite(this.grpProxy, SWT.NONE); + compProxyPortContainer.setLayout(new FormLayout()); + compProxyPortContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + + this.txtProxyPort = new Text(compProxyPortContainer, SWT.BORDER); + this.fd_txtProxyPort = new FormData(); + this.fd_txtProxyPort.top = new FormAttachment(0, 0); + this.fd_txtProxyPort.left = new FormAttachment(0, 5); + this.fd_txtProxyPort.right = new FormAttachment(100, -42); + this.txtProxyPort.setLayoutData(this.fd_txtProxyPort); + + FontData[] fD_txtProxyPort = this.txtProxyPort.getFont().getFontData(); + fD_txtProxyPort[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.txtProxyPort.setFont(new Font(Display.getCurrent(), fD_txtProxyPort[0])); + + this.txtProxyPort.addTraverseListener(e -> { + if (e.detail == SWT.TRAVERSE_RETURN) { + processProxyPortChanged(); + } + }); + + this.txtProxyPortErrorMarker = new ErrorMarker(compProxyPortContainer, SWT.NONE, ""); //$NON-NLS-1$ + this.fd_txtProxyPortErrorMarker = new FormData(); + this.fd_txtProxyPortErrorMarker.left = new FormAttachment(100, -32); + this.fd_txtProxyPortErrorMarker.right = new FormAttachment(100); + this.fd_txtProxyPortErrorMarker.top = new FormAttachment(0); + this.fd_txtProxyPortErrorMarker.bottom = new FormAttachment(0, 32); + this.txtProxyPortErrorMarker.setLayoutData(this.fd_txtProxyPortErrorMarker); + this.txtProxyPortErrorMarker.setVisible(false); + + this.txtProxyPort.addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + processProxyPortChanged(); + } + }); + reloadResources(); + } + + private void performPostFixChanged(String postfix) { + + log.debug("Save file postfix changed to : {}", postfix); //$NON-NLS-1$ + this.configurationContainer.setSaveFilePostFix(postfix); + AdvancedConfigurationComposite.this.txtSaveFilePostFix.setText(postfix); + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#signerChanged() + */ + @Override + protected void signerChanged() { + // Nothing to do here (yet) + } + + void performOutputFolderChanged(String foldername) { + log.debug("Selected Output folder: {}", foldername); //$NON-NLS-1$ + this.configurationContainer.setOutputFolder(foldername); + AdvancedConfigurationComposite.this.txtOutputFolder.setText(foldername); + } + + int getBKUElementIndex(BKUs bku) { + String lookup = "BKU." + bku.toString(); //$NON-NLS-1$ + String bkuName = Messages.getString(lookup); + + int i = this.bkuStrings.indexOf(bkuName); + if (i == -1) { + log.warn("NO BKU match for {}", bkuName); //$NON-NLS-1$ + return 0; + } + return i; + } + + void performBKUSelectionChanged(BKUs selected) { + log.debug("Selected BKU: {}", selected); //$NON-NLS-1$ + this.configurationContainer.setDefaultBKU(selected); + this.cmbBKUAuswahl.select(this.getBKUElementIndex(selected)); + } + + void performBKUSelectionChanged(String selected) { + try { + BKUs bkuvalue = resolveBKU(selected); + 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"), BUTTONS.OK); //$NON-NLS-1$ + dialog.open(); + } + } + + BKUs resolveBKU(String localizedBKU) { + int blen = BKUs.values().length; + + for (int i = 0; i < blen; i++) { + String lookup = "BKU." + BKUs.values()[i].toString(); //$NON-NLS-1$ + if (Messages.getString(lookup).equals(localizedBKU)) { + return BKUs.values()[i]; + } + } + + return BKUs.NONE; + } + + int getLocaleElementIndex(Locale locale) { + for (int i = 0; i < Constants.SUPPORTED_LOCALES.length; i++) { + if (Constants.SUPPORTED_LOCALES[i].equals(locale)) { + log.debug("Locale: {} IDX: {}", locale, i); //$NON-NLS-1$ //$NON-NLS-2$ + return i; + } + } + + log.warn("NO Locale match for {}", locale); //$NON-NLS-1$ + return 0; + } + + void performLocaleSelectionChanged(Locale selected) { + log.debug("Selected Locale: {}", selected); //$NON-NLS-1$ + this.configurationContainer.setLocale(selected); + this.cmbLocaleAuswahl.select(this.getLocaleElementIndex(selected)); + } + + void performPositionSelection(boolean automatic) { + log.debug("Selected Position: {}", automatic); //$NON-NLS-1$ + SignaturePosition pos = automatic ? new SignaturePosition() : null; + this.configurationContainer.setDefaultSignaturePosition(pos); + this.btnAutomatischePositionierung.setSelection(automatic); + } + + void performUseMarkerSelection(boolean useMarker) { + this.configurationContainer.setUseMarker(useMarker); + this.btnPlatzhalterVerwenden.setSelection(useMarker); + } + + void performUseSignatureFieldsSelection(boolean useFields) { + this.configurationContainer.setUseSignatureFields(useFields); + this.btnSignatureFieldsUsage.setSelection(useFields); + } + + void performEnableUsePlaceholder(boolean enable) { + this.btnPlatzhalterVerwenden.setEnabled(enable); + this.btnSignatureFieldsUsage.setEnabled(enable); + this.configurationContainer.setEnablePlaceholderUsage(enable); + this.btnEnablePlaceholderUsage.setSelection(enable); + } + + void performPdfACompatSelection(boolean compat) { + this.configurationContainer.setSignaturePdfACompat(compat); + this.btnPdfACompat.setSelection(compat); + } + + void performKeystoreEnabledSelection(boolean enabled) { + this.configurationContainer.setKeyStoreEnabled(enabled); + this.btnKeystoreEnabled.setSelection(enabled); + this.configurationComposite.keystoreEnabled(enabled); + + int ksIndex = getBKUElementIndex(BKUs.KS); + String ksText = this.bkuStrings.get(ksIndex); + if (enabled) { + if (!this.cmbBKUAuswahl.getItem(ksIndex).equals(ksText)) + this.cmbBKUAuswahl.add(ksText, ksIndex); + } else { + int i = this.cmbBKUAuswahl.indexOf(ksText); + if (i != -1) { + if (this.cmbBKUAuswahl.getSelectionIndex() == i) + performBKUSelectionChanged(BKUs.NONE); + this.cmbBKUAuswahl.remove(i); + } + } + } + + void performPlaceholderTransparency(int transparency) { + this.configurationContainer.setPlaceholderTransparency(transparency); + } + + void performUpdateCheckSelection(boolean checkUpdate) { + this.configurationContainer.setUpdateCheck(checkUpdate); + this.btnUpdateCheck.setSelection(checkUpdate); + } + + void processProxyHostChanged() { + try { + this.proxyHostErrorMarker.setVisible(false); + plainProxyHostSetter(); + } catch (Exception ex) { + this.proxyHostErrorMarker.setVisible(true); + this.proxyHostErrorMarker.setToolTipText(ex.getMessage()); + log.error("processProxyHost: ", ex); //$NON-NLS-1$ + } + } + + /** + * + */ + private void plainProxyHostSetter() { + String host = this.txtProxyHost.getText(); + this.configurationContainer.setProxyHost(host); + } + + void processProxyPortChanged() { + try { + this.txtProxyPortErrorMarker.setVisible(false); + plainProxyPortSetter(); + } catch (Exception ex) { + this.txtProxyPortErrorMarker.setVisible(true); + this.txtProxyPortErrorMarker.setToolTipText(ex.getMessage()); + log.error("processProxyPort: ", ex); //$NON-NLS-1$ + } + } + + /** + * @throws InvalidPortException + */ + private void plainProxyPortSetter() throws InvalidPortException { + String portString = this.txtProxyPort.getText(); + int port = -1; + if (portString == null || portString.trim().isEmpty()) { + port = -1; + } else { + try { + port = Integer.parseInt(portString); + } catch (NumberFormatException e) { + throw new InvalidPortException(portString, e); + } + } + this.configurationContainer.setProxyPort(port); + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() + */ + @Override + public void doLayout() { + // Nothing to do here + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#initConfiguration( + * at.asit.pdfover.gui.workflow.config.PersistentConfigProvider) + */ + @Override + public void initConfiguration(PersistentConfigProvider provider) { + this.configurationContainer.setDefaultSignaturePosition(provider.getDefaultSignaturePositionPersistent()); + this.configurationContainer.setUseMarker(provider.getUseMarker()); + this.configurationContainer.setUseSignatureFields(provider.getUseSignatureFields()); + this.configurationContainer.setEnablePlaceholderUsage(provider.getEnablePlaceholderUsage()); + this.configurationContainer.setSignaturePdfACompat(provider.getSignaturePdfACompat()); + this.configurationContainer.setPlaceholderTransparency(provider.getPlaceholderTransparency()); + + this.configurationContainer.setDefaultBKU(provider.getDefaultBKUPersistent()); + this.configurationContainer.setKeyStoreEnabled(provider.getKeyStoreEnabledPersistent()); + + this.configurationContainer.setOutputFolder(provider.getDefaultOutputFolderPersistent()); + this.configurationContainer.setSaveFilePostFix(provider.getSaveFilePostFix()); + + this.configurationContainer.setLocale(provider.getLocale()); + + this.configurationContainer.setUpdateCheck(provider.getUpdateCheck()); + + this.configurationContainer.setProxyHost(provider.getProxyHostPersistent()); + try { + this.configurationContainer.setProxyPort(provider.getProxyPortPersistent()); + } catch (InvalidPortException e) { + log.error("Failed to set proxy port!", e); //$NON-NLS-1$ + } + this.configurationContainer.setProxyUser(provider.getProxyUserPersistent()); + this.configurationContainer.setProxyPass(provider.getProxyPassPersistent()); + this.configurationContainer.setSignatureProfile(Profile.getProfile(provider.getSignatureProfile())); + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#loadConfiguration() + */ + @Override + public void loadConfiguration() { + // load advanced settings + performBKUSelectionChanged(this.configurationContainer.getDefaultBKU()); + String outputFolder = this.configurationContainer.getOutputFolder(); + if (outputFolder != null) { + performOutputFolderChanged(outputFolder); + } + String postFix = this.configurationContainer.getSaveFilePostFix(); + if (postFix != null) { + performPostFixChanged(postFix); + } else { + performPostFixChanged(Constants.DEFAULT_POSTFIX); + } + SignaturePosition pos = this.configurationContainer.getDefaultSignaturePosition(); + performPositionSelection(pos != null && pos.useAutoPositioning()); + performUseMarkerSelection(this.configurationContainer.getUseMarker()); + performUseSignatureFieldsSelection(this.configurationContainer.getUseSignatureFields()); + performEnableUsePlaceholder(this.configurationContainer.getEnablePlaceholderUsage()); + this.sclTransparenz.setSelection(this.configurationContainer.getPlaceholderTransparency()); + performLocaleSelectionChanged(this.configurationContainer.getLocale()); + performPdfACompatSelection(this.configurationContainer.getSignaturePdfACompat()); + performKeystoreEnabledSelection(this.configurationContainer.getKeyStoreEnabled()); + performUpdateCheckSelection(this.configurationContainer.getUpdateCheck()); + performSetSignatureProfile(this.configurationContainer.getSignatureProfile()); + + int port = this.configurationContainer.getProxyPort(); + if (port > 0) { + this.txtProxyPort.setText(Integer.toString(port)); + } + + String host = this.configurationContainer.getProxyHost(); + if (host != null) { + this.txtProxyHost.setText(host); + } + + } + + /** + * @param profile + * + */ + public void performSetSignatureProfile(Profile profile) { + switch (profile) { + case INVISIBLE: + this.performPositionSelection(true); + this.btnAutomatischePositionierung.setEnabled(false); + this.btnEnablePlaceholderUsage.setEnabled(false); + this.performEnableUsePlaceholder(false); + break; + default: + this.btnAutomatischePositionierung.setEnabled(true); + this.btnEnablePlaceholderUsage.setEnabled(true); + } + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#storeConfiguration( + * at.asit.pdfover.gui.workflow.config.ConfigManipulator, + * at.asit.pdfover.gui.workflow.config.PersistentConfigProvider) + */ + @Override + public void storeConfiguration(ConfigManipulator store, PersistentConfigProvider provider) { + store.setDefaultSignaturePosition(this.configurationContainer.getDefaultSignaturePosition()); + store.setUseMarker(this.configurationContainer.getUseMarker()); + store.setUseSignatureFields(this.configurationContainer.getUseSignatureFields()); + store.setEnablePlaceholderUsage(this.configurationContainer.getEnablePlaceholderUsage()); + store.setSignaturePdfACompat(this.configurationContainer.getSignaturePdfACompat()); + store.setPlaceholderTransparency(this.configurationContainer.getPlaceholderTransparency()); + + store.setDefaultBKU(this.configurationContainer.getDefaultBKU()); + store.setKeyStoreEnabled(this.configurationContainer.getKeyStoreEnabled()); + + store.setDefaultOutputFolder(this.configurationContainer.getOutputFolder()); + store.setSaveFilePostFix(this.configurationContainer.getSaveFilePostFix()); + store.setLocale(this.configurationContainer.getLocale()); + + store.setUpdateCheck(this.configurationContainer.getUpdateCheck()); + + store.setSignatureProfile(this.configurationContainer.getSignatureProfile().name()); + + String hostOld = provider.getProxyHostPersistent(); + String hostNew = this.configurationContainer.getProxyHost(); + if (hostOld != null && !hostOld.isEmpty() && (hostNew == null || hostNew.isEmpty())) { + // Proxy has been removed, let's clear the system properties + // Otherwise, the proxy settings wouldn't get removed + System.clearProperty("http.proxyHost"); //$NON-NLS-1$ + System.clearProperty("https.proxyHost"); //$NON-NLS-1$ + } + store.setProxyHost(hostNew); + + int portOld = provider.getProxyPortPersistent(); + int portNew = this.configurationContainer.getProxyPort(); + if (portOld != -1 && portNew == -1) { + // cf. above + System.clearProperty("http.proxyPort"); //$NON-NLS-1$ + System.clearProperty("https.proxyPort"); //$NON-NLS-1$ + } + store.setProxyPort(portNew); + + String userOld = provider.getProxyUserPersistent(); + String userNew = this.configurationContainer.getProxyUser(); + if (userOld != null && !userOld.isEmpty() && (userNew == null || userNew.isEmpty())) { + // cf. above + System.clearProperty("http.proxyUser"); //$NON-NLS-1$ + System.clearProperty("https.proxyUser"); //$NON-NLS-1$ + } + store.setProxyUser(userNew); + + String passOld = provider.getProxyPassPersistent(); + String passNew = this.configurationContainer.getProxyPass(); + if (passOld != null && passNew == null) { + // cf. above + System.clearProperty("http.proxyPassword"); //$NON-NLS-1$ + System.clearProperty("https.proxyPassword"); //$NON-NLS-1$ + } + store.setProxyPass(passNew); + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#validateSettings() + */ + @Override + public void validateSettings(int resumeIndex) throws Exception { + + String foldername = this.configurationContainer.getOutputFolder(); + + switch (resumeIndex) { + case 0: + if (foldername != null && !foldername.isEmpty()) { + File outputFolder = new File(foldername); + if (!outputFolder.exists()) { + throw new OutputfolderDoesntExistException(outputFolder, 1); + } + if (!outputFolder.isDirectory()) { + throw new OutputfolderNotADirectoryException(outputFolder); + } + } + // Fall through + case 1: + this.plainProxyHostSetter(); + // Fall through + case 2: + this.plainProxyPortSetter(); + // Fall through + // case 3: + // this.plainProxyUserSetter(); + // // Fall through + // case 4: + // this.plainProxyPassSetter(); + } + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() + */ + @Override + public void reloadResources() { + this.grpSignatur.setText(Messages.getString("advanced_config.Signature_Title")); //$NON-NLS-1$ + this.btnAutomatischePositionierung.setText(Messages.getString("advanced_config.AutoPosition")); //$NON-NLS-1$ + this.btnAutomatischePositionierung.setToolTipText(Messages.getString("advanced_config.AutoPosition_ToolTip")); //$NON-NLS-1$ + this.grpPlaceholder.setText(Messages.getString("advanced_config.Placeholder_Title")); //$NON-NLS-1$ + this.btnPlatzhalterVerwenden.setText(Messages.getString("advanced_config.UseMarker")); //$NON-NLS-1$ + this.btnPlatzhalterVerwenden.setToolTipText(Messages.getString("advanced_config.UseMarker_ToolTip")); //$NON-NLS-1$ + this.btnSignatureFieldsUsage.setText(Messages.getString("advanced_config.UseSignatureFields")); //$NON-NLS-1$ + this.btnSignatureFieldsUsage.setToolTipText(Messages.getString("advanced_config.UseSignatureFields_ToolTip")); //$NON-NLS-1$ + this.btnEnablePlaceholderUsage.setText(Messages.getString("advanced_config.Placeholder_Enabled")); + this.btnPdfACompat.setText(Messages.getString("advanced_config.PdfACompat")); //$NON-NLS-1$ + this.btnPdfACompat.setToolTipText(Messages.getString("advanced_config.PdfACompat_ToolTip")); //$NON-NLS-1$ + this.lblTransparenz.setText(Messages.getString("advanced_config.SigPHTransparency")); //$NON-NLS-1$ + this.lblTransparenzLinks.setText(Messages.getString("advanced_config.SigPHTransparencyMin")); //$NON-NLS-1$ + this.lblTransparenzRechts.setText(Messages.getString("advanced_config.SigPHTransparencyMax")); //$NON-NLS-1$ + this.sclTransparenz.setToolTipText(Messages.getString("advanced_config.SigPHTransparencyTooltip")); //$NON-NLS-1$ + + this.grpBkuAuswahl.setText(Messages.getString("advanced_config.BKUSelection_Title")); //$NON-NLS-1$ + this.cmbBKUAuswahl.setToolTipText(Messages.getString("advanced_config.BKUSelection_ToolTip")); //$NON-NLS-1$ + this.btnKeystoreEnabled.setText(Messages.getString("advanced_config.KeystoreEnabled")); //$NON-NLS-1$ + this.btnKeystoreEnabled.setToolTipText(Messages.getString("advanced_config.KeystoreEnabled_ToolTip")); //$NON-NLS-1$ + + this.grpSpeicherort.setText(Messages.getString("advanced_config.OutputFolder_Title")); //$NON-NLS-1$ + this.lblDefaultOutputFolder.setText(Messages.getString("advanced_config.OutputFolder")); //$NON-NLS-1$ + this.txtOutputFolder.setToolTipText(Messages.getString("advanced_config.OutputFolder_ToolTip")); //$NON-NLS-1$ + this.btnBrowse.setText(Messages.getString("common.browse")); //$NON-NLS-1$ + + this.grpLocaleAuswahl.setText(Messages.getString("advanced_config.LocaleSelection_Title")); //$NON-NLS-1$ + this.cmbLocaleAuswahl.setToolTipText(Messages.getString("advanced_config.LocaleSelection_ToolTip")); //$NON-NLS-1$ + + this.grpUpdateCheck.setText(Messages.getString("advanced_config.UpdateCheck_Title")); //$NON-NLS-1$ + this.btnUpdateCheck.setText(Messages.getString("advanced_config.UpdateCheck")); //$NON-NLS-1$ + this.btnUpdateCheck.setToolTipText(Messages.getString("advanced_config.UpdateCheck_ToolTip")); //$NON-NLS-1$ + + this.grpProxy.setText(Messages.getString("advanced_config.Proxy_Title")); //$NON-NLS-1$ + this.lblProxyHost.setText(Messages.getString("advanced_config.ProxyHost")); //$NON-NLS-1$ + this.txtProxyHost.setToolTipText(Messages.getString("advanced_config.ProxyHost_ToolTip")); //$NON-NLS-1$ + this.txtProxyHost.setMessage(Messages.getString("advanced_config.ProxyHost_Template")); //$NON-NLS-1$ + this.lblProxyPort.setText(Messages.getString("advanced_config.ProxyPort")); //$NON-NLS-1$ + this.txtProxyPort.setToolTipText(Messages.getString("advanced_config.ProxyPort_ToolTip")); //$NON-NLS-1$ + this.txtProxyPort.setMessage(Messages.getString("advanced_config.ProxyPort_Template")); //$NON-NLS-1$ + // this.lblProxyUser.setText(Messages.getString("advanced_config.ProxyUser")); + // //$NON-NLS-1$ + // this.txtProxyUser.setToolTipText(Messages + // .getString("advanced_config.ProxyUser_ToolTip")); //$NON-NLS-1$ + // this.txtProxyUser.setMessage(Messages + // .getString("advanced_config.ProxyUser_Template")); //$NON-NLS-1$ + // this.lblProxyPass.setText(Messages.getString("advanced_config.ProxyPass")); + // //$NON-NLS-1$ + // this.txtProxyPass.setToolTipText(Messages + // .getString("advanced_config.ProxyPass_ToolTip")); //$NON-NLS-1$ + // this.txtProxyPass.setMessage(Messages + // .getString("advanced_config.ProxyPass_Template")); //$NON-NLS-1$ + } +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/BaseConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/BaseConfigurationComposite.java new file mode 100644 index 00000000..5af5bcf3 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/BaseConfigurationComposite.java @@ -0,0 +1,105 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.composites.configuration; + + +import org.eclipse.swt.widgets.Composite; + +import at.asit.pdfover.gui.composites.StateComposite; +import at.asit.pdfover.gui.workflow.PDFSigner; +import at.asit.pdfover.gui.workflow.config.ConfigManipulator; +import at.asit.pdfover.gui.workflow.config.ConfigurationContainer; +import at.asit.pdfover.gui.workflow.config.PersistentConfigProvider; +import at.asit.pdfover.gui.workflow.states.State; + +/** + * Base class for configuration composites + */ +public abstract class BaseConfigurationComposite extends StateComposite { + + /** + * the configuration container + */ + protected ConfigurationContainer configurationContainer; + + /** + * The PDF Signer used to produce signature block preview + */ + protected PDFSigner signer; + + /** + * @return the signer + */ + public PDFSigner getSigner() { + return this.signer; + } + + /** + * @param signer the signer to set + */ + public void setSigner(PDFSigner signer) { + this.signer = signer; + this.signerChanged(); + } + + /** + * Called when the signer is changed! + */ + protected abstract void signerChanged(); + + /** + * @param parent + * @param style + * @param state + * @param configuration + */ + public BaseConfigurationComposite(Composite parent, int style, State state, ConfigurationContainer configuration) { + super(parent, style, state); + this.configurationContainer = configuration; + } + + /** + * Initialize ConfigurationContainer from PersistentConfigProvider + * @param provider the PersistentConfigProvider to load config from + */ + public abstract void initConfiguration(PersistentConfigProvider provider); + + /** + * Load configuration from ConfigurationContainer + */ + public abstract void loadConfiguration(); + + /** + * Store configuration from ConfigurationContainer to ConfigManipulator + * @param store the ConfigManipulator to store config to + * @param provider the PersistentConfigProvider containing the old config + */ + public abstract void storeConfiguration(ConfigManipulator store, PersistentConfigProvider provider); + + /** + * Called before exit. + * 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(int resumeFrom) throws Exception; +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java new file mode 100644 index 00000000..f38213e3 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java @@ -0,0 +1,592 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.composites.configuration; + +// Imports +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.commons.Constants; +import at.asit.pdfover.gui.controls.Dialog.BUTTONS; +import at.asit.pdfover.gui.controls.ErrorDialog; +import at.asit.pdfover.gui.exceptions.CantLoadKeystoreException; +import at.asit.pdfover.gui.exceptions.KeystoreAliasDoesntExistException; +import at.asit.pdfover.gui.exceptions.KeystoreAliasNoKeyException; +import at.asit.pdfover.gui.exceptions.KeystoreDoesntExistException; +import at.asit.pdfover.gui.exceptions.KeystoreKeyPasswordException; +import at.asit.pdfover.commons.Messages; +import at.asit.pdfover.gui.workflow.config.ConfigManipulator; +import at.asit.pdfover.gui.workflow.config.ConfigurationContainer; +import at.asit.pdfover.gui.workflow.config.PersistentConfigProvider; +import at.asit.pdfover.gui.workflow.states.State; + +/** + * + */ +public class KeystoreConfigurationComposite extends BaseConfigurationComposite { + + /** + * SLF4J Logger instance + **/ + static final Logger log = LoggerFactory + .getLogger(KeystoreConfigurationComposite.class); + + private Group grpKeystore; + private Label lblKeystoreFile; + Text txtKeystoreFile; + private Button btnBrowse; + private Label lblKeystoreType; + Combo cmbKeystoreType; + private Label lblKeystoreStorePass; + Text txtKeystoreStorePass; + private Button btnLoad; + private Label lblKeystoreAlias; + Combo cmbKeystoreAlias; + private Label lblKeystoreKeyPass; + Text txtKeystoreKeyPass; + + Map<String, String> keystoreTypes; + private Map<String, String> keystoreTypes_i; + + private KeyStore ks; + + /** + * @param parent + * @param style + * @param state + * @param container + */ + public KeystoreConfigurationComposite( + org.eclipse.swt.widgets.Composite parent, int style, State state, + ConfigurationContainer container) { + super(parent, style, state, container); + setLayout(new FormLayout()); + + class InterfaceSetupHelper + { + public void setFontDataHeight(Control c, int height) + { + FontData[] fD = c.getFont().getFontData(); + fD[0].setHeight(height); + c.setFont(new Font(Display.getCurrent(), fD[0])); + } + } + + InterfaceSetupHelper helper = new InterfaceSetupHelper(); + + this.grpKeystore = new Group(this, SWT.NONE | SWT.RESIZE); + FormLayout layout = new FormLayout(); + layout.marginHeight = 10; + layout.marginWidth = 5; + this.grpKeystore.setLayout(layout); + FormData fd_grpKeystore = new FormData(); + fd_grpKeystore.top = new FormAttachment(0, 5); + fd_grpKeystore.left = new FormAttachment(0, 5); + fd_grpKeystore.right = new FormAttachment(100, -5); + this.grpKeystore.setLayoutData(fd_grpKeystore); + helper.setFontDataHeight(this.grpKeystore, Constants.TEXT_SIZE_NORMAL); + + this.lblKeystoreFile = new Label(this.grpKeystore, SWT.NONE); + FormData fd_lblKeystoreFile = new FormData(); + fd_lblKeystoreFile.top = new FormAttachment(0); + fd_lblKeystoreFile.left = new FormAttachment(0, 5); + this.lblKeystoreFile.setLayoutData(fd_lblKeystoreFile); + helper.setFontDataHeight(this.lblKeystoreFile, Constants.TEXT_SIZE_NORMAL); + + this.txtKeystoreFile = new Text(this.grpKeystore, SWT.BORDER); + FormData fd_txtKeystoreFile = new FormData(); + fd_txtKeystoreFile.top = new FormAttachment(this.lblKeystoreFile, 5); + fd_txtKeystoreFile.left = new FormAttachment(0, 15); + this.txtKeystoreFile.setLayoutData(fd_txtKeystoreFile); + helper.setFontDataHeight(this.txtKeystoreFile, Constants.TEXT_SIZE_NORMAL); + + this.btnBrowse = new Button(this.grpKeystore, SWT.NONE); + fd_txtKeystoreFile.right = new FormAttachment(this.btnBrowse, -5); + helper.setFontDataHeight(this.btnBrowse, Constants.TEXT_SIZE_BUTTON); + + FormData fd_btnBrowse = new FormData(); + fd_btnBrowse.top = new FormAttachment(this.lblKeystoreFile, 5); + fd_btnBrowse.right = new FormAttachment(100, -5); + this.btnBrowse.setLayoutData(fd_btnBrowse); + + this.lblKeystoreType = new Label(this.grpKeystore, SWT.NONE); + FormData fd_lblKeystoreType = new FormData(); + fd_lblKeystoreType.top = new FormAttachment(this.txtKeystoreFile, 5); + fd_lblKeystoreType.left = new FormAttachment(0, 5); + this.lblKeystoreType.setLayoutData(fd_lblKeystoreType); + helper.setFontDataHeight(this.lblKeystoreType, Constants.TEXT_SIZE_NORMAL); + + this.cmbKeystoreType = new Combo(this.grpKeystore, SWT.READ_ONLY); + FormData fd_cmbKeystoreType = new FormData(); + fd_cmbKeystoreType.right = new FormAttachment(100, -5); + fd_cmbKeystoreType.top = new FormAttachment(this.lblKeystoreType, 5); + fd_cmbKeystoreType.left = new FormAttachment(0, 15); + this.cmbKeystoreType.setLayoutData(fd_cmbKeystoreType); + helper.setFontDataHeight(this.cmbKeystoreType, Constants.TEXT_SIZE_NORMAL); + + this.lblKeystoreAlias = new Label(this.grpKeystore, SWT.NONE); + FormData fd_lblKeystoreAlias = new FormData(); + fd_lblKeystoreAlias.top = new FormAttachment(this.cmbKeystoreType, 5); + fd_lblKeystoreAlias.left = new FormAttachment(0, 5); + this.lblKeystoreAlias.setLayoutData(fd_lblKeystoreAlias); + helper.setFontDataHeight(this.lblKeystoreAlias, Constants.TEXT_SIZE_NORMAL); + + this.cmbKeystoreAlias = new Combo(this.grpKeystore, SWT.NONE); + FormData fd_cmbKeystoreAlias = new FormData(); + fd_cmbKeystoreAlias.top = new FormAttachment(this.lblKeystoreAlias, 5); + fd_cmbKeystoreAlias.left = new FormAttachment(0, 15); + this.cmbKeystoreAlias.setLayoutData(fd_cmbKeystoreAlias); + helper.setFontDataHeight(this.cmbKeystoreAlias, Constants.TEXT_SIZE_NORMAL); + + + this.txtKeystoreFile.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + performKeystoreFileChanged(KeystoreConfigurationComposite.this.txtKeystoreFile.getText()); + } + }); + + this.btnBrowse.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog dialog = new FileDialog( + KeystoreConfigurationComposite.this.getShell(), SWT.OPEN); + dialog.setFilterExtensions(new String[] { + "*.p12;*.pkcs12;*.pfx;*.ks;*.jks", "*.p12;*.pkcs12;*.pfx;", "*.ks;*.jks*.", "*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + dialog.setFilterNames(new String[] { + Messages.getString("common.KeystoreExtension_Description"), //$NON-NLS-1$ + Messages.getString("common.PKCS12Extension_Description"), //$NON-NLS-1$ + Messages.getString("common.KSExtension_Description"), //$NON-NLS-1$ + Messages.getString("common.AllExtension_Description") }); //$NON-NLS-1$ + String fileName = dialog.open(); + File file = null; + if (fileName != null) { + file = new File(fileName); + if (file.exists()) { + performKeystoreFileChanged(fileName); + } + } + } + }); + + + initKeystoreTypes(); + this.cmbKeystoreType.setItems(this.keystoreTypes.keySet().toArray(new String[0])); + this.cmbKeystoreType.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + performKeystoreTypeChanged( + KeystoreConfigurationComposite.this.keystoreTypes.get( + KeystoreConfigurationComposite.this.cmbKeystoreType.getItem( + KeystoreConfigurationComposite.this.cmbKeystoreType.getSelectionIndex()))); + } + }); + + this.lblKeystoreStorePass = new Label(this.grpKeystore, SWT.NONE); + FormData fd_lblKeystoreStorePass = new FormData(); + fd_lblKeystoreStorePass.top = new FormAttachment(this.cmbKeystoreType, 5); + fd_lblKeystoreStorePass.left = new FormAttachment(0, 5); + this.lblKeystoreStorePass.setLayoutData(fd_lblKeystoreStorePass); + + FontData[] fD_lblKeystoreStorePass = this.lblKeystoreStorePass.getFont() + .getFontData(); + fD_lblKeystoreStorePass[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.lblKeystoreStorePass.setFont(new Font(Display.getCurrent(), + fD_lblKeystoreStorePass[0])); + + this.txtKeystoreStorePass = new Text(this.grpKeystore, SWT.BORDER | SWT.PASSWORD); + FormData fd_txtKeystoreStorePass = new FormData(); + fd_txtKeystoreStorePass.top = new FormAttachment(this.lblKeystoreStorePass, 5); + fd_txtKeystoreStorePass.left = new FormAttachment(0, 15); + this.txtKeystoreStorePass.setLayoutData(fd_txtKeystoreStorePass); + + FontData[] fD_txtKeystoreStorePass = this.txtKeystoreStorePass.getFont() + .getFontData(); + fD_txtKeystoreStorePass[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.txtKeystoreStorePass.setFont(new Font(Display.getCurrent(), + fD_txtKeystoreStorePass[0])); + + this.txtKeystoreStorePass.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + performKeystoreStorePassChanged(KeystoreConfigurationComposite. + this.txtKeystoreStorePass.getText()); + } + }); + + this.btnLoad = new Button(this.grpKeystore, SWT.NONE); + fd_txtKeystoreStorePass.right = new FormAttachment(this.btnLoad, -5); + + FontData[] fD_btnLoad = this.btnLoad.getFont().getFontData(); + fD_btnLoad[0].setHeight(Constants.TEXT_SIZE_BUTTON); + this.btnLoad.setFont(new Font(Display.getCurrent(), fD_btnLoad[0])); + + FormData fd_btnLoad = new FormData(); + fd_btnLoad.top = new FormAttachment(this.lblKeystoreStorePass, 5); + fd_btnLoad.right = new FormAttachment(100, -5); + this.btnLoad.setLayoutData(fd_btnLoad); + + this.btnLoad.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + File f = new File(KeystoreConfigurationComposite.this + .configurationContainer.getKeyStoreFile()); + try { + loadKeystore(); + } catch (KeyStoreException ex) { + log.error("Error loading keystore", ex); //$NON-NLS-1$ + showErrorDialog(Messages.getString("error.KeyStore")); //$NON-NLS-1$ + } catch (FileNotFoundException ex) { + log.error("Error loading keystore", ex); //$NON-NLS-1$ + showErrorDialog(String.format(Messages.getString( + "error.KeyStoreFileNotExist"), f.getName())); //$NON-NLS-1$ + } catch (NoSuchAlgorithmException ex) { + log.error("Error loading keystore", ex); //$NON-NLS-1$ + showErrorDialog(Messages.getString("error.KeyStore")); //$NON-NLS-1$ + } catch (CertificateException ex) { + log.error("Error loading keystore", ex); //$NON-NLS-1$ + showErrorDialog(Messages.getString("error.KeyStore")); //$NON-NLS-1$ + } catch (IOException ex) { + log.error("Error loading keystore", ex); //$NON-NLS-1$ + showErrorDialog(Messages.getString("error.KeyStore")); //$NON-NLS-1$ + } catch (NullPointerException ex) { + log.error("Error loading keystore - NPE?", ex); //$NON-NLS-1$ + showErrorDialog(Messages.getString("error.KeyStore")); //$NON-NLS-1$ + } + } + }); + + this.cmbKeystoreAlias.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + performKeystoreAliasChanged( + KeystoreConfigurationComposite.this.cmbKeystoreAlias.getItem( + KeystoreConfigurationComposite.this.cmbKeystoreAlias.getSelectionIndex())); + } + }); + this.cmbKeystoreAlias.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + performKeystoreAliasChanged(KeystoreConfigurationComposite. + this.cmbKeystoreAlias.getText()); + } + }); + + this.lblKeystoreKeyPass = new Label(this.grpKeystore, SWT.NONE); + FormData fd_lblKeystoreKeyPass = new FormData(); + fd_lblKeystoreKeyPass.top = new FormAttachment(this.cmbKeystoreAlias, 5); + fd_lblKeystoreKeyPass.left = new FormAttachment(0, 5); + this.lblKeystoreKeyPass.setLayoutData(fd_lblKeystoreKeyPass); + + FontData[] fD_lblKeystoreKeyPass = this.lblKeystoreKeyPass.getFont() + .getFontData(); + fD_lblKeystoreKeyPass[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.lblKeystoreKeyPass.setFont(new Font(Display.getCurrent(), + fD_lblKeystoreKeyPass[0])); + + this.txtKeystoreKeyPass = new Text(this.grpKeystore, SWT.BORDER | SWT.PASSWORD); + FormData fd_txtKeystoreKeyPass = new FormData(); + fd_txtKeystoreKeyPass.top = new FormAttachment(this.lblKeystoreKeyPass, 5); + fd_txtKeystoreKeyPass.left = new FormAttachment(0, 15); + fd_txtKeystoreKeyPass.right = new FormAttachment(100, -5); + this.txtKeystoreKeyPass.setLayoutData(fd_txtKeystoreKeyPass); + + FontData[] fD_txtKeystoreKeyPass = this.txtKeystoreKeyPass.getFont() + .getFontData(); + fD_txtKeystoreKeyPass[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.txtKeystoreKeyPass.setFont(new Font(Display.getCurrent(), + fD_txtKeystoreKeyPass[0])); + + this.txtKeystoreKeyPass.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + performKeystoreKeyPassChanged(KeystoreConfigurationComposite. + this.txtKeystoreKeyPass.getText()); + } + }); + + // Load localized strings + reloadResources(); + } + + void showErrorDialog(String error) { + ErrorDialog e = new ErrorDialog(getShell(), error, BUTTONS.OK); + e.open(); + } + + void loadKeystore() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { + ConfigurationContainer config = + KeystoreConfigurationComposite.this.configurationContainer; + File f = new File(config.getKeyStoreFile()); + this.ks = KeyStore.getInstance(config.getKeyStoreType()); + FileInputStream fis = new FileInputStream(f); + this.ks.load(fis, config.getKeyStoreStorePass().toCharArray()); + this.cmbKeystoreAlias.remove(0, this.cmbKeystoreAlias.getItemCount()-1); + Enumeration<String> aliases = this.ks.aliases(); + while (aliases.hasMoreElements()) + this.cmbKeystoreAlias.add(aliases.nextElement()); + } + + private void initKeystoreTypes() { + this.keystoreTypes = new HashMap<String, String>(); + this.keystoreTypes_i = new HashMap<String, String>(); + this.keystoreTypes.put(Messages.getString("keystore_config.KeystoreType_PKCS12"), "PKCS12"); //$NON-NLS-1$ //$NON-NLS-2$ + this.keystoreTypes_i.put("PKCS12", Messages.getString("keystore_config.KeystoreType_PKCS12")); //$NON-NLS-1$ //$NON-NLS-2$ + this.keystoreTypes.put(Messages.getString("keystore_config.KeystoreType_JKS"), "JCEKS"); //$NON-NLS-1$ //$NON-NLS-2$ + this.keystoreTypes_i.put("JCEKS", Messages.getString("keystore_config.KeystoreType_JKS")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + /** + * @param fileName + */ + protected void performKeystoreFileChanged(String fileName) { + log.debug("Selected keystore file: " + fileName); //$NON-NLS-1$ + this.configurationContainer.setKeyStoreFile(fileName); + KeystoreConfigurationComposite.this.txtKeystoreFile.setText(fileName); + int i = fileName.lastIndexOf('.'); + if (i > 0) { + String ext = fileName.substring(i+1); + if ( + ext.equalsIgnoreCase("p12") || //$NON-NLS-1$ + ext.equalsIgnoreCase("pkcs12") || //$NON-NLS-1$ + ext.equalsIgnoreCase("pfx")) //$NON-NLS-1$ + performKeystoreTypeChanged("PKCS12"); //$NON-NLS-1$ + else if ( + ext.equalsIgnoreCase("ks") || //$NON-NLS-1$ + ext.equalsIgnoreCase("jks")) //$NON-NLS-1$ + performKeystoreTypeChanged("JCEKS"); //$NON-NLS-1$ + } + } + + /** + * @param type + */ + protected void performKeystoreTypeChanged(String type) { + log.debug("Selected keystore type: " + type); //$NON-NLS-1$ + this.configurationContainer.setKeyStoreType(type); + String type_text = this.keystoreTypes_i.get(type); + for (int i = 0; i < this.cmbKeystoreType.getItemCount(); ++i) { + if (this.cmbKeystoreType.getItem(i).equals(type_text)) { + this.cmbKeystoreType.select(i); + break; + } + } + } + + /** + * @param storepass + */ + protected void performKeystoreStorePassChanged(String storepass) { + log.debug("Changed keystore store password"); //$NON-NLS-1$ + this.configurationContainer.setKeyStoreStorePass(storepass); + this.txtKeystoreStorePass.setText(storepass); + } + + /** + * @param alias + */ + protected void performKeystoreAliasChanged(String alias) { + log.debug("Selected keystore alias: " + alias); //$NON-NLS-1$ + this.configurationContainer.setKeyStoreAlias(alias); + this.cmbKeystoreAlias.setText(alias); + } + + /** + * @param keypass + */ + protected void performKeystoreKeyPassChanged(String keypass) { + log.debug("Changed keystore key password"); //$NON-NLS-1$ + this.configurationContainer.setKeyStoreKeyPass(keypass); + this.txtKeystoreKeyPass.setText(keypass); + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#signerChanged() + */ + @Override + protected void signerChanged() { + // Nothing to do here (yet) + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() + */ + @Override + public void doLayout() { + layout(true, true); + } + + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.composites.BaseConfigurationComposite#initConfiguration(at.asit.pdfover.gui.workflow.config.PersistentConfigProvider) + */ + @Override + public void initConfiguration(PersistentConfigProvider provider) { + ConfigurationContainer config = this.configurationContainer; + config.setKeyStoreFile(provider.getKeyStoreFilePersistent()); + config.setKeyStoreType(provider.getKeyStoreTypePersistent()); + config.setKeyStoreAlias(provider.getKeyStoreAliasPersistent()); + config.setKeyStoreStorePass(provider.getKeyStoreStorePassPersistent()); + config.setKeyStoreKeyPass(provider.getKeyStoreKeyPassPersistent()); + } + + /* + * (non-Javadoc) + * @see at.asit.pdfover.gui.composites.BaseConfigurationComposite#loadConfiguration + * () + */ + @Override + public void loadConfiguration() { + // Initialize form fields from configuration Container + ConfigurationContainer config = this.configurationContainer; + String ks = config.getKeyStoreFile(); + performKeystoreFileChanged(ks); + performKeystoreTypeChanged(config.getKeyStoreType()); + performKeystoreStorePassChanged(config.getKeyStoreStorePass()); + try { + File ksf = new File(ks); + if (ksf.exists()) + loadKeystore(); + } catch (Exception e) { + log.error("Error loading keystore", e); //$NON-NLS-1$ + } + performKeystoreAliasChanged(config.getKeyStoreAlias()); + performKeystoreKeyPassChanged(config.getKeyStoreKeyPass()); + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.composites.BaseConfigurationComposite#storeConfiguration(at.asit.pdfover.gui.workflow.config.ConfigManipulator, at.asit.pdfover.gui.workflow.config.PersistentConfigProvider) + */ + @Override + public void storeConfiguration(ConfigManipulator store, + PersistentConfigProvider provider) { + ConfigurationContainer config = this.configurationContainer; + store.setKeyStoreFile(config.getKeyStoreFile()); + store.setKeyStoreType(config.getKeyStoreType()); + store.setKeyStoreAlias(config.getKeyStoreAlias()); + store.setKeyStoreStorePass(config.getKeyStoreStorePass()); + store.setKeyStoreKeyPass(config.getKeyStoreKeyPass()); + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#validateSettings + * () + */ + @Override + public void validateSettings(int resumeFrom) throws Exception { + ConfigurationContainer config = this.configurationContainer; + switch (resumeFrom) { + case 0: + String fname = config.getKeyStoreFile(); + if (fname.isEmpty()) + break; //no checks required + File f = new File(fname); + if (!f.exists() || !f.isFile()) + throw new KeystoreDoesntExistException(f, 4); //skip next checks + // Fall through + case 1: + try { + loadKeystore(); + } catch (Exception e) { + throw new CantLoadKeystoreException(e, 4); //skip next checks + } + // Fall through + case 2: + String alias = config.getKeyStoreAlias(); + if (!this.ks.containsAlias(alias)) + throw new KeystoreAliasDoesntExistException(alias, 4); //skip next check + if (!this.ks.isKeyEntry(alias)) + throw new KeystoreAliasNoKeyException(alias, 4); //skip next check + // Fall through + case 3: + try { + alias = config.getKeyStoreAlias(); + String keypass = config.getKeyStoreKeyPass(); + this.ks.getKey(alias, keypass.toCharArray()); + } catch (Exception e) { + throw new KeystoreKeyPasswordException(4); + } + } + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() + */ + @Override + public void reloadResources() { + this.grpKeystore.setText(Messages + .getString("keystore_config.Keystore_Title")); //$NON-NLS-1$ + this.lblKeystoreFile.setText(Messages + .getString("keystore_config.KeystoreFile")); //$NON-NLS-1$ + this.btnBrowse.setText(Messages.getString("common.browse")); //$NON-NLS-1$ + this.txtKeystoreFile.setToolTipText(Messages + .getString("keystore_config.KeystoreFile_ToolTip")); //$NON-NLS-1$ + this.lblKeystoreType.setText(Messages + .getString("keystore_config.KeystoreType")); //$NON-NLS-1$ + this.lblKeystoreStorePass.setText(Messages + .getString("keystore_config.KeystoreStorePass")); //$NON-NLS-1$ + this.txtKeystoreStorePass.setToolTipText(Messages + .getString("keystore_config.KeystoreStorePass_ToolTip")); //$NON-NLS-1$ + this.btnLoad.setText(Messages.getString("keystore_config.Load")); //$NON-NLS-1$ + this.btnLoad.setToolTipText(Messages + .getString("keystore_config.Load_ToolTip")); //$NON-NLS-1$ + this.lblKeystoreAlias.setText(Messages + .getString("keystore_config.KeystoreAlias")); //$NON-NLS-1$ + this.lblKeystoreKeyPass.setText(Messages + .getString("keystore_config.KeystoreKeyPass")); //$NON-NLS-1$ + this.txtKeystoreKeyPass.setToolTipText(Messages + .getString("keystore_config.KeystoreKeyPass_ToolTip")); //$NON-NLS-1$ + } +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java new file mode 100644 index 00000000..a93ff8f2 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java @@ -0,0 +1,981 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.composites.configuration; + +// Imports +import java.io.File; +import java.io.IOException; +import java.util.Locale; + +import javax.imageio.ImageIO; + +import at.asit.pdfover.signator.SignaturePosition; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.dnd.DropTargetAdapter; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.FileTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.commons.Constants; +import at.asit.pdfover.commons.Profile; +import at.asit.pdfover.gui.controls.Dialog.BUTTONS; +import at.asit.pdfover.gui.controls.ErrorDialog; +import at.asit.pdfover.gui.controls.ErrorMarker; +import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; +import at.asit.pdfover.gui.exceptions.InvalidNumberException; +import at.asit.pdfover.gui.utils.ImageConverter; +import at.asit.pdfover.commons.Messages; +import at.asit.pdfover.gui.workflow.config.ConfigManipulator; +import at.asit.pdfover.gui.workflow.config.ConfigurationContainer; +import at.asit.pdfover.gui.workflow.config.PersistentConfigProvider; +import at.asit.pdfover.gui.workflow.states.State; +import at.asit.pdfover.signator.CachedFileNameEmblem; +import at.asit.pdfover.signator.SignatureParameter; + +/** + * + */ +public class SimpleConfigurationComposite extends BaseConfigurationComposite { + + /** + * SLF4J Logger instance + **/ + static final Logger log = LoggerFactory + .getLogger(SimpleConfigurationComposite.class); + + private Group grpHandySignatur; + private Label lblMobileNumber; + protected Text txtMobileNumber; + protected FormData fd_txtMobileNumber; + protected ErrorMarker txtMobileNumberErrorMarker; + protected FormData fd_txtMobileNumberErrorMarker; + + private Group grpLogo; + private Canvas cLogo; + private Label lblDropLogo; + protected Button btnClearImage; + private Button btnBrowseLogo; + protected Canvas cSigPreview; + + private Group grpSignatureNote; + private Label lblSignatureNote; + protected Text txtSignatureNote; + private Button btnSignatureNoteDefault; + + protected final Group grpSignatureLang; + protected final Combo cmbSignatureLang; + + protected String logoFile = null; + protected Image sigPreview = null; + protected Image logo = null; + + protected final Group grpSignatureProfile; + protected final Combo cmbSignatureProfiles; + + + + + /** + * @param parent + * @param style + * @param state + * @param container + */ + public SimpleConfigurationComposite( + org.eclipse.swt.widgets.Composite parent, int style, State state, + ConfigurationContainer container) { + super(parent, style, state, container); + setLayout(new FormLayout()); + + this.grpHandySignatur = new Group(this, SWT.NONE | SWT.RESIZE); + FormData fd_grpHandySignatur = new FormData(); + fd_grpHandySignatur.right = new FormAttachment(100, -5); + fd_grpHandySignatur.left = new FormAttachment(0, 5); + fd_grpHandySignatur.top = new FormAttachment(0, 5); + this.grpHandySignatur.setLayoutData(fd_grpHandySignatur); + this.grpHandySignatur.setLayout(new GridLayout(2, false)); + + FontData[] fD_grpHandySignatur = this.grpHandySignatur.getFont() + .getFontData(); + fD_grpHandySignatur[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.grpHandySignatur.setFont(new Font(Display.getCurrent(), + fD_grpHandySignatur[0])); + + this.lblMobileNumber = new Label(this.grpHandySignatur, SWT.NONE + | SWT.RESIZE); + this.lblMobileNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, + false, false, 1, 1)); + + FontData[] fD_lblMobileNumber = this.lblMobileNumber.getFont() + .getFontData(); + fD_lblMobileNumber[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.lblMobileNumber.setFont(new Font(Display.getCurrent(), + fD_lblMobileNumber[0])); + + Composite compMobileNumerContainer = new Composite(this.grpHandySignatur, SWT.NONE); + compMobileNumerContainer.setLayout(new FormLayout()); + compMobileNumerContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, + 1, 1)); + + this.txtMobileNumber = new Text(compMobileNumerContainer, SWT.BORDER | SWT.RESIZE); + this.fd_txtMobileNumber = new FormData(); + this.fd_txtMobileNumber.left = new FormAttachment(0, 5); + this.fd_txtMobileNumber.right = new FormAttachment(100, -42); + this.fd_txtMobileNumber.top = new FormAttachment(0); + this.txtMobileNumber.setLayoutData(this.fd_txtMobileNumber); + + + this.txtMobileNumberErrorMarker = new ErrorMarker(compMobileNumerContainer, + SWT.NONE, ""); //$NON-NLS-1$ + this.txtMobileNumberErrorMarker.setVisible(false); + this.fd_txtMobileNumberErrorMarker = new FormData(); + this.fd_txtMobileNumberErrorMarker.left = new FormAttachment(100, -32); + this.fd_txtMobileNumberErrorMarker.right = new FormAttachment(100); + this.fd_txtMobileNumberErrorMarker.top = new FormAttachment(0); + this.fd_txtMobileNumberErrorMarker.bottom = new FormAttachment(0, 32); + this.txtMobileNumberErrorMarker + .setLayoutData(this.fd_txtMobileNumberErrorMarker); + + FontData[] fD_txtMobileNumber = this.txtMobileNumber.getFont() + .getFontData(); + fD_txtMobileNumber[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.txtMobileNumber.setFont(new Font(Display.getCurrent(), + fD_txtMobileNumber[0])); + + this.txtMobileNumber.addTraverseListener(e -> { + if (e.detail == SWT.TRAVERSE_RETURN) { + processNumberChanged(); + } + }); + + this.txtMobileNumber.addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + processNumberChanged(); + } + }); + + this.grpSignatureProfile = new Group(this, SWT.NONE); + FormData fd_grpSingnatureProfile = new FormData(); + fd_grpSingnatureProfile.right = new FormAttachment(100, -5); + fd_grpSingnatureProfile.left = new FormAttachment(0, 5); + fd_grpSingnatureProfile.top = new FormAttachment(this.grpHandySignatur, 5); + this.grpSignatureProfile.setLayoutData(fd_grpSingnatureProfile); + this.grpSignatureProfile.setText("Signature Profile"); //$NON-NLS-1$ + this.grpSignatureProfile.setLayout(new FormLayout()); + + FontData[] fD_grpSignatureProfile = this.grpSignatureProfile.getFont() + .getFontData(); + fD_grpSignatureProfile[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.grpSignatureProfile.setFont(new Font(Display.getCurrent(), + fD_grpSignatureProfile[0])); + + + this.cmbSignatureProfiles = new Combo(this.grpSignatureProfile, SWT.READ_ONLY); + + FormData fd_cmbSingatureProfiles = new FormData(); + fd_cmbSingatureProfiles.left = new FormAttachment(0, 10); + fd_cmbSingatureProfiles.right = new FormAttachment(100, -10); + fd_cmbSingatureProfiles.top = new FormAttachment(0, 10); + fd_cmbSingatureProfiles.bottom = new FormAttachment(100, -10); + this.cmbSignatureProfiles.setLayoutData(fd_cmbSingatureProfiles); + + FontData[] fD_cmbSignatureProfile = this.cmbSignatureProfiles.getFont() + .getFontData(); + fD_cmbSignatureProfile[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.cmbSignatureProfiles.setFont(new Font(Display.getCurrent(), + fD_cmbSignatureProfile[0])); + + String[] items = new String[Profile.values().length]; + int i = 0; + for (Profile profile : Profile.values()) { + items[i] = Messages.getString("simple_config." + profile.name()); + i++; + } + + this.cmbSignatureProfiles.setItems(items); + this.cmbSignatureProfiles.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Profile current = SimpleConfigurationComposite.this.configurationContainer.getSignatureProfile(); + int index = SimpleConfigurationComposite.this.cmbSignatureProfiles.getSelectionIndex(); + Profile selected = Profile.values()[index]; + if (!current.equals(selected)) { + preformProfileSelectionChanged(selected); + } + } + }); + + this.grpLogo = new Group(this, SWT.NONE); + FormData fd_grpBildmarke = new FormData(); + fd_grpBildmarke.left = new FormAttachment(0, 5); + fd_grpBildmarke.right = new FormAttachment(100, -5); + fd_grpBildmarke.top = new FormAttachment(this.grpSignatureProfile, 5); + this.grpLogo.setLayoutData(fd_grpBildmarke); + this.grpLogo.setLayout(new FormLayout()); + + FontData[] fD_grpBildmarke = this.grpLogo.getFont().getFontData(); + fD_grpBildmarke[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.grpLogo.setFont(new Font(Display.getCurrent(), + fD_grpBildmarke[0])); + + Composite containerComposite = new Composite(this.grpLogo, + SWT.NONE); + containerComposite.setLayout(new FormLayout()); + FormData fd_containerComposite = new FormData(); + fd_containerComposite.left = new FormAttachment(0); + fd_containerComposite.right = new FormAttachment(100); + fd_containerComposite.top = new FormAttachment(0); + fd_containerComposite.bottom = new FormAttachment(100); + containerComposite.setLayoutData(fd_containerComposite); + + final Composite controlComposite = new Composite(containerComposite, SWT.NONE); + controlComposite.setLayout(new FormLayout()); + FormData fd_controlComposite = new FormData(); + fd_controlComposite.left = new FormAttachment(0, 20); + fd_controlComposite.right = new FormAttachment(0, 300); + fd_controlComposite.top = new FormAttachment(0, 20); + fd_controlComposite.bottom = new FormAttachment(100, -20); + controlComposite.setLayoutData(fd_controlComposite); + controlComposite.addPaintListener(e -> { + e.gc.setForeground(Constants.DROP_BORDER_COLOR); + e.gc.setLineWidth(3); + e.gc.setLineStyle(SWT.LINE_DASH); + Point size = controlComposite.getSize(); + e.gc.drawRoundRectangle(0, 0, size.x - 2, size.y - 2, + 10, 10); + }); + + this.cSigPreview = new Canvas(containerComposite, SWT.RESIZE); + + this.btnBrowseLogo = new Button(controlComposite, SWT.NONE); + + this.lblDropLogo = new Label(controlComposite, SWT.NATIVE | SWT.CENTER); + + this.cLogo = new Canvas(controlComposite, SWT.NONE); + FormData fd_cLogo = new FormData(); + fd_cLogo.left = new FormAttachment(0, 20); + fd_cLogo.right = new FormAttachment(100, -20); + fd_cLogo.top = new FormAttachment(0, 20); + fd_cLogo.bottom = new FormAttachment(this.lblDropLogo, -20); + fd_cLogo.height = 40; + fd_cLogo.width = 40; + this.cLogo.setLayoutData(fd_cLogo); + this.cLogo.addPaintListener(e -> imagePaintControl(e, SimpleConfigurationComposite.this.logo)); + + this.btnClearImage = new Button(controlComposite, SWT.NATIVE); + + FormData fd_lbl_drop = new FormData(); + fd_lbl_drop.left = new FormAttachment(0, 20); + fd_lbl_drop.right = new FormAttachment(100, -20); + fd_lbl_drop.bottom = new FormAttachment(this.btnBrowseLogo, -20); + + this.lblDropLogo.setLayoutData(fd_lbl_drop); + + FormData fd_cSigPreview = new FormData(); + fd_cSigPreview.left = new FormAttachment(controlComposite, 20); + fd_cSigPreview.right = new FormAttachment(100, -20); + fd_cSigPreview.top = new FormAttachment(0, 20); + fd_cSigPreview.bottom = new FormAttachment(100, -20); + + this.cSigPreview.setLayoutData(fd_cSigPreview); + this.cSigPreview.addPaintListener(e -> imagePaintControl(e, SimpleConfigurationComposite.this.sigPreview)); + + FontData[] fD_cSigPreview = this.cSigPreview.getFont().getFontData(); + fD_cSigPreview[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.cSigPreview.setFont(new Font(Display.getCurrent(), fD_cSigPreview[0])); + + DropTarget dnd_target = new DropTarget(controlComposite, + DND.DROP_DEFAULT | DND.DROP_COPY); + final FileTransfer fileTransfer = FileTransfer.getInstance(); + Transfer[] types = new Transfer[] { fileTransfer }; + dnd_target.setTransfer(types); + + dnd_target.addDropListener(new DropTargetAdapter() { + @Override + public void drop(DropTargetEvent event) { + if (fileTransfer.isSupportedType(event.currentDataType)) { + String[] files = (String[]) event.data; + if (files.length > 0) { + // Only taking first file ... + File file = new File(files[0]); + if (!file.exists()) { + log.error("File: {} does not exist!", files[0]); //$NON-NLS-1$//$NON-NLS-2$ + return; + } + processEmblemChanged(file.getAbsolutePath()); + } + } + } + + @Override + public void dragOperationChanged(DropTargetEvent event) { + if (event.detail == DND.DROP_DEFAULT) { + if ((event.operations & DND.DROP_COPY) != 0) { + event.detail = DND.DROP_COPY; + } else { + event.detail = DND.DROP_NONE; + } + } + } + + @Override + public void dragEnter(DropTargetEvent event) { + if (event.detail == DND.DROP_DEFAULT) { + if ((event.operations & DND.DROP_COPY) != 0) { + event.detail = DND.DROP_COPY; + } else { + event.detail = DND.DROP_NONE; + } + } + // Only drop one item! + if (event.dataTypes.length > 1) { + event.detail = DND.DROP_NONE; + return; + } + // will accept text but prefer to have files dropped + for (int i = 0; i < event.dataTypes.length; i++) { + if (fileTransfer.isSupportedType(event.dataTypes[i])) { + event.currentDataType = event.dataTypes[i]; + // files should only be copied + if (event.detail != DND.DROP_COPY) { + event.detail = DND.DROP_NONE; + } + break; + } + } + } + }); + + this.btnClearImage.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + SimpleConfigurationComposite.this.processEmblemChanged(null); + } + }); + + FontData[] fD_btnUseImage = this.btnClearImage.getFont().getFontData(); + fD_btnUseImage[0].setHeight(Constants.TEXT_SIZE_BUTTON); + this.btnClearImage.setFont(new Font(Display.getCurrent(), + fD_btnUseImage[0])); + + FormData fd_btnUseImage = new FormData(); + + fd_btnUseImage.bottom = new FormAttachment(100, -20); + fd_btnUseImage.right = new FormAttachment(this.btnBrowseLogo, -10); + + this.btnClearImage.setLayoutData(fd_btnUseImage); + + FormData fd_btnBrowseLogo = new FormData(); + + fd_btnBrowseLogo.bottom = new FormAttachment(100, -20); + fd_btnBrowseLogo.right = new FormAttachment(100, -20); + + this.btnBrowseLogo.setLayoutData(fd_btnBrowseLogo); + this.btnBrowseLogo.addSelectionListener(new ImageFileBrowser()); + + FontData[] fD_btnBrowseLogo = this.btnBrowseLogo.getFont() + .getFontData(); + fD_btnBrowseLogo[0].setHeight(Constants.TEXT_SIZE_BUTTON); + this.btnBrowseLogo.setFont(new Font(Display.getCurrent(), + fD_btnBrowseLogo[0])); + + + this.grpSignatureLang = new Group(this, SWT.NONE); + FormData fd_grpSignatureLang = new FormData(); + fd_grpSignatureLang.right = new FormAttachment(100, -5); + fd_grpSignatureLang.top = new FormAttachment(this.grpLogo, 5); + fd_grpSignatureLang.left = new FormAttachment(0, 5); + this.grpSignatureLang.setLayoutData(fd_grpSignatureLang); + this.grpSignatureLang.setLayout(new FormLayout()); + + FontData[] fD_grpSignatureLang = this.grpSignatureLang.getFont() + .getFontData(); + fD_grpSignatureLang[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.grpSignatureLang.setFont(new Font(Display.getCurrent(), + fD_grpSignatureLang[0])); + + this.cmbSignatureLang = new Combo(this.grpSignatureLang, SWT.READ_ONLY); + FormData fd_cmbSignatureLang = new FormData(); + fd_cmbSignatureLang.left = new FormAttachment(0, 10); + fd_cmbSignatureLang.right = new FormAttachment(100, -10); + fd_cmbSignatureLang.top = new FormAttachment(0, 10); + fd_cmbSignatureLang.bottom = new FormAttachment(100, -10); + this.cmbSignatureLang.setLayoutData(fd_cmbSignatureLang); + + FontData[] fD_cmbSignatureLang = this.cmbSignatureLang.getFont() + .getFontData(); + fD_cmbSignatureLang[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.cmbSignatureLang.setFont(new Font(Display.getCurrent(), + fD_cmbSignatureLang[0])); + + String[] localeSignStrings = new String[Constants.SUPPORTED_LOCALES.length]; + for (int idx = 0; idx < Constants.SUPPORTED_LOCALES.length; ++idx) { + localeSignStrings[idx] = Constants.SUPPORTED_LOCALES[idx].getDisplayLanguage(); + } + this.cmbSignatureLang.setItems(localeSignStrings); + this.cmbSignatureLang.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Locale currentLocale = SimpleConfigurationComposite.this.configurationContainer + .getSignatureLocale(); + Locale selectedLocale = Constants. + SUPPORTED_LOCALES[SimpleConfigurationComposite.this.cmbSignatureLang + .getSelectionIndex()]; + if (!currentLocale.equals(selectedLocale)) { + performSignatureLangSelectionChanged(selectedLocale, currentLocale); + } + } + }); + + + this.grpSignatureNote = new Group(this, SWT.NONE); + FormData fd_grpSignatureNote = new FormData(); + fd_grpSignatureNote.right = new FormAttachment(100, -5); + fd_grpSignatureNote.top = new FormAttachment(this.grpSignatureLang, 5); + fd_grpSignatureNote.left = new FormAttachment(0, 5); + this.grpSignatureNote.setLayoutData(fd_grpSignatureNote); + this.grpSignatureNote.setLayout(new GridLayout(2, false)); + + FontData[] fD_grpSignatureNote = this.grpSignatureNote.getFont() + .getFontData(); + fD_grpSignatureNote[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.grpSignatureNote.setFont(new Font(Display.getCurrent(), + fD_grpSignatureNote[0])); + + this.lblSignatureNote = new Label(this.grpSignatureNote, SWT.NONE); + GridData gd_lblSignatureNote = new GridData(SWT.LEFT, SWT.CENTER, + false, false, 1, 1); + gd_lblSignatureNote.widthHint = 66; + this.lblSignatureNote.setLayoutData(gd_lblSignatureNote); + this.lblSignatureNote.setBounds(0, 0, 57, 15); + + FontData[] fD_lblSignatureNote = this.lblSignatureNote.getFont() + .getFontData(); + fD_lblSignatureNote[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.lblSignatureNote.setFont(new Font(Display.getCurrent(), + fD_lblSignatureNote[0])); + + Composite compSignatureNoteContainer = new Composite(this.grpSignatureNote, SWT.NONE); + compSignatureNoteContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, + 1, 1)); + compSignatureNoteContainer.setLayout(new FormLayout()); + + this.txtSignatureNote = new Text(compSignatureNoteContainer, SWT.BORDER); + FormData fd_txtSignatureNote = new FormData(); + fd_txtSignatureNote.top = new FormAttachment(0, 0); + fd_txtSignatureNote.left = new FormAttachment(0, 5); + fd_txtSignatureNote.right = new FormAttachment(100, -42); + this.txtSignatureNote.setLayoutData(fd_txtSignatureNote); + + FontData[] fD_txtSignatureNote = this.txtSignatureNote.getFont() + .getFontData(); + fD_txtSignatureNote[0].setHeight(Constants.TEXT_SIZE_NORMAL); + this.txtSignatureNote.setFont(new Font(Display.getCurrent(), + fD_txtSignatureNote[0])); + + this.txtSignatureNote.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + processSignatureNoteChanged(); + } + }); + + this.txtSignatureNote.addTraverseListener(e -> { + if (e.detail == SWT.TRAVERSE_RETURN) { + processSignatureNoteChanged(); + } + }); + + Composite compSignatureNoteButtonContainer = new Composite(this.grpSignatureNote, SWT.NONE); + compSignatureNoteButtonContainer.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, + false, false, 2, 1)); + compSignatureNoteButtonContainer.setLayout(new FormLayout()); + + this.btnSignatureNoteDefault = new Button(compSignatureNoteButtonContainer, SWT.NONE); + FormData fd_btnSignatureNoteDefault = new FormData(); + fd_btnSignatureNoteDefault.top = new FormAttachment(0, 0); + fd_btnSignatureNoteDefault.right = new FormAttachment(100, -42); + this.btnSignatureNoteDefault.setLayoutData(fd_btnSignatureNoteDefault); + FontData[] fD_btnSignatureNoteDefault = this.btnSignatureNoteDefault.getFont() + .getFontData(); + fD_btnSignatureNoteDefault[0].setHeight(Constants.TEXT_SIZE_BUTTON); + this.btnSignatureNoteDefault.setFont(new Font(Display.getCurrent(), + fD_btnSignatureNoteDefault[0])); + this.btnSignatureNoteDefault.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + SimpleConfigurationComposite.this.txtSignatureNote.setText(getSignatureBlockNoteTextAccordingToProfile( + SimpleConfigurationComposite.this.configurationContainer.getSignatureProfile(), + SimpleConfigurationComposite.this.configurationContainer.getSignatureLocale())); + } + }); + + // Load localized strings + reloadResources(); + } + + static void imagePaintControl(PaintEvent e, Image i) { + if (i == null) + return; + + Rectangle r = i.getBounds(); + int srcW = r.width; + int srcH = r.height; + Point p = ((Control) e.widget).getSize(); + float dstW = p.x; + float dstH = p.y; + + float scale = dstW / srcW; + if (srcH * scale > dstH) + scale = dstH / srcH; + + float w = srcW * scale; + float h = srcH * scale; + + int x = (int) ((dstW / 2) - (w / 2)); + int y = (int) ((dstH / 2) - (h / 2)); + e.gc.drawImage(i, 0, 0, srcW, srcH, x, y, (int) w, (int) h); + } + + /** + * + */ + private final class ImageFileBrowser extends SelectionAdapter { + /** + * + */ + public ImageFileBrowser() { + // Nothing to do + } + + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog dialog = new FileDialog( + SimpleConfigurationComposite.this.getShell(), SWT.OPEN); + dialog.setFilterExtensions(new String[] { + "*.jpg;*.png;*.gif", "*.jpg", "*.png", "*.gif", "*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + dialog.setFilterNames(new String[] { + Messages.getString("common.ImageExtension_Description"), //$NON-NLS-1$ + Messages.getString("common.JPGExtension_Description"), //$NON-NLS-1$ + Messages.getString("common.PNGExtension_Description"), //$NON-NLS-1$ + Messages.getString("common.GIFExtension_Description"), //$NON-NLS-1$ + Messages.getString("common.AllExtension_Description") }); //$NON-NLS-1$ + String fileName = dialog.open(); + File file = null; + if (fileName != null) { + file = new File(fileName); + if (file.exists()) { + processEmblemChanged(fileName); + } + } + } + } + + private void setEmblemFile(final String filename) throws Exception { + setEmblemFileInternal(filename, false); + } + + private void setEmblemFileInternal(final String filename, boolean force) + throws Exception { + if (!force && this.configurationContainer.getEmblem() != null) { + if (this.configurationContainer.getEmblem().equals(filename)) { + return; // Ignore ... + } + } + + this.configurationContainer.setEmblem(filename); + this.setVisibleImage(); + this.doLayout(); + } + + void setVisibleImage() { + String image = this.configurationContainer.getEmblem(); + ImageData img = null; + ImageData logo = null; + + try { + if (this.signer != null) { + SignatureParameter param = this.signer.getPDFSigner().newParameter(); + if(this.configurationContainer.getSignatureNote() != null && !this.configurationContainer.getSignatureNote().isEmpty()) { + param.setProperty("SIG_NOTE", this.configurationContainer.getSignatureNote()); //$NON-NLS-1$ + } + + param.setSignatureLanguage(this.configurationContainer.getSignatureLocale().getLanguage()); + param.setSignaturePdfACompat(this.configurationContainer.getSignaturePdfACompat()); + if (image != null && !image.trim().isEmpty()) { + logo = new ImageData(image); + param.setEmblem(new CachedFileNameEmblem(image)); + } + //TODO deactivated the placeholder preview + //TODO display accurate placeholder preview -> now its only standard placeholder shown + //img = SignaturePlaceholderCache.getSWTPlaceholder(param); + } + } catch (Exception e) { + log.error("Failed to load image for display...", e); //$NON-NLS-1 + } + + if (img != null) { + this.sigPreview = new Image(this.getDisplay(), img); + } else { + this.sigPreview = null; + } + + if (logo != null) { + try { + File imgFile = new File(image); + this.logo = new Image(this.getDisplay(), + ImageConverter.convertToSWT(CachedFileNameEmblem.fixImage( + ImageIO.read(imgFile), imgFile))); + } catch (IOException e) { + log.error("Error reading image", e); //$NON-NLS-1$ + } + } else { + this.logo = null; + } + + this.cSigPreview.redraw(); + this.cLogo.redraw(); + } + + void processEmblemChanged(String filename) { + try { + setEmblemFile(filename); + } catch (Exception ex) { + log.error("processEmblemChanged: ", ex); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog( + getShell(), + Messages.getString("error.FailedToLoadEmblem"), BUTTONS.OK); //$NON-NLS-1$ + dialog.open(); + } + } + + void processNumberChanged() { + try { + this.txtMobileNumberErrorMarker.setVisible(false); + plainMobileNumberSetter(); + } catch (Exception ex) { + this.txtMobileNumberErrorMarker.setVisible(true); + this.txtMobileNumberErrorMarker.setToolTipText(Messages + .getString("error.InvalidPhoneNumber")); //$NON-NLS-1$ + log.error("processNumberChanged: ", ex); //$NON-NLS-1$ + this.redraw(); + this.doLayout(); + } + } + + int getLocaleElementIndex(Locale locale) { + for (int i = 0; i < Constants.SUPPORTED_LOCALES.length; i++) { + if (Constants.SUPPORTED_LOCALES[i].equals(locale)) { + log.debug("Locale: {} IDX: {}",locale, i); //$NON-NLS-1$ //$NON-NLS-2$ + return i; + } + } + + log.warn("NO Locale match for {}", locale); //$NON-NLS-1$ + return 0; + } + + void performSignatureLangSelectionChanged(Locale selected, Locale previous) { + log.debug("Selected Sign Locale: {}", selected); //$NON-NLS-1$ + this.configurationContainer.setSignatureLocale(selected); + this.cmbSignatureLang.select(this.getLocaleElementIndex(selected)); + if (previous != null) { + Profile profile = Profile.values()[this.cmbSignatureProfiles.getSelectionIndex()]; + String prev_default_note = getSignatureBlockNoteTextAccordingToProfile(profile, previous); + if (this.txtSignatureNote.getText().equals(prev_default_note)) { + this.txtSignatureNote.setText(getSignatureBlockNoteTextAccordingToProfile(profile, selected)); //$NON-NLS-1$); + processSignatureNoteChanged(); + } + } + } + + + + void preformProfileSelectionChanged(Profile selected) { + log.debug("Signature Profile {} was selected", selected.name()); //$NON-NLS-1$ + this.configurationContainer.setSignatureProfile(selected); + this.cmbSignatureProfiles.select(selected.ordinal()); + + if (selected.equals(Profile.AMTSSIGNATURBLOCK) || selected.equals(Profile.INVISIBLE)){ + this.configurationContainer.setDefaultSignaturePosition(new SignaturePosition()); + } + setSignatureProfileSetting(); + alignSignatureNoteTextToProfile(selected); + + } + + void alignSignatureNoteTextToProfile(Profile profile){ + + if (detectChanges(profile) == false){ + this.txtSignatureNote.setText(getSignatureBlockNoteTextAccordingToProfile(profile, SimpleConfigurationComposite.this.configurationContainer.getSignatureLocale())); + this.configurationContainer.setSignatureNote( + Messages.getString(getSignatureBlockNoteTextAccordingToProfile(profile, SimpleConfigurationComposite.this.configurationContainer.getSignatureLocale())) + ); + } + + } + + boolean detectChanges(Profile profile){ + + String note = this.txtSignatureNote.getText(); + note = note.replace("!",""); + if (note.equals(getSignatureBlockNoteTextAccordingToProfile(Profile.AMTSSIGNATURBLOCK, SimpleConfigurationComposite.this.configurationContainer.getSignatureLocale())) || + note.equals(getSignatureBlockNoteTextAccordingToProfile(Profile.SIGNATURBLOCK_SMALL, SimpleConfigurationComposite.this.configurationContainer.getSignatureLocale())) || + note.equals(getSignatureBlockNoteTextAccordingToProfile(Profile.INVISIBLE, SimpleConfigurationComposite.this.configurationContainer.getSignatureLocale())) || + note.equals(getSignatureBlockNoteTextAccordingToProfile(Profile.BASE_LOGO, SimpleConfigurationComposite.this.configurationContainer.getSignatureLocale()))){ + return false; + } + return true; + } + + + + String getSignatureBlockNoteTextAccordingToProfile(Profile profile, Locale signatureLocale){ + return Profile.getSignatureBlockNoteTextAccordingToProfile(profile, this.configurationContainer.getSignatureLocale()); + } + + void setSignatureProfileSetting(){ + if (this.signer == null){ + log.debug("In setSignatureProfileSettings: Signer was null"); + return; + } + try { + SignatureParameter param = this.signer.getPDFSigner().newParameter(); + param.setSignatureProfile(this.configurationContainer.getSignatureProfile().name()); + + } catch (Exception e){ + log.warn("Cannot save signature profile {}", e.getMessage()); + } + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#signerChanged() + */ + @Override + protected void signerChanged() { + this.setVisibleImage(); + this.setSignatureProfileSetting(); + } + + /** + * @throws InvalidNumberException + */ + private void plainMobileNumberSetter() throws InvalidNumberException { + String number = this.txtMobileNumber.getText(); + this.configurationContainer.setMobileNumber(number); + number = this.configurationContainer.getMobileNumber(); + if (number == null) { + this.txtMobileNumber.setText(""); //$NON-NLS-1$ + return; + } + this.txtMobileNumber.setText(number); + } + + void processSignatureNoteChanged() { + String note = this.txtSignatureNote.getText(); + this.configurationContainer.setSignatureNote(note); + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() + */ + @Override + public void doLayout() { + layout(true, true); + } + + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.composites.BaseConfigurationComposite#initConfiguration(at.asit.pdfover.gui.workflow.config.PersistentConfigProvider) + */ + @Override + public void initConfiguration(PersistentConfigProvider provider) { + try { + this.configurationContainer.setMobileNumber( + provider.getDefaultMobileNumberPersistent()); + } catch (InvalidNumberException e) { + log.error("Failed to set mobile phone number!", e); //$NON-NLS-1$ + } + + try { + this.configurationContainer.setEmblem( + provider.getDefaultEmblemPersistent()); + } catch (InvalidEmblemFile e) { + log.error("Failed to set emblem!", e); //$NON-NLS-1$ + } + + this.configurationContainer.setSignatureLocale( + provider.getSignatureLocale()); + + this.configurationContainer.setSignatureNote( + provider.getSignatureNote()); + } + + /* + * (non-Javadoc) + * @see at.asit.pdfover.gui.composites.BaseConfigurationComposite#loadConfiguration + * () + */ + @Override + public void loadConfiguration() { + // Initialize form fields from configuration Container + String number = this.configurationContainer.getMobileNumber(); + if (number != null) { + this.txtMobileNumber.setText(number); + } + + String emblemFile = this.configurationContainer.getEmblem(); + if (emblemFile != null && !emblemFile.trim().isEmpty()) { + this.logoFile = emblemFile; + try { + setEmblemFileInternal(emblemFile, true); + this.btnClearImage.setSelection(true); + } catch (Exception e1) { + log.error("Failed to load emblem: ", e1); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog( + getShell(), + Messages.getString("error.FailedToLoadEmblem"), BUTTONS.OK); //$NON-NLS-1$ + dialog.open(); + } + } + + String note = this.configurationContainer.getSignatureNote(); + + if (note != null) { + this.txtSignatureNote.setText(note); + } + + this.setVisibleImage(); + + this.performSignatureLangSelectionChanged(this.configurationContainer.getSignatureLocale(), null); + + this.preformProfileSelectionChanged(this.configurationContainer.getSignatureProfile()); + + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.composites.BaseConfigurationComposite#storeConfiguration(at.asit.pdfover.gui.workflow.config.ConfigManipulator, at.asit.pdfover.gui.workflow.config.PersistentConfigProvider) + */ + @Override + public void storeConfiguration(ConfigManipulator store, + PersistentConfigProvider provider) { + store.setDefaultMobileNumber(this.configurationContainer.getMobileNumber()); + + store.setDefaultEmblem(this.configurationContainer.getEmblem()); + + store.setSignatureLocale(this.configurationContainer.getSignatureLocale()); + + store.setSignatureNote(this.configurationContainer.getSignatureNote()); + + store.setSignatureProfile(this.configurationContainer.getSignatureProfile().name()); + + + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#validateSettings + * () + */ + @Override + public void validateSettings(int resumeFrom) throws Exception { + switch (resumeFrom) { + case 0: + this.plainMobileNumberSetter(); + // Fall through + case 1: + this.processSignatureNoteChanged(); + break; + default: + //Fall through + } + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() + */ + @Override + public void reloadResources() { + this.grpHandySignatur.setText(Messages + .getString("simple_config.MobileBKU_Title")); //$NON-NLS-1$ + this.lblMobileNumber.setText(Messages + .getString("simple_config.PhoneNumber")); //$NON-NLS-1$ + this.txtMobileNumber.setToolTipText(Messages + .getString("simple_config.ExampleNumber_ToolTip")); //$NON-NLS-1$ + this.txtMobileNumber.setMessage(Messages + .getString("simple_config.ExampleNumber")); //$NON-NLS-1$ + + this.grpLogo.setText(Messages + .getString("simple_config.Emblem_Title")); //$NON-NLS-1$ + this.lblDropLogo.setText(Messages.getString("simple_config.EmblemEmpty")); //$NON-NLS-1$ + this.btnClearImage.setText(Messages + .getString("simple_config.ClearEmblem")); //$NON-NLS-1$ + this.btnBrowseLogo.setText(Messages.getString("common.browse")); //$NON-NLS-1$ + + this.grpSignatureNote.setText(Messages + .getString("simple_config.Note_Title")); //$NON-NLS-1$ + this.lblSignatureNote.setText(Messages.getString("simple_config.Note")); //$NON-NLS-1$ + this.txtSignatureNote.setToolTipText(Messages + .getString("simple_config.Note_Tooltip")); //$NON-NLS-1$ + this.btnSignatureNoteDefault.setText(Messages + .getString("simple_config.Note_SetDefault")); //$NON-NLS-1$ + + this.grpSignatureLang.setText(Messages.getString("simple_config.SigBlockLang_Title")); //$NON-NLS-1$ + this.cmbSignatureLang.setToolTipText(Messages.getString("simple_config.SigBlockLang_ToolTip")); //$NON-NLS-1$ + } +} |