From 9c0a3462d4c32e8135c794f48a7e5335232ec492 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 21 Jan 2021 15:40:01 +0100 Subject: [PATCH 1/3] add methods to declare success of a step in FlashThread, IFlashHandler and FlashSceneController --- .../subcontrollers/FlashSceneController.java | 10 ++++++++++ .../java/ecorp/easy/installer/threads/FlashThread.java | 5 +++++ .../java/ecorp/easy/installer/utils/IFlashHandler.java | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java index 14db165e..9a561bb2 100644 --- a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java +++ b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java @@ -198,6 +198,16 @@ public class FlashSceneController extends AbstractSubSteppedController implement } } + /** + * @@inheritDoc + */ + @Override + public void onStepSuccess(DataBundle bundle) { + logger.debug("onStepSuccess"); + //Still not implemented + } + + /** * Update text and images instructions * @param instructionsKey diff --git a/src/main/java/ecorp/easy/installer/threads/FlashThread.java b/src/main/java/ecorp/easy/installer/threads/FlashThread.java index e6677dbc..fed999f5 100644 --- a/src/main/java/ecorp/easy/installer/threads/FlashThread.java +++ b/src/main/java/ecorp/easy/installer/threads/FlashThread.java @@ -246,6 +246,11 @@ public class FlashThread extends Thread { protected void doAfterToRunCommand() throws Exception{ atLeastOneError = (atLeastOneError || !success || cancelled); sendIssueLog = (atLeastOneError && !cancelled); + if(success){ + Platform.runLater(()->{ + application.onStepSuccess(null); + }); + } } diff --git a/src/main/java/ecorp/easy/installer/utils/IFlashHandler.java b/src/main/java/ecorp/easy/installer/utils/IFlashHandler.java index 99b1e60d..d935445b 100644 --- a/src/main/java/ecorp/easy/installer/utils/IFlashHandler.java +++ b/src/main/java/ecorp/easy/installer/utils/IFlashHandler.java @@ -33,4 +33,10 @@ public interface IFlashHandler { public void onFlashStop(DataBundle bundle); public void onLogToDisplayRecieved(String log); + + /** + * Update UI when the current step succeeded + * @param bundle data transfered from the thread + */ + public void onStepSuccess(DataBundle bundle); } -- GitLab From f29bc1304775396b8b32640cac9b857fb1ec4ccb Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 21 Jan 2021 18:43:03 +0100 Subject: [PATCH 2/3] make very basic implementation in FlashSceneController.onStepSuccess() and add waitPauseLock() method in FlashThread. Use it to pause the thread while onStepSuccess() --- .../subcontrollers/FlashSceneController.java | 19 +++++++++++- .../easy/installer/threads/FlashThread.java | 30 +++++++++++++++---- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java index 9a561bb2..56cc2c4a 100644 --- a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java +++ b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java @@ -204,7 +204,24 @@ public class FlashSceneController extends AbstractSubSteppedController implement @Override public void onStepSuccess(DataBundle bundle) { logger.debug("onStepSuccess"); - //Still not implemented + //Handle old stuff first + UiUtils.hideNode(stepTitleLabel); + //@TODO : change below instruction because it isn't displayed on step of load type. + instructionsFlow.getChildren().clear(); + parentController.setNextButtonVisible(false); + + //add new stuff + instructionsFlow.getChildren().add(new Label(stepTitleLabel.getText()+" succeed!")); + Button okBtn = new Button("Ok"); //@TODO: the button is display on same line as text. This isn't what I want + okBtn.setOnMouseClicked(( MouseEvent event) -> { + synchronized(pauseLock){ + logger.debug("notify pause lock"); + pauseLock.notify(); + } + parentController.setNextButtonVisible(true); + }); + + instructionsFlow.getChildren().add(okBtn); } diff --git a/src/main/java/ecorp/easy/installer/threads/FlashThread.java b/src/main/java/ecorp/easy/installer/threads/FlashThread.java index fed999f5..1d6ad21b 100644 --- a/src/main/java/ecorp/easy/installer/threads/FlashThread.java +++ b/src/main/java/ecorp/easy/installer/threads/FlashThread.java @@ -229,11 +229,7 @@ public class FlashThread extends Thread { if(stepType.equals(AppConstants.ASK_ACCOUNT_KEY) || stepType.equals(AppConstants.UNLOCK_OEM_KEY)) { - try{ - synchronized(pauseLock){ pauseLock.wait(); } - }catch (InterruptedException e) { - logger.error("error = "+e.toString()); - } + waitPauseLock(); } } @@ -246,10 +242,21 @@ public class FlashThread extends Thread { protected void doAfterToRunCommand() throws Exception{ atLeastOneError = (atLeastOneError || !success || cancelled); sendIssueLog = (atLeastOneError && !cancelled); - if(success){ + + final Command cmd = commands.get(currentStepCode); + + final String stepType = cmd.getNewUIValues().getType(); + + if(success + //Show only for "action" or "load" step + && !stepType.equals(AppConstants.ASK_ACCOUNT_KEY) + && !stepType.equals(AppConstants.UNLOCK_OEM_KEY) ) + { + //Update UI Platform.runLater(()->{ application.onStepSuccess(null); }); + waitPauseLock(); } } @@ -281,6 +288,17 @@ public class FlashThread extends Thread { }); } + /** + * Block the thread until pauseLock.notify() is called + */ + private void waitPauseLock(){ + try{ + synchronized(pauseLock){ pauseLock.wait(); } + }catch (InterruptedException e) { + logger.error("error = "+e.toString()); + } + } + protected void runInitialization() { running = true; } -- GitLab From c6b95a05db52599e35853a7e9d50207c2cb1ed38 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 21 Jan 2021 19:09:17 +0100 Subject: [PATCH 3/3] update FlashSceneController.onStepSuccess --- .../subcontrollers/FlashSceneController.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java index 56cc2c4a..69213286 100644 --- a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java +++ b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java @@ -205,23 +205,43 @@ public class FlashSceneController extends AbstractSubSteppedController implement public void onStepSuccess(DataBundle bundle) { logger.debug("onStepSuccess"); //Handle old stuff first - UiUtils.hideNode(stepTitleLabel); + + UiUtils.hideNode(instructionsVBox); + UiUtils.hideNode(instructionImage); + UiUtils.hideNode(stepTitleIcon); + //@TODO : change below instruction because it isn't displayed on step of load type. instructionsFlow.getChildren().clear(); parentController.setNextButtonVisible(false); - //add new stuff + //Create new stuff + final VBox successContainer = new VBox(); + successContainer.setAlignment(Pos.TOP_LEFT); + final Label successLabel = new Label(" Step succeed!"); + final Button okBtn = new Button("Ok"); //@TODO: the button is display on same line as text. This isn't what I want + + final ObservableList containerChildren = instructionsContainer.getChildren(); + instructionsFlow.getChildren().add(new Label(stepTitleLabel.getText()+" succeed!")); - Button okBtn = new Button("Ok"); //@TODO: the button is display on same line as text. This isn't what I want okBtn.setOnMouseClicked(( MouseEvent event) -> { + //Remove success node + containerChildren.remove(successContainer); + //Display again instructionsVBox, image and icon + //NOTE: there will probably be an issue with load step type + UiUtils.showNode(instructionsVBox); + UiUtils.showNode(instructionImage); + UiUtils.showNode(stepTitleIcon); + + //Unlock Flash Thread synchronized(pauseLock){ - logger.debug("notify pause lock"); pauseLock.notify(); } + parentController.setNextButtonVisible(true); }); - - instructionsFlow.getChildren().add(okBtn); + + successContainer.getChildren().addAll(successLabel, okBtn); + containerChildren.add(successContainer); } -- GitLab