Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » setEditorAreaVisible(false) ignored when switching between perspectives
setEditorAreaVisible(false) ignored when switching between perspectives [message #673836] Tue, 24 May 2011 21:51 Go to next message
Eric Jain is currently offline Eric Jain
Messages: 266
Registered: July 2009
Senior Member
If I have two perspectives, one with and one without an editor area (configured with layout.setEditorAreaVisible(b)), and I switch from the one without to the one with the editor area and back, the perspective without the editor area now also shows an editor area.

Before I file a bug: Has anyone else seen (or have an explanation for) this behavior?

Here's how I switch perspectives:

void setPerspective(IWorkbenchPage page, String perspectiveId) {
  IPerspectiveRegistry registry = page.getWorkbenchWindow()
    .getWorkbench().getPerspectiveRegistry();
  page.setPerspective(registry.findPerspectiveWithId(perspectiveId));
}
Re: setEditorAreaVisible(false) ignored when switching between perspectives [message #673961 is a reply to message #673836] Wed, 25 May 2011 09:52 Go to previous messageGo to next message
David  Pérez is currently offline David Pérez
Messages: 228
Registered: July 2009
Senior Member
This is the code I use:
    public void switchToPerspective(String perspectiveId, IWorkbenchWindow win) {
        try {
            IPerspectiveDescriptor descr = win.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(perspectiveId);
            if (descr == null) {
                log.error("Cannot find perspective ID "+perspectiveId);
                return;
            }
            IPerspectiveDescriptor currentPersp = win.getActivePage().getPerspective();
            if (currentPersp.getId().equals(perspectiveId)) {
                return;
            }
            win.getWorkbench().showPerspective(perspectiveId, win);
        } catch (WorkbenchException ex) {
            log.error("", ex);
        }
    }


and it works ok.
Re: setEditorAreaVisible(false) ignored when switching between perspectives [message #673974 is a reply to message #673836] Wed, 25 May 2011 11:13 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Eric Jain wrote on Tue, 24 May 2011 17:51
If I have two perspectives, one with and one without an editor area (configured with layout.setEditorAreaVisible(b)), and I switch from the one without to the one with the editor area and back, the perspective without the editor area now also shows an editor area.


Does it happen if you switch perspectives via the perspective bar? Either way, it sounds like a bug and I think you should open one: https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform&component=UI

PW


Re: setEditorAreaVisible(false) ignored when switching between perspectives [message #674390 is a reply to message #673974] Thu, 26 May 2011 18:07 Go to previous messageGo to next message
Eric Jain is currently offline Eric Jain
Messages: 266
Registered: July 2009
Senior Member
Paul Webster wrote on Wed, 25 May 2011 07:13
Does it happen if you switch perspectives via the perspective bar?


It happens in a PartListener that switches to an editor-less perspective when the last editor is closed, but also if I switch the perspective through Window > Open Perspective, but then only if there are one or more open editors.

So it looks like the normal perspective switching mechanism won't hide the editor area if one or more editors are open? My current workaround is to register IPerspectiveListeners that call setEditorAreaVisible(b) on perspective activation...

Re: setEditorAreaVisible(false) ignored when switching between perspectives [message #674394 is a reply to message #674390] Thu, 26 May 2011 18:19 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Correct, if there is an editor open we will always show the editor area, even in perspectives that say not to show it. That is done deliberately.

PW


Re: setEditorAreaVisible(false) ignored when switching between perspectives [message #674424 is a reply to message #674394] Thu, 26 May 2011 21:22 Go to previous messageGo to next message
Eric Jain is currently offline Eric Jain
Messages: 266
Registered: July 2009
Senior Member
Paul Webster wrote on Thu, 26 May 2011 14:19
Correct, if there is an editor open we will always show the editor area, even in perspectives that say not to show it. That is done deliberately.


Thanks for clarifying.

I tried closing all open editors when switching to a perspective that doesn't have an editor area, but ran into two problems:

1. Can't get isEditorAreaVisible from an IPerspectiveDescriptor, so I need to maintain a separate list of perspectives that have (or do not have) editor areas.

2. Closing the editors with page.closeAllEditors(true) in IPerspectiveListener.perspectiveActivated(...) appears to be too late to prevent the (now empty) editor area from appearing.

Any ideas?
Re: setEditorAreaVisible(false) ignored when switching between perspectives [message #674565 is a reply to message #674424] Fri, 27 May 2011 11:25 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

We extended IPerspectiveListener after it was released, so new methods went on other intfs. Try org.eclipse.ui.IPerspectiveListener4.perspectivePreDeactivate(IWorkbenchPage, IPerspectiveDescriptor) and see if that helps.

Later,
PW


Re: setEditorAreaVisible(false) ignored when switching between perspectives [message #674649 is a reply to message #674565] Fri, 27 May 2011 17:30 Go to previous message
Eric Jain is currently offline Eric Jain
Messages: 266
Registered: July 2009
Senior Member
Paul Webster wrote on Fri, 27 May 2011 07:25
Try org.eclipse.ui.IPerspectiveListener4.perspectivePreDeactivate(IWorkbenchPage, IPerspectiveDescriptor) and see if that helps.


I might be switching from one perspective with an editor area to another perspective with an editor area, in which case I don't want to close the editors. The perspectivePreDeactivate callback doesn't let me see what perspective I'm switching into, right?

In any case, the workaround with the IPerspectiveListener that calls setEditorAreaVisible(b) seems to work fine; the main ugliness is that there does not appear to be a direct way to check if the editor area should be visible for a given IPerspectiveDescriptor, so I end up having to keep track of that myself.
Previous Topic:update site project does not update artifacts after second build
Next Topic:Legal question on EPL
Goto Forum:
  


Current Time: Wed Oct 22 15:42:32 GMT 2014

Powered by FUDForum. Page generated in 0.06490 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software