diff options
Diffstat (limited to 'pdf-over-gui/src')
23 files changed, 1342 insertions, 217 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java index 9c2e584a..dcf596dc 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java @@ -28,7 +28,6 @@ public class DeveloperMain { /** * SFL4J Logger instance **/ - @SuppressWarnings("unused") private static final Logger log = LoggerFactory.getLogger(DeveloperMain.class); /** @@ -40,8 +39,11 @@ public class DeveloperMain { //BasicConfigurator.configure(); Workflow flow = new Workflow(args); + log.debug("Starting workflow ..."); flow.start(); + + log.debug("Ended workflow ..."); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/BKUSelectionComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/BKUSelectionComposite.java new file mode 100644 index 00000000..78ca0d23 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/BKUSelectionComposite.java @@ -0,0 +1,167 @@ +/* + * 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.graphics.Point; +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.Workflow; +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 Workflow workflow; + + 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.workflow.update(); + } + + /** + * Create the composite. + * @param parent + * @param style + */ + public BKUSelectionComposite(Composite parent, int style, Workflow flow) { + super(parent, style); + + this.workflow = flow; + + 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/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/DataSourceSelectComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/DataSourceSelectComposite.java index e6f3e1ba..d5719917 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/DataSourceSelectComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/DataSourceSelectComposite.java @@ -16,9 +16,12 @@ 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; @@ -30,6 +33,9 @@ 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.Workflow; @@ -37,7 +43,40 @@ import at.asit.pdfover.gui.workflow.Workflow; * * */ -public class DataSourceSelectComposite extends Composite implements StateComposite { +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 @@ -46,22 +85,46 @@ public class DataSourceSelectComposite extends Composite implements StateComposi .getLogger(DataSourceSelectComposite.class); private Workflow 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 + * @param flow */ public DataSourceSelectComposite(Composite parent, int style, Workflow 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); @@ -71,8 +134,89 @@ public class DataSourceSelectComposite extends Composite implements StateComposi this.drop_area.setLayoutData(fd_drop_area); this.drop_area.setLayout(new FormLayout()); this.drop_area.setBackground(back); - - final Label lbl_drag = new Label(this.drop_area, SWT.NONE | SWT.RESIZE ); + + 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); @@ -81,13 +225,12 @@ public class DataSourceSelectComposite extends Composite implements StateComposi 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.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 ); + + 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(); @@ -97,28 +240,25 @@ public class DataSourceSelectComposite extends Composite implements StateComposi 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 - - } - });*/ + + /* + * 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; @@ -136,13 +276,16 @@ public class DataSourceSelectComposite extends Composite implements StateComposi } /** - * @param press the press to set + * @param press + * the press to set */ public void setPress(boolean press) { this.press = press; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.components.StateComposite#doLayout() */ @Override diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java index 704a2440..731c5f57 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/MainWindow.java @@ -16,8 +16,6 @@ package at.asit.pdfover.gui.components; // Imports -import javax.swing.GroupLayout; - import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; @@ -28,9 +26,31 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormAttachment; +import java.lang.Class; +import java.util.HashMap; +import java.util.Map; + +import at.asit.pdfover.gui.components.main_behavior.ConfigOpenEnabled; +import at.asit.pdfover.gui.components.main_behavior.ConfigOpenPositionEnabled; +import at.asit.pdfover.gui.components.main_behavior.MainWindowAllDisabled; +import at.asit.pdfover.gui.components.main_behavior.MainWindowBehavior; +import at.asit.pdfover.gui.components.main_behavior.OnlyConfigEnabled; +import at.asit.pdfover.gui.workflow.Workflow; +import at.asit.pdfover.gui.workflow.WorkflowState; +import at.asit.pdfover.gui.workflow.states.BKUSelectionState; +import at.asit.pdfover.gui.workflow.states.DataSourceSelectionState; +import at.asit.pdfover.gui.workflow.states.LocalBKUState; +import at.asit.pdfover.gui.workflow.states.MobileBKUState; +import at.asit.pdfover.gui.workflow.states.OutputState; +import at.asit.pdfover.gui.workflow.states.PositioningState; +import at.asit.pdfover.gui.workflow.states.PrepareConfigurationState; +import at.asit.pdfover.gui.workflow.states.PrepareSigningState; +import at.asit.pdfover.gui.workflow.states.SigningState; /** * The Main Window of PDFOver 4.0 @@ -38,6 +58,29 @@ import org.eclipse.swt.layout.FormAttachment; public class MainWindow { /** + * + */ + private final class DataSourceSelectionListener implements + SelectionListener { + /** + * + */ + public DataSourceSelectionListener() { + // Nothing to do here + } + + @Override + public void widgetSelected(SelectionEvent e) { + MainWindow.this.workflow.setWorkflowState(new DataSourceSelectionState()); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // Nothing to do here + } + } + + /** * SFL4J Logger instance **/ private static final Logger log = LoggerFactory.getLogger(MainWindow.class); @@ -45,12 +88,81 @@ public class MainWindow { private CLabel lbl_status; private Composite container; private StackLayout stack; + private Workflow workflow; + private Button btn_sign; + + /** + * Gets the sign button + * @return the sign button + */ + public Button getBtn_sign() { + return this.btn_sign; + } + + private Button btn_position; + + /** + * Gets the position button + * @return the position button + */ + public Button getBtn_position() { + return this.btn_position; + } + + private Button btn_open; + + /** + * Gets the open button + * @return the open button + */ + public Button getBtn_open() { + return this.btn_open; + } + + private Button btn_config; + + /** + * Gets the config button + * @return the config button + */ + public Button getBtn_config() { + return this.btn_config; + } + + private Map<Class, MainWindowBehavior> behavior = new HashMap<Class, MainWindowBehavior>(); + + /** + * Default contsructor + * @param workflow The main workflow + */ + public MainWindow(Workflow workflow) { + super(); + + this.behavior.put(PrepareConfigurationState.class, new MainWindowAllDisabled()); + this.behavior.put(PrepareSigningState.class, new MainWindowAllDisabled()); + this.behavior.put(SigningState.class, new MainWindowAllDisabled()); + this.behavior.put(LocalBKUState.class, new MainWindowAllDisabled()); + this.behavior.put(MobileBKUState.class, new MainWindowAllDisabled()); + + this.behavior.put(OutputState.class, new MainWindowAllDisabled()); + + this.behavior.put(DataSourceSelectionState.class, new OnlyConfigEnabled()); + + this.behavior.put(PositioningState.class, new ConfigOpenEnabled()); + + this.behavior.put(BKUSelectionState.class, new ConfigOpenPositionEnabled()); + + this.workflow = workflow; + } /** * Set current status (may be removed in production release) * @param value */ public void setStatus(String value) { + if(this.getShell().isDisposed()) { + return; + } this.lbl_status.setText("[DEBUG]: Current workflow state: " + value); } @@ -61,6 +173,14 @@ public class MainWindow { public void setTopControl(Control ctrl) { log.debug("Top control: " + ctrl.toString()); this.stack.topControl = ctrl; + this.doLayout(); + } + + /** + * Layout the Main Window + */ + public void doLayout() { + Control ctrl = this.stack.topControl; this.container.layout(true, true); this.shell.layout(true, true); // Note: SWT only layouts children! No grandchildren! @@ -84,7 +204,7 @@ public class MainWindow { public static void main(String[] args) { Display display = Display.getDefault(); - MainWindow window = new MainWindow(); + MainWindow window = new MainWindow(null); window.open(); @@ -126,41 +246,42 @@ public class MainWindow { composite.setLayoutData(fd_composite); composite.setLayout(new FormLayout()); - Button btn_config = new Button(composite, SWT.NONE); + this.btn_config = new Button(composite, SWT.NONE); FormData fd_config = new FormData(); fd_config.left = new FormAttachment(0, 0); fd_config.right = new FormAttachment(25, 0); fd_config.top = new FormAttachment(0, 0); fd_config.bottom = new FormAttachment(100, 0); - btn_config.setLayoutData(fd_config); - btn_config.setText("Config ..."); + this.btn_config.setLayoutData(fd_config); + this.btn_config.setText("Config ..."); - Button btn_open = new Button(composite, SWT.NONE); + this.btn_open = new Button(composite, SWT.NONE); FormData fd_open = new FormData(); fd_open.left = new FormAttachment(25, 0); fd_open.right = new FormAttachment(50, 0); fd_open.top = new FormAttachment(0, 0); fd_open.bottom = new FormAttachment(100, 0); - btn_open.setLayoutData(fd_open); - btn_open.setText("Open ..."); + this.btn_open.setLayoutData(fd_open); + this.btn_open.setText("Open ..."); + this.btn_open.addSelectionListener(new DataSourceSelectionListener()); - Button btn_position = new Button(composite, SWT.NONE); + this.btn_position = new Button(composite, SWT.NONE); FormData fd_position = new FormData(); fd_position.left = new FormAttachment(50, 0); fd_position.right = new FormAttachment(75, 0); fd_position.top = new FormAttachment(0, 0); fd_position.bottom = new FormAttachment(100, 0); - btn_position.setLayoutData(fd_position); - btn_position.setText("Positon ..."); + this.btn_position.setLayoutData(fd_position); + this.btn_position.setText("Positon ..."); - Button btn_sign = new Button(composite, SWT.NONE); + this.btn_sign = new Button(composite, SWT.NONE); FormData fd_sign = new FormData(); fd_sign.left = new FormAttachment(75, 0); fd_sign.right = new FormAttachment(100, 0); fd_sign.top = new FormAttachment(0, 0); fd_sign.bottom = new FormAttachment(100, 0); - btn_sign.setLayoutData(fd_sign); - btn_sign.setText("Sign ..."); + this.btn_sign.setLayoutData(fd_sign); + this.btn_sign.setText("Sign ..."); this.container = new Composite(getShell(), SWT.BORDER | SWT.RESIZE); FormData fd_composite_1 = new FormData(); @@ -184,6 +305,19 @@ public class MainWindow { } /** + * Update MainWindow to fit new status + */ + public void UpdateNewState() { + WorkflowState state = this.workflow.getState(); + + log.debug("Updating MainWindow state for : " + state.toString()); + + if(this.behavior.containsKey(state.getClass())) { + this.behavior.get(state.getClass()).SetState(this); + } + } + + /** * @return the shell */ public Shell getShell() { diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/PositioningComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/PositioningComposite.java index 79cbbc68..7c1d4d06 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/PositioningComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/PositioningComposite.java @@ -17,12 +17,16 @@ 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.Workflow; +import at.asit.pdfover.signator.SignaturePosition; /** * @@ -31,11 +35,56 @@ import at.asit.pdfover.gui.workflow.Workflow; 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 Workflow 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 @@ -43,9 +92,17 @@ public class PositioningComposite extends Composite implements StateComposite { */ public PositioningComposite(Composite parent, int style, Workflow workflow) { super(parent, style); + + this.workflow = workflow; + Label test = new Label(this, SWT.NATIVE); - test.setBounds(10, 20, 100, 50); - test.setText("POSITIONING ----"); + 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 diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/WaitingComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/WaitingComposite.java new file mode 100644 index 00000000..371d5e26 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/WaitingComposite.java @@ -0,0 +1,66 @@ +/* + * 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.Workflow; + +/** + * + */ +public class WaitingComposite extends Composite { + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(WaitingComposite.class); + + private Workflow workflow; + + /** + * Create the composite. + * @param parent + * @param style + */ + public WaitingComposite(Composite parent, int style, Workflow 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/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/ConfigOpenEnabled.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/ConfigOpenEnabled.java new file mode 100644 index 00000000..a9280624 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/ConfigOpenEnabled.java @@ -0,0 +1,45 @@ +/* + * 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/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/ConfigOpenPositionEnabled.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/ConfigOpenPositionEnabled.java new file mode 100644 index 00000000..7e1af1ef --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/ConfigOpenPositionEnabled.java @@ -0,0 +1,45 @@ +/* + * 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/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowAllDisabled.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowAllDisabled.java new file mode 100644 index 00000000..c5b70852 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowAllDisabled.java @@ -0,0 +1,46 @@ +/* + * 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/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowAllEnable.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowAllEnable.java new file mode 100644 index 00000000..91d5237a --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowAllEnable.java @@ -0,0 +1,46 @@ +package at.asit.pdfover.gui.components.main_behavior; +/* + * 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. + */ + +// Imports +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.gui.components.MainWindow; + +/** + * + */ +public class MainWindowAllEnable implements MainWindowBehavior { + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(MainWindowAllEnable.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 ALL"); + window.getBtn_config().setEnabled(true); + window.getBtn_open().setEnabled(true); + window.getBtn_position().setEnabled(true); + window.getBtn_sign().setEnabled(true); + } + +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowBehavior.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowBehavior.java new file mode 100644 index 00000000..b36f6b51 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/MainWindowBehavior.java @@ -0,0 +1,29 @@ +/* + * 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; + +import at.asit.pdfover.gui.components.MainWindow; + +/** + * + */ +public interface MainWindowBehavior { + /** + * Changes the state of the main window + * @param window + */ + public void SetState(MainWindow window); +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/OnlyConfigEnabled.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/OnlyConfigEnabled.java new file mode 100644 index 00000000..2a7e863f --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/components/main_behavior/OnlyConfigEnabled.java @@ -0,0 +1,45 @@ +/* + * 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/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Workflow.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Workflow.java index 83fca283..48e57f50 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Workflow.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/Workflow.java @@ -18,19 +18,24 @@ package at.asit.pdfover.gui.workflow; //Imports import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import java.io.File; import java.util.Properties; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import at.asit.pdfover.gui.components.MainWindow; +import at.asit.pdfover.gui.workflow.states.BKUSelectionState; +import at.asit.pdfover.gui.workflow.states.DataSourceSelectionState; +import at.asit.pdfover.gui.workflow.states.PositioningState; import at.asit.pdfover.gui.workflow.states.PrepareConfigurationState; +import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUS; +import at.asit.pdfover.signator.Signator; +import at.asit.pdfover.signator.SignatureParameter; +import at.asit.pdfover.signator.Signer; /** * Workflow holds logical state of signing process and updates the current @@ -41,7 +46,6 @@ public class Workflow { /** * SFL4J Logger instance **/ - @SuppressWarnings("unused") private static final Logger log = LoggerFactory.getLogger(Workflow.class); /** @@ -70,35 +74,45 @@ public class Workflow { return this.state; } - private String[] cmdLineArgs = new String[] {}; - - /** - * sets the command line arguments - * - * @param cmdLineArgs - */ - private void setCmdLineAargs(String[] cmdLineArgs) { - this.cmdLineArgs = cmdLineArgs; - } - /** - * Gets the command line arguments + * 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 * - * @return the command line arguments + * @param state */ - public String[] cetCmdArgs() { - return this.cmdLineArgs; - } + public void setWorkflowState(WorkflowState state) { + if (this.state != state && state != null) { + this.state = state; - private Properties persistentState = new Properties(); + if (state instanceof PositioningState) { + // User jumps to positioning state ! + // restore possible default for bku selection / forget BKU + // selection + this.setSelectedBKU(PrepareConfigurationState + .readSelectedBKU(this.getConfigurationValues())); + // forget position + this.getParameter().setSignaturePosition(null); + } else if (state instanceof BKUSelectionState) { + // User jumps to bku selection state ! + // forget bku selection + this.setSelectedBKU(BKUS.NONE); + } else if (state instanceof DataSourceSelectionState) { + // User jumps to data source selection state ! + // forget bku selection / restore possible default for bku + // selection + this.setSelectedBKU(PrepareConfigurationState + .readSelectedBKU(this.getConfigurationValues())); + // forget position / restore possible default for position + this.getParameter().setSignaturePosition( + PrepareConfigurationState.readDefinedPosition(this + .getConfigurationValues())); + // forget data source selection + this.setDataSource(null); + } - /** - * Gets the persistent state - * - * @return the persistent state - */ - public Properties getPersistentState() { - return this.persistentState; + this.update(); + } } /** @@ -108,11 +122,18 @@ public class Workflow { WorkflowState next = null; while (this.state != null) { this.state.update(this); + if (this.mainWindow != null && !this.mainWindow.getShell().isDisposed()) { + log.debug("Allowing MainWindow to update its state for " + this.state.toString()); + this.mainWindow.UpdateNewState(); + this.mainWindow.doLayout(); + } next = this.state.nextState(); if (next == this.state) { break; } - //this.state.hideGUI(); + // this.state.hideGUI(); + log.debug("Changing state from: " + this.state.toString() + " to " + + next.toString()); this.state = next; } if (this.state != null) { @@ -122,6 +143,21 @@ public class Workflow { } } + /** + * Invoke Update in UI (Main) Thread + */ + public void InvokeUpdate() { + if(this.display != null) { + this.display.asyncExec(new Runnable() { + + @Override + public void run() { + Workflow.this.update(); + } + }); + } + } + private Display display = null; private Shell shell = null; @@ -129,21 +165,21 @@ public class Workflow { private Composite container = null; private MainWindow mainWindow = null; - - private final StackLayout stack = new StackLayout(); /** * Helper method for developing + * * @param value */ public void setCurrentStateMessage(String value) { - if(this.mainWindow != null) { + if (this.mainWindow != null) { this.mainWindow.setStatus(value); } } - + /** * Used by active workflow state to show its own gui component + * * @param ctrl */ public void setTopControl(final Control ctrl) { @@ -152,15 +188,15 @@ public class Workflow { private void createMainWindow() { this.display = Display.getDefault(); - - this.mainWindow = new MainWindow(); - + + this.mainWindow = new MainWindow(this); + this.mainWindow.open(); - + this.shell = this.mainWindow.getShell(); - + this.container = this.mainWindow.getContainer(); - + this.shell.open(); this.shell.layout(); } @@ -195,6 +231,13 @@ public class Workflow { } /** + * Exists the Workflow + */ + public void exitWorkflow() { + this.shell.dispose(); + } + + /** * Only returns a shell if one was already created ... * * @return @@ -224,4 +267,144 @@ public class Workflow { } } + // Data Section + // ============================================================================= + + // Command Line Arguments + // ------------------------------------------------------- + private String[] cmdLineArgs = new String[] {}; + + /** + * sets the command line arguments + * + * @param cmdLineArgs + */ + private void setCmdLineAargs(String[] cmdLineArgs) { + this.cmdLineArgs = cmdLineArgs; + } + + /** + * Gets the command line arguments + * + * @return the command line arguments + */ + public String[] getCmdArgs() { + return this.cmdLineArgs; + } + + // Key Value String properties + // ------------------------------------------------------- + private Properties configurationValues = new Properties(); + + /** + * Gets the persistent state + * + * @return the persistent state + */ + public Properties getConfigurationValues() { + return this.configurationValues; + } + + // Data source + // ------------------------------------------------------- + private File dataSource = null; + + /** + * Gets the DataSource + * + * @return The data source file + */ + public File getDataSource() { + return this.dataSource; + } + + /** + * Sets the DataSource + * + * @param file + */ + public void setDataSource(File file) { + this.dataSource = file; + } + + // Selected BKU + // ------------------------------------------------------- + + /** + * The selected BKU + */ + private BKUS selectedBKU = BKUS.NONE; + + /** + * Gets the selected BKU + * + * @return the selectedBKU + */ + public BKUS getSelectedBKU() { + return this.selectedBKU; + } + + /** + * Sets the selected BKU + * + * @param selectedBKU + * the selectedBKU to set + */ + public void setSelectedBKU(BKUS selectedBKU) { + this.selectedBKU = selectedBKU; + } + + private Signator.Signers usedSignerLib = Signator.Signers.PDFAS; + + /** + * The PDF Signer + */ + private Signer pdfSigner = null; + + /** + * @return the pdfSigner + */ + public Signer getPdfSigner() { + return this.pdfSigner; + } + + /** + * @param pdfSigner + * the pdfSigner to set + */ + public void setPdfSigner(Signer pdfSigner) { + this.pdfSigner = pdfSigner; + } + + private SignatureParameter parameter = null; + + /** + * @return the parameter + */ + public SignatureParameter getParameter() { + return this.parameter; + } + + /** + * @param parameter + * the parameter to set + */ + public void setParameter(SignatureParameter parameter) { + this.parameter = parameter; + } + + /** + * @return the usedSignerLib + */ + public Signator.Signers getUsedSignerLib() { + return usedSignerLib; + } + + /** + * @param usedSignerLib + * the usedSignerLib to set + */ + public void setUsedSignerLib(Signator.Signers usedSignerLib) { + this.usedSignerLib = usedSignerLib; + } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/WorkflowState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/WorkflowState.java index ed0c1fc2..831c4394 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/WorkflowState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/WorkflowState.java @@ -60,9 +60,4 @@ public abstract class WorkflowState { * @param workflow */ public abstract void update(Workflow workflow); - - /** - * Hide the GUI components created in the state - */ - public abstract void hideGUI(); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java index fdd160ac..2bd3361d 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java @@ -16,8 +16,11 @@ package at.asit.pdfover.gui.workflow.states; //Imports +import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import at.asit.pdfover.gui.components.BKUSelectionComposite; import at.asit.pdfover.gui.workflow.Workflow; import at.asit.pdfover.gui.workflow.WorkflowState; @@ -27,25 +30,64 @@ import at.asit.pdfover.gui.workflow.WorkflowState; public class BKUSelectionState extends WorkflowState { /** + * Enumeration of available BKU type + */ + public enum BKUS { + /** + * Local bku + */ + LOCAL, + + /** + * Mobile bku + */ + MOBILE, + + /** + * None bku + */ + NONE + } + + /** * SFL4J Logger instance **/ @SuppressWarnings("unused") private static final Logger log = LoggerFactory.getLogger(BKUSelectionState.class); + private BKUSelectionComposite selectionComposite = null; + + private BKUSelectionComposite getSelectionComposite(Workflow workflow) { + if (this.selectionComposite == null) { + this.selectionComposite = new BKUSelectionComposite( + workflow.getComposite(), SWT.RESIZE, workflow); + } + + return this.selectionComposite; + } + @Override public void update(Workflow workflow) { - // TODO Auto-generated method stub - this.setNextState(state) - } + if(workflow.getSelectedBKU() == BKUS.NONE) { + BKUSelectionComposite selection = this + .getSelectionComposite(workflow); - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.WorkflowState#hideGUI() - */ - @Override - public void hideGUI() { - // TODO Auto-generated method stub + workflow.setTopControl(selection); + selection.layout(); + + workflow.setSelectedBKU(selection.getSelected()); + if(workflow.getSelectedBKU() == BKUS.NONE) { + this.setNextState(this); + return; + } + } + this.setNextState(new PrepareSigningState()); + } + + @Override + public String toString() { + return "BKUSelectionState"; } - } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/DataSourceSelectionState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/DataSourceSelectionState.java index 223ba17d..10492dfe 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/DataSourceSelectionState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/DataSourceSelectionState.java @@ -16,10 +16,9 @@ package at.asit.pdfover.gui.workflow.states; //Imports +import java.io.File; + import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,59 +34,47 @@ public class DataSourceSelectionState extends WorkflowState { /** * SFL4J Logger instance **/ - @SuppressWarnings("unused") - private static final Logger log = LoggerFactory.getLogger(DataSourceSelectionState.class); - + private static final Logger log = LoggerFactory + .getLogger(DataSourceSelectionState.class); + private DataSourceSelectComposite selectionComposite = null; - + private DataSourceSelectComposite getSelectionComposite(Workflow workflow) { - if(this.selectionComposite == null) { - this.selectionComposite = new DataSourceSelectComposite(workflow.getComposite(), SWT.RESIZE, workflow); + if (this.selectionComposite == null) { + this.selectionComposite = new DataSourceSelectComposite( + workflow.getComposite(), SWT.RESIZE, workflow); } - + return this.selectionComposite; } - + @Override public void update(Workflow workflow) { - DataSourceSelectComposite selection = this.getSelectionComposite(workflow); - - workflow.setTopControl(selection); - selection.layout(); - - if(selection.isPress()) { - this.setNextState(new PositioningState()); - } else { - this.setNextState(this); - } - } - private void recursiveHide(Control ctrl) { - if(ctrl instanceof Composite) { - Composite comp = (Composite)ctrl; - Control[] childs = comp.getChildren(); - for(int i = 0; i < childs.length; i++) { - this.recursiveHide(childs[i]); + if (workflow.getDataSource() == null) { + DataSourceSelectComposite selection = this + .getSelectionComposite(workflow); + + workflow.setTopControl(selection); + selection.layout(); + + File source = selection.getSelected(); + if(source != null) { + workflow.setDataSource(source); } + + if (workflow.getDataSource() == null) { + // Not selected yet + this.setNextState(this); + return; + } } - ctrl.setVisible(false); + log.debug("Got Datasource: " + workflow.getDataSource().getAbsolutePath()); + this.setNextState(new PositioningState()); } - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.WorkflowState#hideGUI() - */ @Override - public void hideGUI() { - /*if(this.selectionComposite != null) { - Shell shell = this.selectionComposite.getShell(); - Composite comp = this.selectionComposite.getParent(); - recursiveHide(this.selectionComposite); - this.selectionComposite.layout(); - //this.selectionComposite.setVisible(false); - comp.layout(); - //shell.pack(true); - shell.layout(true); - }*/ + public String toString() { + return "DataSourceSelectionState"; } - } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java index 5f3a00d5..aa352be7 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java @@ -37,17 +37,13 @@ public class LocalBKUState extends WorkflowState { */ @Override public void update(Workflow workflow) { - // TODO Auto-generated method stub + // TODO Process SL Request and set SL Response + this.setNextState(new SigningState()); } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.WorkflowState#hideGUI() - */ + @Override - public void hideGUI() { - // TODO Auto-generated method stub - + public String toString() { + return "LocalBKUState"; } - } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java index 9d88ce0c..643abd45 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java @@ -37,17 +37,14 @@ public class MobileBKUState extends WorkflowState { */ @Override public void update(Workflow workflow) { - // TODO Auto-generated method stub + // TODO Process SL Request and set SL Response + + this.setNextState(new SigningState()); } - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.WorkflowState#hideGUI() - */ @Override - public void hideGUI() { - // TODO Auto-generated method stub - + public String toString() { + return "MobileBKUState"; } - } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java index 44d9a55f..d7df5c19 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java @@ -34,17 +34,14 @@ public class OutputState extends WorkflowState { @Override public void update(Workflow workflow) { - // TODO Auto-generated method stub + // TODO Preform output operations ... end workflow + workflow.exitWorkflow(); } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.WorkflowState#hideGUI() - */ + @Override - public void hideGUI() { - // TODO Auto-generated method stub - + public String toString() { + return "OutputState"; } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java index 9841ffce..180b98d9 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java @@ -49,23 +49,24 @@ public class PositioningState extends WorkflowState { @Override public void update(Workflow workflow) { - // TODO Auto-generated method stub - PositioningComposite position = this.getPositioningComosite(workflow); - - workflow.setTopControl(position); + if(workflow.getParameter().getSignaturePosition() == null) { + PositioningComposite position = this.getPositioningComosite(workflow); + + workflow.setTopControl(position); + + workflow.getParameter().setSignaturePosition(position.getPosition()); + + if(workflow.getParameter().getSignaturePosition() == null) { + this.setNextState(this); + return; + } + } this.setNextState(new BKUSelectionState()); } - /* - * (non-Javadoc) - * - * @see at.asit.pdfover.gui.workflow.WorkflowState#hideGUI() - */ @Override - public void hideGUI() { - // TODO Auto-generated method stub - + public String toString() { + return "PositioningState"; } - } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java index b90f38db..91ebf01b 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java @@ -16,10 +16,15 @@ 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.Workflow; import at.asit.pdfover.gui.workflow.WorkflowState; +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 @@ -28,24 +33,65 @@ import at.asit.pdfover.gui.workflow.WorkflowState; */ public class PrepareConfigurationState extends WorkflowState { + public final static String BKU_SELECTION_CONFIG = "DEFAULT_BKU"; + /** * SFL4J Logger instance **/ @SuppressWarnings("unused") - private static final Logger log = LoggerFactory.getLogger(PrepareConfigurationState.class); - + private static final Logger log = LoggerFactory + .getLogger(PrepareConfigurationState.class); + @Override public void update(Workflow workflow) { + // TODO: Read config file and command line arguments + // Set usedSignerLib ... + + // Create PDF Signer + workflow.setPdfSigner(Signator.getSigner(workflow.getUsedSignerLib())); + + workflow.setParameter(workflow.getPdfSigner().newParameter()); + + workflow.setSelectedBKU(PrepareConfigurationState.readSelectedBKU(workflow.getConfigurationValues())); + + workflow.getParameter().setSignaturePosition(readDefinedPosition(workflow.getConfigurationValues())); + this.setNextState(new DataSourceSelectionState()); } - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.WorkflowState#hideGUI() - */ @Override - public void hideGUI() { - // TODO Auto-generated method stub - + public String toString() { + return "PrepareConfigurationState"; } + /** + * 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; + } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java index a18dc389..f1c291f8 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java @@ -16,10 +16,14 @@ package at.asit.pdfover.gui.workflow.states; //Imports +import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import at.asit.pdfover.gui.components.WaitingComposite; import at.asit.pdfover.gui.workflow.Workflow; import at.asit.pdfover.gui.workflow.WorkflowState; +import at.asit.pdfover.gui.workflow.states.BKUSelectionState.BKUS; /** * User waiting state, wait for PDF Signator library to prepare document for signing. @@ -27,24 +31,80 @@ import at.asit.pdfover.gui.workflow.WorkflowState; public class PrepareSigningState extends WorkflowState { /** + * Debug background thread + */ + private final class DebugSleeperThread implements Runnable { + + private Workflow workflow; + + /** + * Default constructor + * @param work + */ + public DebugSleeperThread(Workflow work) { + this.workflow = work; + } + + @Override + public void run() { + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + this.workflow.InvokeUpdate(); + } + } + + /** * SFL4J Logger instance **/ - @SuppressWarnings("unused") private static final Logger log = LoggerFactory.getLogger(PrepareSigningState.class); + private WaitingComposite selectionComposite = null; + + private WaitingComposite getSelectionComposite(Workflow workflow) { + if (this.selectionComposite == null) { + this.selectionComposite = new WaitingComposite( + workflow.getComposite(), SWT.RESIZE, workflow); + } + + return this.selectionComposite; + } + + private boolean run = false; + @Override public void update(Workflow workflow) { - // TODO Auto-generated method stub + // TODO SHOW BACKGROUND ACTIVITY .... + WaitingComposite waiting = this.getSelectionComposite(workflow); + + workflow.setTopControl(waiting); + + if(!this.run) { + Thread t = new Thread(new DebugSleeperThread(workflow)); + this.run = true; + t.start(); + return; + } + // 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()); + } else { + log.error("Invalid selected BKU Value \"NONE\" in PrepareSigningState!"); + this.setNextState(new BKUSelectionState()); + } } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.WorkflowState#hideGUI() - */ + @Override - public void hideGUI() { - // TODO Auto-generated method stub - + public String toString() { + return "PrepareSigningState"; } - + + } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java index 2305c1c6..8b9a5475 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java @@ -34,17 +34,13 @@ public class SigningState extends WorkflowState { @Override public void update(Workflow workflow) { - // TODO Auto-generated method stub + // TODO Wait until output ready and set output + this.setNextState(new OutputState()); } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.WorkflowState#hideGUI() - */ + @Override - public void hideGUI() { - // TODO Auto-generated method stub - + public String toString() { + return "SigningState"; } - } |