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

Save & restore: support search on PV name(s) #2905

Merged
merged 7 commits into from
Jan 16, 2024
Merged
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.phoebus.framework.nls.NLS;

@SuppressWarnings("unused")
public class Messages {

public static String alertContinue;
Expand Down Expand Up @@ -129,9 +130,6 @@ public class Messages {
public static String searchEntryToolTip;
public static String searchErrorBody;
public static String searchFailed;
public static String searchNoResultsTitle;
public static String searchNoResult;

public static String setpoint;
public static String setpointPVWhen;
public static String severity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,15 @@

import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Pagination;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.image.ImageView;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.Dragboard;
Expand All @@ -70,7 +50,7 @@
import org.phoebus.applications.saveandrestore.ui.snapshot.tag.TagUtil;
import org.phoebus.applications.saveandrestore.ui.snapshot.tag.TagWidget;
import org.phoebus.framework.jobs.JobManager;
import org.phoebus.ui.dialog.DialogHelper;
import org.phoebus.ui.autocomplete.PVAutocompleteMenu;
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
import org.phoebus.ui.dialog.ListSelectionPopOver;
import org.phoebus.ui.javafx.ImageCache;
Expand All @@ -80,15 +60,7 @@
import javax.ws.rs.core.MultivaluedMap;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.Stack;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -161,21 +133,6 @@ public class SearchAndFilterViewController extends SaveAndRestoreBaseController
@FXML
private CheckBox goldenOnlyCheckbox;

@FXML
private ImageView goldenImageView;

@FXML
private ImageView folderImageView;

@FXML
private ImageView configurationImageView;

@FXML
private ImageView snapshotImageView;

@FXML
private ImageView compositeSnapshotImageView;

@FXML
private Label queryLabel;

Expand Down Expand Up @@ -203,6 +160,9 @@ public class SearchAndFilterViewController extends SaveAndRestoreBaseController
@FXML
private TableColumn<Filter, Filter> deleteColumn;

@FXML
private TextField pvsTextField;

private final SimpleStringProperty filterNameProperty = new SimpleStringProperty();

private final SaveAndRestoreService saveAndRestoreService;
Expand All @@ -214,6 +174,8 @@ public class SearchAndFilterViewController extends SaveAndRestoreBaseController
private final SimpleIntegerProperty pageSizeProperty =
new SimpleIntegerProperty(Preferences.search_result_page_size);

private final SimpleStringProperty pvNamesProperty = new SimpleStringProperty();

private final ObservableList<Node> tableEntries = FXCollections.observableArrayList();

private ListSelectionPopOver tagSearchPopover;
Expand Down Expand Up @@ -259,28 +221,24 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
}
});
nodeTypeFolderCheckBox.selectedProperty().bindBidirectional(nodeTypeFolderProperty);
folderImageView.imageProperty().set(ImageRepository.FOLDER);
nodeTypeFolderCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null && !newValue.equals(oldValue)) {
updateParametersAndSearch();
}
});
nodeTypeConfigurationCheckBox.selectedProperty().bindBidirectional(nodeTypeConfigurationProperty);
configurationImageView.imageProperty().set(ImageRepository.CONFIGURATION);
nodeTypeConfigurationCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null && !newValue.equals(oldValue)) {
updateParametersAndSearch();
}
});
nodeTypeSnapshotCheckBox.selectedProperty().bindBidirectional(nodeTypeSnapshotProperty);
snapshotImageView.imageProperty().set(ImageRepository.SNAPSHOT);
nodeTypeSnapshotCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null && !newValue.equals(oldValue)) {
updateParametersAndSearch();
}
});
nodeTypeCompositeSnapshotCheckBox.selectedProperty().bindBidirectional(nodeTypeCompositeSnapshotProperty);
compositeSnapshotImageView.imageProperty().set(ImageRepository.COMPOSITE_SNAPSHOT);
nodeTypeCompositeSnapshotCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null && !newValue.equals(oldValue)) {
updateParametersAndSearch();
Expand All @@ -294,8 +252,6 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
}
});

goldenImageView.imageProperty().set(ImageRepository.GOLDEN_SNAPSHOT);

descTextField.textProperty().bindBidirectional(descProperty);
descTextField.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.ENTER) {
Expand All @@ -315,6 +271,17 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
}
});

pvsTextField.textProperty().bindBidirectional(pvNamesProperty);
// NOTE: setOnKeyPressed will not work here as that is supposed to trigger the PV autocompletion
// mechanism, which will consume the event.
pvsTextField.setOnKeyReleased(e -> {
if (e.getCode() == KeyCode.ENTER) {
updateParametersAndSearch();
}
});

PVAutocompleteMenu.INSTANCE.attachField(pvsTextField);

startTime.textProperty().bindBidirectional(startTimeProperty);
startTime.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.ENTER) {
Expand Down Expand Up @@ -458,7 +425,7 @@ protected void updateItem(Node node, boolean empty) {
// This is to accept numerical input only, and at most 3 digits (maximizing search to 999 hits).
pageSizeTextField.textProperty().addListener((observable, oldValue, newValue) -> {
if (DIGIT_PATTERN.matcher(newValue).matches()) {
if ("".equals(newValue)) {
if (newValue.isEmpty()) {
pageSizeProperty.set(Preferences.search_result_page_size);
} else if (newValue.length() > 3) {
pageSizeTextField.setText(oldValue);
Expand Down Expand Up @@ -487,15 +454,13 @@ protected void updateItem(Node node, boolean empty) {
resultTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
resultTableView.setOnDragDetected(e -> {
List<Node> selectedNodes = resultTableView.getSelectionModel().getSelectedItems();
if(selectedNodes.stream().filter(n ->
if (selectedNodes.stream().anyMatch(n ->
!n.getNodeType().equals(NodeType.SNAPSHOT) &&
!n.getNodeType().equals(NodeType.COMPOSITE_SNAPSHOT)).findFirst().isPresent())
{
!n.getNodeType().equals(NodeType.COMPOSITE_SNAPSHOT))) {
return;
}
final ClipboardContent content = new ClipboardContent();
final List<Node> nodes = new ArrayList<>();
resultTableView.getSelectionModel().getSelectedItems().forEach(i -> nodes.add(i));
final List<Node> nodes = new ArrayList<>(resultTableView.getSelectionModel().getSelectedItems());
content.put(SaveAndRestoreApplication.NODE_SELECTION_FORMAT, nodes);
final Dragboard db = resultTableView.startDragAndDrop(TransferMode.LINK);
db.setContent(content);
Expand Down Expand Up @@ -592,14 +557,7 @@ public void search() {
hitCountProperty.set(searchResult.getHitCount());
});
} else {
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(Messages.searchNoResultsTitle);
alert.setHeaderText(Messages.searchNoResult);
DialogHelper.positionDialog(alert, resultTableView, -300, -200);
alert.show();
tableEntries.clear();
});
Platform.runLater(tableEntries::clear);
}
} catch (Exception e) {
ExceptionDetailsErrorDialog.openError(
Expand Down Expand Up @@ -669,6 +627,9 @@ private String buildQueryString() {
if (tagsProperty.get() != null && !tagsProperty.get().isEmpty()) {
map.put(Keys.TAGS.getName(), tagsProperty.get());
}
if (pvNamesProperty.get() != null && !pvNamesProperty.get().isEmpty()) {
map.put(Keys.PVS.getName(), pvNamesProperty.get());
}
List<String> types = new ArrayList<>();
if (nodeTypeFolderProperty.get()) {
types.add(NodeType.FOLDER.name().toLowerCase());
Expand Down Expand Up @@ -723,7 +684,7 @@ private class DeleteTableCell extends TableCell<Filter, Filter> {
protected void updateItem(final Filter filter, final boolean empty) {
super.updateItem(filter, empty);
// If user clicks on the delete column cell, consume the mouse event to prevent the filter from being loaded.
setOnMouseClicked(event -> event.consume());
setOnMouseClicked(Event::consume);
if (empty) {
setGraphic(null);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,9 @@
import javafx.beans.property.SimpleStringProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.Pagination;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.image.ImageView;
import org.phoebus.applications.saveandrestore.DirectoryUtilities;
import org.phoebus.applications.saveandrestore.Messages;
Expand All @@ -52,23 +43,14 @@
import org.phoebus.applications.saveandrestore.ui.ImageRepository;
import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreService;
import org.phoebus.framework.jobs.JobManager;
import org.phoebus.ui.dialog.DialogHelper;
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
import org.phoebus.util.time.TimestampFormats;

import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.Stack;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
Expand All @@ -80,6 +62,7 @@
* @author <a href="mailto:[email protected]">Genie Jhang</a>
*/

@SuppressWarnings("unused")
public class SearchWindowController implements Initializable {

private SearchAndFilterViewController searchAndFilterViewController;
Expand Down Expand Up @@ -184,7 +167,7 @@ protected void updateItem(Node node, boolean empty) {
// This is to accept numerical input only, and at most 3 digits (maximizing search to 999 hits).
pageSizeTextField.textProperty().addListener((observable, oldValue, newValue) -> {
if (DIGIT_PATTERN.matcher(newValue).matches()) {
if ("".equals(newValue)) {
if (newValue.isEmpty()) {
pageSizeProperty.set(Preferences.search_result_page_size);
} else if (newValue.length() > 3) {
pageSizeTextField.setText(oldValue);
Expand Down Expand Up @@ -282,14 +265,7 @@ public void search() {
resultTableView.getItems().setAll(tableEntries);
});
} else {
Platform.runLater(() -> {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(Messages.searchNoResultsTitle);
alert.setHeaderText(Messages.searchNoResult);
DialogHelper.positionDialog(alert, resultTableView, -300, -200);
alert.show();
clearSearchResult();
});
Platform.runLater(this::clearSearchResult);
}
} catch (Exception e) {
ExceptionDetailsErrorDialog.openError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ promptRenameNodeTitle=Rename node
promptRenameNodeContent=Specify a new name (case sensitive)
pvList=PV List
pvName=PV Name
pvNames=PV name(s)
pvNameToolTip=A list of pv's separated by space or semi colon
pvNameReadback=Readback PV Name
pvNameReadbackTooltip=A list of readback pv's separated by space or semi colon
Expand All @@ -160,7 +161,6 @@ searchEntryToolTip=Double-click to select the node in the tree view
searchFailed=Search failed
searchFieldToolTip=Type search query and press Enter to invoke search
searchErrorBody=Search failed
searchNoResultsTitle=Search Done
searchNoResult=Empty search result
searchKeywordLabel=Keyword
searchQuery=Search Query
Expand Down
Loading
Loading