0

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.

YogiWatcher
  • 165
  • 1
  • 8

1 Answers1

1

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

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • That worked for getting logos to be right justified. But it seems that there is a limit to how much it will stretch. It stretches while resizing the window until certain point. Beyond which it collapses and moves the perspective bar on the same line. As you said there may not be a way to keep the perspective switcher on a separate line. Although, adding this third tool control, somehow messed up my foreground and background colors of the logo composite :-( – YogiWatcher Feb 15 '23 at 18:22
  • IS there a list of what all tags, like stretch, supported? I see "logo" and "solo" tags being used. What do those tags do? – YogiWatcher Feb 15 '23 at 18:24
  • 1
    Tags vary depending on what element they are used with and the renderer / layout dealing with it. Here it is `org.eclipse.e4.ui.workbench.renderers.swt.TrimBarLayout` which supports `stretch` and `glue`. Applications can also use tags for their own purposes. You would have to study that code for more details of what the layout does. It is possible to override most parts of the renderer but it can be a lot of work. – greg-449 Feb 15 '23 at 19:34
  • Before adding the third Tool Control with "stretch" tag, my trim bar logos had blue background, and trim bar text was black on white. After adding the additional tool control, logos changed to white background, and text changed to black on black. Any idea why? I can't seem to get original colors back even after removing the third tool control. – YogiWatcher Feb 15 '23 at 20:19
  • If you are using CSS it is probably problems with that. There is a CSS Spy tool that can help see what CSS is being applied. – greg-449 Feb 15 '23 at 20:36