|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Child rows in TreeListHi,
I'm trying to add child rows to a treelist. Through which mechanism would I be able to do this? Following the TreeListExample Ken posted up. Adding to the table is done via the TreeFormat.getPath() method, i.e. private static class SimpleBeanTreeFormat implements TreeList.Format<SimpleBean> { public void getPath(List<SimpleBean> path, SimpleBean element) { path.add(new FakeSimpleBean(element.getAssociatedFile())); path.add(element); } public boolean allowsChildren(SimpleBean element) { return element instanceof FakeSimpleBean; } public Comparator<? extends SimpleBean> getComparator(int i) { return GlazedLists.comparableComparator(); } } The above snippet will an element as a child to the new FakeSimpleBean instance. However how am I to add another child to the same FakeSimpleBean instance? Cheers! |
|
|
Re: Child rows in TreeListdingwa wrote:
> Hi, > > I'm trying to add child rows to a treelist. Through which mechanism would I > be able to do this? Adding child rows to a treelist is done through the flat, basic eventlist that was initially used to create the treelist. When you add an element to the basic event list, it will notify treelist that an element was added and treelist will transform that element to have hierarchy information. > Following the TreeListExample Ken posted up. Adding to > the table is done via the TreeFormat.getPath() TreeFormat.getPath() is not the place for adding child rows to the synthetic/fake parent elements. It defines the tree structure and relationship for a single element in your basic event list to one (or more) FakeSimpleBean parents which make up the hierarchy for that single element. > However how am I to add another child to the same FakeSimpleBean > instance? > > You don't have to worry about adding items to FakeSimpleBean. When you add an element to the basic event list, a new instance of FakeSimpleBean will be created to represent the tree structure for that added element. Treelist will then compact all the instances of FakeSimpleBean to provide a single parent node which will contain all the child rows associated with that parent. Hope that helps. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: Child rows in TreeListBrian's right...there's a little bit of a mental shift when working with TreeList. It's not like TreeModel where you add children to nodes - it's more like you specify the rule for determining the hierarchy (that's the getPath method) and the rest just works! When you add items to your list, GL will revaluate the hierarchy and update the tree as necessary.
As Brian mentioned, as long as you make sure your adding elements under the correct parent in the path, GL will take care of coalescing those individual paths such that all children parented to an element will show up under that node in the tree. So if you had three elements in your list, you'd receive three calls to getPath where you would do the following: Do this each call: path.add(new FakeElement(element.getCategory())); path.add(element); Which might end up looking like this: * Car - Porsche Boxster - Infiniti G35 * Truck - Ford F-150 Does that help? -Ken
|
| Free Forum Powered by Nabble | Forum Help |