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);
}
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);
}
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);
}
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();
}
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);
}
});
}
Aggregations