Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » GlazedList.clear() throws java.lang.IndexOutOfBoundsException
GlazedList.clear() throws java.lang.IndexOutOfBoundsException [message #1422177] Fri, 12 September 2014 12:43 Go to next message
Vincent Lorenzo is currently offline Vincent LorenzoFriend
Messages: 248
Registered: June 2010
Location: Paris Saclay, France
Senior Member
Hello everybody,
This is a message about GlazedList (not really about NatTable), but I hope than someone will have an answer for my problem.

I have a problem with the method clear() on TreeList. This method throws a
java.lang.IndexOutOfBoundsException.

I provide an example in the attached file to reproduce the bug.
Moreover, in this example, I do
treeList.getReadWriteLock().writeLock().lock();			
boolean answer = treeList.add(Integer.valueOf(0));
//answer is true
answer =treeList.add(Integer.valueOf(1));
//answer is false
treeList.getReadWriteLock().writeLock().unlock();


The second add seems not work (
anwser==false
). Maybe my problem comes from this actions, but I would like to get some help on this subject.

Thank you.

I posted the same topic herehttp://glazedlists.1045722.n5.nabble.com/TreeList-clear-generates-a-java-lang-IndexOutOfBoundsException-Cannot-remove-at-1-on-list-of-size-td5710154.html
Re: GlazedList.clear() throws java.lang.IndexOutOfBoundsException [message #1423297 is a reply to message #1422177] Sun, 14 September 2014 07:00 Go to previous messageGo to next message
Arye Shemesh is currently offline Arye ShemeshFriend
Messages: 37
Registered: November 2012
Member
Hi Vincent,

This happens because TreeList has a more complex representation of the tree. It can use virtual nodes for ancestors in the tree.
When you called treeList.clear(), it removed the first node. However, because the second node is a child of the first node, and it cannot be seen without it, it created a virtual node to replace the first node. It then tried to remove the virtual node and failed.

(More on TreeList inner representation can be found here (although it was updated since) : http://publicobject.com/glazedlists/documentation/TreeList_and_Barcode.pdf)

Generally, it is more complicated to add/remove objects directly with tree list.

There are 2 solutions:
1. You can alter the underlying source list. Calling source.clear() can do the job.
2. You can delete the nodes from child to parent, making sure that the parent is expanded so that the child will be visible.
In your example, calling treeList.remove(1) and then treeList.remove(0) does it.


Hope it helps.
Re: GlazedList.clear() throws java.lang.IndexOutOfBoundsException [message #1424909 is a reply to message #1423297] Tue, 16 September 2014 15:39 Go to previous messageGo to next message
Vincent Lorenzo is currently offline Vincent LorenzoFriend
Messages: 248
Registered: June 2010
Location: Paris Saclay, France
Senior Member
Hi Arye,
thank you for your answer, it resolved my problem. I have an other question.

I would like to be able to remove a node and with its children, from the list, without knowing the children. Is it possible? How to proceed?
Re: GlazedList.clear() throws java.lang.IndexOutOfBoundsException [message #1425049 is a reply to message #1424909] Tue, 16 September 2014 19:59 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
You could use the ITreeRowModel to retrieve the child indexes. Then either remove the elements step by step by going backwards through the list of indexes to remove, or collect all corresponding objects and removeAll()
Previous Topic:Autoscroll during Drag&Drop?
Next Topic:GlazedLists FIlter Strategy for Custom Object
Goto Forum:
  


Current Time: Tue Apr 23 16:49:32 GMT 2024

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

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

Back to the top