Search code examples
eclipsee4

How do I add second toolbar to Eclipse Application UI?


Eclipse e4 Application (Eclipse 2018-12).

I have developed a custom PerspectiveSwitcher class extending Composite. This class builds an UI to display - (1) user information using Label, (2) quick group change drop down combo box using Combo, and (3) tabbed perspective switcher using CTabFolder.

I want to add PerspectiveSwitcher UI as a second toolbar on the separate line, like in the image below: enter image description here

However,

  1. I want the "Company and App LOGO" to be placed on the right side (as pointed to by the red arrow). I tried several combinations of GridData parameters, but none worked.
  2. When I stretch the application window horizontally long enough, the icon toolbar and my custom toolbar merge, as below: enter image description here

Here is my Application.e4xmi is as follows. The first Tool Control adds the "Company and App LOGO", while the second Tool Control adds the PerspectiveSwitcher UI.

enter image description here

The first Tool Control class is:

public class TrimLogoControl
{
    @PostConstruct
    public void createPartControl(final Composite parent)
    {
        final Composite composite = new Composite(parent, SWT.NONE);
        composite.setLayout(new GridLayout(2, false));

        final Label logoLabel1 = new Label(composite, SWT.NONE);
        logoLabel1.setImage(PlugIn.createImage("icons/company_logo.png"));
        logoLabel1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        final Label logoLabel2 = new Label(composite, SWT.NONE);
        logoLabel2.setImage(Plugin.createImage("icons/app_logo.png"));
        logoLabel2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    }
}

The second Tool Control class is:

public class PerspectiveSwitcherControl
{
    @PostConstruct
    public void createPartControl(final Composite parent)
    {
        final Composite composite = new Composite(parent, SWT.NONE);
        composite.setLayout(new GridLayout(1, false));

        new PerspectiveSwitcher(composite, SWT.NONE); // Custom class
    }
}

I would very much appreciate, if someone can answer - how to move logos to the right, and how to keep the PerspectiveSwitcher toolbar on the separate line?

I tried adding another Tool Control before the first Tool Control and setting it to FillLayout as explained in How to add Perspective Bar Switcher to pure eclipse 4 rcp application. But that did not work.

I also checked the thread Eclipse e4 tool Control in trimbars, but that did not help either.


Solution

  • To align controls at the right of a trim bar add a separate ToolControl with a tag of stretch. This control will grab any available space in the bar giving right alignment for the result of the bar.

    The code for the control can just be an empty Composite with a FillLayout.

    I don't know if it possible to force things on to a separate line.

    Stretch tag