Get current Tree Select Node

Hi,ALL
I want to return JTree selection.
As you know If use JTree object, we can use
getSelectionPaths(), and use Treepah object method
getLastPathComponent to get selected node.
What I want to do is.
My JTree Object model is DefaultMutableTreeNode
i want to use DefaultMutableTreeNode to access selected Node.
Can I do like this?
If I can, how to do it?
Thanks in advanced

Hi,
if you following that pdf ,
i think your not implemented the below code in DomodifyView method
if (firstTime) {
      IWDTreeNodeType treeNode = (IWDTreeNodeType) view.getElement("TheNode");
      /* The following line is necessary to create parameter mapping from parameter "path" to parameter "selectedElement".
Parameter "path" is of type string and contains the string representation of the tree element (its corresponding context element to be exact)
that raised the onAction event. Parameter "selectedElement" is of type IWDNodeElement (or extends it) and is defined as parameter in the event handler
that handles the onAction. The parameter mapping defined here translates the String "path" into the corresponding context element that then can
be accessed within the event handler
      treeNode.mappingOfOnAction().addSourceMapping("path", "selectedElement");
      /* The following line is necessary to create parameter mapping from parameter "path" to parameter "element".
Parameter "path" is of type string and contains the string representation of the tree element (its corresponding context element to be exact)
that raised the onLoadChildren event. Parameter "element" is of type IWDNodeElement (or extends it) and is defined as parameter in the event handler
that handles the onLoadChildren. The parameter mapping defined here translates the String "path" into the corresponding context element that then can
be accessed within the event handler
      treeNode.mappingOfOnLoadChildren().addSourceMapping("path", "element");
please cross check once.
Thanks,
Ramesh

Similar Messages

  • TreeModel - get path of selected node

    How can I get path of selected node. I know getRowKey will return me for example [0,1,0] , but how can I use that to get string representation [Test, Folder1, Node0]
    I tried to loop thru it but the results are inccorect.

    public String pickPara_action() {
    // Add event code here...
    setCurrentParagraphNumberFromRow();
    return null;
    private void setCurrentParagraphNumberFromRow() {
    FacesContext ctx = FacesContext.getCurrentInstance();
    //java.lang.ClassCastException: oracle.jbo.uicli.binding.JUCtrlHierNodeBinding
    /*JUCtrlValueBindingRef*/JUCtrlHierNodeBinding tableRowRef =
    /*(JUCtrlValueBindingRef)*/(JUCtrlHierNodeBinding)this.getParagraphTreeTable().getRowData();
    try
    paragraphPk = (Double)tableRowRef.getRow().getAttribute("pk");
    catch (Exception ex) {
    System.err.println ("backingToc: exception at get attribute"+ex);
    String paragraphPk_str = paragraphPk.toString();
    System.err.println("backingToc: before store");
    IMS_UserSystemState.storeCurrentParagraphNumber(paragraphPk_str);
    }

  • How to get the current tree element (node/childnode/childnode/...) ?

    Hello!
    I'm trying to create a kind of a navigation tree for my application.
    It should represent some elements of an XML structure and some other nodes for other options.
    The binding with the context is not a problem, I can create the tree up to all the levels I want to.
    The problem now is, that I don't know, how to get the "current tree element", when there is any action.
    For example:
    public void onActionSelect(...) {
    String test = wdContext.currentTreeNodeElement().getText();
    wdThis.wdGetContext().currentContextElement().setSelectedElement(test);
    With this method I can get the text of the "first level nodes". If I want to get the "second level node", I can do
    String test = wdContext.currentTreeNodeElement().currentChildElement.getText();
    ..and for the next levels so on.
    Isn't there any general method to get the information of the selected element without knowing before, whether it is a nodeElement or a nodeElement.currentChildElement or a nodeElement.currentChildElement.currentChildElement, ...?
    Greetings,
    Ramó

    Hi,
    if you following that pdf ,
    i think your not implemented the below code in DomodifyView method
    if (firstTime) {
          IWDTreeNodeType treeNode = (IWDTreeNodeType) view.getElement("TheNode");
          /* The following line is necessary to create parameter mapping from parameter "path" to parameter "selectedElement".
    Parameter "path" is of type string and contains the string representation of the tree element (its corresponding context element to be exact)
    that raised the onAction event. Parameter "selectedElement" is of type IWDNodeElement (or extends it) and is defined as parameter in the event handler
    that handles the onAction. The parameter mapping defined here translates the String "path" into the corresponding context element that then can
    be accessed within the event handler
          treeNode.mappingOfOnAction().addSourceMapping("path", "selectedElement");
          /* The following line is necessary to create parameter mapping from parameter "path" to parameter "element".
    Parameter "path" is of type string and contains the string representation of the tree element (its corresponding context element to be exact)
    that raised the onLoadChildren event. Parameter "element" is of type IWDNodeElement (or extends it) and is defined as parameter in the event handler
    that handles the onLoadChildren. The parameter mapping defined here translates the String "path" into the corresponding context element that then can
    be accessed within the event handler
          treeNode.mappingOfOnLoadChildren().addSourceMapping("path", "element");
    please cross check once.
    Thanks,
    Ramesh

  • Get tree selected node onPageLoad

    We just turned on change persistence to keep our row selections as we traverse our taskflows and pages.
    In one of our pages we have a situation where we have a tree (master) and table (table) whose data is partially based on what is selected in that tree. We use the following logic to determine what is selected in the tree to perform the query on the table.
    public static JUCtrlHierNodeBinding getTreeSelectedNode(RichTree tree) {
    JUCtrlHierNodeBinding node = null;
    if (tree != null) {
    Object oldRowKey = tree.getRowKey();
    try {
    RowKeySet selectedRowKeySet = tree.getSelectedRowKeys();
    if (selectedRowKeySet != null) {
    for (Object selectedRowKey : selectedRowKeySet) {
    tree.setRowKey(selectedRowKey);
    node = (JUCtrlHierNodeBinding)tree.getRowData();
    break;
    } finally {
    tree.setRowKey(oldRowKey);
    return node;
    I hooked up a beforePhase listener on my jspx to call this function and get the (previously - last time user was on this page) selected row and then refresh the table based on the selected tree row's data. This seems to work, but . . . in my log I'm seeing the following error. It seems like for some reason it's trying to convert my Raw UUID to an int, I have no idea why.
    <SortableModel> <_toRowIndex> Invalid rowkey:oracle.jbo.Key[B68F305BF7F5496D8A0FF99EE8F97CF0 ] type:class oracle.jbo.Key
    <SortableModel> <_toRowIndex>
    java.lang.ClassCastException: oracle.jbo.Key cannot be cast to java.lang.Integer
    at org.apache.myfaces.trinidad.model.SortableModel._toRowIndex(SortableModel.java:341)
    at org.apache.myfaces.trinidad.model.SortableModel.setRowKey(SortableModel.java:137)
    at org.apache.myfaces.trinidad.model.ChildPropertyTreeModel._setRowKey(ChildPropertyTreeModel.java:376)
    at org.apache.myfaces.trinidad.model.ChildPropertyTreeModel.setRowKey(ChildPropertyTreeModel.java:178)
    at org.apache.myfaces.trinidad.component.UIXCollection.setRowKey(UIXCollection.java:425)
    at oracle.apps.aia.sr.common.JSFUtils.getTreeSelectedNode(JSFUtils.java:392)
    So, I thought that maybe this wasn't the best way to get the selected node. So, after some research I changed the logic to be:
    public static JUCtrlHierNodeBinding getTreeSelectedNode(RichTree tree) {
    JUCtrlHierNodeBinding node = null;
    if (tree != null) {
    CollectionModel treeModel = (CollectionModel)tree.getValue();
    if (treeModel != null ){
    JUCtrlHierBinding treeBinding = (JUCtrlHierBinding)treeModel.getWrappedData();
    if (treeBinding != null){
    RowKeySet rks = tree.getSelectedRowKeys();
    if (rks != null){
    if (!rks.isEmpty()){
    List firstSet = (List)rks.iterator().next();
    node = treeBinding.findNodeByKeyPath(firstSet);
    return node;
    However, at the time of the beforePhase (I even tried an afterPhase listener) the tree isn't null, but the CollectionModel is null for some reason. I'm not sure where to go from here, any ideas?

    Hi,
    if you use lazy loading (contentdelivery="lazy" then the data is queried after the tree renders. ou would need to set it to immediate to acess data suring the Preparerender phase).
    Frank

  • Dynamic tree selected node property id issue...

    hi -
    I'm successfully building a two-tier tree dynamically, but when a node is selected, it isn't consistently giving the correct property id for that node... sometimes it's correct, sometimes it's null, sometimes I have to select the node twice to get a value, or it shows the value from the previous selected node...
    I've tried tree1.getSelected() and tree1.getCookieSelectedTreeNode() but it's still the same result... it acts as though the cookie isn't getting updated each time... I've tried it with and without setting 'immediate' with the same result... below is the relevant part of my code... does anyone see why it's not getting the selected property id each time? help and suggestions welcome... Thanks
    try {
    java.util.List newNodeChildren = newNode.getChildren();
    while (srs.next()){
    TreeNode newNode2 = new TreeNode();
    newNode2.setTarget("_blank");
    newNode2.setText(srs.getString( "issue_title"));
    newNode2.setId("x" + issue_id);
    //Setup action event
    Hyperlink nodelink = new Hyperlink();
    nodelink.setText(newNode2.getText());
    nodelink.setId(newNode2.getId());
    Class[] signatures = {ActionEvent.class};
    MethodBinding mb1 = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{Page2.treeNodeActionListener}", signatures);
    nodelink.setActionListener(mb1);
    newNode2.getFacets().put(newNode2.CONTENT_FACET_KEY, nodelink);
    newNodeChildren.add(newNode2);
    srs.release();
    } catch(SQLException ex) {
    / error("SQL Error StatusTree Retrieval: " + ex);
    public void treeNodeActionListener(ActionEvent event) {
    String id = tree1.getCookieSelectedTreeNode();
    String actualId = id.substring(id.lastIndexOf(":")+2);
    info("treeNodeActionListener actualId = " + actualId);
    }

    Hi,
    1 I dropped Tree component from Palette. I deleted TreeNode1.
    <ui:tree binding="#{Navigator.tree1}" expandOnSelect="false" id="tree1" immediate="true" style="left: 0px; top: 0px; position: absolute" text="Sometext"/>
    2 In the init() method I called paintTree()
    It works fine.
    I use action method because I need only the id of selected node but I tested also listener method and it works
    Here is my code
    public void paintTree(){
    ArrayList conturi=new ArrayList();
    TreeNode nodN1 = new TreeNode();
    TreeNode nodN2 = new TreeNode();
    TreeNode nodN3 = new TreeNode();
    TreeNode nodN9 = new TreeNode();
    String Id;
    int lga=0;
    int lgc=0;
    try {
    conturi=getSessionBean1().getSes01FacadeRemoteClient1().getMyEjbMethod();
    } catch (Exception ex) {
    log(".....", ex);
    Iterator iterator=conturi.iterator();
    while (iterator.hasNext()) {
    detalii.Conturi cont=(detalii.Conturi)iterator.next();
    lgc=cont.getConts().length();
    if (lga < lgc) {
    if (lgc == 1) {
    nodN1=new TreeNode();
    Id= "Node_"+cont.getId();
    nodN1.setId(Id);
    nodN1.setText(cont.getDenumire());
    tree1.getChildren().add(nodN1);
    if (lgc == 2){
    nodN2=new TreeNode();
    Id= "Node_"+cont.getId();
    nodN2.setId(Id);
    nodN2.setText(cont.getConts()+"-"+cont.getDenumire());
    nodN2.setStyleClass("leftAligned");
    nodN1.getChildren().add(nodN2);
    if (lgc == 3){
    nodN3=new TreeNode();
    Id= "Node_"+cont.getId();
    nodN3.setId(Id);
    nodN3.setText(cont.getConts());
    nodN3.setStyleClass("leftAligned");
    FacesContext context=FacesContext.getCurrentInstance();
    MethodBinding mb1 = context.getApplication().createMethodBinding("#{Navigator.treeNode_action}", null);
    nodN3.setAction(mb1);
    nodN2.getChildren().add(nodN3);
    } //end-if
    } //end while
    public String treeNode_action() {
    try {
    clientId=tree1.getCookieSelectedTreeNode();
    String id =clientId.substring(clientId.lastIndexOf("_")+1);
    getSessionBean1().setContId(id);
    info("clientId = "+ clientId);
    } catch (Exception ex) {
    log("Error Description", ex);
    return null;
    }

  • JTree get selected node/object values

    I wan to get all the selected nodes/objects values that I added to the JTree. How can I do this?
    Thanks.

    TreePath[] paths = tree.getSelectedPath();
    for(int i = 0; i < paths.length; i++){
    TreeNode node = (TreeNode)paths.getLastPathComponent();
    Object mySelectedObject = node.getUserObject();
    }Some minor Errors
    We have to use array paths[i] instead of paths
    The correct code as used by me is
            javax.swing.tree.TreePath[] paths = jTree1.getSelectionModel().getSelectionPaths();
            for(int i = 0; i < paths.length; i++){
                javax.swing.tree.TreeNode node = (javax.swing.tree.TreeNode)paths.getLastPathComponent();
    System.out.println(((javax.swing.tree.DefaultMutableTreeNode)node).getUserObject());
    CSJakharia

  • JTree: How to get the currently selected node

    How do I get the currently selected node in JTree?
    getLastSelectedPathComponent() this method always return the last selected node and not the current one.
    Thanks in advance
    Sachin

    Use
    TreePath selectedPath = tree.getSelectionPath()If your tree allows multiple selections, use
    TreePath [] selectedPaths = tree.getSelectionPaths() this will return an array of all selected tree paths.
    Once you get the tree path, call the treePath.getLastPathComponent(). this should tell you the currently selected node.
    Hope this helps
    Sai Pullabhotla

  • Help in getting current expanded node in Tree UI

    HI,
    I have a requirement to build a tree dynamically. On expanding each node I need to create sub nodes inside that. But it is always creating inside the node where the lead selection is and not inside the current expanded node. Even though I have used getTreeSelection () to get the current element.
    <b>Detailed description about the application.,</b>
    I have created a context with the following structure,
    TreeNode (0..n)
    |
    |--> ChildNode (recursive SiteTree)
    |--> Name (string)
    I have created a Tree UI Element in the view and inserted a node type 'TreeNodeType'.
    I have set the properties of the inserted node type as given bellow,
    Value Attribute in TreeNode -> Name I have assigned to 'Text' property of 'TreeNodeType'.
    Initially I have created four nodes in the init() method ., using the following code :
    for(int i=0;i<3;i++)
    IPrivateTestTreeView.ITreeNodeNode treenode=wdContext.nodeTreeNode();
    IPrivateTestTreeView.ITreeNodeElement treeelement=wdContext.createTreeNodeElement();
    treeelement.setName("Testroot:"+i);
    treenode.addElement(treeelement);
    Now I need to create sub-nodes for this dynamically.,
    I have created an action and called it in 'onLoadChildren' event of 'TreeNodeType' with the following code:
    public void OnCurrentSelection()
    IPrivateTestTreeView.ITreeNodeElement el = wdContext.nodeTreeNode().getTreeSelection();
    wdComponentAPI.getMessageManager().reportSuccess(el.getName());
    <b>
    Where this returns me only the name of LeadSelection node and not the  node which i try to expand.  </b>
    Is there anyway I can get the currently expanded node., Kindly help me out in this.
    Points will be rewarded for helpful answers. Thanks in advance.
    Regards,
    Nirmal

    HI Ayyapparaj ,
    <b>First I would like to thank you for your reply.</b>
    So it means that we cannot identify the currently expanded node in tree UI element and It will always be the lead selection node we will be able to get rite?
    Can we make the current lead selection to currently expanded node 'By Default'?
    Coming back to your solution.,
    I created a context element 'isExpanded' of type boolean inside the TreeNode.
    You said that there will be a call made to 'getter and setter' methods while we expand the node and we can set the lead selection to that element from there.
    Could you please give me some more details of how to achieve it.
    Thanks in advance.
    Regards,
    Nirmal G

  • How to get all tree node parents upon select

    I have a tree, and when user clicks an item in the tree, I want to get all the parents of the selectedItem node.
    So if I have this XML:
    <products>
        <item>
            <sku>1001</sku>
            <quantity value="100" />
        </item>
        <item>
            <sku>2001</sku>
            <quantity value="250" />
        </item>
        <item>
            <sku>3001</sku>
            <quantity value="300" />
        </item>
    </products>  
    If user clicks on the 1001 sku, I want to get something like this:
    <products><item><sku>
    Also if I have a custom component, perhaps based on tree or but maybe not, and if this custom component shows the actual XML and used can click on XML elements or XML attributes, how can I use the selected item to get the parent nodes, so if they click on the value="100", I want to get this:
    <products><item><sku><quantity>
    I need this because I have a set of fields, and users will drag their XML node elements or attributes to my fields, to define a mapping between their XML and my fields.
    The selectedItem is just a snippet of XML cut off from its source XMLListCollection, and I might be able to search the XMLListCollection, but what if there were say <sku> elements at more than one level in the XML? I'm guessing a search might return multiple hits for a selected element, when I want the actual parent nodes for the actual selected node.
    Thanks very much!

    var path:Array=[]
    var parent:XML = xxxx.selectedItem.parent()
    while(parent){
    path.push(parent.localName())
    parent = parent.parent()
    Or, i didn't get your question and xxxx.selectedItem is "detached" XML snippet ?

  • How to get the selected node value of a tree which is build on java code

    Hi Experts,
    How can i get the selected node value if I build the tree programatically.
    I am using the following code in selectionListener but it is throwing error.
    RichTreeTable treeTable = (RichTreeTable)getQaReasontreeTable();
    CollectionModel _tableModel =
    (CollectionModel)treeTable.getValue();
    RowKeySet _selectedRowData = treeTable.getSelectedRowKeys();
    Iterator rksIterator = _selectedRowData.iterator();
    String selectedQaCode ="";
    while (rksIterator.hasNext()) {
    List key = (List)rksIterator.next();
    JUCtrlHierBinding treeTableBinding =
    (JUCtrlHierBinding)((CollectionModel)treeTable.getValue()).getWrappedData();
    JUCtrlHierNodeBinding nodeBinding =
    treeTableBinding.findNodeByKeyPath(key);
    String nodeStuctureDefname =
    nodeBinding.getHierTypeBinding().getStructureDefName();
    selectedQaCode = selectedQaCode + nodeBinding.getAttribute(0);
    where I am using following link to create a tree with java code.
    http://one-size-doesnt-fit-all.blogspot.com/2007/05/back-to-programming-programmatic-adf.html
    Please help me in resolving this issue.
    Regards
    Gayaz

    Hi,
    you should also move
    JUCtrlHierBinding treeTableBinding =
    (JUCtrlHierBinding)((CollectionModel)treeTable.getValue()).getWrappedData();
    out of the while loop as this is not necessary to be repeated for each key in the set
    Frank

  • How to get UIComponent of the selected node in af:tree with drag and drop

    Hi
    Are there examples showing how one could get a UIComponent using DropEvent to be used with a Popup showing as a custom "context menu" at the target node ?
    Right now, with dropEvent.getDropComponent, we could only get the tree.
    We like to get its selected node so that the popup shows at the node level, not at the tree level.
    Thanks

    Hi Frank
    Thanks for responding.
    We like to show on our custom "context menu" using PopupHints (not using facet name contextmenu) with 3 commandMenuItems.
    Since component id is needed by PopupHints to place this custom "context menu", we tried
    RichTree dropTree = (RichTree)dropEvent.getDropComponent();
    alignId = dropTree.getClientId(context);
    // alignId = pt1:pt_region1:1:pt1:pc1:navTree
    getClientId returns us the tree id and hence the context menu is placed next to tree.
    We like to place the context menu next to a target node of the tree when dragging and dropping.
    But we couldn't figure out how to get that node id.
    In your suggestion,
    List dropRowKey = (List) dropEvent.getDropSite();
    RichTree dropComponent = (RichTree) dropEvent.getDropComponent();
    dropCompoent.setRowKey(dropRowKey);
    how do we then get the id of this node then ? What's the method ?
    Thanks Frank

  • Right click select node in tree (for a standalone Air app)?

    For the sake of userfriendliness (in regard to a context menu) I wold like to "move" the selected node in a tree to the node that currently has the focus when right clicking it - like how the context menu access in windows file explorer works (focus and selected item are always the same  when right clicking).
    In worst case scenario I would like to disable a created context menu if the selected node and the node that currently has the focus are not the same).
    Now users can get confused when right clicking to access my context menu, in the tree structure, if the selected node and the node they are currently hovering over (and thus are in focus) are different.
    I was thinking of finding which node currently has the focus and then making that node the selected node - but I cant get it to work:-).
    Please, help a beginner.

    Hi,
    Duplicate thread of
    http://swforum.sun.com/jive/thread.jspa?threadID=64518
    MJ

  • Selecting node of tree

    Hello thanks for anyone before..
    I have a problem with selection of my Tree. my tree nodes contains of ItemFormat like :
    class ItemFormat
    private String code;
    private String description;
    ..... mutator and accessor methods......
    when i have displayed my tree successfully i can print on screen about selected itemFormat to display description instance variable.
    but after I edit my node and then i selected again the selected node can't be casted to ItemFormat to display its description...
    please help me...
    thanks before....

    Thanks Tony,
    The application I have is a means of commercial seafood dealers recording what species they have purchased/landed. The page is designed with a tree listing all of the species and their sizes and then the tabular report of landings. The current application uses a collection to display the landings....I was trying to get rid of the collection and populate the table directly.
    thanks for getting back to me. Sounds like I will need to keep the collection....just looking for examples.

  • How to get the tree index of a child node

    Hi, I am loading a tree object from an XML source file (via
    an XMLListCollection)
    I can find the children on the currently selected node, like:
    var children:XMLList =
    XMLList(myTree.selectedItem).children();
    for(var i:Number=0; i < children.length(); i++) {
    trace("Child Found: " + children
    .@caption);
    But how can I determine the tree index for each of the
    children? I would like to be able to grab and save the tree index
    for each child, so that I can later just to do
    "myTree.selectedIndex = (saved child index) (based on some form
    action the user performs). I can't find any method of determining
    what the tree index for a child is, other than walking down the
    tree from the parent node and counting the number of nodes till I
    hit each child. Is there a simple method?

    Tree is hierarchical, index is linear. I have never seen
    anyone successfully use selectedIndex with Tree.
    You best bet is to put an id on each node and use e4x
    expression to find that node when you want.
    Tracy

  • How can I get the previous clicked node in a Tree?

    I have a JTree. If a node is selected, before the user select another, I need to make a question if he have sure about the new selection.
    If the user answers not, I need to select the previous node.
    I have in my class a variable, type of DefaultMutableTreeNode, that makes reference to the last node selected.
    How can I turn this node selected again, if the user select "No"?
    Thanks for any help.
    Renato de Melo

    You don't want to maintain a reference to the last selected node, but to the last selected path. Nodes within a tree are addressed using a TreePath, with contains references to each node from the root, down to a specific node. Look at the JavaDocs of javax.swing.tree.TreePath for more info.
    Also, JTree has getter/setter methods for the selectionPath.

Maybe you are looking for

  • How to get the draft and sent folder in java mail

    i found the File Not Found error while accessing the draft,sent folder to fecth from the mail sever using IMAP. i m using the code like tis draft=store.getFolder("draft"); sent=store.getFolder("sent"); And i want to know whether the draft,sent,trash

  • Unable to send or receive from C601 Bluetooth to A...

    Hi, I tried to send a file to my nokia c601, it got connected, all drivers installes successfully, yet I am unable to send a file, be it any fle type. When I send the file, I dont get even the request to accept the incoming file, just the data transf

  • Inventory GL Account Bad Entry

    Hello All, I have a situation I am struggling with. I have some Raw Materials that were received tied to our Finished Goods account. Either the group was set up wrong or someone keyed in the wrong account, or something. In the image I attached you ca

  • How can I flash my Windows Mobile 6.5.3 ROM to Firefox OS?

    Hello. I am the very last user running Windows Mobile 6.5.3, the old and abandoned operating system by Microsoft. As a Mozilla's enthusiast, I am really interested in using Firefox OS, however I can't find any ways to install such OS into my phone. M

  • "We could not complete you iTunes store request.  An unknown error..."

    "We could not complete you iTunes store request. An unknown error ocurred (-50). There was an error in the iTunes store. Please try again later." I have a macbook that has two users, me and my daughter. Whenever my daughter tries to open the iTunes s