From d9d0ceead2dbbe1c31d6e1c9101102f3ac3dc527 Mon Sep 17 00:00:00 2001 From: Rohit Awate Date: Tue, 24 Jul 2018 17:28:12 +0530 Subject: [PATCH] Add maintenance logic for the selected status of tabs from Composer and ResponseTabPane --- .../controllers/DashboardController.java | 83 +++++++++++++++++-- .../controllers/HomeWindowController.java | 3 +- .../controllers/state/DashboardState.java | 10 ++- 3 files changed, 87 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java index 3eb60ac..07f7fef 100644 --- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java +++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java @@ -110,6 +110,14 @@ public class DashboardController implements Initializable { PROMPT, LOADING, RESPONSE, ERROR } + public enum ResponseTab { + BODY, VISUALIZER, HEADERS + } + + public enum ComposerTab { + PARAMS, AUTH, HEADERS, BODY + } + @Override public void initialize(URL url, ResourceBundle rb) { try { @@ -426,6 +434,22 @@ public class DashboardController implements Initializable { responseTime.setText(Long.toString(state.responseTime) + " ms"); responseSize.setText(Integer.toString(state.responseSize) + " B"); responseHeadersViewer.populate(state.responseHeaders); + + if (state.visibleResponseTab != null) { + int tab; + switch (state.visibleResponseTab) { + case VISUALIZER: + tab = 1; + break; + case HEADERS: + tab = 2; + break; + default: + tab = 0; + } + + responseTabPane.getSelectionModel().select(tab); + } } private void prettifyResponseBody(String body, String contentType) { @@ -501,6 +525,7 @@ public class DashboardController implements Initializable { private void clearResponseArea() { responseArea.clear(); showLayer(ResponseLayer.PROMPT); + addressField.requestFocus(); } @FXML @@ -586,6 +611,33 @@ public class DashboardController implements Initializable { } } + public ComposerTab getVisibleComposerTab() { + int visibleTab = requestOptionsTab.getSelectionModel().getSelectedIndex(); + switch (visibleTab) { + case 1: + return ComposerTab.AUTH; + case 2: + return ComposerTab.HEADERS; + case 3: + return ComposerTab.BODY; + default: + return ComposerTab.PARAMS; + } + } + + + private ResponseTab getVisibleResponseTab() { + int visibleTab = responseTabPane.getSelectionModel().getSelectedIndex(); + switch (visibleTab) { + case 1: + return ResponseTab.VISUALIZER; + case 2: + return ResponseTab.HEADERS; + default: + return ResponseTab.BODY; + } + } + /** * @return Current state of the Dashboard. */ @@ -610,10 +662,12 @@ public class DashboardController implements Initializable { composerState.params = getParamFieldStates(); dashboardState.composer = composerState; - dashboardState.visibleLayer = visibleLayer; + dashboardState.visibleResponseLayer = visibleLayer; + dashboardState.visibleComposerTab = getVisibleComposerTab(); switch (visibleLayer) { case RESPONSE: + dashboardState.visibleResponseTab = getVisibleResponseTab(); dashboardState.responseHeaders = responseHeadersViewer.getHeaders(); dashboardState.responseCode = Integer.parseInt(statusCode.getText()); @@ -665,8 +719,27 @@ public class DashboardController implements Initializable { if (state == null) return; - if (state.visibleLayer != null) { - switch (state.visibleLayer) { + if (state.visibleComposerTab != null) { + int tab; + switch (state.visibleComposerTab) { + case AUTH: + tab = 1; + break; + case HEADERS: + tab = 2; + break; + case BODY: + tab = 3; + break; + default: + tab = 0; + } + + requestOptionsTab.getSelectionModel().select(tab); + } + + if (state.visibleResponseLayer != null) { + switch (state.visibleResponseLayer) { case RESPONSE: showResponse(state); break; @@ -676,10 +749,10 @@ public class DashboardController implements Initializable { showLayer(ResponseLayer.ERROR); break; } - if (state.visibleLayer.equals(ResponseLayer.RESPONSE)) + if (state.visibleResponseLayer.equals(ResponseLayer.RESPONSE)) showResponse(state); else - showLayer(state.visibleLayer); + showLayer(state.visibleResponseLayer); } if (state.composer == null) diff --git a/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java b/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java index 7663852..f3d3de1 100644 --- a/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java +++ b/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java @@ -186,7 +186,8 @@ public class HomeWindowController implements Initializable { onTabSwitched(prevState, prevTab, newTab); newTab.setOnCloseRequest(e -> { - tabStateMap.remove(newTab); + DashboardState closedState = tabStateMap.remove(newTab); + closedState = null; tabPane.getTabs().remove(newTab); // Closes the application if the last tab is closed diff --git a/src/main/java/com/rohitawate/everest/controllers/state/DashboardState.java b/src/main/java/com/rohitawate/everest/controllers/state/DashboardState.java index 5b6c3d3..4261afa 100644 --- a/src/main/java/com/rohitawate/everest/controllers/state/DashboardState.java +++ b/src/main/java/com/rohitawate/everest/controllers/state/DashboardState.java @@ -16,7 +16,9 @@ package com.rohitawate.everest.controllers.state; +import com.rohitawate.everest.controllers.DashboardController.ComposerTab; import com.rohitawate.everest.controllers.DashboardController.ResponseLayer; +import com.rohitawate.everest.controllers.DashboardController.ResponseTab; import com.rohitawate.everest.exceptions.RedirectException; import com.rohitawate.everest.exceptions.UnreliableResponseException; import com.rohitawate.everest.misc.Services; @@ -35,7 +37,9 @@ import java.util.HashMap; public class DashboardState { public ComposerState composer; - public ResponseLayer visibleLayer; + public ResponseLayer visibleResponseLayer; + public ResponseTab visibleResponseTab; + public ComposerTab visibleComposerTab; // ResponseLayer parameters public int responseCode; @@ -62,7 +66,7 @@ public class DashboardState { } private void onRequestSucceeded(Event e) { - this.visibleLayer = ResponseLayer.RESPONSE; + this.visibleResponseLayer = ResponseLayer.RESPONSE; EverestResponse response = requestManager.getValue(); responseCode = response.getStatusCode(); responseType = response.getMediaType().toString(); @@ -79,7 +83,7 @@ public class DashboardState { } private void onRequestFailed(Event e) { - this.visibleLayer = ResponseLayer.ERROR; + this.visibleResponseLayer = ResponseLayer.ERROR; Throwable throwable = requestManager.getException(); Exception exception = (Exception) throwable; Services.loggingService.logWarning(this.composer.httpMethod + " request could not be processed.", exception, LocalDateTime.now());