Bug 54559 - [ViewMgmt] No part closed notification when view shared across perspectives
Summary: [ViewMgmt] No part closed notification when view shared across perspectives
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 50171 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-03-11 18:20 EST by Jared Burns CLA
Modified: 2009-08-30 02:15 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jared Burns CLA 2004-03-11 18:20:53 EST
I checked out org.eclipse.jface, org.eclipse.ui, and org.eclipse.ui.workbench from HEAD in order 
to pick up a new API that was added to the workbench. But in my testing, I'm not getting any
partClosed() notifications.

By debugging, I've verified that my part listener is being registered with the active workbench 
page. I've got an existing bug report open for the fact that *some* part notifications haven't been 
getting sent (bug 50171), but now I'm not getting any.
Comment 1 Nick Edgar CLA 2004-03-12 01:05:31 EST
Nick Edgar wrote:
It's not a bug.  It's just that the part is hidden - it hasn't been
closed, so there wouldn't be any close notification.

Jared replied:
"Hidden" in the API means "obscured". partHidden() notifications are sent 
whenever a view is covered by another view.

If closing a part doesn't send a partClosed() notification, what notification 
is sent?

Nick responds:
OK, so "hidden" wasn't quite the correct term.  Hidden/visible notifications 
are intended to handle obscuring, as you describe, not view open/close.
For further terminological confusion, note the IWorkbenchPage.hideView() is 
equivalent to manually closing it.  It is, however, symmetrical with showView
(), both in name and function.

The semantics of partClosed have been complicated by the sharing of views 
across perspectives (introduced in Eclipse 2.0).  Note that IPartListener[2] is 
registered on IPartService via IWorkbenchPage, not the perspective.  So it 
currently only notifies when the part has been closed from all perspectives in 
the page.  That is, you'll only get a partClosed() notification when the part 
itself is being disposed.  

There are no notifications currently to say "this part has been closed in this 
perspective" or "this part has been closed in the active perspective".

It's too risky to change the behaviour of partClosed() now.  Existing listeners 
may care more about the lifecycle of the part itself rather than whether it's 
open in the current perspective.

We may be able to add new lifecycle methods, e.g. partClosed
(IPerspectiveDescriptor, IWorkbenchPartReference) or 
partClosedInCurrentPerspective(IWorkbenchPartReference).

Unfortunately, it would be very difficult to make this happen 3.0 at this point 
though.

It would help to know a bit more about what you're trying to do and what you 
really need to know.  

You might be able to get by for now with tracking partHidden, then seeing if 
the view is still there using IWorkbenchPage.findViewReference(String).
Note that this -does- limit itself to the current perspective.
And, yes, I acknowledge that this is inconsistent with the notifications.

Just for the record, here are the notifications you currently get when closing 
a Navigator that is shared between the Java and Resource perspectives.  It's 
being closed from the Java perspective.
Clearly there are some inefficiencies here.  The Hierarchy should not be 
getting materialized and the TextEditor should not be getting activated.

partDeactivated(Navigator)
partActivated(TextEditor)
partHidden(Navigator)
partOpened(Hierarchy)
partVisible(Hierarchy)
partHidden(Hierarchy)
partDeactivated(TextEditor)
partActivated(PackageExplorer)

And here are the notifications you currently get when you close the last 
occurrence of it from the Resource perspective:
partDeactivated(Navigator)
partActivated(TextEditor)
partHidden(Navigator)
partClosed(Navigator)

Comment 2 Jared Burns CLA 2004-03-12 11:49:34 EST
My concern here stems from our automatic view opening/closing in the Debug 
perspective. I register a listener for partClosed/partOpened because I want to 
know when the user closes or opens a view. The reason being that once the user's 
manually closed/opened a "managed" view, we won't open/close that view again.

If we can't accurately track this, it means that the user will end up wrestling 
with the debugger. There might be some other way for us to manage this, but 
nothing's come to mind yet. DarinW may disagree, but if we can't prevent the 
feature from overriding the user's choices, I'd consider our context management 
story unshippable.
Comment 3 Nick Edgar CLA 2004-03-12 11:59:11 EST
Can youi try hooking partHidden and testing whether it's still in the 
perspective via findView?
Comment 4 Jared Burns CLA 2004-03-12 12:01:50 EST
The JavaDoc on IPartListener(2) should really be beefed up to explain when the 
various notifications are sent. I never would have guessed that the listeners 
behave the way they do by reading the doc.

I poked around a bit, though, and it looks like IPerspectiveListeners are sent a 
partHidden notification when a view is closed (but not when they're "hidden"). 
The fact that partHidden notifications aren't sent when views are hidden is 
probably a bug, but in this case it works to our advantage. To make these 
notifications consistent with the part notifications, I'd suggest that 
partHidden should be sent when a view is obscured and a new event, partClosed, 
should be sent when a part is closed within a perspective.
Comment 5 Jared Burns CLA 2004-03-12 12:05:29 EST
Not sure I was clear in my last paragraph (I should really proof-read my 
comments *before* I submit them :)  ). CHANGE_VIEW_HIDE perspective events are 
currently fired at the "right time" for our purposes. But for consistency in the 
API's terminology, I'd suggest making CHANGE_VIEW_HIDE be sent when views are 
"obscured" and adding a new CHANGE_VIEW_CLOSED event that is sent when a view is 
closed within a perspective.
Comment 6 Nick Edgar CLA 2004-03-12 12:44:29 EST
You'd probably also want to be told -which- part too.
Comment 7 Jared Burns CLA 2004-03-12 13:07:12 EST
Whoops! Scratch the perspective listener idea, then. Your suggestion about 
listening to partHidden notifications and using findView should work.
Comment 8 Jared Burns CLA 2004-03-12 17:18:19 EST
It looks like partOpen notifications aren't sent when you open a part either (if it's open elsewhere). 
:( Is there a similar workaround I'm not thinking of?

Do you think there's any chance of adding a new listener for 3.0? Not a breaking API change, but 
an addition. Something like IPerspectiveListener2, which adds the part notifications?
Comment 9 Nick Edgar CLA 2004-03-14 17:12:55 EST
Can you use IPartListener2.partVisible then check if it's newly opened using 
page.findView?  You'd have to check findView before registering the listener to 
detect whether it was initially opened or closed in the perspective.

If these workarounds don't work for you, we can look add adding new API early 
in M9.
Comment 10 Nick Edgar CLA 2004-03-31 09:32:52 EST
*** Bug 50171 has been marked as a duplicate of this bug. ***
Comment 11 Nick Edgar CLA 2004-03-31 09:33:10 EST
Jared, please let us know whether any action is needed here.
Comment 12 Jared Burns CLA 2004-03-31 13:00:35 EST
Well, we need to know when views are opened and closed in the intuitive sense, 
not just the first time a view is opened in a window or the last time it's 
closed.

Your workarounds might work (though I suspect that the partOpen workaround would 
be buggy), but I really feel that the workbench should be sending notifications 
in this case. It doesn't seem right that clients should have to keep track of 
the views themselves in order to figure out when they're being opened and 
closed. The workbench should take care of that for us.
Comment 13 Nick Edgar CLA 2004-04-01 16:14:51 EST
Will investigate for M9.
Comment 14 Jared Burns CLA 2004-04-20 16:54:16 EDT
It looks like the unspec'ed behavior of IWorkbenchPage#findView has changed such that the 
workaround we're using for partClosed() is no longer working. As suggested, we're currently 
listening to partHidden() and then calling findView() to see if the view has actually been closed. 
IWorkbenchPage#findView() used to return null if the view wasn't open in the current perspective.

But now I get a non-null value when I call findView(...) in the viewHidden() callback when a view 
is "closed" (really closed, not just closed for the last time). This workaround failure was reported 
as Bug 58591 in the debugger.
Comment 15 Jared Burns CLA 2004-04-20 16:55:40 EDT
*** Bug 58591 has been marked as a duplicate of this bug. ***
Comment 16 Jared Burns CLA 2004-04-26 17:55:16 EDT
I've filed Bug 60039 to track the failure of the workaround. This new bug is a major problem for the 
debugger.
Comment 17 Nick Edgar CLA 2004-04-28 14:09:57 EDT
While looking at bug 60039 (fixed), I noticed that LaunchViewContextListener
often calls getActiveWorkbenchWindow and getActivePage.  I'm not sure exactly
what this class does, but it seems to me that if the intent is to track
visibility of other views in the same perspective as the Launch view, then it
should just use the Launch view's page.  I did encounter one instance where it
appeared to get confused by me having two windows open (it was talking to a
different window than the one containing its Launch view).

In Eclipse >= 2.0, there is only ever one page per window, but the page may
contain multiple perspectives.

Can the calls to getActiveWorkbenchWindow and getActivePage() be eliminated?
Comment 18 Jared Burns CLA 2004-04-28 16:51:55 EDT
Good question. I filed bug 60327 against Platform-Debug to look into this 
problem.
Comment 19 Nick Edgar CLA 2004-05-04 22:08:55 EDT
Sorry, we'll have to live with the workarounds for 3.0.
Will consider new lifecycle API for 3.1.
Comment 20 Denis Roy CLA 2009-08-30 02:15:24 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.