Skip to content

Commit

Permalink
CSSTUDIO-1989 Fix the logic to place the tab of a newly opened instan…
Browse files Browse the repository at this point in the history
…ce correctly.
  • Loading branch information
abrahamwolk committed Apr 15, 2024
1 parent 72854bb commit bc3651d
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.function.Consumer;
import java.util.function.Supplier;

import static org.phoebus.applications.display.navigator.NavigatorController.OPI_ROOT;

Expand Down Expand Up @@ -110,10 +111,12 @@ private static Consumer<Target> createLoadAction_DataBrowser(String relativePath
navigatorController.disableNavigator();
DataBrowserApp dataBrowserApp = new DataBrowserApp();

Runnable createDataBrowserInstance = () -> {
Supplier<DockItem> createDataBrowserInstance = () -> {
try {
DataBrowserInstance dataBrowserInstance = dataBrowserApp.create();
dataBrowserInstance.loadResource(new URI("file:" + OPI_ROOT + relativePath));

return dataBrowserInstance.getDockItem();
}
catch (URISyntaxException uriSyntaxException) {
throw new RuntimeException(uriSyntaxException.getMessage());
Expand Down Expand Up @@ -142,10 +145,12 @@ private static Consumer<Target> createLoadAction_OPI(String absolutePath,
navigatorController.enableNavigator();
}
else {
Runnable createDisplayRuntimeInstance = () -> {
Supplier<DockItem> createDisplayRuntimeInstance = () -> {
DisplayRuntimeApplication displayRuntimeApplication = new DisplayRuntimeApplication();
DisplayRuntimeInstance displayRuntimeInstance = displayRuntimeApplication.create();
displayRuntimeInstance.loadDisplayFile(new DisplayInfo(absolutePath, "Name", new Macros(), false));

return displayRuntimeInstance.getDockItem();
};

openAppInstance(createDisplayRuntimeInstance, navigatorController, target);
Expand All @@ -155,7 +160,7 @@ private static Consumer<Target> createLoadAction_OPI(String absolutePath,
}


private static void openAppInstance(Runnable createAppInstance,
private static void openAppInstance(Supplier<DockItem> createAppInstance,
NavigatorController navigatorController,
Target target) {
DockPane activeDockPane = DockPane.getActiveDockPane();
Expand All @@ -181,15 +186,11 @@ private static void openAppInstance(Runnable createAppInstance,
if (shouldProceed) {
Platform.runLater(() -> {
activeDockPane.setStyle("-fx-open-tab-animation: NONE; -fx-close-tab-animation: NONE;");
createAppInstance.run();

int indexOfAddedItem = activeDockPane.getDockItems().size() - 1;
if (indexOfAddedItem > 0) {
// The instance is not the only running instance.
Tab dataBrowserDockItem = activeDockItems.get(indexOfAddedItem);
activeDockItems.remove(dataBrowserDockItem);
activeDockItems.add(indexOfActiveDockItem + 1, dataBrowserDockItem);
}

DockItem dockItemOfCreatedApplication = createAppInstance.get(); // The new application instance may not have been created in activeDockPane if the navigator is located in a different window from activeDockPane.

dockItemOfCreatedApplication.getDockPane().getTabs().remove(dockItemOfCreatedApplication);
activeDockItems.add(indexOfActiveDockItem + 1, dockItemOfCreatedApplication);

if (target == Target.CurrentTab || target == Target.NewTab) {
activeDockPane.getSelectionModel().select(indexOfActiveDockItem + 1);
Expand Down

0 comments on commit bc3651d

Please sign in to comment.