Search in sources :

Example 61 with VType

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

the class RadioRepresentation method contentChanged.

/**
 * The value or how we treat the value changed
 */
private void contentChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value) {
    final VType value = model_widget.runtimePropValue().getValue();
    final boolean fromPV = model_widget.propItemsFromPV().getValue() && value instanceof VEnum;
    items = computeItems(value, fromPV);
    index = determineIndex(items, value);
    dirty_content.mark();
    // Adjust colors
    dirty_style.mark();
    toolkit.scheduleUpdate(this);
}
Also used : VType(org.diirt.vtype.VType) VEnum(org.diirt.vtype.VEnum)

Example 62 with VType

use of org.diirt.vtype.VType 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 63 with VType

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

the class ThermometerRepresentation method valueChanged.

private void valueChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value) {
    final VType vtype = model_widget.runtimePropValue().getValue();
    final boolean limits_from_pv = model_widget.propLimitsFromPV().getValue();
    double min_val = model_widget.propMinimum().getValue();
    double max_val = model_widget.propMaximum().getValue();
    if (limits_from_pv) {
        // Try display range from PV
        final Display display_info = ValueUtil.displayOf(vtype);
        if (display_info != null) {
            min_val = display_info.getLowerDisplayLimit();
            max_val = display_info.getUpperDisplayLimit();
        }
    }
    // Fall back to 0..100 range
    if (min_val >= max_val) {
        min_val = 0.0;
        max_val = 100.0;
    }
    // Determine percentage of value within the min..max range
    final double value = VTypeUtil.getValueNumber(vtype).doubleValue();
    min = min_val;
    max = max_val;
    val = value;
    dirty_value.mark();
    toolkit.scheduleUpdate(this);
}
Also used : VType(org.diirt.vtype.VType) Display(org.diirt.vtype.Display)

Example 64 with VType

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

the class ScriptUtil method getWidgetValueByName.

// ==================
// Workspace helpers
/**
 * Locate a widget by name, then fetch its value
 *
 *  <p>Value is the content of the "value" property.
 *  If there is no such property, the primary PV
 *  of the widget is read.
 *
 *  @param widget Widget used to locate the widget model
 *  @param name Name of widget to find
 *  @return Value of the widget
 *  @throws Exception on error
 */
public static VType getWidgetValueByName(final Widget widget, final String name) throws Exception {
    final Widget w = findWidgetByName(widget, name);
    final Optional<WidgetProperty<Object>> value_prop = w.checkProperty("value");
    if (value_prop.isPresent()) {
        final Object value = value_prop.get().getValue();
        if (value == null || value instanceof VType)
            return (VType) value;
    }
    return getPrimaryPV(w).read();
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) VType(org.diirt.vtype.VType) Widget(org.csstudio.display.builder.model.Widget)

Example 65 with VType

use of org.diirt.vtype.VType 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

VType (org.diirt.vtype.VType)69 Test (org.junit.Test)17 IPV (org.csstudio.simplepv.IPV)8 ArrayList (java.util.ArrayList)7 Display (org.diirt.vtype.Display)7 VEnum (org.diirt.vtype.VEnum)7 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)6 ListNumber (org.diirt.util.array.ListNumber)6 IFigure (org.eclipse.draw2d.IFigure)6 Instant (java.time.Instant)5 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)5 VNumberArray (org.diirt.vtype.VNumberArray)5 VString (org.diirt.vtype.VString)5 List (java.util.List)4 RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)4 RuntimePVListener (org.csstudio.display.builder.runtime.pv.RuntimePVListener)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 ValueIterator (org.csstudio.archive.reader.ValueIterator)3 ArchiveVNumber (org.csstudio.archive.vtype.ArchiveVNumber)3 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)3