How to add Perspective Bar Switcher to pure eclipse 4 rcp application

柔情痞子 提交于 2019-11-29 15:45:17

EPartService.switchPerspective will do the actual switch, but you will have to design and implement the UI.

You could use a ToolBar in the window Trim Bar with buttons for each perspective. Alternatively a Combo as a Tool Control with a list of the perspectives, it is up to you.

To put a control at the right of a Trim Bar you need to add two Tool Control objects to the trim. Something like:

The first Tool Control is just a spacer to fill the center of the bar.

On the tags tab for the control add the word stretch to tell e4 to stretch this control over as much space as possible:

You will also have to specify a class for the control. This just needs to create an empty Composite to occupy the space. For example:

public class SpacerControl
{
  @PostConstruct
  public void postConstruct(final Composite parent)
  {
    Composite body = new Composite(parent, SWT.NONE);

    body.setLayout(new FillLayout());
  }
}

The second Tool Control will contain your Combo control for the perspective switch. Something like:

public class ComboControl
{
  @PostConstruct
  public void createGui(final Composite parent)
  {
    Combo combo = new Combo(parent, SWT.READ_ONLY);

    ... initialize Combo, add listeners, ....
  }
}

This should end up looking something like this:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!