Skip to content

Commit

Permalink
CSSTUDIO-1989 Bugfix: ensure that a Scene has been created before ini…
Browse files Browse the repository at this point in the history
…tializing splitPlane. Add case for when oldCenterPane is an instance of SplitPane.
  • Loading branch information
abrahamwolk committed Apr 15, 2024
1 parent a1e676e commit a0c55b0
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToolBar;
Expand All @@ -11,12 +12,14 @@
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.Window;
import org.phoebus.framework.persistence.Memento;
import org.phoebus.framework.spi.AppDescriptor;
import org.phoebus.framework.spi.AppInstance;
import org.phoebus.ui.application.PhoebusApplication;
import org.phoebus.ui.docking.DockPane;
import org.phoebus.ui.docking.DockStage;
import org.phoebus.ui.docking.SplitDock;
import org.phoebus.ui.javafx.ImageCache;

import java.awt.geom.Rectangle2D;
Expand Down Expand Up @@ -49,18 +52,8 @@ public NavigatorInstance(NavigatorAppResourceDescriptor navigatorAppResourceDesc
}

navigator = navigatorAppResourceDescriptor;
BorderPane borderPane = DockStage.getLayout((Stage) DockPane.getActiveDockPane().getScene().getWindow());

Node oldCenterPane = borderPane.getCenter();
SplitPane splitPane = new SplitPane(oldCenterPane);
borderPane.setCenter(splitPane);
if (oldCenterPane instanceof DockPane) {
DockPane dockPane = (DockPane) oldCenterPane;
dockPane.setDockParent(splitPane);
}
else {
throw new RuntimeException("Error loading navigator: object of type 'DockPane' expected, but received object of type '" + oldCenterPane.getClass().toString() + "'.");
}

SplitPane splitPane = new SplitPane();

phoebusApplicationToolbar = PhoebusApplication.INSTANCE.getToolbar();
ImageView homeIcon = ImageCache.getImageView(ImageCache.class, "/icons/navigator.png");
Expand Down Expand Up @@ -88,6 +81,23 @@ public NavigatorInstance(NavigatorAppResourceDescriptor navigatorAppResourceDesc
phoebusApplicationToolbar.getItems().add(0, navigatorButton);

DockPane.getActiveDockPane().deferUntilInScene(scene -> {

Stage activeWindow = (Stage) scene.getWindow();
BorderPane borderPane = DockStage.getLayout(activeWindow);

Node oldCenterPane = borderPane.getCenter();
splitPane.getItems().add(oldCenterPane);
borderPane.setCenter(splitPane);
if (oldCenterPane instanceof DockPane dockPane) {
dockPane.setDockParent(splitPane);
}
else if (oldCenterPane instanceof SplitPane oldSplitPane) {
// Do nothing.
}
else {
throw new RuntimeException("Error loading navigator: object of type 'DockPane' expected, but received object of type '" + oldCenterPane.getClass().toString() + "'.");
}

var window = scene.getWindow();
window.addEventFilter(KeyEvent.KEY_PRESSED, keyEvent -> {
if (keyEvent.isControlDown() && keyEvent.isShiftDown()) {
Expand Down

0 comments on commit a0c55b0

Please sign in to comment.