Eclipse RCP - ToolItems not rendering with Edge browser until window resized

Viewed 53

Hope you can help with a bit of a strange problem I'm having.

Take a very simple RCP application, with a toolbar along the top, where the user can switch between perspectives. One perspective contains a Browser component.

Normally, when a user switches to the HelpDocumentsView, a browser is displayed and a bunch of red icons (highlighted) appear along the top.

enter image description here

But when using Edge webview2 as the browser component, using the following VM augments:

-Dorg.eclipse.swt.browser.DefaultType=edge -Dorg.eclipse.swt.browser.EdgeDir=path\to\Microsoft.WebView2.FixedVersionRuntime.103.0.1264.37.x64

The red icons are not displayed: enter image description here

But when the application is resized, they appear: enter image description here

Somehow the choice of browser rendering engine is changing how the ToolItems are being rendered, and I don't understand why.

I'm trying to use Edge because on Windows it'll use IE, and IE is unable to render the Javascript contained on the page I'd like to render in the browser.

PerspectiveSwitcherToolbar.java:

package com.me.rcp.perspective;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;

import com.me.images.ImageProvider;

public class PerspectiveSwitcherToolbar implements EventHandler {
    private static final String HELP_ID = "Help"; //$NON-NLS-1$

    @Inject
    private static MApplication app;

    @Inject
    private static EPartService partService;

    @Inject
    private static EModelService modelService;

    private static ToolBar toolBar;

    @PostConstruct
    private static void postConstruct(final Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);

    composite.setLayout(new RowLayout(SWT.HORIZONTAL));

    toolBar = new ToolBar(composite, SWT.FLAT | SWT.WRAP | SWT.RIGHT);

    parent.pack();

    perspectiveSwitch("DataDashboard"); //$NON-NLS-1$
    }

    private static void perspectiveSwitch(final String id) {
    final Menu switcherMenu = new Menu(toolBar);

    final ToolItem choosePerspective = new ToolItem(toolBar, SWT.DROP_DOWN);
    choosePerspective.setImage(ImageProvider.DATA_DASHBOARD);
    choosePerspective.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
        final Rectangle rect = choosePerspective.getBounds();
        final Point pt = switcherMenu.getParent().toDisplay(new Point(rect.x, rect.y));
        switcherMenu.setLocation(pt.x, pt.y + rect.height);
        switcherMenu.setVisible(true);
        }
    });

    final MenuItem helpMenu = new MenuItem(switcherMenu, SWT.PUSH);
    helpMenu.setImage(ImageProvider.HELP);
    helpMenu.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
        perspectiveSwitch(HELP_ID);
        }
    });

    partService.switchPerspective((MPerspective) modelService.find(id, app));

    if (id.equals(HELP_ID)) {
        for (int i = 0; i < 10; i++) {
        new ToolItem(toolBar, SWT.PUSH).setImage(ImageProvider.USER_GUIDE);
        }
    }
    }

    @Override
    public void handleEvent(final Event event) {
    }
}

HelpDocumentsView.java:

package com.me.rcp.viewpart;

import javax.annotation.PostConstruct;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;

public class HelpDocumentsView {
    @PostConstruct
    public void createPartControl(final Composite parent) {
    new Browser(parent, SWT.NONE);
    }
}
1 Answers

I think the problem is that the ToolItem doesn't have a text property set, only an image - and because of this one of the nested layout() calls is skipping it

When I set it to a zero-width space (e.g. item.setText("\u200B")) it renders correctly.

Related