Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » TableViewer with ILazyContentProvider does not remove elements
TableViewer with ILazyContentProvider does not remove elements [message #1406227] Sat, 09 August 2014 11:34 Go to next message
Demian Tols is currently offline Demian TolsFriend
Messages: 3
Registered: August 2014
Junior Member
I have a TableViewer that uses SWT.VIRTUAL flag and my own simple ILazyContentProvider implementation.

So, during scrolling, a can load some more elements (kind of infinite scrolling) like this:

	final List<PropertirizedLong> loadedlist = config.getLoader().load(config, 70);
	kList.addAll((Collection<? extends PropertirizedLong>) loadedlist);

	//tv.setItemCount(kList.size());  //I made this earlier

	for (int i = 0; i < loadedlist.size(); i++) {
		tv.add(config.getMainTable().get(loadedlist.get(i).get()));
	}


	Assert.isTrue(tv.getTable().getItemCount() == kList.size());
	notBusy.set(true);


As you can see at first I was just setting an item count because content provider on the moment of load didn't ask for those indexes yet. But then juast to be sure a made an exact add call. Also I tried to call all this code on a separate thread with an asynExec thing - scrolling became smoother but the application still crashes.


Also insome cases I call a function that removes entries considered by me in my own way as expired. I have a code something like this:

    long now = System.nanoTime();

    ArrayList<PropertirizedLong> keyList = new ArrayList<>();
    ArrayList<Entity> valueList = new ArrayList<>();

    for (int i = 0; i < tickedOnTop; i++) {
        PropertirizedLong key = kList.get(i);
        long hidingTime = key.hidingTime;

        if(hidingTime > 0L && (now - hidingTime) > nanoCleanTime ){
            Entity ent = config.getMainTable().get(key.get());

            keyList.add(key);
            valueList.add(ent);
        }
    }

    Assert.isTrue(keyList.size() == valueList.size());

    if(keyList.size() != 0){
        tv.remove(valueList.toArray());
        kList.removeAll(keyList);
    }


That removes an entry from TableViewer and then from the model which is a list of keys to some map. The problem is that after some scrolls back and forth the getItemCount of TableViewer and a model-list becomes different. It becomes more in TableViewer then in the list, so when TV calls index from list that is bigger then list size it crashes. I also tried to do it on a separate thread - still crashes.

I went through the code of TableViewer in a debug mode and found out that during remove call it DOES NOT find a widget associated with an element, so it does not do any removals.

Also this doesn't happen every time. I can scroll from up and down ten or thousand times and everything works fine and then it just becomes wrong and crashes.

If you need the stacktrace:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 105, Size: 105
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at com.t.tableviewers.ConsistenedLazyProviderListener.updateElement(ConsistenedLazyProviderListener.java:64)
at org.eclipse.jface.viewers.AbstractTableViewer$1.handleEvent(AbstractTableViewer.java:87)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4166)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1466)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1489)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1474)
at org.eclipse.swt.widgets.Table.checkData(Table.java:274)
at org.eclipse.swt.widgets.Table.tableView_objectValueForTableColumn_row(Table.java:3207)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:5856)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
at org.eclipse.swt.widgets.Widget.drawRect(Widget.java:742)
at org.eclipse.swt.widgets.Table.drawRect(Table.java:1172)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:5534)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
at org.eclipse.swt.widgets.Display.applicationNextEventMatchingMask(Display.java:4918)
at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5296)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
at org.eclipse.swt.internal.cocoa.NSApplication.nextEventMatchingMask(NSApplication.java:94)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3645)
at com.t.Main.main(Main.java:50)


Also I have my output that says:

TV Item Count:139
kList size:105

So, contentProvider wants the 105th (as in stacktrace) but there is no one left.

What's wrong and how can I fix it? I tried a lot of stuff before asking a question here.
Re: TableViewer with ILazyContentProvider does not remove elements [message #1406600 is a reply to message #1406227] Sun, 10 August 2014 15:03 Go to previous messageGo to next message
Demian Tols is currently offline Demian TolsFriend
Messages: 3
Registered: August 2014
Junior Member
I have simplimized my project to a one file so you can try it.

It becomes adding and removing after the 100 index everytime index is changing. Also, the listener handles a mouse wheel scrolling and page up/downs on some platforms.

I got this bug on Mac OS and Ubuntu already.

Is this some known bug or I should bugreport it?
  • Attachment: BugTest.java
    (Size: 2.94KB, Downloaded 366 times)
Re: TableViewer with ILazyContentProvider does not remove elements [message #1406699 is a reply to message #1406600] Sun, 10 August 2014 22:21 Go to previous message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
Moving this to the JFace forum.
Previous Topic:Filter ComboBox content prior to its expansion
Next Topic:creating JSF application in Eclipse, putting jar files in WEB-INF
Goto Forum:
  


Current Time: Thu Apr 25 19:02:46 GMT 2024

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

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

Back to the top