Skip to content

Commit

Permalink
Changes based on review feed-back
Browse files Browse the repository at this point in the history
  • Loading branch information
georgweiss committed Oct 29, 2024
1 parent 3a565d0 commit c1145a8
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1423,31 +1423,31 @@ private void openNode(String nodeId) {

List<MenuItem> menuItems = Arrays.asList(
new LoginMenuItem(this, selectedItemsProperty,
unused -> ApplicationService.createInstance("credentials_management")),
() -> ApplicationService.createInstance("credentials_management")),
new NewFolderMenuItem(this, selectedItemsProperty,
unused -> createNewFolder()),
() -> createNewFolder()),
new NewConfigurationMenuItem(this, selectedItemsProperty,
unused -> createNewConfiguration()),
() -> createNewConfiguration()),
new CreateSnapshotMenuItem(this, selectedItemsProperty,
unused -> openConfigurationForSnapshot()),
() -> openConfigurationForSnapshot()),
new NewCompositeSnapshotMenuItem(this, selectedItemsProperty,
unused -> createNewCompositeSnapshot()),
() -> createNewCompositeSnapshot()),
new SeparatorMenuItem(),
new EditCompositeMenuItem(this, selectedItemsProperty, unused -> editCompositeSnapshot()),
new RenameFolderMenuItem(this, selectedItemsProperty, unused -> renameNode()),
new CopyMenuItem(this, selectedItemsProperty, unused -> copySelectionToClipboard()),
new PasteMenuItem(this, selectedItemsProperty, unused -> pasteFromClipboard()),
new DeleteNodeMenuItem(this, selectedItemsProperty, unused -> deleteNodes()),
new EditCompositeMenuItem(this, selectedItemsProperty, () -> editCompositeSnapshot()),
new RenameFolderMenuItem(this, selectedItemsProperty, () -> renameNode()),
new CopyMenuItem(this, selectedItemsProperty, () -> copySelectionToClipboard()),
new PasteMenuItem(this, selectedItemsProperty, () -> pasteFromClipboard()),
new DeleteNodeMenuItem(this, selectedItemsProperty, () -> deleteNodes()),
new SeparatorMenuItem(),
new CompareSnapshotsMenuItem(this, selectedItemsProperty, unused -> compareSnapshot()),
new TagGoldenMenuItem(this, selectedItemsProperty, null),
new CompareSnapshotsMenuItem(this, selectedItemsProperty, () -> compareSnapshot()),
new TagGoldenMenuItem(this, selectedItemsProperty),
tagWithComment,
new SeparatorMenuItem(),
new CopyUniqueIdToClipboardMenuItem(this, selectedItemsProperty,
unused -> copyUniqueNodeIdToClipboard()),
() -> copyUniqueNodeIdToClipboard()),
new SeparatorMenuItem(),
new ImportFromCSVMenuItem(this, selectedItemsProperty, unused -> importFromCSV()),
new ExportToCSVMenuItem(this, selectedItemsProperty, unused -> exportToCSV())
new ImportFromCSVMenuItem(this, selectedItemsProperty, () -> importFromCSV()),
new ExportToCSVMenuItem(this, selectedItemsProperty, () -> exportToCSV())
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class CompareSnapshotsMenuItem extends SaveAndRestoreMenuItem {

public CompareSnapshotsMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Consumer onAction) {
public CompareSnapshotsMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
setText(Messages.contextMenuCompareSnapshots);
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/save-and-restore/compare.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@

public class CopyMenuItem extends SaveAndRestoreMenuItem {

public CopyMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Consumer onAction) {
public CopyMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
setText(Messages.copy);
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/copy.png"));
}

@Override
public void configure() {
//visibleProperty().set(!allFoldersOrRootFolder(selectedItemsProperty));
disableProperty().set(saveAndRestoreController.getUserIdentity().isNull().get() ||
allFoldersOrRootFolder(selectedItemsProperty) ||
!saveAndRestoreController.mayCopy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class CopyUniqueIdToClipboardMenuItem extends SaveAndRestoreMenuItem {

public CopyUniqueIdToClipboardMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Consumer onAction) {
public CopyUniqueIdToClipboardMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
setText(Messages.copyUniqueIdToClipboard);
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/copy.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class CreateSnapshotMenuItem extends SaveAndRestoreMenuItem {

public CreateSnapshotMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Consumer onAction) {
public CreateSnapshotMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
setText(Messages.contextMenuCreateSnapshot);
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/save-and-restore/snapshot.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class DeleteNodeMenuItem extends SaveAndRestoreMenuItem {

public DeleteNodeMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Consumer onAction) {
public DeleteNodeMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
setText(Messages.contextMenuDelete);
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/delete.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class EditCompositeMenuItem extends SaveAndRestoreMenuItem {

public EditCompositeMenuItem(SaveAndRestoreController saveAndRestoreController,
ObservableList<Node> selectedItemsProperty,
Consumer onAction) {
Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
setText(Messages.Edit);
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/save-and-restore/edit-configuration.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ExportToCSVMenuItem extends SaveAndRestoreMenuItem {

public ExportToCSVMenuItem(SaveAndRestoreController saveAndRestoreController,
ObservableList<Node> selectedItemsProperty,
Consumer onAction) {
Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
// Set text in configure()
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/csv_export.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ImportFromCSVMenuItem extends SaveAndRestoreMenuItem {

public ImportFromCSVMenuItem(SaveAndRestoreController saveAndRestoreController,
ObservableList<Node> selectedItemsProperty,
Consumer onAction) {
Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
// Set text in configure()
setGraphic(new ImageView(ImageCache.getImage(ImportFromCSVMenuItem.class, "/icons/csv_import.png")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class LoginMenuItem extends SaveAndRestoreMenuItem {

public LoginMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Consumer<Void> onAction) {
public LoginMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItemsProperty, Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
setText(Messages.login);
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/credentials.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class NewCompositeSnapshotMenuItem extends SaveAndRestoreMenuItem {

public NewCompositeSnapshotMenuItem(SaveAndRestoreController saveAndRestoreController,
ObservableList<Node> selectedItemsProperty,
Consumer onAction) {
Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
setText(Messages.contextMenuNewCompositeSnapshot);
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/save-and-restore/composite-snapshot.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class NewConfigurationMenuItem extends SaveAndRestoreMenuItem {

public NewConfigurationMenuItem(SaveAndRestoreController saveAndRestoreController,
ObservableList<Node> selectedItemsProperty,
Consumer onAction) {
Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
setText(Messages.contextMenuNewConfiguration);
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/save-and-restore/configuration.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class NewFolderMenuItem extends SaveAndRestoreMenuItem {

public NewFolderMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItems, Consumer onAction) {
public NewFolderMenuItem(SaveAndRestoreController saveAndRestoreController, ObservableList<Node> selectedItems, Runnable onAction) {
super(saveAndRestoreController, selectedItems, onAction);
setText(Messages.contextMenuNewFolder);
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/save-and-restore/folder.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class PasteMenuItem extends SaveAndRestoreMenuItem {

public PasteMenuItem(SaveAndRestoreController saveAndRestoreController,
ObservableList<Node> selectedItemsProperty,
Consumer onAction) {
Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
setText(Messages.paste);
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/paste.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RenameFolderMenuItem extends SaveAndRestoreMenuItem {

public RenameFolderMenuItem(SaveAndRestoreController saveAndRestoreController,
ObservableList<Node> selectedItemsProperty,
Consumer onAction) {
Runnable onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
setText(Messages.contextMenuRename);
setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/rename_col.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ public abstract class SaveAndRestoreMenuItem extends MenuItem {
* needed to determine if and how to render this {@link MenuItem}.
* @param selectedItemsProperty An {@link ObservableList} property objects of this class will listen on. When
* a change is detected, the {@link #configure()} is called.
* @param onAction Client provided {@link Consumer} defining the action of the {@link MenuItem}.
* @param onAction Client provided {@link Runnable} defining the action of the {@link MenuItem}.
*/
public SaveAndRestoreMenuItem(SaveAndRestoreController saveAndRestoreController,
ObservableList<Node> selectedItemsProperty,
Consumer onAction) {
Runnable onAction) {
this.saveAndRestoreController = saveAndRestoreController;
this.selectedItemsProperty = selectedItemsProperty;
ListChangeListener<Node> l = change -> configure();
this.selectedItemsProperty.addListener(l);
if (onAction != null) {
setOnAction(ae -> onAction.accept(null));
if(onAction != null){
setOnAction(ae -> onAction.run());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ public class TagGoldenMenuItem extends SaveAndRestoreMenuItem {
private final ImageView goldenIcon = ImageCache.getImageView(ImageCache.class, "/icons/save-and-restore/snapshot-golden.png");

public TagGoldenMenuItem(SaveAndRestoreController saveAndRestoreController,
ObservableList<Node> selectedItemsProperty,
Consumer onAction) {
super(saveAndRestoreController, selectedItemsProperty, onAction);
ObservableList<Node> selectedItemsProperty) {
super(saveAndRestoreController, selectedItemsProperty, null);
setText(Messages.contextMenuTagAsGolden);
setGraphic(regularIcon);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ protected void updateItem(Node node, boolean empty) {

ContextMenu contextMenu = new ContextMenu();
MenuItem loginMenuItem =
new LoginMenuItem(saveAndRestoreController, selectedItemsProperty, unused -> ApplicationService.createInstance("credentials_management"));
MenuItem tagGoldenMenuItem = new TagGoldenMenuItem(saveAndRestoreController, selectedItemsProperty, null);
new LoginMenuItem(saveAndRestoreController, selectedItemsProperty, () -> ApplicationService.createInstance("credentials_management"));
MenuItem tagGoldenMenuItem = new TagGoldenMenuItem(saveAndRestoreController, selectedItemsProperty);

ImageView snapshotTagsIconImage = new ImageView(ImageRepository.SNAPSHOT_ADD_TAG);
Menu tagMenuItem = new Menu(Messages.contextMenuTags, snapshotTagsIconImage);
Expand All @@ -470,6 +470,11 @@ protected void updateItem(Node node, boolean empty) {

contextMenu.setOnShowing(event -> {
selectedItemsProperty.setAll(resultTableView.getSelectionModel().getSelectedItems());
// Empty result table -> hide menu and return
if(selectedItemsProperty.isEmpty()){
Platform.runLater(() -> contextMenu.hide());
return;
}
tagMenuItem.disableProperty().set(saveAndRestoreController.getUserIdentity().isNull().get());
restoreMenuItem.disableProperty().set(saveAndRestoreController.getUserIdentity().isNull().get());
NodeType selectedItemType = resultTableView.getSelectionModel().getSelectedItem().getNodeType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ public void newCompositeSnapshot(Node parentNode, List<Node> snapshotNodes) {
* @return <code>true</code> if the source {@link Node}s may be added.
*/
private boolean mayDrop(List<Node> sourceNodes) {
return sourceNodes.stream().noneMatch(n -> !n.getNodeType().equals(NodeType.SNAPSHOT) &&
!n.getNodeType().equals(NodeType.COMPOSITE_SNAPSHOT));
return sourceNodes.stream().allMatch(n -> n.getNodeType().equals(NodeType.SNAPSHOT) ||
n.getNodeType().equals(NodeType.COMPOSITE_SNAPSHOT));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ public void takeSnapshot() {
snapshotTab.setText(Messages.unnamedSnapshot);
snapshotTableViewController.takeSnapshot(snapshotControlsViewController.getDefaultSnapshotMode(), snapshot -> {
disabledUi.set(false);
if (snapshot != null) {
snapshotProperty.set(snapshot);
if (snapshot.isPresent()) {
snapshotProperty.set(snapshot.get());
}
});
}
Expand Down Expand Up @@ -408,13 +408,13 @@ public void addSnapshot(Node snapshotNode) {
public void addSnapshotFromArchiver() {
disabledUi.set(true);
snapshotTableViewController.takeSnapshot(SnapshotMode.FROM_ARCHIVER, snapshot -> {
if (snapshot == null) {
if (snapshot.isEmpty()) {
disabledUi.set(false);
return;
}
Platform.runLater(() -> {
try {
snapshotTableViewController.addSnapshot(snapshot);
snapshotTableViewController.addSnapshot(snapshot.get());
} finally {
disabledUi.set(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ public void updateItem(final Boolean item, final boolean empty) {
}
}

public void takeSnapshot(SnapshotMode snapshotMode, Consumer<Snapshot> consumer) {
public void takeSnapshot(SnapshotMode snapshotMode, Consumer<Optional<Snapshot>> consumer) {
switch (snapshotMode) {
case READ_PVS -> takeSnapshot(consumer);
case FROM_ARCHIVER -> takeSnapshotFromArchiver(consumer);
default -> throw new IllegalArgumentException("Snapshot mode " + snapshotMode + " not supported");
}
}

private void takeSnapshotFromArchiver(Consumer<Snapshot> consumer) {
private void takeSnapshotFromArchiver(Consumer<Optional<Snapshot>> consumer) {
DateTimePane dateTimePane = new DateTimePane();
Dialog<Instant> timePickerDialog = new Dialog<>();
timePickerDialog.setTitle(Messages.dateTimePickerTitle);
Expand All @@ -194,7 +194,7 @@ private void takeSnapshotFromArchiver(Consumer<Snapshot> consumer) {
});
Optional<Instant> time = timePickerDialog.showAndWait();
if (time.isEmpty()) { // User cancels date/time picker dialog
consumer.accept(null);
consumer.accept(Optional.empty());
return;
}
JobManager.schedule("Add snapshot from archiver", monitor -> {
Expand All @@ -211,11 +211,11 @@ private void takeSnapshotFromArchiver(Consumer<Snapshot> consumer) {
snapshotData.setUniqueId("anonymous");
snapshotData.setSnapshotItems(snapshotItems);
snapshot.setSnapshotData(snapshotData);
consumer.accept(snapshot);
consumer.accept(Optional.of(snapshot));
});
}

private void takeSnapshot(Consumer<Snapshot> consumer) {
private void takeSnapshot(Consumer<Optional<Snapshot>> consumer) {
JobManager.schedule("Take snapshot", monitor -> {
// Clear snapshots array
snapshots.clear();
Expand All @@ -224,7 +224,7 @@ private void takeSnapshot(Consumer<Snapshot> consumer) {
snapshotItems = SaveAndRestoreService.getInstance().takeSnapshot(snapshotController.getConfigurationNode().getUniqueId());
} catch (Exception e) {
ExceptionDetailsErrorDialog.openError(snapshotTableView, Messages.errorGeneric, Messages.takeSnapshotFailed, e);
consumer.accept(null);
consumer.accept(Optional.empty());
return;
}
// Service can only return nulls for disconnected PVs, but UI expects VDisonnectedData
Expand All @@ -246,7 +246,7 @@ private void takeSnapshot(Consumer<Snapshot> consumer) {
SimpleDateFormat formatter = new SimpleDateFormat(Preferences.default_snapshot_name_date_format);
snapshot.getSnapshotNode().setName(formatter.format(new Date()));
}
consumer.accept(snapshot);
consumer.accept(Optional.of(snapshot));
});

}
Expand Down
Loading

0 comments on commit c1145a8

Please sign in to comment.