use of org.csstudio.trends.databrowser3.export.Source 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);
}
});
}
use of org.csstudio.trends.databrowser3.export.Source in project org.csstudio.display.builder by kasemir.
the class AddPVAction method runWithSuggestedName.
/**
* Run the 'add PV' dialog with optional defaults
* @param name Suggested PV name, for example from drag-n-drop
* @param archive Archive data source for the new PV
* @return <code>true</code> if PV name was added, <code>false</code> if canceled by user
*/
public boolean runWithSuggestedName(final String name, final ArchiveDataSource archive) {
// Prompt for PV name
final AddPVDialog dlg = new AddPVDialog(shell, 1, model, formula);
dlg.setName(0, name);
if (dlg.open() != Window.OK)
return false;
// Did user select axis?
final AxisConfig axis;
if (dlg.getAxisIndex(0) >= 0)
axis = model.getAxis(dlg.getAxisIndex(0));
else
// Use first empty axis, or create a new one
axis = model.getEmptyAxis().orElseGet(() -> new AddAxisCommand(operations_manager, model).getAxis());
// Create item
if (formula) {
final Optional<AddModelItemCommand> command = AddModelItemCommand.forFormula(shell, operations_manager, model, dlg.getName(0), axis);
if (!command.isPresent())
return false;
// Open configuration dialog
final FormulaItem formula = (FormulaItem) command.get().getItem();
final EditFormulaDialog edit = new EditFormulaDialog(operations_manager, shell, formula);
edit.open();
} else
AddModelItemCommand.forPV(shell, operations_manager, model, dlg.getName(0), dlg.getScanPeriod(0), axis, archive);
return true;
}
use of org.csstudio.trends.databrowser3.export.Source in project org.csstudio.display.builder by kasemir.
the class ControllerBase method getArchivedData.
/**
* Initiate archive data retrieval for a specific model item
* @param item Model item. NOP for non-PVItem
* @param start Start time
* @param end End time
*/
private void getArchivedData(final ModelItem item, final Instant start, final Instant end) {
// Only useful for PVItems with archive data source
if (!(item instanceof PVItem))
return;
final PVItem pv_item = (PVItem) item;
if (pv_item.getArchiveDataSources().length <= 0)
return;
// Determine ongoing jobs for this item
final List<ArchiveFetchJob> ongoing = new ArrayList<>();
final ArchiveFetchJob new_job = makeArchiveFetchJob(pv_item, start, end);
synchronized (archive_fetch_jobs) {
for (Iterator<ArchiveFetchJob> iter = archive_fetch_jobs.iterator(); iter.hasNext(); ) /**/
{
final ArchiveFetchJob job = iter.next();
if (job.getPVItem() == pv_item) {
ongoing.add(job);
iter.remove();
}
}
// Track new job
archive_fetch_jobs.add(new_job);
}
// job.schedule();
Activator.getThreadPool().execute(() -> {
// In background, stop ongoing jobs
for (ArchiveFetchJob running : ongoing) {
try {
running.cancel();
running.join(10000, null);
} catch (Exception ex) {
logger.log(Level.WARNING, "Cannot cancel " + running, ex);
}
}
// .. then start new one
new_job.schedule();
});
}
use of org.csstudio.trends.databrowser3.export.Source in project org.csstudio.display.builder by kasemir.
the class ExportTest method createPVItem.
/**
* @return PV with some archive data source
*/
private PVItem createPVItem(final String name) throws Exception {
final PVItem item = new PVItem(name, 1.0);
item.addArchiveDataSource(new ArchiveDataSource(URL, KEY, "test"));
return item;
}
Aggregations