Switch perspective in a RCP application since Eclipse Juno?
Asked Answered
O

3

6

In my RCP application I use this code to switch perspective :

IWorkbenchWindow window = getViewSite().getWorkbenchWindow();
window.getWorkbench().showPerspective(PRODUCT_PERSPECTIVE_ID, window);

I didn't change my code but I changed my developement environnement from

java 6 64bits + windows + Eclipse Indigo

to

java 7 32bits + windows + Eclipse Juno

And now the perspective doesn't switch any more, with no exception and nothing suspect visible in debug.

I didn't find any bug report.

Is there an explanation ? A workaround ?

Owe answered 17/7, 2012 at 13:8 Comment(0)
C
6

I have run into this problem as well. As far as I can tell, it is a regression in Juno (4.2.0). I used the debugger to step through the call to showPerspective(). At no point was any explicit attempt made to actually change the perspective. Perhaps there is an internal event listener missing, or perhaps the port of showPerspective() to the new framework is incomplete.

As a work-around, the following code successfully changed perspectives for me:

IWorkbenchWindow window = getViewSite().getWorkbenchWindow();
IPerspectiveRegistry registry = workbench.getPerspectiveRegistry();
IWorkbenchPage page = window.getActivePage();
page.setPerspective(registry.findPerspectiveWithId(PRODUCT_PERSPECTIVE_ID));

Depending upon the context in which these calls are made, you might want to null-guard some of these calls, or check Workbench.isClosing() to be safe.

Curassow answered 7/8, 2012 at 15:0 Comment(2)
Thanks. That's not the solution I choose for my program, I did what's written in my answer as Juno is much too buggy and ugly to enter production today. But your answer seems good and might be useful to others so I finally accept it :)Sinful
@dystroy Thanks for the accept. I have come to the same conclusion as you: the 4.x versions are still too buggy.Curassow
R
2

This is bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=395084 and fixed for Eclipse Luna which is scheduled to be released in June.

Rna answered 6/2, 2014 at 13:34 Comment(1)
No problem at all. I am actually using the workaround provided here because Luna isn't officially released yet and using it gives other bugs.Rna
O
1

Here's an answer that aims at clarifying and solving my problem :

Using the Eclipse 4 IDE, build a RCP application developped before Eclipse 4, integrating Java 7 features and compatible with Windows 32 bits. And of course be able to switch perspective.

This answer doesn't solve the problem of those who'd want to switch perspective in a RCP application AND use the features or look of the new Eclipse 4 Platform (not to be confused with the Eclipse 4 IDE). But I wouldn't recommend it, at least for an old application (that is developped on Eclipse 3), given that :

  • that's so slow it renders the application barely usable
  • there are numerous graphical glitches
  • there are bugs, among them the one related to perspective switch

For these 3 points, I can't say if it's due to the Eclipse 4 platform or the Eclipse 3 compatibility layer. I hope new applications developed specifically for the new Eclipse 4 platform would correctly run.

So my solution was to define an Eclipse 3 target and use it for the build.

Here's the complete procedure :

  1. Have the JDK 7 installed (32bits version)
  2. Install Eclipse 3.7 (32bits version)
  3. Install Eclipse 4 (32bits version)
  4. Launch Eclipse 4 and import the needed projects
  5. Go to Window/Preferences/Plug-in Development/Target Platform
  6. Click "Add" then "Nothing"
  7. Click "Add" then "Installation" and choose your Eclipse 3.7 directory
  8. Once your target created, select it (still in Window/Preferences/Plug-in Development/Target Platform)

Now, in your .product, the "Eclipse Product Export Wizard" will build an Eclipse 3 executable.

Practical notes :

  • "clean all" wasn't enough and I had to stop/restart Eclipse to get it working after target selection
  • the installation process erased some on my .product fields. I had to reset the ID and to check "The product includes native laucher artifacts"
Owe answered 18/7, 2012 at 10:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.