TableViewer with ILazyContentProvider does not remove elements [message #1406227] |
Sat, 09 August 2014 07:34  |
Eclipse User |
|
|
|
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.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04662 seconds