Search in sources :

Example 6 with AlarmSeverity

use of org.diirt.vtype.AlarmSeverity in project yamcs-studio by yamcs.

the class PVWidgetEditpartDelegate method registerBasePropertyChangeHandlers.

public void registerBasePropertyChangeHandlers() {
    IWidgetPropertyChangeHandler borderHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            editpart.setFigureBorder(editpart.calculateBorder());
            return true;
        }
    };
    editpart.setPropertyChangeHandler(IPVWidgetModel.PROP_BORDER_ALARMSENSITIVE, borderHandler);
    // value
    IWidgetPropertyChangeHandler valueHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure figure) {
            // No valid value is given. Do nothing.
            if (newValue == null || !(newValue instanceof VType))
                return false;
            AlarmSeverity newSeverity = VTypeHelper.getAlarmSeverity((VType) newValue);
            if (newSeverity == null)
                return false;
            if (newSeverity != alarmSeverity) {
                alarmSeverity = newSeverity;
                fireAlarmSeverityChanged(newSeverity, figure);
            }
            return true;
        }
    };
    editpart.setPropertyChangeHandler(AbstractPVWidgetModel.PROP_PVVALUE, valueHandler);
    // Border Alarm Sensitive
    addAlarmSeverityListener(new AlarmSeverityListener() {

        @Override
        public boolean severityChanged(AlarmSeverity severity, IFigure figure) {
            if (!isBorderAlarmSensitive)
                return false;
            editpart.setFigureBorder(editpart.calculateBorder());
            return true;
        }
    });
    // BackColor Alarm Sensitive
    addAlarmSeverityListener(new AlarmSeverityListener() {

        @Override
        public boolean severityChanged(AlarmSeverity severity, IFigure figure) {
            if (!isBackColorAlarmSensitive)
                return false;
            figure.setBackgroundColor(calculateBackColor());
            return true;
        }
    });
    // ForeColor Alarm Sensitive
    addAlarmSeverityListener(new AlarmSeverityListener() {

        @Override
        public boolean severityChanged(AlarmSeverity severity, IFigure figure) {
            if (!isForeColorAlarmSensitive)
                return false;
            figure.setForegroundColor(calculateForeColor());
            return true;
        }
    });
    // Pulsing Alarm Sensitive
    addAlarmSeverityListener(new AlarmSeverityListener() {

        @Override
        public boolean severityChanged(AlarmSeverity severity, IFigure figure) {
            if (!isAlarmPulsing)
                return false;
            if (severity == AlarmSeverity.MAJOR || severity == AlarmSeverity.MINOR) {
                startPulsing();
            } else {
                stopPulsing();
            }
            return true;
        }
    });
    class PVNamePropertyChangeHandler implements IWidgetPropertyChangeHandler {

        private String pvNamePropID;

        public PVNamePropertyChangeHandler(String pvNamePropID) {
            this.pvNamePropID = pvNamePropID;
        }

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            IPV oldPV = pvMap.get(pvNamePropID);
            editpart.removeFromConnectionHandler((String) oldValue);
            if (oldPV != null) {
                oldPV.stop();
                oldPV.removeListener(pvListenerMap.get(pvNamePropID));
            }
            pvMap.remove(pvNamePropID);
            String newPVName = ((String) newValue).trim();
            if (newPVName.length() <= 0)
                return false;
            try {
                lastWriteAccess = null;
                IPV newPV = BOYPVFactory.createPV(newPVName, isAllValuesBuffered);
                WidgetPVListener pvListener = new WidgetPVListener(pvNamePropID);
                newPV.addListener(pvListener);
                pvMap.put(pvNamePropID, newPV);
                editpart.addToConnectionHandler(newPVName, newPV);
                pvListenerMap.put(pvNamePropID, pvListener);
                newPV.start();
            } catch (Exception e) {
                OPIBuilderPlugin.getLogger().log(Level.WARNING, // $NON-NLS-1$
                "Unable to connect to PV:" + newPVName, e);
            }
            return false;
        }
    }
    // PV name
    for (StringProperty pvNameProperty : editpart.getWidgetModel().getPVMap().keySet()) {
        if (editpart.getExecutionMode() == ExecutionMode.RUN_MODE)
            editpart.setPropertyChangeHandler(pvNameProperty.getPropertyID(), new PVNamePropertyChangeHandler(pvNameProperty.getPropertyID()));
    }
    if (editpart.getExecutionMode() == ExecutionMode.EDIT_MODE)
        editpart.getWidgetModel().getProperty(IPVWidgetModel.PROP_PVNAME).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                // reselect the widget to update feedback.
                int selected = editpart.getSelected();
                if (selected != EditPart.SELECTED_NONE) {
                    editpart.setSelected(EditPart.SELECTED_NONE);
                    editpart.setSelected(selected);
                }
            }
        });
    IWidgetPropertyChangeHandler backColorHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            saveBackColor = ((OPIColor) newValue).getSWTColor();
            return false;
        }
    };
    editpart.setPropertyChangeHandler(AbstractWidgetModel.PROP_COLOR_BACKGROUND, backColorHandler);
    IWidgetPropertyChangeHandler foreColorHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            saveForeColor = ((OPIColor) newValue).getSWTColor();
            return false;
        }
    };
    editpart.setPropertyChangeHandler(AbstractWidgetModel.PROP_COLOR_FOREGROUND, foreColorHandler);
    IWidgetPropertyChangeHandler backColorAlarmSensitiveHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            isBackColorAlarmSensitive = (Boolean) newValue;
            figure.setBackgroundColor(calculateBackColor());
            return true;
        }
    };
    editpart.setPropertyChangeHandler(AbstractPVWidgetModel.PROP_BACKCOLOR_ALARMSENSITIVE, backColorAlarmSensitiveHandler);
    IWidgetPropertyChangeHandler foreColorAlarmSensitiveHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            isForeColorAlarmSensitive = (Boolean) newValue;
            figure.setForegroundColor(calculateForeColor());
            return true;
        }
    };
    editpart.setPropertyChangeHandler(AbstractPVWidgetModel.PROP_FORECOLOR_ALARMSENSITIVE, foreColorAlarmSensitiveHandler);
    IWidgetPropertyChangeHandler alarmPulsingHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            isAlarmPulsing = (Boolean) newValue;
            stopPulsing();
            fireAlarmSeverityChanged(alarmSeverity, figure);
            return true;
        }
    };
    editpart.setPropertyChangeHandler(AbstractPVWidgetModel.PROP_ALARM_PULSING, alarmPulsingHandler);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) AlarmSeverity(org.diirt.vtype.AlarmSeverity) PropertyChangeListener(java.beans.PropertyChangeListener) StringProperty(org.csstudio.opibuilder.properties.StringProperty) IPV(org.csstudio.simplepv.IPV) VType(org.diirt.vtype.VType) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IFigure(org.eclipse.draw2d.IFigure)

Example 7 with AlarmSeverity

use of org.diirt.vtype.AlarmSeverity in project yamcs-studio by yamcs.

the class AverageAggregator method calculate.

@Override
protected VDouble calculate(List<VDouble> data) {
    // TODO: this code should be consolidated with the StatisticsDoubleAggregator
    double totalSum = 0;
    AlarmSeverity statSeverity = null;
    for (VDouble vDouble : data) {
        switch(vDouble.getAlarmSeverity()) {
            case NONE:
                // severity should be NONE
                if (statSeverity != MINOR || statSeverity != MAJOR)
                    statSeverity = NONE;
                totalSum += vDouble.getValue();
                break;
            case MINOR:
                // set it to MINOR
                if (statSeverity != MAJOR)
                    statSeverity = MINOR;
                totalSum += vDouble.getValue();
                break;
            case MAJOR:
                statSeverity = MAJOR;
                totalSum += vDouble.getValue();
                break;
            case UNDEFINED:
                if (statSeverity == null)
                    statSeverity = UNDEFINED;
                break;
            case INVALID:
                if (statSeverity == null || statSeverity == UNDEFINED)
                    statSeverity = INVALID;
                break;
            default:
        }
    }
    return newVDouble(totalSum / data.size(), newAlarm(statSeverity, "NONE"), newTime(data.get(data.size() / 2).getTimestamp()), data.get(0));
}
Also used : AlarmSeverity(org.diirt.vtype.AlarmSeverity) VDouble(org.diirt.vtype.VDouble)

Example 8 with AlarmSeverity

use of org.diirt.vtype.AlarmSeverity in project org.csstudio.display.builder by kasemir.

the class RegionBaseRepresentation method computeValueBorder.

private void computeValueBorder(final Object value) {
    AlarmSeverity severity;
    if (alarm_sensitive_border_prop.getValue()) {
        if (value instanceof Alarm)
            // Have alarm info
            severity = ((Alarm) value).getAlarmSeverity();
        else if (value instanceof VType)
            // VType that doesn't provide alarm, always OK
            severity = AlarmSeverity.NONE;
        else if (value != null)
            // Not a vtype, but non-null, assume OK
            severity = AlarmSeverity.NONE;
        else
            // null
            severity = AlarmSeverity.UNDEFINED;
    } else
        severity = AlarmSeverity.NONE;
    computeAlarmBorder(severity);
}
Also used : AlarmSeverity(org.diirt.vtype.AlarmSeverity) VType(org.diirt.vtype.VType) Alarm(org.diirt.vtype.Alarm)

Example 9 with AlarmSeverity

use of org.diirt.vtype.AlarmSeverity in project org.csstudio.display.builder by kasemir.

the class SampleView method doCreatePartControl.

/**
 * {@inheritDoc}
 */
@Override
protected void doCreatePartControl(final Composite parent) {
    final GridLayout layout = new GridLayout(3, false);
    parent.setLayout(layout);
    // Item: pvs [Refresh]
    Label l = new Label(parent, 0);
    l.setText(Messages.SampleView_Item);
    l.setLayoutData(new GridData());
    items = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    items.setLayoutData(new GridData(SWT.FILL, 0, true, false));
    items.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            // Configure table to display samples of the selected model item
            if (items.getSelectionIndex() == 0) {
                sample_table.setInput(null);
                return;
            }
            // / Skip initial "Select item" entry
            final int selected = items.getSelectionIndex() - 1;
            int index = 0;
            for (ModelItem item : model.getItems()) {
                if (index == selected) {
                    sample_table.setInput(item);
                    return;
                }
                ++index;
            }
            Activator.getLogger().log(Level.WARNING, "Invalid item index " + selected);
        }
    });
    final Button refresh = new Button(parent, SWT.PUSH);
    refresh.setText(Messages.SampleView_Refresh);
    refresh.setToolTipText(Messages.SampleView_RefreshTT);
    refresh.setLayoutData(new GridData());
    refresh.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            // Trigger GUI update
            update(false);
        }
    });
    // Sample Table
    // TableColumnLayout requires this to be in its own container
    final Composite table_parent = new Composite(parent, 0);
    table_parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));
    final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10);
    table_parent.setLayout(table_layout);
    sample_table = new TableViewer(table_parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
    sample_table.setContentProvider(new SampleTableContentProvider());
    final Table table = sample_table.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    // Time column
    TableViewerColumn col = TableHelper.createColumn(table_layout, sample_table, Messages.TimeColumn, 90, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            cell.setText(TimestampHelper.format(sample.getPosition()));
        }
    });
    // Value column
    col = TableHelper.createColumn(table_layout, sample_table, Messages.ValueColumn, 50, 100);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            cell.setText(format.format(sample.getVType()));
        }

        @Override
        public String getToolTipText(Object element) {
            final PlotSample sample = (PlotSample) element;
            final VType value = sample.getVType();
            // Show numbers in their 'natural' format which may differ from the Display settings
            if (value instanceof VStatistics) {
                final VStatistics mmd = (VStatistics) value;
                return NLS.bind(Messages.SampleView_MinMaxValueTT, new String[] { Double.toString(mmd.getAverage()), Double.toString(mmd.getMin()), Double.toString(mmd.getMax()) });
            } else if (value instanceof VNumber) {
                final VNumber dbl = (VNumber) value;
                return Double.toString(dbl.getValue().doubleValue());
            } else
                return VTypeHelper.toString(value);
        }
    });
    // Severity column
    col = TableHelper.createColumn(table_layout, sample_table, Messages.SeverityColumn, 90, 50);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            final VType value = sample.getVType();
            final AlarmSeverity severity = VTypeHelper.getSeverity(value);
            cell.setText(severity.toString());
            if (severity == AlarmSeverity.NONE) {
                cell.setBackground(null);
                return;
            }
            final Display display = cell.getControl().getDisplay();
            if (severity == AlarmSeverity.MAJOR)
                cell.setBackground(display.getSystemColor(SWT.COLOR_RED));
            else if (severity == AlarmSeverity.MINOR)
                cell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
            else
                cell.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
        }
    });
    // Status column
    col = TableHelper.createColumn(table_layout, sample_table, Messages.StatusColumn, 90, 50);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            final VType value = sample.getVType();
            cell.setText(VTypeHelper.getMessage(value));
        }
    });
    // Sample Source column
    col = TableHelper.createColumn(table_layout, sample_table, Messages.SampleView_Source, 90, 10);
    col.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            final PlotSample sample = (PlotSample) cell.getElement();
            cell.setText(sample.getSource());
        }
    });
    ColumnViewerToolTipSupport.enableFor(sample_table);
    // Be ignorant of any change of the current model after this view
    // is disposed.
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (model != null)
                model.removeListener(model_listener);
        }
    });
}
Also used : MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) DisposeListener(org.eclipse.swt.events.DisposeListener) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) DisposeEvent(org.eclipse.swt.events.DisposeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) VType(org.diirt.vtype.VType) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) VStatistics(org.diirt.vtype.VStatistics) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) Table(org.eclipse.swt.widgets.Table) AlarmSeverity(org.diirt.vtype.AlarmSeverity) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) VNumber(org.diirt.vtype.VNumber) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridData(org.eclipse.swt.layout.GridData) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener) Display(org.eclipse.swt.widgets.Display)

Aggregations

AlarmSeverity (org.diirt.vtype.AlarmSeverity)9 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)4 VType (org.diirt.vtype.VType)4 IFigure (org.eclipse.draw2d.IFigure)4 AlarmSeverityListener (org.csstudio.opibuilder.editparts.AlarmSeverityListener)3 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)2 VDouble (org.diirt.vtype.VDouble)2 MatFileIncrementalWriter (com.jmatio.io.MatFileIncrementalWriter)1 MLDouble (com.jmatio.types.MLDouble)1 MLStructure (com.jmatio.types.MLStructure)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 ValueIterator (org.csstudio.archive.reader.ValueIterator)1 StringProperty (org.csstudio.opibuilder.properties.StringProperty)1 ProgressBarModel (org.csstudio.opibuilder.widgets.model.ProgressBarModel)1 IPV (org.csstudio.simplepv.IPV)1 ProgressBarFigure (org.csstudio.swt.widgets.figures.ProgressBarFigure)1 TankFigure (org.csstudio.swt.widgets.figures.TankFigure)1