Search in sources :

Example 1 with ScriptsInput

use of org.csstudio.opibuilder.script.ScriptsInput in project yamcs-studio by yamcs.

the class ScriptProperty method readValueFromXML.

@Override
public ScriptsInput readValueFromXML(Element propElement) {
    ScriptsInput result = new ScriptsInput();
    for (Object oe : propElement.getChildren(XML_ELEMENT_PATH)) {
        Element se = (Element) oe;
        ScriptData sd = new ScriptData();
        if (se.getAttributeValue(XML_ATTRIBUTE_PATHSTRING).equals(EMBEDDEDJS)) {
            sd.setEmbedded(true);
            sd.setScriptType(ScriptType.JAVASCRIPT);
            sd.setScriptText(se.getChildText(XML_ELEMENT_SCRIPT_TEXT));
            sd.setScriptName(se.getChildText(XML_ELEMENT_SCRIPT_NAME));
        } else if (se.getAttributeValue(XML_ATTRIBUTE_PATHSTRING).equals(EMBEDDEDPY)) {
            sd.setEmbedded(true);
            sd.setScriptType(ScriptType.PYTHON);
            sd.setScriptText(se.getChildText(XML_ELEMENT_SCRIPT_TEXT));
            sd.setScriptName(se.getChildText(XML_ELEMENT_SCRIPT_NAME));
        } else
            sd = new ScriptData(new Path(se.getAttributeValue(XML_ATTRIBUTE_PATHSTRING)));
        if (se.getAttributeValue(XML_ATTRIBUTE_CHECKCONNECT) != null)
            sd.setCheckConnectivity(Boolean.parseBoolean(se.getAttributeValue(XML_ATTRIBUTE_CHECKCONNECT)));
        if (se.getAttributeValue(XML_ATTRIBUTE_SKIP_FIRST_EXECUTION) != null)
            sd.setSkipPVsFirstConnection(Boolean.parseBoolean(se.getAttributeValue(XML_ATTRIBUTE_SKIP_FIRST_EXECUTION)));
        if (se.getAttributeValue(XML_ATTRIBUTE_STOP_EXECUTE_ON_ERROR) != null)
            sd.setStopExecuteOnError(Boolean.parseBoolean(se.getAttributeValue(XML_ATTRIBUTE_STOP_EXECUTE_ON_ERROR)));
        for (Object o : se.getChildren(XML_ELEMENT_PV)) {
            Element pve = (Element) o;
            boolean trig = true;
            if (pve.getAttribute(XML_ATTRIBUTE_TRIGGER) != null)
                trig = Boolean.parseBoolean(pve.getAttributeValue(XML_ATTRIBUTE_TRIGGER));
            sd.addPV(new PVTuple(pve.getText(), trig));
        }
        result.getScriptList().add(sd);
    }
    return result;
}
Also used : Path(org.eclipse.core.runtime.Path) Element(org.jdom.Element) ScriptsInput(org.csstudio.opibuilder.script.ScriptsInput) ScriptData(org.csstudio.opibuilder.script.ScriptData) PVTuple(org.csstudio.opibuilder.script.PVTuple)

Example 2 with ScriptsInput

use of org.csstudio.opibuilder.script.ScriptsInput in project yamcs-studio by yamcs.

the class AbstractBaseEditPart method activate.

@Override
public void activate() {
    if (!isActive()) {
        super.activate();
        initFigure(getFigure());
        // add listener to all properties.
        for (String id : getWidgetModel().getAllPropertyIDs()) {
            AbstractWidgetProperty property = getWidgetModel().getProperty(id);
            if (property != null) {
                WidgetPropertyChangeListener listener = new WidgetPropertyChangeListener(this, property);
                property.addPropertyChangeListener(listener);
                propertyListenerMap.put(id, listener);
                property.setExecutionMode(executionMode);
                property.setWidgetModel(getWidgetModel());
            }
        }
        registerBasePropertyChangeHandlers();
        registerPropertyChangeHandlers();
        if (executionMode == ExecutionMode.RUN_MODE) {
            // hook open display action
            Set<String> allPropIds = getWidgetModel().getAllPropertyIDs();
            if (allPropIds.contains(AbstractWidgetModel.PROP_ACTIONS) && allPropIds.contains(AbstractWidgetModel.PROP_ENABLED)) {
                hookMouseClickAction();
            }
            // script and rules execution
            ScriptsInput scriptsInput = getWidgetModel().getScriptsInput();
            scriptDataList = new ArrayList<>(scriptsInput.getScriptList());
            for (RuleData rd : getWidgetModel().getRulesInput().getRuleDataList()) {
                scriptDataList.add(rd.convertToScriptData());
            }
            for (final ScriptData scriptData : scriptDataList) {
                final IPV[] pvArray = new IPV[scriptData.getPVList().size()];
                int i = 0;
                for (PVTuple pvTuple : scriptData.getPVList()) {
                    String pvName = pvTuple.pvName;
                    if (pvMap.containsKey(pvName)) {
                        pvArray[i] = pvMap.get(pvName);
                    } else {
                        try {
                            IPV pv = BOYPVFactory.createPV(pvName, false, 2);
                            pvMap.put(pvName, pv);
                            addToConnectionHandler(pvName, pv);
                            pvArray[i] = pv;
                        } catch (Exception e) {
                            String message = NLS.bind("Unable to connect to PV: {0}! \n" + "This may cause error when executing the script.", pvName);
                            OPIBuilderPlugin.getLogger().log(Level.WARNING, message, e);
                            ConsoleService.getInstance().writeError(message);
                            pvArray[i] = null;
                        }
                    }
                    i++;
                }
                ScriptService.getInstance().registerScript(scriptData, AbstractBaseEditPart.this, pvArray);
                UIBundlingThread.getInstance().addRunnable(new Runnable() {

                    @Override
                    public void run() {
                        if (!isActive()) {
                            // already deactivated
                            return;
                        }
                        hasStartedPVs = true;
                        for (IPV pv : pvArray) if (pv != null && !pv.isStarted())
                            try {
                                pv.start();
                            } catch (Exception e) {
                                OPIBuilderPlugin.getLogger().log(Level.WARNING, "Unable to start PV " + pv.getName(), // $NON-NLS-1$
                                e);
                            }
                    }
                });
            }
        }
        doActivate();
    }
    // Rap specified code
    displayDisposeListener = new Runnable() {

        @Override
        public void run() {
            deactivate();
        }
    };
}
Also used : AbstractWidgetProperty(org.csstudio.opibuilder.properties.AbstractWidgetProperty) ScriptData(org.csstudio.opibuilder.script.ScriptData) PVTuple(org.csstudio.opibuilder.script.PVTuple) WidgetPropertyChangeListener(org.csstudio.opibuilder.properties.WidgetPropertyChangeListener) IPV(org.csstudio.simplepv.IPV) Point(org.eclipse.draw2d.geometry.Point) RuleData(org.csstudio.opibuilder.script.RuleData) ScriptsInput(org.csstudio.opibuilder.script.ScriptsInput)

Example 3 with ScriptsInput

use of org.csstudio.opibuilder.script.ScriptsInput in project yamcs-studio by yamcs.

the class AbstractWidgetModel method processVersionDifference.

/**
 * Make necessary adjustment for widget compatibility between different versions.
 */
public void processVersionDifference(Version boyVersionOnFile) {
    // update pv name
    if (UpgradeUtil.VERSION_WITH_PVMANAGER.compareTo(boyVersionOnFile) > 0) {
        if (propertyMap.containsKey(PROP_SCRIPTS)) {
            ScriptsInput scriptsInput = getScriptsInput();
            for (ScriptData sd : scriptsInput.getScriptList()) {
                for (PVTuple tuple : sd.getPVList()) {
                    tuple.pvName = UpgradeUtil.convertUtilityPVNameToPM(tuple.pvName);
                }
            }
            setPropertyValue(PROP_SCRIPTS, scriptsInput);
        }
        if (propertyMap.containsKey(PROP_RULES)) {
            RulesInput rulesInput = getRulesInput();
            for (RuleData rd : rulesInput.getRuleDataList()) {
                for (PVTuple tuple : rd.getPVList()) {
                    tuple.pvName = UpgradeUtil.convertUtilityPVNameToPM(tuple.pvName);
                }
            }
            setPropertyValue(PROP_RULES, rulesInput);
        }
    }
}
Also used : RuleData(org.csstudio.opibuilder.script.RuleData) RulesInput(org.csstudio.opibuilder.script.RulesInput) ScriptsInput(org.csstudio.opibuilder.script.ScriptsInput) ScriptData(org.csstudio.opibuilder.script.ScriptData) PVTuple(org.csstudio.opibuilder.script.PVTuple)

Example 4 with ScriptsInput

use of org.csstudio.opibuilder.script.ScriptsInput in project yamcs-studio by yamcs.

the class ScriptProperty method writeToXML.

@Override
public void writeToXML(Element propElement) {
    for (ScriptData scriptData : ((ScriptsInput) getPropertyValue()).getScriptList()) {
        Element pathElement = new Element(XML_ELEMENT_PATH);
        String pathString = null;
        if (scriptData.isEmbedded()) {
            if (scriptData.getScriptType() == ScriptType.JAVASCRIPT)
                pathString = EMBEDDEDJS;
            else if (scriptData.getScriptType() == ScriptType.PYTHON)
                pathString = EMBEDDEDPY;
            Element scriptNameElement = new Element(XML_ELEMENT_SCRIPT_NAME);
            scriptNameElement.setText(scriptData.getScriptName());
            pathElement.addContent(scriptNameElement);
            Element scriptTextElement = new Element(XML_ELEMENT_SCRIPT_TEXT);
            scriptTextElement.setContent(new CDATA(scriptData.getScriptText()));
            pathElement.addContent(scriptTextElement);
        } else
            pathString = scriptData.getPath().toPortableString();
        pathElement.setAttribute(XML_ATTRIBUTE_PATHSTRING, pathString);
        pathElement.setAttribute(XML_ATTRIBUTE_CHECKCONNECT, Boolean.toString(scriptData.isCheckConnectivity()));
        pathElement.setAttribute(XML_ATTRIBUTE_SKIP_FIRST_EXECUTION, Boolean.toString(scriptData.isSkipPVsFirstConnection()));
        pathElement.setAttribute(XML_ATTRIBUTE_STOP_EXECUTE_ON_ERROR, Boolean.toString(scriptData.isStopExecuteOnError()));
        for (PVTuple pv : scriptData.getPVList()) {
            Element pvElement = new Element(XML_ELEMENT_PV);
            pvElement.setText(pv.pvName);
            pvElement.setAttribute(XML_ATTRIBUTE_TRIGGER, Boolean.toString(pv.trigger));
            pathElement.addContent(pvElement);
        }
        propElement.addContent(pathElement);
    }
}
Also used : Element(org.jdom.Element) ScriptData(org.csstudio.opibuilder.script.ScriptData) ScriptsInput(org.csstudio.opibuilder.script.ScriptsInput) PVTuple(org.csstudio.opibuilder.script.PVTuple) CDATA(org.jdom.CDATA)

Example 5 with ScriptsInput

use of org.csstudio.opibuilder.script.ScriptsInput in project yamcs-studio by yamcs.

the class ScriptProperty method getPropertyValue.

@Override
public Object getPropertyValue() {
    if (executionMode == ExecutionMode.RUN_MODE && widgetModel != null) {
        ScriptsInput value = (ScriptsInput) super.getPropertyValue();
        for (ScriptData sd : value.getScriptList()) {
            for (Object pv : sd.getPVList().toArray()) {
                PVTuple pvTuple = (PVTuple) pv;
                String newPV = OPIBuilderMacroUtil.replaceMacros(widgetModel, pvTuple.pvName);
                if (!newPV.equals(pvTuple.pvName)) {
                    int i = sd.getPVList().indexOf(pv);
                    sd.getPVList().remove(pv);
                    sd.getPVList().add(i, new PVTuple(newPV, pvTuple.trigger));
                }
            }
        }
        return value;
    } else
        return super.getPropertyValue();
}
Also used : ScriptsInput(org.csstudio.opibuilder.script.ScriptsInput) ScriptData(org.csstudio.opibuilder.script.ScriptData) PVTuple(org.csstudio.opibuilder.script.PVTuple)

Aggregations

PVTuple (org.csstudio.opibuilder.script.PVTuple)5 ScriptData (org.csstudio.opibuilder.script.ScriptData)5 ScriptsInput (org.csstudio.opibuilder.script.ScriptsInput)5 RuleData (org.csstudio.opibuilder.script.RuleData)2 Element (org.jdom.Element)2 AbstractWidgetProperty (org.csstudio.opibuilder.properties.AbstractWidgetProperty)1 WidgetPropertyChangeListener (org.csstudio.opibuilder.properties.WidgetPropertyChangeListener)1 RulesInput (org.csstudio.opibuilder.script.RulesInput)1 IPV (org.csstudio.simplepv.IPV)1 Path (org.eclipse.core.runtime.Path)1 Point (org.eclipse.draw2d.geometry.Point)1 CDATA (org.jdom.CDATA)1