diff options
author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-07-06 14:40:26 +0200 |
---|---|---|
committer | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-07-06 14:40:26 +0200 |
commit | 6f27ed0949dea874e89dcab40ec66a68fa50b362 (patch) | |
tree | 6dc8aefaaf04c3bafece8aff28c4ea5cf51708eb /pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow | |
parent | 1ac8a347bcabcd1b9c6ca70c6aacaf6ae9f661eb (diff) | |
download | pdf-over-6f27ed0949dea874e89dcab40ec66a68fa50b362.tar.gz pdf-over-6f27ed0949dea874e89dcab40ec66a68fa50b362.tar.bz2 pdf-over-6f27ed0949dea874e89dcab40ec66a68fa50b362.zip |
YAGNI: StateMachine getters
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow')
13 files changed, 131 insertions, 168 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java index 5a1248d7..68eeb78b 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java @@ -44,11 +44,10 @@ public class StateMachine implements GUIProvider { private static final Logger log = LoggerFactory.getLogger(StateMachine.class); - private Status status; - - private PDFSigner pdfSigner; - - private ConfigProviderImpl configProvider; + public final Status status; + public final PDFSigner pdfSigner; + public final ConfigProviderImpl configProvider; + public final String[] cmdLineArgs; /** * Default constructor @@ -60,7 +59,7 @@ public class StateMachine implements GUIProvider { this.status.setCurrentState(new PrepareConfigurationState(this)); this.pdfSigner = new PDFSigner(); this.configProvider = new ConfigProviderImpl(); - setCmdLineArgs(cmdLineArgs); + this.cmdLineArgs = cmdLineArgs; } /** @@ -268,37 +267,6 @@ public class StateMachine implements GUIProvider { display.dispose(); } } - public ConfigProvider getConfigProvider() { - return this.configProvider; - } - public PersistentConfigProvider getPersistentConfigProvider() { - return this.configProvider; - } - public ConfigManipulator getConfigManipulator() { - return this.configProvider; - } - public ConfigOverlayManipulator getConfigOverlayManipulator() { - return this.configProvider; - } - public Status getStatus() { - return this.status; - } - - public PDFSigner getPDFSigner() { - return this.pdfSigner; - } - - public GUIProvider getGUIProvider() { - return this; - } - - private String[] cmdLineArgs = new String[] {}; - private void setCmdLineArgs(String[] cmdLineArgs) { - this.cmdLineArgs = cmdLineArgs; - } - public String[] getCmdArgs() { - return this.cmdLineArgs; - } public synchronized Shell getMainShell() { 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 dcffe2c0..01df1863 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 @@ -53,11 +53,11 @@ public class BKUSelectionState extends State { private BKUSelectionComposite getSelectionComposite() { if (this.selectionComposite == null) { this.selectionComposite = - getStateMachine().getGUIProvider().createComposite(BKUSelectionComposite.class, SWT.RESIZE, this); + getStateMachine().createComposite(BKUSelectionComposite.class, SWT.RESIZE, this); } - if (getStateMachine().getConfigProvider().getKeyStoreEnabled()) { - File ks = new File(getStateMachine().getConfigProvider().getKeyStoreFile()); + if (getStateMachine().configProvider.getKeyStoreEnabled()) { + File ks = new File(getStateMachine().configProvider.getKeyStoreFile()); this.selectionComposite.setKeystoreEnabled(ks.exists()); } else this.selectionComposite.setKeystoreEnabled(false); @@ -67,7 +67,7 @@ public class BKUSelectionState extends State { @Override public void run() { - Status status = getStateMachine().getStatus(); + Status status = getStateMachine().status; State previousState = status.getPreviousState(); if (!( (previousState instanceof OpenState) || @@ -76,14 +76,14 @@ public class BKUSelectionState extends State { )) { status.bku = BKUs.NONE; } else if(!(status.getPreviousState() instanceof BKUSelectionState)) { - ConfigProvider config = getStateMachine().getConfigProvider(); + ConfigProvider config = getStateMachine().configProvider; status.bku = config.getDefaultBKU(); } if(status.bku == BKUs.NONE) { BKUSelectionComposite selection = this.getSelectionComposite(); - getStateMachine().getGUIProvider().display(selection); + getStateMachine().display(selection); selection.layout(); status.bku = selection.getSelected(); @@ -109,7 +109,7 @@ public class BKUSelectionState extends State { */ @Override public void updateMainWindowBehavior() { - MainWindowBehavior behavior = getStateMachine().getStatus().behavior; + MainWindowBehavior behavior = getStateMachine().status.behavior; behavior.reset(); behavior.setEnabled(Buttons.CONFIG, true); behavior.setEnabled(Buttons.OPEN, true); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java index 8450629f..1e02893a 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java @@ -44,10 +44,10 @@ public class ConfigurationUIState extends State { private ConfigurationComposite getConfigurationComposite() { if (this.configurationComposite == null) { this.configurationComposite = - getStateMachine().getGUIProvider().createComposite(ConfigurationComposite.class, SWT.RESIZE, this); - this.configurationComposite.setConfigManipulator(getStateMachine().getConfigManipulator()); - this.configurationComposite.setConfigProvider(getStateMachine().getPersistentConfigProvider()); - this.configurationComposite.setSigner(getStateMachine().getPDFSigner()); + getStateMachine().createComposite(ConfigurationComposite.class, SWT.RESIZE, this); + this.configurationComposite.setConfigManipulator(getStateMachine().configProvider); + this.configurationComposite.setConfigProvider(getStateMachine().configProvider); + this.configurationComposite.setSigner(getStateMachine().pdfSigner); } return this.configurationComposite; @@ -66,11 +66,11 @@ public class ConfigurationUIState extends State { */ @Override public void run() { - Status status = getStateMachine().getStatus(); + Status status = getStateMachine().status; ConfigurationComposite config = this.getConfigurationComposite(); - getStateMachine().getGUIProvider().display(config); + getStateMachine().display(config); if(config.isUserDone()) { @@ -96,7 +96,7 @@ public class ConfigurationUIState extends State { @Override public void updateMainWindowBehavior() { // Leave the state as it is - MainWindowBehavior behavior = getStateMachine().getStatus().behavior; + MainWindowBehavior behavior = getStateMachine().status.behavior; behavior.setEnabled(Buttons.CONFIG, false); behavior.setMainBarVisible(false); } @@ -105,6 +105,6 @@ public class ConfigurationUIState extends State { * Triggers to reload the resources */ public void reloadResources() { - getStateMachine().getGUIProvider().reloadResources(); + getStateMachine().reloadResources(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/KSState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/KSState.java index 1ecf880c..94171262 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/KSState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/KSState.java @@ -61,10 +61,10 @@ public class KSState extends State { */ @Override public void run() { - Status status = getStateMachine().getStatus(); + Status status = getStateMachine().status; SigningState signingState = status.signingState; - ConfigProvider config = getStateMachine().getConfigProvider(); + ConfigProvider config = getStateMachine().configProvider; try { String file = config.getKeyStoreFile(); @@ -72,7 +72,7 @@ public class KSState extends State { if (!f.isFile()) { log.error("Keystore not found"); ErrorDialog dialog = new ErrorDialog( - getStateMachine().getGUIProvider().getMainShell(), + getStateMachine().getMainShell(), String.format(Messages.getString("error.KeyStoreFileNotExist"), f.getName()), BUTTONS.RETRY_CANCEL); if (dialog.open() != SWT.RETRY) { @@ -87,7 +87,7 @@ public class KSState extends State { String storePass = config.getKeyStoreStorePass(); if (storePass.isEmpty()) { PasswordInputDialog pwd = new PasswordInputDialog( - getStateMachine().getGUIProvider().getMainShell(), + getStateMachine().getMainShell(), Messages.getString("keystore_config.KeystoreStorePass"), Messages.getString("keystore.KeystoreStorePassEntry")); storePass = pwd.open(); @@ -95,7 +95,7 @@ public class KSState extends State { String keyPass = config.getKeyStoreKeyPass(); if (keyPass.isEmpty()) { PasswordInputDialog pwd = new PasswordInputDialog( - getStateMachine().getGUIProvider().getMainShell(), + getStateMachine().getMainShell(), Messages.getString("keystore_config.KeystoreKeyPass"), Messages.getString("keystore.KeystoreKeyPassEntry")); keyPass = pwd.open(); @@ -105,7 +105,7 @@ public class KSState extends State { } catch (SignatureException e) { log.error("Error loading keystore", e); ErrorDialog dialog = new ErrorDialog( - getStateMachine().getGUIProvider().getMainShell(), + getStateMachine().getMainShell(), Messages.getString("error.KeyStore"), BUTTONS.RETRY_CANCEL); if (dialog.open() != SWT.RETRY) { @@ -138,7 +138,7 @@ public class KSState extends State { */ @Override public void updateMainWindowBehavior() { - MainWindowBehavior behavior = getStateMachine().getStatus().behavior; + MainWindowBehavior behavior = getStateMachine().status.behavior; behavior.reset(); behavior.setActive(Buttons.OPEN, true); behavior.setActive(Buttons.POSITION, true); 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 3ec134d4..51151338 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 @@ -171,7 +171,7 @@ public class LocalBKUState extends State { */ @Override public void run() { - Status status = getStateMachine().getStatus(); + Status status = getStateMachine().status; SigningState signingState = status.signingState; @@ -185,7 +185,7 @@ public class LocalBKUState extends State { if (this.threadException != null) { ErrorDialog dialog = new ErrorDialog( - getStateMachine().getGUIProvider().getMainShell(), + getStateMachine().getMainShell(), Messages.getString("error.LocalBKU"), BUTTONS.RETRY_CANCEL); if (dialog.open() != SWT.RETRY) { @@ -219,7 +219,7 @@ public class LocalBKUState extends State { */ @Override public void updateMainWindowBehavior() { - MainWindowBehavior behavior = getStateMachine().getStatus().behavior; + MainWindowBehavior behavior = getStateMachine().status.behavior; behavior.reset(); behavior.setActive(Buttons.OPEN, true); behavior.setActive(Buttons.POSITION, true); 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 a2c65938..6d59dfd5 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 @@ -64,16 +64,16 @@ public class MobileBKUState extends State { public MobileBKUState(StateMachine stateMachine) {
super(stateMachine);
- ConfigProvider provider = stateMachine.getConfigProvider();
+ ConfigProvider provider = stateMachine.configProvider;
switch(provider.getMobileBKUType()) {
case A_TRUST:
this.status = new ATrustStatus(provider);
- this.handler = new ATrustHandler(this, stateMachine.getGUIProvider().getMainShell(), provider.getMobileBKUBase64());
+ this.handler = new ATrustHandler(this, stateMachine.getMainShell(), provider.getMobileBKUBase64());
break;
case IAIK:
this.status = new IAIKStatus(provider);
- this.handler = new IAIKHandler(this, stateMachine.getGUIProvider().getMainShell());
+ this.handler = new IAIKHandler(this, stateMachine.getMainShell());
break;
default:
@@ -86,7 +86,7 @@ public class MobileBKUState extends State { WaitingForAppComposite waitingForAppComposite = null;
WaitingForAppComposite getWaitingForAppComposite() {
if (this.waitingForAppComposite == null) {
- this.waitingForAppComposite = getStateMachine().getGUIProvider()
+ this.waitingForAppComposite = getStateMachine()
.createComposite(WaitingForAppComposite.class, SWT.RESIZE, this);
}
@@ -96,7 +96,7 @@ public class MobileBKUState extends State { WaitingComposite waitingComposite = null;
WaitingComposite getWaitingComposite() {
if (this.waitingComposite == null) {
- this.waitingComposite = getStateMachine().getGUIProvider()
+ this.waitingComposite = getStateMachine()
.createComposite(WaitingComposite.class, SWT.RESIZE, this);
}
@@ -105,7 +105,7 @@ public class MobileBKUState extends State { MobileBKUEnterTANComposite getMobileBKUEnterTANComposite() {
if (this.mobileBKUEnterTANComposite == null) {
- this.mobileBKUEnterTANComposite = getStateMachine().getGUIProvider()
+ this.mobileBKUEnterTANComposite = getStateMachine()
.createComposite(MobileBKUEnterTANComposite.class, SWT.RESIZE, this);
}
@@ -115,7 +115,7 @@ public class MobileBKUState extends State { MobileBKUQRComposite mobileBKUQRComposite = null;
MobileBKUQRComposite getMobileBKUQRComposite() {
if (this.mobileBKUQRComposite == null) {
- this.mobileBKUQRComposite = getStateMachine().getGUIProvider()
+ this.mobileBKUQRComposite = getStateMachine()
.createComposite(MobileBKUQRComposite.class, SWT.RESIZE, this);
}
@@ -125,7 +125,7 @@ public class MobileBKUState extends State { MobileBKUEnterNumberComposite mobileBKUEnterNumberComposite = null;
MobileBKUEnterNumberComposite getMobileBKUEnterNumberComposite() {
if (this.mobileBKUEnterNumberComposite == null) {
- this.mobileBKUEnterNumberComposite = getStateMachine().getGUIProvider()
+ this.mobileBKUEnterNumberComposite = getStateMachine()
.createComposite(MobileBKUEnterNumberComposite.class, SWT.RESIZE, this);
}
@@ -135,7 +135,7 @@ public class MobileBKUState extends State { MobileBKUFingerprintComposite mobileBKUFingerprintComposite = null;
MobileBKUFingerprintComposite getMobileBKUFingerprintComposite() {
if (this.mobileBKUFingerprintComposite == null) {
- this.mobileBKUFingerprintComposite = getStateMachine().getGUIProvider()
+ this.mobileBKUFingerprintComposite = getStateMachine()
.createComposite(MobileBKUFingerprintComposite.class, SWT.RESIZE, this);
}
@@ -147,7 +147,7 @@ public class MobileBKUState extends State { * @return the mobile BKU URL
*/
public String getURL() {
- return getStateMachine().getConfigProvider().getMobileBKUURL();
+ return getStateMachine().configProvider.getMobileBKUURL();
}
/**
@@ -181,7 +181,7 @@ public class MobileBKUState extends State { public void displayError(final String message) {
log.error(message);
Display.getDefault().syncExec(() -> {
- ErrorDialog error = new ErrorDialog(getStateMachine().getGUIProvider().getMainShell(), message, BUTTONS.OK);
+ ErrorDialog error = new ErrorDialog(getStateMachine().getMainShell(), message, BUTTONS.OK);
error.open();
});
}
@@ -222,9 +222,9 @@ public class MobileBKUState extends State { ui.setMobilePassword(mobileStatus.mobilePassword);
}
ui.enableButton();
- getStateMachine().getGUIProvider().display(ui);
+ getStateMachine().display(ui);
- Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
+ Display display = getStateMachine().getMainShell().getDisplay();
while (!ui.userAck && !ui.userCancel) {
if (!display.readAndDispatch()) {
display.sleep();
@@ -246,7 +246,7 @@ public class MobileBKUState extends State { mobileStatus.mobilePassword = ui.getMobilePassword();
// show waiting composite
- getStateMachine().getGUIProvider().display(this.getWaitingComposite());
+ getStateMachine().display(this.getWaitingComposite());
});
}
@@ -272,9 +272,9 @@ public class MobileBKUState extends State { tan.setTries(mobileStatus.tanTries);
}
tan.enableButton();
- getStateMachine().getGUIProvider().display(tan);
+ getStateMachine().display(tan);
- Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
+ Display display = getStateMachine().getMainShell().getDisplay();
while (!tan.isUserAck() && !tan.isUserCancel()) {
if (!display.readAndDispatch()) {
display.sleep();
@@ -294,7 +294,7 @@ public class MobileBKUState extends State { mobileStatus.tan = tan.getTan();
// show waiting composite
- getStateMachine().getGUIProvider().display(getWaitingComposite());
+ getStateMachine().display(getWaitingComposite());
});
}
@@ -315,7 +315,7 @@ public class MobileBKUState extends State { if (handler.handleQRResponse(resp)) {
log.debug("Signature page response: " + resp);
getMobileBKUQRComposite().setDone(true);
- Display display = getStateMachine().getGUIProvider().
+ Display display = getStateMachine().
getMainShell().getDisplay();
display.wake();
checkDone.cancel();
@@ -338,9 +338,9 @@ public class MobileBKUState extends State { this.threadException = new Exception(Messages.getString("error.FailedToLoadQRCode"));
}
qr.setQR(qrcode);
- getStateMachine().getGUIProvider().display(qr);
+ getStateMachine().display(qr);
- Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
+ Display display = getStateMachine().getMainShell().getDisplay();
while (!qr.isUserCancel() && !qr.isUserSMS() && !qr.isDone()) {
if (!display.readAndDispatch()) {
display.sleep();
@@ -364,7 +364,7 @@ public class MobileBKUState extends State { qr.setDone(false);
// show waiting composite
- getStateMachine().getGUIProvider().display(this.getWaitingComposite());
+ getStateMachine().display(this.getWaitingComposite());
});
}
@@ -377,9 +377,9 @@ public class MobileBKUState extends State { Display.getDefault().syncExec(() -> {
WaitingForAppComposite waitingForAppcomposite = this.getWaitingForAppComposite();
- getStateMachine().getGUIProvider().display(waitingForAppcomposite);
+ getStateMachine().display(waitingForAppcomposite);
- Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
+ Display display = getStateMachine().getMainShell().getDisplay();
undecidedPolling();
long timeoutTime = System.nanoTime() + (300 * ((long)1e9));
@@ -402,7 +402,7 @@ public class MobileBKUState extends State { status.errorMessage = "sms";
status.isSMSTan = true;
// show waiting composite
- getStateMachine().getGUIProvider().display(this.getWaitingComposite());
+ getStateMachine().display(this.getWaitingComposite());
return;
}
@@ -459,7 +459,7 @@ public class MobileBKUState extends State { if (handler.handleQRResponse(resp)) {
log.debug("Signature page response: " + resp);
getMobileBKUFingerprintComposite().setDone(true);
- Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
+ Display display = getStateMachine().getMainShell().getDisplay();
display.wake();
checkDone.cancel();
}
@@ -475,9 +475,9 @@ public class MobileBKUState extends State { fingerprintComposite.setRefVal(status.refVal);
fingerprintComposite.setSignatureData(status.signatureDataURL);
fingerprintComposite.setErrorMessage(status.errorMessage);
- getStateMachine().getGUIProvider().display(fingerprintComposite);
+ getStateMachine().display(fingerprintComposite);
- Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
+ Display display = getStateMachine().getMainShell().getDisplay();
while (!fingerprintComposite.isUserCancel() && !fingerprintComposite.isUserSMS() && !fingerprintComposite.isDone()) {
if (!display.readAndDispatch()) {
display.sleep();
@@ -500,7 +500,7 @@ public class MobileBKUState extends State { fingerprintComposite.setDone(false);
// show waiting composite
- getStateMachine().getGUIProvider().display(this.getWaitingComposite());
+ getStateMachine().display(this.getWaitingComposite());
});
}
@@ -521,7 +521,7 @@ public class MobileBKUState extends State { */
@Override
public void run() {
- this.signingState = getStateMachine().getStatus().signingState;
+ this.signingState = getStateMachine().status.signingState;
this.signingState.setBKUConnector(new MobileBKUConnector(this));
log.debug("Setting base64 request to " + this.handler.useBase64Request());
@@ -534,7 +534,7 @@ public class MobileBKUState extends State { if (errormsg != null && !errormsg.isEmpty())
message += ": " + errormsg;
ErrorDialog error = new ErrorDialog(
- getStateMachine().getGUIProvider().getMainShell(),
+ getStateMachine().getMainShell(),
message, BUTTONS.OK);
// error.setException(this.threadException);
// this.setNextState(error);
@@ -543,7 +543,7 @@ public class MobileBKUState extends State { return;
}
- getStateMachine().getGUIProvider().display(
+ getStateMachine().display(
this.getWaitingComposite());
this.setNextState(new at.asit.pdfover.gui.workflow.states.SigningState(getStateMachine()));
@@ -573,7 +573,7 @@ public class MobileBKUState extends State { */
@Override
public void updateMainWindowBehavior() {
- MainWindowBehavior behavior = getStateMachine().getStatus().behavior;
+ MainWindowBehavior behavior = getStateMachine().status.behavior;
behavior.reset();
behavior.setActive(Buttons.OPEN, true);
behavior.setActive(Buttons.POSITION, true);
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java index 64de1640..4457f902 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java @@ -74,15 +74,15 @@ public class OpenState extends State { private DataSourceSelectComposite getSelectionComposite() { if (this.selectionComposite == null) { this.selectionComposite = - getStateMachine().getGUIProvider().createComposite(DataSourceSelectComposite.class, SWT.RESIZE, this); + getStateMachine().createComposite(DataSourceSelectComposite.class, SWT.RESIZE, this); } return this.selectionComposite; } @Override public void run() { - ConfigProvider config = getStateMachine().getConfigProvider(); - Status status = getStateMachine().getStatus(); + ConfigProvider config = getStateMachine().configProvider; + Status status = getStateMachine().status; if (!(status.getPreviousState() instanceof PrepareConfigurationState) && !(status.getPreviousState() instanceof OpenState)) { status.bku = config.getDefaultBKU(); @@ -96,7 +96,7 @@ public class OpenState extends State { if (status.document == null) { DataSourceSelectComposite selection = this.getSelectionComposite(); - getStateMachine().getGUIProvider().display(selection); + getStateMachine().display(selection); selection.layout(); status.document = selection.getSelected(); @@ -106,12 +106,12 @@ public class OpenState extends State { return; } } - log.debug("Got Datasource: " + getStateMachine().getStatus().document.getAbsolutePath()); + log.debug("Got Datasource: " + getStateMachine().status.document.getAbsolutePath()); // scan for signature placeholders // - see if we want to scan for placeholders in the settings if (config.getEnablePlaceholderUsage()) { - try (PDDocument pddocument = PDDocument.load(getStateMachine().getStatus().document)) { + try (PDDocument pddocument = PDDocument.load(getStateMachine().status.document)) { // - scan for placeholders boolean useSignatureFields = config.getUseSignatureFields(); boolean useMarker = config.getUseMarker(); @@ -126,7 +126,7 @@ public class OpenState extends State { { // create a dialog with ok and cancel buttons and a question // icon - MessageBox dialog = new MessageBox(getStateMachine().getGUIProvider().getMainShell(), + MessageBox dialog = new MessageBox(getStateMachine().getMainShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO | SWT.CANCEL); dialog.setText(Messages.getString("dataSourceSelection.usePlaceholderTitle")); dialog.setMessage(Messages.getString("dataSourceSelection.usePlaceholderText")); @@ -143,11 +143,11 @@ public class OpenState extends State { } else if (fields.size() > 1) { PlaceholderSelectionGui gui = new PlaceholderSelectionGui( - getStateMachine().getGUIProvider().getMainShell(), 65570, "text", + getStateMachine().getMainShell(), 65570, "text", "select the fields", fields); int res = gui.open(); if (res != -1) { - getStateMachine().getStatus().searchForPlacehoderSignature = true; + getStateMachine().status.searchForPlacehoderSignature = true; addPlaceholderSelectionToConfig(fields.get(res)); this.setNextState(new BKUSelectionState(getStateMachine())); } @@ -156,7 +156,7 @@ public class OpenState extends State { } } else if (result == SWT.NO) { - getStateMachine().getStatus().searchForPlacehoderSignature = false; + getStateMachine().status.searchForPlacehoderSignature = false; } else { status.document = null; return; @@ -172,7 +172,7 @@ public class OpenState extends State { if (null != signaturePlaceholderData) { // create a dialog with ok and cancel buttons and a question icon - MessageBox dialog = new MessageBox(getStateMachine().getGUIProvider().getMainShell(), + MessageBox dialog = new MessageBox(getStateMachine().getMainShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO | SWT.CANCEL); dialog.setText(Messages.getString("dataSourceSelection.usePlaceholderTitle")); dialog.setMessage(Messages.getString("dataSourceSelection.usePlaceholderText")); @@ -190,10 +190,10 @@ public class OpenState extends State { signaturePlaceholderData.getTablePos().getPosY(), signaturePlaceholderData.getTablePos().getPage()); - getStateMachine().getStatus().searchForPlacehoderSignature = true; + getStateMachine().status.searchForPlacehoderSignature = true; } else if (result == SWT.NO) { - getStateMachine().getStatus().searchForPlacehoderSignature = false; + getStateMachine().status.searchForPlacehoderSignature = false; } else { status.document = null; return; @@ -256,7 +256,7 @@ public class OpenState extends State { */ @Override public void updateMainWindowBehavior() { - MainWindowBehavior behavior = getStateMachine().getStatus().behavior; + MainWindowBehavior behavior = getStateMachine().status.behavior; behavior.reset(); behavior.setEnabled(Buttons.CONFIG, true); behavior.setEnabled(Buttons.OPEN, true); 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 bae7cb13..e8b9402d 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 @@ -46,11 +46,11 @@ public class OutputState extends State { private OutputComposite getOutputComposite() { if (this.outputComposite == null) { - this.outputComposite = getStateMachine().getGUIProvider() + this.outputComposite = getStateMachine() .createComposite(OutputComposite.class, SWT.RESIZE, this); - ConfigProvider config = getStateMachine().getConfigProvider(); - Status status = getStateMachine().getStatus(); + ConfigProvider config = getStateMachine().configProvider; + Status status = getStateMachine().status; File tmpDir = new File(config.getConfigurationDirectory() + File.separator + "tmp"); @@ -78,10 +78,10 @@ public class OutputState extends State { @Override public void run() { - Status status = getStateMachine().getStatus(); + Status status = getStateMachine().status; if (status.signResult == null) { - ErrorDialog error = new ErrorDialog(getStateMachine().getGUIProvider().getMainShell(), + ErrorDialog error = new ErrorDialog(getStateMachine().getMainShell(), Messages.getString("error.Signatur"), BUTTONS.RETRY_CANCEL); if(error.open() == SWT.RETRY) { this.setNextState(new PrepareSigningState(getStateMachine())); @@ -94,7 +94,7 @@ public class OutputState extends State { OutputComposite outputComposite = this.getOutputComposite(); // Display dialog - getStateMachine().getGUIProvider().display(outputComposite); + getStateMachine().display(outputComposite); } /* @@ -105,7 +105,7 @@ public class OutputState extends State { @Override public void cleanUp() { - getStateMachine().getStatus().signResult = null; + getStateMachine().status.signResult = null; if (this.outputComposite != null) this.outputComposite.dispose(); @@ -118,7 +118,7 @@ public class OutputState extends State { */ @Override public void updateMainWindowBehavior() { - MainWindowBehavior behavior = getStateMachine().getStatus().behavior; + MainWindowBehavior behavior = getStateMachine().status.behavior; behavior.reset(); behavior.setEnabled(Buttons.CONFIG, true); behavior.setEnabled(Buttons.OPEN, true); 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 427edb85..6d00cce0 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 @@ -82,7 +82,7 @@ public class PositioningState extends State { private void openPDFDocument() throws IOException { closePDFDocument(); - File documentPath = getStateMachine().getStatus().document; + File documentPath = getStateMachine().status.document; PDFFile pdf = null; RandomAccessFile rafile = new RandomAccessFile(documentPath, "r"); FileChannel chan = rafile.getChannel(); @@ -114,13 +114,13 @@ public class PositioningState extends State { StateMachine stateMachine = getStateMachine(); if (this.positionComposite == null) { this.positionComposite = - stateMachine.getGUIProvider().createComposite(PositioningComposite.class, SWT.RESIZE, this); - log.debug("Displaying " + stateMachine.getStatus().document); + stateMachine.createComposite(PositioningComposite.class, SWT.RESIZE, this); + log.debug("Displaying " + stateMachine.status.document); this.positionComposite.displayDocument(document); } // Update possibly changed values - ConfigProvider config = stateMachine.getConfigProvider(); - SignatureParameter param = stateMachine.getPDFSigner().getPDFSigner().newParameter(); + ConfigProvider config = stateMachine.configProvider; + SignatureParameter param = stateMachine.pdfSigner.getPDFSigner().newParameter(); Emblem emblem = new CachedFileNameEmblem(config.getDefaultEmblem()); param.setEmblem(emblem); if(config.getSignatureNote() != null && !config.getSignatureNote().isEmpty()) { @@ -146,7 +146,7 @@ public class PositioningState extends State { @Override public void run() { - Status status = getStateMachine().getStatus(); + Status status = getStateMachine().status; if (!(status.getPreviousState() instanceof PositioningState) && !(status.getPreviousState() instanceof OpenState)) { @@ -155,7 +155,7 @@ public class PositioningState extends State { } if ((this.document == null) || - (this.loadedDocumentPath != getStateMachine().getStatus().document)) { + (this.loadedDocumentPath != getStateMachine().status.document)) { log.debug("Checking PDF document for encryption"); try { openPDFDocument(); @@ -166,7 +166,7 @@ public class PositioningState extends State { if (message == null) message = Messages.getString("error.IOError"); ErrorDialog dialog = new ErrorDialog( - getStateMachine().getGUIProvider().getMainShell(), + getStateMachine().getMainShell(), message, BUTTONS.RETRY_CANCEL); if(dialog.open() == SWT.RETRY) { run(); @@ -184,7 +184,7 @@ public class PositioningState extends State { } catch(Exception ex) { log.error("Failed to create composite (probably a mac...)", ex); ErrorDialog dialog = new ErrorDialog( - getStateMachine().getGUIProvider().getMainShell(), + getStateMachine().getMainShell(), Messages.getString("error.PositioningNotPossible"), BUTTONS.OK); dialog.open(); status.signaturePosition = new SignaturePosition(); @@ -192,7 +192,7 @@ public class PositioningState extends State { return; } - getStateMachine().getGUIProvider().display(position); + getStateMachine().display(position); status.signaturePosition = position.getPosition(); @@ -221,7 +221,7 @@ public class PositioningState extends State { */ @Override public void updateMainWindowBehavior() { - MainWindowBehavior behavior = getStateMachine().getStatus().behavior; + MainWindowBehavior behavior = getStateMachine().status.behavior; behavior.reset(); behavior.setEnabled(Buttons.CONFIG, true); behavior.setEnabled(Buttons.OPEN, true); 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 22f66d32..451f2b55 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 @@ -110,9 +110,9 @@ public class PrepareConfigurationState extends State { try { try { - getStateMachine().getConfigProvider().loadConfiguration( + getStateMachine().configProvider.loadConfiguration( new FileInputStream( - getStateMachine().getConfigProvider().getConfigurationDirectory() + FILE_SEPARATOR + filename)); + getStateMachine().configProvider.getConfigurationDirectory() + FILE_SEPARATOR + filename)); log.info("Loaded config from file : " + filename); } catch (FileNotFoundException ex) { @@ -122,7 +122,7 @@ public class PrepareConfigurationState extends State { try { InputStream is = getClass().getResourceAsStream( Constants.RES_PKG_PATH + filename); - getStateMachine().getConfigProvider() + getStateMachine().configProvider .loadConfiguration(is); log.info("Loaded config from resource : " + filename); @@ -144,7 +144,7 @@ public class PrepareConfigurationState extends State { * Update configuration values as necessary */ private void updateConfiguration() { - ConfigProvider config = getStateMachine().getConfigProvider(); + ConfigProvider config = getStateMachine().configProvider; //Update signature note if old default is used String note = config.getSignatureNote(); @@ -156,7 +156,7 @@ public class PrepareConfigurationState extends State { } private void resetSignatureNoteField(ConfigProvider config){ - getStateMachine().getConfigManipulator().setSignatureNote( + getStateMachine().configProvider.setSignatureNote( Profile.getProfile(config.getSignatureProfile()).getDefaultSignatureBlockNote(config.getLocale()) ); } @@ -181,7 +181,7 @@ public class PrepareConfigurationState extends State { inputStream = getClass().getResourceAsStream( Constants.RES_PKG_PATH + Constants.DEFAULT_CONFIG_FILENAME); pdfOverConfig = new FileOutputStream( - getStateMachine().getConfigProvider().getConfigurationDirectory() + + getStateMachine().configProvider.getConfigurationDirectory() + FILE_SEPARATOR + Constants.DEFAULT_CONFIG_FILENAME); while ((byteCount = inputStream.read(buffer)) >= 0) { @@ -226,7 +226,7 @@ public class PrepareConfigurationState extends State { try { inputStream = getClass().getResourceAsStream( Constants.RES_PKG_PATH + Constants.DEFAULT_LOG4J_FILENAME); - String filename = getStateMachine().getConfigProvider().getConfigurationDirectory() + String filename = getStateMachine().configProvider.getConfigurationDirectory() + FILE_SEPARATOR + Constants.DEFAULT_LOG4J_FILENAME; pdfOverConfig = new FileOutputStream(filename); @@ -294,12 +294,12 @@ public class PrepareConfigurationState extends State { private void initializeConfig() throws InitializationException { initializeFromConfigurationFile(getStateMachine() - .getConfigProvider().getConfigurationFile()); + .configProvider.getConfigurationFile()); - resetSignatureNoteField(getStateMachine().getConfigProvider()); + resetSignatureNoteField(getStateMachine().configProvider); try { - getStateMachine().getConfigManipulator().saveCurrentConfiguration(); + getStateMachine().configProvider.saveCurrentConfiguration(); } catch (IOException e) { log.error( "Failed to set local configuration signature note!", e); @@ -399,8 +399,8 @@ public class PrepareConfigurationState extends State { // Read config file try { StateMachine stateMachine = getStateMachine(); - ConfigProvider config = stateMachine.getConfigProvider(); - final GUIProvider gui = stateMachine.getGUIProvider(); + ConfigProvider config = stateMachine.configProvider; + final GUIProvider gui = stateMachine; String cDir = config.getConfigurationDirectory(); File configDir = new File(cDir); File configFile = new File(configDir, Constants.DEFAULT_CONFIG_FILENAME); @@ -419,8 +419,7 @@ public class PrepareConfigurationState extends State { // Read cli arguments for config file first try { - initializeFromArguments(stateMachine.getCmdArgs(), - this.configFileHandler); + initializeFromArguments(stateMachine.cmdLineArgs, this.configFileHandler); } catch (InitializationException e) { log.error("Error in cmd line arguments: ", e); ErrorDialog error = new ErrorDialog(gui.getMainShell(), @@ -437,8 +436,7 @@ public class PrepareConfigurationState extends State { // Read cli arguments try { - initializeFromArguments(stateMachine.getCmdArgs(), - this.handler); + initializeFromArguments(stateMachine.cmdLineArgs, this.handler); } catch (InitializationException e) { log.error("Error in cmd line arguments: ", e); ErrorDialog error; @@ -501,20 +499,20 @@ public class PrepareConfigurationState extends State { } // Set usedSignerLib ... - stateMachine.getPDFSigner().setUsedPDFSignerLibrary( + stateMachine.pdfSigner.setUsedPDFSignerLibrary( Signator.Signers.PDFAS4); // Create PDF Signer - Status status = stateMachine.getStatus(); - status.bku = getStateMachine().getConfigProvider().getDefaultBKU(); - status.signaturePosition = getStateMachine().getConfigProvider().getDefaultSignaturePosition(); + Status status = stateMachine.status; + status.bku = getStateMachine().configProvider.getDefaultBKU(); + status.signaturePosition = getStateMachine().configProvider.getDefaultSignaturePosition(); setNextState(new OpenState(stateMachine)); } catch (InitializationException e) { log.error("Failed to initialize: ", e); ErrorDialog error = new ErrorDialog(getStateMachine() - .getGUIProvider().getMainShell(), + .getMainShell(), Messages.getString("error.Initialization"), BUTTONS.OK); // error.setException(e); 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 e00ec6e7..5bc9ec54 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 @@ -67,10 +67,9 @@ public class PrepareSigningState extends State { public void run() { try { - Status status = this.state.getStateMachine().getStatus(); + Status status = this.state.getStateMachine().status; - ConfigProvider configuration = this.state.getStateMachine() - .getConfigProvider(); + ConfigProvider configuration = this.state.getStateMachine().configProvider; // SET PROXY HOST and PORT settings final String proxyHost = configuration.getProxyHost(); @@ -124,13 +123,11 @@ public class PrepareSigningState extends State { }); } if (this.state.signer == null) { - this.state.signer = this.state.getStateMachine().getPDFSigner() - .getPDFSigner(); + this.state.signer = this.state.getStateMachine().pdfSigner.getPDFSigner(); } if (this.state.signatureParameter == null) { - this.state.signatureParameter = this.state.signer - .newParameter(); + this.state.signatureParameter = this.state.signer.newParameter(); } this.state.signatureParameter.setInputDocument(new PDFFileDocumentSource(status.document)); @@ -149,7 +146,7 @@ public class PrepareSigningState extends State { "SIG_NOTE", configuration.getSignatureNote()); } - this.state.signatureParameter.setSearchForPlaceholderSignatures(getStateMachine().getStatus().searchForPlacehoderSignature); + this.state.signatureParameter.setSearchForPlaceholderSignatures(getStateMachine().status.searchForPlacehoderSignature); this.state.signatureParameter.setSignatureLanguage(configuration.getSignatureLocale().getLanguage()); @@ -180,7 +177,7 @@ public class PrepareSigningState extends State { private WaitingComposite getSelectionComposite() { if (this.waitingComposite == null) { - this.waitingComposite = getStateMachine().getGUIProvider() + this.waitingComposite = getStateMachine() .createComposite(WaitingComposite.class, SWT.RESIZE, this); } @@ -197,11 +194,11 @@ public class PrepareSigningState extends State { public void run() { WaitingComposite waiting = this.getSelectionComposite(); - getStateMachine().getGUIProvider().display(waiting); + getStateMachine().display(waiting); - this.signer = getStateMachine().getPDFSigner().getPDFSigner(); + this.signer = getStateMachine().pdfSigner.getPDFSigner(); - Status status = getStateMachine().getStatus(); + Status status = getStateMachine().status; if (this.signatureParameter == null) { this.signatureParameter = this.signer.newParameter(); @@ -215,7 +212,7 @@ public class PrepareSigningState extends State { if (this.threadException != null) { ErrorDialog error = new ErrorDialog(getStateMachine() - .getGUIProvider().getMainShell(), + .getMainShell(), Messages.getString("error.PrepareDocument"), BUTTONS.RETRY_CANCEL); this.threadException = null; @@ -263,7 +260,7 @@ public class PrepareSigningState extends State { */ @Override public void updateMainWindowBehavior() { - MainWindowBehavior behavior = getStateMachine().getStatus().behavior; + MainWindowBehavior behavior = getStateMachine().status.behavior; behavior.reset(); behavior.setActive(Buttons.OPEN, true); behavior.setActive(Buttons.POSITION, true); 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 1bf901d3..82cdb31c 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 @@ -54,8 +54,8 @@ public class SigningState extends State { @Override public void run() { try { - Signer signer = this.state.getStateMachine().getPDFSigner().getPDFSigner(); - Status status = this.state.getStateMachine().getStatus(); + Signer signer = this.state.getStateMachine().pdfSigner.getPDFSigner(); + Status status = this.state.getStateMachine().status; status.signResult = signer.sign(status.signingState); } catch(Exception e) { @@ -82,7 +82,7 @@ public class SigningState extends State { @Override public void run() { - Status status = getStateMachine().getStatus(); + Status status = getStateMachine().status; if(status.signResult == null && this.threadException == null) { @@ -120,7 +120,7 @@ public class SigningState extends State { // if we have gotten to this point, this is an actual exception log.error("FinishSignThread: ", this.threadException); - ErrorDialog error = new ErrorDialog(getStateMachine().getGUIProvider().getMainShell(), + ErrorDialog error = new ErrorDialog(getStateMachine().getMainShell(), message, BUTTONS.RETRY_CANCEL); this.threadException = null; if(error.open() == SWT.RETRY) { @@ -147,7 +147,7 @@ public class SigningState extends State { */ @Override public void updateMainWindowBehavior() { - MainWindowBehavior behavior = getStateMachine().getStatus().behavior; + MainWindowBehavior behavior = getStateMachine().status.behavior; behavior.reset(); behavior.setActive(Buttons.OPEN, true); behavior.setActive(Buttons.POSITION, true); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/State.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/State.java index 55aee598..a6cca51f 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/State.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/State.java @@ -84,7 +84,7 @@ public abstract class State { /** * Update the main window behavior of this state if necessary - * Should update this.stateMachine.getStatus().getBehavior() + * Should update this.stateMachine.status.getBehavior() */ public abstract void updateMainWindowBehavior(); } |