Skip to content

Commit

Permalink
Merge pull request #3146 from ControlSystemStudio/CSSTUDIO-2685
Browse files Browse the repository at this point in the history
Fixed switch to save&restore UI from action button
  • Loading branch information
georgweiss authored Sep 25, 2024
2 parents 4edc414 + 1b15515 commit 8910e44
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,41 @@
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;

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
Expand All @@ -78,10 +87,6 @@ public void secureStoreChanged(List<ScopedAuthenticationToken> validTokens){
}

public void raise(){
if(!DockPane.getActiveDockPane().getDockItems().contains(tab)){
DockPane.getActiveDockPane().addTab(tab);
}

tab.select();
dockItem.select();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -129,15 +126,19 @@ public class SaveAndRestoreController extends SaveAndRestoreBaseController
@FXML
protected SplitPane splitPane;

@SuppressWarnings("unused")
@FXML
private ProgressIndicator progressIndicator;

@SuppressWarnings("unused")
@FXML
private ComboBox<Filter> filtersComboBox;

@SuppressWarnings("unused")
@FXML
private Button searchButton;

@SuppressWarnings("unused")
@FXML
private CheckBox enableFilterCheckBox;

Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
* <ul>
* <li>The active tab must be a {@link org.phoebus.applications.saveandrestore.ui.snapshot.SnapshotTab}</li>
* <li>The active {@link org.phoebus.applications.saveandrestore.ui.snapshot.SnapshotTab} must not show an unsaved snapshot.</li>
Expand Down

0 comments on commit 8910e44

Please sign in to comment.