diff options
author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-07-06 12:49:13 +0200 |
---|---|---|
committer | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-07-06 12:49:13 +0200 |
commit | f4c665e207973856578c2ad75de4df39b7bca641 (patch) | |
tree | 9c1bab8b5a4b51da863cfa4bded2391ef432df4d | |
parent | e4767bccc7324d4b61a334bf6c0558d0080045e2 (diff) | |
download | pdf-over-f4c665e207973856578c2ad75de4df39b7bca641.tar.gz pdf-over-f4c665e207973856578c2ad75de4df39b7bca641.tar.bz2 pdf-over-f4c665e207973856578c2ad75de4df39b7bca641.zip |
refactor runnable -> lambda
7 files changed, 204 insertions, 277 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java index aa98317e..5c0e108c 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java @@ -172,23 +172,20 @@ public class ATrustHandler extends MobileBKUHandler { log.info(notice);
if (!expiryNoticeDisplayed) {
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- Dialog d = new Dialog(ATrustHandler.this.shell, Messages.getString("common.info"), Messages.getString("mobileBKU.certExpiresSoon"), BUTTONS.YES_NO, ICON.WARNING); // //
- if (d.open() == SWT.YES) {
- log.debug("Trying to open " + ACTIVATION_URL); //
- if (Desktop.isDesktopSupported()) {
- try {
- Desktop.getDesktop().browse(new URI(ACTIVATION_URL));
- return;
- } catch (Exception e) {
- log.debug("Error opening URL", e); //
- }
+ Display.getDefault().syncExec(()-> {
+ Dialog d = new Dialog(ATrustHandler.this.shell, Messages.getString("common.info"), Messages.getString("mobileBKU.certExpiresSoon"), BUTTONS.YES_NO, ICON.WARNING); // //
+ if (d.open() == SWT.YES) {
+ log.debug("Trying to open " + ACTIVATION_URL); //
+ if (Desktop.isDesktopSupported()) {
+ try {
+ Desktop.getDesktop().browse(new URI(ACTIVATION_URL));
+ return;
+ } catch (Exception e) {
+ log.debug("Error opening URL", e); //
}
- log.info("SWT Desktop is not supported on this platform"); //
- Program.launch(ACTIVATION_URL);
}
+ log.info("SWT Desktop is not supported on this platform"); //
+ Program.launch(ACTIVATION_URL);
}
});
expiryNoticeDisplayed = true;
@@ -353,21 +350,18 @@ public class ATrustHandler extends MobileBKUHandler { if (getStatus().tanTries <= 0) {
getStatus().errorMessage = null;
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- Dialog dialog = new Dialog(ATrustHandler.this.shell, Messages.getString("common.warning"), //
- Messages.getString("mobileBKU.tan_tries_exceeded"), //
- BUTTONS.OK_CANCEL, ICON.QUESTION);
-
- // TODO: THIS IS A COLOSSAL HACK
- if (dialog.open() == SWT.CANCEL) {
- // Go back to BKU Selection
- getStatus().tanTries = -1;
- } else {
- // Start signature process over
- getStatus().tanTries = -2;
- }
+ Display.getDefault().syncExec(() -> {
+ Dialog dialog = new Dialog(ATrustHandler.this.shell, Messages.getString("common.warning"), //
+ Messages.getString("mobileBKU.tan_tries_exceeded"), //
+ BUTTONS.OK_CANCEL, ICON.QUESTION);
+
+ // TODO: THIS IS A COLOSSAL HACK
+ if (dialog.open() == SWT.CANCEL) {
+ // Go back to BKU Selection
+ getStatus().tanTries = -1;
+ } else {
+ // Start signature process over
+ getStatus().tanTries = -2;
}
});
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKHandler.java index 77572f26..e1e838fc 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKHandler.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKHandler.java @@ -315,20 +315,17 @@ public class IAIKHandler extends MobileBKUHandler { executePost(client, post);
} catch (Exception e) {
// Assume that wrong TAN was entered too many times
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- Dialog dialog = new Dialog(IAIKHandler.this.shell, Messages.getString("common.warning"), //
- Messages.getString("mobileBKU.tan_tries_exceeded"), //
- BUTTONS.OK_CANCEL, ICON.QUESTION);
- // TODO: ALSO A COLOSSAL HACK HERE
- if (dialog.open() == SWT.CANCEL) {
- // Go back to BKU Selection
- status.tanTries = -1;
- } else {
- // Start signature process over
- status.tanTries = -2;
- }
+ Display.getDefault().syncExec(() -> {
+ Dialog dialog = new Dialog(IAIKHandler.this.shell, Messages.getString("common.warning"), //
+ Messages.getString("mobileBKU.tan_tries_exceeded"), //
+ BUTTONS.OK_CANCEL, ICON.QUESTION);
+ // TODO: ALSO A COLOSSAL HACK HERE
+ if (dialog.open() == SWT.CANCEL) {
+ // Go back to BKU Selection
+ status.tanTries = -1;
+ } else {
+ // Start signature process over
+ status.tanTries = -2;
}
});
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java index a98cdf9e..4e6af9ba 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java @@ -137,18 +137,12 @@ public class PositioningComposite extends StateComposite { this.mainArea.setLayoutData(fd_mainArea); this.scrollbar = this.mainArea.getVerticalBar(); - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - getDisplay().syncExec(new Runnable() { - @Override - public void run() { - PositioningComposite.this.frame = SWT_AWT.new_Frame(PositioningComposite.this.mainArea); - PositioningComposite.this.frame.addKeyListener(PositioningComposite.this.keyListener); - PositioningComposite.this.frame.addMouseWheelListener(PositioningComposite.this.mouseListener); - } - }); - } + EventQueue.invokeLater(() -> { + getDisplay().syncExec(() -> { + this.frame = SWT_AWT.new_Frame(this.mainArea); + this.frame.addKeyListener(this.keyListener); + this.frame.addMouseWheelListener(this.mouseListener); + }); }); this.scrollbar.addSelectionListener(this.selectionListener); @@ -163,30 +157,24 @@ public class PositioningComposite extends StateComposite { */ public void displayDocument(final PDFFile document) { if (this.viewer == null) { - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - PositioningComposite.this.viewer = new SignaturePanel(document); - PositioningComposite.this.viewer.setSignaturePlaceholderBorderColor(new Color( - Constants.MAINBAR_ACTIVE_BACK_DARK.getRed(), - Constants.MAINBAR_ACTIVE_BACK_DARK.getGreen(), - Constants.MAINBAR_ACTIVE_BACK_DARK.getBlue())); - PositioningComposite.this.frame.add(PositioningComposite.this.viewer, BorderLayout.CENTER); - } + EventQueue.invokeLater(() -> { + this.viewer = new SignaturePanel(document); + this.viewer.setSignaturePlaceholderBorderColor(new Color( + Constants.MAINBAR_ACTIVE_BACK_DARK.getRed(), + Constants.MAINBAR_ACTIVE_BACK_DARK.getGreen(), + Constants.MAINBAR_ACTIVE_BACK_DARK.getBlue())); + this.frame.add(this.viewer, BorderLayout.CENTER); }); } else { - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - PositioningComposite.this.viewer.setDocument(document); - } + EventQueue.invokeLater(() -> { + this.viewer.setDocument(document); }); } if (document != null) { this.numPages = document.getNumPages(); - PositioningComposite.this.scrollbar.setValues(1, 1, this.numPages + 1, 1, 1, 1); + this.scrollbar.setValues(1, 1, this.numPages + 1, 1, 1, 1); showPage(this.numPages); } } @@ -201,22 +189,16 @@ public class PositioningComposite extends StateComposite { * Request focus (to enable keyboard input) */ public void requestFocus() { - getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - if (!PositioningComposite.this.isDisposed() && !PositioningComposite.this.mainArea.isDisposed()) { - PositioningComposite.this.mainArea.setFocus(); - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - if (!PositioningComposite.this.isDisposed()) { - if(!PositioningComposite.this.frame.hasFocus()) { - PositioningComposite.this.frame.requestFocus(); - } - } + getDisplay().asyncExec(() -> { + if (!this.isDisposed() && !this.mainArea.isDisposed()) { + this.mainArea.setFocus(); + EventQueue.invokeLater(() -> { + if (!this.isDisposed()) { + if (!this.frame.hasFocus()) { + this.frame.requestFocus(); } - }); - } + } + }); } }); } @@ -236,13 +218,10 @@ public class PositioningComposite extends StateComposite { */ public void setPlaceholder(final Image placeholder, final int width, final int height, final int transparency) { - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - if (PositioningComposite.this.viewer == null) - return; - PositioningComposite.this.viewer.setSignaturePlaceholder(placeholder, width, height, transparency); - } + EventQueue.invokeLater(() -> { + if (this.viewer == null) + return; + this.viewer.setSignaturePlaceholder(placeholder, width, height, transparency); }); } @@ -342,36 +321,27 @@ public class PositioningComposite extends StateComposite { void showPage(final int page) { final int previousPage = this.currentPage; this.currentPage = page; - getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - int currentPage = PositioningComposite.this.currentPage; - int numPages = PositioningComposite.this.numPages; - if ((previousPage > numPages) && (currentPage <= numPages)) { - // Was on new page - PositioningComposite.this.btnNewPage.setText( - Messages.getString("positioning.newPage")); // - PositioningComposite.this.btnNewPage.setSelection(false); - PositioningComposite.this.bottomBar.layout(); - PositioningComposite.this.scrollbar.setMaximum(numPages + 1); - } else if ((previousPage <= numPages) && (currentPage > numPages)) { - // Go to new page - PositioningComposite.this.btnNewPage.setText( - Messages.getString("positioning.removeNewPage")); // - PositioningComposite.this.btnNewPage.setSelection(true); - PositioningComposite.this.bottomBar.layout(); - PositioningComposite.this.scrollbar.setMaximum(numPages + 2); - } - PositioningComposite.this.scrollbar.setSelection(currentPage); - PositioningComposite.this.lblPage.setText(String.format( - Messages.getString("positioning.page"), currentPage, numPages)); // + getDisplay().asyncExec(() -> { + int currentPage = this.currentPage; + int numPages = this.numPages; + if ((previousPage > numPages) && (currentPage <= numPages)) { + // Was on new page + this.btnNewPage.setText(Messages.getString("positioning.newPage")); // + this.btnNewPage.setSelection(false); + this.bottomBar.layout(); + this.scrollbar.setMaximum(numPages + 1); + } else if ((previousPage <= numPages) && (currentPage > numPages)) { + // Go to new page + this.btnNewPage.setText(Messages.getString("positioning.removeNewPage")); // + this.btnNewPage.setSelection(true); + this.bottomBar.layout(); + this.scrollbar.setMaximum(numPages + 2); } + this.scrollbar.setSelection(currentPage); + this.lblPage.setText(String.format(Messages.getString("positioning.page"), currentPage, numPages)); // }); - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - PositioningComposite.this.viewer.showPage(page); - } + EventQueue.invokeLater(() -> { + PositioningComposite.this.viewer.showPage(page); }); } @@ -400,12 +370,8 @@ public class PositioningComposite extends StateComposite { * signature placeholder vertical position offset */ public void translateSignaturePosition(final int sigXOffset, final int sigYOffset) { - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - PositioningComposite.this.viewer.translateSignaturePosition(sigXOffset, - sigYOffset); - } + EventQueue.invokeLater(() -> { + this.viewer.translateSignaturePosition(sigXOffset, sigYOffset); }); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/osx/CocoaUIEnhancer.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/osx/CocoaUIEnhancer.java index a6960f87..3ded94eb 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/osx/CocoaUIEnhancer.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/osx/CocoaUIEnhancer.java @@ -170,11 +170,8 @@ public class CocoaUIEnhancer { } // Schedule disposal of callback object - display.disposeExec(new Runnable() { - @Override - public void run() { - CocoaUIEnhancer.invoke(proc3Args, "dispose"); // - } + display.disposeExec(() -> { + CocoaUIEnhancer.invoke(proc3Args, "dispose"); // }); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java index a48c0e5e..8b05a528 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java @@ -140,11 +140,8 @@ public class StateMachineImpl implements StateMachine, GUIProvider { @Override public void invokeUpdate() { if (this.display != null) { - this.display.asyncExec(new Runnable() { - @Override - public void run() { - StateMachineImpl.this.update(); - } + this.display.asyncExec(() -> { + StateMachineImpl.this.update(); }); } } 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 86266b13..153d4b1d 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 @@ -180,13 +180,9 @@ public class MobileBKUState extends State { */
public void displayError(final String message) {
log.error(message);
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- ErrorDialog error = new ErrorDialog(getStateMachine().getGUIProvider()
- .getMainShell(), message, BUTTONS.OK);
- error.open();
- }
+ Display.getDefault().syncExec(() -> {
+ ErrorDialog error = new ErrorDialog(getStateMachine().getGUIProvider().getMainShell(), message, BUTTONS.OK);
+ error.open();
});
}
@@ -200,62 +196,57 @@ public class MobileBKUState extends State { mobileStatus.mobilePassword != null && !mobileStatus.mobilePassword.isEmpty())
return;
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- MobileBKUEnterNumberComposite ui = MobileBKUState.this
- .getMobileBKUEnterNumberComposite();
-
- if (!ui.userAck) {
- // We need number and password => show UI!
- if (mobileStatus.errorMessage != null
- && !mobileStatus.errorMessage.isEmpty()) {
- // set possible error message
- ui.setErrorMessage(mobileStatus.errorMessage);
- mobileStatus.errorMessage = null;
- } else if (mobileStatus instanceof ATrustStatus) {
- ui.setErrorMessage(Messages.getString("mobileBKU.aTrustDisclaimer")); //
- }
+ Display.getDefault().syncExec(() -> {
+ MobileBKUEnterNumberComposite ui = this.getMobileBKUEnterNumberComposite();
+
+ if (!ui.userAck) {
+ // We need number and password => show UI!
+ if (mobileStatus.errorMessage != null
+ && !mobileStatus.errorMessage.isEmpty()) {
+ // set possible error message
+ ui.setErrorMessage(mobileStatus.errorMessage);
+ mobileStatus.errorMessage = null;
+ } else if (mobileStatus instanceof ATrustStatus) {
+ ui.setErrorMessage(Messages.getString("mobileBKU.aTrustDisclaimer")); //
+ }
- if (ui.getMobileNumber() == null
- || ui.getMobileNumber().isEmpty()) {
- // set possible phone number
- ui.setMobileNumber(mobileStatus.phoneNumber);
- }
+ if (ui.getMobileNumber() == null
+ || ui.getMobileNumber().isEmpty()) {
+ // set possible phone number
+ ui.setMobileNumber(mobileStatus.phoneNumber);
+ }
- if (ui.getMobilePassword() == null
- || ui.getMobilePassword().isEmpty()) {
- // set possible password
- ui.setMobilePassword(mobileStatus.mobilePassword);
- }
- ui.enableButton();
- getStateMachine().getGUIProvider().display(ui);
-
- Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
- while (!ui.userAck && !ui.userCancel) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
+ if (ui.getMobilePassword() == null
+ || ui.getMobilePassword().isEmpty()) {
+ // set possible password
+ ui.setMobilePassword(mobileStatus.mobilePassword);
}
+ ui.enableButton();
+ getStateMachine().getGUIProvider().display(ui);
- if (ui.userCancel) {
- ui.userCancel = false;
- mobileStatus.errorMessage = "cancel"; //
- return;
+ Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
+ while (!ui.userAck && !ui.userCancel) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
}
+ }
- // user hit ok
- ui.userAck = false;
+ if (ui.userCancel) {
+ ui.userCancel = false;
+ mobileStatus.errorMessage = "cancel"; //
+ return;
+ }
- // get number and password from UI
- mobileStatus.phoneNumber = ui.getMobileNumber();
- mobileStatus.mobilePassword = ui.getMobilePassword();
+ // user hit ok
+ ui.userAck = false;
- // show waiting composite
- getStateMachine().getGUIProvider().display(
- MobileBKUState.this.getWaitingComposite());
- }
+ // get number and password from UI
+ mobileStatus.phoneNumber = ui.getMobileNumber();
+ mobileStatus.mobilePassword = ui.getMobilePassword();
+
+ // show waiting composite
+ getStateMachine().getGUIProvider().display(MobileBKUState.this.getWaitingComposite());
});
}
@@ -265,50 +256,45 @@ public class MobileBKUState extends State { public void checkTAN() {
final MobileBKUStatus mobileStatus = this.status;
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- MobileBKUEnterTANComposite tan = MobileBKUState.this
- .getMobileBKUEnterTANComposite();
-
- if (!tan.isUserAck()) {
- // we need the TAN
- tan.setRefVal(mobileStatus.refVal);
- tan.setSignatureData(mobileStatus.signatureDataURL);
- tan.setErrorMessage(mobileStatus.errorMessage);
- if (mobileStatus.tanTries < mobileStatus.getMaxTanTries()
- && mobileStatus.tanTries > 0) {
- // show warning message x tries left!
- // overrides error message
-
- tan.setTries(mobileStatus.tanTries);
- }
- tan.enableButton();
- getStateMachine().getGUIProvider().display(tan);
-
- Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
- while (!tan.isUserAck() && !tan.isUserCancel()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
+ Display.getDefault().syncExec(() -> {
+ MobileBKUEnterTANComposite tan = getMobileBKUEnterTANComposite();
+
+ if (!tan.isUserAck()) {
+ // we need the TAN
+ tan.setRefVal(mobileStatus.refVal);
+ tan.setSignatureData(mobileStatus.signatureDataURL);
+ tan.setErrorMessage(mobileStatus.errorMessage);
+ if (mobileStatus.tanTries < mobileStatus.getMaxTanTries()
+ && mobileStatus.tanTries > 0) {
+ // show warning message x tries left!
+ // overrides error message
+
+ tan.setTries(mobileStatus.tanTries);
}
+ tan.enableButton();
+ getStateMachine().getGUIProvider().display(tan);
- if (tan.isUserCancel()) {
- tan.setUserCancel(false);
- mobileStatus.errorMessage = "cancel";
- return;
+ Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
+ while (!tan.isUserAck() && !tan.isUserCancel()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
}
+ }
+
+ if (tan.isUserCancel()) {
+ tan.setUserCancel(false);
+ mobileStatus.errorMessage = "cancel";
+ return;
+ }
- // user hit ok!
- tan.setUserAck(false);
+ // user hit ok!
+ tan.setUserAck(false);
- mobileStatus.tan = tan.getTan();
+ mobileStatus.tan = tan.getTan();
- // show waiting composite
- getStateMachine().getGUIProvider().display(
- MobileBKUState.this.getWaitingComposite());
- }
+ // show waiting composite
+ getStateMachine().getGUIProvider().display(getWaitingComposite());
});
}
@@ -321,7 +307,6 @@ public class MobileBKUState extends State { final Timer checkDone = new Timer();
checkDone.scheduleAtFixedRate(new TimerTask() {
-
@Override
public void run() {
// ping signature page to see if code has been scanned
@@ -390,11 +375,8 @@ public class MobileBKUState extends State { * This composite notifies the user to open the signature-app
*/
public void showOpenAppMessage() {
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- getStateMachine().getGUIProvider().display(MobileBKUState.this.getWaitingForAppComposite());
- }
+ Display.getDefault().syncExec(() -> {
+ getStateMachine().getGUIProvider().display(this.getWaitingForAppComposite());
});
}
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 d653a07f..062231b4 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 @@ -461,47 +461,41 @@ public class PrepareConfigurationState extends State { // Check for updates if (config.getUpdateCheck() && Constants.APP_VERSION != null) { - new Thread(new Runnable() { - @Override - public void run() { - HttpClient client = (HttpClient) BKUHelper.getHttpClient(); - GetMethod method = new GetMethod(Constants.CURRENT_RELEASE_URL); - try { - client.executeMethod(method); - final String version = method.getResponseBodyAsString().trim(); - if (!VersionComparator.before(Constants.APP_VERSION, version)) - return; - - // wait 500ms before invoke the GUI message, because GUI had to be started from - // main thread - try {Thread.sleep(500); } catch (InterruptedException e1) { } - // invoke GUI message in main thread - gui.getMainShell().getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - Dialog info = new Dialog(gui.getMainShell(), - Messages.getString("version_check.UpdateTitle"), // - String.format(Messages.getString("version_check.UpdateText"), // - version), - BUTTONS.OK_CANCEL, ICON.INFORMATION); - if (info.open() == SWT.OK) - { - if (Desktop.isDesktopSupported()) { - try { - Desktop.getDesktop().browse(new URI(Constants.UPDATE_URL)); - } catch (Exception e) { - log.error("Error opening update location ", e); // - } - } else { - log.info("SWT Desktop is not supported on this platform"); // - Program.launch(Constants.UPDATE_URL); - } - } + new Thread(() -> { + HttpClient client = (HttpClient) BKUHelper.getHttpClient(); + GetMethod method = new GetMethod(Constants.CURRENT_RELEASE_URL); + try { + client.executeMethod(method); + final String version = method.getResponseBodyAsString().trim(); + if (!VersionComparator.before(Constants.APP_VERSION, version)) + return; + + // wait 500ms before invoke the GUI message, because GUI had to be started from + // main thread + try {Thread.sleep(500); } catch (InterruptedException e1) { } + // invoke GUI message in main thread + gui.getMainShell().getDisplay().asyncExec(() -> { + Dialog info = new Dialog(gui.getMainShell(), + Messages.getString("version_check.UpdateTitle"), // + String.format(Messages.getString("version_check.UpdateText"), version), + BUTTONS.OK_CANCEL, ICON.INFORMATION); + + if (info.open() == SWT.OK) + { + if (Desktop.isDesktopSupported()) { + try { + Desktop.getDesktop().browse(new URI(Constants.UPDATE_URL)); + } catch (Exception e) { + log.error("Error opening update location ", e); // + } + } else { + log.info("SWT Desktop is not supported on this platform"); // + Program.launch(Constants.UPDATE_URL); } - }); - } catch (Exception e) { - log.error("Error downloading update information: ", e); // - } + } + }); + } catch (Exception e) { + log.error("Error downloading update information: ", e); // } }).start(); } |