diff options
author | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:53:11 +0000 |
---|---|---|
committer | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:53:11 +0000 |
commit | b2968bef5d56723826cfe38f1fe5ab1d60aa79f3 (patch) | |
tree | 8bf68cf3b7c8a6d80d3338046110a6decd60fce2 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow | |
parent | 2e533b04ae8b232a50a83101692e20cda53696fb (diff) | |
download | pdf-over-b2968bef5d56723826cfe38f1fe5ab1d60aa79f3.tar.gz pdf-over-b2968bef5d56723826cfe38f1fe5ab1d60aa79f3.tar.bz2 pdf-over-b2968bef5d56723826cfe38f1fe5ab1d60aa79f3.zip |
State Machine refactoring
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@23 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow')
19 files changed, 779 insertions, 345 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java index 1296b373..30d7aed8 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java @@ -15,13 +15,24 @@ */ package at.asit.pdfover.gui.workflow; -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs; +import at.asit.pdfover.signator.SignaturePosition; /** * */ public interface ConfigProvider { - + //TODO: define interface for config provider .... + + /** + * Get the default configured BKU + * @return the default configured BKU + */ + public BKUs getDefaultBKU(); + + /** + * Get the default configured SignaturePosition + * @return the default configured SignaturePosition or null if not configured + */ + public SignaturePosition getDefaultSignaturePosition(); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java new file mode 100644 index 00000000..3787ef50 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java @@ -0,0 +1,54 @@ +/* + * 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.workflow; + +// Imports +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs; +import at.asit.pdfover.signator.SignaturePosition; + +/** + * + */ +public class ConfigProviderImpl implements ConfigProvider { + /** + * SLF4J Logger instance + **/ + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory + .getLogger(ConfigProviderImpl.class); + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultBKU() + */ + @Override + public BKUs getDefaultBKU() { + // TODO Read Config + return BKUs.NONE; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultSignaturePosition() + */ + @Override + public SignaturePosition getDefaultSignaturePosition() { + // TODO Read Config + return null; + } + +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/GUIProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/GUIProvider.java new file mode 100644 index 00000000..4e7955fd --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/GUIProvider.java @@ -0,0 +1,44 @@ +/* + * 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.workflow; + +import org.eclipse.swt.widgets.Composite; + + +/** + * + */ +public interface GUIProvider { + /** + * Get the container Composite + * @return the container Composite + */ + public Composite getComposite(); + + /** + * Create a new Composite + * @param compositeClass The class of the Composite to create + * @param style the SWT style + * @return the new Composite + */ + public <T> T createComposite(Class<T> compositeClass, int style); + + /** + * Display the composite as top most in main window + * @param composite the composite + */ + public void display(final Composite composite); +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSigner.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSigner.java new file mode 100644 index 00000000..33e8c176 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSigner.java @@ -0,0 +1,43 @@ +/* + * 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.workflow; + +// Imports +import at.asit.pdfover.signator.Signator; +import at.asit.pdfover.signator.Signer; + +/** + * + */ +public interface PDFSigner { + /** + * Gets the PDF Signer Type + * @return the signer type + */ + public Signator.Signers getUsedPDFSignerLibrary(); + + /** + * Set PDF Signer Type + * @param signer the signer type + */ + public void setUsedPDFSignerLibrary(Signator.Signers signer); + + /** + * Gets the currently used PDF Signer + * @return the pdf signer + */ + public Signer getPDFSigner(); +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSignerImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSignerImpl.java new file mode 100644 index 00000000..812e6ba0 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSignerImpl.java @@ -0,0 +1,72 @@ +/* + * 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.workflow; + +// Imports +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.signator.Signator; +import at.asit.pdfover.signator.Signator.Signers; +import at.asit.pdfover.signator.Signer; + +/** + * + */ +public class PDFSignerImpl implements PDFSigner { + /** + * SLF4J Logger instance + **/ + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory + .getLogger(PDFSignerImpl.class); + + private Signers signer = Signator.Signers.PDFAS; + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.PDFSigner#getPDFSignerType() + */ + @Override + public Signers getUsedPDFSignerLibrary() { + return this.signer; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.PDFSigner#setPDFSignerType(at.asit.pdfover.signator.Signator.Signers) + */ + @Override + public void setUsedPDFSignerLibrary(Signers signer) { + if(signer != this.signer) { + // TYPE CHANGE remove cached signer! + this.signerLib = null; + } + this.signer = signer; + } + + private Signer signerLib; + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.PDFSigner#getPDFSigner() + */ + @Override + public Signer getPDFSigner() { + if(this.signerLib == null) { + this.signerLib = Signator.getSigner(getUsedPDFSignerLibrary()); + } + return this.signerLib; + } + +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java index 92505d19..1298bda8 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java @@ -15,7 +15,7 @@ */ package at.asit.pdfover.gui.workflow; -import org.eclipse.swt.widgets.Composite; +import at.asit.pdfover.gui.workflow.states.State; /** * @@ -28,30 +28,48 @@ public interface StateMachine { public ConfigProvider getConfigProvider(); /** - * Get the container Composite - * @return the container Composite + * Get the PDF Signer + * @return the PDF Signer */ - public Composite getComposite(); - - /** - * Create a new Composite - * @param compositeClass The class of the Composite to create - * @return the new Composite - */ - public <T> T createComposite(Class<T> compositeClass); - - //public void display(Composite composite) + public PDFSigner getPDFSigner(); + /** * Get the Status * @return the Status */ public Status getStatus(); + + /** + * Gets the GUI provider + * @return the GUI provider + */ + public GUIProvider getGUIProvider(); + + /** + * Jump to specific state + * + * Sets the state machine 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 the target state. + * + * Example: Usually the MainWindow allows the user to jump to the states: + * DataSourceSelectionState, PositioningState and BKUSelectionState + * + * @param state the state to jump to + */ + public void jumpToState(State state); /** * Update state machine * Calls the next state. */ public void update(); + + /** + * Update state machine from other thread + * Calls the next state within the main thread + */ + public void InvokeUpdate(); /** * Exit state machine execution diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java index 8549007c..bb292c74 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java @@ -19,38 +19,36 @@ package at.asit.pdfover.gui.workflow; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.Properties; - -import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; -import at.asit.pdfover.gui.components.BKUSelectionComposite; -import at.asit.pdfover.gui.components.MainWindow; +import at.asit.pdfover.gui.MainWindow; import at.asit.pdfover.gui.workflow.states.BKUSelectionState; -import at.asit.pdfover.gui.workflow.states.DataSourceSelectionState; +import at.asit.pdfover.gui.workflow.states.OpenState; import at.asit.pdfover.gui.workflow.states.PositioningState; import at.asit.pdfover.gui.workflow.states.PrepareConfigurationState; +import at.asit.pdfover.gui.workflow.states.State; 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 * logical state */ -public class StateMachineImpl implements StateMachine { +public class StateMachineImpl implements StateMachine, GUIProvider { /** * SFL4J Logger instance **/ - private static final Logger log = LoggerFactory.getLogger(StateMachineImpl.class); + private static final Logger log = LoggerFactory + .getLogger(StateMachineImpl.class); + + private StatusImpl status; + + private PDFSignerImpl pdfSigner; + + private ConfigProviderImpl configProvider; /** * Default constructor @@ -58,61 +56,49 @@ public class StateMachineImpl implements StateMachine { * @param cmdLineArgs */ public StateMachineImpl(String[] cmdLineArgs) { + this.status = new StatusImpl(); + this.status.setCurrentState(new PrepareConfigurationState(this)); + this.pdfSigner = new PDFSignerImpl(); + this.configProvider = new ConfigProviderImpl(); setCmdLineAargs(cmdLineArgs); } /** - * @uml.property name="state" - * @uml.associationEnd multiplicity="(1 1)" aggregation="shared" - * inverse="workflow1:at.asit.pdfover.gui.workflow.WorkflowState" - */ - private State state = new PrepareConfigurationState(); - - /** - * Getter of the property <tt>state</tt> - * - * @return Returns the state. - * @uml.property name="state" - */ - public State getState() { - return this.state; - } - - /** - * Sets the workflow state This method should be used to let the user jump + * 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 * * @param state */ - public void setState(State state) { - if (this.state != state && state != null) { - this.state = state; + @Override + public void jumpToState(State state) { + if (this.status.getCurrentState() != state && state != null) { + this.status.setCurrentState(state); + // TODO rewrite when Config is done ... if (state instanceof PositioningState) { // User jumps to positioning state ! // restore possible default for bku selection / forget BKU // selection - this.setSelectedBKU(PrepareConfigurationState - .readSelectedBKU(this.getConfigurationValues())); + this.getStatus().setBKU( + this.getConfigProvider().getDefaultBKU()); // forget position - this.getParameter().setSignaturePosition(null); + this.getStatus().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) { + this.getStatus().setBKU(BKUs.NONE); + } else if (state instanceof OpenState) { // User jumps to data source selection state ! // forget bku selection / restore possible default for bku // selection - this.setSelectedBKU(PrepareConfigurationState - .readSelectedBKU(this.getConfigurationValues())); + this.getStatus().setBKU( + this.getConfigProvider().getDefaultBKU()); // forget position / restore possible default for position - this.getParameter().setSignaturePosition( - PrepareConfigurationState.readDefinedPosition(this - .getConfigurationValues())); + this.getStatus().setSignaturePosition( + this.getConfigProvider().getDefaultSignaturePosition()); // forget data source selection - this.setDataSource(null); + this.getStatus().setDocument(null); } this.update(); @@ -125,24 +111,29 @@ public class StateMachineImpl implements StateMachine { @Override public void update() { State next = null; - while (this.state != null) { - this.state.run(); - if (this.mainWindow != null && !this.mainWindow.getShell().isDisposed()) { - log.debug("Allowing MainWindow to update its state for " + this.state.toString()); - this.mainWindow.UpdateNewState(); + while (this.status.getCurrentState() != null) { + State current = this.status.getCurrentState(); + current.run(); + if (this.mainWindow != null + && !this.mainWindow.getShell().isDisposed()) { + log.debug("Allowing MainWindow to update its state for " + + current); + current.updateMainWindowBehavior(); + this.mainWindow.applyBehavior(); this.mainWindow.doLayout(); } - next = this.state.nextState(); - if (next == this.state) { + next = current.nextState(); + if (next == current) { break; } - // this.state.hideGUI(); - log.debug("Changing state from: " + this.state.toString() + " to " + log.debug("Changing state from: " + + current + " to " + next.toString()); - this.state = next; + this.status.setCurrentState(next); } - if (this.state != null) { - this.setCurrentStateMessage(this.state.toString()); + if (this.status.getCurrentState() != null) { + this.setCurrentStateMessage(this.status.getCurrentState() + .toString()); } else { this.setCurrentStateMessage(""); } @@ -151,10 +142,11 @@ public class StateMachineImpl implements StateMachine { /** * Invoke Update in UI (Main) Thread */ + @Override public void InvokeUpdate() { - if(this.display != null) { + if (this.display != null) { this.display.asyncExec(new Runnable() { - + @Override public void run() { StateMachineImpl.this.update(); @@ -162,7 +154,7 @@ public class StateMachineImpl implements StateMachine { }); } } - + private Display display = null; private Shell shell = null; @@ -182,13 +174,16 @@ public class StateMachineImpl implements StateMachine { } } - /** - * Used by active workflow state to show its own gui component + /* + * (non-Javadoc) * - * @param ctrl + * @see + * at.asit.pdfover.gui.workflow.StateMachine#display(org.eclipse.swt.widgets + * .Composite) */ - public void setTopControl(final Control ctrl) { - this.mainWindow.setTopControl(ctrl); + @Override + public void display(Composite composite) { + this.mainWindow.setTopControl(composite); } private void createMainWindow() { @@ -228,13 +223,16 @@ public class StateMachineImpl implements StateMachine { } @Override - public <T> T createComposite(Class<T> compositeClass) { + public <T> T createComposite(Class<T> compositeClass, int style) { T composite = null; try { - Constructor<T> constructor = compositeClass.getDeclaredConstructor(Composite.class, int.class, BKUSelectionState.class); - composite = constructor.newInstance(getComposite(), SWT.RESIZE, this); + Constructor<T> constructor = compositeClass.getDeclaredConstructor( + Composite.class, int.class, BKUSelectionState.class); + composite = constructor.newInstance(getComposite(), style, this); } catch (Exception e) { - log.error("Could not create Composite for Class " + compositeClass.getName(), e); + log.error( + "Could not create Composite for Class " + + compositeClass.getName(), e); } return composite; } @@ -286,22 +284,42 @@ public class StateMachineImpl implements StateMachine { } } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.workflow.StateMachine#getConfigProvider() */ @Override public ConfigProvider getConfigProvider() { - // TODO Auto-generated method stub - return null; + return this.configProvider; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.workflow.StateMachine#getStatus() */ @Override public Status getStatus() { - // TODO Auto-generated method stub - return null; + return this.status; + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.workflow.StateMachine#getPDFSigner() + */ + @Override + public PDFSigner getPDFSigner() { + return this.pdfSigner; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.StateMachine#getGUIProvider() + */ + @Override + public GUIProvider getGUIProvider() { + return this; } // Data Section @@ -328,120 +346,4 @@ public class StateMachineImpl implements StateMachine { 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 this.usedSignerLib; - } - - /** - * @param usedSignerLib - * the usedSignerLib to set - */ - public void setUsedSignerLib(Signator.Signers usedSignerLib) { - this.usedSignerLib = usedSignerLib; - } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java index ff06286b..9af0b034 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java @@ -17,19 +17,60 @@ package at.asit.pdfover.gui.workflow; import java.io.File; +import at.asit.pdfover.gui.MainWindowBehavior; import at.asit.pdfover.gui.workflow.states.BKUSelectionState; +import at.asit.pdfover.gui.workflow.states.State; import at.asit.pdfover.signator.SignaturePosition; /** - * + * Interface for persistent status of state machine */ public interface Status { + /** + * Sets the document + * @param document the document + */ public void setDocument(File document); + + /** + * Gets the document + * @return the document + */ public File getDocument(); + /** + * Sets the signature position + * @param position the position + */ public void setSignaturePosition(SignaturePosition position); + + /** + * Gets the signature position + * @return the signature position + */ public SignaturePosition getSignaturePosition(); + /** + * Sets the selected BKU + * @param bku the selected BKU + */ public void setBKU(BKUSelectionState.BKUs bku); + + /** + * Gets the selected BKU + * @return the selected BKU + */ public BKUSelectionState.BKUs getBKU(); + + /** + * Gets the current state + * @return the current state + */ + public State getCurrentState(); + + /** + * Gets the main window behavior + * @return the main window behavior + */ + public MainWindowBehavior getBehavior(); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java new file mode 100644 index 00000000..9bc4bfec --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java @@ -0,0 +1,124 @@ +/* + * 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.workflow; + +// Imports +import java.io.File; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.workflow.states.State; +import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs; +import at.asit.pdfover.signator.SignaturePosition; + +/** + * + */ +public class StatusImpl implements Status { + /** + * SLF4J Logger instance + **/ + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(StatusImpl.class); + + private File document = null; + + private SignaturePosition signaturePosition = null; + + private BKUs bku = BKUs.NONE; + + private State currentState = null; + + private MainWindowBehavior behavior; + + /** + * Constructor + */ + public StatusImpl() { + this.behavior = new MainWindowBehavior(); + } + + @Override + public State getCurrentState() { + return this.currentState; + } + + /** + * Sets the current state + * @param currentState + */ + public void setCurrentState(State currentState) { + this.currentState = currentState; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.Status#setDocument(java.io.File) + */ + @Override + public void setDocument(File document) { + this.document = document; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.Status#getDocument() + */ + @Override + public File getDocument() { + return this.document; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.Status#setSignaturePosition(at.asit.pdfover.signator.SignaturePosition) + */ + @Override + public void setSignaturePosition(SignaturePosition position) { + this.signaturePosition = position; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.Status#getSignaturePosition() + */ + @Override + public SignaturePosition getSignaturePosition() { + return this.signaturePosition; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.Status#setBKU(at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs) + */ + @Override + public void setBKU(BKUs bku) { + this.bku = bku; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.Status#getBKU() + */ + @Override + public BKUs getBKU() { + return this.bku; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.Status#getBehavior() + */ + @Override + public MainWindowBehavior getBehavior() { + return behavior; + } +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java index 1d2c5524..86bd50c9 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java @@ -20,10 +20,10 @@ import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.asit.pdfover.gui.components.BKUSelectionComposite; +import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.MainWindow.Buttons; +import at.asit.pdfover.gui.composites.BKUSelectionComposite; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.StateMachineImpl; -import at.asit.pdfover.gui.workflow.State; /** * Decides which BKU to use (preconfigured or let user choose) @@ -67,8 +67,8 @@ public class BKUSelectionState extends State { private BKUSelectionComposite getSelectionComposite() { if (this.selectionComposite == null) { - this.selectionComposite = new BKUSelectionComposite( - this.stateMachine.getComposite(), SWT.RESIZE, this); + this.selectionComposite = new BKUSelectionComposite( + this.stateMachine.getGUIProvider().getComposite(), SWT.RESIZE, this); } return this.selectionComposite; @@ -81,21 +81,35 @@ public class BKUSelectionState extends State { BKUSelectionComposite selection = this .getSelectionComposite(); - this.stateMachine.setTopControl(selection); + this.stateMachine.getGUIProvider().display(selection); selection.layout(); - this.stateMachine.setSelectedBKU(selection.getSelected()); + this.stateMachine.getStatus().setBKU(selection.getSelected()); - if(this.stateMachine.getSelectedBKU() == BKUs.NONE) { - this.setNextState(this); + if(this.stateMachine.getStatus().getBKU() == BKUs.NONE) { return; } } - this.setNextState(new PrepareSigningState()); + this.setNextState(new PrepareSigningState(this.stateMachine)); } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior() + */ + @Override + public void updateMainWindowBehavior() { + MainWindowBehavior behavior = this.stateMachine.getStatus().getBehavior(); + behavior.reset(); + behavior.setEnabled(Buttons.CONFIG, true); + behavior.setEnabled(Buttons.OPEN, true); + behavior.setEnabled(Buttons.POSITION, true); + behavior.setActive(Buttons.OPEN, true); + behavior.setActive(Buttons.POSITION, true); + behavior.setActive(Buttons.SIGN, true); + } + @Override public String toString() { - return "BKUSelectionState"; + return this.getClass().getName(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java index 2a53dcbc..2d3a31ec 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java @@ -19,16 +19,25 @@ package at.asit.pdfover.gui.workflow.states; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.MainWindow.Buttons; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.State; /** * Logical state for performing the BKU Request to a local BKU */ public class LocalBKUState extends State { /** + * @param stateMachine + */ + public LocalBKUState(StateMachine stateMachine) { + super(stateMachine); + } + + /** * SLF4J Logger instance **/ + @SuppressWarnings("unused") private static final Logger log = LoggerFactory .getLogger(LocalBKUState.class); @@ -36,14 +45,26 @@ public class LocalBKUState extends State { * @see at.asit.pdfover.gui.workflow.WorkflowState#update(at.asit.pdfover.gui.workflow.Workflow) */ @Override - public void run(StateMachine stateMachine) { + public void run() { // TODO Process SL Request and set SL Response - this.setNextState(new SigningState()); + this.setNextState(new SigningState(this.stateMachine)); } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior() + */ + @Override + public void updateMainWindowBehavior() { + MainWindowBehavior behavior = this.stateMachine.getStatus().getBehavior(); + behavior.reset(); + behavior.setActive(Buttons.OPEN, true); + behavior.setActive(Buttons.POSITION, true); + behavior.setActive(Buttons.SIGN, true); + } + @Override public String toString() { - return "LocalBKUState"; + return this.getClass().getName(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java index 169e9e59..c160a524 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java @@ -19,16 +19,25 @@ package at.asit.pdfover.gui.workflow.states; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.MainWindow.Buttons; +import at.asit.pdfover.gui.MainWindowBehavior; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.State; /** * Logical state for performing the BKU Request to the A-Trust Mobile BKU */ public class MobileBKUState extends State { /** + * @param stateMachine + */ + public MobileBKUState(StateMachine stateMachine) { + super(stateMachine); + } + + /** * SLF4J Logger instance **/ + @SuppressWarnings("unused") private static final Logger log = LoggerFactory .getLogger(MobileBKUState.class); @@ -36,15 +45,26 @@ public class MobileBKUState extends State { * @see at.asit.pdfover.gui.workflow.WorkflowState#update(at.asit.pdfover.gui.workflow.Workflow) */ @Override - public void run(StateMachine stateMachine) { + public void run() { // TODO Process SL Request and set SL Response - - this.setNextState(new SigningState()); + this.setNextState(new SigningState(this.stateMachine)); + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior() + */ + @Override + public void updateMainWindowBehavior() { + MainWindowBehavior behavior = this.stateMachine.getStatus().getBehavior(); + behavior.reset(); + behavior.setActive(Buttons.OPEN, true); + behavior.setActive(Buttons.POSITION, true); + behavior.setActive(Buttons.SIGN, true); } @Override public String toString() { - return "MobileBKUState"; + return this.getClass().getName(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/DataSourceSelectionState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java index 6b69947a..ee90a69b 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/DataSourceSelectionState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java @@ -16,66 +16,78 @@ package at.asit.pdfover.gui.workflow.states; //Imports -import java.io.File; - import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.asit.pdfover.gui.components.DataSourceSelectComposite; +import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.MainWindow.Buttons; +import at.asit.pdfover.gui.composites.DataSourceSelectComposite; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.StateMachineImpl; -import at.asit.pdfover.gui.workflow.State; /** * Selects the data source for the signature process. */ -public class DataSourceSelectionState extends State { +public class OpenState extends State { + + /** + * @param stateMachine + */ + public OpenState(StateMachine stateMachine) { + super(stateMachine); + } /** * SFL4J Logger instance **/ private static final Logger log = LoggerFactory - .getLogger(DataSourceSelectionState.class); + .getLogger(OpenState.class); private DataSourceSelectComposite selectionComposite = null; - private DataSourceSelectComposite getSelectionComposite(StateMachineImpl workflow) { + private DataSourceSelectComposite getSelectionComposite() { if (this.selectionComposite == null) { this.selectionComposite = new DataSourceSelectComposite( - workflow.getComposite(), SWT.RESIZE, workflow); + this.stateMachine.getGUIProvider().getComposite(), SWT.RESIZE, this); } return this.selectionComposite; } @Override - public void run(StateMachine stateMachine) { + public void run() { - if (workflow.getDataSource() == null) { + if (this.stateMachine.getStatus().getDocument() == null) { DataSourceSelectComposite selection = this - .getSelectionComposite(workflow); + .getSelectionComposite(); - workflow.setTopControl(selection); + this.stateMachine.getGUIProvider().display(selection); selection.layout(); - File source = selection.getSelected(); - if(source != null) { - workflow.setDataSource(source); - } + this.stateMachine.getStatus().setDocument(selection.getSelected()); - if (workflow.getDataSource() == null) { + if (this.stateMachine.getStatus().getDocument() == null) { // Not selected yet - this.setNextState(this); return; } } - log.debug("Got Datasource: " + workflow.getDataSource().getAbsolutePath()); - this.setNextState(new PositioningState()); + log.debug("Got Datasource: " + this.stateMachine.getStatus().getDocument().getAbsolutePath()); + this.setNextState(new PositioningState(this.stateMachine)); } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior() + */ + @Override + public void updateMainWindowBehavior() { + MainWindowBehavior behavior = this.stateMachine.getStatus().getBehavior(); + behavior.reset(); + behavior.setEnabled(Buttons.CONFIG, true); + behavior.setActive(Buttons.OPEN, true); + } + @Override public String toString() { - return "DataSourceSelectionState"; + return this.getClass().getName(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java index 933dd559..8a04dd3f 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java @@ -19,8 +19,9 @@ package at.asit.pdfover.gui.workflow.states; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.MainWindow.Buttons; +import at.asit.pdfover.gui.MainWindowBehavior; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.State; /** * Procduces the output of the signature process. (save file, open file) @@ -28,21 +29,44 @@ import at.asit.pdfover.gui.workflow.State; public class OutputState extends State { /** + * @param stateMachine + */ + public OutputState(StateMachine stateMachine) { + super(stateMachine); + } + + /** * SFL4J Logger instance **/ @SuppressWarnings("unused") private static final Logger log = LoggerFactory.getLogger(OutputState.class); @Override - public void run(StateMachine stateMachine) { + public void run() { // TODO Preform output operations ... end workflow - stateMachine.exit(); + this.stateMachine.exit(); } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior() + */ @Override - public String toString() { - return "OutputState"; + public void updateMainWindowBehavior() { + MainWindowBehavior behavior = this.stateMachine.getStatus().getBehavior(); + behavior.reset(); + behavior.setEnabled(Buttons.CONFIG, true); + behavior.setEnabled(Buttons.OPEN, true); + behavior.setEnabled(Buttons.POSITION, true); + behavior.setEnabled(Buttons.SIGN, true); + behavior.setActive(Buttons.OPEN, true); + behavior.setActive(Buttons.POSITION, true); + behavior.setActive(Buttons.SIGN, true); + behavior.setActive(Buttons.FINAL, true); } + @Override + public String toString() { + return this.getClass().getName(); + } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java index 5b764084..c7c92a89 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java @@ -20,10 +20,10 @@ import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.asit.pdfover.gui.components.PositioningComposite; +import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.MainWindow.Buttons; +import at.asit.pdfover.gui.composites.PositioningComposite; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.StateMachineImpl; -import at.asit.pdfover.gui.workflow.State; /** * Decides where to position the signature block @@ -31,6 +31,13 @@ import at.asit.pdfover.gui.workflow.State; public class PositioningState extends State { /** + * @param stateMachine + */ + public PositioningState(StateMachine stateMachine) { + super(stateMachine); + } + + /** * SFL4J Logger instance **/ @SuppressWarnings("unused") @@ -39,35 +46,47 @@ public class PositioningState extends State { private PositioningComposite positionComposite = null; - private PositioningComposite getPositioningComosite(StateMachineImpl workflow) { + private PositioningComposite getPositioningComosite() { if (this.positionComposite == null) { this.positionComposite = new PositioningComposite( - workflow.getComposite(), SWT.NONE, workflow); + this.stateMachine.getGUIProvider().getComposite(), SWT.NONE, this); } return this.positionComposite; } @Override - public void run(StateMachine stateMachine) { + public void run() { - if(workflow.getParameter().getSignaturePosition() == null) { - PositioningComposite position = this.getPositioningComosite(workflow); + if(this.stateMachine.getStatus().getSignaturePosition() == null) { + PositioningComposite position = this.getPositioningComosite(); - workflow.setTopControl(position); + this.stateMachine.getGUIProvider().display(position); - workflow.getParameter().setSignaturePosition(position.getPosition()); + this.stateMachine.getStatus().setSignaturePosition(position.getPosition()); - if(workflow.getParameter().getSignaturePosition() == null) { - this.setNextState(this); + if(this.stateMachine.getStatus().getSignaturePosition() == null) { return; } } - this.setNextState(new BKUSelectionState()); + this.setNextState(new BKUSelectionState(this.stateMachine)); + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior() + */ + @Override + public void updateMainWindowBehavior() { + MainWindowBehavior behavior = this.stateMachine.getStatus().getBehavior(); + behavior.reset(); + behavior.setEnabled(Buttons.CONFIG, true); + behavior.setEnabled(Buttons.OPEN, true); + behavior.setActive(Buttons.OPEN, true); + behavior.setActive(Buttons.POSITION, true); } @Override public String toString() { - return "PositioningState"; + return this.getClass().getName(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java index 45e04dfd..4fa9e362 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java @@ -16,16 +16,12 @@ package at.asit.pdfover.gui.workflow.states; //Imports -import java.util.Properties; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.State; -import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs; import at.asit.pdfover.signator.Signator; -import at.asit.pdfover.signator.SignaturePosition; + /** * Starting state of workflow proccess @@ -34,7 +30,12 @@ import at.asit.pdfover.signator.SignaturePosition; */ public class PrepareConfigurationState extends State { - public final static String BKU_SELECTION_CONFIG = "DEFAULT_BKU"; + /** + * @param stateMachine + */ + public PrepareConfigurationState(StateMachine stateMachine) { + super(stateMachine); + } /** * SFL4J Logger instance @@ -44,55 +45,29 @@ public class PrepareConfigurationState extends State { .getLogger(PrepareConfigurationState.class); @Override - public void run(StateMachine stateMachine) { + public void run() { // TODO: Read config file and command line arguments // Set usedSignerLib ... - + this.stateMachine.getPDFSigner().setUsedPDFSignerLibrary(Signator.Signers.PDFAS); + // Create PDF Signer - workflow.setPdfSigner(Signator.getSigner(workflow.getUsedSignerLib())); - - workflow.setParameter(workflow.getPdfSigner().newParameter()); - - workflow.setSelectedBKU(PrepareConfigurationState.readSelectedBKU(workflow.getConfigurationValues())); + this.stateMachine.getStatus().setBKU(this.stateMachine.getConfigProvider().getDefaultBKU()); - workflow.getParameter().setSignaturePosition(readDefinedPosition(workflow.getConfigurationValues())); + this.stateMachine.getStatus().setSignaturePosition(this.stateMachine.getConfigProvider().getDefaultSignaturePosition()); - this.setNextState(new DataSourceSelectionState()); + this.setNextState(new OpenState(this.stateMachine)); } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior() + */ @Override - public String toString() { - return "PrepareConfigurationState"; + public void updateMainWindowBehavior() { + //no behavior necessary yet } - /** - * Gets BKUS value from Properties - * @param props - * @return The BKUS value - */ - public static BKUs readSelectedBKU(final Properties props) { - if (props.containsKey(BKU_SELECTION_CONFIG)) { - String value = props.getProperty(BKU_SELECTION_CONFIG); - value = value.trim().toLowerCase(); - - if (value.equals(BKUs.LOCAL.toString().trim().toLowerCase())) { - - return BKUs.LOCAL; - } else if (value - .equals(BKUs.MOBILE.toString().trim().toLowerCase())) { - return BKUs.MOBILE; - } - } - return BKUs.NONE; - } - - /** - * Gets BKUS value from Properties - * @param props - * @return The BKUS value - */ - public static SignaturePosition readDefinedPosition(final Properties props) { - // TODO - return null; + @Override + public String toString() { + return this.getClass().getName(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java index efccc5de..061869c1 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java @@ -20,10 +20,10 @@ import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.asit.pdfover.gui.components.WaitingComposite; +import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.MainWindow.Buttons; +import at.asit.pdfover.gui.composites.WaitingComposite; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.StateMachineImpl; -import at.asit.pdfover.gui.workflow.State; import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs; /** @@ -32,17 +32,24 @@ import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs; public class PrepareSigningState extends State { /** + * @param stateMachine + */ + public PrepareSigningState(StateMachine stateMachine) { + super(stateMachine); + } + + /** * Debug background thread */ private final class DebugSleeperThread implements Runnable { - private StateMachineImpl workflow; + private StateMachine workflow; /** * Default constructor * @param work */ - public DebugSleeperThread(StateMachineImpl work) { + public DebugSleeperThread(final StateMachine work) { this.workflow = work; } @@ -65,10 +72,10 @@ public class PrepareSigningState extends State { private WaitingComposite selectionComposite = null; - private WaitingComposite getSelectionComposite(StateMachineImpl workflow) { + private WaitingComposite getSelectionComposite() { if (this.selectionComposite == null) { this.selectionComposite = new WaitingComposite( - workflow.getComposite(), SWT.RESIZE, workflow); + this.stateMachine.getGUIProvider().getComposite(), SWT.RESIZE, this); } return this.selectionComposite; @@ -77,14 +84,14 @@ public class PrepareSigningState extends State { private boolean run = false; @Override - public void run(StateMachine stateMachine) { + public void run() { // TODO SHOW BACKGROUND ACTIVITY .... - WaitingComposite waiting = this.getSelectionComposite(workflow); + WaitingComposite waiting = this.getSelectionComposite(); - workflow.setTopControl(waiting); + this.stateMachine.getGUIProvider().display(waiting); if(!this.run) { - Thread t = new Thread(new DebugSleeperThread(workflow)); + Thread t = new Thread(new DebugSleeperThread(this.stateMachine)); this.run = true; t.start(); return; @@ -92,20 +99,30 @@ public class PrepareSigningState extends State { // WAIT FOR SLREQUEST and dispatch according to BKU selection - if(workflow.getSelectedBKU() == BKUs.LOCAL) { - this.setNextState(new LocalBKUState()); - } else if(workflow.getSelectedBKU() == BKUs.MOBILE) { - this.setNextState(new MobileBKUState()); + if(this.stateMachine.getStatus().getBKU() == BKUs.LOCAL) { + this.setNextState(new LocalBKUState(this.stateMachine)); + } else if(this.stateMachine.getStatus().getBKU() == BKUs.MOBILE) { + this.setNextState(new MobileBKUState(this.stateMachine)); } else { - log.error("Invalid selected BKU Value \"NONE\" in PrepareSigningState!"); - this.setNextState(new BKUSelectionState()); + log.error("Invalid selected BKU Value \"NONE\" in PrepareSigningState!"); //$NON-NLS-1$ + this.setNextState(new BKUSelectionState(this.stateMachine)); } } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior() + */ + @Override + public void updateMainWindowBehavior() { + MainWindowBehavior behavior = this.stateMachine.getStatus().getBehavior(); + behavior.reset(); + behavior.setActive(Buttons.OPEN, true); + behavior.setActive(Buttons.POSITION, true); + behavior.setActive(Buttons.SIGN, true); + } + @Override public String toString() { - return "PrepareSigningState"; + return this.getClass().getName(); } - - } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java index 27dd7420..3447fc4c 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java @@ -20,7 +20,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.State; /** * Logical state for signing process, usually show BKU Dialog during this state. @@ -28,20 +27,35 @@ import at.asit.pdfover.gui.workflow.State; public class SigningState extends State { /** + * @param stateMachine + */ + public SigningState(StateMachine stateMachine) { + super(stateMachine); + } + + /** * SFL4J Logger instance **/ @SuppressWarnings("unused") private static final Logger log = LoggerFactory.getLogger(SigningState.class); @Override - public void run(StateMachine stateMachine) { + public void run() { // TODO Wait until output ready and set output - this.setNextState(new OutputState()); + this.setNextState(new OutputState(this.stateMachine)); } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior() + */ + @Override + public void updateMainWindowBehavior() { + //no change of behavior necessary + } + @Override public String toString() { - return "SigningState"; + return this.getClass().getName(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/State.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/State.java index 305c5033..8b9a3ebb 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/State.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/State.java @@ -13,12 +13,15 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.workflow; +package at.asit.pdfover.gui.workflow.states; //Imports import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.workflow.StateMachine; + /** * Base state class */ @@ -36,9 +39,10 @@ public abstract class State { private static final Logger log = LoggerFactory.getLogger(State.class); private State nextState = null; - + /** * Default Workflow State constructor + * @param stateMachine the State Machine */ public State(StateMachine stateMachine) { this.stateMachine = stateMachine; @@ -63,7 +67,6 @@ public abstract class State { /** * Perform main logic for this state - * @param stateMachine the state machine */ public abstract void run(); @@ -72,6 +75,12 @@ public abstract class State { */ public void updateStateMachine() { - stateMachine.update(); + this.stateMachine.update(); } + + /** + * Update the main window behavior of this state if necessary + * Should update this.stateMachine.getStatus().getBehavior() + */ + public abstract void updateMainWindowBehavior(); } |