summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit/pdfover
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java20
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/BKUSelectionState.java27
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java4
3 files changed, 41 insertions, 10 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java
index fe1e3a29..1f68a020 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java
@@ -17,7 +17,7 @@ package at.asit.pdfover.gui.bku;
// Imports
import java.io.IOException;
-
+import java.net.Socket;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
@@ -45,6 +45,24 @@ public class LocalBKUConnector implements BkuSlConnector {
**/
private static final Logger log = LoggerFactory.getLogger(LocalBKUConnector.class);
+ private static boolean isAvailable = false;
+ public static boolean IsAvailable() { return isAvailable; }
+ private static Thread pollingThread = new Thread(() -> {
+ while (true) {
+ try { Thread.sleep(isAvailable ? 30000 : 5000); } catch (InterruptedException e) {}
+ try (Socket socket = new Socket("127.0.0.1", 3495)) {
+ isAvailable = true;
+ } catch (IOException e) {
+ isAvailable = false;
+ }
+ }
+ }, "LocalBKUProbeThread");
+ static {
+ pollingThread.setDaemon(true);
+ pollingThread.start();
+ }
+
+
/**
* HTTP Response server HEADER
*/
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 a86e68b3..d1bdfe0d 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
@@ -23,6 +23,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import at.asit.pdfover.gui.MainWindow.Buttons;
+import at.asit.pdfover.gui.bku.LocalBKUConnector;
import at.asit.pdfover.commons.BKUs;
import at.asit.pdfover.gui.MainWindowBehavior;
import at.asit.pdfover.gui.composites.BKUSelectionComposite;
@@ -48,36 +49,44 @@ public class BKUSelectionState extends State {
private static final Logger log = LoggerFactory.getLogger(BKUSelectionState.class);
private BKUSelectionComposite selectionComposite = null;
-
private BKUSelectionComposite getSelectionComposite() {
if (this.selectionComposite == null) {
this.selectionComposite =
getStateMachine().createComposite(BKUSelectionComposite.class, SWT.RESIZE, this);
}
+ return this.selectionComposite;
+ }
+
+ private boolean isKeystoreEnabled() {
if (getStateMachine().configProvider.getKeyStoreEnabled()) {
File ks = new File(getStateMachine().configProvider.getKeyStoreFile());
- this.selectionComposite.setKeystoreEnabled(ks.exists());
+ return ks.exists();
} else
- this.selectionComposite.setKeystoreEnabled(false);
-
- return this.selectionComposite;
+ return false;
}
@Override
public void run() {
Status status = getStateMachine().status;
State previousState = status.getPreviousState();
- if (!(
+
+ final boolean hasLocalBKU = LocalBKUConnector.IsAvailable();
+ final boolean hasKeystore = isKeystoreEnabled();
+ if (
(previousState instanceof OpenState) ||
- (previousState instanceof PositioningState) ||
- (previousState instanceof BKUSelectionState)
- )) {
+ (previousState instanceof PositioningState)
+ ) {
+ if (!hasLocalBKU && !hasKeystore)
+ status.bku = BKUs.MOBILE;
+ } else if (!(previousState instanceof BKUSelectionState)) {
status.bku = BKUs.NONE;
}
if(status.bku == BKUs.NONE) {
BKUSelectionComposite selection = this.getSelectionComposite();
+ selection.setLocalBKUEnabled(hasLocalBKU);
+ selection.setKeystoreEnabled(hasKeystore);
getStateMachine().display(selection);
selection.layout();
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 082f7277..4d881496 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
@@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
import at.asit.pdfover.commons.Constants;
import at.asit.pdfover.gui.MainWindow.Buttons;
+import at.asit.pdfover.gui.bku.LocalBKUConnector;
import at.asit.pdfover.gui.MainWindowBehavior;
import at.asit.pdfover.gui.PlaceholderSelectionGui;
import at.asit.pdfover.gui.composites.DataSourceSelectComposite;
@@ -93,6 +94,9 @@ public class OpenState extends State {
status.getPreviousState().cleanUp();
}
+ /* force static initialization and start polling */
+ LocalBKUConnector.IsAvailable();
+
if (status.document == null) {
DataSourceSelectComposite selection = this.getSelectionComposite();