Skip to content
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

SAR #3161

Merged
merged 12 commits into from
Oct 21, 2024
Merged

SAR #3161

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/save-and-restore/app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<artifactId>save-and-restore-model</artifactId>
<version>4.7.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.phoebus</groupId>
<artifactId>save-and-restore-util</artifactId>
<version>4.7.4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.phoebus</groupId>
<artifactId>app-display-model</artifactId>
Expand Down Expand Up @@ -76,6 +82,7 @@
<scope>test</scope>
</dependency>


</dependencies>
<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class Messages {
public static String closeCompositeSnapshotWarning;
public static String closeTabPrompt;
public static String compositeSnapshotConsistencyCheckFailed;
public static String contextMenuAddTag;
@Deprecated
public static String contextMenuAddTagWithComment;
public static String contextMenuCreateSnapshot;
public static String contextMenuCompareSnapshots;
Expand All @@ -52,6 +54,8 @@ public class Messages {
public static String contextMenuRename;
public static String contextMenuRemoveGoldenTag;
public static String contextMenuTagAsGolden;
public static String contextMenuTags;
@Deprecated
public static String contextMenuTagsWithComment;
public static String contextMenuOpenCompositeSnapshotForRestore;

Expand Down Expand Up @@ -129,6 +133,8 @@ public class Messages {
public static String restore;
public static String restoreFailed;
public static String restoreFailedPVs;
public static String restoreFromClient;
public static String restoreFromService;
public static String saveFilter;

public static String saveFilterConfirmOverwrite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public class Preferences {
@Preference
public static String default_snapshot_mode;

/**
* Default restore mode
*/
@Preference
public static String default_restore_mode;

static {
AnnotatedPreferences.initialize(Preferences.class, "/save_and_restore_preferences.properties");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ContextMenuCompositeSnapshot extends ContextMenuBase {
public ContextMenuCompositeSnapshot(SaveAndRestoreController saveAndRestoreController) {
super(saveAndRestoreController);

Image snapshotTagsWithCommentIcon = ImageCache.getImage(SaveAndRestoreController.class, "/icons/save-and-restore/snapshot-tags.png");
Image snapshotTagsIcon = ImageCache.getImage(SaveAndRestoreController.class, "/icons/save-and-restore/snapshot-tags.png");

MenuItem editCompositeSnapshotMenuItem = new MenuItem(Messages.Edit, new ImageView(ImageRepository.EDIT_CONFIGURATION));
editCompositeSnapshotMenuItem.disableProperty().bind(multipleNodesSelectedProperty);
Expand All @@ -48,20 +48,20 @@ public ContextMenuCompositeSnapshot(SaveAndRestoreController saveAndRestoreContr
userIsAuthenticatedProperty.not().get() || multipleNodesSelectedProperty.get(),
userIsAuthenticatedProperty, multipleNodesSelectedProperty));

ImageView snapshotTagsWithCommentIconImage = new ImageView(snapshotTagsWithCommentIcon);
snapshotTagsWithCommentIconImage.setFitHeight(22);
snapshotTagsWithCommentIconImage.setFitWidth(22);
ImageView snapshotTagsIconImage = new ImageView(snapshotTagsIcon);
snapshotTagsIconImage.setFitHeight(22);
snapshotTagsIconImage.setFitWidth(22);

Menu tagWithComment = new Menu(Messages.contextMenuTagsWithComment, snapshotTagsWithCommentIconImage);
tagWithComment.setOnShowing(event -> saveAndRestoreController.tagWithComment(tagWithComment));
tagWithComment.disableProperty().bind(Bindings.createBooleanBinding(() ->
Menu tags = new Menu(Messages.contextMenuTags, snapshotTagsIconImage);
tags.setOnShowing(event -> saveAndRestoreController.tag(tags));
tags.disableProperty().bind(Bindings.createBooleanBinding(() ->
multipleNodesSelectedProperty.get() || userIsAuthenticatedProperty.not().get(),
multipleNodesSelectedProperty, userIsAuthenticatedProperty));

CustomMenuItem addTagWithCommentMenuItem = TagWidget.AddTagWithCommentMenuItem();
addTagWithCommentMenuItem.setOnAction(action -> saveAndRestoreController.addTagToSnapshots());
CustomMenuItem addTagMenuItem = TagWidget.AddTagMenuItem();
addTagMenuItem.setOnAction(action -> saveAndRestoreController.addTagToSnapshots());

tagWithComment.getItems().addAll(addTagWithCommentMenuItem, new SeparatorMenuItem());
tags.getItems().addAll(addTagMenuItem, new SeparatorMenuItem());

Image copyIcon = ImageCache.getImage(SaveAndRestoreController.class, "/icons/copy.png");
MenuItem copyMenuItem = new MenuItem(Messages.copy, new ImageView(copyIcon));
Expand All @@ -76,7 +76,7 @@ public ContextMenuCompositeSnapshot(SaveAndRestoreController saveAndRestoreContr
copyMenuItem,
deleteNodesMenuItem,
copyUniqueIdToClipboardMenuItem,
tagWithComment);
tags);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ContextMenuSnapshot extends ContextMenuBase {

private final MenuItem tagGoldenMenuItem;

private final Menu tagWithComment;
private final Menu tags;

private final SimpleBooleanProperty mayTagProperty = new SimpleBooleanProperty();

Expand All @@ -55,21 +55,21 @@ public ContextMenuSnapshot(SaveAndRestoreController saveAndRestoreController) {
compareSnapshotsMenuItem.setOnAction(ae -> saveAndRestoreController.compareSnapshot());
compareSnapshotsMenuItem.disableProperty().bind(mayCompareSnapshotsProperty.not());

ImageView snapshotTagsWithCommentIconImage = new ImageView(ImageRepository.SNAPSHOT_ADD_TAG_WITH_COMMENT);
ImageView snapshotTagsIconImage = new ImageView(ImageRepository.SNAPSHOT_ADD_TAG);

tagWithComment = new Menu(Messages.contextMenuTagsWithComment, snapshotTagsWithCommentIconImage);
tagWithComment.setOnShowing(event -> saveAndRestoreController.tagWithComment(tagWithComment));
tagWithComment.disableProperty().bind(Bindings.createBooleanBinding(() ->
tags = new Menu(Messages.contextMenuTags, snapshotTagsIconImage);
tags.setOnShowing(event -> saveAndRestoreController.tag(tags));
tags.disableProperty().bind(Bindings.createBooleanBinding(() ->
multipleNodesSelectedProperty.get() || userIsAuthenticatedProperty.not().get(),
multipleNodesSelectedProperty, userIsAuthenticatedProperty));

MenuItem addTagWithCommentMenuItem = TagWidget.AddTagWithCommentMenuItem();
addTagWithCommentMenuItem.setOnAction(action -> saveAndRestoreController.addTagToSnapshots());
addTagWithCommentMenuItem.disableProperty().bind(Bindings.createBooleanBinding(() ->
MenuItem addTagMenuItem = TagWidget.AddTagMenuItem();
addTagMenuItem.setOnAction(action -> saveAndRestoreController.addTagToSnapshots());
addTagMenuItem.disableProperty().bind(Bindings.createBooleanBinding(() ->
multipleNodesSelectedProperty.get() || mayTagProperty.not().get(),
multipleNodesSelectedProperty, mayTagProperty));

tagWithComment.getItems().addAll(addTagWithCommentMenuItem);
tags.getItems().addAll(addTagMenuItem);

MenuItem findReferencesMenuItem = new MenuItem(Messages.findSnapshotReferences, new ImageView(ImageRepository.COMPOSITE_SNAPSHOT));
findReferencesMenuItem.setOnAction(ae -> saveAndRestoreController.findSnapshotReferences());
Expand Down Expand Up @@ -97,7 +97,7 @@ public ContextMenuSnapshot(SaveAndRestoreController saveAndRestoreController) {
deleteNodesMenuItem,
compareSnapshotsMenuItem,
tagGoldenMenuItem,
tagWithComment,
tags,
copyMenuItem,
copyUniqueIdToClipboardMenuItem,
exportSnapshotMenuItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ImageRepository {
public static final Image EDIT_CONFIGURATION =
ImageCache.getImage(ImageRepository.class, "/icons/save-and-restore/edit-configuration.png");

public static final Image SNAPSHOT_ADD_TAG_WITH_COMMENT =
public static final Image SNAPSHOT_ADD_TAG =
ImageCache.getImage(ImageRepository.class, "/icons/save-and-restore/snapshot-add_tag.png");

public static final Image DELETE = ImageCache.getImage(SaveAndRestoreController.class, "/icons/delete.png");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2024 European Spallation Source ERIC.
*/

package org.phoebus.applications.saveandrestore.ui;

import org.phoebus.applications.saveandrestore.Messages;

public enum RestoreMode {

/**
* Classic mode: read data from IOC
*/
CLIENT_RESTORE(Messages.restoreFromClient),

/**
* Read PV data from archiver
*/
SERVICE_RESTORE(Messages.restoreFromService);

private final String name;

RestoreMode(final String name) {
this.name = name;
}

@Override
public String toString(){
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1026,17 +1026,17 @@ protected void addTagToSnapshots() {
}

/**
* Configures the "tag with comment" sub-menu. Items are added based on existing {@link Tag}s on the
* Configures the "tag" sub-menu. Items are added based on existing {@link Tag}s on the
* selected {@link Node}s
*
* @param tagWithCommentMenu The {@link Menu} subject to configuration.
* @param tagMenu The {@link Menu} subject to configuration.
*/
public void tagWithComment(final Menu tagWithCommentMenu) {
public void tag(final Menu tagMenu) {

List<Node> selectedNodes =
browserSelectionModel.getSelectedItems().stream().map(TreeItem::getValue).collect(Collectors.toList());

TagUtil.tagWithComment(tagWithCommentMenu, selectedNodes, updatedNodes -> updatedNodes.forEach(this::nodeChanged));
TagUtil.tag(tagMenu, selectedNodes, updatedNodes -> updatedNodes.forEach(this::nodeChanged));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,20 +417,20 @@ protected void updateItem(Node node, boolean empty) {
ContextMenu contextMenu = new ContextMenu();
MenuItem tagGoldenMenuItem = new MenuItem(Messages.contextMenuTagAsGolden, new ImageView(ImageRepository.SNAPSHOT));

ImageView snapshotTagsWithCommentIconImage = new ImageView(ImageRepository.SNAPSHOT_ADD_TAG_WITH_COMMENT);
Menu tagMenuItem = new Menu(Messages.contextMenuTagsWithComment, snapshotTagsWithCommentIconImage);
ImageView snapshotTagsIconImage = new ImageView(ImageRepository.SNAPSHOT_ADD_TAG);
Menu tagMenuItem = new Menu(Messages.contextMenuTags, snapshotTagsIconImage);

MenuItem addTagWithCommentMenuItem = TagWidget.AddTagWithCommentMenuItem();
addTagWithCommentMenuItem.setOnAction(event -> TagUtil.addTag(resultTableView.getSelectionModel().getSelectedItems()));
tagMenuItem.getItems().add(addTagWithCommentMenuItem);
MenuItem addTagMenuItem = TagWidget.AddTagMenuItem();
addTagMenuItem.setOnAction(event -> TagUtil.addTag(resultTableView.getSelectionModel().getSelectedItems()));
tagMenuItem.getItems().add(addTagMenuItem);

MenuItem restoreMenuItem = new MenuItem(Messages.restore);
restoreMenuItem.setOnAction(e -> doRestore(resultTableView.getSelectionModel().getSelectedItem().getUniqueId()));

contextMenu.setOnShowing(event -> {
NodeType selectedItemType = resultTableView.getSelectionModel().getSelectedItem().getNodeType();
if (selectedItemType.equals(NodeType.SNAPSHOT)) {
TagUtil.tagWithComment(tagMenuItem,
TagUtil.tag(tagMenuItem,
resultTableView.getSelectionModel().getSelectedItems(),
updatedNodes -> { // Callback, any extra handling added here
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public void loadSnapshot(Node snapshotNode) {
}

public void restore(ActionEvent actionEvent) {
snapshotTableViewController.restore(snapshotProperty.get(), restoreResultList -> {
snapshotTableViewController.restoreSnapshot(snapshotControlsViewController.getRestoreMode(), snapshotProperty.get(), restoreResultList -> {
if (snapshotControlsViewController.logAction()) {
eventReceivers.forEach(r -> r.snapshotRestored(snapshotProperty.get().getSnapshotNode(), restoreResultList, this::showLoggingError));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.phoebus.applications.saveandrestore.model.Node;
import org.phoebus.applications.saveandrestore.model.NodeType;
import org.phoebus.applications.saveandrestore.model.event.SaveAndRestoreEventReceiver;
import org.phoebus.applications.saveandrestore.ui.RestoreMode;
import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreBaseController;
import org.phoebus.applications.saveandrestore.ui.SnapshotMode;
import org.phoebus.ui.docking.DockPane;
Expand Down Expand Up @@ -128,6 +129,14 @@ public class SnapshotControlsViewController extends SaveAndRestoreBaseController
@FXML
private RadioButton readFromArchiver;

@SuppressWarnings("unused")
@FXML
private RadioButton restoreFromClient;

@SuppressWarnings("unused")
@FXML
private RadioButton restoreFromService;

private List<List<Pattern>> regexPatterns = new ArrayList<>();

protected final SimpleStringProperty snapshotNameProperty = new SimpleStringProperty();
Expand Down Expand Up @@ -155,6 +164,8 @@ public class SnapshotControlsViewController extends SaveAndRestoreBaseController

private final SimpleObjectProperty<SnapshotMode> snapshotModeProperty = new SimpleObjectProperty<>(SnapshotMode.READ_PVS);

private final SimpleObjectProperty<RestoreMode> restoreModeProperty = new SimpleObjectProperty<>(RestoreMode.CLIENT_RESTORE);

public void setSnapshotController(SnapshotController snapshotController) {
this.snapshotController = snapshotController;
}
Expand Down Expand Up @@ -313,6 +324,29 @@ public void initialize() {
toggleGroup.selectedToggleProperty().addListener((obs, o, n) -> {
snapshotModeProperty.set((SnapshotMode) n.getUserData());
});

restoreFromClient.setUserData(RestoreMode.CLIENT_RESTORE);
restoreFromService.setUserData(RestoreMode.SERVICE_RESTORE);

String restoreModeString = Preferences.default_restore_mode;
if (restoreModeString == null || restoreModeString.isEmpty()) {
restoreModeProperty.set(RestoreMode.CLIENT_RESTORE);
} else {
try {
restoreModeProperty.set(RestoreMode.valueOf(restoreModeString));
} catch (IllegalArgumentException e) {
logger.log(Level.WARNING, "Unknown restore mode \"" + restoreModeString + "\", defaulting to " + RestoreMode.CLIENT_RESTORE);
restoreModeProperty.set(RestoreMode.CLIENT_RESTORE);
}
}

ToggleGroup restoreToggleGroup = new ToggleGroup();
restoreToggleGroup.getToggles().addAll(restoreFromClient, restoreFromService);
restoreToggleGroup.selectToggle(restoreToggleGroup.getToggles().stream()
.filter(t -> t.getUserData().equals(restoreModeProperty.get())).findFirst().get());
restoreToggleGroup.selectedToggleProperty().addListener((obs, o, n) -> {
restoreModeProperty.set((RestoreMode) n.getUserData());
});
}

public SimpleStringProperty getSnapshotNameProperty() {
Expand Down Expand Up @@ -379,6 +413,9 @@ public void setSnapshotRestorableProperty(boolean restorable) {
public SnapshotMode getDefaultSnapshotMode() {
return snapshotModeProperty.get();
}
public RestoreMode getRestoreMode() {
return restoreModeProperty.get();
}

public boolean logAction() {
return logActionProperty.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @author <a href="mailto:[email protected]">Genie Jhang</a>
*/

public class SnapshotNewTagDialog extends Dialog<Pair<String, String>> {
public class SnapshotNewTagDialog extends Dialog<String> {

private final TextInputControl tagNameTextField;

Expand Down Expand Up @@ -81,21 +81,15 @@ public SnapshotNewTagDialog(List<Node> nodes) {
gridPane.setPadding(new Insets(12, 8, 3, 8));

Label tagNameLabel = new Label(Messages.tagNameLabel);
Label tagCommentLabel = new Label(Messages.tagCommentLabel);

GridPane.setHalignment(tagNameLabel, HPos.RIGHT);
GridPane.setHalignment(tagCommentLabel, HPos.RIGHT);

tagNameTextField = new TextField();
TextField tagCommentTextField = new TextField();
// TextField tagCommentTextField = new TextField();

tagNameTextField.setMinWidth(400);
tagCommentTextField.setMinWidth(400);

gridPane.add(tagNameLabel, 0, 0);
gridPane.add(tagCommentLabel, 0, 1);
gridPane.add(tagNameTextField, 1, 0);
gridPane.add(tagCommentTextField, 1, 1);

getDialogPane().setContent(gridPane);

Expand All @@ -117,7 +111,7 @@ public SnapshotNewTagDialog(List<Node> nodes) {
setResultConverter(dialogButton -> {
if (dialogButton == saveTagButton) {

return new Pair<>(tagNameTextField.getText(), tagCommentTextField.getText());
return tagNameTextField.getText();
}

return null;
Expand Down
Loading
Loading