Re-implemented logic for changing tab-text with URL

This commit is contained in:
Rohit Awate 2018-07-18 22:58:47 +05:30
parent cef97f0fec
commit 32dcc0bce2
2 changed files with 36 additions and 28 deletions

View file

@ -119,14 +119,14 @@ public class DashboardController implements Initializable {
headerTabController = headerTabLoader.getController();
headersTab.setContent(headerTabContent);
// Loading the rawBody tab
// Loading the body tab
FXMLLoader bodyTabLoader = new FXMLLoader(getClass().getResource("/fxml/homewindow/BodyTab.fxml"));
Parent bodyTabContent = bodyTabLoader.load();
ThemeManager.setTheme(bodyTabContent);
bodyTabController = bodyTabLoader.getController();
bodyTab.setContent(bodyTabContent);
} catch (IOException e) {
Services.loggingService.logSevere("Could not load headers/rawBody tabs.", e, LocalDateTime.now());
Services.loggingService.logSevere("Could not load headers/body tabs.", e, LocalDateTime.now());
}
snackbar = new JFXSnackbar(dashboard);
@ -360,7 +360,7 @@ public class DashboardController implements Initializable {
if (requestManager.getClass() == DataDispatchRequestManager.class) {
if (throwable.getCause() != null && throwable.getCause().getClass() == IllegalArgumentException.class) {
errorTitle.setText("Did you forget something?");
errorDetails.setText("Please specify at least one rawBody part for your " + httpMethodBox.getValue() + " request.");
errorDetails.setText("Please specify a body for your " + httpMethodBox.getValue() + " request.");
} else if (throwable.getClass() == FileNotFoundException.class) {
errorTitle.setText("File(s) not found:");
errorDetails.setText(throwable.getMessage());
@ -372,23 +372,20 @@ public class DashboardController implements Initializable {
}
private void onCancelled() {
loadingLayer.setVisible(false);
promptLayer.setVisible(true);
displayLayer(ResponseLayer.PROMPT);
snackbar.show("Request canceled.", 2000);
requestManager.reset();
}
private void onSucceeded() {
displayResponse(requestManager.getValue());
errorLayer.setVisible(false);
loadingLayer.setVisible(false);
displayLayer(ResponseLayer.RESPONSE);
requestManager.reset();
}
private void whileRunning() {
responseArea.clear();
errorLayer.setVisible(false);
loadingLayer.setVisible(true);
displayLayer(ResponseLayer.LOADING);
}
private void displayLayer(ResponseLayer layer) {

View file

@ -58,6 +58,7 @@ public class HomeWindowController implements Initializable {
private HashMap<Tab, DashboardState> tabStateMap;
private HistoryPaneController historyController;
private DashboardController dashboard;
private StringProperty addressProperty;
@Override
public void initialize(URL location, ResourceBundle resources) {
@ -72,6 +73,7 @@ public class HomeWindowController implements Initializable {
Parent dashboardFXML = dashboardLoader.load();
dashboard = dashboardLoader.getController();
dashboardContainer.getChildren().add(dashboardFXML);
addressProperty = dashboard.addressField.textProperty();
} catch (IOException e) {
e.printStackTrace();
}
@ -139,25 +141,6 @@ public class HomeWindowController implements Initializable {
private void addTab(ComposerState composerState) {
Tab newTab = new Tab();
StringProperty addressProperty = dashboard.addressField.textProperty();
newTab.textProperty().bind(
Bindings.when(addressProperty.isNotEmpty())
.then(addressProperty)
.otherwise("New Tab"));
newTab.setOnCloseRequest(e -> {
tabStateMap.remove(newTab);
tabPane.getTabs().remove(newTab);
// Closes the application if the last tab is closed
if (tabPane.getTabs().size() == 0) {
saveState();
Stage thisStage = (Stage) homeWindowSP.getScene().getWindow();
thisStage.close();
}
});
DashboardState newState = new DashboardState(composerState);
tabStateMap.put(newTab, newState);
@ -174,6 +157,34 @@ public class HomeWindowController implements Initializable {
tabPane.getTabs().add(newTab);
tabPane.getSelectionModel().select(newTab);
onTabSwitched(prevState, prevTab, newTab);
// Makes the Tab's text change with the URL
newTab.textProperty().bind(
Bindings.when(Bindings.and(addressProperty.isNotEmpty(), newTab.selectedProperty()))
.then(addressProperty)
.otherwise(getTabText(newTab))
);
newTab.setOnCloseRequest(e -> {
tabStateMap.remove(newTab);
tabPane.getTabs().remove(newTab);
// Closes the application if the last tab is closed
if (tabPane.getTabs().size() == 0) {
saveState();
Stage thisStage = (Stage) homeWindowSP.getScene().getWindow();
thisStage.close();
}
});
}
private String getTabText(Tab newTab) {
DashboardState state = tabStateMap.get(newTab);
if (state == null || state.composer == null || state.composer.target.equals(""))
return "New Tab";
else
return state.composer.target;
}
private void saveState() {