diff options
author | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:52:37 +0000 |
---|---|---|
committer | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:52:37 +0000 |
commit | e710a326314184f31cd50d4637959f44232a74ee (patch) | |
tree | 59ac4f739626271327af3cf6ff7ec5af1cd29983 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java | |
parent | a21a8667956535db3fa97cdead0f10e7da7b178e (diff) | |
download | mocca-e710a326314184f31cd50d4637959f44232a74ee.tar.gz mocca-e710a326314184f31cd50d4637959f44232a74ee.tar.bz2 mocca-e710a326314184f31cd50d4637959f44232a74ee.zip |
State Machine stuff
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@20 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java')
-rw-r--r-- | pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java | 164 |
1 files changed, 149 insertions, 15 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java index 704a2440..731c5f57 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java @@ -16,8 +16,6 @@ package at.asit.pdfover.gui.components; // Imports -import javax.swing.GroupLayout; - import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; @@ -28,9 +26,31 @@ import org.eclipse.swt.widgets.Composite; 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 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.Workflow; +import at.asit.pdfover.gui.workflow.WorkflowState; +import at.asit.pdfover.gui.workflow.states.BKUSelectionState; +import at.asit.pdfover.gui.workflow.states.DataSourceSelectionState; +import at.asit.pdfover.gui.workflow.states.LocalBKUState; +import at.asit.pdfover.gui.workflow.states.MobileBKUState; +import at.asit.pdfover.gui.workflow.states.OutputState; +import at.asit.pdfover.gui.workflow.states.PositioningState; +import at.asit.pdfover.gui.workflow.states.PrepareConfigurationState; +import at.asit.pdfover.gui.workflow.states.PrepareSigningState; +import at.asit.pdfover.gui.workflow.states.SigningState; /** * The Main Window of PDFOver 4.0 @@ -38,6 +58,29 @@ import org.eclipse.swt.layout.FormAttachment; public class MainWindow { /** + * + */ + private final class DataSourceSelectionListener implements + SelectionListener { + /** + * + */ + public DataSourceSelectionListener() { + // Nothing to do here + } + + @Override + public void widgetSelected(SelectionEvent e) { + MainWindow.this.workflow.setWorkflowState(new DataSourceSelectionState()); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // Nothing to do here + } + } + + /** * SFL4J Logger instance **/ private static final Logger log = LoggerFactory.getLogger(MainWindow.class); @@ -45,12 +88,81 @@ public class MainWindow { private CLabel lbl_status; private Composite container; private StackLayout stack; + private Workflow workflow; + private Button btn_sign; + + /** + * Gets the sign button + * @return the sign button + */ + public Button getBtn_sign() { + return this.btn_sign; + } + + private Button btn_position; + + /** + * Gets the position button + * @return the position button + */ + public Button getBtn_position() { + return this.btn_position; + } + + private Button btn_open; + + /** + * Gets the open button + * @return the open button + */ + public Button getBtn_open() { + return this.btn_open; + } + + private Button btn_config; + + /** + * Gets the config button + * @return the config button + */ + public Button getBtn_config() { + return this.btn_config; + } + + private Map<Class, MainWindowBehavior> behavior = new HashMap<Class, MainWindowBehavior>(); + + /** + * Default contsructor + * @param workflow The main workflow + */ + public MainWindow(Workflow workflow) { + super(); + + this.behavior.put(PrepareConfigurationState.class, new MainWindowAllDisabled()); + this.behavior.put(PrepareSigningState.class, new MainWindowAllDisabled()); + this.behavior.put(SigningState.class, new MainWindowAllDisabled()); + this.behavior.put(LocalBKUState.class, new MainWindowAllDisabled()); + this.behavior.put(MobileBKUState.class, new MainWindowAllDisabled()); + + this.behavior.put(OutputState.class, new MainWindowAllDisabled()); + + this.behavior.put(DataSourceSelectionState.class, new OnlyConfigEnabled()); + + this.behavior.put(PositioningState.class, new ConfigOpenEnabled()); + + this.behavior.put(BKUSelectionState.class, new ConfigOpenPositionEnabled()); + + this.workflow = workflow; + } /** * Set current status (may be removed in production release) * @param value */ public void setStatus(String value) { + if(this.getShell().isDisposed()) { + return; + } this.lbl_status.setText("[DEBUG]: Current workflow state: " + value); } @@ -61,6 +173,14 @@ public class MainWindow { public void setTopControl(Control ctrl) { log.debug("Top control: " + ctrl.toString()); this.stack.topControl = ctrl; + this.doLayout(); + } + + /** + * Layout the Main Window + */ + public void doLayout() { + Control ctrl = this.stack.topControl; this.container.layout(true, true); this.shell.layout(true, true); // Note: SWT only layouts children! No grandchildren! @@ -84,7 +204,7 @@ public class MainWindow { public static void main(String[] args) { Display display = Display.getDefault(); - MainWindow window = new MainWindow(); + MainWindow window = new MainWindow(null); window.open(); @@ -126,41 +246,42 @@ public class MainWindow { composite.setLayoutData(fd_composite); composite.setLayout(new FormLayout()); - Button btn_config = new Button(composite, SWT.NONE); + this.btn_config = new Button(composite, SWT.NONE); FormData fd_config = new FormData(); fd_config.left = new FormAttachment(0, 0); fd_config.right = new FormAttachment(25, 0); fd_config.top = new FormAttachment(0, 0); fd_config.bottom = new FormAttachment(100, 0); - btn_config.setLayoutData(fd_config); - btn_config.setText("Config ..."); + this.btn_config.setLayoutData(fd_config); + this.btn_config.setText("Config ..."); - Button btn_open = new Button(composite, SWT.NONE); + this.btn_open = new Button(composite, SWT.NONE); FormData fd_open = new FormData(); fd_open.left = new FormAttachment(25, 0); fd_open.right = new FormAttachment(50, 0); fd_open.top = new FormAttachment(0, 0); fd_open.bottom = new FormAttachment(100, 0); - btn_open.setLayoutData(fd_open); - btn_open.setText("Open ..."); + this.btn_open.setLayoutData(fd_open); + this.btn_open.setText("Open ..."); + this.btn_open.addSelectionListener(new DataSourceSelectionListener()); - Button btn_position = new Button(composite, SWT.NONE); + this.btn_position = new Button(composite, SWT.NONE); FormData fd_position = new FormData(); fd_position.left = new FormAttachment(50, 0); fd_position.right = new FormAttachment(75, 0); fd_position.top = new FormAttachment(0, 0); fd_position.bottom = new FormAttachment(100, 0); - btn_position.setLayoutData(fd_position); - btn_position.setText("Positon ..."); + this.btn_position.setLayoutData(fd_position); + this.btn_position.setText("Positon ..."); - Button btn_sign = new Button(composite, SWT.NONE); + this.btn_sign = new Button(composite, SWT.NONE); FormData fd_sign = new FormData(); fd_sign.left = new FormAttachment(75, 0); fd_sign.right = new FormAttachment(100, 0); fd_sign.top = new FormAttachment(0, 0); fd_sign.bottom = new FormAttachment(100, 0); - btn_sign.setLayoutData(fd_sign); - btn_sign.setText("Sign ..."); + this.btn_sign.setLayoutData(fd_sign); + this.btn_sign.setText("Sign ..."); this.container = new Composite(getShell(), SWT.BORDER | SWT.RESIZE); FormData fd_composite_1 = new FormData(); @@ -184,6 +305,19 @@ public class MainWindow { } /** + * Update MainWindow to fit new status + */ + public void UpdateNewState() { + WorkflowState state = this.workflow.getState(); + + log.debug("Updating MainWindow state for : " + state.toString()); + + if(this.behavior.containsKey(state.getClass())) { + this.behavior.get(state.getClass()).SetState(this); + } + } + + /** * @return the shell */ public Shell getShell() { |