changed_items = item_changes.getAndSet(null);
final String[] update_array;
- synchronized (items_to_update)
+ synchronized (item_paths_to_update)
{
- update_array = items_to_update.toArray(new String[items_to_update.size()]);
- items_to_update.clear();
+ update_array = item_paths_to_update.toArray(new String[item_paths_to_update.size()]);
+ item_paths_to_update.clear();
}
Platform.runLater(() ->
{
diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java
index f3d65c9801..45dd03ed18 100644
--- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java
+++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java
@@ -12,18 +12,24 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.stream.Collectors;
import javafx.collections.FXCollections;
+import javafx.scene.control.TextField;
+import javafx.scene.control.ToggleButton;
+import javafx.scene.layout.HBox;
import org.phoebus.applications.alarm.AlarmSystem;
import org.phoebus.applications.alarm.client.AlarmClient;
import org.phoebus.applications.alarm.client.AlarmClientLeaf;
@@ -31,8 +37,10 @@
import org.phoebus.applications.alarm.client.AlarmClientNode;
import org.phoebus.applications.alarm.model.AlarmTreeItem;
import org.phoebus.applications.alarm.model.BasicState;
+import org.phoebus.applications.alarm.model.SeverityLevel;
import org.phoebus.applications.alarm.ui.AlarmContextMenuHelper;
import org.phoebus.applications.alarm.ui.AlarmUI;
+import org.phoebus.applications.alarm.ui.Messages;
import org.phoebus.applications.alarm.ui.config.ItemConfigDialog;
import org.phoebus.framework.selection.Selection;
import org.phoebus.framework.selection.SelectionService;
@@ -40,6 +48,7 @@
import org.phoebus.ui.application.SaveSnapshotAction;
import org.phoebus.ui.dialog.DialogHelper;
import org.phoebus.ui.docking.DockPane;
+import org.phoebus.ui.javafx.ClearingTextField;
import org.phoebus.ui.javafx.ImageCache;
import org.phoebus.ui.javafx.PrintAction;
import org.phoebus.ui.javafx.Screenshot;
@@ -80,11 +89,34 @@
* as generic JavaFX Node, only calling public methods
* defined on this class.
*
+ * The model (AlarmClient) and the AlarmTreeView are kept in
+ * sync by a lockstep between model and view updates. When the
+ * model is changed, it calls item[removed|added]. The AlarmClient
+ * then blocks until the method returns (i.e. until the UI has
+ * been updated) and then can move on to the next update. The
+ * exception to this is itemUpdated, which adds to a queue of
+ * items to be updated which is then regularly processed.
+ *
* @author Kay Kasemir
*/
@SuppressWarnings("nls")
public class AlarmTreeView extends BorderPane implements AlarmClientListener
{
+ private enum AlarmFilter
+ {
+ DISABLED(leaf -> !leaf.isEnabled()),
+ OK(leaf -> leaf.isEnabled() && leaf.getState().severity == SeverityLevel.OK),
+ ACTIVE(leaf -> leaf.getState().severity.isActive()),
+ ACKNOWLEDGED(leaf -> leaf.getState().severity.isAcknowledged());
+
+ final Predicate predicate;
+
+ AlarmFilter(final Predicate predicate)
+ {
+ this.predicate = predicate;
+ }
+ }
+
private final Label no_server = AlarmUI.createNoServerLabel();
private final TreeView> tree_view = new TreeView<>();
@@ -112,13 +144,13 @@ public class AlarmTreeView extends BorderPane implements AlarmClientListener
private final CountDownLatch block_item_changes = new CountDownLatch(1);
/** Map from alarm tree path to view's TreeItem */
- private final ConcurrentHashMap>> path2view = new ConcurrentHashMap<>();
+ private final Map>> path2view = new HashMap<>();
/** Items to update, ordered by time of original update request
*
- * SYNC on access
+ * SYNC on access
*/
- private final Set>> items_to_update = new LinkedHashSet<>();
+ private final Set item_paths_to_update = new LinkedHashSet<>();
/** Throttle [5Hz] used for updates of existing items */
private final UpdateThrottle throttle = new UpdateThrottle(200, TimeUnit.MILLISECONDS, this::performUpdates);
@@ -140,6 +172,12 @@ public class AlarmTreeView extends BorderPane implements AlarmClientListener
items.remove(changing);
});
+ private final TextField searchBox;
+
+ private final List filterButtons = new ArrayList<>();
+
+ private final Set activeFilters = EnumSet.noneOf(AlarmFilter.class);
+
// Javadoc for TreeItem shows example for overriding isLeaf() and getChildren()
// to dynamically create TreeItem as TreeView requests information.
//
@@ -161,7 +199,7 @@ public AlarmTreeView(final AlarmClient model) {
* @param model Model to represent. Must not be running, yet
* @param itemName item name that may be expanded or given focus
*/
- public AlarmTreeView(final AlarmClient model, String itemName)
+ public AlarmTreeView(final AlarmClient model, final String itemName)
{
if (model.isRunning())
throw new IllegalStateException();
@@ -176,6 +214,15 @@ public AlarmTreeView(final AlarmClient model, String itemName)
tree_view.setCellFactory(view -> new AlarmTreeViewCell());
tree_view.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
+ searchBox = new ClearingTextField();
+ searchBox.setPromptText(Messages.searchByPv);
+ searchBox.setPrefWidth(300);
+
+ addFilterButton(ImageCache.getImageView(AlarmUI.class, "/icons/filter_disabled.png"), AlarmFilter.DISABLED, Messages.filterDisabledAlarmsTooltip, "left-pill");
+ addFilterButton(ImageCache.getImageView(AlarmUI.class, "/icons/filter_ok.png"), AlarmFilter.OK, Messages.filterOkAlarmsTooltip, "center-pill");
+ addFilterButton(ImageCache.getImageView(AlarmUI.class, "/icons/filter_active.png"), AlarmFilter.ACTIVE, Messages.filterActiveAlarmsTooltip, "center-pill");
+ addFilterButton(ImageCache.getImageView(AlarmUI.class, "/icons/filter_ack.png"), AlarmFilter.ACKNOWLEDGED, Messages.filterAcknowledgedAlarmsTooltip, "right-pill");
+
setTop(createToolbar());
setCenter(tree_view);
@@ -217,9 +264,9 @@ private void startup()
// expand tree item if is matches item name
if (tree_view.getRoot() != null && itemName != null) {
- for (TreeItem treeItem : tree_view.getRoot().getChildren()) {
- if (((AlarmTreeItem>) treeItem.getValue()).getName().equals(itemName)) {
- expandAlarms(treeItem);
+ for (final TreeItem> treeItem : tree_view.getRoot().getChildren()) {
+ if (treeItem.getValue().getName().equals(itemName)) {
+ treeItem.setExpanded(true);
break;
}
}
@@ -238,24 +285,31 @@ private ToolBar createToolbar()
{
final Button collapse = new Button("",
ImageCache.getImageView(AlarmUI.class, "/icons/collapse.png"));
- collapse.setTooltip(new Tooltip("Collapse alarm tree"));
- collapse.setOnAction(event ->
+ collapse.setTooltip(new Tooltip(Messages.collapseAlarmTree));
+ collapse.setOnAction(event -> expandOrCollapseSelection(false));
+
+ final Button expand = new Button("",
+ ImageCache.getImageView(AlarmUI.class, "/icons/expand.png"));
+ expand.setTooltip(new Tooltip(Messages.expandAlarmTree));
+ expand.setOnAction(event -> expandOrCollapseSelection(true));
+
+ final Button searchButton = new Button(Messages.search);
+
+ searchButton.setOnAction(event -> propagateVisibilityDownTree(tree_view.getRoot()));
+ searchBox.setOnAction(event -> propagateVisibilityDownTree(tree_view.getRoot())); // act as if button pressed when enter pressed
+ searchBox.textProperty().addListener(_ ->
{
- for (TreeItem> sub : tree_view.getRoot().getChildren())
- sub.setExpanded(false);
+ // act as if button pressed when text box cleared
+ if (searchBox.getText().isEmpty())
+ {
+ propagateVisibilityDownTree(tree_view.getRoot());
+ }
});
- final Button show_alarms = new Button("",
- ImageCache.getImageView(AlarmUI.class, "/icons/expand_alarms.png"));
- show_alarms.setTooltip(new Tooltip("Expand alarm tree to show active alarms"));
- show_alarms.setOnAction(event -> expandAlarms(tree_view.getRoot()));
-
- final Button show_disabled = new Button("",
- ImageCache.getImageView(AlarmUI.class, "/icons/expand_disabled.png"));
- show_disabled.setTooltip(new Tooltip("Expand alarm tree to show disabled PVs"));
- show_disabled.setOnAction(event -> expandDisabledPVs(tree_view.getRoot()));
+ final HBox filterBox = new HBox();
+ filterBox.getChildren().addAll(filterButtons);
- return new ToolBar(no_server, changing, ToolbarHelper.createSpring(), collapse, show_alarms, show_disabled);
+ return new ToolBar(searchBox, searchButton, filterBox, no_server, changing, ToolbarHelper.createSpring(), collapse, expand);
}
ToolBar getToolbar()
@@ -263,42 +317,158 @@ ToolBar getToolbar()
return (ToolBar) getTop();
}
- private void expandAlarms(final TreeItem> node)
+ /** Recursively updates the tree so that it only shows the items matching the search.
+ *
+ * This is done bottom-up, by recursing down to the leaf nodes initially to determine
+ * whether they should be visible, and then returning up the tree to determine whether
+ * each component should be visible or not, and showing/hiding it accordingly.
+ */
+ private boolean propagateVisibilityDownTree(final TreeItem> item)
{
- if (node.isLeaf())
- return;
+ for (final AlarmTreeItem> child : item.getValue().getChildren())
+ {
+ final TreeItem> childItem = path2view.get(child.getPathName());
+ if (childItem == null) {
+ continue;
+ }
+
+ final boolean shouldDisplay = propagateVisibilityDownTree(childItem);
+ if (shouldDisplay)
+ {
+ final boolean doesNotHaveChildAlready = item.getChildren().stream()
+ .noneMatch(viewChild -> viewChild.getValue().getPathName().equals(child.getPathName()));
+ if (doesNotHaveChildAlready)
+ // should display and does not have child, so add child
+ addChildToParent(item, childItem);
+ }
+ else
+ item.getChildren().remove(childItem);
+ }
- // Always expand the root, which itself is not visible,
- // but this will show all the top-level elements.
- // In addition, expand those items which are in active alarm.
- final boolean expand = node.getValue().getState().severity.isActive() ||
- node == tree_view.getRoot();
- node.setExpanded(expand);
- for (TreeItem> sub : node.getChildren())
- expandAlarms(sub);
+ return shouldDisplay(item);
}
- /** @param node Subtree node where to expand disabled PVs
- * @return Does subtree contain disabled PVs?
+ /** Ensures that an item is shown if it matches the search term, and not shown if it does not.
+ *
+ * This is done by determining whether the current node should be visible, and then propagating
+ * up the tree to ensure all the parent nodes are also only visible if they match the search term.
+ * This does not consider child nodes; it's intended to be called when a single node is added or
+ * updated to minimise state updates.
*/
- private boolean expandDisabledPVs(final TreeItem> node)
+ private void propagateVisibilityUpTree(final TreeItem> item)
{
- if (node != null && (node.getValue() instanceof AlarmClientLeaf))
+ final AlarmTreeItem> modelParent = item.getValue().getParent();
+ if (modelParent == null)
{
- AlarmClientLeaf pv = (AlarmClientLeaf) node.getValue();
- if (! pv.isEnabled())
- return true;
+ // root
+ return;
}
- // Always expand the root, which itself is not visible,
- // but this will show all the top-level elements.
- // In addition, expand those items which contain disabled PV.
- boolean expand = node == tree_view.getRoot();
- for (TreeItem> sub : node.getChildren())
- if (expandDisabledPVs(sub))
- expand = true;
- node.setExpanded(expand);
- return expand;
+ final TreeItem> currentParent = item.getParent();
+ final TreeItem> actualParent = path2view.get(modelParent.getPathName());
+ if (actualParent == null) {
+ return;
+ }
+
+ final boolean shouldDisplay = shouldDisplay(item);
+ if (shouldDisplay && currentParent == null)
+ {
+ // should display but does not have a parent (so will not be displayed)
+ addChildToParent(actualParent, item);
+ propagateVisibilityUpTree(actualParent);
+ }
+ else if (!shouldDisplay && currentParent != null)
+ {
+ // should not display but has a parent (so will be displayed)
+ actualParent.getChildren().remove(item);
+ propagateVisibilityUpTree(actualParent);
+ }
+ }
+
+ private boolean shouldDisplay(final TreeItem> item)
+ {
+ final boolean hasVisibleChildren = !item.getChildren().isEmpty();
+ if (hasVisibleChildren) {
+ return true;
+ }
+
+ // Always show components with no children... unfortunate tradeoff; otherwise they would never be shown because
+ // they don't have any leaf to match the filters
+ final boolean isEmptyComponent = item.getValue() instanceof final AlarmClientNode node && node.getChildren().isEmpty();
+ if (isEmptyComponent) {
+ return true;
+ }
+
+ // At this point, the item must match both the search and the filter to be displayed
+ final boolean matchesSearch = searchBox.getText().isEmpty() || item.getValue() instanceof final AlarmClientLeaf leaf
+ && leaf.getName().toLowerCase().contains(searchBox.getText().toLowerCase());
+ if (!matchesSearch) {
+ return false;
+ }
+
+ boolean matchesAnyFilter = activeFilters.isEmpty(); // no filters selected = show everything
+ for (final AlarmFilter filter : activeFilters) {
+ final boolean matchesFilter = item.getValue() instanceof final AlarmClientLeaf leaf && filter.predicate.test(leaf);
+ matchesAnyFilter = matchesAnyFilter || matchesFilter;
+ }
+
+ return matchesAnyFilter;
+ }
+
+ /**
+ * Adds a child TreeItem to a parent TreeItem, ensuring the order is preserved
+ *
+ * @param view_parent
+ * @param view_item
+ */
+ private static void addChildToParent(TreeItem> view_parent, TreeItem> view_item)
+ {
+ // Keep sorted by inserting at appropriate index
+ final List>> items = view_parent.getChildren();
+ final int index = Collections.binarySearch(items, view_item,
+ (a, b) -> CompareNatural.compareTo(a.getValue().getName(),
+ b.getValue().getName()));
+ if (index < 0)
+ items.add(-index - 1, view_item);
+ else
+ items.add(index, view_item);
+ }
+
+ /** Collapses or expands (depending on the value of expand) the
+ * given component, plus all of its children recursively.
+ */
+ private void expandOrCollapse(final TreeItem> component, final boolean expand)
+ {
+ if (component != tree_view.getRoot()) {
+ component.setExpanded(expand);
+ }
+
+ final List> children = component.getValue().getChildren();
+ if (!children.isEmpty()) {
+ for (final AlarmTreeItem> child : children) {
+ // We use path2view.get because component might have hidden children, which we still want to expand/collapse
+ final TreeItem> view_item = path2view.get(child.getPathName());
+ if (view_item != null) {
+ expandOrCollapse(view_item, expand);
+ }
+ }
+ }
+ }
+
+ /** Reads the selection and collapses or expands (depending on the
+ * value of expand) the selected components. If leaf nodes are
+ * selected, their parents are collapsed.
+ */
+ private void expandOrCollapseSelection(final boolean expand) {
+ // We clone the selection because we might be about to modify it
+ final List>> selected = tree_view.getSelectionModel().getSelectedItems().stream().toList();
+ if (selected.isEmpty()) {
+ expandOrCollapse(tree_view.getRoot(), expand);
+ } else {
+ for (final TreeItem> item : selected) {
+ expandOrCollapse(item.getValue() instanceof AlarmClientLeaf ? item.getParent() : item, expand);
+ }
+ }
}
private TreeItem> createViewItem(final AlarmTreeItem> model_item)
@@ -331,7 +501,7 @@ private void indicateChange()
setCursor(Cursor.WAIT);
final ObservableList items = getToolbar().getItems();
if (! items.contains(changing))
- items.add(1, changing);
+ items.add(5, changing);
}
else
previous.cancel(false);
@@ -343,7 +513,7 @@ private void showServerState(final boolean alive)
final ObservableList items = getToolbar().getItems();
items.remove(no_server);
if (! alive)
- // Place left of spring, collapse, expand_alarms,
+ // Place left of spring, collapse button, expand button,
// i.e. right of potential AlarmConfigSelector
items.add(items.size()-3, no_server);
}
@@ -387,37 +557,31 @@ private void blockItemChanges()
public void itemAdded(final AlarmTreeItem> item)
{
blockItemChanges();
- // System.out.println(Thread.currentThread() + " Add " + item.getPathName());
-
- // Parent must already exist
- final AlarmTreeItem model_parent = item.getParent();
- final TreeItem> view_parent = path2view.get(model_parent.getPathName());
-
- if (view_parent == null)
- {
- dumpTree(tree_view.getRoot());
- throw new IllegalStateException("Missing parent view item for " + item.getPathName());
- }
- // Create view item ASAP so that following updates will find it..
- final TreeItem> view_item = createViewItem(item);
- // .. but defer showing it on screen to UI thread
final CountDownLatch done = new CountDownLatch(1);
+
Platform.runLater(() ->
{
indicateChange();
- // Keep sorted by inserting at appropriate index
- final List>> items = view_parent.getChildren();
- final int index = Collections.binarySearch(items, view_item,
- (a, b) -> CompareNatural.compareTo(a.getValue().getName(),
- b.getValue().getName()));
- if (index < 0)
- items.add(-index-1, view_item);
- else
- items.add(index, view_item);
+
+ // Parent must already exist
+ final AlarmTreeItem model_parent = item.getParent();
+ final TreeItem> view_parent = path2view.get(model_parent.getPathName());
+
+ if (view_parent == null) {
+ dumpTree(tree_view.getRoot());
+ throw new IllegalStateException("Missing parent view item for " + item.getPathName());
+ }
+ final TreeItem> view_item = createViewItem(item);
+
+ propagateVisibilityUpTree(view_item);
+ // Special case: 1 - empty component added, 2 - alarm added to that component. If the filter
+ // does not match the leaf, the component should now be hidden... but propagateVisibilityUpTree
+ // short circuits, so the parent's visibility is never updated
+ propagateVisibilityUpTree(view_parent);
+
done.countDown();
});
- updateStats();
// Waiting on the UI thread throttles the model's updates
// to a rate that the UI can handle.
@@ -438,28 +602,30 @@ public void itemAdded(final AlarmTreeItem> item)
public void itemRemoved(final AlarmTreeItem> item)
{
blockItemChanges();
- // System.out.println(Thread.currentThread() + " Removed " + item.getPathName());
- // Remove item and all sub-items from model2ui
- final TreeItem> view_item = removeViewItems(item);
- if (view_item == null)
- throw new IllegalStateException("No view item for " + item.getPathName());
-
- // Remove the corresponding view
final CountDownLatch done = new CountDownLatch(1);
Platform.runLater(() ->
{
indicateChange();
+
+ // Remove item and all sub-items from model2ui
+ final TreeItem> view_item = removeViewItems(item);
+ if (view_item == null)
+ throw new IllegalStateException("No view item for " + item.getPathName());
+
+ // Remove the corresponding view
+ //
// Can only locate the parent view item on UI thread,
// because item might just have been created by itemAdded() event
// and won't be on the screen until UI thread runs.
final TreeItem> view_parent = view_item.getParent();
- if (view_parent == null)
- throw new IllegalStateException("No parent in view for " + item.getPathName());
- view_parent.getChildren().remove(view_item);
+ if (view_parent != null)
+ {
+ view_parent.getChildren().remove(view_item);
+ propagateVisibilityUpTree(view_parent);
+ }
done.countDown();
});
- updateStats();
// Waiting on the UI thread throttles the model's updates
// to a rate that the UI can handle.
@@ -493,87 +659,89 @@ private TreeItem> removeViewItems(final AlarmTreeItem> item)
public void itemUpdated(final AlarmTreeItem> item)
{
blockItemChanges();
- // System.out.println(Thread.currentThread() + " Updated " + item.getPathName());
- final TreeItem> view_item = path2view.get(item.getPathName());
- if (view_item == null)
- {
- System.out.println("Unknown view for " + item.getPathName());
- path2view.keySet().stream().forEach(System.out::println);
- throw new IllegalStateException("No view item for " + item.getPathName());
- }
// UI update of existing item, i.e.
// Platform.runLater(() -> TreeHelper.triggerTreeItemRefresh(view_item));
// is throttled.
// If several items update, they're all redrawn in one Platform call,
// and rapid updates of the same item are merged into just one final update
- synchronized (items_to_update)
+ // We push the path instead of the view item in case the view item is removed
+ // between now and the update being handled.
+ synchronized (item_paths_to_update)
{
- items_to_update.add(view_item);
+ item_paths_to_update.add(item.getPathName());
}
throttle.trigger();
- updateStats();
}
/** Called by throttle to perform accumulated updates */
- @SuppressWarnings("unchecked")
private void performUpdates()
{
- final TreeItem>[] view_items;
- synchronized (items_to_update)
+
+ // Drain items to update in one go; we will process it later on the main thread
+ final String[] view_item_paths;
+ synchronized (item_paths_to_update)
{
- // Creating a direct copy, i.e. another new LinkedHashSet<>(items_to_update),
- // would be expensive, since we only need a _list_ of what's to update.
- // Could use type-safe
- // new ArrayList>>(items_to_update)
- // but that calls toArray() internally, so doing that directly
- view_items = items_to_update.toArray(new TreeItem[items_to_update.size()]);
- items_to_update.clear();
+ view_item_paths = item_paths_to_update.toArray(new String[item_paths_to_update.size()]);
+ item_paths_to_update.clear();
}
- // Remember selection
- final ObservableList>> updatedSelectedItems =
- FXCollections.observableArrayList(tree_view.getSelectionModel().getSelectedItems());
-
- // How to update alarm tree cells when data changed?
- // `setValue()` with a truly new value (not 'equal') should suffice,
- // but there are two problems:
- // Since we're currently using the alarm tree model item as a value,
- // the value as seen by the TreeView remains the same.
- // We could use a model item wrapper class as the cell value
- // and replace it (while still holding the same model item!)
- // for the TreeView to see a different wrapper value, but
- // as shown in org.phoebus.applications.alarm.TreeItemUpdateDemo,
- // replacing a tree cell value fails to trigger refreshes
- // for certain hidden items.
- // Only replacing the TreeItem gives reliable refreshes.
- for (final TreeItem> view_item : view_items)
- // Top-level item has no parent, and is not visible, so we keep it
- if (view_item.getParent() != null)
- {
- // Locate item in tree parent
- final TreeItem> parent = view_item.getParent();
- final int index = parent.getChildren().indexOf(view_item);
-
- // Create new TreeItem for that value
- final AlarmTreeItem> value = view_item.getValue();
- final TreeItem> update = new TreeItem<>(value);
- if (updatedSelectedItems.contains(view_item)) {
- updatedSelectedItems.remove(view_item);
- updatedSelectedItems.add(update);
+ Platform.runLater(() -> {
+ // Remember selection
+ final ObservableList>> updatedSelectedItems =
+ FXCollections.observableArrayList(tree_view.getSelectionModel().getSelectedItems());
+
+ // How to update alarm tree cells when data changed?
+ // `setValue()` with a truly new value (not 'equal') should suffice,
+ // but there are two problems:
+ // Since we're currently using the alarm tree model item as a value,
+ // the value as seen by the TreeView remains the same.
+ // We could use a model item wrapper class as the cell value
+ // and replace it (while still holding the same model item!)
+ // for the TreeView to see a different wrapper value, but
+ // as shown in org.phoebus.applications.alarm.TreeItemUpdateDemo,
+ // replacing a tree cell value fails to trigger refreshes
+ // for certain hidden items.
+ // Only replacing the TreeItem gives reliable refreshes.
+ for (final String view_item_path : view_item_paths) {
+ final TreeItem> view_item = path2view.get(view_item_path);
+ if (view_item == null) {
+ // Possible if the item has been removed since it was added to the update queue
+ continue;
+ }
+
+ // Top-level item has no parent, and is not visible, so we keep it
+ if (view_item.getParent() != null) {
+ // Locate item in tree parent
+ final TreeItem> parent = view_item.getParent();
+ final int index = parent.getChildren().indexOf(view_item);
+
+ // Create new TreeItem for that value
+ final AlarmTreeItem> value = view_item.getValue();
+ final TreeItem> update = new TreeItem<>(value);
+ if (updatedSelectedItems.contains(view_item)) {
+ updatedSelectedItems.remove(view_item);
+ updatedSelectedItems.add(update);
+ }
+ // Move child links to new item
+ final ArrayList>> children = new ArrayList<>(view_item.getChildren());
+ view_item.getChildren().clear();
+ update.getChildren().addAll(children);
+ update.setExpanded(view_item.isExpanded());
+
+ path2view.put(value.getPathName(), update);
+ parent.getChildren().set(index, update);
}
- // Move child links to new item
- final ArrayList>> children = new ArrayList<>(view_item.getChildren());
- view_item.getChildren().clear();
- update.getChildren().addAll(children);
- update.setExpanded(view_item.isExpanded());
-
- path2view.put(value.getPathName(), update);
- parent.getChildren().set(index, update);
+
+ propagateVisibilityUpTree(path2view.get(view_item.getValue().getPathName()));
}
- // Restore selection
- tree_view.getSelectionModel().clearSelection();
- updatedSelectedItems.forEach(item -> tree_view.getSelectionModel().select(item));
+
+ // Restore selection
+ tree_view.getSelectionModel().clearSelection();
+ updatedSelectedItems.stream()
+ .filter(item -> item.getParent() != null)
+ .forEach(item -> tree_view.getSelectionModel().select(item));
+ });
}
/** Context menu, details depend on selected items */
@@ -689,25 +857,24 @@ private void addDragSupport()
});
}
-// private long next_stats = 0;
-// private final AtomicInteger update_count = new AtomicInteger();
-// private volatile double updates_per_sec = 0.0;
-
- private void updateStats()
+ private void addFilterButton(final Node graphic, final AlarmFilter filter, final String tooltip, final String pillClass)
{
-// final long time = System.currentTimeMillis();
-// if (time > next_stats)
-// {
-// final int updates = update_count.getAndSet(0);
-// updates_per_sec = updates_per_sec * 0.9 + updates * 0.1;
-// next_stats = time + 1000;
-// System.out.format("%.2f updates/sec\n", updates_per_sec);
-// }
-// else
-// update_count.incrementAndGet();
+ final ToggleButton toggleButton = new ToggleButton();
+ toggleButton.setGraphic(graphic);
+ toggleButton.setTooltip(new Tooltip(tooltip));
+ toggleButton.getStyleClass().add(pillClass);
+ toggleButton.selectedProperty().addListener(_ -> {
+ if (toggleButton.isSelected()) {
+ activeFilters.add(filter);
+ } else {
+ activeFilters.remove(filter);
+ }
+ propagateVisibilityDownTree(tree_view.getRoot());
+ });
+ filterButtons.add(toggleButton);
}
- private void dumpTree(TreeItem> item)
+ private static void dumpTree(final TreeItem> item)
{
final ObservableList>> children = item.getChildren();
System.out.printf("item: %s , has %d children.\n", item.getValue().getName(), children.size());
diff --git a/app/alarm/ui/src/main/resources/icons/collapse.png b/app/alarm/ui/src/main/resources/icons/collapse.png
index 6946307f0f..73ce30bfea 100644
Binary files a/app/alarm/ui/src/main/resources/icons/collapse.png and b/app/alarm/ui/src/main/resources/icons/collapse.png differ
diff --git a/app/alarm/ui/src/main/resources/icons/expand.png b/app/alarm/ui/src/main/resources/icons/expand.png
new file mode 100644
index 0000000000..bc3253b555
Binary files /dev/null and b/app/alarm/ui/src/main/resources/icons/expand.png differ
diff --git a/app/alarm/ui/src/main/resources/icons/filter_ack.png b/app/alarm/ui/src/main/resources/icons/filter_ack.png
new file mode 100644
index 0000000000..592184475b
Binary files /dev/null and b/app/alarm/ui/src/main/resources/icons/filter_ack.png differ
diff --git a/app/alarm/ui/src/main/resources/icons/filter_active.png b/app/alarm/ui/src/main/resources/icons/filter_active.png
new file mode 100644
index 0000000000..7f44751c2d
Binary files /dev/null and b/app/alarm/ui/src/main/resources/icons/filter_active.png differ
diff --git a/app/alarm/ui/src/main/resources/icons/filter_disabled.png b/app/alarm/ui/src/main/resources/icons/filter_disabled.png
new file mode 100644
index 0000000000..be8224360b
Binary files /dev/null and b/app/alarm/ui/src/main/resources/icons/filter_disabled.png differ
diff --git a/app/alarm/ui/src/main/resources/icons/filter_ok.png b/app/alarm/ui/src/main/resources/icons/filter_ok.png
new file mode 100644
index 0000000000..a943e184d0
Binary files /dev/null and b/app/alarm/ui/src/main/resources/icons/filter_ok.png differ
diff --git a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties
index 2d6d863eff..e89aa7a185 100644
--- a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties
+++ b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties
@@ -31,6 +31,7 @@ annunciateTooltip=Request audible alarm annunciation (using the description)?
automatedActions=Automated Actions:
behavior=Behavior:
behaviorTooltip=Enable alarms? See also 'Enabling Filter'
+collapseAlarmTree=Collapse selected item
commands=Commands:
configure=Configure
dateTimePickerTooltip=Select a date until which the alarm should be disabled
@@ -57,6 +58,11 @@ enablingFilterTooltip=Optional expression for enabling the alarm
error=Error
enableAlarmFailed=Failed to enable alarm
enableAlarms=Enable Alarms
+expandAlarmTree=Expand selected item
+filterAcknowledgedAlarmsTooltip=Filter acknowledged alarms
+filterActiveAlarmsTooltip=Filter active alarms
+filterDisabledAlarmsTooltip=Filter disabled alarms
+filterOkAlarmsTooltip=Filter OK alarms
guidance=Guidance:
headerAlreadyDisabled=All PVs in the selected section are already disabled
headerAlreadyEnabled=All PVs in the selected section are already enabled
@@ -86,5 +92,7 @@ tooltipMoveEditDetail=Edit the detail field of table item
tooltipMoveTableItemDown=Move table item down
tooltipMoveTableItemUp=Move table item up
totalPVs=PVs: {0}
+search=Search
+searchByPv=Search by PV
unacknowledgeFailed=Failed to unacknowledge alarm(s)
withEnableDate=With Enable Date