use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class SampleView method update.
/**
* Update combo box of this view.
* @param model_changed set true if the model was changed.
*/
private void update(final boolean model_changed) {
if (model == null) {
// Clear/disable GUI
items.setItems(new String[] { Messages.SampleView_NoPlot });
items.select(0);
items.setEnabled(false);
sample_table.setInput(null);
return;
}
// Show PV names.
// Also build array for following index-based check of selected item
final List<ModelItem> model_items = new ArrayList<>();
final List<String> names_list = new ArrayList<>();
names_list.add(Messages.SampleView_SelectItem);
for (ModelItem item : model.getItems()) {
model_items.add(item);
names_list.add(item.getName());
}
final String[] names = names_list.toArray(new String[names_list.size()]);
if (!model_changed && items.getSelectionIndex() > 0) {
// Is the previously selected item still valid?
if (sample_table.getInput() instanceof ModelItem) {
final ModelItem selected_item = (ModelItem) sample_table.getInput();
if (model_items.indexOf(selected_item) != -1) {
// Show same PV name again in combo box
items.setItems(names);
items.select(model_items.indexOf(selected_item) + 1);
items.setEnabled(true);
// Update sample table size. Not locking for size()
sample_table.setItemCount(selected_item.getSamples().size());
sample_table.refresh();
return;
}
}
}
// Previously selected item no longer valid.
// Show new items, clear rest
items.setItems(names);
items.select(0);
items.setEnabled(true);
sample_table.setInput(null);
}
use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class AddModelItemCommand method forFormula.
/**
* Create PV via undo-able AddModelItemCommand,
* displaying errors in dialog
* @param shell Shell used for error dialogs
* @param operations_manager OperationsManager where command will be reg'ed
* @param model Model were PV is to be added
* @param axis Axis
* @return AddModelItemCommand or <code>null</code> on error
*/
public static Optional<AddModelItemCommand> forFormula(final Shell shell, final UndoableActionManager operations_manager, final Model model, final String formula_name, final AxisConfig axis) {
// Create item
final FormulaItem item;
try {
// $NON-NLS-1$
item = new FormulaItem(formula_name, "0", new FormulaInput[0]);
axis.setVisible(true);
item.setAxis(axis);
} catch (Exception ex) {
MessageDialog.openError(shell, Messages.Error, NLS.bind(Messages.AddItemErrorFmt, formula_name, ex.getMessage()));
return Optional.empty();
}
// Add to model via undo-able command
return Optional.of(new AddModelItemCommand(shell, operations_manager, model, item));
}
use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class AddModelItemCommand method forPV.
/**
* Create PV via undo-able AddModelItemCommand,
* displaying errors in dialog
* @param shell Shell used for error dialogs
* @param operations_manager OperationsManager where command will be reg'ed
* @param model Model were PV is to be added
* @param pv_name Name of new PV
* @param period scan period
* @param axis Axis
* @param archive Archive data source
* @return AddModelItemCommand or <code>null</code> on error
*/
public static Optional<AddModelItemCommand> forPV(final Shell shell, final UndoableActionManager operations_manager, final Model model, final String pv_name, final double period, final AxisConfig axis, final ArchiveDataSource archive) {
// Create item
final PVItem item;
try {
item = new PVItem(pv_name, period);
if (archive != null)
item.addArchiveDataSource(archive);
else
item.useDefaultArchiveDataSources();
axis.setVisible(true);
item.setAxis(axis);
} catch (Exception ex) {
MessageDialog.openError(shell, Messages.Error, NLS.bind(Messages.AddItemErrorFmt, pv_name, ex.getMessage()));
return Optional.empty();
}
// Add to model via undo-able command
return Optional.of(new AddModelItemCommand(shell, operations_manager, model, item));
}
use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class ControllerBase method start.
/**
* Start model items and initiate scrolling/updates
* @throws Exception on error: Already running, problem starting threads, ...
* @see #isRunning()
*/
public void start() throws Exception {
if (isRunning())
throw new IllegalStateException("Already started");
plot.getPlot().setBackground(SWTMediaPool.getJFX(model.getPlotBackground()));
plot.getPlot().getXAxis().setGridVisible(model.isGridVisible());
plot.getPlot().showToolbar(model.isToolbarVisible());
plot.getPlot().showLegend(model.isLegendVisible());
plot.getPlot().setTitleFont(SWTMediaPool.getJFX(model.getTitleFont()));
plot.getPlot().setLegendFont(SWTMediaPool.getJFX(model.getLegendFont()));
String title = model.getTitle().orElse(null);
if (title != null)
title = model.resolveMacros(title);
plot.getPlot().setTitle(title);
plot.getPlot().setScrollStep(model.getScrollStep());
final List<Trace<Instant>> traces = new ArrayList<>();
for (Trace<Instant> trace : plot.getPlot().getTraces()) traces.add(trace);
for (AnnotationInfo info : model.getAnnotations()) {
final Trace<Instant> trace = traces.get(info.getItemIndex());
final Annotation<Instant> annotation = new Annotation<Instant>(info.isInternal(), trace, info.getTime(), info.getValue(), info.getOffset(), info.getText());
plot.getPlot().addAnnotation(annotation);
}
createUpdateTask();
model.start();
// Initial time range setup, schedule archive fetch
if (!model.isScrollEnabled())
plot.getPlot().setScrolling(false);
model_listener.changedTimerange();
}
use of org.csstudio.trends.databrowser3.model.Model in project org.csstudio.display.builder by kasemir.
the class ControllerBase method stop.
/**
* Stop scrolling and model items
* @throws IllegalStateException when not running
*/
public void stop() {
if (!isRunning())
throw new IllegalStateException("Not started");
// Stop ongoing archive access
synchronized (archive_fetch_jobs) {
for (ArchiveFetchJob job : archive_fetch_jobs) job.cancel();
archive_fetch_jobs.clear();
}
// Stop update task
model.stop();
model.removeListener(model_listener);
update_task.cancel(true);
update_task = null;
}
Aggregations