Search in sources :

Example 6 with AbstractWidgetAction

use of org.csstudio.opibuilder.widgetActions.AbstractWidgetAction in project yamcs-studio by yamcs.

the class ActionsInputDialog method createActions.

/**
 * Creates the actions.
 */
private void createActions() {
    addAction = new Action("Add") {

        @Override
        public void run() {
        }
    };
    addAction.setMenuCreator(new IMenuCreator() {

        private Menu menu;

        @Override
        public void dispose() {
            if (menu != null) {
                menu.dispose();
                menu = null;
            }
        }

        @Override
        public Menu getMenu(final Control parent) {
            if (menu != null) {
                menu.dispose();
            }
            menu = createMenu(parent, false);
            return menu;
        }

        @Override
        public Menu getMenu(final Menu parent) {
            return null;
        }
    });
    addAction.setToolTipText("Add an action");
    addAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/add.gif"));
    copyAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
                AbstractWidgetAction newAction = ((AbstractWidgetAction) selection.getFirstElement()).getCopy();
                actionsInput.addAction(newAction);
                actionsViewer.setSelection(new StructuredSelection(newAction));
                refreshActionsViewer(newAction);
            }
        }
    };
    copyAction.setText("Copy Action");
    copyAction.setToolTipText("Copy the selected action");
    copyAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/copy.gif"));
    copyAction.setEnabled(false);
    removeAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
                actionsList.remove((AbstractWidgetAction) selection.getFirstElement());
                refreshActionsViewer(null);
                this.setEnabled(false);
            }
        }
    };
    removeAction.setText("Remove Action");
    removeAction.setToolTipText("Remove the selected action from the list");
    removeAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/delete.gif"));
    removeAction.setEnabled(false);
    moveUpAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
                AbstractWidgetAction widgetAction = (AbstractWidgetAction) selection.getFirstElement();
                int i = actionsList.indexOf(widgetAction);
                if (i > 0) {
                    actionsList.remove(widgetAction);
                    actionsList.add(i - 1, widgetAction);
                    refreshActionsViewer(widgetAction);
                }
            }
        }
    };
    moveUpAction.setText("Move Up Action");
    moveUpAction.setToolTipText("Move up the selected action");
    moveUpAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/search_prev.gif"));
    moveUpAction.setEnabled(false);
    moveDownAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
                AbstractWidgetAction widgetAction = (AbstractWidgetAction) selection.getFirstElement();
                int i = actionsList.indexOf(widgetAction);
                if (i < actionsList.size() - 1) {
                    actionsList.remove(widgetAction);
                    actionsList.add(i + 1, widgetAction);
                    refreshActionsViewer(widgetAction);
                }
            }
        }
    };
    moveDownAction.setText("Move Down Action");
    moveDownAction.setToolTipText("Move down the selected action");
    moveDownAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/search_next.gif"));
    moveDownAction.setEnabled(false);
}
Also used : AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction) Action(org.eclipse.jface.action.Action) Control(org.eclipse.swt.widgets.Control) IMenuCreator(org.eclipse.jface.action.IMenuCreator) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Menu(org.eclipse.swt.widgets.Menu) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)

Example 7 with AbstractWidgetAction

use of org.csstudio.opibuilder.widgetActions.AbstractWidgetAction in project yamcs-studio by yamcs.

the class Draw2DButtonEditPartDelegate method hookMouseClickAction.

/* (non-Javadoc)
     * @see org.csstudio.opibuilder.widgets.editparts.IButtonEditPartDelegate#hookMouseClickAction()
     */
@Override
public void hookMouseClickAction() {
    ((ActionButtonFigure) editpart.getFigure()).addActionListener(new ButtonActionListener() {

        @Override
        public void actionPerformed(int mouseEventState) {
            List<AbstractWidgetAction> actions = editpart.getHookedActions();
            if (actions != null) {
                for (AbstractWidgetAction action : actions) {
                    if (action instanceof OpenDisplayAction)
                        ((OpenDisplayAction) action).runWithModifiers((mouseEventState & SWT.CONTROL) != 0, (mouseEventState & SWT.SHIFT) != 0);
                    else
                        action.run();
                }
            }
        }
    });
}
Also used : OpenDisplayAction(org.csstudio.opibuilder.widgetActions.OpenDisplayAction) List(java.util.List) ActionButtonFigure(org.csstudio.swt.widgets.figures.ActionButtonFigure) ButtonActionListener(org.csstudio.swt.widgets.figures.ActionButtonFigure.ButtonActionListener) AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)

Example 8 with AbstractWidgetAction

use of org.csstudio.opibuilder.widgetActions.AbstractWidgetAction 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)

Example 9 with AbstractWidgetAction

use of org.csstudio.opibuilder.widgetActions.AbstractWidgetAction in project yamcs-studio by yamcs.

the class NativeButtonEditPartDelegate method hookMouseClickAction.

@Override
public void hookMouseClickAction() {
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            List<AbstractWidgetAction> actions = editpart.getHookedActions();
            if (actions != null) {
                for (AbstractWidgetAction action : actions) {
                    if (action instanceof OpenDisplayAction)
                        ((OpenDisplayAction) action).runWithModifiers((e.stateMask & SWT.CTRL) != 0, (e.stateMask & SWT.SHIFT) != 0);
                    else
                        action.run();
                }
            }
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) OpenDisplayAction(org.csstudio.opibuilder.widgetActions.OpenDisplayAction) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)

Example 10 with AbstractWidgetAction

use of org.csstudio.opibuilder.widgetActions.AbstractWidgetAction in project yamcs-studio by yamcs.

the class ActionsProperty method writeToXML.

@Override
public void writeToXML(Element propElement) {
    ActionsInput actionsInput = (ActionsInput) getPropertyValue();
    // //$NON-NLS-1$
    propElement.setAttribute(XML_ATTRIBUTE_HOOK_FIRST, "" + actionsInput.isFirstActionHookedUpToWidget());
    // //$NON-NLS-1$
    propElement.setAttribute(XML_ATTRIBUTE_HOOK_ALL, "" + actionsInput.isHookUpAllActionsToWidget());
    for (AbstractWidgetAction action : actionsInput.getActionsList()) {
        Element actionElement = new Element(XML_ELEMENT_ACTION);
        actionElement.setAttribute(XML_ATTRIBUTE_ACTION_TYPE, action.getActionType().toString());
        for (AbstractWidgetProperty property : action.getAllProperties()) {
            Element propEle = new Element(property.getPropertyID());
            property.writeToXML(propEle);
            actionElement.addContent(propEle);
        }
        propElement.addContent(actionElement);
    }
}
Also used : ActionsInput(org.csstudio.opibuilder.widgetActions.ActionsInput) Element(org.jdom.Element) AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)

Aggregations

AbstractWidgetAction (org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)10 ActionsInput (org.csstudio.opibuilder.widgetActions.ActionsInput)4 OpenDisplayAction (org.csstudio.opibuilder.widgetActions.OpenDisplayAction)4 List (java.util.List)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 WidgetActionMenuAction (org.csstudio.opibuilder.actions.WidgetActionMenuAction)2 MenuManager (org.eclipse.jface.action.MenuManager)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Menu (org.eclipse.swt.widgets.Menu)2 Element (org.jdom.Element)2 OpenRelatedDisplayAction (org.csstudio.opibuilder.actions.OpenRelatedDisplayAction)1 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 ScriptData (org.csstudio.opibuilder.script.ScriptData)1 IPV (org.csstudio.simplepv.IPV)1 ActionButtonFigure (org.csstudio.swt.widgets.figures.ActionButtonFigure)1 ButtonActionListener (org.csstudio.swt.widgets.figures.ActionButtonFigure.ButtonActionListener)1 Point (org.eclipse.draw2d.geometry.Point)1 Action (org.eclipse.jface.action.Action)1