Re-implemented logic for changing tab-text with URL
This commit is contained in:
parent
cef97f0fec
commit
32dcc0bce2
2 changed files with 36 additions and 28 deletions
|
@ -119,14 +119,14 @@ public class DashboardController implements Initializable {
|
||||||
headerTabController = headerTabLoader.getController();
|
headerTabController = headerTabLoader.getController();
|
||||||
headersTab.setContent(headerTabContent);
|
headersTab.setContent(headerTabContent);
|
||||||
|
|
||||||
// Loading the rawBody tab
|
// Loading the body tab
|
||||||
FXMLLoader bodyTabLoader = new FXMLLoader(getClass().getResource("/fxml/homewindow/BodyTab.fxml"));
|
FXMLLoader bodyTabLoader = new FXMLLoader(getClass().getResource("/fxml/homewindow/BodyTab.fxml"));
|
||||||
Parent bodyTabContent = bodyTabLoader.load();
|
Parent bodyTabContent = bodyTabLoader.load();
|
||||||
ThemeManager.setTheme(bodyTabContent);
|
ThemeManager.setTheme(bodyTabContent);
|
||||||
bodyTabController = bodyTabLoader.getController();
|
bodyTabController = bodyTabLoader.getController();
|
||||||
bodyTab.setContent(bodyTabContent);
|
bodyTab.setContent(bodyTabContent);
|
||||||
} catch (IOException e) {
|
} 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);
|
snackbar = new JFXSnackbar(dashboard);
|
||||||
|
@ -360,7 +360,7 @@ public class DashboardController implements Initializable {
|
||||||
if (requestManager.getClass() == DataDispatchRequestManager.class) {
|
if (requestManager.getClass() == DataDispatchRequestManager.class) {
|
||||||
if (throwable.getCause() != null && throwable.getCause().getClass() == IllegalArgumentException.class) {
|
if (throwable.getCause() != null && throwable.getCause().getClass() == IllegalArgumentException.class) {
|
||||||
errorTitle.setText("Did you forget something?");
|
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) {
|
} else if (throwable.getClass() == FileNotFoundException.class) {
|
||||||
errorTitle.setText("File(s) not found:");
|
errorTitle.setText("File(s) not found:");
|
||||||
errorDetails.setText(throwable.getMessage());
|
errorDetails.setText(throwable.getMessage());
|
||||||
|
@ -372,23 +372,20 @@ public class DashboardController implements Initializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onCancelled() {
|
private void onCancelled() {
|
||||||
loadingLayer.setVisible(false);
|
displayLayer(ResponseLayer.PROMPT);
|
||||||
promptLayer.setVisible(true);
|
|
||||||
snackbar.show("Request canceled.", 2000);
|
snackbar.show("Request canceled.", 2000);
|
||||||
requestManager.reset();
|
requestManager.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSucceeded() {
|
private void onSucceeded() {
|
||||||
displayResponse(requestManager.getValue());
|
displayResponse(requestManager.getValue());
|
||||||
errorLayer.setVisible(false);
|
displayLayer(ResponseLayer.RESPONSE);
|
||||||
loadingLayer.setVisible(false);
|
|
||||||
requestManager.reset();
|
requestManager.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void whileRunning() {
|
private void whileRunning() {
|
||||||
responseArea.clear();
|
responseArea.clear();
|
||||||
errorLayer.setVisible(false);
|
displayLayer(ResponseLayer.LOADING);
|
||||||
loadingLayer.setVisible(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayLayer(ResponseLayer layer) {
|
private void displayLayer(ResponseLayer layer) {
|
||||||
|
|
|
@ -58,6 +58,7 @@ public class HomeWindowController implements Initializable {
|
||||||
private HashMap<Tab, DashboardState> tabStateMap;
|
private HashMap<Tab, DashboardState> tabStateMap;
|
||||||
private HistoryPaneController historyController;
|
private HistoryPaneController historyController;
|
||||||
private DashboardController dashboard;
|
private DashboardController dashboard;
|
||||||
|
private StringProperty addressProperty;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
@ -72,6 +73,7 @@ public class HomeWindowController implements Initializable {
|
||||||
Parent dashboardFXML = dashboardLoader.load();
|
Parent dashboardFXML = dashboardLoader.load();
|
||||||
dashboard = dashboardLoader.getController();
|
dashboard = dashboardLoader.getController();
|
||||||
dashboardContainer.getChildren().add(dashboardFXML);
|
dashboardContainer.getChildren().add(dashboardFXML);
|
||||||
|
addressProperty = dashboard.addressField.textProperty();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -139,25 +141,6 @@ public class HomeWindowController implements Initializable {
|
||||||
private void addTab(ComposerState composerState) {
|
private void addTab(ComposerState composerState) {
|
||||||
Tab newTab = new Tab();
|
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);
|
DashboardState newState = new DashboardState(composerState);
|
||||||
tabStateMap.put(newTab, newState);
|
tabStateMap.put(newTab, newState);
|
||||||
|
|
||||||
|
@ -174,6 +157,34 @@ public class HomeWindowController implements Initializable {
|
||||||
tabPane.getTabs().add(newTab);
|
tabPane.getTabs().add(newTab);
|
||||||
tabPane.getSelectionModel().select(newTab);
|
tabPane.getSelectionModel().select(newTab);
|
||||||
onTabSwitched(prevState, prevTab, 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() {
|
private void saveState() {
|
||||||
|
|
Loading…
Reference in a new issue