This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 395084 - IWorkbench.showPerspective(id, window) not working after switching to 4.2.1 target
Summary: IWorkbench.showPerspective(id, window) not working after switching to 4.2.1 t...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.4 M2   Edit
Assignee: Daniel Rolka CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-26 11:06 EST by Flavio Donze CLA
Modified: 2013-09-17 05:08 EDT (History)
8 users (show)

See Also:


Attachments
bug395084.zip (5.35 KB, application/octet-stream)
2013-05-10 10:47 EDT, Krzysztof Kazmierczyk CLA
no flags Details
workbench comments (1.52 KB, text/plain)
2013-05-13 03:47 EDT, Flavio Donze CLA
no flags Details
Standalone Application (21.45 KB, application/x-zip-compressed)
2013-05-17 09:13 EDT, Flavio Donze CLA
no flags Details
standalone.bug395084 modified (10.59 KB, multipart/x-zip)
2013-07-25 04:35 EDT, Daniel Rolka CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Flavio Donze CLA 2012-11-26 11:06:39 EST
I'm migrating our product from Eclipse 3.7.1 to 4.2.1. I use certain handlers that  call:
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
PlatformUI.getWorkbench().showPerspective(id, window);

Since I changed the target platform to 4.2.1 this call does nothing. I don't get an exception and nothing happens. 

If I can be of any assistant, please let me know.
Comment 1 Paul Webster CLA 2012-11-28 09:22:19 EST
Looks like the org.eclipse.ui.internal.Workbench.showPerspective(String, IWorkbenchWindow, IAdaptable) method calls org.eclipse.ui.internal.Workbench.activate(String, IWorkbenchPage, IAdaptable, boolean) with the new perspective ID, but then activate(*) simply activates the window in the application model, and doesn't do anything with the perspective.

Then showPerspective(*) returns instead of going to the end of the method where it would actually set the perspective.

PW
Comment 2 Vincenzo Caselli CLA 2013-01-11 13:17:23 EST
Hi Flavio,
just as a temporary workaround we are using the solution showed here:
http://stackoverflow.com/questions/11523187/switch-perspective-in-a-rcp-application-since-eclipse-juno

that is replacing 

PlatformUI.getWorkbench().showPerspective()

with

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

HTH

Vincenzo
RCP Vision
Comment 3 Flavio Donze CLA 2013-01-14 02:14:48 EST
Hi Vincenzo

Thanks for sharing, I'll keep it in mind. Probably I just wait with upgrading our target to 4.x, until this and some other issues are fixed.
Comment 4 Eric Moffatt CLA 2013-01-16 14:08:11 EST
Paul, why don't we change the existing (broken) code in Workbench to be a refactored version of the workaround ??
Comment 5 Krzysztof Kazmierczyk CLA 2013-05-10 10:47:24 EDT
Created attachment 230778 [details]
bug395084.zip
Comment 6 Krzysztof Kazmierczyk CLA 2013-05-10 10:48:08 EDT
Hello Flavio,
I have tested it on 4.3.0.I20130505-2000 (The atest incremental for 4.3) and it is working for me.

Attaching my plug-in. Could you test it?
Comment 7 Flavio Donze CLA 2013-05-10 12:08:59 EDT
I just tested your plug-in with version 4.3.0.I20130502-0800 and it did not work. 

Maybe next week I'll be able to test the latest, has there been done any changes to fix this issue, between those two versions?
Comment 8 Flavio Donze CLA 2013-05-13 02:35:09 EDT
Sorry my bad, I was bit in a hurry when I tested.

I have my own target definition which does not contain the java perspective, I didn't see the exception.

Changed the perspective id to "org.eclipse.debug.ui.DebugPerspective" and it worked. 

I have to get my application running with the new 4.3 target, will report back, but I'm pretty confident that it will work.
Comment 9 Flavio Donze CLA 2013-05-13 03:45:06 EDT
After testing my application I found out that it still does not work.
I did a little debugging and this is what I found out:

public IWorkbenchPage showPerspective(String perspectiveId, IWorkbenchWindow targetWindow,
		IAdaptable input) throws WorkbenchException {

	## REMOVED UNINTERESSTING STUFF
		
	if (targetWindow != null) {
		IWorkbenchPage page = targetWindow.getActivePage();
		if (activate(perspectiveId, page, input, false)) {
			## MY APPLICATION RETURNS
			return page;
		}
		## SAMPLE APPLICATION GOES ON
		IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
		int mode = store.getInt(IPreferenceConstants.OPEN_PERSP_MODE);

		if (IPreferenceConstants.OPM_NEW_WINDOW != mode) {
			targetWindow.getShell().open();
			if (page == null) {
				page = targetWindow.openPage(perspectiveId, input);
			} else {
				page.setPerspective(targetPerspective);
			}
			return page;
		}
	}

	return openWorkbenchWindow(perspectiveId, input).getActivePage();
}


private boolean activate(String perspectiveId, IWorkbenchPage page, IAdaptable input,
			boolean checkPerspective) {
	if (page != null) {
		for (IPerspectiveDescriptor openedPerspective : page.getOpenPerspectives()) {
			if (!checkPerspective || openedPerspective.getId().equals(perspectiveId)) {
				## INPUT IS NULL IN BOTH CASES, BUT IN THE SAMPLE APPLICATION, page.getInput() DOES NOT RETURN NULL
				if (page.getInput() == input) {
					WorkbenchWindow wwindow = (WorkbenchWindow) page.getWorkbenchWindow();
					MWindow model = wwindow.getModel();
					application.setSelectedElement(model);
					return true;
				}
			}
		}
	}
	return false;
}

I can not find out what page.getInput() is since the debugger does not show it to me because of some unresovled dependency.

Maybe I'm missing some bundles?
Comment 10 Flavio Donze CLA 2013-05-13 03:47:13 EDT
Created attachment 230843 [details]
workbench comments

attached it as txt file since the comment is hard to read
Comment 11 Flavio Donze CLA 2013-05-13 04:01:35 EDT
After some more debugging:

IWorkbenchPage page = window.getActivePage();
page.getInput();

My application: null
Sampel application: org.eclipse.core.internal.resources.WorkspaceRoot object with "R/" as content.
Comment 12 Krzysztof Kazmierczyk CLA 2013-05-13 09:09:38 EDT
I believe, that original issue (PlatformUI.getWorkbench().showPerspective()) has been fixed. Paul, can you close this defect?

For page.getInput() - Flavio - could you open new bug?
Comment 13 Flavio Donze CLA 2013-05-13 09:17:42 EDT
Is the page required to deliver an input?
I think depending on the application, it should be ok for the page to deliver no input e.g. null.
Comment 14 Paul Webster CLA 2013-05-13 09:29:53 EDT
The original issue has been fixed in kepler.

PW
Comment 15 Flavio Donze CLA 2013-05-13 09:31:57 EDT
does it handle null inputs now? or do I have to create a new issue for this?
Comment 16 Paul Webster CLA 2013-05-13 09:43:54 EDT
(In reply to comment #15)
> does it handle null inputs now? or do I have to create a new issue for this?

Please create a new issue for page inputs.

PW
Comment 17 Paul Webster CLA 2013-05-17 08:21:25 EDT
Let's look at this again in Luna

PW
Comment 18 Flavio Donze CLA 2013-05-17 09:13:18 EDT
Created attachment 231152 [details]
Standalone Application

I created a standalone application, based on the eclipse sample "with view".
I just created another perspective/view and added the SWITCH command.
You should be able to reproduce this issue with it.
Comment 19 Flavio Donze CLA 2013-05-17 09:14:07 EDT
I also ran it on Eclipse 3.7.1 where it worked.
Comment 20 Paul Webster CLA 2013-07-24 15:53:20 EDT
Gerrit change https://git.eclipse.org/r/#/c/14068/

PW
Comment 21 Paul Webster CLA 2013-07-24 16:12:02 EDT
(In reply to comment #18)
> Created attachment 231152 [details]
> Standalone Application

I ran this app, and https://git.eclipse.org/r/#/c/14068 had no effect on using the Switch menu item (there was no visible change to the app)

PW
Comment 22 Daniel Rolka CLA 2013-07-25 03:25:15 EDT
(In reply to comment #21)
> (In reply to comment #18)
> > Created attachment 231152 [details]
> > Standalone Application
> 
> I ran this app, and https://git.eclipse.org/r/#/c/14068 had no effect on
> using the Switch menu item (there was no visible change to the app)
> 
> PW

It looks like this patch has stopped to work. I'll investigate what happened

Daniel
Comment 23 Daniel Rolka CLA 2013-07-25 04:35:21 EDT
Created attachment 233784 [details]
standalone.bug395084 modified

It looks that the issue is with the sample application that tries to switch to the same perspective without checking the current one (fixed perspective id). I've slightly modified the application and now after "switch" action the invisible perspective is displayed

Daniel
Comment 24 Paul Webster CLA 2013-07-25 14:59:21 EDT
(In reply to comment #23)
> Created attachment 233784 [details]
> standalone.bug395084 modified

The app that was attached starts up in standalone.bug395084.perspective and then the switch handler switches to standalone.bug395084.perspective2

It should work as is at least once, and I don't see that.  Can you get the original plugin to work at least once with your fix?

PW
Comment 26 Daniel Rolka CLA 2013-09-17 05:08:45 EDT
Verified in the build: I20130916-2330