Java Code Examples for javafx.scene.control.Tab#setOnCloseRequest()
The following examples show how to use
javafx.scene.control.Tab#setOnCloseRequest() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HomeWindowController.java From Everest with Apache License 2.0 | 5 votes |
/** * Adds a new tab to the tabPane initialized with * the ComposerState provided. */ private void addTab(ComposerState composerState) { Tab newTab = new Tab(); /* Initializing the tab text based on the target in the ComposerState. Further handling of the tab text is done by onTargetChanged(). */ String target = composerState.target; if (target == null || target.equals("")) newTab.setText("New Tab"); else newTab.setText(target); DashboardState newState = new DashboardState(composerState); tabStateMap.put(newTab, newState); /* DO NOT mess with the following code. The sequence of these steps is very crucial: 1. Get the currently selected tab. 2. Get the current state of the dashboard to save to the map. 3. Add the new tab, since the previous state is now with us. 4. Switch to the new tab. 5. Call onTabSwitched() to update the Dashboard and save the oldState. */ Tab prevTab = tabPane.getSelectionModel().getSelectedItem(); DashboardState prevState = dashboard.getState(); tabPane.getTabs().add(newTab); tabPane.getSelectionModel().select(newTab); onTabSwitched(prevState, prevTab, newTab); newTab.setOnCloseRequest(e -> { removeTab(newTab); // Closes the application if the last tab is closed if (tabPane.getTabs().size() == 0) { saveState(); Stage thisStage = (Stage) homeWindowSP.getScene().getWindow(); thisStage.close(); } }); }
Example 2
Source File: HomeWindowController.java From Everest with Apache License 2.0 | 5 votes |
private void removeTab(Tab newTab) { DashboardState state = tabStateMap.remove(newTab); state = null; tabPane.getTabs().remove(newTab); newTab.setOnCloseRequest(null); newTab = null; }
Example 3
Source File: TabDockingContainer.java From marathonv5 with Apache License 2.0 | 5 votes |
private Tab newTab(Dockable dockable) { DockKey dockKey = dockable.getDockKey(); Tab tab = new Tab(dockKey.getName(), dockable.getComponent()); if (dockKey.getPolicy() == TabPolicy.NotClosable) { tab.setClosable(false); } if (dockKey.isCloseOptionsNeeded()) { MenuItem closeMenuItem = new MenuItem("Close"); closeMenuItem.setOnAction((e) -> requestClose(tab)); ContextMenu contextMenu = new ContextMenu(closeMenuItem); contextMenu.showingProperty().addListener((obs, wasShowing, isNowShowing) -> { if (isNowShowing) { populateMenuItems(contextMenu, tab); } }); tab.setContextMenu(contextMenu); } dockKey.nameProperty().addListener((event, o, n) -> tab.setText(n)); tab.setOnClosed((event) -> { remove(dockable); }); tab.setGraphic(dockKey.getIcon()); tab.setOnCloseRequest((event) -> { desktop.fireDockableStateWillChangeEvent(dockable, State.DOCKED, State.CLOSED, event); }); return tab; }
Example 4
Source File: PluginLoader.java From xJavaFxTool-spring with Apache License 2.0 | 5 votes |
public static void loadPluginAsTab(PluginJarInfo plugin, TabPane tabPane) { try { FXMLLoader generatingCodeFXMLLoader = new FXMLLoader(PluginLoader.class.getResource(plugin.getFxmlPath())); if (StringUtils.isNotEmpty(plugin.getBundleName())) { ResourceBundle resourceBundle = ResourceBundle.getBundle(plugin.getBundleName(), Config.defaultLocale); generatingCodeFXMLLoader.setResources(resourceBundle); } Tab tab = new Tab(plugin.getTitle()); if (StringUtils.isNotEmpty(plugin.getIconPath())) { ImageView imageView = new ImageView(new Image(plugin.getIconPath())); imageView.setFitHeight(18); imageView.setFitWidth(18); tab.setGraphic(imageView); } tab.setContent(generatingCodeFXMLLoader.load()); tabPane.getTabs().add(tab); tabPane.getSelectionModel().select(tab); tab.setOnCloseRequest( event -> JavaFxViewUtil.setControllerOnCloseRequest(generatingCodeFXMLLoader.getController(), event) ); } catch (Exception e) { log.error("加载插件失败", e); } }
Example 5
Source File: IdeController.java From jace with GNU General Public License v2.0 | 5 votes |
private Program createTab(DocumentType type, File document, boolean isBlank) { WebView editor = new WebView(); Program proxy = new Program(type, globalOptions); proxy.initEditor(editor, document, isBlank); Tab t = new Tab(proxy.getName(), editor); tabPane.getTabs().add(t); openDocuments.put(t, proxy); t.setOnCloseRequest(this::handleCloseTabRequest); return proxy; }
Example 6
Source File: BowlerStudioController.java From BowlerStudio with GNU General Public License v3.0 | 4 votes |
public ScriptingFileWidget createFileTab(File file) { if (openFiles.get(file.getAbsolutePath()) != null && widgets.get(file.getAbsolutePath()) != null) { BowlerStudioModularFrame.getBowlerStudioModularFrame() .setSelectedTab(openFiles.get(file.getAbsolutePath())); return widgets.get(file.getAbsolutePath()).getScripting(); } Tab fileTab = new Tab(file.getName()); openFiles.put(file.getAbsolutePath(), fileTab); try { Log.warning("Loading local file from: " + file.getAbsolutePath()); LocalFileScriptTab t = new LocalFileScriptTab(file); new Thread() { public void run() { BowlerStudioMenuWorkspace.add(t.getScripting().getGitRepo()); } }.start(); String key = t.getScripting().getGitRepo() + ":" + t.getScripting().getGitFile(); ArrayList<String> files = new ArrayList<>(); files.add(t.getScripting().getGitRepo()); files.add(t.getScripting().getGitFile()); if(key.length()>3 && files.get(0).length()>0 && files.get(1).length()>0)// catch degenerates ConfigurationDatabase.setObject("studio-open-git", key, files); fileTab.setContent(t); fileTab.setGraphic( AssetFactory.loadIcon("Script-Tab-" + ScriptingEngine.getShellType(file.getName()) + ".png")); addTab(fileTab, true); widgets.put(file.getAbsolutePath(), t); fileTab.setOnCloseRequest(event -> { widgets.remove(file.getAbsolutePath()); openFiles.remove(file.getAbsolutePath()); ConfigurationDatabase.removeObject("studio-open-git", key); t.getScripting().close(); System.out.println("Closing " + file.getAbsolutePath()); }); t.setFontSize(size); return t.getScripting(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
Example 7
Source File: DockCommons.java From AnchorFX with GNU Lesser General Public License v3.0 | 4 votes |
public static DockTabberContainer createTabber(Node existNode, Node newNode, DockNode.DockPosition position) { if (existNode instanceof DockNode && newNode instanceof DockNode) { DockNode existDockNode = (DockNode) existNode; DockNode newDockNode = (DockNode) newNode; DockTabberContainer tabber = new DockTabberContainer(); Tab existTabPanel = new Tab(existDockNode.getContent().titleProperty().get()); Tab newTabPanel = new Tab(newDockNode.getContent().titleProperty().get()); existTabPanel.setOnCloseRequest(event -> { if (existDockNode.getCloseRequestHandler() == null || existDockNode.getCloseRequestHandler().canClose()) { existDockNode.undock(); event.consume(); } }); newTabPanel.setOnCloseRequest(event -> { if (newDockNode.getCloseRequestHandler() == null || newDockNode.getCloseRequestHandler().canClose()) { newDockNode.undock(); event.consume(); } }); existTabPanel.closableProperty().bind(existDockNode.closeableProperty()); newTabPanel.closableProperty().bind(newDockNode.closeableProperty()); existTabPanel.setContent(existDockNode); newTabPanel.setContent(newDockNode); DockContainableComponent existContainableComponent = (DockContainableComponent) existNode; DockContainableComponent newContainableComponent = (DockContainableComponent) newNode; existContainableComponent.setParentContainer(tabber); newContainableComponent.setParentContainer(tabber); tabber.getTabs().addAll(existTabPanel, newTabPanel); tabber.getStyleClass().add("docknode-tab-pane"); newDockNode.ensureVisibility(); return tabber; } return null; }