Search in sources :

Example 1 with ActionsInput

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

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

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

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

the class ActionButtonEditPart method getHookedActionsForButton.

/**
 * A shared static method for all button widgets.
 *
 * @param widgetModel
 * @param isSelected
 * @return
 */
public static List<AbstractWidgetAction> getHookedActionsForButton(ActionButtonModel widgetModel, boolean isSelected) {
    int actionIndex;
    if (widgetModel.isToggleButton()) {
        if (isSelected) {
            actionIndex = widgetModel.getActionIndex();
        } else
            actionIndex = widgetModel.getReleasedActionIndex();
    } else
        actionIndex = widgetModel.getActionIndex();
    ActionsInput actionsInput = widgetModel.getActionsInput();
    if (actionsInput.getActionsList().size() <= 0)
        return null;
    if (actionsInput.isHookUpAllActionsToWidget())
        return actionsInput.getActionsList();
    if (actionIndex >= 0 && actionsInput.getActionsList().size() > actionIndex) {
        return widgetModel.getActionsInput().getActionsList().subList(actionIndex, actionIndex + 1);
    }
    if (actionIndex == -1)
        return actionsInput.getActionsList();
    return null;
}
Also used : ActionsInput(org.csstudio.opibuilder.widgetActions.ActionsInput)

Example 5 with ActionsInput

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

the class ActionsInputDialog method getOutput.

public ActionsInput getOutput() {
    ActionsInput actionsInput = new ActionsInput(actionsList);
    actionsInput.setHookUpFirstActionToWidget(hookedUpFirstActionToWidget);
    actionsInput.setHookUpAllActionsToWidget(hookedUpAllActionsToWidget);
    return actionsInput;
}
Also used : ActionsInput(org.csstudio.opibuilder.widgetActions.ActionsInput)

Aggregations

ActionsInput (org.csstudio.opibuilder.widgetActions.ActionsInput)8 AbstractWidgetAction (org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)4 IPV (org.csstudio.simplepv.IPV)2 Element (org.jdom.Element)2 OpenRelatedDisplayAction (org.csstudio.opibuilder.actions.OpenRelatedDisplayAction)1 WidgetActionMenuAction (org.csstudio.opibuilder.actions.WidgetActionMenuAction)1 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 ScriptData (org.csstudio.opibuilder.script.ScriptData)1 OpenDisplayAction (org.csstudio.opibuilder.widgetActions.OpenDisplayAction)1 WritePVAction (org.csstudio.opibuilder.widgetActions.WritePVAction)1 VEnum (org.diirt.vtype.VEnum)1 VType (org.diirt.vtype.VType)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1