-
Notifications
You must be signed in to change notification settings - Fork 127
Stand-alone app for save-and-restore search results #3279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright (C) 2024 European Spallation Source ERIC. | ||
| */ | ||
|
|
||
| package org.phoebus.applications.saveandrestore; | ||
|
|
||
| import org.phoebus.framework.spi.AppInstance; | ||
| import org.phoebus.framework.spi.AppResourceDescriptor; | ||
|
|
||
| import java.net.URI; | ||
|
|
||
| /** | ||
| * Application showing list of save-and-restore nodes matching a particular filter. Its UI is a subset of the | ||
| * search and filter view of the {@link SaveAndRestoreApplication} UI. | ||
| */ | ||
| public class FilterViewApplication implements AppResourceDescriptor { | ||
|
|
||
| public static final String NAME = "saveandrestorefilterview"; | ||
| public static final String DISPLAY_NAME = "SAR Filter"; | ||
|
|
||
| @Override | ||
| public String getDisplayName() { | ||
| return DISPLAY_NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public AppInstance create() { | ||
| return create(null); | ||
| } | ||
|
|
||
| @Override | ||
| public AppInstance create(URI uri) { | ||
| if(FilterViewInstance.INSTANCE == null){ | ||
| FilterViewInstance.INSTANCE = new FilterViewInstance(this); | ||
| } | ||
| else{ | ||
| FilterViewInstance.INSTANCE.raise(); | ||
| } | ||
|
|
||
| if(uri != null){ | ||
| FilterViewInstance.INSTANCE.openResource(uri); | ||
| } | ||
|
|
||
| return FilterViewInstance.INSTANCE; | ||
| } | ||
|
|
||
| public AppInstance getInstance(){ | ||
| return FilterViewInstance.INSTANCE; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Copyright (C) 2024 European Spallation Source ERIC. | ||
| */ | ||
|
|
||
| package org.phoebus.applications.saveandrestore; | ||
|
|
||
| import javafx.fxml.FXMLLoader; | ||
| import org.phoebus.applications.saveandrestore.ui.search.SearchResultTableViewController; | ||
| import org.phoebus.framework.nls.NLS; | ||
| import org.phoebus.framework.spi.AppDescriptor; | ||
| import org.phoebus.framework.spi.AppInstance; | ||
| import org.phoebus.security.tokens.ScopedAuthenticationToken; | ||
| import org.phoebus.ui.docking.DockItem; | ||
| import org.phoebus.ui.docking.DockPane; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.URLDecoder; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.List; | ||
| import java.util.ResourceBundle; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| /** | ||
| * Instance maintaining a list of save-and-restore nodes matching a particular filter. Its UI is a subset of the | ||
| * search and filter view of the {@link SaveAndRestoreApplication} UI. | ||
| */ | ||
| public class FilterViewInstance implements AppInstance { | ||
|
|
||
| private final AppDescriptor appDescriptor; | ||
| public static FilterViewInstance INSTANCE; | ||
| private DockItem dockItem; | ||
| private final SearchResultTableViewController searchResultTableViewController; | ||
|
|
||
| public FilterViewInstance(AppDescriptor appDescriptor) { | ||
| this.appDescriptor = appDescriptor; | ||
|
|
||
| dockItem = null; | ||
|
|
||
| FXMLLoader loader = new FXMLLoader(); | ||
| try { | ||
| ResourceBundle resourceBundle = NLS.getMessages(Messages.class); | ||
| loader.setResources(resourceBundle); | ||
| loader.setLocation(FilterViewApplication.class.getResource("/org/phoebus/applications/saveandrestore/ui/search/SearchResultTableView.fxml")); | ||
| dockItem = new DockItem(this, loader.load()); | ||
| } catch (Exception e) { | ||
| Logger.getLogger(SaveAndRestoreApplication.class.getName()).log(Level.SEVERE, "Failed loading fxml", e); | ||
| } | ||
|
|
||
| searchResultTableViewController = loader.getController(); | ||
| dockItem.addCloseCheck(() -> { | ||
| INSTANCE = null; | ||
| return CompletableFuture.completedFuture(true); | ||
| }); | ||
|
|
||
| DockPane.getActiveDockPane().addTab(dockItem); | ||
| } | ||
|
|
||
| @Override | ||
| public AppDescriptor getAppDescriptor() { | ||
| return appDescriptor; | ||
| } | ||
|
|
||
| public void openResource(URI uri) { | ||
| searchResultTableViewController.loadFilter(URLDecoder.decode(uri.getPath().substring(1), StandardCharsets.UTF_8)); | ||
| } | ||
|
|
||
| public void raise() { | ||
| dockItem.select(); | ||
| } | ||
|
|
||
| public void secureStoreChanged(List<ScopedAuthenticationToken> validTokens) { | ||
| searchResultTableViewController.secureStoreChanged(validTokens); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
|
|
||
| package org.phoebus.applications.saveandrestore.authentication; | ||
|
|
||
| import org.phoebus.applications.saveandrestore.FilterViewApplication; | ||
| import org.phoebus.applications.saveandrestore.FilterViewInstance; | ||
| import org.phoebus.applications.saveandrestore.SaveAndRestoreApplication; | ||
| import org.phoebus.applications.saveandrestore.SaveAndRestoreInstance; | ||
| import org.phoebus.framework.spi.AppDescriptor; | ||
|
|
@@ -38,15 +40,26 @@ public class SecureStoreChangeHandlerImpl implements SecureStoreChangeHandler { | |
| */ | ||
| @Override | ||
| public void secureStoreChanged(List<ScopedAuthenticationToken> validTokens) { | ||
| AppDescriptor appDescriptor = ApplicationService.findApplication(SaveAndRestoreApplication.NAME); | ||
| if (appDescriptor != null && appDescriptor instanceof SaveAndRestoreApplication) { | ||
| SaveAndRestoreApplication saveAndRestoreApplication = (SaveAndRestoreApplication) appDescriptor; | ||
| AppDescriptor saveAndRestoreAppDescriptor = ApplicationService.findApplication(SaveAndRestoreApplication.NAME); | ||
| if (saveAndRestoreAppDescriptor != null && saveAndRestoreAppDescriptor instanceof SaveAndRestoreApplication) { | ||
| SaveAndRestoreApplication saveAndRestoreApplication = (SaveAndRestoreApplication) saveAndRestoreAppDescriptor; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cast can be made type-safe by changing the the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is it not type-safe the way it stands?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is type-safe. In the newfangled syntax, the type is only written once
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a downside, the new syntax is ugly.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @georgweiss: You are right that casting (in Java) is type-safe. However, a runtime-exception will be thrown if the cast doesn't succeed, and the compiler doesn't check that the runtime exception is caught. With the pattern matching construct the compiler can give better guarantees: in the body of the In simple cases such as this, the main advantage is to guard against typos as @kasemir pointed out. In more complicated cases it can help the programmer to know that all cases that can arise have been covered in the code. |
||
| SaveAndRestoreInstance saveAndRestoreInstance = (SaveAndRestoreInstance) saveAndRestoreApplication.getInstance(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cast can be made type-safe by changing the return type of |
||
| // Save&restore app may not be launched (yet) | ||
| if(saveAndRestoreInstance == null){ | ||
| return; | ||
| } | ||
| saveAndRestoreInstance.secureStoreChanged(validTokens); | ||
| } | ||
|
|
||
| AppDescriptor filterViewAppDescriptor = ApplicationService.findApplication(FilterViewApplication.NAME); | ||
| if (filterViewAppDescriptor != null && filterViewAppDescriptor instanceof FilterViewApplication) { | ||
| FilterViewApplication filterViewApplication = (FilterViewApplication) filterViewAppDescriptor; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, this cast can be made type-safe by changing the |
||
| FilterViewInstance filterViewInstance = (FilterViewInstance) filterViewApplication.getInstance(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, this can be made type-safe by changing the return type of |
||
| // Save&restore filter view app may not be launched (yet) | ||
| if(filterViewInstance == null){ | ||
| return; | ||
| } | ||
| filterViewInstance.secureStoreChanged(validTokens); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,14 +8,15 @@ | |
| import org.phoebus.applications.saveandrestore.Messages; | ||
| import org.phoebus.applications.saveandrestore.model.Node; | ||
| import org.phoebus.applications.saveandrestore.model.NodeType; | ||
| import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreBaseController; | ||
| import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreController; | ||
| import org.phoebus.ui.javafx.ImageCache; | ||
|
|
||
| import java.util.function.Consumer; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import. |
||
|
|
||
| public class CompareSnapshotsMenuItem extends SaveAndRestoreMenuItem { | ||
|
|
||
| public CompareSnapshotsMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) { | ||
| public CompareSnapshotsMenuItem(SaveAndRestoreBaseController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) { | ||
| super(saveAndRestoreController, selectedItemsProperty, onAction); | ||
| setText(Messages.contextMenuCompareSnapshots); | ||
| setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/save-and-restore/compare.png")); | ||
|
|
@@ -25,6 +26,6 @@ public CompareSnapshotsMenuItem(SaveAndRestoreController saveAndRestoreControlle | |
| public void configure() { | ||
| disableProperty().set(selectedItemsProperty.size() != 1 || | ||
| !selectedItemsProperty.get(0).getNodeType().equals(NodeType.SNAPSHOT) || | ||
| !saveAndRestoreController.compareSnapshotsPossible()); | ||
| !((SaveAndRestoreController)saveAndRestoreController).compareSnapshotsPossible()); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,14 +8,15 @@ | |
| import org.phoebus.applications.saveandrestore.Messages; | ||
| import org.phoebus.applications.saveandrestore.model.Node; | ||
| import org.phoebus.applications.saveandrestore.model.NodeType; | ||
| import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreBaseController; | ||
| import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreController; | ||
| import org.phoebus.ui.javafx.ImageCache; | ||
|
|
||
| import java.util.function.Consumer; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import. |
||
|
|
||
| public class CopyMenuItem extends SaveAndRestoreMenuItem { | ||
|
|
||
| public CopyMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) { | ||
| public CopyMenuItem(SaveAndRestoreBaseController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) { | ||
| super(saveAndRestoreController, selectedItemsProperty, onAction); | ||
| setText(Messages.copy); | ||
| setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/copy.png")); | ||
|
|
@@ -25,7 +26,7 @@ public CopyMenuItem(SaveAndRestoreController saveAndRestoreController, Observabl | |
| public void configure() { | ||
| disableProperty().set(saveAndRestoreController.getUserIdentity().isNull().get() || | ||
| allFoldersOrRootFolder(selectedItemsProperty) || | ||
| !saveAndRestoreController.mayCopy()); | ||
| !((SaveAndRestoreController)saveAndRestoreController).mayCopy()); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, here saveAndRestoreController is cast to SaveAndRestoreController, but the constructor takes as argument a SaveAndRestoreBaseController. Is this correct? |
||
| } | ||
|
|
||
| private boolean allFoldersOrRootFolder(ObservableList<Node> selectedItemsProperty) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,14 +7,15 @@ | |
| import javafx.collections.ObservableList; | ||
| import org.phoebus.applications.saveandrestore.Messages; | ||
| import org.phoebus.applications.saveandrestore.model.Node; | ||
| import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreBaseController; | ||
| import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreController; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import. |
||
| import org.phoebus.ui.javafx.ImageCache; | ||
|
|
||
| import java.util.function.Consumer; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import. |
||
|
|
||
| public class CopyUniqueIdToClipboardMenuItem extends SaveAndRestoreMenuItem { | ||
|
|
||
| public CopyUniqueIdToClipboardMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) { | ||
| public CopyUniqueIdToClipboardMenuItem(SaveAndRestoreBaseController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) { | ||
| super(saveAndRestoreController, selectedItemsProperty, onAction); | ||
| setText(Messages.copyUniqueIdToClipboard); | ||
| setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/copy.png")); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,14 +9,15 @@ | |
| import org.phoebus.applications.saveandrestore.Messages; | ||
| import org.phoebus.applications.saveandrestore.model.Node; | ||
| import org.phoebus.applications.saveandrestore.model.NodeType; | ||
| import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreBaseController; | ||
| import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreController; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import. |
||
| import org.phoebus.ui.javafx.ImageCache; | ||
|
|
||
| import java.util.function.Consumer; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import. |
||
|
|
||
| public class CreateSnapshotMenuItem extends SaveAndRestoreMenuItem { | ||
|
|
||
| public CreateSnapshotMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) { | ||
| public CreateSnapshotMenuItem(SaveAndRestoreBaseController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) { | ||
| super(saveAndRestoreController, selectedItemsProperty, onAction); | ||
| setText(Messages.contextMenuCreateSnapshot); | ||
| setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/save-and-restore/snapshot.png")); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.