How to reset perspective programmatically in Eclipse RCP E4 not E3 - eclipse

I just added 2 perspectives in my RCP App. I can switch from one to another without problems.
But I didn't find a way to reset perspective, for example if I close a Part excidently I need to reset my perspective.
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().resetPerspective();
this didn't work because I use E4.
-clearPersistedState -persistState false
is not a solution cause I need to reset without restart my App.

Use the resetPerspective method of EModelService:
public void resetPerspectiveModel(MPerspective persp, MWindow window)
Note that PlatformUI and associated APIs can't be used in a pure e4 application.

Related

how to add python perspective in rcp

i am working with eclipse oxygen, i download pydev 6.3.2 and this was added to eclipse.
Now i want add Pydev in my custom rcp application, i read vogella book but i can't figure out how do this.
If anyone have the tip of the iceberg where i can start i will be thankful.
I have a e3 rcp application with Pydev Perspective already working but i want updated the technologies that i am working now that is i why start with e4.
In e3 i add the pydev plugins trougth Windows, Preferences, Plug-in Development, Target Platform.
Then i added in Dependence Tab in plugin.xml the "com.python.pydev.*"
Last step was create an button and in the handler put the next code
public class ShowPydevPerspective extends AbstractHandler
{
#Override
public Object execute(ExecutionEvent event) throws ExecutionException
{
ViewUtility.OpenPerspective("org.python.pydev.ui.PythonPerspective");
return null;
}
}
When the app run and click on the button the pydev perspective appears with all the context.
I try to do the same steps in e4 but is not working.
I added in my plugin.xml , dependece tab all
org.python.pyedev.*
org.eclipse.ui.*
I added too a button with the code that i mentioned after.
I have the following error, has you see in the image attached.
pydev integration error
Regards
PyDev is written for e3 and won't run in a pure e4 app. If you want to use this stick to an e3 RCP.
You can't just include org.eclipse.ui.xxx plugins in an e4 app {with one or two exceptions) - these are 3.x compatibility mode code and require a lot of setup that e4 doesn't do.

How to add perspective change listener in e4 RCP application?

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
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.

e4 Toolbar at Top Position invisible

I have a question regarding e4 rcp applications.
I am creating an Eclipse e4 RCP project which uses the compatibilty layer.
Basically I created an 3.x RCP project, a product and an Application.e4xmi to use e4 features in my 3.x RCP project. I did this to be able to use the compatibilty layer for stuff like the project explorer, the console etc....
I started with that tutorial: http://dirksmetric.wordpress.com/2012/08/01/tutorial-eclipse-rcp-e4-with-3-x-views-like-project-explorer-properties-etc/
and now I'm migrating my own plugins from 3.x to e4.
Till now that worked out pretty well. I can still use a multiparteditor from 3.x but also dependency injection for some parts. Now I'm facing a rather odd problem.
My Application has a Trimmed Window with a Main menu some parts and then there are the TrimBars...my problem.
The toolbar I create there is not shown if I choose the 'top' side...every other side is working.
In a pure e4 Application that is working fine. I'm not sure why...maybe you have an idea.
Thx.
After you have created your RCP application, you should have class ApplicationWorkbenchWindowAdvisor (extends WorkbenchWindowAdvisor) created for you. It has preWindowOpen() method overridden with IWorkbenchWindowConfigurer.setShowCoolBar(false). Change it to true:
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(400, 300));
configurer.setShowCoolBar(true);
configurer.setShowStatusLine(false);
configurer.setTitle("RCP Application");
}
Make sure that your XMI file defines the 'TOP' TrimBar with the id 'org.eclipse.ui.main.menu', there's currently some dependency on the handling code that requires this (i.e. it finds the trim bar by ID rather than position).

How can I make my Eclipse RCP app's keyboard shortcuts (accelerators) work immediately after startup?

Our Eclipse RCP application was originally built in the 3.1/3.2 era and was running on 3.2 until we switched to 3.6 recently. Its IApplication runs via PlatformUI.createAndRunWorkbench(...). The WorkbenchAdvisor we pass to that function overridescreateWorkbenchWindowAdvisor(...) to return a WorkbenchWindowAdvisor whose createActionBarAdvisor(...) returns an ActionBarAdvisor.
This ActionBarAdvisor's makeActions(...) creates and register()s a bunch of org.eclipse.jface.action.Actions, many of which do things like setAccelerator(SWT.CTRL | 'O'); in their constructors. The Actions are subsequently installed in the ActionBarAdvisor's fillMenuBar(...) and fillCoolBar(...) methods.
The problem we are having (now that we are on Eclipse RCP 3.6) is that these accelerators don't seem to be active until their menus are shown (even if no action is taken besides closing the menu again).
We see a relevant bug but are having some difficulty understanding how to apply its remedy to our situation. We recognize that instead of Actions we "ought" to be using commands, handlers, and key bindings. But we're hoping we don't have to go down that path just yet.
How can we make our accelerators "live" as soon as the application starts up?
If you don't choose to use o.e.ui.bindings extension point, then there isn't a better way. You should only force update the menuManager yourself as you have done in your answer.
As #Prakash mentioned, if you want to keep down that path in your RCP app you must render all of the main menus to see your accelerators.
There is a partial upgrade path that will get you on the right track to commands without forcing a complete switch over right away. For each action in your menu, define a command with an id and define a binding to the shortcut you want in your plugin.xml. Then, when you create the action in your ActionBarAdvisor, don't set the accelerator. Set the IAction.setActionDefinitionId(*) to the command id, can call register(action);
Then you no longer need to use menuManager.updateAll(true) to eagerly render all of your main menu.
After hunting around and experimenting a bit trying to apply the advice from the bug, we added the following to our WorkbenchWindowAdvisor, which seems to have done the trick:
#Override
public void postWindowCreate() {
getWindowConfigurer().getActionBarConfigurer().getMenuManager().updateAll(true);
}
We have no idea how well this fits with the Workbench's design expectations; there could be a better way.

Execute code when loading an Eclipse perspective

I'm creating an Eclipse plug-in which amongst other things creates a new perspective. I want to I execute some code when the perspective loads. Previously I was doing this through createInitialLayout of IPerspectiveFactory but then I realized that this is for defining the page layout only and is usually called when when launching the perspective for the first time only.
How can I specify some code to execute whenever the perspective is displayed? (e.g. when it is loaded as the default perspective by Eclipse)
Thanks and regards,
Krt_Malta
Check the documentation for the IPerspectiveListener interface or the PerspectiveAdapter class, the perspective lifecycle events are explained there.