Search in sources :

Example 6 with RuleData

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

the class RulesInputDialog method createActions.

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

        @Override
        public void run() {
            RuleDataEditDialog dialog = new RuleDataEditDialog(getShell(), new RuleData(widgetModel));
            if (dialog.open() == OK) {
                ruleDataList.add(dialog.getOutput());
                rulesViewer.refresh();
            }
        }
    };
    addAction.setToolTipText("Add a Rule");
    addAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, // $NON-NLS-1$
    "icons/add.gif"));
    editAction = new Action("Edit") {

        @Override
        public void run() {
            invokeRuleDataDialog();
        }
    };
    editAction.setToolTipText("Edit Selected Rule");
    editAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, // $NON-NLS-1$
    "icons/edit.gif"));
    editAction.setEnabled(false);
    copyAction = new Action("Copy") {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) rulesViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof RuleData) {
                RuleData ruleData = ((RuleData) selection.getFirstElement()).getCopy();
                ruleDataList.add(ruleData);
                setRulesViewerSelection(ruleData);
            }
        }
    };
    copyAction.setToolTipText("Copy Selected Rule");
    copyAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, // $NON-NLS-1$
    "icons/copy.gif"));
    copyAction.setEnabled(false);
    removeAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) rulesViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof RuleData) {
                ruleDataList.remove((RuleData) selection.getFirstElement());
                setRulesViewerSelection(null);
                this.setEnabled(false);
            }
        }
    };
    removeAction.setToolTipText("Remove Selected Rule");
    removeAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, // $NON-NLS-1$
    "icons/delete.gif"));
    removeAction.setEnabled(false);
    moveUpAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) rulesViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof RuleData) {
                RuleData ruleData = (RuleData) selection.getFirstElement();
                int i = ruleDataList.indexOf(ruleData);
                if (i > 0) {
                    ruleDataList.remove(ruleData);
                    ruleDataList.add(i - 1, ruleData);
                    setRulesViewerSelection(ruleData);
                }
            }
        }
    };
    moveUpAction.setText("Move Rule Up");
    moveUpAction.setToolTipText("Move Selected Rule up");
    moveUpAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, // $NON-NLS-1$
    "icons/search_prev.gif"));
    moveUpAction.setEnabled(false);
    moveDownAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) rulesViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof RuleData) {
                RuleData ruleData = (RuleData) selection.getFirstElement();
                int i = ruleDataList.indexOf(ruleData);
                if (i < ruleDataList.size() - 1) {
                    ruleDataList.remove(ruleData);
                    ruleDataList.add(i + 1, ruleData);
                    setRulesViewerSelection(ruleData);
                }
            }
        }
    };
    moveDownAction.setText("Move Rule Down");
    moveDownAction.setToolTipText("Move Selected Rule Down");
    moveDownAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, // $NON-NLS-1$
    "icons/search_next.gif"));
    moveDownAction.setEnabled(false);
}
Also used : Action(org.eclipse.jface.action.Action) RuleData(org.csstudio.opibuilder.script.RuleData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 7 with RuleData

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

the class RulesProperty method writeToXML.

@Override
public void writeToXML(Element propElement) {
    for (RuleData ruleData : ((RulesInput) getPropertyValue()).getRuleDataList()) {
        Element ruleElement = new Element(XML_ELEMENT_RULE);
        ruleElement.setAttribute(XML_ATTRIBUTE_NAME, ruleData.getName());
        ruleElement.setAttribute(XML_ATTRIBUTE_PROPID, ruleData.getPropId());
        ruleElement.setAttribute(XML_ATTRIBUTE_OUTPUTEXPRESSION, Boolean.toString(ruleData.isOutputExpValue()));
        for (Expression exp : ruleData.getExpressionList()) {
            Element expElement = new Element(XML_ELEMENT_EXPRESSION);
            expElement.setAttribute(XML_ATTRIBUTE_BOOLEXP, exp.getBooleanExpression());
            Element valueElement = new Element(XML_ELEMENT_VALUE);
            if (ruleData.isOutputExpValue())
                valueElement.setText(exp.getValue().toString());
            else {
                Object savedValue = ruleData.getProperty().getPropertyValue();
                ruleData.getProperty().setPropertyValue_IgnoreOldValue(exp.getValue());
                ruleData.getProperty().writeToXML(valueElement);
                ruleData.getProperty().setPropertyValue_IgnoreOldValue(savedValue);
            }
            expElement.addContent(valueElement);
            ruleElement.addContent(expElement);
        }
        for (PVTuple pv : ruleData.getPVList()) {
            Element pvElement = new Element(XML_ELEMENT_PV);
            pvElement.setText(pv.pvName);
            pvElement.setAttribute(XML_ATTRIBUTE_TRIGGER, Boolean.toString(pv.trigger));
            ruleElement.addContent(pvElement);
        }
        propElement.addContent(ruleElement);
    }
}
Also used : RuleData(org.csstudio.opibuilder.script.RuleData) RulesInput(org.csstudio.opibuilder.script.RulesInput) Expression(org.csstudio.opibuilder.script.Expression) Element(org.jdom.Element) PVTuple(org.csstudio.opibuilder.script.PVTuple)

Aggregations

RuleData (org.csstudio.opibuilder.script.RuleData)7 PVTuple (org.csstudio.opibuilder.script.PVTuple)5 RulesInput (org.csstudio.opibuilder.script.RulesInput)4 Expression (org.csstudio.opibuilder.script.Expression)2 ScriptData (org.csstudio.opibuilder.script.ScriptData)2 ScriptsInput (org.csstudio.opibuilder.script.ScriptsInput)2 Element (org.jdom.Element)2 AbstractWidgetProperty (org.csstudio.opibuilder.properties.AbstractWidgetProperty)1 WidgetPropertyChangeListener (org.csstudio.opibuilder.properties.WidgetPropertyChangeListener)1 IPV (org.csstudio.simplepv.IPV)1 Point (org.eclipse.draw2d.geometry.Point)1 Action (org.eclipse.jface.action.Action)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1