Add checks in DashboardController while applying state to check if it belongs to active state

This commit is contained in:
Rohit Awate 2018-08-27 15:14:29 +05:30
parent 4b1ba0c80a
commit 2a8046a97e
No known key found for this signature in database
GPG key ID: 1051D7B79CF2EE25
2 changed files with 32 additions and 8 deletions

View file

@ -76,12 +76,12 @@ public class DashboardController implements Initializable {
@FXML @FXML
ComboBox<String> httpMethodBox, responseTypeBox; ComboBox<String> httpMethodBox, responseTypeBox;
@FXML @FXML
private VBox responseBox, responseLayer, loadingLayer, promptLayer, errorLayer, paramsBox; private VBox responseLayer, loadingLayer, promptLayer, errorLayer, paramsBox;
@FXML @FXML
private Label statusCode, statusCodeDescription, responseTime, private Label statusCode, statusCodeDescription, responseTime,
responseSize, errorTitle, errorDetails; responseSize, errorTitle, errorDetails;
@FXML @FXML
private JFXButton sendButton, cancelButton, copyBodyButton; private JFXButton cancelButton, copyBodyButton;
@FXML @FXML
TabPane requestOptionsTab, responseTabPane; TabPane requestOptionsTab, responseTabPane;
@FXML @FXML
@ -104,9 +104,10 @@ public class DashboardController implements Initializable {
private GETRequest getRequest; private GETRequest getRequest;
private DataRequest dataRequest; private DataRequest dataRequest;
private DELETERequest deleteRequest; private DELETERequest deleteRequest;
private HashMap<String, String> params;
private EverestCodeArea responseArea; private EverestCodeArea responseArea;
private ResponseLayer visibleLayer; private ResponseLayer visibleLayer;
private HashMap<Tab, DashboardState> tabStateMap;
private TabPane tabPane;
public enum ResponseLayer { public enum ResponseLayer {
PROMPT, LOADING, RESPONSE, ERROR PROMPT, LOADING, RESPONSE, ERROR
@ -706,6 +707,21 @@ public class DashboardController implements Initializable {
if (state == null) if (state == null)
return; 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) { if (state.visibleComposerTab != null) {
int tab; int tab;
switch (state.visibleComposerTab) { switch (state.visibleComposerTab) {
@ -812,9 +828,6 @@ public class DashboardController implements Initializable {
} }
void clearParams() { void clearParams() {
if (params != null)
params.clear();
if (paramsControllers != null) if (paramsControllers != null)
paramsControllers.clear(); paramsControllers.clear();
@ -822,4 +835,12 @@ public class DashboardController implements Initializable {
paramsCountProperty.set(0); paramsCountProperty.set(0);
addParamField(); addParamField();
} }
void setTabStateMap(HashMap<Tab, DashboardState> tabStateMap) {
this.tabStateMap = tabStateMap;
}
void setTabPane(TabPane tabPane) {
this.tabPane = tabPane;
}
} }

View file

@ -67,6 +67,9 @@ public class HomeWindowController implements Initializable {
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
syncManager = new SyncManager(this); syncManager = new SyncManager(this);
// Using LinkedHashMap because it retains order
tabStateMap = new LinkedHashMap<>();
try { try {
FXMLLoader historyLoader = new FXMLLoader(getClass().getResource("/fxml/homewindow/HistoryPane.fxml")); FXMLLoader historyLoader = new FXMLLoader(getClass().getResource("/fxml/homewindow/HistoryPane.fxml"));
Parent historyFXML = historyLoader.load(); Parent historyFXML = historyLoader.load();
@ -79,14 +82,14 @@ public class HomeWindowController implements Initializable {
Parent dashboardFXML = dashboardLoader.load(); Parent dashboardFXML = dashboardLoader.load();
dashboard = dashboardLoader.getController(); dashboard = dashboardLoader.getController();
dashboard.setSyncManager(syncManager); dashboard.setSyncManager(syncManager);
dashboard.setTabPane(tabPane);
dashboard.setTabStateMap(tabStateMap);
dashboardContainer.getChildren().add(dashboardFXML); dashboardContainer.getChildren().add(dashboardFXML);
addressProperty = dashboard.addressField.textProperty(); addressProperty = dashboard.addressField.textProperty();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
// Using LinkedHashMap because it retains order
tabStateMap = new LinkedHashMap<>();
recoverState(); recoverState();
homeWindowSP.setFocusTraversable(true); homeWindowSP.setFocusTraversable(true);