From 25e73cd033e08fc204daf26a2fbd1dfd8091ef84 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Wed, 25 Sep 2024 12:47:06 +0200 Subject: [PATCH 1/2] Fixed switch to save&restore UI from action button --- .../SaveAndRestoreApplication.java | 25 ++++++------------- .../SaveAndRestoreInstance.java | 23 ++++++++++------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/SaveAndRestoreApplication.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/SaveAndRestoreApplication.java index 4f3ceb286b..3cef8afefa 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/SaveAndRestoreApplication.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/SaveAndRestoreApplication.java @@ -37,8 +37,6 @@ public class SaveAndRestoreApplication implements AppResourceDescriptor { public static final String NAME = "saveandrestore"; public static final String DISPLAY_NAME = "Save And Restore"; - private AppInstance instance; - /** * Custom MIME type definition for the purpose of drag-n-drop in the */ @@ -62,30 +60,21 @@ public AppInstance create() { @Override public AppInstance create(URI uri) { - instance = null; - for (Stage stage : DockStage.getDockStages()) { - for (DockPane pane : DockStage.getDockPanes(stage)) { - for (DockItem tab : pane.getDockItems()) { - if (tab.getApplication().getAppDescriptor().getName().equals(NAME)) { - tab.select(); - instance = tab.getApplication(); - } - } - } + if(SaveAndRestoreInstance.INSTANCE == null){ + SaveAndRestoreInstance.INSTANCE = new SaveAndRestoreInstance(this); } - if(instance == null){ - instance = new SaveAndRestoreInstance(this); + else{ + SaveAndRestoreInstance.INSTANCE.raise(); } - ((SaveAndRestoreInstance)instance).raise(); if(uri != null){ - ((SaveAndRestoreInstance)instance).openResource(uri); + SaveAndRestoreInstance.INSTANCE.openResource(uri); } - return instance; + return SaveAndRestoreInstance.INSTANCE; } public AppInstance getInstance(){ - return instance; + return SaveAndRestoreInstance.INSTANCE; } } diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/SaveAndRestoreInstance.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/SaveAndRestoreInstance.java index 633269e7b1..e55c44e555 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/SaveAndRestoreInstance.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/SaveAndRestoreInstance.java @@ -31,6 +31,7 @@ import java.net.URI; import java.util.List; import java.util.ResourceBundle; +import java.util.concurrent.CompletableFuture; import java.util.logging.Level; import java.util.logging.Logger; @@ -38,25 +39,33 @@ public class SaveAndRestoreInstance implements AppInstance { private final AppDescriptor appDescriptor; private final SaveAndRestoreController saveAndRestoreController; - private DockItem tab; + private DockItem dockItem; + + public static SaveAndRestoreInstance INSTANCE; public SaveAndRestoreInstance(AppDescriptor appDescriptor) { this.appDescriptor = appDescriptor; - tab = null; + dockItem = null; FXMLLoader loader = new FXMLLoader(); try { ResourceBundle resourceBundle = NLS.getMessages(Messages.class); loader.setResources(resourceBundle); loader.setLocation(SaveAndRestoreApplication.class.getResource("ui/SaveAndRestoreUI.fxml")); - tab = new DockItem(this, loader.load()); + dockItem = new DockItem(this, loader.load()); } catch (Exception e) { Logger.getLogger(SaveAndRestoreApplication.class.getName()).log(Level.SEVERE, "Failed loading fxml", e); } saveAndRestoreController = loader.getController(); - tab.setOnCloseRequest(event -> saveAndRestoreController.handleTabClosed()); + dockItem.addCloseCheck(() -> { + saveAndRestoreController.handleTabClosed(); + INSTANCE = null; + return CompletableFuture.completedFuture(true); + }); + + DockPane.getActiveDockPane().addTab(dockItem); } @Override @@ -78,10 +87,6 @@ public void secureStoreChanged(List validTokens){ } public void raise(){ - if(!DockPane.getActiveDockPane().getDockItems().contains(tab)){ - DockPane.getActiveDockPane().addTab(tab); - } - - tab.select(); + dockItem.select(); } } From 1b155153191b8096f2bcf5557c6fbdae1c552e5b Mon Sep 17 00:00:00 2001 From: georgweiss Date: Wed, 25 Sep 2024 15:18:29 +0200 Subject: [PATCH 2/2] Some code cleanup --- .../saveandrestore/ui/SaveAndRestoreController.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java index a392ac2cf6..acb8d8ff3f 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java @@ -36,7 +36,6 @@ import javafx.scene.control.ButtonType; import javafx.scene.control.CheckBox; import javafx.scene.control.ComboBox; -import javafx.scene.control.Dialog; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.Menu; @@ -86,7 +85,6 @@ import org.phoebus.ui.dialog.DialogHelper; import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; import org.phoebus.ui.javafx.ImageCache; -import org.phoebus.ui.time.DateTimePane; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; @@ -97,7 +95,6 @@ import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.text.MessageFormat; -import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -129,15 +126,19 @@ public class SaveAndRestoreController extends SaveAndRestoreBaseController @FXML protected SplitPane splitPane; + @SuppressWarnings("unused") @FXML private ProgressIndicator progressIndicator; + @SuppressWarnings("unused") @FXML private ComboBox filtersComboBox; + @SuppressWarnings("unused") @FXML private Button searchButton; + @SuppressWarnings("unused") @FXML private CheckBox enableFilterCheckBox; @@ -161,6 +162,7 @@ public class SaveAndRestoreController extends SaveAndRestoreBaseController private static final Logger logger = Logger.getLogger(SaveAndRestoreController.class.getName()); + @SuppressWarnings("unused") @FXML private Tooltip filterToolTip; @@ -284,7 +286,7 @@ public void loadTreeData() { JobManager.schedule("Load save-and-restore tree data", monitor -> { Node rootNode = saveAndRestoreService.getRootNode(); - if(rootNode == null){ // Service off-line or not reachable + if (rootNode == null) { // Service off-line or not reachable treeInitializationCountDownLatch.countDown(); errorPane.visibleProperty().set(true); return; @@ -1441,7 +1443,7 @@ public boolean checkTaggable() { } /** - * Determines if comparing snapshots is possible, which is the case if all of the following holds true: + * Determines if comparing snapshots is possible, which is the case if all the following holds true: *
    *
  • The active tab must be a {@link org.phoebus.applications.saveandrestore.ui.snapshot.SnapshotTab}
  • *
  • The active {@link org.phoebus.applications.saveandrestore.ui.snapshot.SnapshotTab} must not show an unsaved snapshot.