Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Deferred content provider
Deferred content provider [message #897599] Tue, 24 July 2012 16:31 Go to next message
Fabio Mancinelli is currently offline Fabio MancinelliFriend
Messages: 16
Registered: July 2009
Junior Member
Hi everybody,

I have a weird problem with a deferred content provider and a TreeViewer.

I use it in order to lazily retrieve data from a remote server.
Globally it works quite well but sometimes when I expand a node it
returns to its not-expanded state just after removing the "Pending..."
placeholder.

I have to re-expand it to actually see the content (sometimes repeatedly)

I have put some println in the IElementCollector I use for collecting
items and they are retrieved correctly but, as I said before, sometimes
they are not displayed.

Has anyone ever had this problem?

Thanks for your help,
Fabio
Re: Deferred content provider [message #897610 is a reply to message #897599] Tue, 24 July 2012 17:57 Go to previous messageGo to next message
Fabio Mancinelli is currently offline Fabio MancinelliFriend
Messages: 16
Registered: July 2009
Junior Member
On 07/24/2012 06:31 PM, Fabio Mancinelli wrote:
> Hi everybody,
>
> I have a weird problem with a deferred content provider and a TreeViewer.
>
> I use it in order to lazily retrieve data from a remote server.
> Globally it works quite well but sometimes when I expand a node it
> returns to its not-expanded state just after removing the "Pending..."
> placeholder.
>
> I have to re-expand it to actually see the content (sometimes repeatedly)
>
> I have put some println in the IElementCollector I use for collecting
> items and they are retrieved correctly but, as I said before, sometimes
> they are not displayed.
>
> Has anyone ever had this problem?
>
> Thanks for your help,
> Fabio

I reply to myself because I think I have found a possible clue to spot
the problem.

By putting a Thread.sleep(100) in the element collector, the problem
seems to disappear (i.e., nodes with children correctly show them the
first time they are expanded)

I think there is some race-condition somewhere (maybe with Jobs that
handle the placeholder removal)

I am not doing anything particular so I really don't know how to proceed.

Any help/idea is very appreciated.

Thanks,
Fabio
Re: Deferred content provider [message #897615 is a reply to message #897610] Tue, 24 July 2012 18:39 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi, where exactly do you have to put the Thread.sleep?
Re: Deferred content provider [message #897618 is a reply to message #897615] Tue, 24 July 2012 18:49 Go to previous messageGo to next message
Fabio Mancinelli is currently offline Fabio MancinelliFriend
Messages: 16
Registered: July 2009
Junior Member
On 07/24/2012 08:39 PM, Jan Krakora wrote:
> Hi, where exactly do you have to put the Thread.sleep?

I've put it in the

public void add(Object[] elements, IProgressMonitor monitor)

of my implementation of a IElementCollector interface, which I use to
filter out some elements if they don't belong to a working set.

I call this method in fetchDeferredChildren of my deferred content
provider as soon as elements are retrieved remotely.

-Fabio
Re: Deferred content provider [message #897742 is a reply to message #897618] Wed, 25 July 2012 07:58 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Could you post here your IElementCollector implementation and the content of the fetchDeferredChildren method?
Re: Deferred content provider [message #897750 is a reply to message #897742] Wed, 25 July 2012 08:14 Go to previous messageGo to next message
Fabio Mancinelli is currently offline Fabio MancinelliFriend
Messages: 16
Registered: July 2009
Junior Member
On 07/25/2012 09:58 AM, Jan Krakora wrote:
> Could you post here your IElementCollector implementation and the
> content of the fetchDeferredChildren method?

Sure.

Here it is my fetchDeferredChildren method:

public void fetchDeferredChildren(Object object, IElementCollector
collector, IProgressMonitor monitor) {
collector.add(getChildren(object), monitor);
collector.done();
}

getChildren does the heavy work and when it's done it returns the array
with the retrieved objects.

And this is the class that wraps the standard deferred content manager
in order to use an element collector that filters things wrt the
selected working set.

public class WorkingSetDeferredTreeContentManager extends
DeferredTreeContentManager
{
private IWorkingSet workingSet;

private static class WorkingSetElementCollectorFilter implements
IElementCollector
{
private IWorkingSet workingSet;

private IElementCollector elementCollector;

public WorkingSetElementCollectorFilter(IWorkingSet workingSet,
IElementCollector elementCollector)
{
this.workingSet = workingSet;
this.elementCollector = elementCollector;
}

public void add(Object element, IProgressMonitor monitor)
{
if (workingSet != null) {
if (UIUtils.isInWorkingSet(element, workingSet)) {
elementCollector.add(element, monitor);
}
} else {
elementCollector.add(element, monitor);
}
}

public void add(Object[] elements, IProgressMonitor monitor)
{
Object[] filteredObjects = null;

if (workingSet != null) {
filteredObjects = UIUtils.filterByWorkingSet(elements,
workingSet);
} else {
filteredObjects = elements;
}

elementCollector.add(filteredObjects, monitor);

try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}

public void done()
{
elementCollector.done();
}

}

public WorkingSetDeferredTreeContentManager(AbstractTreeViewer
viewer, IWorkingSet workingSet)
{
super(null, viewer);
this.workingSet = workingSet;
}

@Override
protected IElementCollector createElementCollector(Object parent,
PendingUpdateAdapter placeholder)
{
IElementCollector elementCollector =
super.createElementCollector(parent, placeholder);
return new WorkingSetElementCollectorFilter(workingSet,
elementCollector);
}

}

-Fabio
Re: Deferred content provider [message #897795 is a reply to message #897750] Wed, 25 July 2012 09:13 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Oh man, put it in code format, this is terrible Razz
Re: Deferred content provider [message #897813 is a reply to message #897795] Wed, 25 July 2012 09:34 Go to previous messageGo to next message
Fabio Mancinelli is currently offline Fabio MancinelliFriend
Messages: 16
Registered: July 2009
Junior Member
On 07/25/2012 11:13 AM, Jan Krakora wrote:
> Oh man, put it in code format, this is terrible :p

Right :) Sorry for that.

Here it is: http://pastebin.com/tbe8RY7b

-Fabio
Re: Deferred content provider [message #897888 is a reply to message #897813] Wed, 25 July 2012 11:25 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
You can format the code right here in the forum (check the formatting tools above the text field which you're writing the message in).

Anyway, I can't see any error here. Are you sure the UIUtils.filterByWorkingSet(elements, workingSet) return something?
Re: Deferred content provider [message #898407 is a reply to message #897888] Thu, 26 July 2012 10:44 Go to previous messageGo to next message
Fabio Mancinelli is currently offline Fabio MancinelliFriend
Messages: 16
Registered: July 2009
Junior Member
On 07/25/2012 01:25 PM, Jan Krakora wrote:
> You can format the code right here in the forum (check the formatting
> tools above the text field which you're writing the message in).
>
Ehm... I use Thunderbird for reading this NG :)


> Anyway, I can't see any error here. Are you sure the
> UIUtils.filterByWorkingSet(elements, workingSet) return something?

Yes. I put a System.out just before doing elementCollector.add() and
what happens is the following:

1) Expand node x
2) I see in output console "Added 13 elements"
3) Node x is collapsed immediately.
4) Goto 1, eventually Node x won't be collapsed and the viewer will
correctly display the 13 elements.

I really think it's a race condition. But I don't know how to proceed to
debug it.

-Fabio
Re: Deferred content provider [message #898429 is a reply to message #898407] Thu, 26 July 2012 11:32 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I would try to debug the WorkbenchJob in the DeferredTreeContentManager at the line 353. This should call your label provider.
Re: Deferred content provider [message #898436 is a reply to message #898429] Thu, 26 July 2012 11:38 Go to previous message
Fabio Mancinelli is currently offline Fabio MancinelliFriend
Messages: 16
Registered: July 2009
Junior Member
On 07/26/2012 01:32 PM, Jan Krakora wrote:
> I would try to debug the WorkbenchJob in the DeferredTreeContentManager
> at the line 353. This should call your label provider.

Thanks for the hint... I will look into this.

-Fabio
Previous Topic:Getting IValueProperty of a certain value in a MAP
Next Topic:New TreeItem is not updating in UI
Goto Forum:
  


Current Time: Tue Mar 19 02:17:22 GMT 2024

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

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

Back to the top