use of org.csstudio.opibuilder.actions.WidgetActionMenuAction in project yamcs-studio by yamcs.
the class OPIRunnerContextMenuProvider method addWidgetActionToMenu.
/**
* Adds the defined {@link AbstractWidgetAction}s to the given {@link IMenuManager}.
*
* @param menu
* The {@link IMenuManager}
*/
private void addWidgetActionToMenu(final IMenuManager menu) {
List<?> selectedEditParts = ((IStructuredSelection) getViewer().getSelection()).toList();
if (selectedEditParts.size() == 1) {
if (selectedEditParts.get(0) instanceof AbstractBaseEditPart) {
AbstractBaseEditPart editPart = (AbstractBaseEditPart) selectedEditParts.get(0);
AbstractWidgetModel widget = editPart.getWidgetModel();
// add menu Open, Open in New Tab and Open in New Window
List<AbstractWidgetAction> hookedActions = editPart.getHookedActions();
if (hookedActions != null && hookedActions.size() == 1) {
AbstractWidgetAction hookedAction = hookedActions.get(0);
if (hookedAction instanceof OpenDisplayAction) {
final OpenDisplayAction original_action = (OpenDisplayAction) hookedAction;
menu.add(new OpenRelatedDisplayAction(original_action, OpenDisplayTarget.DEFAULT));
menu.add(new OpenRelatedDisplayAction(original_action, OpenDisplayTarget.NEW_TAB));
menu.add(new OpenRelatedDisplayAction(original_action, OpenDisplayTarget.NEW_WINDOW));
menu.add(new OpenRelatedDisplayAction(original_action, OpenDisplayTarget.NEW_SHELL));
}
}
ActionsInput ai = widget.getActionsInput();
if (ai != null) {
List<AbstractWidgetAction> widgetActions = ai.getActionsList();
if (!widgetActions.isEmpty()) {
MenuManager actionMenu = new MenuManager("Actions", "actions");
for (AbstractWidgetAction action : widgetActions) {
actionMenu.add(new WidgetActionMenuAction(action));
}
menu.add(actionMenu);
}
}
}
}
}
use of org.csstudio.opibuilder.actions.WidgetActionMenuAction in project yamcs-studio by yamcs.
the class MenuButtonEditPart method showMenu.
/**
* Show Menu
*
* @param point
* the location of the mouse-event in the OPI display
* @param absolutX
* The x coordinate of the mouse on the monitor
* @param absolutY
* The y coordinate of the mouse on the monitor
*/
private void showMenu(final Point point, final int absolutX, final int absolutY) {
if (getExecutionMode().equals(ExecutionMode.RUN_MODE)) {
final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
MenuManager menuManager = new MenuManager();
for (AbstractWidgetAction action : getWidgetModel().getActionsInput().getActionsList()) {
menuManager.add(new WidgetActionMenuAction(action));
}
Menu menu = menuManager.createContextMenu(shell);
/*
* We need to position the menu in absolute monitor coordinates.
* First we calculate the coordinates of the display, then add the
* widget coordinates to these so that the menu opens on the
* bottom left of the widget.
*/
int x = absolutX - point.x;
int y = absolutY - point.y;
x += getWidgetModel().getLocation().x;
y += getWidgetModel().getLocation().y + getWidgetModel().getSize().height;
menu.setLocation(x, y);
menu.setVisible(true);
}
}
Aggregations