diff options
author | tkellner <tkellner@3a0b52a2-8410-0410-bc02-ff6273a87459> | 2012-08-24 17:04:50 +0000 |
---|---|---|
committer | tkellner <tkellner@3a0b52a2-8410-0410-bc02-ff6273a87459> | 2012-08-24 17:04:50 +0000 |
commit | 52edf7dfea3015e807e72e0812d99abbb53e6f9f (patch) | |
tree | dedf1ba82f6e4a9b1ed48c84b70c761daf673e7b /trunk/pdf-over-gui/src/main/java/at/asit/pdfover | |
parent | 2159fac36839b3d0db4784b624b25e3bb1163315 (diff) | |
download | pdf-over-52edf7dfea3015e807e72e0812d99abbb53e6f9f.tar.gz pdf-over-52edf7dfea3015e807e72e0812d99abbb53e6f9f.tar.bz2 pdf-over-52edf7dfea3015e807e72e0812d99abbb53e6f9f.zip |
State Machine refactoring
git-svn-id: https://svn.iaik.tugraz.at/svn/egiz/prj/current/12PDF-OVER-4.0@12388 3a0b52a2-8410-0410-bc02-ff6273a87459
Diffstat (limited to 'trunk/pdf-over-gui/src/main/java/at/asit/pdfover')
29 files changed, 868 insertions, 1306 deletions
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/MainWindow.java index 96195780..706064bd 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/MainWindow.java @@ -13,10 +13,10 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.components; +package at.asit.pdfover.gui; // Imports -import java.util.HashMap; +import java.util.EnumMap; import java.util.Map; import org.eclipse.swt.SWT; @@ -35,23 +35,10 @@ 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.State; +import at.asit.pdfover.gui.composites.StateComposite; 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; -import at.asit.pdfover.gui.workflow.states.MobileBKUState; -import at.asit.pdfover.gui.workflow.states.OutputState; +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.PrepareSigningState; -import at.asit.pdfover.gui.workflow.states.SigningState; /** * The Main Window of PDFOver 4.0 @@ -59,12 +46,35 @@ import at.asit.pdfover.gui.workflow.states.SigningState; public class MainWindow { /** - * + * Selection Listener for Position Button + */ + private final class PositionSelectionListener implements SelectionListener { + /** + * Default constructor + */ + public PositionSelectionListener() { + // Nothing to do here + } + + @Override + public void widgetSelected(SelectionEvent e) { + MainWindow.this.stateMachine.jumpToState(new PositioningState( + MainWindow.this.stateMachine)); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // Nothing to do here + } + } + + /** + * Selection Listener for Open Button */ private final class DataSourceSelectionListener implements SelectionListener { /** - * + * Default constructor */ public DataSourceSelectionListener() { // Nothing to do here @@ -72,7 +82,9 @@ public class MainWindow { @Override public void widgetSelected(SelectionEvent e) { - MainWindow.this.stateMachine.setState(new DataSourceSelectionState()); + MainWindow.this.stateMachine + .jumpToState(new OpenState( + MainWindow.this.stateMachine)); } @Override @@ -84,84 +96,45 @@ public class MainWindow { /** * SFL4J Logger instance **/ - private static final Logger log = LoggerFactory.getLogger(MainWindow.class); + static final Logger log = LoggerFactory.getLogger(MainWindow.class); + private Shell shell; private CLabel lbl_status; private Composite container; private StackLayout stack; - private StateMachine stateMachine; + StateMachine stateMachine; 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; + + public enum Buttons { + CONFIG, OPEN, POSITION, SIGN, FINAL } - private Map<Class, MainWindowBehavior> behavior = new HashMap<Class, MainWindowBehavior>(); - + private Map<Buttons, Button> buttonMap; + /** - * Default contsructor - * @param stateMachine The main workflow + * Default constructor + * + * @param stateMachine + * The main workflow */ public MainWindow(StateMachine stateMachine) { 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.stateMachine = stateMachine; + + this.buttonMap = new EnumMap<MainWindow.Buttons, Button>(Buttons.class); } /** * Set current status (may be removed in production release) + * * @param value */ public void setStatus(String value) { - if(this.getShell().isDisposed()) { + if (this.getShell().isDisposed()) { return; } this.lbl_status.setText("[DEBUG]: Current workflow state: " + value); @@ -169,6 +142,7 @@ public class MainWindow { /** * Sets top level composite for stack layout + * * @param ctrl */ public void setTopControl(Control ctrl) { @@ -176,7 +150,7 @@ public class MainWindow { this.stack.topControl = ctrl; this.doLayout(); } - + /** * Layout the Main Window */ @@ -185,30 +159,32 @@ public class MainWindow { this.container.layout(true, true); this.shell.layout(true, true); // Note: SWT only layouts children! No grandchildren! - if(ctrl instanceof StateComposite) { - ((StateComposite)ctrl).doLayout(); + if (ctrl instanceof StateComposite) { + ((StateComposite) ctrl).doLayout(); } } - + /** * Gets the container composite - * @return + * + * @return the container composite */ public Composite getContainer() { return this.container; } - + /** * Entrance point for swt designer + * * @param args */ public static void main(String[] args) { Display display = Display.getDefault(); - + MainWindow window = new MainWindow(null); - + window.open(); - + window.getShell().open(); window.getShell().layout(); while (!window.getShell().isDisposed()) { @@ -217,9 +193,10 @@ public class MainWindow { } } } - + /** * Open the window. + * * @wbp.parser.entryPoint */ public void open() { @@ -232,12 +209,10 @@ public class MainWindow { protected void createContents() { this.shell = new Shell(); getShell().setSize(450, 329); - getShell().setText("PDF OVER 4.0! :)"); - + getShell().setText("PDF-Over"); + getShell().setLayout(new FormLayout()); - - - + Composite composite = new Composite(getShell(), SWT.NONE); FormData fd_composite = new FormData(); fd_composite.left = new FormAttachment(0, 5); @@ -246,7 +221,7 @@ public class MainWindow { fd_composite.bottom = new FormAttachment(0, 40); composite.setLayoutData(fd_composite); composite.setLayout(new FormLayout()); - + this.btn_config = new Button(composite, SWT.NONE); FormData fd_config = new FormData(); fd_config.left = new FormAttachment(0, 0); @@ -255,7 +230,8 @@ public class MainWindow { fd_config.bottom = new FormAttachment(100, 0); this.btn_config.setLayoutData(fd_config); this.btn_config.setText("Config ..."); - + buttonMap.put(Buttons.CONFIG, btn_config); + this.btn_open = new Button(composite, SWT.NONE); FormData fd_open = new FormData(); fd_open.left = new FormAttachment(25, 0); @@ -265,7 +241,8 @@ public class MainWindow { this.btn_open.setLayoutData(fd_open); this.btn_open.setText("Open ..."); this.btn_open.addSelectionListener(new DataSourceSelectionListener()); - + buttonMap.put(Buttons.OPEN, btn_open); + this.btn_position = new Button(composite, SWT.NONE); FormData fd_position = new FormData(); fd_position.left = new FormAttachment(50, 0); @@ -274,7 +251,9 @@ public class MainWindow { fd_position.bottom = new FormAttachment(100, 0); this.btn_position.setLayoutData(fd_position); this.btn_position.setText("Positon ..."); - + this.btn_position.addSelectionListener(new PositionSelectionListener()); + buttonMap.put(Buttons.POSITION, btn_position); + this.btn_sign = new Button(composite, SWT.NONE); FormData fd_sign = new FormData(); fd_sign.left = new FormAttachment(75, 0); @@ -283,7 +262,8 @@ public class MainWindow { fd_sign.bottom = new FormAttachment(100, 0); this.btn_sign.setLayoutData(fd_sign); this.btn_sign.setText("Sign ..."); - + buttonMap.put(Buttons.SIGN, btn_sign); + this.container = new Composite(getShell(), SWT.BORDER | SWT.RESIZE); FormData fd_composite_1 = new FormData(); fd_composite_1.bottom = new FormAttachment(100, -25); @@ -293,7 +273,7 @@ public class MainWindow { this.container.setLayoutData(fd_composite_1); this.stack = new StackLayout(); this.container.setLayout(this.stack); - + this.lbl_status = new CLabel(getShell(), SWT.NONE); FormData fd_lblNewLabel = new FormData(); fd_lblNewLabel.right = new FormAttachment(100, -5); @@ -308,16 +288,27 @@ public class MainWindow { /** * Update MainWindow to fit new status */ - public void UpdateNewState() { - State state = this.stateMachine.getState(); - - log.debug("Updating MainWindow state for : " + state.toString()); - - if(this.behavior.containsKey(state.getClass())) { - this.behavior.get(state.getClass()).SetState(this); + public void applyBehavior() { + MainWindowBehavior behavior = this.stateMachine.getStatus() + .getBehavior(); + + log.debug("Updating MainWindow state for : " + + this.stateMachine.getStatus().getCurrentState().toString()); + + for (Buttons button : Buttons.values()) { + boolean active = behavior.getActive(button); + boolean enabled = behavior.getEnabled(button); + + Button theButton = buttonMap.get(button); + if (theButton != null) + { + theButton.setEnabled(enabled); + } } + + //TODO: Display/Hide main bar } - + /** * @return the shell */ diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindowBehavior.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindowBehavior.java new file mode 100644 index 00000000..63c2dafd --- /dev/null +++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindowBehavior.java @@ -0,0 +1,74 @@ +/* + * 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; + +import java.util.EnumMap; +import java.util.Map; + +import at.asit.pdfover.gui.MainWindow.Buttons; + +/** + * Behavior manipulation for Main Window + */ +public class MainWindowBehavior { + protected Map<Buttons, Boolean> buttonsEnabled; + protected Map<Buttons, Boolean> buttonsActive; + protected boolean mainBarVisible; + + public MainWindowBehavior() { + this.buttonsActive = new EnumMap<MainWindow.Buttons, Boolean>(MainWindow.Buttons.class); + this.buttonsEnabled = new EnumMap<MainWindow.Buttons, Boolean>( MainWindow.Buttons.class); + reset(); + } + + public void setActive(Buttons button, boolean active) { + this.buttonsActive.put(button, active); + } + + public boolean getActive(Buttons button) { + return this.buttonsActive.get(button); + } + + public void setEnabled(Buttons button, boolean enabled) { + this.buttonsEnabled.put(button, enabled); + } + + public boolean getEnabled(Buttons button) { + return this.buttonsEnabled.get(button); + } + + /** + * Resets all behavior to a default state + * All buttons are inactive + * All buttons are disabled + * Main bar is visible + */ + public void reset() { + for (Buttons button : Buttons.values()) { + setActive(button, false); + setEnabled(button, false); + } + setMainBarVisible(true); + } + + public void setMainBarVisible(boolean visible) { + this.mainBarVisible = visible; + } + + public boolean getMainBarVisible() { + return this.mainBarVisible; + } +} 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 deleted file mode 100644 index 84b38a07..00000000 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/BKUSelectionComposite.java +++ /dev/null @@ -1,167 +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.components; - -// Imports -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.FormAttachment; -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.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.states.BKUSelectionState; -import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs; - -/** - * - */ -public class BKUSelectionComposite extends Composite implements StateComposite { - - - /** - * Listener for local bku selection - */ - private final class LocalSelectionListener implements SelectionListener { - - /** - * Default constructor - */ - public LocalSelectionListener() { - // Nothing here - } - - @Override - public void widgetSelected(SelectionEvent e) { - log.debug("Setting BKU to LOCAL"); - setSelected(BKUs.LOCAL); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - // Nothing here - } - } - - /** - * Listener for mobile bku selection - */ - private final class MobileSelectionListener implements SelectionListener { - - /** - * Default constructor - */ - public MobileSelectionListener() { - // Nothing here - } - - @Override - public void widgetSelected(SelectionEvent e) { - log.debug("Setting BKU to MOBILE"); - setSelected(BKUs.MOBILE); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - // Nothing here - } - } - - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(BKUSelectionComposite.class); - - private BKUSelectionState state; - - private BKUs selected = BKUs.NONE; - - /** - * Gets selected BKU type - * @return BKUS enum - */ - public BKUs getSelected() { - return this.selected; - } - - /** - * Sets selected BKU and updates workflow - * @param selected - */ - public void setSelected(final BKUs selected) { - this.selected = selected; - this.state.updateStateMachine(); - } - - /** - * Create the composite. - * @param parent - * @param style - * @param state - */ - public BKUSelectionComposite(Composite parent, int style, BKUSelectionState state) { - super(parent, style); - - this.state = state; - - this.setLayout(new FormLayout()); - - - Button btn_mobile = new Button(this, SWT.NATIVE | SWT.RESIZE); - btn_mobile.setText("MOBILE"); - //Point mobile_size = btn_mobile.computeSize(SWT.DEFAULT, SWT.DEFAULT); - FormData fd_btn_mobile = new FormData(); - fd_btn_mobile.left = new FormAttachment(40, 0); - fd_btn_mobile.right = new FormAttachment(50, 0); - fd_btn_mobile.top = new FormAttachment(45, 0); - fd_btn_mobile.bottom = new FormAttachment(55, 0); - btn_mobile.setLayoutData(fd_btn_mobile); - btn_mobile.addSelectionListener(new MobileSelectionListener()); - - Button btn_card = new Button(this, SWT.NATIVE | SWT.RESIZE); - btn_card.setText("CARD"); - //Point card_size = btn_card.computeSize(SWT.DEFAULT, SWT.DEFAULT); - FormData fd_btn_card = new FormData(); - fd_btn_card.left = new FormAttachment(50, 0); - fd_btn_card.right = new FormAttachment(60, 0); - fd_btn_card.top = new FormAttachment(45, 0); - fd_btn_card.bottom = new FormAttachment(55, 0); - btn_card.setLayoutData(fd_btn_card); - btn_card.addSelectionListener(new LocalSelectionListener()); - - this.pack(); - } - - @Override - protected void checkSubclass() { - // Disable the check that prevents subclassing of SWT components - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.components.StateComposite#doLayout() - */ - @Override - public void doLayout() { - this.layout(true, true); - } - -} diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/DataSourceSelectComposite.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/DataSourceSelectComposite.java deleted file mode 100644 index fe0cb2ee..00000000 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/DataSourceSelectComposite.java +++ /dev/null @@ -1,296 +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.components; - -// Imports -import java.io.File; - -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Label; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.*; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; - -import at.asit.pdfover.gui.workflow.StateMachineImpl; - -/** - * - * - */ -public class DataSourceSelectComposite extends Composite implements - StateComposite { - - /** - * - */ - private final class FileBrowseDialog implements SelectionListener { - /** - * - */ - public FileBrowseDialog() { - // Nothing to do here - } - - @Override - public void widgetSelected(SelectionEvent e) { - FileDialog dialog = new FileDialog(DataSourceSelectComposite.this.getShell(), SWT.OPEN); - dialog.setFilterExtensions(new String[] {"*.pdf"}); - dialog.setFilterNames(new String[] {"PDF Dateien"}); - String fileName = dialog.open(); - File file = null; - if (fileName != null) { - file = new File(fileName); - if(file.exists()) { - DataSourceSelectComposite.this.setSelected(file); - } - } - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - // Nothing to do here - } - } - - /** - * SFL4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(DataSourceSelectComposite.class); - - private StateMachineImpl workflow; - - /** - * Set this value through the setter method!! - */ - private File selected = null; - - /** - * Sets the selected file and calls update to the workflow - * @param selected - */ - protected void setSelected(File selected) { - this.selected = selected; - workflow.update(); - } - - /** - * Gets the selected file - * - * @return the selected file - */ - public File getSelected() { - return this.selected; - } - - /** - * Create the composite. - * - * @param parent - * @param style - * @param flow - */ - public DataSourceSelectComposite(Composite parent, int style, StateMachineImpl flow) { - super(parent, style); - - this.workflow = flow; - - this.setLayout(new FormLayout()); - - Color back = new Color(Display.getCurrent(), 77, 190, 250); - - this.drop_area = new Composite(this, SWT.RESIZE | SWT.BORDER_DASH); - FormData fd_drop_area = new FormData(); - fd_drop_area.left = new FormAttachment(0, 0); - fd_drop_area.right = new FormAttachment(100, 0); - fd_drop_area.top = new FormAttachment(0, 0); - fd_drop_area.bottom = new FormAttachment(100, 0); - this.drop_area.setLayoutData(fd_drop_area); - this.drop_area.setLayout(new FormLayout()); - this.drop_area.setBackground(back); - - DropTarget dnd_target = new DropTarget(this.drop_area, DND.DROP_DEFAULT - | DND.DROP_COPY); - final FileTransfer fileTransfer = FileTransfer.getInstance(); - Transfer[] types = new Transfer[] { fileTransfer }; - dnd_target.setTransfer(types); - - dnd_target.addDropListener(new DropTargetListener() { - - @Override - public void dropAccept(DropTargetEvent event) { - // TODO Auto-generated method stub - - } - - @Override - public void drop(DropTargetEvent event) { - if (fileTransfer.isSupportedType(event.currentDataType)){ - String[] files = (String[])event.data; - if(files.length > 0) { - // Only taking first file ... - File file = new File(files[0]); - if(!file.exists()) - { - log.error("File: " + files[0] + " doesnot exists!"); - return; - } - DataSourceSelectComposite.this.setSelected(file); - } - } - } - - @Override - public void dragOver(DropTargetEvent event) { - // TODO Auto-generated method stub - - } - - @Override - public void dragOperationChanged(DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) { - if ((event.operations & DND.DROP_COPY) != 0) { - event.detail = DND.DROP_COPY; - } else { - event.detail = DND.DROP_NONE; - } - } - } - - @Override - public void dragLeave(DropTargetEvent event) { - // No need to do anything here... - } - - @Override - public void dragEnter(DropTargetEvent event) { - if (event.detail == DND.DROP_DEFAULT) { - if ((event.operations & DND.DROP_COPY) != 0) { - event.detail = DND.DROP_COPY; - } else { - event.detail = DND.DROP_NONE; - } - } - // Only drop one item! - if(event.dataTypes.length > 1) { - event.detail = DND.DROP_NONE; - return; - } - // will accept text but prefer to have files dropped - for (int i = 0; i < event.dataTypes.length; i++) { - if (fileTransfer.isSupportedType(event.dataTypes[i])) { - event.currentDataType = event.dataTypes[i]; - // files should only be copied - if (event.detail != DND.DROP_COPY) { - event.detail = DND.DROP_NONE; - } - break; - } - } - } - }); - - final Label lbl_drag = new Label(this.drop_area, SWT.NONE | SWT.RESIZE); - FormData fd_lbl_drag = new FormData(); - fd_lbl_drag.left = new FormAttachment(5, 5); - fd_lbl_drag.right = new FormAttachment(100, -5); - fd_lbl_drag.top = new FormAttachment(5, 5); - fd_lbl_drag.bottom = new FormAttachment(55, -5); - lbl_drag.setLayoutData(fd_lbl_drag); - FontData[] fD = lbl_drag.getFont().getFontData(); - fD[0].setHeight(18); - lbl_drag.setFont(new Font(Display.getCurrent(), fD[0])); - lbl_drag.setText("Drag and Drop"); - lbl_drag.setAlignment(SWT.CENTER); - lbl_drag.setBackground(back); - - Button btn_open = new Button(this.drop_area, SWT.NATIVE | SWT.RESIZE); - btn_open.setText("Choose file ..."); - Point size = btn_open.computeSize(SWT.DEFAULT, SWT.DEFAULT); - FormData fd_btn_open = new FormData(); - fd_btn_open.left = new FormAttachment(100, size.x * -1 - 10); - fd_btn_open.right = new FormAttachment(100, -5); - fd_btn_open.top = new FormAttachment(100, size.y * -1 - 10); - fd_btn_open.bottom = new FormAttachment(100, -5); - btn_open.setLayoutData(fd_btn_open); - btn_open.setBackground(back); - btn_open.addSelectionListener(new FileBrowseDialog()); - this.drop_area.pack(); - - /* - * Button btn = new Button(this, SWT.NATIVE); btn.setBounds(50, 20, 100, - * 50); btn.setText("Click Me"); btn.addSelectionListener(new - * SelectionListener() { - * - * @Override public void widgetSelected(SelectionEvent arg0) { - * DataSourceSelectComposite.this.setPress(true); - * DataSourceSelectComposite.this.workflow.update(); } - * - * @Override public void widgetDefaultSelected(SelectionEvent arg0) { // - * TODO Auto-generated method stub - * - * } }); - */ - } - - private boolean press = false; - - private Composite drop_area; - - @Override - protected void checkSubclass() { - // Disable the check that prevents subclassing of SWT components - } - - /** - * @return the press - */ - public boolean isPress() { - return this.press; - } - - /** - * @param press - * the press to set - */ - public void setPress(boolean press) { - this.press = press; - } - - /* - * (non-Javadoc) - * - * @see at.asit.pdfover.gui.components.StateComposite#doLayout() - */ - @Override - public void doLayout() { - this.layout(true, true); - this.drop_area.layout(true, true); - } -} diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/PositioningComposite.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/PositioningComposite.java deleted file mode 100644 index c924ef79..00000000 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/PositioningComposite.java +++ /dev/null @@ -1,120 +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.components; - -// Imports -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.workflow.StateMachineImpl; -import at.asit.pdfover.signator.SignaturePosition; - -/** - * - * - */ -public class PositioningComposite extends Composite implements StateComposite { - - /** - * Selection listener when position was fixed - */ - private final class PositionSelectedListener implements SelectionListener { - - /** - * Default constructor - */ - public PositionSelectedListener() { - // Nothing to do - } - - @Override - public void widgetSelected(SelectionEvent e) { - // TODO: FIX to get real position - PositioningComposite.this.setPosition(new SignaturePosition()); // Setting auto position for testing - PositioningComposite.this.workflow.update(); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - // Nothing to do - } - } - - /** - * SFL4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(PositioningComposite.class); - - private StateMachineImpl workflow; - - private SignaturePosition position = null; - - /** - * Gets the Position - * @return - */ - public SignaturePosition getPosition() { - return this.position; - } - - /** - * Sets the position - * @param position - */ - public void setPosition(SignaturePosition position) { - this.position = position; - } - - /** - * Create the composite. - * @param parent - * @param style - */ - public PositioningComposite(Composite parent, int style, StateMachineImpl workflow) { - super(parent, style); - - this.workflow = workflow; - - Label test = new Label(this, SWT.NATIVE); - test.setBounds(10, 20, 100, 30); - test.setText("POSITIONING ---- TODO!!"); - - Button btn_position = new Button(this, SWT.NATIVE | SWT.RESIZE); - btn_position.setBounds(10, 50, 100, 30); - btn_position.setText("FAKE Position"); - btn_position.addSelectionListener(new PositionSelectedListener()); - } - - @Override - protected void checkSubclass() { - // Disable the check that prevents subclassing of SWT components - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.components.StateComposite#doLayout() - */ - @Override - public void doLayout() { - this.layout(true, true); - } -} diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/WaitingComposite.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/WaitingComposite.java deleted file mode 100644 index 6ce53b22..00000000 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/WaitingComposite.java +++ /dev/null @@ -1,66 +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.components; - -// Imports -import org.eclipse.swt.widgets.Composite; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.eclipse.swt.widgets.ProgressBar; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormAttachment; - -import at.asit.pdfover.gui.workflow.StateMachineImpl; - -/** - * - */ -public class WaitingComposite extends Composite { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(WaitingComposite.class); - - private StateMachineImpl workflow; - - /** - * Create the composite. - * @param parent - * @param style - */ - public WaitingComposite(Composite parent, int style, StateMachineImpl workflow) { - super(parent, style); - setLayout(new FormLayout()); - - this.workflow = workflow; - - ProgressBar progressBar = new ProgressBar(this, SWT.HORIZONTAL | SWT.INDETERMINATE); - FormData fd_progressBar = new FormData(); - fd_progressBar.top = new FormAttachment(50, -15); - fd_progressBar.bottom = new FormAttachment(50, +15); - fd_progressBar.left = new FormAttachment(50, -100); - fd_progressBar.right = new FormAttachment(50, +100); - progressBar.setLayoutData(fd_progressBar); - } - - @Override - protected void checkSubclass() { - // Disable the check that prevents subclassing of SWT components - } -} diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/ConfigOpenEnabled.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/ConfigOpenEnabled.java deleted file mode 100644 index a9280624..00000000 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/ConfigOpenEnabled.java +++ /dev/null @@ -1,45 +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.components.main_behavior; - -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.components.MainWindow; - -/** - * - */ -public class ConfigOpenEnabled implements MainWindowBehavior { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(ConfigOpenEnabled.class); - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.components.MainWindowBehavior#SetState(at.asit.pdfover.gui.components.MainWindow) - */ - @Override - public void SetState(MainWindow window) { - log.debug("ENABLING config & open"); - window.getBtn_config().setEnabled(true); - window.getBtn_open().setEnabled(true); - window.getBtn_position().setEnabled(false); - window.getBtn_sign().setEnabled(false); - } -} diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/ConfigOpenPositionEnabled.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/ConfigOpenPositionEnabled.java deleted file mode 100644 index 7e1af1ef..00000000 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/ConfigOpenPositionEnabled.java +++ /dev/null @@ -1,45 +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.components.main_behavior; - -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.components.MainWindow; - -/** - * - */ -public class ConfigOpenPositionEnabled implements MainWindowBehavior { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(ConfigOpenPositionEnabled.class); - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.components.MainWindowBehavior#SetState(at.asit.pdfover.gui.components.MainWindow) - */ - @Override - public void SetState(MainWindow window) { - log.debug("ENABLING config & open & position"); - window.getBtn_config().setEnabled(true); - window.getBtn_open().setEnabled(true); - window.getBtn_position().setEnabled(true); - window.getBtn_sign().setEnabled(false); - } -} diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowAllDisabled.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowAllDisabled.java deleted file mode 100644 index c5b70852..00000000 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowAllDisabled.java +++ /dev/null @@ -1,46 +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.components.main_behavior; - -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.components.MainWindow; - -/** - * - */ -public class MainWindowAllDisabled implements MainWindowBehavior { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(MainWindowAllDisabled.class); - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.components.MainWindowBehavior#SetState(at.asit.pdfover.gui.components.MainWindow) - */ - @Override - public void SetState(MainWindow window) { - log.debug("DISABLING ALL"); - window.getBtn_config().setEnabled(false); - window.getBtn_open().setEnabled(false); - window.getBtn_position().setEnabled(false); - window.getBtn_sign().setEnabled(false); - } - -} diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/OnlyConfigEnabled.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/OnlyConfigEnabled.java deleted file mode 100644 index 2a7e863f..00000000 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/OnlyConfigEnabled.java +++ /dev/null @@ -1,45 +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.components.main_behavior; - -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.components.MainWindow; - -/** - * - */ -public class OnlyConfigEnabled implements MainWindowBehavior { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(OnlyConfigEnabled.class); - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.components.MainWindowBehavior#SetState(at.asit.pdfover.gui.components.MainWindow) - */ - @Override - public void SetState(MainWindow window) { - log.debug("ENABLING ONLY config"); - window.getBtn_config().setEnabled(true); - window.getBtn_open().setEnabled(false); - window.getBtn_position().setEnabled(false); - window.getBtn_sign().setEnabled(false); - } -} diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java index 1296b373..30d7aed8 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java +++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowAllEnable.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java index 91d5237a..3787ef50 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowAllEnable.java +++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java @@ -1,4 +1,3 @@ -package at.asit.pdfover.gui.components.main_behavior; /* * Copyright 2012 by A-SIT, Secure Information Technology Center Austria * @@ -14,33 +13,42 @@ package at.asit.pdfover.gui.components.main_behavior; * 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.components.MainWindow; +import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUs; +import at.asit.pdfover.signator.SignaturePosition; /** * */ -public class MainWindowAllEnable implements MainWindowBehavior { +public class ConfigProviderImpl implements ConfigProvider { /** * SLF4J Logger instance **/ + @SuppressWarnings("unused") private static final Logger log = LoggerFactory - .getLogger(MainWindowAllEnable.class); + .getLogger(ConfigProviderImpl.class); /* (non-Javadoc) - * @see at.asit.pdfover.gui.components.MainWindowBehavior#SetState(at.asit.pdfover.gui.components.MainWindow) + * @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultBKU() */ @Override - public void SetState(MainWindow window) { - log.debug("ENABLING ALL"); - window.getBtn_config().setEnabled(true); - window.getBtn_open().setEnabled(true); - window.getBtn_position().setEnabled(true); - window.getBtn_sign().setEnabled(true); + 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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/StateComposite.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/GUIProvider.java index 0bfd7b87..4e7955fd 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/StateComposite.java +++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/GUIProvider.java @@ -13,20 +13,32 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.components; +package at.asit.pdfover.gui.workflow; + +import org.eclipse.swt.widgets.Composite; -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** - * Composite interface for workflow state gui implementations + * */ -public interface StateComposite { +public interface GUIProvider { + /** + * Get the container Composite + * @return the container Composite + */ + public Composite getComposite(); /** - * Performs layout for all children in composite - * (SWT layout(...) only layouts children no grandchildren!) + * 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 doLayout(); + public void display(final Composite composite); } diff --git a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowBehavior.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSigner.java index b36f6b51..33e8c176 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowBehavior.java +++ b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSigner.java @@ -13,17 +13,31 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.components.main_behavior; +package at.asit.pdfover.gui.workflow; -import at.asit.pdfover.gui.components.MainWindow; +// Imports +import at.asit.pdfover.signator.Signator; +import at.asit.pdfover.signator.Signer; /** * */ -public interface MainWindowBehavior { +public interface PDFSigner { /** - * Changes the state of the main window - * @param window + * Gets the PDF Signer Type + * @return the signer type */ - public void SetState(MainWindow window); + 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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSignerImpl.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PDFSignerImpl.java new file mode 100644 index 00000000..812e6ba0 --- /dev/null +++ b/trunk/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/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 92505d19..1298bda8 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 @@ -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/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 8549007c..bb292c74 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 @@ -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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java index ff06286b..9af0b034 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Status.java +++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java new file mode 100644 index 00000000..9bc4bfec --- /dev/null +++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java index 1d2c5524..86bd50c9 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java +++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java index 2a53dcbc..2d3a31ec 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java +++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java index 169e9e59..c160a524 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java +++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/DataSourceSelectionState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java index 6b69947a..ee90a69b 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/DataSourceSelectionState.java +++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java index 933dd559..8a04dd3f 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java +++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java index 5b764084..c7c92a89 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java +++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java index 45e04dfd..4fa9e362 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java +++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java index efccc5de..061869c1 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java +++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java index 27dd7420..3447fc4c 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java +++ b/trunk/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/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/State.java b/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/State.java index 305c5033..8b9a3ebb 100644 --- a/trunk/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/State.java +++ b/trunk/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(); } |