use of org.csstudio.trends.databrowser3.ui.ControllerSWT 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.ControllerSWT 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();
}
Aggregations