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

Bug 215734

Summary: [Progress] Need way to listen to when DeferredTreeContentManager is finished
Product: [Eclipse Project] Platform Reporter: Brian Bauman <baumanbr>
Component: UIAssignee: Tod Creasey <Tod_Creasey>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: lesojones, remy.suen, tom.schindl
Version: 3.4   
Target Milestone: 3.4 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 191365    
Attachments:
Description Flags
proposed patch
none
Suggested API none

Description Brian Bauman CLA 2008-01-17 19:17:16 EST
In PDE, we are trying to initialize the Plug-ins view using DeferredTreeContentManager.  I am currently running into a few problems.  

The first is that since we have a count and I don't know when the content manager has removed the place holder, I have to hack up some code to analyze the last element in the tree to see if it is the place holder.  If I could some how listen to the place holder's removal, I could them update the count when this even occurs.

The second is that for a long list, the removal of the placeholder sets the visibility of the list to the bottom.  In a perfect world, I would love to see a call to reset the scrollbar to the top like it would normally be initialized.  But, if I could listen to the removal of the place holder, I could manually reset the scrollbar.

I have thought of different ways to solve this problem.  One way would be to allow users to add a job change listener which would be added to both jobs.  The less invasive way would be to create a protected function called "getClearPlaceHolderJob(PendingUpdateAdapter)" or something like that.  This would allow me to extend the DeferredTreeContentManager class and add my own IJobChangeListener to the removal job when it is created.

If there is anything I can do to help, please let me know.
Comment 1 Tod Creasey CLA 2008-01-18 15:28:14 EST
Don't you control the contents though?Why don't you know when you are done?
Comment 2 Brian Bauman CLA 2008-01-18 16:23:05 EST
The DeferredTreeContentManager adds a PendingUpdateAdapter object to the tree as a place holder.  It then runs a job to do the searching for children which is where our code adds children to the Tree (by calling the anonymous IElementCollector.add(..) class in DeferredTreeContentManager).  

At this point, I have added all the children I need to and I am done populating the tree so my code returns.  This more or less finishes the Job which was created to populate the contents in the background.  

The PendingUpdateAdapter object is still in the tree, so another Job is run to remove it (see DeferredTreeContentManager.runClearPlaceholderJob(...)).  This job modifies the tree by removing the PendingAdapter which is really the event I need to listen to (so I can accurate get the element count from the Tree and reset the scrollbar to the top of the Tree).

So I know when I am done populating the Tree, but DeferredTreeContentManager still has some clean up to do and I can't tell when that has been completed.

Hope that makes sense :)
Comment 3 Tod Creasey CLA 2008-01-21 09:05:59 EST
Doesn't your model have the accurate count from the job you used to populate it? Do you not have access to the data from that job?

Relying on the tree contents is always dangerous as we optimize population of the tree so it is never as reliable as your model.
Comment 4 Brian Bauman CLA 2008-01-21 10:17:43 EST
We have a total count from our models, but the view uses filters and the count is updated based on how many items are visible.  So for this we use the count of the tree, which has not had us go wrong sense.

Just for the record, I was able to get the count working with some type checking in the tree (mainly seeing if the last element was a PendingUpdateAdapter).  The part I can't solve it trying to reset the scroll bar to the top of the list when everything is finished.  I figured if there was this notification, I could do that and update the count at the same time, killing two birds with one stone.  If the platform could manually reset the focus of the tree to the top of the list after removing the PendingUpdateAdapter, I would be fine with that also.
Comment 5 Tod Creasey CLA 2008-01-22 07:57:07 EST
Brian having a model that is unaware of what it is showing is pretty dangerous. I think you are going to get bitten by a viewer optimization at some point.

I think the listener is the best choice because it is the least invasive solution. If you propose a patch I can look at it.
Comment 6 Les Jones CLA 2008-01-22 08:44:59 EST
Tom, I may be misunderstanding you, but your last comment seemed to imply that the model should become viewer aware?
Comment 7 Les Jones CLA 2008-01-22 09:28:04 EST
Grovelling apologies Tod, I called you Tom. Sorry.
Comment 8 Tod Creasey CLA 2008-01-22 09:38:16 EST
Quite the opposite Les - I am concerned that Brian is relying on the viewer rather than his model to understand what is being shown.
Comment 9 Les Jones CLA 2008-01-22 10:00:33 EST
Tod, if I understand Brian correctly, he's showing the number of items visible in the tree, which can be controlled via ViewerFilter instances - these are inherently viewer specific and the model knows nothing of these. When a new filter is applied, the tree viewer will (potentially) show a different subset of elements; again the model is unaware of this. 

Without querying the viewer itself (or in this case viewer.getTree().getItemCount()) to get the number of visible items, how would you get this information?
Comment 10 Brian Bauman CLA 2008-01-31 01:46:18 EST
Created attachment 88373 [details]
proposed patch

This is the simplest modification which allows me to add the listener I need.  It should be pretty simple as all I did was refactor out the creation of the "clearJob" into a protected function responsible for creating the job.
Comment 11 Tod Creasey CLA 2008-01-31 15:43:07 EST
Created attachment 88456 [details]
Suggested API

He is my proposal - add an listener for the update job and I will apply it when the clear job is created.
Comment 12 Brian Bauman CLA 2008-01-31 15:59:03 EST
> Here is my proposal - add an listener for the update job and I will apply it when
> the clear job is created.

That looks great!  That will give us everything we will need.  Thanks for looking into this Tod.

Comment 13 Tod Creasey CLA 2008-01-31 16:26:38 EST
Patch released for build >20080131-0800
Comment 14 Tod Creasey CLA 2008-02-06 10:41:48 EST
Brian can you verify this please?
Comment 15 Brian Bauman CLA 2008-02-06 11:01:12 EST
Verified on I20080204-0800.

Thanks Tod for working with me to get this in for the milestone.  The Plug-ins view is working great with the loading in the background!