Tree Collapse All/Expand All?

81 views
Skip to first unread message

r...@akelex.com

unread,
Feb 20, 2014, 7:33:23 PM2/20/14
to codenameone...@googlegroups.com
I'm using a subclass of com.codename1.ui.tree.Tree in an application and it's working fine.  I'd like to add a control to collapse the tree (i.e., collapse all expanded nodes), and can't find a way to do that.  Is there a way?  Similarly, I'd like to be able to force all nodes to expand.

Shai Almog

unread,
Feb 21, 2014, 2:25:57 AM2/21/14
to codenameone...@googlegroups.com, r...@akelex.com
Yes,
there are new methods in tree specifically collapsePath(Object... path) and expandPath(Object... path)

r...@akelex.com

unread,
Feb 21, 2014, 12:27:24 PM2/21/14
to codenameone...@googlegroups.com, r...@akelex.com
I saw those methods and tried them but couldn't get them to work.  What does one pass to collapsePath() and expandPath()?  I tried passing in my root objects, their associated tree objects (the buttons), and a few other things and it always failed.  Eg, if I pass one of of the "root" objects in the tree, I get:

java.lang.ClassCastException: com.codename1.ui.Button cannot be cast to com.codename1.ui.Container
    at com.codename1.ui.tree.Tree.collapsePathNode(Tree.java:297)
    at com.codename1.ui.tree.Tree.collapsePath(Tree.java:331)
    at com.akelex.rbkcn1.ProblemTypeTree.collapseAll(ProblemTypeTree.java:210)
    at userclasses.StateMachine$3.actionPerformed(StateMachine.java:740)
    at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:345)
    at com.codename1.ui.Button.fireActionEvent(Button.java:378)
    at com.codename1.ui.Button.released(Button.java:417)
    at com.codename1.ui.Button.pointerReleased(Button.java:505)
    at com.codename1.ui.Form.pointerReleased(Form.java:2273)
    at com.codename1.ui.Form.pointerReleased(Form.java:2206)
    at com.codename1.ui.Component.pointerReleased(Component.java:2332)
    at com.codename1.ui.Display.handleEvent(Display.java:1892)
    at com.codename1.ui.Display.edtLoopImpl(Display.java:994)
    at com.codename1.ui.Display.mainEDTLoop(Display.java:925)
    at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
    at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

Shai Almog

unread,
Feb 21, 2014, 12:42:13 PM2/21/14
to codenameone...@googlegroups.com, r...@akelex.com
You should pass a tree object path e.g.: root, child, child

r...@akelex.com

unread,
Feb 21, 2014, 12:45:11 PM2/21/14
to codenameone...@googlegroups.com, r...@akelex.com
I am passing a root object from the model.  The code never gets to worrying about what object I passed in, I'm wondering if there's a bug in Tree.collapsePathNode()?

Shai Almog

unread,
Feb 22, 2014, 1:21:31 AM2/22/14
to codenameone...@googlegroups.com, r...@akelex.com
Root is always invisible so you need to collapse all the children of root.

r...@akelex.com

unread,
Feb 22, 2014, 12:23:44 PM2/22/14
to codenameone...@googlegroups.com, r...@akelex.com
I have a tree instance with multiple roots, in that when the model is called at getChildren(null), I return a Vector of model object that each have no parent.  Some have children, others not.  What I'm passing to collapsePath() is one of these "root" model instances, that has no parent but does have children.  The code in class Tree never even gets to looking at my object, it throws an exception before getting there.

Shai Almog

unread,
Feb 22, 2014, 3:29:11 PM2/22/14
to codenameone...@googlegroups.com, r...@akelex.com
Is that node expanded?

r...@akelex.com

unread,
Feb 22, 2014, 5:34:04 PM2/22/14
to codenameone...@googlegroups.com, r...@akelex.com
In the case I was running, I think it was not expanded.  However, there is no exposed method in class Tree to query about whether a given model object is expanded or not.

On Saturday, February 22, 2014 12:29:11 PM UTC-8, Shai Almog wrote:
Is that node expanded?

Shai Almog

unread,
Feb 23, 2014, 2:26:12 AM2/23/14
to codenameone...@googlegroups.com, r...@akelex.com
I just wanted to understand the use case, we'll fix the exception for the next update.

Arunraj Govindasamy

unread,
May 4, 2017, 9:37:02 AM5/4/17
to CodenameOne Discussions, r...@akelex.com
how to specify the path object

Arunraj Govindasamy

unread,
May 4, 2017, 11:16:16 AM5/4/17
to CodenameOne Discussions, r...@akelex.com
container = this ; causes the null pointer exception how to rectify it ???????

Shai Almog

unread,
May 5, 2017, 12:51:42 AM5/5/17
to CodenameOne Discussions, r...@akelex.com
Reply all
Reply to author
Forward
0 new messages