Skip to content
Open
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
2 changes: 1 addition & 1 deletion app/alarm/ui/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ Where the include component is identified in the inclusion file with a DID decla
Context Menu
------------

In the Alarm Tree and the Alarm Table views user may right click on an alarm item to launch a context menu:
In the Alarm Tree, the Alarm Table views and the Annunciator user may right click on an alarm item to launch a context menu:

.. image:: images/context_menu_new.png
:width: 20%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,42 @@
import static org.phoebus.applications.alarm.AlarmSystem.logger;

import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.stream.Collectors;

import javafx.collections.ObservableList;
import javafx.scene.control.*;
import org.phoebus.applications.alarm.AlarmSystem;
import org.phoebus.applications.alarm.client.AlarmClientLeaf;
import org.phoebus.applications.alarm.client.AlarmClientNode;
import org.phoebus.applications.alarm.model.AlarmTreeItem;
import org.phoebus.applications.alarm.model.SeverityLevel;
import org.phoebus.applications.alarm.talk.TalkClient;
import org.phoebus.applications.alarm.talk.TalkClientListener;
import org.phoebus.applications.alarm.ui.AlarmContextMenuHelper;
import org.phoebus.applications.alarm.ui.AlarmUI;
import org.phoebus.applications.alarm.ui.tree.*;
import org.phoebus.framework.selection.Selection;
import org.phoebus.framework.selection.SelectionService;
import org.phoebus.ui.application.ContextMenuService;
import org.phoebus.ui.application.SaveSnapshotAction;
import org.phoebus.ui.dialog.DialogHelper;
import org.phoebus.ui.docking.DockPane;
import org.phoebus.ui.javafx.ImageCache;
import org.phoebus.ui.javafx.PrintAction;
import org.phoebus.ui.javafx.Screenshot;
import org.phoebus.ui.javafx.ToolbarHelper;
import org.phoebus.ui.selection.AppSelection;
import org.phoebus.ui.spi.ContextMenuEntry;
import org.phoebus.util.time.TimestampFormats;

import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.SortType;
import javafx.scene.control.TableView;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToolBar;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Background;
Expand Down Expand Up @@ -271,10 +279,42 @@

getChildren().setAll(toolbar, table);

// Annunciate message so that user can determine if annunciator and table are indeed functional.
createContextMenu();

messageReceived(SeverityLevel.OK, true, "Annunciator started");
}

private void createContextMenu()
{
final ContextMenu menu = new ContextMenu();

table.setOnContextMenuRequested(event ->
{
final ObservableList<MenuItem> menu_items = menu.getItems();

Check warning on line 293 in app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/annunciator/AnnunciatorTable.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ-ocqoZiLnwHvvk_H4w&open=AZ-ocqoZiLnwHvvk_H4w&pullRequest=3897
menu_items.clear();

final Selection originalSelection = SelectionService.getInstance().getSelection();
final List<AppSelection> newSelection = Arrays.asList(AppSelection.of(table, "Annunciator Screenshot", "see annunciator screenshot", () -> Screenshot.imageFromNode(table)));
SelectionService.getInstance().setSelection("Annunciator", newSelection);

Check failure on line 298 in app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/annunciator/AnnunciatorTable.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "Annunciator" 3 times.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ-ocqoZiLnwHvvk_H4x&open=AZ-ocqoZiLnwHvvk_H4x&pullRequest=3897
List<ContextMenuEntry> supported = ContextMenuService.getInstance().listSupportedContextMenuEntries();
supported.stream().forEach(action -> {
MenuItem supportedMenuItem = new MenuItem(action.getName(), new ImageView(action.getIcon()));
supportedMenuItem.setOnAction((e) -> {
try{
SelectionService.getInstance().setSelection("Annunciator", newSelection);
action.call(table, SelectionService.getInstance().getSelection());
} catch (Exception ex) {
logger.log(Level.WARNING, "Failed to execute " + action.getName() + " from Annunciator.", ex);
}
});
menu_items.add(supportedMenuItem);
});
menu_items.add(new SaveSnapshotAction(DockPane.getActiveDockPane()));
SelectionService.getInstance().setSelection("Annunciator", originalSelection);
menu.show(table.getScene().getWindow(), event.getScreenX(), event.getScreenY());
});
}

ToolBar getToolbar()
{
return toolbar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@
* @return A list of {@link ContextMenuEntry}'s supported for the current
* selection
*/

public List<ContextMenuEntry> listSupportedContextMenuEntries() {
// List of types of the current selection
List<Class> selectionTypes = SelectionService.getInstance().getSelection().getSelections().stream().map(s -> {
return s.getClass();
}).collect(Collectors.toList());

System.out.println("selection types: " + selectionTypes);

Check warning on line 64 in core/ui/src/main/java/org/phoebus/ui/application/ContextMenuService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this use of System.out by a logger.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ-ocqr0iLnwHvvk_H4y&open=AZ-ocqr0iLnwHvvk_H4y&pullRequest=3897

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a debug printout added while working on this. Remove?

// Take into account the types the selected objects can be converted into
List<Class> allAdaptableSelectionType = new ArrayList<>();
selectionTypes.forEach(s -> {
Expand Down
Loading