-->

How to add perspective change listener in e4 RCP a

2019-06-08 16:49发布

问题:

I am currently working on a E4 RCP application where I need to detect when ever perspective is chnaged or switched so I need to add listener .Previously in eclipse 3x i used to do like below code .

PlatformUI.getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener()

But this code will not work in E4 as platformui is not acessible in E4.

I tried searching on web and I came across below tutorial. http://www.vogella.com/tutorials/Eclipse4ModelEvents/article.html#exercise_perspective_switch Is there any other way available without listening to whole @EventTopic(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT) and only listening to only perspective change

回答1:

I don't see any specific events for perspective switch in the source code that does this (org.eclipse.e4.ui.internal.workbench.PartServiceImpl).

The EPartService addPartListener should be called but I think the UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT is probably the better option. It is normal for code to be listening to events like this (the main problem being working out which one to listen too!)

The old perspective changed listener is implemented in Eclipse 4 by listening to the UIEvents.EventTags.ELEMENT event.