use of org.csstudio.trends.databrowser3.model.PVItem in project org.csstudio.display.builder by kasemir.
the class DataBrowserEditor method init.
/**
* Initialize model from editor input
* {@inheritDoc}
*/
@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
setSite(site);
if (input instanceof DataBrowserModelEditorInput) {
// Received model with input
model = ((DataBrowserModelEditorInput) input).getModel();
setInput(input);
} else {
// Create new model
model = new Model();
setInput(new DataBrowserModelEditorInput(input, model));
// Load model content from file
try (final InputStream stream = SingleSourcePlugin.getResourceHelper().getInputStream(input)) {
if (stream != null)
new XMLPersistence().load(model, stream);
} catch (Exception ex) {
throw new PartInitException(NLS.bind(Messages.ConfigFileErrorFmt, input.getName()), ex);
}
}
// Update the editor's name from "Data Browser" to title of model or file name
// See DataBrowserModelEditorInput.getName()
setPartName(getEditorInput().getName());
model_listener = new ModelListenerAdapter() {
@Override
public void changedSaveChangesBehavior(final boolean save_changes) {
is_dirty = save_changes;
firePropertyChange(IEditorPart.PROP_DIRTY);
}
@Override
public void changedTitle() {
setDirty(true);
}
@Override
public void changedLayout() {
setDirty(true);
}
@Override
public void changedTiming() {
setDirty(true);
}
@Override
public void changedArchiveRescale() {
setDirty(true);
}
@Override
public void changedColorsOrFonts() {
setDirty(true);
}
@Override
public void changedTimerange() {
setDirty(true);
}
@Override
public void changeTimeAxisConfig() {
setDirty(true);
}
@Override
public void changedAxis(final Optional<AxisConfig> axis) {
setDirty(true);
}
@Override
public void itemAdded(final ModelItem item) {
setDirty(true);
}
@Override
public void itemRemoved(final ModelItem item) {
setDirty(true);
}
@Override
public void changedItemVisibility(final ModelItem item) {
setDirty(true);
}
@Override
public void changedItemLook(final ModelItem item) {
site.getShell().getDisplay().asyncExec(() -> setDirty(true));
}
@Override
public void changedItemDataConfig(PVItem item) {
setDirty(true);
}
@Override
public void scrollEnabled(final boolean scroll_enabled) {
setDirty(true);
}
@Override
public void changedAnnotations() {
setDirty(true);
}
};
model.addListener(model_listener);
}
use of org.csstudio.trends.databrowser3.model.PVItem in project org.csstudio.display.builder by kasemir.
the class EditFormulaDialogDemo method dialogDemo.
public void dialogDemo() throws Exception {
final Shell shell = new Shell();
// Demo model with some PVs and a formula
final Model model = new Model();
model.addItem(new PVItem("fred", 0.0));
model.addItem(new PVItem("freddy", 0.0));
model.addItem(new PVItem("jane", 0.0));
model.addItem(new PVItem("janet", 0.0));
final FormulaItem formula = new FormulaItem("demo", "2*x2", new FormulaInput[] { new FormulaInput(model.getItem("fred"), "x2"), new FormulaInput(model.getItem("janet"), "jj") });
model.addItem(formula);
final EditFormulaDialog edit = new EditFormulaDialog(null, shell, formula);
System.out.println("Before editing:");
dump(formula);
if (edit.open()) {
System.out.println("After editing:");
dump(formula);
} else
System.out.println("Cancelled");
}
use of org.csstudio.trends.databrowser3.model.PVItem in project org.csstudio.display.builder by kasemir.
the class ControllerDemo method debug.
protected void debug() {
for (ModelItem item : model.getItems()) {
if (!(item instanceof PVItem)) {
continue;
}
System.out.println("\n" + item.getName() + ":");
final PlotSamples samples = item.getSamples();
samples.getLock().lock();
try {
if (samples.size() <= 0)
continue;
Instant last = samples.get(0).getPosition();
for (int s = 0; s < samples.size(); ++s) {
final PlotSample sample = samples.get(s);
System.out.println(sample);
final Instant time = sample.getPosition();
if (time.compareTo(last) < 0) {
System.out.println("Time sequence error!");
break;
}
last = time;
}
} finally {
samples.getLock().unlock();
}
}
new XMLPersistence().write(model, System.out);
}
use of org.csstudio.trends.databrowser3.model.PVItem in project org.csstudio.display.builder by kasemir.
the class OpenDataBrowserPopup method add.
/**
* Add item
* @param model Model to which to add the item
* @param pv PV to add
* @param archive Archive to use or <code>null</code>
* @throws Exception on error
*/
private void add(final Model model, final ProcessVariable pv, final ArchiveDataSource archive) throws Exception {
final PVItem item = new PVItem(pv.getName(), period);
if (archive == null)
item.useDefaultArchiveDataSources();
else
item.addArchiveDataSource(archive);
// Add item to new axis
item.setAxis(model.addAxis());
model.addItem(item);
}
use of org.csstudio.trends.databrowser3.model.PVItem in project org.csstudio.display.builder by kasemir.
the class OpenDataBrowserPopup method execute.
/**
* {@inheritDoc}
*/
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
// Get selection first because the ApplicationContext might change.
ISelection selection = HandlerUtil.getActiveMenuSelection(event);
if (selection == null) {
// This works for double-clicks.
selection = HandlerUtil.getCurrentSelection(event);
}
// Create new editor
final DataBrowserEditor editor = DataBrowserEditor.createInstance();
if (editor == null)
return null;
// Add received items
final Model model = editor.getModel();
try {
if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).getFirstElement() instanceof ChannelInfo) {
// Received items are from search dialog
final Object[] channels = ((IStructuredSelection) selection).toArray();
for (Object channel : channels) {
final ChannelInfo info = (ChannelInfo) channel;
add(model, info.getProcessVariable(), info.getArchiveDataSource());
}
} else {
// Add received PVs with default archive data sources
final List<TimestampedPV> timestampedPVs = Arrays.asList(AdapterUtil.convert(selection, TimestampedPV.class));
if (!timestampedPVs.isEmpty()) {
// Add received items, tracking their start..end time
long start_ms = Long.MAX_VALUE, end_ms = 0;
for (TimestampedPV timestampedPV : timestampedPVs) {
final long time = timestampedPV.getTime();
if (time < start_ms)
start_ms = time;
if (time > end_ms)
end_ms = time;
final PVItem item = new PVItem(timestampedPV.getName().trim(), period);
item.setAxis(model.addAxis());
item.useDefaultArchiveDataSources();
model.addItem(item);
}
final Instant start = Instant.ofEpochMilli(start_ms).minus(Duration.ofMinutes(30));
final Instant end = Instant.ofEpochMilli(end_ms).plus(Duration.ofMinutes(30));
model.enableScrolling(false);
model.setTimerange(start, end);
} else {
final ProcessVariable[] pvs = AdapterUtil.convert(selection, ProcessVariable.class);
for (ProcessVariable pv : pvs) add(model, pv, null);
}
}
} catch (Exception ex) {
MessageDialog.openError(editor.getSite().getShell(), Messages.Error, NLS.bind(Messages.ErrorFmt, ex.getMessage()));
}
return null;
}
Aggregations