Sorting Nodes in JTree

Can someone please help me. I got this class (MyTreeNode) from this forum but has problem compiling/using it due to my beginners status in Java. My current program is shown below. My problem is that if I change DefaultMutableTreeNode to MyTreeNode the program won't compile as the constructor for MyTreeNode does not take a parameter. Please show my how I can modify this to make use of the new class. I only want to sort the nodes in alphabetical order. If someone has a better way of doing it, please post it here.
public void xpy()
DefaultMutableTreeNode node1 = new DefaultMutableTreeNode(field1);
DefaultMutableTreeNode node2 = new DefaultMutableTreeNode(field2);
node1.add(node2);
class MyTreeNode extends DefaultMutableTreeNode
private static Comparator nodeComparator = new Comparator ()
public int compare(Object o1, Object o2)
return o1.toString().compareTo(o2.toString());
public boolean equals(Object obj)
return false; //static class -- 1 instance only
public void add(MutableTreeNode node)
super.add(node);
Collections.sort(this.children, nodeComparator); //this.children is a proteced variable reference to the node's vector of children.
Thanks
pslloo

Just add a constructor to your subclass:
class MyTreeNode extends DefaultMutableTreeNode {
  public MyTreeNode(Object obj) {
    super(obj);
...Regards

Similar Messages

  • Help needed with finding node in JTree

    Hi,
    In my application i will be entering some string data in a text box for search criteria.
    When I click on search, I will get data from database which will be shown as a JTree.
    This Jtree will have some nodes in which, node with string entered in the search text box exists.
    I need to focus on this node and I have only a string to find this node.
    How can I do this?How can I find a node in JTree using string value?
    Is there any alternate option by which I can achive my need?
    Please suggest.
    Thanks.

    @OP: please assign your dukes.
    @Andre_Uhres: if you don't get rewarded in the next couple of days, please let me know here to get at least one duke for your effort.
    Bye.

  • Problem inserting new node into JTree with depthFirstEnumeration()

    Hello,
    I'm currently trying to use depthFirstEnumeration() to add and delete nodes for a simple JTree. I've written a method to handle this, but it keeps coming back with an exception saying that 'new child is an ancestor'.
    All I'm trying to do is add and delete nodes from a JTree using add and remove buttons within a swing program. When a user adds the new node the JTree needs to be updated with new labels in sequential order dependent upon a depthFirst traversal of the JTree.
    My current code for the add button is as follows,
    public void actionPerformed(ActionEvent event) 
            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
            Enumeration e = rootNode.depthFirstEnumeration();
            if(event.getSource().equals(addButton))
                if (selectedNode != null)
                    while (e.hasMoreElements()) {
                    // add the new node as a child of a selected node at the end
                    DefaultMutableTreeNode newNode = (DefaultMutableTreeNode)e.nextElement();
                     // treeModel.insertNodeInto(newNode, selectedNode, selectedNode.getChildCount());
                    //System.out.print(newNode.getUserObject() + "" + newNodeSuffix++);
                    String label = "Node"+i;
                    treeModel.insertNodeInto(newNode, selectedNode, selectedNode.getChildCount());
                    i++;
                      //make the node visible by scrolling to it
                    TreeNode[] totalNodes = treeModel.getPathToRoot(newNode);
                    TreePath path = new TreePath(totalNodes);
                    tree.scrollPathToVisible(path);
                    //System.out.println();
            else if(event.getSource().equals(deleteButton))
                //remove the selected node, except the parent node
                removeSelectedNode();           
        } As you can see in the above code, I've tested the incrementing of the new nodes in a System.out.print() statement and they appear to be incrementing correctly. I just can't see how to correctly output the labels for the nodes.
    Any help and advice always appreciated.

    This is about the 5th posting on the same question. Here is the link to the last posting so you can see what has already been suggested so you don't waste your time making the same suggestion.
    http://forum.java.sun.com/thread.jspa?threadID=704980
    The OP doesn't seem to understand that nodes don't just rename themselves and that renderers will only display the text of the current node. If you want the text displayed to changed, then you need to change the text associated with each node, which means iterating through the entire tree to update each node with new text. Then again, maybe I don't understand the question, but the OP keeps posting the same question without any additional information.

  • Drag and Drop nodes in JTree

    Is there a way to drap and drop JTree nodes without resorting to hacks? http://www.javaworld.com/javatips/jw-javatip97.html outlines a hack to get drag and drop working but it is kinda old. I am wondering whether there is a now a way to do this in Swing. http://weblogs.java.net/blog/shan_man/archive/2006/01/first_class_dra.html outlines a seemingly promising way but when I tried it it still wouldn't let me drag JTree nodes. (btw, if you are going to try it, you must replace TransferHandler.TransferInfo with TransferHandler.TransferSupport. It has apprently been renamed.)

    I have implemented drag and drop of nodes in JTree they same way it is explained in JavaWorld link that you mentioned, I customized it for my application and it worked great.

  • Wordwrap nodes in jtree

    Anyone know how we can do wordwrap of nodes in jtree?
    Please help...
    Thanks.

    Any example on this? what html code should I use? The simplest possible, eg
    yourNode.setText("<html>" + yourNodeText + "</html>");Most JComponents can render this html string and produce a good result. But if you wanna get a little more complex and use styles and other web things, then do as said, (two posts above) and use a JEditorPane specifically for cell renderer
    ICE

  • How to set the default tree node in JTree?

    I want to set a default tree node in JTree when start the program,
    what is the method or the function to call?
    Thanks~

    If you by "default" mean "selected", then you can use one of the setSelectionXXX methods in the JTree API.
    If you by "default" mean something else, never mind this post :-)

  • Setting custom color for selected node in JTree?

    Hi,
    i want to set my own color for selected node in JTree. i don't want to set for all the nodes...how to set Color for Selected node using TreeCellRender class?
    Thanks
    Mani

    I assume you are not setting a custom tree cell renderer...
    javax.swing.JTree theTree = ...;
    java.awt.Color newBGColor = ...;
    ((javax.swing.tree.DefaultTreeCellRenderer)theTree.getCellRenderer())
        .setBackgroundSelectionColor(newColor);

  • Add node to JTree

    I have an already populated JTree. At Runtime I add one or more node to JTree, using something like
    parentNode.add(newNode)....
    If I call a repaint method, the new node isn't visible, I have to reload model using
    DefaultTreeModel dtm = ((DefaultTreeModel)myTree.getModel());
    TreeNode rootNode = (TreeNode) dtm.getRoot();
    dtm.reload(rootNode);
    Unfortunately this method cause the lost of focus on the currently selected node and the collapse of all JTree around its root node; If I change an existing node (for example changing its text or icon) I must reload the model too!!!
    Does exist an other more "soft" method to change the aspect of a JTree without reload the entire model?

    You must use or implement the
        public void valueForPathChanged(javax.swing.tree.TreePath path,java.lang.Object newNode) {
            Object[]    p = path.getPath();
            Object[]    pp = p;
            //insert node here
            int[] ci = new int[] {index};
            Object[] cc = new Object[] {node};
            fireTreeNodesChanged(this, pp, ci, cc);
            fireTreeStructureChanged(this, pp, ci, cc);
        }from the TreeModel. To fire the last two is essensial.
    I implemented a GP in JAVA so i had the same problem wehn i started.

  • How to dynamically add Nodes to JTree?

    How to add nodes to a Jtree by getting the information into a specific file
    For example, in JList:
    DefaultListModel workgroups;
    workgroups = new DefaultListModel();
    List<String> workgroupsList = new ArrayList<String>();
    workgroupsList = ParserUtils.getWorkgroupList(ParserUtils.getConfigPath() + "\\.workgroup.properties");
    if (!workgroupsList.isEmpty()){
         for (String workgroup : workgroupsList){
              workgroups.addElement(workgroup.toString().trim());
    workgroupList = new JList(workgroups); //adds the list workgroupsThe output of this will be a JList displaying the list of workgroups per line. The list could be found in a file name "workgroup.properties"
    Question is, is it possible to adapt this same method in JTree. The information per line will serve as one node in the tree. For example, I have 3 workgroups in the list, there will also be 3 nodes to be found in the tree.
    Any suggestions?
    THanks.

    There's a huge JTree example in the Swing tutorial. It's a bit of a beast to use.

  • How to show only all children of selected node in JTree??

    Dear friends:
    I have Two Panels, PA and PB,
    PA has a Jtree as code below, and PB listens to PA,
    I hope to do following,
    If I select a node called A in PA, then Node A's all children such as A1, A2, A3 will be displayed in PB, but not display A1, A2, A3's children such as A3 has C1, C2, C3, C4 & C5, until I select A3 then PB will display only all A3's children: C1, C2, C3, C4 & C5;
    i.e, only populate each ONE level of children of Node A or any node I select, not its grandchildren and its grand-grand children;
    Please help how to do it??
    I tried amny times, failed.
    Thanks
    [1]. PA panel code:
    package com.atest;
         import java.awt.BorderLayout;
         import java.awt.event.MouseAdapter;
         import java.awt.event.MouseEvent;
         import java.util.Enumeration;
         import java.awt.Dimension;
         import javax.swing.JFrame;
         import javax.swing.JPanel;
         import javax.swing.JScrollPane;
         import javax.swing.JTextField;
         import javax.swing.JTree;
         import javax.swing.tree.DefaultMutableTreeNode;
         import javax.swing.tree.TreeModel;
         import javax.swing.tree.TreePath;
         public class DefaultMutableTreeMain extends JPanel {
         protected DefaultMutableTreeNode    top = new DefaultMutableTreeNode("Options");
         protected DefaultMutableTreeNode      selectedNode = null;
         protected final JTree tree;
         protected final JTextField jtf;
        protected Enumeration      vEnum = null;
         private      TreeModel                m;
         protected  DefaultMutableTreeNode      getDefaultMutableTreeNode()  {
              //textArea.getText();
                   return selectedNode;
         protected  DefaultMutableTreeNode setDefaultMutableTreeNode(DefaultMutableTreeNode tt)  {
              //textArea.getText();
                   selectedNode = tt;
                   return selectedNode;
         protected  TreeModel getJTModel()  {
              //textArea.getText();
                   return m;
         protected  TreeModel setJTModel(TreeModel ta)  {
                   m = ta;
                   return m;
           public DefaultMutableTreeMain() {
             setSize(300,300);
             setLayout(new BorderLayout());
             DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
             top.add(a);
             DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
             a.add(a1);
             DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
             a.add(a2);
             DefaultMutableTreeNode a3 = new DefaultMutableTreeNode("A3");
             a.add(a3);
             DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
             top.add(b);
             DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
             b.add(b1);
             DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
             b.add(b2);
             DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
             b.add(b3);
             DefaultMutableTreeNode c = new DefaultMutableTreeNode("C");
             a3.add(c);
             DefaultMutableTreeNode c1 = new DefaultMutableTreeNode("C1");
             c.add(c1);
             DefaultMutableTreeNode c2 = new DefaultMutableTreeNode("C2");
             c.add(c2);
             DefaultMutableTreeNode c3 = new DefaultMutableTreeNode("C3");
             c.add(c3);
             DefaultMutableTreeNode c4 = new DefaultMutableTreeNode("C4");
             c.add(c4);
             DefaultMutableTreeNode c5 = new DefaultMutableTreeNode("C5");
             c.add(c5);
             tree = new JTree(top);
             JScrollPane jsp = new JScrollPane(tree);
             jsp.setPreferredSize(new Dimension(400,300));
             add(jsp, BorderLayout.CENTER);
             jtf = new JTextField("", 20);
             add(jtf, BorderLayout.SOUTH);
               tree.addMouseListener(new MouseAdapter() {
               public void mouseClicked(MouseEvent me) {
                  TreePath   path = tree.getSelectionPath();
                  DefaultMutableTreeNode      selectedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
                 TreePath tp = tree.getPathForLocation(me.getX(), me.getY());
                 setDefaultMutableTreeNode(selectedNode);
                     System.out.println("Current node selected is (tp.toString()=" + tp.toString());
                     System.out.println("Current node selected is getDefaultMutableTreeNode()=" + getDefaultMutableTreeNode());
                 if (tp != null){
                     jtf.setText(tp.toString());
                      System.out.println("It Has Children as selectedNode.getChildCount()= " + selectedNode.getChildCount());
                            Enumeration vEnum = selectedNode.children();
                                int i = 0;
                                while(vEnum.hasMoreElements()){
                                    System.out.println("2 selectedNode = " +  path.toString() + "  has " + i++ + " Children in vEnum.nextElement(" + i + ") = " + vEnum.nextElement());
                 else
                   jtf.setText("");
           public static void main(String[] args) {
             JFrame frame = new JFrame();
             frame.getContentPane().add(new DefaultMutableTreeMain());
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             frame.setSize(400, 400);
             frame.setVisible(true);
         }[2]. PB Panel code
    package com.atest;
    import java.awt.BorderLayout;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.JPanel;
    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.event.TreeSelectionListener;
    import javax.swing.tree.*;
    import javax.swing.JButton;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreePath;
    public class DefaultMutableTreeSub extends JPanel implements java.io.Serializable{
      private JButton removeButton;
      private JButton addButton;
      JTree tree;
      private TreeModel      m;
      protected TreeDragSource ds;
      protected TreeDropTarget dt;
    protected  TreeModel getJTModel()  {
              //textArea.getText();
                   return m;
    protected  TreeModel setJTModel(TreeModel ta)  {
                   m = ta;
                   return m;
    protected DefaultTreeModel model;
    protected DefaultMutableTreeNode rootNode;
    DefaultMutableTreeMain dmm = null;
    JPanel inputPanel  = new JPanel();
      public JPanel SLTreeDNDEditableDynamic(DefaultMutableTreeMain tdnd ) {
        //super("Rearrangeable Tree");
        setSize(400,450);
        dmm = tdnd;
             setLayout(new BorderLayout());
             inputPanel.setLayout(new BorderLayout());
             JPanel outputPanel = new JPanel();
             System.out.println("Sub selectedNode tdnd= " + tdnd);
             tdnd.tree.addTreeSelectionListener(new TreeSelectionListener(){
                  public void valueChanged(TreeSelectionEvent evt){
                  TreePath[] paths = evt.getPaths();
                  TreePath   path = dmm.tree.getSelectionPath();
                  DefaultMutableTreeNode      selectedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
                 DefaultMutableTreeNode itemNode = dmm.getDefaultMutableTreeNode();
                     System.out.println("Sub node selected is dmm.getDefaultMutableTreeNode()=" + dmm.getDefaultMutableTreeNode());
                  model = new DefaultTreeModel(itemNode);
                  tree = new JTree(model);
                  System.out.println("Sub selectedNode paths= " + paths);
                  System.out.println("Sub selectedNode path= " + path);
                  System.out.println("Sub selectedNode = " + selectedNode);
                  System.out.println("Sub itemNode = " + itemNode);
                  tree.putClientProperty("JTree.lineStyle", "Angled");
                  tree.setRootVisible(true);
                   inputPanel.add(new JScrollPane(tree),BorderLayout.CENTER);
             return inputPanel;
         public DefaultMutableTreeSub() {
              super();
    }thanks
    sunny

    Thanks so much, I use your code and import followig:
    import java.util.ArrayList;
    import java.awt.List;
    but
    private static List<Object> getChildNodes(JTree j) {
         Object parent = j.getLastSelectedPathComponent();
         int childNodeCount = j.getModel().getChildCount(parent);
         List<Object> results = new ArrayList()<Object>;
         for (i = 0; i < childNodeCount; i++) {
              results.add(parent, i);
         return results;
    here List<Object> and ArrayList()<Object> show red,
    Is my JDK version problem??
    my one is JKD
    C:\temp\swing>java -version
    java version "1.4.2_08"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
    Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)
    Error as follows:
    C:\temp\swing>javac DefaultMutableTreeSub.java
    DefaultMutableTreeSub.java:38: <identifier> expected
    private static List<Object> getChildNodes(JTree j) {
    ^
    1 error
    any idea??
    Thanks

  • How to search a child node in JTree

    Hi I am new to swings..
    My requirement is I have a Jsplit pane.
    I have search button with a text box in one and Jree in another pane.
    When I enter a string and hit Search button...It need to search the tree and expand that node highlight it.
    can anyone help in getting this done.

    public void actionPerformed(ActionEvent e)
      DefaultTreeModel m_model = new DefaultTreeModel(entityRoot);
      DefaultMutableTreeNode node = searchNode(m_searchText.getText());
      JTree m_tree = new JTree(m_model);
      TreePath root = m_tree.getPathForRow(0);
      searchTree(m_tree, root, m_searchText.getText());
    private void searchTree(JTree tree, TreePath path, String q)
    TreeNode node = (TreeNode)path.getLastPathComponent();
    if(node==null) return;
    if(node.toString().startsWith(q))
       tree.setScrollsOnExpand(true);
       tree.setSelectionPath(path);
    if(!node.isLeaf() && node.getChildCount()>=0)
       Enumeration e = node.children();
       while(e.hasMoreElements())
       searchTree(tree, path.pathByAddingChild(e.nextElement()), q);
    }Edited by: EJP on 27/06/2011 09:53: added {noformat}{noformat} tags. Please use them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Change icon of a non selected node in JTree

    Hello
    I have a swing application contening a JTree.
    I'd like to know how to change the icon of a non selected node in my tree. I have the information about the node and its path. I try to change userObject information and the icon of the node with the setIcon of (DefaultMutableTreeNode), and reload the node (DefaultTreeModel) but it doesn't work.
    Do I have to set the change in my CellRenderer ?
    Any advice will be welcome
    Anne

    If you carefully look at the java tutorial tree, the change is made for all the leaf icon. What I want is to change the icon of a not selected node of my tree while I do other stuff with the other nodes like select, display their contents, drag them ...
    the operation of a not selected node is independant from the selection in the tree.
    So I still ask how to force a node to reload and take care of the change of his icon.
    Anne

  • How to cut, copy and paste a tree node in JTree?????

    Hi, Java GUI guru. Thank you for your help in advance.
    I am working on a File Explorer project with JTree. There are cut, copy and paste item menus in my menu bar. I need three EventAction methods or classes to implements the three tasks. I tried to use Clipboard to copy and paste tree node. But I can not copy any tree node from my tree.
    Are there any body has sample source code about cut, copy, and paste for tree? If possible, would you mind send me your sample source code to [email protected]
    I would appreciate you very very much for your help!!!!
    X.G.

    Hi, Paul Clapham:
    Thank you for your quick answer.
    I store the node in a DefaultMutableTreeNode variable, and assign it to another DefaultMutableTreeNode variable. I set up two classes (CopyNode and PasteNode). Here they are as follows:
    //CopyNode class
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class CopyNode implements ActionListener{
    private TreeList jtree;
    String treeNodeName;
    TreePath currentSelection;
    DefaultMutableTreeNode currentNode;
    public CopyNode(TreeList t){
    jtree = t;
    public void actionPerformed(ActionEvent e){
    currentSelection = jtree.tree.getSelectionPath();
    if(currentSelection != null){
    currentNode = (DefaultMutableTreeNode)(currentSelection.getLastPathComponent());
    treeNodeName = currentNode.toString();
    //PasteNode class
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    public class PasteNode extends DefaultMutableTreeNode{
    private TreeList jtree;
    CopyNode copyNode;
    public PasteNode(TreeList t){
    jtree = t;
    copyNode = new CopyNode(t);
    public DefaultMutableTreeNode addObject(Object child){
    DefaultMutableTreeNode parentNode = null;
    TreePath parentPath = jtree.tree.getSelectionPath();
    if(parentPath == null){
    parentNode = jtree.root;
    else{
    parentNode = (DefaultMutableTreeNode)parentPath.getLastPathComponent();
    return addObject(parentNode, child, true);
    public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, Object child, boolean shouldBeVisible){
    DefaultMutableTreeNode childNode = copyNode.currentNode;
    if(parent == null){
    parent = jtree.root;
    jtree.treemodel.insertNodeInto(childNode, parent, parent.getChildCount());
    if(shouldBeVisible){
    jtree.tree.scrollPathToVisible(new TreePath(childNode.getPath()));
    return childNode;
    I used these two classes objects in "actionPerformed(ActionEvent e)" methods in my tree:
    //invoke copyNode
    copyItem = new JMenuItem("Copy");
    copyItem.addActionListener(copyNode);
    //invoke pasteNode
    pasteItem = new JMenuItem("Paste");
    pasteItem.addActionListener(
    new ActionListener(){
    public void actionPerformed(ActionEvent e){
    pasteName.addObject(copyName.treeNodeName);
    When I run the drive code, making a copy some node from my tree list, I got bunch of error messages.
    Can you figour out what is wrong in my two classes? If you have sample code, would you mind mail me for reference.
    Thank you very much in advance.
    X.G.

  • Mapping: Sorting nodes

    Hello all,
    please see below input document which should be converted to output below in PI.
    Nodes //node1/item should be sorted in same order like //node2/item (identified by value of <pid>) and if item does not exist in node2 (like with pid=501 below) it should get a position at the end. //node2 should be copied 1:1.
    Any ideas for this mapping in XSLT, Java Mapping or with Graphical Mapping and UDF?
    Regards
    Markus
    Input:
    <root>
      <node1>
         <item>
           <pid>201</pid>
           <name>MA</name>
           <street>
              <no>123</no>
           </street>
         </item>
         <item>
           <pid>401</pid>
           <name>MA</name>
           <street>
              <no>123</no>
           </street>
         </item>
         <item>
           <pid>501</pid>
           <name>MA</name>
           <street>
              <no>123</no>
           </street>
         </item>
         <item>
           <pid>101</pid>
           <name>MA</name>
           <street>
              <no>123</no>
           </street>
         </item>
      <node1>
      <node2>
        <item>
           <pid>101</pid>
        </item>
        <item>
           <pid>401</pid>
        </item>
        <item>
           <pid>201</pid>
        </item>
      <node2>
    </root>
    Output:
    <root>
      <node1>
         <item>
           <pid>101</pid>
           <name>MA</name>
           <street>
              <no>123</no>
           </street>
         </item>
         <item>
           <pid>401</pid>
           <name>MA</name>
           <street>
              <no>123</no>
           </street>
         </item>
         <item>
           <pid>201</pid>
           <name>MA</name>
           <street>
              <no>123</no>
           </street>
         </item>
         <item>
           <pid>501</pid>
           <name>MA</name>
           <street>
              <no>123</no>
           </street>
         </item>
      <node1>
      <node2>
        <item>
           <pid>101</pid>
        </item>
        <item>
           <pid>401</pid>
        </item>
        <item>
           <pid>201</pid>
        </item>
      <node2>
    </root>

    Hi Markus,
    This is only achievable by using UDF. Please refer to mapping below:
    for node1:
    pid(node1) --> mapWithDefault:suppressed --> concat: : --> concat: : --> removeContext --> UDF1 --> node1
    name --> mapWithDefault:suppressed ----------> /            /                                /
    no --> mapWithDefault:suppressed ------------------------> /                                /
    pid(node2) --> removeContext ------------------------------------------------------------> /
    UDF1 is of CONTEXT Type, the arguments are:
    Arr1
    Arr2
    Here is the code:
    GlobalContainer globalContainer = container.getGlobalContainer();
    String sortedArr[] = new String[Arr1.length];
    String out = "";
    int cnt = 0;
    for(int a=0;a<Arr2.length;a++){
       for(int b=0;b<Arr1.length;b++){
          if(Arr1<b>.indexOf(Arr2[a])>-1){
            sortedArr[cnt]=Arr1<b>;
            Arr1<b> = "retrieved";
            cnt++;
    for(int a=0;a<Arr1.length;a++){
       if(!Arr1[a].equals("retrieved")){
          sortedArr[cnt]=Arr1[a];
          cnt++;
    for(int a=0;a<sortedArr.length;a++){
       out += sortedArr[a] + " ";
       result.addValue(sortedArr[a]);
    globalContainer.setParameter("Result",out);
    for pid:
    Constant:PID --> mapWithDefault --> UDF2 --> SplitByValue:eachValue --> pid
    for name:
    Constant:NAME --> mapWithDefault --> UDF2 --> SplitByValue:eachValue --> name
    for no:
    Constant:NUMBER --> mapWithDefault --> UDF2 --> SplitByValue:eachValue --> no
    UDF2 is of CONTEXT TYPE, input argument is: param
    Here is the code for UDF2:
    GlobalContainer globalContainer = container.getGlobalContainer();
    String temp  = (String) globalContainer.getParameter("Result");
    String arr[] = temp.split(" ");
    if(param[0].equals("PID")){
       for(int a=0;a<arr.length;a++){
          result.addValue(arr[a].substring(0,arr[a].indexOf(":")));
    else if(param[0].equals("NAME")){
       for(int a=0;a<arr.length;a++){
          result.addValue(arr[a].substring(arr[a].indexOf(":"),arr[a].lastIndexOf(":")));
    else
       for(int a=0;a<arr.length;a++){
         result.addValue(arr[a].substring(arr[a].lastIndexOf(":"),arr[a].length()));
    Hope this helps,
    Mark

  • SORT NODE Fn. in Mapping

    Hello,
    I am trying to use this node fn sort in my gui mapping and whenever i use this fn and execute my mapping shows error:
    RuntimeException in Message-Mapping transformation: Exception:[java.lang.IllegalArgumentException: Unknown comparator type: Lexicografical] in class com.sap.aii.mappingtool.flib3.NodeFunctions method sort[com.sap.aii.mappingtool.flib3.Plainer@9a64eb0]
    Have any of you experienced such a situation?

    Hi
    check this thread,
    Message Mapping - Dump
    it maybe a different error, but it guides u in the right direction to analyse the problem.
    Sameer

Maybe you are looking for