public void addTab(Path path) {
AnchorPane anchorPane = new AnchorPane();
WebView webView = createWebView();
WebEngine webEngine = webView.getEngine();
webEngine.getLoadWorker().stateProperty().addListener((observableValue1, state, state2) -> {
if (state2 == Worker.State.SUCCEEDED) {
webEngine.executeScript(String.format("waitForSetValue('%s')", IOHelper.normalize(IOHelper.readFile(path))));
}
});
anchorPane.getChildren().add(webView);
fitToParent(webView);
Tab tab = createTab();
((Label) tab.getGraphic()).setText(path.getFileName().toString());
tab.setContent(anchorPane);
tab.selectedProperty().addListener((observableValue, before, after) -> {
if (after) {
current.putTab(tab, path, webView);
webEngine.executeScript("if((typeof waitForGetValue)!='undefined') waitForGetValue()");
}
});
current.putTab(tab, path, webView);
tabPane.getTabs().add(tab);