use of org.csstudio.trends.databrowser3.model.PVItem in project org.csstudio.display.builder by kasemir.
the class EditItemsDialog method createDialogArea.
@Override
protected Control createDialogArea(final Composite parent) {
final Composite composite = (Composite) super.createDialogArea(parent);
composite.setLayout(new GridLayout(3, false));
Label label = new Label(composite, SWT.NONE);
label.setText(Messages.ApplyChanges);
label.setLayoutData(new GridData(SWT.LEFT, 0, true, false, 3, 1));
// Show property
chkApplyShow = new Button(composite, SWT.CHECK);
chkApplyShow.setLayoutData(new GridData());
label = new Label(composite, SWT.NONE);
label.setText(Messages.TraceVisibility);
label.setLayoutData(new GridData());
chkShow = new Button(composite, SWT.CHECK);
chkShow.setToolTipText(Messages.TraceVisibilityTT);
if (!items.isEmpty())
chkShow.setSelection(items.get(0).isVisible());
chkShow.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chkApplyShow.setSelection(true);
}
});
chkShow.setLayoutData(new GridData());
// Item property
chkApplyItem = new Button(composite, SWT.CHECK);
chkApplyItem.setLayoutData(new GridData());
label = new Label(composite, SWT.NONE);
label.setText(Messages.ItemName);
label.setLayoutData(new GridData());
textItem = new Text(composite, SWT.SINGLE | SWT.BORDER);
textItem.setToolTipText(Messages.ItemNameTT);
if (!items.isEmpty())
textItem.setText(items.get(0).getName());
textItem.addModifyListener((ModifyEvent e) -> chkApplyItem.setSelection(true));
textItem.setLayoutData(new GridData(SWT.FILL, 0, true, false));
// Display name property
chkApplyDisplayName = new Button(composite, SWT.CHECK);
chkApplyDisplayName.setLayoutData(new GridData());
label = new Label(composite, SWT.NONE);
label.setText(Messages.TraceDisplayName);
label.setLayoutData(new GridData());
textDisplayName = new Text(composite, SWT.SINGLE | SWT.BORDER);
textDisplayName.setToolTipText(Messages.TraceDisplayNameTT);
if (!items.isEmpty())
textDisplayName.setText(items.get(0).getDisplayName());
textDisplayName.addModifyListener((ModifyEvent e) -> chkApplyDisplayName.setSelection(true));
textDisplayName.setLayoutData(new GridData(SWT.FILL, 0, true, false));
// Color property
chkApplyColor = new Button(composite, SWT.CHECK);
chkApplyColor.setLayoutData(new GridData());
label = new Label(composite, SWT.NONE);
label.setText(Messages.Color);
label.setLayoutData(new GridData());
blobColor = new ColorBlob(composite, new RGB(0, 0, 0));
blobColor.setToolTipText(Messages.ColorTT);
// TODO: this should probably use Javafx color instead of SWT...
if (!items.isEmpty())
blobColor.setColor(SWTMediaPool.getRGB(items.get(0).getPaintColor()));
blobColor.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
ColorDialog dialog = new ColorDialog(getShell());
RGB color = dialog.open();
if (color != null) {
blobColor.setColor(color);
chkApplyColor.setSelection(true);
}
}
});
GridData gd = new GridData(SWT.LEFT, 0, true, false);
gd.widthHint = 40;
gd.heightHint = 15;
blobColor.setLayoutData(gd);
// Scan period property
chkApplyScan = new Button(composite, SWT.CHECK);
chkApplyScan.setLayoutData(new GridData());
label = new Label(composite, SWT.NONE);
label.setText(Messages.ScanPeriod);
label.setLayoutData(new GridData());
textScan = new Text(composite, SWT.SINGLE | SWT.BORDER);
textScan.setToolTipText(Messages.ScanPeriodTT);
boolean enableScan = false;
for (ModelItem item : items) {
if (item instanceof PVItem) {
textScan.setText(Double.toString(((PVItem) item).getScanPeriod()));
enableScan = true;
break;
}
}
chkApplyScan.setEnabled(enableScan);
textScan.setEnabled(enableScan);
textScan.addVerifyListener(new NumericalVerifyListener(textScan, true));
textScan.addModifyListener((ModifyEvent e) -> chkApplyScan.setSelection(true));
textScan.setLayoutData(new GridData(SWT.FILL, 0, true, false));
// Buffer size property
chkApplyBufferSize = new Button(composite, SWT.CHECK);
chkApplyBufferSize.setLayoutData(new GridData());
label = new Label(composite, SWT.NONE);
label.setText(Messages.LiveSampleBufferSize);
label.setLayoutData(new GridData());
textBufferSize = new Text(composite, SWT.SINGLE | SWT.BORDER);
boolean enableBufferSize = false;
for (ModelItem item : items) {
if (item instanceof PVItem) {
textBufferSize.setText(Integer.toString(((PVItem) item).getLiveCapacity()));
enableBufferSize = true;
break;
}
}
chkApplyBufferSize.setEnabled(enableBufferSize);
textBufferSize.setEnabled(enableBufferSize);
textBufferSize.addVerifyListener(new NumericalVerifyListener(textBufferSize, false));
textBufferSize.addModifyListener((ModifyEvent e) -> chkApplyBufferSize.setSelection(true));
textBufferSize.setLayoutData(new GridData(SWT.FILL, 0, true, false));
// Width property
chkApplyWidth = new Button(composite, SWT.CHECK);
chkApplyWidth.setLayoutData(new GridData());
label = new Label(composite, SWT.NONE);
label.setText(Messages.TraceLineWidth);
label.setLayoutData(new GridData());
textWidth = new Text(composite, SWT.SINGLE | SWT.BORDER);
textWidth.setToolTipText(Messages.TraceLineWidthTT);
if (!items.isEmpty())
textWidth.setText(Integer.toString(items.get(0).getLineWidth()));
textWidth.addVerifyListener(new NumericalVerifyListener(textWidth, false));
textWidth.addModifyListener((ModifyEvent e) -> chkApplyWidth.setSelection(true));
textWidth.setLayoutData(new GridData(SWT.FILL, 0, true, false));
// Axis property
chkApplyAxis = new Button(composite, SWT.CHECK);
chkApplyAxis.setLayoutData(new GridData());
label = new Label(composite, SWT.NONE);
label.setText(Messages.Axis);
label.setLayoutData(new GridData());
cmbAxis = new Combo(composite, SWT.READ_ONLY);
cmbAxis.setToolTipText(Messages.AxisTT);
int i = 0;
for (AxisConfig axis : axes) {
cmbAxis.add(axis.getName());
if (items.size() >= 0 && items.get(0).getAxisIndex() == i)
cmbAxis.select(i);
++i;
}
cmbAxis.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chkApplyAxis.setSelection(true);
}
});
cmbAxis.setLayoutData(new GridData(SWT.FILL, 0, true, false));
// Trace type property
chkApplyTraceType = new Button(composite, SWT.CHECK);
chkApplyTraceType.setLayoutData(new GridData());
label = new Label(composite, SWT.NONE);
label.setText(Messages.TraceType);
label.setLayoutData(new GridData());
cmbTraceType = new Combo(composite, SWT.READ_ONLY);
cmbTraceType.setToolTipText(Messages.TraceTypeTT);
for (i = 0; i < TraceType.values().length; i++) {
TraceType type = TraceType.values()[i];
cmbTraceType.add(type.toString());
if (items.size() >= 1 && type == items.get(0).getTraceType())
cmbTraceType.select(i);
}
cmbTraceType.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chkApplyTraceType.setSelection(true);
}
});
cmbTraceType.setLayoutData(new GridData(SWT.FILL, 0, true, false));
// Request property
chkApplyRequest = new Button(composite, SWT.CHECK);
chkApplyRequest.setLayoutData(new GridData());
label = new Label(composite, SWT.NONE);
label.setText(Messages.RequestType);
label.setLayoutData(new GridData());
cmbRequest = new Combo(composite, SWT.READ_ONLY);
cmbRequest.setToolTipText(Messages.RequestTypeTT);
RequestType defaultType = RequestType.OPTIMIZED;
boolean enableRequest = false;
for (ModelItem item : items) {
if (item instanceof PVItem) {
defaultType = ((PVItem) item).getRequestType();
enableRequest = true;
break;
}
}
chkApplyRequest.setEnabled(enableRequest);
cmbRequest.setEnabled(enableRequest);
if (enableRequest) {
for (i = 0; i < RequestType.values().length; i++) {
RequestType type = RequestType.values()[i];
cmbRequest.add(type.toString());
if (type == defaultType)
cmbRequest.select(i);
}
}
cmbRequest.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
chkApplyRequest.setSelection(true);
}
});
cmbRequest.setLayoutData(new GridData(SWT.FILL, 0, true, false));
// Index property
chkApplyIndex = new Button(composite, SWT.CHECK);
chkApplyIndex.setLayoutData(new GridData());
label = new Label(composite, SWT.NONE);
label.setText(Messages.WaveformIndex);
label.setLayoutData(new GridData());
textIndex = new Text(composite, SWT.SINGLE | SWT.BORDER);
textIndex.setToolTipText(Messages.WaveformIndexColTT);
if (!items.isEmpty())
textIndex.setText(Integer.toString(items.get(0).getWaveformIndex()));
textIndex.addVerifyListener(new NumericalVerifyListener(textIndex, false));
textIndex.addModifyListener((ModifyEvent e) -> chkApplyIndex.setSelection(true));
textIndex.setLayoutData(new GridData(SWT.FILL, 0, true, false));
return composite;
}
use of org.csstudio.trends.databrowser3.model.PVItem in project org.csstudio.display.builder by kasemir.
the class ExportJob method printItemInfo.
/**
* Print info about item
* @param out PrintStream for output
* @param item ModelItem
*/
protected void printItemInfo(final PrintStream out, final ModelItem item) {
out.println(comment + "Channel: " + item.getName());
// If display name differs from PV, show the _resolved_ version
if (!item.getName().equals(item.getDisplayName()))
out.println(comment + "Name : " + item.getResolvedDisplayName());
if (item instanceof PVItem) {
final PVItem pv = (PVItem) item;
out.println(comment + "Archives:");
final ArchiveDataSource[] archives = pv.getArchiveDataSources();
for (int i = 0; i < archives.length; ++i) {
out.println(comment + (i + 1) + ") " + archives[i].getName());
out.println(comment + " URL: " + archives[i].getUrl());
out.println(comment + " Key: " + archives[i].getKey());
}
}
out.println(comment);
}
use of org.csstudio.trends.databrowser3.model.PVItem in project org.csstudio.display.builder by kasemir.
the class ExportJob method createValueIterator.
/**
* @param item ModelItem
* @return ValueIterator for samples in the item
* @throws Exception on error
*/
protected ValueIterator createValueIterator(final ModelItem item) throws Exception {
if (source == Source.PLOT || !(item instanceof PVItem))
return new ModelSampleIterator(item, start, end);
// Start ValueIterator for each sub-archive
final ArchiveDataSource[] archives = ((PVItem) item).getArchiveDataSources();
final List<ValueIterator> iters = new ArrayList<>();
Exception error = null;
for (ArchiveDataSource archive : archives) {
// Create reader, remember to close it when done
final ArchiveReader reader = ArchiveRepository.getInstance().getArchiveReader(archive.getUrl());
archive_readers.add(reader);
// Create ValueIterator
try {
ValueIterator iter;
if (source == Source.OPTIMIZED_ARCHIVE && optimize_parameter > 1)
iter = reader.getOptimizedValues(archive.getKey(), item.getName(), start, end, (int) optimize_parameter);
else {
iter = reader.getRawValues(archive.getKey(), item.getName(), start, end);
if (source == Source.LINEAR_INTERPOLATION && optimize_parameter >= 1)
iter = new LinearValueIterator(iter, TimeDuration.ofSeconds(optimize_parameter));
}
iters.add(iter);
} catch (Exception ex) {
Logger.getLogger(getClass().getName()).log(Level.FINE, "Export error for " + item.getName(), ex);
if (error == null)
error = ex;
}
}
// If none of the iterators work out, report the first error that we found
if (iters.isEmpty() && error != null)
throw error;
// Return a merging iterator
return new MergingValueIterator(iters.toArray(new ValueIterator[iters.size()]));
}
use of org.csstudio.trends.databrowser3.model.PVItem in project org.csstudio.display.builder by kasemir.
the class XMLPersistence method load.
private void load(final Model model, final Document doc) throws Exception {
if (model.getItems().iterator().hasNext())
throw new RuntimeException("Model was already in use");
// Check if it's a <databrowser/>.
doc.getDocumentElement().normalize();
final Element root_node = doc.getDocumentElement();
if (!root_node.getNodeName().equals(TAG_DATABROWSER))
throw new Exception("Expected " + TAG_DATABROWSER + " but got " + root_node.getNodeName());
// Global settings
String title = DOMHelper.getSubelementString(root_node, TAG_TITLE);
if (!title.isEmpty())
model.setTitle(title);
model.setSaveChanges(DOMHelper.getSubelementBoolean(root_node, TAG_SAVE_CHANGES, true));
model.setGridVisible(DOMHelper.getSubelementBoolean(root_node, TAG_GRID, false));
model.enableScrolling(DOMHelper.getSubelementBoolean(root_node, TAG_SCROLL, true));
model.setUpdatePeriod(DOMHelper.getSubelementDouble(root_node, TAG_UPDATE_PERIOD, Preferences.getUpdatePeriod()));
try {
model.setScrollStep(Duration.ofSeconds(DOMHelper.getSubelementInt(root_node, TAG_SCROLL_STEP, (int) Preferences.getScrollStep().getSeconds())));
} catch (Throwable ex) {
// Ignore
}
final String start = DOMHelper.getSubelementString(root_node, TAG_START);
final String end = DOMHelper.getSubelementString(root_node, TAG_END);
if (start.length() > 0 && end.length() > 0)
model.setTimerange(start, end);
final String rescale = DOMHelper.getSubelementString(root_node, TAG_ARCHIVE_RESCALE, ArchiveRescale.STAGGER.name());
try {
model.setArchiveRescale(ArchiveRescale.valueOf(rescale));
} catch (Throwable ex) {
// Ignore
}
model.setToolbarVisible(DOMHelper.getSubelementBoolean(root_node, TAG_SHOW_TOOLBAR, true));
model.setLegendVisible(DOMHelper.getSubelementBoolean(root_node, TAG_SHOW_LEGEND, true));
// Value Axes
Element list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_AXES);
if (list != null) {
Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_AXIS);
while (item != null) {
model.addAxis(AxisConfig.fromDocument(item));
item = DOMHelper.findNextElementNode(item, TAG_AXIS);
}
} else {
// Check for legacy <xyGraphSettings> <axisSettingsList>
list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_OLD_XYGRAPH_SETTINGS);
if (list != null) {
loadColorFromDocument(list, "plotAreaBackColor").ifPresent(model::setPlotBackground);
Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), "axisSettingsList");
if (item != null) {
// First axis is 'X'
model.setGridVisible(DOMHelper.getSubelementBoolean(item, "showMajorGrid", false));
// Read 'Y' axes
item = DOMHelper.findNextElementNode(item, "axisSettingsList");
while (item != null) {
final String name = DOMHelper.getSubelementString(item, "title", null);
final AxisConfig axis = new AxisConfig(name);
loadColorFromDocument(item, "foregroundColor").ifPresent(axis::setColor);
axis.setGridVisible(DOMHelper.getSubelementBoolean(item, "showMajorGrid", false));
axis.setLogScale(DOMHelper.getSubelementBoolean(item, "logScale", false));
axis.setAutoScale(DOMHelper.getSubelementBoolean(item, "autoScale", false));
final Element range = DOMHelper.findFirstElementNode(item.getFirstChild(), "range");
if (range != null) {
double min = DOMHelper.getSubelementDouble(range, "lower", axis.getMin());
double max = DOMHelper.getSubelementDouble(range, "upper", axis.getMax());
axis.setRange(min, max);
}
model.addAxis(axis);
// Using legacy settings from _last_ axis for fonts
loadFontFromDocument(item, "scaleFont").ifPresent(model::setScaleFont);
loadFontFromDocument(item, "titleFont").ifPresent(model::setLabelFont);
item = DOMHelper.findNextElementNode(item, "axisSettingsList");
}
}
}
}
// New settings, possibly replacing settings from legacy <xyGraphSettings> <axisSettingsList>
loadColorFromDocument(root_node, TAG_BACKGROUND).ifPresent(model::setPlotBackground);
loadFontFromDocument(root_node, TAG_TITLE_FONT).ifPresent(model::setTitleFont);
loadFontFromDocument(root_node, TAG_LABEL_FONT).ifPresent(model::setLabelFont);
loadFontFromDocument(root_node, TAG_SCALE_FONT).ifPresent(model::setScaleFont);
loadFontFromDocument(root_node, TAG_LEGEND_FONT).ifPresent(model::setLegendFont);
// Load Annotations
list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_ANNOTATIONS);
if (list != null) {
// Load PV items
final List<AnnotationInfo> annotations = new ArrayList<>();
Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_ANNOTATION);
while (item != null) {
try {
annotations.add(AnnotationInfo.fromDocument(item));
} catch (Throwable ex) {
Activator.getLogger().log(Level.INFO, "XML error in Annotation", ex);
}
item = DOMHelper.findNextElementNode(item, TAG_ANNOTATION);
}
model.setAnnotations(annotations);
}
// Load PVs/Formulas
list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_PVLIST);
if (list != null) {
// Load PV items
Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_PV);
while (item != null) {
final PVItem model_item = PVItem.fromDocument(model, item);
// Adding item creates the axis for it if not already there
model.addItem(model_item);
// Ancient data browser stored axis configuration with each item: Update axis from that.
final AxisConfig axis = model_item.getAxis();
String s = DOMHelper.getSubelementString(item, TAG_AUTO_SCALE);
if (s.equalsIgnoreCase("true"))
axis.setAutoScale(true);
s = DOMHelper.getSubelementString(item, TAG_LOG_SCALE);
if (s.equalsIgnoreCase("true"))
axis.setLogScale(true);
final double min = DOMHelper.getSubelementDouble(item, TAG_MIN, axis.getMin());
final double max = DOMHelper.getSubelementDouble(item, TAG_MAX, axis.getMax());
axis.setRange(min, max);
item = DOMHelper.findNextElementNode(item, TAG_PV);
}
// Load Formulas
item = DOMHelper.findFirstElementNode(list.getFirstChild(), TAG_FORMULA);
while (item != null) {
model.addItem(FormulaItem.fromDocument(model, item));
item = DOMHelper.findNextElementNode(item, TAG_FORMULA);
}
}
// Update items from legacy <xyGraphSettings>
list = DOMHelper.findFirstElementNode(root_node.getFirstChild(), TAG_OLD_XYGRAPH_SETTINGS);
if (list != null) {
title = DOMHelper.getSubelementString(list, TAG_TITLE);
if (!title.isEmpty())
model.setTitle(title);
final Iterator<ModelItem> model_items = model.getItems().iterator();
Element item = DOMHelper.findFirstElementNode(list.getFirstChild(), "traceSettingsList");
while (item != null) {
if (!model_items.hasNext())
break;
final ModelItem pv = model_items.next();
Optional<RGB> rgb = loadColorFromDocument(item, "traceColor");
if (rgb.isPresent()) {
pv.setColor(SWTMediaPool.getJFX(rgb.get()));
}
pv.setLineWidth(DOMHelper.getSubelementInt(item, "lineWidth", pv.getLineWidth()));
pv.setDisplayName(DOMHelper.getSubelementString(item, "name", pv.getDisplayName()));
item = DOMHelper.findNextElementNode(item, "traceSettingsList");
}
}
}
use of org.csstudio.trends.databrowser3.model.PVItem 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();
});
}
Aggregations