Search in sources :

Example 1 with WidgetActionMenuAction

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);
                }
            }
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) WidgetActionMenuAction(org.csstudio.opibuilder.actions.WidgetActionMenuAction) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) OpenDisplayAction(org.csstudio.opibuilder.widgetActions.OpenDisplayAction) ActionsInput(org.csstudio.opibuilder.widgetActions.ActionsInput) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) OpenRelatedDisplayAction(org.csstudio.opibuilder.actions.OpenRelatedDisplayAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)

Example 2 with WidgetActionMenuAction

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);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) WidgetActionMenuAction(org.csstudio.opibuilder.actions.WidgetActionMenuAction) MenuManager(org.eclipse.jface.action.MenuManager) Menu(org.eclipse.swt.widgets.Menu) AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

WidgetActionMenuAction (org.csstudio.opibuilder.actions.WidgetActionMenuAction)2 AbstractWidgetAction (org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)2 MenuManager (org.eclipse.jface.action.MenuManager)2 OpenRelatedDisplayAction (org.csstudio.opibuilder.actions.OpenRelatedDisplayAction)1 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 ActionsInput (org.csstudio.opibuilder.widgetActions.ActionsInput)1 OpenDisplayAction (org.csstudio.opibuilder.widgetActions.OpenDisplayAction)1 Point (org.eclipse.draw2d.geometry.Point)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Menu (org.eclipse.swt.widgets.Menu)1 Shell (org.eclipse.swt.widgets.Shell)1