From e710a326314184f31cd50d4637959f44232a74ee Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 18:52:37 +0000 Subject: State Machine stuff git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@20 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../at/asit/pdfover/gui/workflow/Workflow.java | 263 +++++++++++++++++---- 1 file changed, 223 insertions(+), 40 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Workflow.java') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Workflow.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Workflow.java index 83fca283..48e57f50 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Workflow.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Workflow.java @@ -18,19 +18,24 @@ package at.asit.pdfover.gui.workflow; //Imports import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import java.io.File; import java.util.Properties; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import at.asit.pdfover.gui.components.MainWindow; +import at.asit.pdfover.gui.workflow.states.BKUSelectionState; +import at.asit.pdfover.gui.workflow.states.DataSourceSelectionState; +import at.asit.pdfover.gui.workflow.states.PositioningState; import at.asit.pdfover.gui.workflow.states.PrepareConfigurationState; +import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUS; +import at.asit.pdfover.signator.Signator; +import at.asit.pdfover.signator.SignatureParameter; +import at.asit.pdfover.signator.Signer; /** * Workflow holds logical state of signing process and updates the current @@ -41,7 +46,6 @@ public class Workflow { /** * SFL4J Logger instance **/ - @SuppressWarnings("unused") private static final Logger log = LoggerFactory.getLogger(Workflow.class); /** @@ -70,35 +74,45 @@ public class Workflow { return this.state; } - private String[] cmdLineArgs = new String[] {}; - - /** - * sets the command line arguments - * - * @param cmdLineArgs - */ - private void setCmdLineAargs(String[] cmdLineArgs) { - this.cmdLineArgs = cmdLineArgs; - } - /** - * Gets the command line arguments + * Sets the workflow state This method should be used to let the user jump + * around between states. This Method also resets certain properties defined + * by later states then state * - * @return the command line arguments + * @param state */ - public String[] cetCmdArgs() { - return this.cmdLineArgs; - } + public void setWorkflowState(WorkflowState state) { + if (this.state != state && state != null) { + this.state = state; - private Properties persistentState = new Properties(); + if (state instanceof PositioningState) { + // User jumps to positioning state ! + // restore possible default for bku selection / forget BKU + // selection + this.setSelectedBKU(PrepareConfigurationState + .readSelectedBKU(this.getConfigurationValues())); + // forget position + this.getParameter().setSignaturePosition(null); + } else if (state instanceof BKUSelectionState) { + // User jumps to bku selection state ! + // forget bku selection + this.setSelectedBKU(BKUS.NONE); + } else if (state instanceof DataSourceSelectionState) { + // User jumps to data source selection state ! + // forget bku selection / restore possible default for bku + // selection + this.setSelectedBKU(PrepareConfigurationState + .readSelectedBKU(this.getConfigurationValues())); + // forget position / restore possible default for position + this.getParameter().setSignaturePosition( + PrepareConfigurationState.readDefinedPosition(this + .getConfigurationValues())); + // forget data source selection + this.setDataSource(null); + } - /** - * Gets the persistent state - * - * @return the persistent state - */ - public Properties getPersistentState() { - return this.persistentState; + this.update(); + } } /** @@ -108,11 +122,18 @@ public class Workflow { WorkflowState next = null; while (this.state != null) { this.state.update(this); + if (this.mainWindow != null && !this.mainWindow.getShell().isDisposed()) { + log.debug("Allowing MainWindow to update its state for " + this.state.toString()); + this.mainWindow.UpdateNewState(); + this.mainWindow.doLayout(); + } next = this.state.nextState(); if (next == this.state) { break; } - //this.state.hideGUI(); + // this.state.hideGUI(); + log.debug("Changing state from: " + this.state.toString() + " to " + + next.toString()); this.state = next; } if (this.state != null) { @@ -122,6 +143,21 @@ public class Workflow { } } + /** + * Invoke Update in UI (Main) Thread + */ + public void InvokeUpdate() { + if(this.display != null) { + this.display.asyncExec(new Runnable() { + + @Override + public void run() { + Workflow.this.update(); + } + }); + } + } + private Display display = null; private Shell shell = null; @@ -129,21 +165,21 @@ public class Workflow { private Composite container = null; private MainWindow mainWindow = null; - - private final StackLayout stack = new StackLayout(); /** * Helper method for developing + * * @param value */ public void setCurrentStateMessage(String value) { - if(this.mainWindow != null) { + if (this.mainWindow != null) { this.mainWindow.setStatus(value); } } - + /** * Used by active workflow state to show its own gui component + * * @param ctrl */ public void setTopControl(final Control ctrl) { @@ -152,15 +188,15 @@ public class Workflow { private void createMainWindow() { this.display = Display.getDefault(); - - this.mainWindow = new MainWindow(); - + + this.mainWindow = new MainWindow(this); + this.mainWindow.open(); - + this.shell = this.mainWindow.getShell(); - + this.container = this.mainWindow.getContainer(); - + this.shell.open(); this.shell.layout(); } @@ -194,6 +230,13 @@ public class Workflow { return this.shell; } + /** + * Exists the Workflow + */ + public void exitWorkflow() { + this.shell.dispose(); + } + /** * Only returns a shell if one was already created ... * @@ -224,4 +267,144 @@ public class Workflow { } } + // Data Section + // ============================================================================= + + // Command Line Arguments + // ------------------------------------------------------- + private String[] cmdLineArgs = new String[] {}; + + /** + * sets the command line arguments + * + * @param cmdLineArgs + */ + private void setCmdLineAargs(String[] cmdLineArgs) { + this.cmdLineArgs = cmdLineArgs; + } + + /** + * Gets the command line arguments + * + * @return the command line arguments + */ + public String[] getCmdArgs() { + return this.cmdLineArgs; + } + + // Key Value String properties + // ------------------------------------------------------- + private Properties configurationValues = new Properties(); + + /** + * Gets the persistent state + * + * @return the persistent state + */ + public Properties getConfigurationValues() { + return this.configurationValues; + } + + // Data source + // ------------------------------------------------------- + private File dataSource = null; + + /** + * Gets the DataSource + * + * @return The data source file + */ + public File getDataSource() { + return this.dataSource; + } + + /** + * Sets the DataSource + * + * @param file + */ + public void setDataSource(File file) { + this.dataSource = file; + } + + // Selected BKU + // ------------------------------------------------------- + + /** + * The selected BKU + */ + private BKUS selectedBKU = BKUS.NONE; + + /** + * Gets the selected BKU + * + * @return the selectedBKU + */ + public BKUS getSelectedBKU() { + return this.selectedBKU; + } + + /** + * Sets the selected BKU + * + * @param selectedBKU + * the selectedBKU to set + */ + public void setSelectedBKU(BKUS selectedBKU) { + this.selectedBKU = selectedBKU; + } + + private Signator.Signers usedSignerLib = Signator.Signers.PDFAS; + + /** + * The PDF Signer + */ + private Signer pdfSigner = null; + + /** + * @return the pdfSigner + */ + public Signer getPdfSigner() { + return this.pdfSigner; + } + + /** + * @param pdfSigner + * the pdfSigner to set + */ + public void setPdfSigner(Signer pdfSigner) { + this.pdfSigner = pdfSigner; + } + + private SignatureParameter parameter = null; + + /** + * @return the parameter + */ + public SignatureParameter getParameter() { + return this.parameter; + } + + /** + * @param parameter + * the parameter to set + */ + public void setParameter(SignatureParameter parameter) { + this.parameter = parameter; + } + + /** + * @return the usedSignerLib + */ + public Signator.Signers getUsedSignerLib() { + return usedSignerLib; + } + + /** + * @param usedSignerLib + * the usedSignerLib to set + */ + public void setUsedSignerLib(Signator.Signers usedSignerLib) { + this.usedSignerLib = usedSignerLib; + } } -- cgit v1.2.3