diff options
Diffstat (limited to 'trunk/pdf-over-gui/src/main')
6 files changed, 46 insertions, 494 deletions
diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/BKUSelectionComposite.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/BKUSelectionComposite.java index 70282202..84b38a07 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/BKUSelectionComposite.java +++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/BKUSelectionComposite.java @@ -116,6 +116,7 @@ public class BKUSelectionComposite extends Composite implements StateComposite { * Create the composite. * @param parent * @param style + * @param state */ public BKUSelectionComposite(Composite parent, int style, BKUSelectionState state) { super(parent, style); diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java index 088afe3c..96195780 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java +++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java @@ -16,32 +16,33 @@ package at.asit.pdfover.gui.components; // Imports -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.eclipse.swt.widgets.Composite; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.custom.StackLayout; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormAttachment; -import java.lang.Class; -import java.util.HashMap; -import java.util.Map; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.components.main_behavior.ConfigOpenEnabled; import at.asit.pdfover.gui.components.main_behavior.ConfigOpenPositionEnabled; import at.asit.pdfover.gui.components.main_behavior.MainWindowAllDisabled; import at.asit.pdfover.gui.components.main_behavior.MainWindowBehavior; import at.asit.pdfover.gui.components.main_behavior.OnlyConfigEnabled; -import at.asit.pdfover.gui.workflow.StateMachineImpl; import at.asit.pdfover.gui.workflow.State; +import at.asit.pdfover.gui.workflow.StateMachine; +import at.asit.pdfover.gui.workflow.StateMachineImpl; import at.asit.pdfover.gui.workflow.states.BKUSelectionState; import at.asit.pdfover.gui.workflow.states.DataSourceSelectionState; import at.asit.pdfover.gui.workflow.states.LocalBKUState; @@ -71,7 +72,7 @@ public class MainWindow { @Override public void widgetSelected(SelectionEvent e) { - MainWindow.this.workflow.setWorkflowState(new DataSourceSelectionState()); + MainWindow.this.stateMachine.setState(new DataSourceSelectionState()); } @Override @@ -88,7 +89,7 @@ public class MainWindow { private CLabel lbl_status; private Composite container; private StackLayout stack; - private StateMachineImpl workflow; + private StateMachine stateMachine; private Button btn_sign; /** @@ -133,9 +134,9 @@ public class MainWindow { /** * Default contsructor - * @param workflow The main workflow + * @param stateMachine The main workflow */ - public MainWindow(StateMachineImpl workflow) { + public MainWindow(StateMachine stateMachine) { super(); this.behavior.put(PrepareConfigurationState.class, new MainWindowAllDisabled()); @@ -152,7 +153,7 @@ public class MainWindow { this.behavior.put(BKUSelectionState.class, new ConfigOpenPositionEnabled()); - this.workflow = workflow; + this.stateMachine = stateMachine; } /** @@ -308,7 +309,7 @@ public class MainWindow { * Update MainWindow to fit new status */ public void UpdateNewState() { - State state = this.workflow.getState(); + State state = this.stateMachine.getState(); log.debug("Updating MainWindow state for : " + state.toString()); diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java index b315b9d2..92505d19 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java +++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java @@ -26,13 +26,20 @@ public interface StateMachine { * @return the ConfigProvider */ public ConfigProvider getConfigProvider(); - + /** * Get the container Composite * @return the container Composite */ 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) /** * Get the Status diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java index 990ff00c..8549007c 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java +++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java @@ -20,13 +20,17 @@ 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.workflow.states.BKUSelectionState; import at.asit.pdfover.gui.workflow.states.DataSourceSelectionState; @@ -81,7 +85,7 @@ public class StateMachineImpl implements StateMachine { * * @param state */ - public void setWorkflowState(State state) { + public void setState(State state) { if (this.state != state && state != null) { this.state = state; @@ -223,6 +227,18 @@ public class StateMachineImpl implements StateMachine { return this.container; } + @Override + public <T> T createComposite(Class<T> compositeClass) { + T composite = null; + try { + Constructor<T> constructor = compositeClass.getDeclaredConstructor(Composite.class, int.class, BKUSelectionState.class); + composite = constructor.newInstance(getComposite(), SWT.RESIZE, this); + } catch (Exception e) { + log.error("Could not create Composite for Class " + compositeClass.getName(), e); + } + return composite; + } + /** * Only returns a shell if one was already created ... * diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Workflow.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Workflow.java deleted file mode 100644 index 48e57f50..00000000 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Workflow.java +++ /dev/null @@ -1,410 +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; - -//Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.util.Properties; - -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.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 - * logical state - */ -public class Workflow { - - /** - * SFL4J Logger instance - **/ - private static final Logger log = LoggerFactory.getLogger(Workflow.class); - - /** - * Default constructor - * - * @param cmdLineArgs - */ - public Workflow(String[] cmdLineArgs) { - setCmdLineAargs(cmdLineArgs); - } - - /** - * @uml.property name="state" - * @uml.associationEnd multiplicity="(1 1)" aggregation="shared" - * inverse="workflow1:at.asit.pdfover.gui.workflow.WorkflowState" - */ - private WorkflowState state = new PrepareConfigurationState(); - - /** - * Getter of the property <tt>state</tt> - * - * @return Returns the state. - * @uml.property name="state" - */ - public WorkflowState getState() { - return this.state; - } - - /** - * 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 setWorkflowState(WorkflowState state) { - if (this.state != state && state != null) { - this.state = state; - - 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); - } - - this.update(); - } - } - - /** - * Update Workflow logic and let state machine do its job... - */ - public void update() { - 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(); - log.debug("Changing state from: " + this.state.toString() + " to " - + next.toString()); - this.state = next; - } - if (this.state != null) { - this.setCurrentStateMessage(this.state.toString()); - } else { - this.setCurrentStateMessage(""); - } - } - - /** - * 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; - - private Composite container = null; - - private MainWindow mainWindow = null; - - /** - * Helper method for developing - * - * @param value - */ - public void setCurrentStateMessage(String value) { - 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) { - this.mainWindow.setTopControl(ctrl); - } - - private void createMainWindow() { - this.display = Display.getDefault(); - - this.mainWindow = new MainWindow(this); - - this.mainWindow.open(); - - this.shell = this.mainWindow.getShell(); - - this.container = this.mainWindow.getContainer(); - - this.shell.open(); - this.shell.layout(); - } - - /** - * Gets the Shell for drawing the ui - * - * @return Composite - */ - public Composite getComposite() { - // Main window will be build on first call - // returns SWT Composite container for states to draw their GUI - - if (this.container == null) { - this.createMainWindow(); - } - - if (this.container == null) { - // TODO throw Exception... - } - - return this.container; - } - - /** - * Only returns a shell if one was already created ... - * - * @return - */ - private Shell nonCreatingGetShell() { - return this.shell; - } - - /** - * Exists the Workflow - */ - public void exitWorkflow() { - this.shell.dispose(); - } - - /** - * Only returns a shell if one was already created ... - * - * @return - */ - private Display nonCreatingGetDisplay() { - return this.display; - } - - /** - * Workflow main entrance point - */ - public void start() { - // Call update to start processing ... - this.update(); - - // if a user interaction is required we have a shell ... - Shell shell = this.nonCreatingGetShell(); - Display display = this.nonCreatingGetDisplay(); - - if (shell != null && display != null) { - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - display.dispose(); - } - } - - // 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; - } -} diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/WorkflowState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/WorkflowState.java deleted file mode 100644 index 831c4394..00000000 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/WorkflowState.java +++ /dev/null @@ -1,63 +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; - -//Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Base state class - */ -public abstract class WorkflowState { - - /** - * SFL4J Logger instance - **/ - @SuppressWarnings("unused") - private static final Logger log = LoggerFactory.getLogger(WorkflowState.class); - - private WorkflowState _next = null; - - /** - * Default Workflow State constructor - */ - public WorkflowState() { - this._next = this; - } - - /** - * Gets the next logical state or null if this their is no state transition - * @return the next state (or null) - */ - public WorkflowState nextState() { - return this._next; - } - - /** - * Sets the next logical state - * @param state - */ - protected void setNextState(WorkflowState state) { - this._next = state; - } - - /** - * Perform main logic for this state - * @param workflow - */ - public abstract void update(Workflow workflow); -} |