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

安稳与你 提交于 2019-11-28 08:56:37

问题


I have created a pure Eclipse e4 rich client platform application application model. I created multiple perspectives using perspective stack, but I am unable to switch other perspective because there is no default perspective bar or switcher icon present in Eclipse e4. How to implement a perspective switcher in pure Eclipse e4?


回答1:


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:



来源:https://stackoverflow.com/questions/35063724/how-to-add-perspective-bar-switcher-to-pure-eclipse-4-rcp-application

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