From b2968bef5d56723826cfe38f1fe5ab1d60aa79f3 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 18:53:11 +0000 Subject: State Machine refactoring git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@23 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../gui/workflow/states/BKUSelectionState.java | 36 ++++++--- .../workflow/states/DataSourceSelectionState.java | 81 ------------------- .../pdfover/gui/workflow/states/LocalBKUState.java | 29 ++++++- .../gui/workflow/states/MobileBKUState.java | 30 +++++-- .../pdfover/gui/workflow/states/OpenState.java | 93 ++++++++++++++++++++++ .../pdfover/gui/workflow/states/OutputState.java | 34 ++++++-- .../gui/workflow/states/PositioningState.java | 47 +++++++---- .../workflow/states/PrepareConfigurationState.java | 67 +++++----------- .../gui/workflow/states/PrepareSigningState.java | 57 ++++++++----- .../pdfover/gui/workflow/states/SigningState.java | 22 ++++- .../at/asit/pdfover/gui/workflow/states/State.java | 86 ++++++++++++++++++++ 11 files changed, 392 insertions(+), 190 deletions(-) delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/DataSourceSelectionState.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/State.java (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states') 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/DataSourceSelectionState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/DataSourceSelectionState.java deleted file mode 100644 index 6b69947a..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/DataSourceSelectionState.java +++ /dev/null @@ -1,81 +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.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.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 { - - /** - * SFL4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(DataSourceSelectionState.class); - - private DataSourceSelectComposite selectionComposite = null; - - private DataSourceSelectComposite getSelectionComposite(StateMachineImpl workflow) { - if (this.selectionComposite == null) { - this.selectionComposite = new DataSourceSelectComposite( - workflow.getComposite(), SWT.RESIZE, workflow); - } - - return this.selectionComposite; - } - - @Override - public void run(StateMachine stateMachine) { - - if (workflow.getDataSource() == null) { - DataSourceSelectComposite selection = this - .getSelectionComposite(workflow); - - workflow.setTopControl(selection); - selection.layout(); - - File source = selection.getSelected(); - if(source != null) { - workflow.setDataSource(source); - } - - if (workflow.getDataSource() == null) { - // Not selected yet - this.setNextState(this); - return; - } - } - log.debug("Got Datasource: " + workflow.getDataSource().getAbsolutePath()); - this.setNextState(new PositioningState()); - } - - @Override - public String toString() { - return "DataSourceSelectionState"; - } -} 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/OpenState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java new file mode 100644 index 00000000..ee90a69b --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java @@ -0,0 +1,93 @@ +/* + * 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.states; + +//Imports +import org.eclipse.swt.SWT; +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.composites.DataSourceSelectComposite; +import at.asit.pdfover.gui.workflow.StateMachine; + +/** + * Selects the data source for the signature process. + */ +public class OpenState extends State { + + /** + * @param stateMachine + */ + public OpenState(StateMachine stateMachine) { + super(stateMachine); + } + + /** + * SFL4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(OpenState.class); + + private DataSourceSelectComposite selectionComposite = null; + + private DataSourceSelectComposite getSelectionComposite() { + if (this.selectionComposite == null) { + this.selectionComposite = new DataSourceSelectComposite( + this.stateMachine.getGUIProvider().getComposite(), SWT.RESIZE, this); + } + + return this.selectionComposite; + } + + @Override + public void run() { + + if (this.stateMachine.getStatus().getDocument() == null) { + DataSourceSelectComposite selection = this + .getSelectionComposite(); + + this.stateMachine.getGUIProvider().display(selection); + selection.layout(); + + this.stateMachine.getStatus().setDocument(selection.getSelected()); + + if (this.stateMachine.getStatus().getDocument() == null) { + // Not selected yet + return; + } + } + 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 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,14 +19,22 @@ 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) */ public class OutputState extends State { + /** + * @param stateMachine + */ + public OutputState(StateMachine stateMachine) { + super(stateMachine); + } + /** * SFL4J Logger instance **/ @@ -34,15 +42,31 @@ public class OutputState extends State { 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,16 +20,23 @@ 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 */ public class PositioningState extends State { + /** + * @param stateMachine + */ + public PositioningState(StateMachine stateMachine) { + super(stateMachine); + } + /** * SFL4J Logger instance **/ @@ -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; /** @@ -31,18 +31,25 @@ 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,13 +20,19 @@ 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. */ public class SigningState extends State { + /** + * @param stateMachine + */ + public SigningState(StateMachine stateMachine) { + super(stateMachine); + } + /** * SFL4J Logger instance **/ @@ -34,14 +40,22 @@ public class SigningState extends State { 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/states/State.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/State.java new file mode 100644 index 00000000..8b9a3ebb --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/State.java @@ -0,0 +1,86 @@ +/* + * 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.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 + */ +public abstract class State { + + /** + * The StateMachine + */ + protected StateMachine stateMachine; + + /** + * SFL4J Logger instance + **/ + @SuppressWarnings("unused") + 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; + this.nextState = this; + } + + /** + * Gets the next logical state or null if this their is no state transition + * @return the next state (or null) + */ + public State nextState() { + return this.nextState; + } + + /** + * Sets the next logical state + * @param state + */ + protected void setNextState(State state) { + this.nextState = state; + } + + /** + * Perform main logic for this state + */ + public abstract void run(); + + /** + * Update the state machine + */ + public void updateStateMachine() + { + this.stateMachine.update(); + } + + /** + * Update the main window behavior of this state if necessary + * Should update this.stateMachine.getStatus().getBehavior() + */ + public abstract void updateMainWindowBehavior(); +} -- cgit v1.2.3