Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 174213

Summary: [ViewMgmt] add attribute to close a sticky view in all open perspectives
Product: [Eclipse Project] Platform Reporter: Jamie Liu <liuj1>
Component: UIAssignee: Boris Bokowski <bokowski>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: cbeth, eclipse, emoffatt, Matthew_Hatem, n.a.edgar, pwebster
Version: 3.2.1Keywords: api, helpwanted
Target Milestone: 3.3 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Preliminary patch for those that want to help in testing.
none
Updated patch with preference and unit tests
none
Updated patch to resolve issues that Kim found.
none
New refactored patch, simplifies WorkbenchPage.java
none
New refactored patch, simplifies WorkbenchPage.java
none
Updated patch with new unit tests. none

Description Jamie Liu CLA 2007-02-14 13:55:58 EST
Currently, when you open a sticky view, it remains open when you switch perspectives.  However, when you close a sticky view, it only closes the sticky view in the current active perspective.  Could we add an attribute to the contribution to specify that the sticky view be closed in all other open perspectives?

Use case: Based on usability feedback for our product, users are getting very confused when they see the help view reappear when they change perspectives, after having closed the help view.  They are expecting that when they close it in one perspective, it closes it in all other open perspectives, not just the active perspective.
Comment 1 Jamie Liu CLA 2007-02-14 14:07:05 EST
This issue was mentioned in bug 88568 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=88568) with the original author's Point #6.  However, based on the last comment (#14), it appears to be a feature request as opposed to a defect, therefore creating a separate bugzilla report to track only this issue.
Comment 2 Boris Bokowski CLA 2007-02-14 15:21:34 EST
Sounds like a reasonable request. Unfortunately, we might not have the resources to look into this for 3.3.  Would you be interested in contributing a patch?
Comment 3 Nick Edgar CLA 2007-02-15 11:30:57 EST
I think it's reasonable and expected that if a sticky view is closed, it should be closed in all perspectives in which it was opened due to being a sticky view.
The reason this wasn't done originally is because the implementation was tricky - see 88568 comment 12, not because we thought it wasn't the right behaviour.

If a sticky view S is open in perspective P due to having its own association with the view, then I'm not sure that closing S in perpective Q should affect P.  But maybe that's too complicated a user model.  Something to consider though.
Comment 4 Matthew Hatem CLA 2007-03-13 20:34:57 EDT
Created attachment 60756 [details]
Preliminary patch for those that want to help in testing.

It can't be this easy.  

Ultimately we need to wrap this new behavior with a preference setting.  I'll address that in another patch.  

I haven't completely tested this but, aside from the preference setting, I don't see why this patch wouldn't resolve this bug.  I'm probably missing something.  There might be some hidden gotchas with saveable views.

Can someone review the patch and provide feedback.
Comment 5 Boris Bokowski CLA 2007-03-13 20:59:32 EDT
Kim, prove Matt wrong or you lose two Curries!  ;-)
Comment 6 Matthew Hatem CLA 2007-03-15 10:27:51 EDT
Created attachment 60944 [details]
Updated patch with preference and unit tests

This is a more complete patch with the preference to enable the new behavior.  Naming this preference was tricky.

Before I added the preference one of the intro tests (testPerspectiveChange) was failing, which was expected.  Once the preference was added this test no longer failed.  

I've also added a couple new unit tests to test this new behavior.  I put them in IntroTest.java.  Not sure if this is the right place for them.
Comment 7 Kim Horne CLA 2007-03-15 14:30:18 EDT
Mmmm almost.  :)  

Open clean workspace
Open sticky help view
Open second perspective - note the help view appears
Close help view in second perspective
Switch back to first perspective - help view still visible

I noticed another case I haven't been able to reproduce just yet - in it it I got into the state where I opened a sticky view, changed to a second perspective and saw that the help wasn't visible.  I switched back to the first perspective only to find it wasn't visible there either.

I hadn't thought of this approach Matthew - my attempts were around actually closing a view in a non visible perspective which seemed hopeless.  This seems like it could work with enough poking and prodding... 
Comment 8 Matthew Hatem CLA 2007-03-15 14:34:02 EDT
Kim, I've tried that case it it worked for me.  Are you enabling the preference?
Comment 9 Kim Horne CLA 2007-03-15 14:42:17 EDT
Matt: yep.  It may be more complicated than that.  It seems like resetting the
perspective has a different effect than using the "dirty" one.  I'll poke at it
a bit more.
Comment 10 Matthew Hatem CLA 2007-03-15 14:52:48 EDT
I am seeing some unexpected when running with saved state for the perspectives.  Seems that the activatedSticky list isn't the same in that case.
Comment 11 Boris Bokowski CLA 2007-03-15 14:54:57 EDT
Btw, the preference should work the other way (if you can get this to work): The fixed behaviour should be the default, with a way to turn it off if people relied on the old behaviour. 
Comment 12 Matthew Hatem CLA 2007-03-15 14:56:27 EDT
One problem might be that we never remove a view from the activatedStickyViews list.
Comment 13 Matthew Hatem CLA 2007-03-15 15:07:53 EDT
I think that's it.  Since the new behavior is that the visibility of the sticky view is consistent across perspectives, then the active sticky view list needs to be cleaned up when a view is closed via hideView().  Attaching and updated patch based on HEAD.
Comment 14 Matthew Hatem CLA 2007-03-15 15:08:33 EDT
Created attachment 61000 [details]
Updated patch to resolve issues that Kim found.
Comment 15 Matthew Hatem CLA 2007-03-16 09:24:50 EDT
Created attachment 61085 [details]
New refactored patch, simplifies WorkbenchPage.java

After looking at this some more I've realized that with the new close behavior we really don't need to keep track of activated sticky views for each perspective.  Instead we simply need to ensure that the visibility of sticky views is consistent  when we switch perspectives.  

In an effort to simplify the WorkbenchPage class I've refactored things a bit.  I've moved all of the sticky view handling to a new class and created two classes one for the old 3.2 behavior that still uses a map and tracks the activated views, saves state etc.  The class responsible for the new behavior is much more simple.

I've also updated the preference and the preference initialization to reflect Boris' comments in comment #11.
Comment 16 Matthew Hatem CLA 2007-03-16 09:35:44 EDT
Created attachment 61089 [details]
New refactored patch, simplifies WorkbenchPage.java

Sorry, previous patch had a line of debug code in it.  This one is clean.
Comment 17 Kim Horne CLA 2007-03-16 12:12:00 EDT
The patch appears to work and is easy to understand but I'm getting three test failures - testPerspectiveChange, testPerspectiveChangeWithCloseAllPrefTrue, and testPerspectiveChangeWithCloseAllPrefFalse.  There may be more but I haven't ran the full suite, only IntroTests
Comment 18 Matthew Hatem CLA 2007-03-16 16:28:09 EDT
testPerspectiveChange is expected to fail now that the new behavior is turned on by default.

The other two tests testPerspectiveChangeWithCloseAllPrefTrue,
and testPerspectiveChangeWithCloseAllPrefFalse are the ones that I added.  Not sure why those are failing, probably the same reason as the first.

I'll update the patch.
Comment 19 Mike Wilson CLA 2007-03-16 17:02:44 EDT
+1
Comment 20 Matthew Hatem CLA 2007-03-16 17:04:06 EDT
Created attachment 61168 [details]
Updated patch with new unit tests.

I've updated the unit tests to reflect the fact that the new behavior is now enabled by default.  Also the previous tests assumed the preference was dynamic, which is no longer the case.
Comment 21 Boris Bokowski CLA 2007-03-16 17:04:24 EDT
(In reply to comment #19)
> +1

I just talked to McQ, he gave the +1 for adding the preference.
Comment 22 Boris Bokowski CLA 2007-03-19 16:59:00 EDT
Released with a small fix (NPE when running the tests).  Thanks for your patch, Matt!
Comment 23 Matthew Hatem CLA 2007-03-19 20:08:41 EDT
Thanks Boris.  Can you tell me where the NPE was?  I'd like to adapt this patch to 3.2.2.

Comment 24 Boris Bokowski CLA 2007-03-19 20:48:22 EDT
The NPE happened when one of the perspectives was null - this happens e.g. when you close all perspectives and then open a new one. I added a null check at the beginning of update():
if (newPersp == null || oldPersp == null) {
  return;
}
Comment 25 Kim Horne CLA 2007-03-23 09:02:24 EDT
Verified in I20070322-1800.  Thanks Matt!  I owe you curry next time you're in town.  :)