From 2a8046a97e22e678ea9d81376e98ad839a668f4f Mon Sep 17 00:00:00 2001 From: Rohit Awate Date: Mon, 27 Aug 2018 15:14:29 +0530 Subject: [PATCH] Add checks in DashboardController while applying state to check if it belongs to active state --- .../controllers/DashboardController.java | 33 +++++++++++++++---- .../controllers/HomeWindowController.java | 7 ++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java index e6bdfa4..05e7c4a 100644 --- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java +++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java @@ -76,12 +76,12 @@ public class DashboardController implements Initializable { @FXML ComboBox httpMethodBox, responseTypeBox; @FXML - private VBox responseBox, responseLayer, loadingLayer, promptLayer, errorLayer, paramsBox; + private VBox responseLayer, loadingLayer, promptLayer, errorLayer, paramsBox; @FXML private Label statusCode, statusCodeDescription, responseTime, responseSize, errorTitle, errorDetails; @FXML - private JFXButton sendButton, cancelButton, copyBodyButton; + private JFXButton cancelButton, copyBodyButton; @FXML TabPane requestOptionsTab, responseTabPane; @FXML @@ -104,9 +104,10 @@ public class DashboardController implements Initializable { private GETRequest getRequest; private DataRequest dataRequest; private DELETERequest deleteRequest; - private HashMap params; private EverestCodeArea responseArea; private ResponseLayer visibleLayer; + private HashMap tabStateMap; + private TabPane tabPane; public enum ResponseLayer { PROMPT, LOADING, RESPONSE, ERROR @@ -706,6 +707,21 @@ public class DashboardController implements Initializable { if (state == null) return; + /* + Sanity check to ensure that the state being applied belongs to the active tab. + Everest works perfectly almost every time despite the 4 lines that follow this comment, + but some moronic testers like me might obliterate their Ctrl + Tab key combo. + While switching between tabs at such speeds that approach that of light, + Everest might apply the state to some other tab. + + This may happen when a RequestManager that was handed over + to a DashboardState were to change its state during a tab shift. + */ + Tab activeTab = tabPane.getSelectionModel().getSelectedItem(); + DashboardState activeState = tabStateMap.get(activeTab); + if (state != activeState) + state = activeState; + if (state.visibleComposerTab != null) { int tab; switch (state.visibleComposerTab) { @@ -812,9 +828,6 @@ public class DashboardController implements Initializable { } void clearParams() { - if (params != null) - params.clear(); - if (paramsControllers != null) paramsControllers.clear(); @@ -822,4 +835,12 @@ public class DashboardController implements Initializable { paramsCountProperty.set(0); addParamField(); } + + void setTabStateMap(HashMap tabStateMap) { + this.tabStateMap = tabStateMap; + } + + void setTabPane(TabPane tabPane) { + this.tabPane = tabPane; + } } diff --git a/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java b/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java index f383205..871e247 100644 --- a/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java +++ b/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java @@ -67,6 +67,9 @@ public class HomeWindowController implements Initializable { public void initialize(URL location, ResourceBundle resources) { syncManager = new SyncManager(this); + // Using LinkedHashMap because it retains order + tabStateMap = new LinkedHashMap<>(); + try { FXMLLoader historyLoader = new FXMLLoader(getClass().getResource("/fxml/homewindow/HistoryPane.fxml")); Parent historyFXML = historyLoader.load(); @@ -79,14 +82,14 @@ public class HomeWindowController implements Initializable { Parent dashboardFXML = dashboardLoader.load(); dashboard = dashboardLoader.getController(); dashboard.setSyncManager(syncManager); + dashboard.setTabPane(tabPane); + dashboard.setTabStateMap(tabStateMap); dashboardContainer.getChildren().add(dashboardFXML); addressProperty = dashboard.addressField.textProperty(); } catch (IOException e) { e.printStackTrace(); } - // Using LinkedHashMap because it retains order - tabStateMap = new LinkedHashMap<>(); recoverState(); homeWindowSP.setFocusTraversable(true);