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
ComboBox<String> 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<String, String> params;
private EverestCodeArea responseArea;
private ResponseLayer visibleLayer;
private HashMap<Tab, DashboardState> 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<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) {
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);