Search in sources :

Example 6 with PVTuple

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

the class ScriptsInputDialog method okPressed.

@Override
protected void okPressed() {
    pvsEditor.forceFocus();
    for (ScriptData scriptData : scriptDataList) {
        boolean hasTrigger = false;
        for (PVTuple pvTuple : scriptData.getPVList()) {
            hasTrigger |= pvTuple.trigger;
        }
        if (!hasTrigger) {
            MessageDialog.openWarning(getShell(), "Warning", NLS.bind("At least one trigger PV must be selected for the script:\n{0}", scriptData.getPath().toString()));
            return;
        }
    }
    super.okPressed();
}
Also used : ScriptData(org.csstudio.opibuilder.script.ScriptData) PVTuple(org.csstudio.opibuilder.script.PVTuple)

Example 7 with PVTuple

use of org.csstudio.opibuilder.script.PVTuple 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 8 with PVTuple

use of org.csstudio.opibuilder.script.PVTuple 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 9 with PVTuple

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

the class PVTupleTableEditor method createPVTupleListTableViewer.

/**
 * Creates and configures a {@link TableViewer}.
 *
 * @param parent
 *            The parent for the table
 * @return The {@link TableViewer}
 */
private TableViewer createPVTupleListTableViewer(final Composite parent) {
    final TableViewer viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    final TableViewerColumn numColumn = new TableViewerColumn(viewer, SWT.NONE);
    numColumn.getColumn().setText("#");
    numColumn.getColumn().setMoveable(false);
    numColumn.getColumn().setWidth(50);
    final TableViewerColumn pvColumn = new TableViewerColumn(viewer, SWT.NONE);
    pvColumn.getColumn().setText("PV Name");
    pvColumn.getColumn().setMoveable(false);
    pvColumn.getColumn().setWidth(220);
    pvColumn.setEditingSupport(new PVColumnEditingSupport(viewer, viewer.getTable()));
    final TableViewerColumn TrigColumn = new TableViewerColumn(viewer, SWT.NONE);
    TrigColumn.getColumn().setText("Trigger");
    TrigColumn.getColumn().setMoveable(false);
    TrigColumn.getColumn().pack();
    TrigColumn.setEditingSupport(new TriggerColumnEditingSupport(viewer, viewer.getTable()));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new PVTupleLabelProvider(pvTupleList));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(final SelectionChangedEvent event) {
            refreshToolbarOnSelection();
        }
    });
    viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    DropTarget target = new DropTarget(viewer.getControl(), DND.DROP_MOVE | DND.DROP_COPY);
    target.setTransfer(new Transfer[] { TextTransfer.getInstance() });
    target.addDropListener(new DropTargetListener() {

        @Override
        public void dragEnter(DropTargetEvent event) {
        }

        @Override
        public void dragLeave(DropTargetEvent event) {
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
        }

        @Override
        public void dragOver(DropTargetEvent event) {
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (event == null || !(event.data instanceof String))
                return;
            String txt = (String) event.data;
            String[] names = txt.split("[\r\n]+");
            PVTuple[] tuples = new PVTuple[names.length];
            int i = 0;
            for (String name : names) {
                tuples[i] = new PVTuple(name, true);
                pvTupleList.add(tuples[i]);
                i++;
            }
            refreshTableViewerFromAction(tuples);
        }

        @Override
        public void dropAccept(DropTargetEvent event) {
        }
    });
    return viewer;
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PVTuple(org.csstudio.opibuilder.script.PVTuple) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) DropTarget(org.eclipse.swt.dnd.DropTarget) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 10 with PVTuple

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

the class PVTupleTableEditor method createActions.

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

        @Override
        public void run() {
            PVTuple tuple = new PVTuple("", true);
            pvTupleList.add(tuple);
            refreshTableViewerFromAction(new PVTuple[] { tuple });
        }
    };
    addAction.setToolTipText("Add a PV");
    addAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/add.gif"));
    removeAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) pvTupleListTableViewer.getSelection();
            if (!selection.isEmpty()) {
                @SuppressWarnings("rawtypes") Iterator iter = selection.iterator();
                while (iter.hasNext()) {
                    Object item = iter.next();
                    if (item instanceof PVTuple) {
                        pvTupleList.remove(item);
                    }
                }
                refreshTableViewerFromAction(null);
                super.setEnabled(false);
            }
        }
    };
    removeAction.setText("Remove");
    removeAction.setToolTipText("Remove the selected PVs 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) pvTupleListTableViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof PVTuple) {
                PVTuple tuple = (PVTuple) selection.getFirstElement();
                int i = pvTupleList.indexOf(tuple);
                if (i > 0) {
                    pvTupleList.remove(tuple);
                    pvTupleList.add(i - 1, tuple);
                    refreshTableViewerFromAction(new PVTuple[] { tuple });
                }
            }
        }
    };
    moveUpAction.setText("Move Up");
    moveUpAction.setToolTipText("Move up the selected PV");
    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) pvTupleListTableViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof PVTuple) {
                PVTuple tuple = (PVTuple) selection.getFirstElement();
                int i = pvTupleList.indexOf(tuple);
                if (i < pvTupleList.size() - 1) {
                    pvTupleList.remove(tuple);
                    pvTupleList.add(i + 1, tuple);
                    refreshTableViewerFromAction(new PVTuple[] { tuple });
                }
            }
        }
    };
    moveDownAction.setText("Move Down");
    moveDownAction.setToolTipText("Move down the selected PV");
    moveDownAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/search_next.gif"));
    moveDownAction.setEnabled(false);
    checkTriggerAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) pvTupleListTableViewer.getSelection();
            if (!selection.isEmpty()) {
                @SuppressWarnings("rawtypes") Iterator iter = selection.iterator();
                ArrayList<PVTuple> tuples = new ArrayList<PVTuple>();
                while (iter.hasNext()) {
                    Object item = iter.next();
                    if (item instanceof PVTuple) {
                        PVTuple tuple = (PVTuple) item;
                        tuple.trigger = true;
                        tuples.add(tuple);
                    }
                }
                refreshTableViewerFromAction(tuples.toArray(new PVTuple[tuples.size()]));
            }
        }
    };
    checkTriggerAction.setText("Check Trigger");
    checkTriggerAction.setToolTipText("Check trigger option of the selected PVs");
    checkTriggerAction.setEnabled(false);
    uncheckTriggerAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) pvTupleListTableViewer.getSelection();
            if (!selection.isEmpty()) {
                @SuppressWarnings("rawtypes") Iterator iter = selection.iterator();
                ArrayList<PVTuple> tuples = new ArrayList<PVTuple>();
                while (iter.hasNext()) {
                    Object item = iter.next();
                    if (item instanceof PVTuple) {
                        PVTuple tuple = (PVTuple) item;
                        tuple.trigger = false;
                        tuples.add(tuple);
                    }
                }
                refreshTableViewerFromAction(tuples.toArray(new PVTuple[tuples.size()]));
            }
        }
    };
    uncheckTriggerAction.setText("Uncheck Trigger");
    uncheckTriggerAction.setToolTipText("Uncheck trigger option of the selected PVs");
    uncheckTriggerAction.setEnabled(false);
}
Also used : Action(org.eclipse.jface.action.Action) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) PVTuple(org.csstudio.opibuilder.script.PVTuple) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

PVTuple (org.csstudio.opibuilder.script.PVTuple)13 ScriptData (org.csstudio.opibuilder.script.ScriptData)6 RuleData (org.csstudio.opibuilder.script.RuleData)5 ScriptsInput (org.csstudio.opibuilder.script.ScriptsInput)5 RulesInput (org.csstudio.opibuilder.script.RulesInput)4 Element (org.jdom.Element)4 Expression (org.csstudio.opibuilder.script.Expression)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 AbstractWidgetProperty (org.csstudio.opibuilder.properties.AbstractWidgetProperty)1 WidgetPropertyChangeListener (org.csstudio.opibuilder.properties.WidgetPropertyChangeListener)1 IPV (org.csstudio.simplepv.IPV)1 Path (org.eclipse.core.runtime.Path)1 Point (org.eclipse.draw2d.geometry.Point)1 Action (org.eclipse.jface.action.Action)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1