use of org.csstudio.trends.databrowser3.ui.ModelBasedPlot in project org.csstudio.display.builder by kasemir.
the class DataBrowserEditor method createPartControl.
/**
* Create Plot GUI, connect to model via Controller
* {@inheritDoc}
*/
@Override
public void createPartControl(final Composite parent) {
// Create GUI elements (Plot)
parent.setLayout(new FillLayout());
final JFX_SWT_Wrapper wrapper = new JFX_SWT_Wrapper(parent, () -> {
try {
plot = new ModelBasedPlot(true);
} catch (Exception ex) {
logger.log(Level.WARNING, "Cannot create plot", ex);
}
return new Scene(plot.getPlot());
});
final Control plot_canvas = wrapper.getFXCanvas();
final Scene scene = wrapper.getScene();
JFXCursorFix.apply(scene, parent.getDisplay());
try {
hookDragAndDrop(plot_canvas);
} catch (Throwable ex) {
// Adding D&D to FXCanvas involves some hacking
// that might break as SWT internals get updated.
logger.log(Level.WARNING, "Cannot initialize Drag&Drop", ex);
}
// Create and start controller
controller = new ControllerSWT(parent.getShell(), model, plot);
try {
controller.start();
} catch (Exception ex) {
ExceptionDetailsErrorDialog.openError(parent.getShell(), Messages.Error, ex);
}
// Only the 'page' seems to know if a part is visible or not,
// so use PartListener to update controller's redraw handling
getSite().getPage().addPartListener(new IPartListener2() {
private boolean isThisEditor(final IWorkbenchPartReference part) {
return part.getPart(false) == DataBrowserEditor.this;
}
// Enable redraws...
@Override
public void partOpened(final IWorkbenchPartReference part) {
if (isThisEditor(part))
controller.suppressRedraws(false);
}
@Override
public void partVisible(final IWorkbenchPartReference part) {
if (isThisEditor(part))
controller.suppressRedraws(false);
}
// Suppress redraws...
@Override
public void partHidden(final IWorkbenchPartReference part) {
if (isThisEditor(part))
controller.suppressRedraws(true);
}
@Override
public void partClosed(final IWorkbenchPartReference part) {
if (isThisEditor(part))
controller.suppressRedraws(true);
}
// Ignore
@Override
public void partInputChanged(final IWorkbenchPartReference part) {
/* NOP */
}
@Override
public void partDeactivated(final IWorkbenchPartReference part) {
/* NOP */
}
@Override
public void partBroughtToTop(final IWorkbenchPartReference part) {
/* NOP */
}
@Override
public void partActivated(final IWorkbenchPartReference part) {
/* NOP */
}
});
toggle_legend = new ToggleLegendAction(plot.getPlot(), true);
toggle_toolbar = new ToggleToolbarAction(plot.getPlot(), true);
snapshot = new SnapshotAction(plot.getPlot(), parent.getShell());
createContextMenu(plot_canvas);
}
use of org.csstudio.trends.databrowser3.ui.ModelBasedPlot in project org.csstudio.display.builder by kasemir.
the class PlotDemo method createGUI.
// final private PlotListener listener = new PlotListener()
// {
// @Override
// public void scrollRequested(final boolean enable_scrolling)
// {
// System.out.println("Scroll enabled: " + enable_scrolling);
// scroll = enable_scrolling;
// }
//
// @Override
// public void timeConfigRequested()
// {
// System.out.println("Time Config requested");
// }
//
// @Override
// public void timeAxisChanged(final long start_ms, final long end_ms)
// {
// start_time = TimestampHelper.fromMillisecs(start_ms);
// end_time = TimestampHelper.fromMillisecs(end_ms);
// System.out.println("Time axis: " + start_time + " ... " + end_time);
// }
//
// @Override
// public void valueAxisChanged(final int index, final double lower, final double upper)
// {
// System.out.println("Value axis " + index + ": " + lower + " ... " + upper);
// }
//
// @Override
// public void droppedName(final String name)
// {
// System.out.println("Name dropped: " + name);
// }
//
// @Override
// public void droppedPVName(final ProcessVariable name, final ArchiveDataSource archive)
// {
// System.out.println("PV Name dropped: " + name);
// }
//
// @Override
// public void droppedFilename(final String file_name)
// {
// System.out.println("File Name dropped: " + file_name);
// }
//
// @Override
// public void xyGraphConfigChanged(XYGraph newValue) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void removeAnnotationChanged(Annotation oldValue) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void addAnnotationChanged(Annotation newValue) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void backgroundColorChanged(Color newValue) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void timeAxisForegroundColorChanged(Color oldColor,
// Color newColor) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void valueAxisForegroundColorChanged(int index, Color oldColor,
// Color newColor) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void valueAxisTitleChanged(int index, String oldTitle,
// String newTitle) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void valueAxisAutoScaleChanged(int index, boolean oldAutoScale,
// boolean newAutoScale) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void traceNameChanged(int index, String oldName, String newName) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void traceYAxisChanged(int index, AxisConfig oldConfig,
// AxisConfig config) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void traceTypeChanged(int index, TraceType old,
// TraceType newTraceType) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void traceColorChanged(int index, Color old, Color newColor) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void valueAxisLogScaleChanged(int index, boolean old,
// boolean logScale) {
// // TODO Auto-generated method stub
//
// }
// };
private void createGUI(final Composite parent) {
final GridLayout layout = new GridLayout(1, false);
parent.setLayout(layout);
ModelBasedPlot plot;
try {
plot = new ModelBasedPlot(true);
} catch (Exception e1) {
e1.printStackTrace();
return;
}
final FXCanvas canvas = new FXCanvas(parent, SWT.NONE);
canvas.setScene(new Scene(plot.getPlot()));
canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));
// [Done] button to end demo
final Button ok = new Button(parent, SWT.PUSH);
ok.setText("Done");
ok.setLayoutData(new GridData(SWT.RIGHT, 0, true, false));
ok.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
run = false;
}
});
// plot.addListener(listener);
// Create demo samples
final List<PlotSample> values = new ArrayList<PlotSample>();
for (int i = 1; i < 10; ++i) values.add(new PlotSample("Test", TestHelper.makeValue(i)));
values.add(new PlotSample("Test", TestHelper.makeError(15, "Disconnected")));
// Single value. Line should continue until the following 'disconnect'.
values.add(new PlotSample("Test", TestHelper.makeValue(17)));
values.add(new PlotSample("Test", TestHelper.makeError(18, "Disconnected")));
for (int i = 20; i < 30; ++i) values.add(new PlotSample("Test", TestHelper.makeValue(i)));
final PlotSampleArray samples = new PlotSampleArray();
samples.set(values);
// Add item with demo samples
final ModelItem item = new ModelItem("Demo") {
@Override
public PlotSamples getSamples() {
return samples;
}
@Override
public void write(final PrintWriter writer) {
// NOP
}
};
// TODO: Fix or remove
// item.setColor(new RGB(0, 0, 255));
plot.addTrace(item);
// start_time = VTypeHelper.getTimestamp(samples.getSample(0).getValue());
// end_time = VTypeHelper.getTimestamp(samples.getSample(samples.getSize()-1).getValue());
// plot.setTimeRange(start_time, end_time);
}
use of org.csstudio.trends.databrowser3.ui.ModelBasedPlot in project org.csstudio.display.builder by kasemir.
the class DataBrowserWidgedEditPart method activate.
/**
* {@inheritDoc}}
*/
@Override
public void activate() {
// In run mode, start controller, which will start model
if (getExecutionMode() == ExecutionMode.RUN_MODE) {
try {
// Connect plot to model (created by OPI/GEF)
final ModelBasedPlot plot_widget = gui.getDataBrowserPlot();
controller = new ControllerSWT(null, getWidgetModel().createDataBrowserModel(), plot_widget);
controller.start();
// Have PV for cursor data?
final String pv_name = getWidgetModel().getSelectionValuePv();
if (!pv_name.isEmpty()) {
pv.set(PVManager.write(ExpressionLanguage.channel(pv_name)).async());
plot_widget.getPlot().addListener(plot_listener);
}
// Add context menu to the SWT control
// for opening full data browser
final MenuManager mm = new MenuManager();
mm.add(new OpenDataBrowserAction(this));
mm.add(new ShowToolbarAction(this));
// TODO: legend action
// mm.add(plot_widget.getPlot().getLegendAction());
final Control control = gui.getSWTWidget();
final Menu menu = mm.createContextMenu(control);
control.setMenu(menu);
} catch (Exception ex) {
Logger.getLogger(Activator.ID).log(Level.SEVERE, "Cannot start Data Browser Widget", ex);
}
}
super.activate();
}
use of org.csstudio.trends.databrowser3.ui.ModelBasedPlot in project org.csstudio.display.builder by kasemir.
the class DataBrowserWidgetFigure method createSWTWidget.
@Override
protected Control createSWTWidget(final Composite parent, final int style) {
final JFX_SWT_Wrapper wrapper = new JFX_SWT_Wrapper(parent, () -> {
Parent root;
try {
plot = new ModelBasedPlot(editPart.getExecutionMode() == ExecutionMode.RUN_MODE);
root = plot.getPlot();
} catch (Exception ex) {
logger.log(Level.WARNING, "Cannot create Data Browser OPI Widget's plot", ex);
root = new Label("Cannot initialize Plot");
}
return new Scene(root);
});
return wrapper.getFXCanvas();
}
Aggregations