use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class WaveformView method showSelectedSample.
/**
* Show the current sample of the current model item.
*/
private void showSelectedSample() {
// Get selected sample (= one waveform)
final PlotSamples samples = model_item.getSamples();
final int idx = sample_index.getSelection();
final PlotSample sample;
samples.getLock().lock();
try {
sample_index.setMaximum(samples.size());
sample = samples.get(idx);
} finally {
samples.getLock().unlock();
}
// Setting the value can be delayed while the plot is being updated
final VType value = sample.getVType();
Activator.getThreadPool().execute(() -> waveform.setValue(value));
if (value == null)
clearInfo();
else {
updateAnnotation(sample.getPosition(), sample.getValue());
int size = value instanceof VNumberArray ? ((VNumberArray) value).getData().size() : 1;
plot.getXAxis().setValueRange(0.0, (double) size);
timestamp.setText(TimestampHelper.format(VTypeHelper.getTimestamp(value)));
status.setText(NLS.bind(Messages.SeverityStatusFmt, VTypeHelper.getSeverity(value).toString(), VTypeHelper.getMessage(value)));
}
plot.requestUpdate();
}
use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class WaveformView method doCreatePartControl.
/**
* {@inheritDoc}
*/
@Override
protected void doCreatePartControl(final Composite parent) {
// Arrange disposal
parent.addDisposeListener((DisposeEvent e) -> {
// Ignore current model after this view is disposed.
if (model != null) {
model.removeListener(model_listener);
removeAnnotation();
}
});
final GridLayout layout = new GridLayout(4, false);
parent.setLayout(layout);
// PV: .pvs..... [Refresh]
// =====================
// ======= Plot ========
// =====================
// <<<<<< Slider >>>>>>
// Timestamp: __________ Sevr./Status: __________
// PV: .pvs..... [Refresh]
Label l = new Label(parent, 0);
l.setText(Messages.SampleView_Item);
l.setLayoutData(new GridData());
pv_name = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
pv_name.setLayoutData(new GridData(SWT.FILL, 0, true, false, layout.numColumns - 2, 1));
pv_name.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(final SelectionEvent e) {
widgetDefaultSelected(e);
}
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
// First item is "--select PV name--"
if (pv_name.getSelectionIndex() == 0)
selectPV(null);
else
selectPV(model.getItem(pv_name.getText()));
}
});
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) {
// First item is "--select PV name--"
if (pv_name.getSelectionIndex() == 0)
selectPV(null);
else
selectPV(model.getItem(pv_name.getText()));
}
});
// =====================
// ======= Plot ========
// =====================
final JFX_SWT_Wrapper wrapper = new JFX_SWT_Wrapper(parent, () -> {
plot = new RTValuePlot(true);
plot.getXAxis().setName(Messages.WaveformIndex);
plot.getYAxes().get(0).setName(Messages.WaveformAmplitude);
plot.getYAxes().get(0).setAutoscale(true);
return new Scene(plot);
});
final Control plot_canvas = wrapper.getFXCanvas();
plot_canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));
// <<<<<< Slider >>>>>>
sample_index = new Slider(parent, SWT.HORIZONTAL);
sample_index.setToolTipText(Messages.WaveformTimeSelector);
sample_index.setLayoutData(new GridData(SWT.FILL, 0, true, false, layout.numColumns, 1));
sample_index.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showSelectedSample();
}
});
// Timestamp: __________ Sevr./Status: __________
l = new Label(parent, 0);
l.setText(Messages.WaveformTimestamp);
l.setLayoutData(new GridData());
timestamp = new Text(parent, SWT.BORDER | SWT.READ_ONLY);
timestamp.setLayoutData(new GridData(SWT.FILL, 0, true, false));
l = new Label(parent, 0);
l.setText(Messages.WaveformStatus);
l.setLayoutData(new GridData());
status = new Text(parent, SWT.BORDER | SWT.READ_ONLY);
status.setLayoutData(new GridData(SWT.FILL, 0, true, false));
// Context Menu
final MenuManager mm = new MenuManager();
mm.setRemoveAllWhenShown(true);
final Menu menu = mm.createContextMenu(plot_canvas);
plot_canvas.setMenu(menu);
getSite().registerContextMenu(mm, null);
mm.addMenuListener(manager -> {
mm.add(new ToggleToolbarAction(plot, true));
mm.add(new ToggleLegendAction(plot, true));
mm.add(new Separator());
mm.add(new ToggleYAxisAction());
});
}
use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class DataBrowserPropertySheetPage method createTracesMenuAndToolbarActions.
/**
* Create context menu and toolbar actions for the traces table
*/
private void createTracesMenuAndToolbarActions() {
final MenuManager menu = new MenuManager();
menu.setRemoveAllWhenShown(true);
final Shell shell = trace_table.getControl().getShell();
final AddPVAction add_pv = new AddPVAction(operations_manager, shell, model, false);
final AddPVAction add_formula = new AddPVAction(operations_manager, shell, model, true);
final EditItemsAction edit_pv = new EditItemsAction(operations_manager, shell, trace_table, model);
final DeleteItemsAction delete_pv = new DeleteItemsAction(operations_manager, trace_table, model);
menu.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
final PVItem[] pvs = getSelectedPVs();
menu.add(add_pv);
menu.add(add_formula);
menu.add(edit_pv);
if (pvs.length == 1)
menu.add(new MoveItemAction(operations_manager, model, pvs[0], true));
menu.add(delete_pv);
if (pvs.length == 1)
menu.add(new MoveItemAction(operations_manager, model, pvs[0], false));
menu.add(new RemoveUnusedAxesAction(operations_manager, model));
if (pvs.length > 0) {
menu.add(new AddArchiveAction(operations_manager, shell, pvs));
menu.add(new UseDefaultArchivesAction(operations_manager, pvs));
}
menu.add(new Separator());
menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
}
});
final Table table = trace_table.getTable();
table.setMenu(menu.createContextMenu(table));
// Allow object contributions based on selected items
getSite().registerContextMenu(menu.getId(), menu, trace_table);
// Add to tool bar
final IToolBarManager toolbar = getSite().getActionBars().getToolBarManager();
toolbar.add(add_pv);
toolbar.add(add_formula);
}
use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class DeleteAxesAction method run.
@Override
public void run() {
// Get selected axis items
final Object[] sel = ((IStructuredSelection) axes_table.getSelection()).toArray();
if (sel.length <= 0)
return;
final AxisConfig[] axes = new AxisConfig[sel.length];
for (int i = 0; i < axes.length; ++i) {
axes[i] = (AxisConfig) sel[i];
// Check if axis is used by any model items.
final ModelItem item = model.getFirstItemOnAxis(axes[i]);
if (item != null) {
MessageDialog.openWarning(axes_table.getTable().getShell(), Messages.DeleteAxis, NLS.bind(Messages.DeleteAxisWarningFmt, axes[i].getName(), item.getName()));
return;
}
}
// one axis position
for (AxisConfig axis : axes) new DeleteAxisCommand(operations_manager, model, axis);
}
use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class EditFormulaDialog method determineInputs.
/**
* @return List of inputs for formula: Each model item is a possible input,
* mapped to a variable name that's either already used in the
* formula for that model item, or a simple "x1", "x2", ... when
* not already used
*/
@SuppressWarnings("nls")
private InputItem[] determineInputs() {
final Model model = formula.getModel().get();
// Create list of inputs.
final ArrayList<InputItem> inputs = new ArrayList<InputItem>();
// Every model item is a possible input.
model_loop: for (ModelItem model_item : model.getItems()) {
// Formula cannot be an input to itself
if (model_item == formula)
continue;
// Create InputItem for that ModelItem
InputItem input = null;
// See if model item is already used in the formula
for (FormulaInput existing_input : formula.getInputs()) {
if (existing_input.getItem() == model_item) {
// Yes, use the existing variable name
input = new InputItem(model_item.getName(), existing_input.getVariableName());
break;
}
}
// If input is unused, assign variable name x1, x2, ...
if (input == null) {
for (InputItem existing_item : inputs) if (existing_item.getInputName().equals(model_item.getName())) {
// The item with the same name was already added to the input list.
continue model_loop;
}
// Try "x1", then "xx1", "xxx1" until an unused name is found
String var_name = Integer.toString(inputs.size() + 1);
boolean name_in_use;
do {
name_in_use = false;
var_name = "x" + var_name;
for (final FormulaInput existing_input : formula.getInputs()) if (existing_input.getVariableName().equals(var_name)) {
name_in_use = true;
break;
}
} while (name_in_use);
input = new InputItem(model_item.getName(), var_name);
}
inputs.add(input);
}
return inputs.toArray(new InputItem[inputs.size()]);
}
Aggregations