diff options
author | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:57:07 +0000 |
---|---|---|
committer | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:57:07 +0000 |
commit | a8222b9d16145d8b2f8803d13e5afe2b99d47fc0 (patch) | |
tree | 36637499e140a59d6e43f74eaceb3e23ec3e1f07 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites | |
parent | 9f07d0ac1f3d53d03a4f105b1b99dccd4ac2d473 (diff) | |
download | pdf-over-a8222b9d16145d8b2f8803d13e5afe2b99d47fc0.tar.gz pdf-over-a8222b9d16145d8b2f8803d13e5afe2b99d47fc0.tar.bz2 pdf-over-a8222b9d16145d8b2f8803d13e5afe2b99d47fc0.zip |
Configuration and Main Bar Buttons
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@53 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites')
10 files changed, 636 insertions, 506 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java index 5b826097..e3869105 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java @@ -17,12 +17,30 @@ package at.asit.pdfover.gui.composites; // Imports import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.TabItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.controls.ErrorDialog; +import at.asit.pdfover.gui.workflow.ConfigurationContainer; import at.asit.pdfover.gui.workflow.states.State; +import at.asit.pdfover.signator.BKUs; + import org.eclipse.swt.widgets.Label; import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Text; /** * @@ -36,11 +54,234 @@ public class AdvancedConfigurationComposite extends BaseConfigurationComposite { public AdvancedConfigurationComposite(Composite parent, int style, State state, ConfigurationContainer container) { super(parent, style, state, container); + setLayout(new FormLayout()); + + TabFolder tabFolder = new TabFolder(this, SWT.NONE); + FormData fd_tabFolder = new FormData(); + fd_tabFolder.bottom = new FormAttachment(100, -5); + fd_tabFolder.right = new FormAttachment(100, -5); + fd_tabFolder.top = new FormAttachment(0, 5); + fd_tabFolder.left = new FormAttachment(0, 5); + tabFolder.setLayoutData(fd_tabFolder); + + TabItem simpleTabItem = new TabItem(tabFolder, SWT.NULL); + simpleTabItem.setText("Simple"); + + this.simpleComposite = new SimpleConfigurationComposite(tabFolder, + SWT.NONE, state, container); + + simpleTabItem.setControl(this.simpleComposite); + + TabItem advancedTabItem = new TabItem(tabFolder, SWT.NULL); + advancedTabItem.setText("Advanced"); + + Composite advancedComposite = new Composite(tabFolder, SWT.NONE); + + advancedTabItem.setControl(advancedComposite); + advancedComposite.setLayout(new FormLayout()); + + Group grpSignaturPosition = new Group(advancedComposite, SWT.NONE); + grpSignaturPosition.setText("Signatur Position"); + grpSignaturPosition.setLayout(new FormLayout()); + FormData fd_grpSignaturPosition = new FormData(); + fd_grpSignaturPosition.top = new FormAttachment(0, 5); + fd_grpSignaturPosition.bottom = new FormAttachment(33, -5); + fd_grpSignaturPosition.right = new FormAttachment(100, -5); + fd_grpSignaturPosition.left = new FormAttachment(0, 5); + grpSignaturPosition.setLayoutData(fd_grpSignaturPosition); + + this.btnAutomatischePositionierung = new Button(grpSignaturPosition, + SWT.CHECK); + FormData fd_btnAutomatischePositionierung = new FormData(); + fd_btnAutomatischePositionierung.right = new FormAttachment(100, -5); + fd_btnAutomatischePositionierung.top = new FormAttachment(0, 5); + fd_btnAutomatischePositionierung.left = new FormAttachment(0, 5); + this.btnAutomatischePositionierung + .setLayoutData(fd_btnAutomatischePositionierung); + this.btnAutomatischePositionierung.setText("Automatische Positionierung"); - Label lblAdvancedConfigLayout = new Label(this, SWT.NONE); - lblAdvancedConfigLayout.setBounds(113, 126, 243, 15); - lblAdvancedConfigLayout.setText("Advanced Config Layout!"); - // TODO Auto-generated constructor stub + this.btnAutomatischePositionierung.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + AdvancedConfigurationComposite.this.performPositionSelection( + AdvancedConfigurationComposite.this.btnAutomatischePositionierung.getSelection()); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // Nothing to do + } + }); + + Group grpBkuAuswahl = new Group(advancedComposite, SWT.NONE); + grpBkuAuswahl.setText("BKU Selection"); + grpBkuAuswahl.setLayout(new FormLayout()); + FormData fd_grpBkuAuswahl = new FormData(); + fd_grpBkuAuswahl.top = new FormAttachment(33, 5); + fd_grpBkuAuswahl.left = new FormAttachment(0, 5); + fd_grpBkuAuswahl.right = new FormAttachment(100, -5); + fd_grpBkuAuswahl.bottom = new FormAttachment(66, -5); + grpBkuAuswahl.setLayoutData(fd_grpBkuAuswahl); + + this.cmbBKUAuswahl = new Combo(grpBkuAuswahl, SWT.NONE); + FormData fd_cmbBKUAuswahl = new FormData(); + fd_cmbBKUAuswahl.right = new FormAttachment(100, -5); + fd_cmbBKUAuswahl.top = new FormAttachment(0, 5); + fd_cmbBKUAuswahl.left = new FormAttachment(0, 5); + + int blen = BKUs.values().length; + + this.bkuStrings = new String[blen]; + + // TODO: Implement translation into user language for ENUM Values!! + for (int i = 0; i < blen; i++) { + this.bkuStrings[i] = BKUs.values()[i].toString(); + } + + this.cmbBKUAuswahl.setItems(this.bkuStrings); + + this.cmbBKUAuswahl.setLayoutData(fd_cmbBKUAuswahl); + + this.cmbBKUAuswahl.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + int selectionIndex = getBKUElementIndex(AdvancedConfigurationComposite.this.configurationContainer.getBKUSelection()); + if(AdvancedConfigurationComposite.this.cmbBKUAuswahl.getSelectionIndex() != selectionIndex) { + selectionIndex = AdvancedConfigurationComposite.this.cmbBKUAuswahl.getSelectionIndex(); + performBKUSelectionChanged(AdvancedConfigurationComposite.this.cmbBKUAuswahl.getItem(selectionIndex)); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // Nothing to do here + } + }); + + Group grpSpeicherort = new Group(advancedComposite, SWT.NONE); + grpSpeicherort.setText("Outputfolder"); + grpSpeicherort.setLayout(new FormLayout()); + FormData fd_grpSpeicherort = new FormData(); + fd_grpSpeicherort.top = new FormAttachment(66, 5); + fd_grpSpeicherort.left = new FormAttachment(0, 5); + fd_grpSpeicherort.right = new FormAttachment(100, -5); + fd_grpSpeicherort.bottom = new FormAttachment(100, -5); + grpSpeicherort.setLayoutData(fd_grpSpeicherort); + + Label lblDefaultOutputFolder = new Label(grpSpeicherort, SWT.NONE); + FormData fd_lblDefaultOutputFolder = new FormData(); + fd_lblDefaultOutputFolder.top = new FormAttachment(0, 5); + fd_lblDefaultOutputFolder.left = new FormAttachment(0, 5); + lblDefaultOutputFolder.setLayoutData(fd_lblDefaultOutputFolder); + lblDefaultOutputFolder.setText("Default output folder:"); + + this.txtOutputFolder = new Text(grpSpeicherort, SWT.BORDER); + FormData fd_text = new FormData(); + fd_text.top = new FormAttachment(lblDefaultOutputFolder, 5); + fd_text.left = new FormAttachment(0, 5); + this.txtOutputFolder.setLayoutData(fd_text); + + this.txtOutputFolder.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + performOutputFolderChanged(AdvancedConfigurationComposite.this.txtOutputFolder.getText()); + } + + @Override + public void focusGained(FocusEvent e) { + // Nothing to do here! + } + }); + + Button btnBrowse = new Button(grpSpeicherort, SWT.NONE); + fd_text.right = new FormAttachment(btnBrowse, -5); + + FormData fd_btnBrowse = new FormData(); + fd_btnBrowse.top = new FormAttachment(lblDefaultOutputFolder, 5); + fd_btnBrowse.right = new FormAttachment(100, -5); + btnBrowse.setLayoutData(fd_btnBrowse); + btnBrowse.setText("browse"); + + btnBrowse.addSelectionListener(new SelectionListener() { + + @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("Select Output folder"); + + // Customizable message displayed in the dialog + dlg.setMessage("Select a directory"); + + // 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); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // Nothing to do + } + }); + } + + 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) { + // TODO: Translate to user language! + String bkuName = bku.toString(); + + for(int i = 0; i < this.bkuStrings.length; i++) { + if(this.bkuStrings[i].equals(bkuName)) { + log.debug("BKU: " + bkuName + " IDX: " + i); //$NON-NLS-1$ //$NON-NLS-2$ + return i; + } + } + + log.warn("NO BKU match for " + bkuName); //$NON-NLS-1$ + return 0; + } + + void performBKUSelectionChanged(BKUs selected) { + log.debug("Selected BKU: " + selected.toString()); //$NON-NLS-1$ + this.configurationContainer.setBKUSelection(selected); + this.cmbBKUAuswahl.select(this.getBKUElementIndex(selected)); + } + + void performBKUSelectionChanged(String selected) { + try { + BKUs bkuvalue = BKUs.valueOf(selected); + this.performBKUSelectionChanged(bkuvalue); + } catch (Exception ex) { + log.error("Failed to parse BKU value: " + selected, ex); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, "Invalid BKU selection. Please check.", ex); + dialog.open(); + } + } + + void performPositionSelection(boolean automatic) { + log.debug("Selected Position: " + automatic); //$NON-NLS-1$ + this.configurationContainer.setAutomaticPosition(automatic); + this.btnAutomatischePositionierung.setSelection(automatic); } /** @@ -48,13 +289,44 @@ public class AdvancedConfigurationComposite extends BaseConfigurationComposite { **/ private static final Logger log = LoggerFactory .getLogger(AdvancedConfigurationComposite.class); + SimpleConfigurationComposite simpleComposite; + Text txtOutputFolder; + Combo cmbBKUAuswahl; + String[] bkuStrings; + Button btnAutomatischePositionierung; - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() */ @Override public void doLayout() { - // TODO Auto-generated method stub - + // Nothing to do here + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#loadConfiguration + * () + */ + @Override + public void loadConfiguration() { + this.simpleComposite.loadConfiguration(); + + // load advanced settings + this.performBKUSelectionChanged(this.configurationContainer.getBKUSelection()); + this.performOutputFolderChanged(this.configurationContainer.getOutputFolder()); + this.performPositionSelection(this.configurationContainer.getAutomaticPosition()); + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.composites.BaseConfigurationComposite#validateSettings() + */ + @Override + public void validateSettings() throws Exception { + this.simpleComposite.validateSettings(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java index 88156343..19b3f46c 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java @@ -19,6 +19,8 @@ package at.asit.pdfover.gui.composites; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; @@ -111,24 +113,32 @@ public class BKUSelectionComposite extends StateComposite { btn_mobile.setText("MOBILE"); //Point mobile_size = btn_mobile.computeSize(SWT.DEFAULT, SWT.DEFAULT); FormData fd_btn_mobile = new FormData(); - fd_btn_mobile.left = new FormAttachment(40, 0); - fd_btn_mobile.right = new FormAttachment(50, 0); - fd_btn_mobile.top = new FormAttachment(45, 0); - fd_btn_mobile.bottom = new FormAttachment(55, 0); + //fd_btn_mobile.left = new FormAttachment(40, 0); + fd_btn_mobile.right = new FormAttachment(50, -5); + fd_btn_mobile.top = new FormAttachment(40, 0); + //fd_btn_mobile.bottom = new FormAttachment(55, 0); btn_mobile.setLayoutData(fd_btn_mobile); btn_mobile.addSelectionListener(new MobileSelectionListener()); + Image mobile = new Image(getDisplay(), new ImageData(this.getClass().getResourceAsStream("/img/handy.gif"))); + + btn_mobile.setImage(mobile); + Button btn_card = new Button(this, SWT.NATIVE | SWT.RESIZE); btn_card.setText("CARD"); //Point card_size = btn_card.computeSize(SWT.DEFAULT, SWT.DEFAULT); FormData fd_btn_card = new FormData(); - fd_btn_card.left = new FormAttachment(50, 0); - fd_btn_card.right = new FormAttachment(60, 0); - fd_btn_card.top = new FormAttachment(45, 0); - fd_btn_card.bottom = new FormAttachment(55, 0); + fd_btn_card.left = new FormAttachment(50, 5); + //fd_btn_card.right = new FormAttachment(60, 0); + fd_btn_card.top = new FormAttachment(40, 0); + //fd_btn_card.bottom = new FormAttachment(55, 0); btn_card.setLayoutData(fd_btn_card); btn_card.addSelectionListener(new LocalSelectionListener()); + Image karte = new Image(getDisplay(), new ImageData(this.getClass().getResourceAsStream("/img/karte.gif"))); + + btn_card.setImage(karte); + this.pack(); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java index 831a4aa6..3c79e124 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java @@ -17,6 +17,8 @@ package at.asit.pdfover.gui.composites; import org.eclipse.swt.widgets.Composite; + +import at.asit.pdfover.gui.workflow.ConfigurationContainer; import at.asit.pdfover.gui.workflow.states.State; /** @@ -39,4 +41,16 @@ public abstract class BaseConfigurationComposite extends StateComposite { super(parent, style, state); this.configurationContainer = configuration; } + + /** + * Load configuration from ConfigurationContainer + */ + public abstract void loadConfiguration(); + + /** + * Called before exit. + * The method validates every setting in the configuration before exit + * @throws Exception + */ + public abstract void validateSettings() throws Exception; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java index db58ae4a..0e78e507 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java @@ -16,13 +16,23 @@ package at.asit.pdfover.gui.composites; // Imports +import java.io.IOException; + import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.controls.ErrorDialog; +import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; +import at.asit.pdfover.gui.exceptions.InvalidNumberException; +import at.asit.pdfover.gui.exceptions.InvalidPortException; import at.asit.pdfover.gui.workflow.ConfigManipulator; +import at.asit.pdfover.gui.workflow.ConfigProvider; +import at.asit.pdfover.gui.workflow.ConfigurationContainer; +import at.asit.pdfover.gui.workflow.ConfigurationContainerImpl; import at.asit.pdfover.gui.workflow.states.State; +import at.asit.pdfover.signator.SignaturePosition; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; @@ -38,7 +48,7 @@ import org.eclipse.swt.layout.FormAttachment; * */ public class ConfigurationComposite extends StateComposite { - + /** * */ @@ -57,7 +67,7 @@ public class ConfigurationComposite extends StateComposite { // switch to advanced ConfigurationComposite.this.configComposite.dispose(); ConfigurationComposite.this.configComposite = new AdvancedConfigurationComposite( - ConfigurationComposite.this.containerComposite, + ConfigurationComposite.this.containerComposite, ConfigurationComposite.this.style, ConfigurationComposite.this.state, ConfigurationComposite.this.configurationContainer); @@ -66,13 +76,14 @@ public class ConfigurationComposite extends StateComposite { // switch to simple ConfigurationComposite.this.configComposite.dispose(); ConfigurationComposite.this.configComposite = new SimpleConfigurationComposite( - ConfigurationComposite.this.containerComposite, + ConfigurationComposite.this.containerComposite, ConfigurationComposite.this.style, ConfigurationComposite.this.state, ConfigurationComposite.this.configurationContainer); ConfigurationComposite.this.btnAdvanced.setText("Advanced"); } - + + ConfigurationComposite.this.configComposite.loadConfiguration(); ConfigurationComposite.this.compositeStack.topControl = ConfigurationComposite.this.configComposite; ConfigurationComposite.this.doLayout(); } @@ -91,10 +102,12 @@ public class ConfigurationComposite extends StateComposite { ConfigManipulator configManipulator = null; + ConfigProvider configProvider = null; + BaseConfigurationComposite configComposite; ConfigurationContainer configurationContainer = new ConfigurationContainerImpl(); - + StackLayout compositeStack = new StackLayout(); int style; @@ -115,6 +128,54 @@ public class ConfigurationComposite extends StateComposite { } /** + * Sets the configuration provider + * + * @param provider + */ + public void setConfigProvider(ConfigProvider provider) { + this.configProvider = provider; + if (this.configProvider != null) { + + // Initialize Configuration Container + if (this.configProvider.getDefaultSignaturePosition() != null) { + this.configurationContainer + .setAutomaticPosition(this.configProvider + .getDefaultSignaturePosition() + .useAutoPositioning()); + } + + this.configurationContainer.setBKUSelection(this.configProvider + .getDefaultBKU()); + try { + this.configurationContainer.setEmblem(this.configProvider + .getDefaultEmblem()); + } catch (InvalidEmblemFile e) { + log.error("Failed to set emblem!", e); //$NON-NLS-1$ + } + try { + this.configurationContainer.setNumber(this.configProvider + .getDefaultMobileNumber()); + } catch (InvalidNumberException e) { + log.error("Failed to set mobile phone number!", e); //$NON-NLS-1$ + } + + this.configurationContainer.setOutputFolder(this.configProvider + .getDefaultOutputFolder()); + + this.configurationContainer.setProxyHost(this.configProvider + .getProxyHost()); + try { + this.configurationContainer.setProxyPort(this.configProvider + .getProxyPort()); + } catch (InvalidPortException e) { + log.error("Failed to set proxy port!", e); //$NON-NLS-1$ + } + + this.configComposite.loadConfiguration(); + } + } + + /** * Create the composite. * * @param parent @@ -130,7 +191,8 @@ public class ConfigurationComposite extends StateComposite { this.containerComposite = new Composite(this, SWT.FILL | SWT.RESIZE); this.configComposite = new SimpleConfigurationComposite( - this.containerComposite, SWT.FILL | style, state, this.configurationContainer); + this.containerComposite, SWT.FILL | style, state, + this.configurationContainer); FormData fd_composite = new FormData(); fd_composite.top = new FormAttachment(0, 5); @@ -151,6 +213,10 @@ public class ConfigurationComposite extends StateComposite { btnSpeichern.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { + if (ConfigurationComposite.this.storeConfiguration()) { + ConfigurationComposite.this.userDone = true; + ConfigurationComposite.this.state.updateStateMachine(); + } } }); btnSpeichern.setText("Speichern"); @@ -180,16 +246,63 @@ public class ConfigurationComposite extends StateComposite { } - private void storeConfiguration() { - // TODO: Collect info from UI and set in ConfigManipulator + boolean storeConfiguration() { + + try { + this.configComposite.validateSettings(); - // TODO: call save configuration in ConfigManipulator + // Write current Configuration + this.configManipulator.setDefaultBKU(this.configurationContainer + .getBKUSelection()); + this.configManipulator + .setDefaultMobileNumber(this.configurationContainer + .getNumber()); + if (this.configurationContainer.getAutomaticPosition()) { + this.configManipulator + .setDefaultSignaturePosition(new SignaturePosition()); + } else { + this.configManipulator + .setDefaultSignaturePosition(null); + } + + this.configManipulator + .setDefaultOutputFolder(this.configurationContainer + .getOutputFolder()); + + this.configManipulator.setProxyHost(this.configurationContainer + .getProxyHost()); + this.configManipulator.setProxyPort(this.configurationContainer + .getProxyPort()); + this.configManipulator.setDefaultEmblem(this.configurationContainer + .getEmblem()); + + } catch (Exception e) { + log.error("Settings validation failed!", e); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog( + getShell(), + SWT.NONE, + "Invalid settings are still present. Please check your input.", + e); + dialog.open(); + return false; + } + // Save current config to file + try { + this.configManipulator.saveCurrentConfiguration(); + } catch (IOException e) { + log.error("Failed to save configuration to file!", e); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, + "Failed to save configuration file!", e); + dialog.open(); + return false; + } + return true; } /** * Checks if the user has finished working with the configuration composite * - * @return + * @return if the user is done */ public boolean isUserDone() { return this.userDone; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainer.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainer.java deleted file mode 100644 index 66245123..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainer.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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; - -import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; -import at.asit.pdfover.gui.exceptions.InvalidNumberException; -import at.asit.pdfover.gui.exceptions.InvalidPortException; -import at.asit.pdfover.signator.BKUs; - -/** - * - */ -public interface ConfigurationContainer { - - /** - * Gets the configured emblem - * @return the configured emblem - */ - public String getEmblem(); - - /** - * Sets the emblem - * @param emblem the emblem - * @throws InvalidEmblemFile - */ - public void setEmblem(String emblem) throws InvalidEmblemFile; - - /** - * Gets the mobile phone number - * @return the mobile phone number - */ - public String getNumber(); - - /** - * Sets the mobile phone number - * @param number the mobile phone number - * @throws InvalidNumberException - */ - public void setNumber(String number) throws InvalidNumberException; - - /** - * Gets the proxy host - * @return the proxy host - */ - public String getProxyHost(); - - /** - * Sets the proxy host - * @param host the proxy host - */ - public void setProxyHost(String host); - - /** - * Gets the proxy port - * - * if port is -1 no port is selected - * - * @return the proxy port - */ - public int getProxyPort(); - - /** - * Sets the proxy port - * - * set to -1 for no port - * - * @param port the proxy port - * @throws InvalidPortException - */ - public void setProxyPort(int port) throws InvalidPortException; - - /** - * Gets the automatic position - * @return the automatic position - */ - public boolean getAutomaticPosition(); - - /** - * Sets the automatic position - * @param automatic the automatic position - */ - public void setAutomaticPosition(boolean automatic); - - /** - * Gets the default BKU - * @return the default BKU - */ - public BKUs getBKUSelection(); - - /** - * Sets the default BKU - * @param bkuSelection the default BKU - */ - public void setBKUSelection(BKUs bkuSelection); - - /** - * Gets the default output folder - * @return the default output folder - */ - public String getOutputFolder(); - - /** - * Sets the default output folder - * @param folder the default output folder - */ - public void setOutputFolder(String folder); -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainerImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainerImpl.java deleted file mode 100644 index dd305201..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainerImpl.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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; - -// Imports -import java.io.File; -import java.io.FileNotFoundException; - -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.widgets.Display; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; -import at.asit.pdfover.gui.exceptions.InvalidNumberException; -import at.asit.pdfover.gui.exceptions.InvalidPortException; -import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHelper; -import at.asit.pdfover.signator.BKUs; - -/** - * - */ -public class ConfigurationContainerImpl implements ConfigurationContainer { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(ConfigurationContainerImpl.class); - - - /** - * the emblem File - */ - protected String emblemFile = null; - - /** - * The mobile phone number - */ - protected String mobileNumber = null; - - /** - * Holds the proxy Host - */ - protected String proxyHost = null; - - /** - * Holds the proxy port number - */ - protected int proxyPort = -1; - - /** - * Holds the output folder - */ - protected String folder = null; - - /** - * Holds the default BKU to use - */ - protected BKUs defaulBKU = BKUs.NONE; - - /** - * Holds the automatic positioning value - */ - protected boolean automaticPositioning = false; - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getEmblem() - */ - @Override - public String getEmblem() { - return this.emblemFile; - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setEmblem(java.lang.String) - */ - @Override - public void setEmblem(String emblemFile) throws InvalidEmblemFile { - if (emblemFile == null || emblemFile.trim().equals("")) { //$NON-NLS-1$ - // Ok to set no file ... - } else { - File imageFile = new File(emblemFile); - if (!imageFile.exists()) { - throw new InvalidEmblemFile(imageFile, - new FileNotFoundException(emblemFile)); - } - - try { - Image img = new Image(Display.getDefault(), new ImageData( - emblemFile)); - - img.dispose(); - } catch (Exception ex) { - throw new InvalidEmblemFile(imageFile, ex); - } - } - - this.emblemFile = emblemFile; - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getNumber() - */ - @Override - public String getNumber() { - return this.mobileNumber; - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setNumber(java.lang.String) - */ - @Override - public void setNumber(String number) throws InvalidNumberException { - if(number == null || number.trim().equals("")) { //$NON-NLS-1$ - this.mobileNumber = null; - return; - } - this.mobileNumber = ATrustHelper.normalizeMobileNumber(number); - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getProxyHost() - */ - @Override - public String getProxyHost() { - return this.proxyHost; - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setProxyHost(java.lang.String) - */ - @Override - public void setProxyHost(String host) { - this.proxyHost = host; - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getProxyPort() - */ - @Override - public int getProxyPort() { - return this.proxyPort; - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setProxyPort(int) - */ - @Override - public void setProxyPort(int port) throws InvalidPortException { - if(port > 0 && port < 0xFFFF) { - this.proxyPort = port; - return; - } - if(port == -1) { - this.proxyPort = -1; - return; - } - throw new InvalidPortException(port); - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getAutomaticPosition() - */ - @Override - public boolean getAutomaticPosition() { - return this.automaticPositioning; - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setAutomaticPosition(boolean) - */ - @Override - public void setAutomaticPosition(boolean automatic) { - this.automaticPositioning = automatic; - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getBKUSelection() - */ - @Override - public BKUs getBKUSelection() { - return this.defaulBKU; - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setBKUSelection(at.asit.pdfover.signator.BKUs) - */ - @Override - public void setBKUSelection(BKUs bkuSelection) { - this.defaulBKU = bkuSelection; - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getOutputFolder() - */ - @Override - public String getOutputFolder() { - return this.folder; - } - - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setOutputFolder(java.lang.String) - */ - @Override - public void setOutputFolder(String folder) { - this.folder = folder; - } - -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/DataSourceSelectComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/DataSourceSelectComposite.java index 91ac7d6d..ac7494e8 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/DataSourceSelectComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/DataSourceSelectComposite.java @@ -118,9 +118,9 @@ public class DataSourceSelectComposite extends StateComposite { this.setLayout(new FormLayout()); - Color back = new Color(Display.getCurrent(), 77, 190, 250); + //Color back = new Color(Display.getCurrent(), 77, 190, 250); - this.drop_area = new Composite(this, SWT.RESIZE | SWT.BORDER_DASH); + this.drop_area = new Composite(this, SWT.RESIZE | SWT.BORDER); FormData fd_drop_area = new FormData(); fd_drop_area.left = new FormAttachment(0, 0); fd_drop_area.right = new FormAttachment(100, 0); @@ -128,7 +128,7 @@ public class DataSourceSelectComposite extends StateComposite { fd_drop_area.bottom = new FormAttachment(100, 0); this.drop_area.setLayoutData(fd_drop_area); this.drop_area.setLayout(new FormLayout()); - this.drop_area.setBackground(back); + //this.drop_area.setBackground(back); DropTarget dnd_target = new DropTarget(this.drop_area, DND.DROP_DEFAULT | DND.DROP_COPY); @@ -195,17 +195,17 @@ public class DataSourceSelectComposite extends StateComposite { final Label lbl_drag = new Label(this.drop_area, SWT.NONE | SWT.RESIZE); FormData fd_lbl_drag = new FormData(); - fd_lbl_drag.left = new FormAttachment(5, 5); - fd_lbl_drag.right = new FormAttachment(100, -5); - fd_lbl_drag.top = new FormAttachment(5, 5); - fd_lbl_drag.bottom = new FormAttachment(55, -5); + fd_lbl_drag.left = new FormAttachment(0, 10); + fd_lbl_drag.right = new FormAttachment(100, -10); + fd_lbl_drag.top = new FormAttachment(0, 10); + //fd_lbl_drag.bottom = new FormAttachment(100, -10); lbl_drag.setLayoutData(fd_lbl_drag); FontData[] fD = lbl_drag.getFont().getFontData(); fD[0].setHeight(18); lbl_drag.setFont(new Font(Display.getCurrent(), fD[0])); - lbl_drag.setText("Drag and Drop"); + lbl_drag.setText("To sign a document\ndrag and drop it here\nor use the button below"); lbl_drag.setAlignment(SWT.CENTER); - lbl_drag.setBackground(back); + //lbl_drag.setBackground(back); Button btn_open = new Button(this.drop_area, SWT.NATIVE | SWT.RESIZE); btn_open.setText("Choose file ..."); @@ -216,24 +216,9 @@ public class DataSourceSelectComposite extends StateComposite { fd_btn_open.top = new FormAttachment(100, size.y * -1 - 10); fd_btn_open.bottom = new FormAttachment(100, -5); btn_open.setLayoutData(fd_btn_open); - btn_open.setBackground(back); + //btn_open.setBackground(back); btn_open.addSelectionListener(new FileBrowseDialogListener()); this.drop_area.pack(); - - /* - * Button btn = new Button(this, SWT.NATIVE); btn.setBounds(50, 20, 100, - * 50); btn.setText("Click Me"); btn.addSelectionListener(new - * SelectionListener() { - * - * @Override public void widgetSelected(SelectionEvent arg0) { - * DataSourceSelectComposite.this.setPress(true); - * DataSourceSelectComposite.this.workflow.update(); } - * - * @Override public void widgetDefaultSelected(SelectionEvent arg0) { // - * TODO Auto-generated method stub - * - * } }); - */ } private boolean press = false; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java index bd630f8e..595ca1bd 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java @@ -16,12 +16,9 @@ package at.asit.pdfover.gui.composites; // Imports -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; @@ -37,13 +34,6 @@ import at.asit.pdfover.gui.exceptions.InvalidPasswordException; import at.asit.pdfover.gui.workflow.states.State; import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHelper; -import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; - /** * */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java index f6653da8..26e5480c 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java @@ -147,10 +147,10 @@ public class OutputComposite extends StateComposite { btn_open.setText("OPEN"); // Point mobile_size = btn_mobile.computeSize(SWT.DEFAULT, SWT.DEFAULT); FormData fd_btn_open = new FormData(); - fd_btn_open.left = new FormAttachment(40, 0); - fd_btn_open.right = new FormAttachment(50, 0); - fd_btn_open.top = new FormAttachment(45, 0); - fd_btn_open.bottom = new FormAttachment(55, 0); + //fd_btn_open.left = new FormAttachment(40, 0); + fd_btn_open.right = new FormAttachment(50, -5); + fd_btn_open.top = new FormAttachment(40, 0); + //fd_btn_open.bottom = new FormAttachment(55, 0); btn_open.setLayoutData(fd_btn_open); btn_open.addSelectionListener(new OpenSelectionListener()); @@ -162,10 +162,10 @@ public class OutputComposite extends StateComposite { btn_save.setText("SAVE"); // Point card_size = btn_card.computeSize(SWT.DEFAULT, SWT.DEFAULT); FormData fd_btn_save = new FormData(); - fd_btn_save.left = new FormAttachment(50, 0); - fd_btn_save.right = new FormAttachment(60, 0); - fd_btn_save.top = new FormAttachment(45, 0); - fd_btn_save.bottom = new FormAttachment(55, 0); + fd_btn_save.left = new FormAttachment(50, 5); + //fd_btn_save.right = new FormAttachment(60, 0); + fd_btn_save.top = new FormAttachment(40, 0); + //fd_btn_save.bottom = new FormAttachment(55, 0); btn_save.setLayoutData(fd_btn_save); btn_save.addSelectionListener(new SaveSelectionListener()); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java index 0e8bea04..3830d6cf 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java @@ -19,6 +19,12 @@ package at.asit.pdfover.gui.composites; import java.io.File; 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.FocusEvent; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.MouseEvent; @@ -50,6 +56,9 @@ import org.slf4j.LoggerFactory; 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.exceptions.InvalidPortException; +import at.asit.pdfover.gui.workflow.ConfigurationContainer; import at.asit.pdfover.gui.workflow.states.State; import org.eclipse.swt.layout.FillLayout; @@ -195,7 +204,8 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { this.recalculateEmblemSize(); } catch (Exception e) { - this.lblEmblem.setText("No Image"); + this.lblEmblem + .setText("No Image. Drag and Drop a Image. Or use the browse button to select an emblem."); this.lblEmblem.setImage(null); if (this.origEmblem != null) { this.origEmblem.dispose(); @@ -212,27 +222,27 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { void processEmblemChanged(String filename) { try { // String filename = this.txtEmblemFile.getText(); - this.emblemFile = filename; - this.setEmblemFileInternal(filename); - this.btnUseImage.setSelection(true); + plainEmblemSetter(filename); } catch (Exception ex) { // TODO: Show error message! log.error("processEmblemChanged: ", ex); //$NON-NLS-1$ } } + /** + * @param filename + * @throws Exception + */ + private void plainEmblemSetter(String filename) throws Exception { + this.emblemFile = filename; + this.setEmblemFileInternal(filename); + this.btnUseImage.setSelection(true); + } + void processNumberChanged() { try { - this.txtMobileNumberErrorMarker.setVisible(false); - String number = this.txtMobileNumber.getText(); - this.configurationContainer.setNumber(number); - number = this.configurationContainer.getNumber(); - if (number == null) { - this.txtMobileNumber.setText(""); //$NON-NLS-1$ - return; - } - this.txtMobileNumber.setText(number); + plainMobileNumberSetter(); } catch (Exception ex) { // TODO: Show error message! this.txtMobileNumberErrorMarker.setVisible(true); @@ -242,11 +252,24 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { } } + /** + * @throws InvalidNumberException + */ + private void plainMobileNumberSetter() throws InvalidNumberException { + String number = this.txtMobileNumber.getText(); + this.configurationContainer.setNumber(number); + number = this.configurationContainer.getNumber(); + if (number == null) { + this.txtMobileNumber.setText(""); //$NON-NLS-1$ + return; + } + this.txtMobileNumber.setText(number); + } + void processProxyHostChanged() { try { this.proxyHostErrorMarker.setVisible(false); - String host = this.txtProxyHost.getText(); - this.configurationContainer.setProxyHost(host); + plainProxyHostSetter(); } catch (Exception ex) { // TODO: Show error message! this.proxyHostErrorMarker.setVisible(true); @@ -255,17 +278,18 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { } } + /** + * + */ + private void plainProxyHostSetter() { + String host = this.txtProxyHost.getText(); + this.configurationContainer.setProxyHost(host); + } + void processProxyPortChanged() { try { this.txtProxyPortErrorMarker.setVisible(false); - String portString = this.txtProxyPort.getText(); - int port = -1; - if (portString == null || portString.trim().equals("")) { - port = -1; - } else { - port = Integer.parseInt(portString); - } - this.configurationContainer.setProxyPort(port); + plainProxyPortSetter(); } catch (Exception ex) { // TODO: Show error message! this.txtProxyPortErrorMarker.setVisible(true); @@ -274,6 +298,20 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { } } + /** + * @throws InvalidPortException + */ + private void plainProxyPortSetter() throws InvalidPortException { + String portString = this.txtProxyPort.getText(); + int port = -1; + if (portString == null || portString.trim().equals("")) { //$NON-NLS-1$ + port = -1; + } else { + port = Integer.parseInt(portString); + } + this.configurationContainer.setProxyPort(port); + } + ConfigurationComposite configurationComposite; FormData fd_txtProxyPortErrorMarker; @@ -396,45 +434,84 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { } }); - /* - * Label lblDateiname = new Label(grpBildmarke, SWT.NONE); - * lblDateiname.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, - * false, false, 1, 1)); lblDateiname.setText("Dateiname:"); new - * Label(grpBildmarke, SWT.NONE); - */ + DropTarget dnd_target = new DropTarget(this.lblEmblem, 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: " + files[0] + " does not exist!"); //$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.txtEmblemFile = new Text(grpBildmarke, SWT.BORDER); GridData - * gd_txtEmblemFile = new GridData(SWT.FILL, SWT.FILL, false, false, 2, - * 1); gd_txtEmblemFile.widthHint = 123; - * this.txtEmblemFile.setLayoutData(gd_txtEmblemFile); - * this.txtEmblemFile.addFocusListener(new FocusListener() { - * - * @Override public void focusLost(FocusEvent e) { - * processEmblemChanged(); } - * - * @Override public void focusGained(FocusEvent e) { // Nothing to do - * here! } }); this.txtEmblemFile.addTraverseListener(new - * TraverseListener() { - * - * @Override public void keyTraversed(TraverseEvent e) { if (e.detail == - * SWT.TRAVERSE_RETURN) { processEmblemChanged(); } } }); new - * Label(grpBildmarke, SWT.NONE); - */ new Label(grpBildmarke, SWT.NONE); new Label(grpBildmarke, SWT.NONE); this.btnUseImage = new Button(grpBildmarke, SWT.CHECK); this.btnUseImage.setText("Use Image"); this.btnUseImage.addSelectionListener(new SelectionListener() { - + @Override public void widgetSelected(SelectionEvent e) { - if(SimpleConfigurationComposite.this.btnUseImage.getSelection()) { + if (SimpleConfigurationComposite.this.btnUseImage + .getSelection()) { processEmblemChanged(SimpleConfigurationComposite.this.emblemFile); } else { try { - SimpleConfigurationComposite.this.configurationContainer.setEmblem(null); + SimpleConfigurationComposite.this.configurationContainer + .setEmblem(null); } catch (InvalidEmblemFile e1) { // TODO Auto-generated catch block e1.printStackTrace(); @@ -572,35 +649,6 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { } }); - // Initialize form fields from configuration Container - String number = this.configurationContainer.getNumber(); - if (number != null) { - this.txtMobileNumber.setText(number); - } - - String emblemFile = this.configurationContainer.getEmblem(); - if (emblemFile != null && !emblemFile.trim().equals("")) { //$NON-NLS-1$ - // this.txtEmblemFile.setText(emblemFile); - this.emblemFile = emblemFile; - try { - this.setEmblemFileInternal(emblemFile, true); - } catch (Exception e1) { - // TODO Auto-generated catch block - log.error("initialize emblem: ", e1); //$NON-NLS-1$ - } - } - - 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); - } - this.addListener(SWT.Resize, new Listener() { @Override @@ -638,7 +686,7 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { /** * SLF4J Logger instance **/ - private static final Logger log = LoggerFactory + static final Logger log = LoggerFactory .getLogger(SimpleConfigurationComposite.class); private ErrorMarker proxyHostErrorMarker; ErrorMarker txtMobileNumberErrorMarker; @@ -655,7 +703,61 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { */ @Override public void doLayout() { - // TODO Auto-generated method stub + // Nothing to do here + } + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#loadConfiguration + * () + */ + @Override + public void loadConfiguration() { + // Initialize form fields from configuration Container + String number = this.configurationContainer.getNumber(); + if (number != null) { + this.txtMobileNumber.setText(number); + } + + String emblemFile = this.configurationContainer.getEmblem(); + if (emblemFile != null && !emblemFile.trim().equals("")) { //$NON-NLS-1$ + // this.txtEmblemFile.setText(emblemFile); + this.emblemFile = emblemFile; + try { + this.setEmblemFileInternal(emblemFile, true); + this.btnUseImage.setSelection(true); + } catch (Exception e1) { + // TODO Auto-generated catch block + log.error("Failed to load emblem: ", e1); //$NON-NLS-1$ + } + } + + 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); + } + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#validateSettings + * () + */ + @Override + public void validateSettings() throws Exception { + this.plainMobileNumberSetter(); + this.plainEmblemSetter(this.emblemFile); + this.plainProxyHostSetter(); + this.plainProxyPortSetter(); } } |