Search in sources :

Example 1 with ControllerSWT

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);
}
Also used : FillLayout(org.eclipse.swt.layout.FillLayout) Scene(javafx.scene.Scene) PartInitException(org.eclipse.ui.PartInitException) IPartListener2(org.eclipse.ui.IPartListener2) ModelBasedPlot(org.csstudio.trends.databrowser3.ui.ModelBasedPlot) Control(org.eclipse.swt.widgets.Control) JFX_SWT_Wrapper(org.csstudio.javafx.swt.JFX_SWT_Wrapper) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) ControllerSWT(org.csstudio.trends.databrowser3.ui.ControllerSWT)

Example 2 with ControllerSWT

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();
}
Also used : Control(org.eclipse.swt.widgets.Control) MenuManager(org.eclipse.jface.action.MenuManager) Menu(org.eclipse.swt.widgets.Menu) ControllerSWT(org.csstudio.trends.databrowser3.ui.ControllerSWT) ModelBasedPlot(org.csstudio.trends.databrowser3.ui.ModelBasedPlot)

Aggregations

ControllerSWT (org.csstudio.trends.databrowser3.ui.ControllerSWT)2 ModelBasedPlot (org.csstudio.trends.databrowser3.ui.ModelBasedPlot)2 Control (org.eclipse.swt.widgets.Control)2 Scene (javafx.scene.Scene)1 JFX_SWT_Wrapper (org.csstudio.javafx.swt.JFX_SWT_Wrapper)1 MenuManager (org.eclipse.jface.action.MenuManager)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Menu (org.eclipse.swt.widgets.Menu)1 IPartListener2 (org.eclipse.ui.IPartListener2)1 IWorkbenchPartReference (org.eclipse.ui.IWorkbenchPartReference)1 PartInitException (org.eclipse.ui.PartInitException)1