Search in sources :

Example 1 with AbstractWidgetAction

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

the class ActionsProperty method readValueFromXML.

@Override
public ActionsInput readValueFromXML(Element propElement) {
    ActionsInput result = new ActionsInput();
    result.setHookUpFirstActionToWidget(Boolean.parseBoolean(propElement.getAttributeValue(XML_ATTRIBUTE_HOOK_FIRST)));
    if (propElement.getAttribute(XML_ATTRIBUTE_HOOK_ALL) != null)
        result.setHookUpAllActionsToWidget(Boolean.parseBoolean(propElement.getAttributeValue(XML_ATTRIBUTE_HOOK_ALL)));
    for (Object oe : propElement.getChildren(XML_ELEMENT_ACTION)) {
        Element se = (Element) oe;
        AbstractWidgetAction action = WidgetActionFactory.createWidgetAction(ActionType.parseAction(se.getAttributeValue(XML_ATTRIBUTE_ACTION_TYPE)));
        if (action != null) {
            List<?> children = se.getChildren();
            Iterator<?> iterator = children.iterator();
            Set<String> propIdSet = action.getAllPropertyIDs();
            while (iterator.hasNext()) {
                Element subElement = (Element) iterator.next();
                // handle property
                if (propIdSet.contains(subElement.getName())) {
                    String propId = subElement.getName();
                    try {
                        action.setPropertyValue(propId, action.getProperty(propId).readValueFromXML(subElement));
                    } catch (Exception e) {
                        String errorMessage = "Failed to read the " + propId + " property for " + action.getDescription() + ". " + "The default property value will be setted instead. \n" + e;
                        OPIBuilderPlugin.getLogger().log(Level.WARNING, errorMessage, e);
                        ConsoleService.getInstance().writeWarning(errorMessage);
                    }
                }
            }
            result.getActionsList().add(action);
        }
    }
    return result;
}
Also used : ActionsInput(org.csstudio.opibuilder.widgetActions.ActionsInput) Element(org.jdom.Element) AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)

Example 2 with AbstractWidgetAction

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

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

the class AbstractBaseEditPart method deactivate.

@Override
public void deactivate() {
    if (isActive()) {
        doDeActivate();
        ActionsInput input = getWidgetModel().getActionsInput();
        for (AbstractWidgetAction a : input.getActionsList()) {
            a.dispose();
        }
        super.deactivate();
        // remove listener from all properties.
        for (String id : getWidgetModel().getAllPropertyIDs()) {
            getWidgetModel().getProperty(id).removeAllPropertyChangeListeners();
        }
        if (executionMode == ExecutionMode.RUN_MODE) {
            // remove script listeners before stopping PV.
            for (ScriptData scriptData : scriptDataList) {
                ScriptService.getInstance().unRegisterScript(scriptData);
            }
            if (hasStartedPVs) {
                // we should not attempt to stop those pvs; this can happen with linking container
                for (Object pv : pvMap.values().toArray()) {
                    ((IPV) pv).stop();
                }
            }
        }
        propertyListenerMap.clear();
    // propertyListenerMap = null;
    }
}
Also used : ActionsInput(org.csstudio.opibuilder.widgetActions.ActionsInput) ScriptData(org.csstudio.opibuilder.script.ScriptData) AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction) IPV(org.csstudio.simplepv.IPV)

Example 4 with AbstractWidgetAction

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

the class NativeButtonEditPart method hookMouseClickAction.

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            List<AbstractWidgetAction> actions = 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 5 with AbstractWidgetAction

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

the class ActionsInputDialog method refreshGUIOnSelection.

/**
 * Refreshes the enabled-state of the actions.
 */
private void refreshGUIOnSelection() {
    IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
    if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
        removeAction.setEnabled(true);
        moveUpAction.setEnabled(true);
        moveDownAction.setEnabled(true);
        copyAction.setEnabled(true);
        propertiesViewer.setInput(((AbstractWidgetAction) selection.getFirstElement()).getAllProperties());
        propertiesViewer.getTable().setEnabled(true);
    } else {
        removeAction.setEnabled(false);
        moveUpAction.setEnabled(false);
        moveDownAction.setEnabled(false);
        propertiesViewer.getTable().setEnabled(false);
        copyAction.setEnabled(false);
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) 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