Sorting the nodes...

hi group,
the tree has root.The top root has multiple nodes in it..say suppose..nearly 100 nodes in it..
for ex:
abc
def
ghi
jkl
mno
pqr
stu
vwx
xyz
i want to sort these nodes in btn action means it should sort and at the same time it should fix in the root node with sorting order.
Any body has idea on it??
shalini.

if its a DefaultMutableTreeNode, you can get the children Vector (protected variable) and sort it using the Arrays utility class. i think it has a vector or object array sorting method in which you can specify the comparator.
it might be more useful to override the add() method of your node so that when a node is added, you sort the children so the user never has to explicitly do it.

Similar Messages

  • Sort the Nodes and remove duplicate nodes

    Hello Experts,
    I have a requirement to sort the nodes based on a key value.
    e.g.
    <Node>
        <Key>2<Key>
        <Value1>name1<Value1>
        <Value2>email1<Value2>
    </Node>
    <Node>
         <Key>1<Key>
         <Value1>name2<Value1>
        <Value2>email2<Value2>
    </Node>
    <Node>
         <Key>2<Key>
         <Value1>name3<Value1>
        <Value2>email3<Value2>
    </Node>
    and the Output should be
    <TNode>
         <Key>1<Key>
         <Value1>name2<Value1>
        <Value2>email2<Value2>
    </TNode>
    <TNode>
         <Key>2<Key>
         <Value1>name3<Value1>
        <Value2>email3<Value2>
    </TNode>
    I tried using SortByKey function for Node i.e.
    Key --> SortByKey , Node --> TNode
    But I dont get sorted value for Value1 and Value2.
    Can anybody give solution for this?
    I have around 25000 records as input and there are around 25 values in structure.
    Please help.
    Thanks in advance,
    Beena.

    Beena,
    Here you go. If it doesn't helps then let me know.
    Mapping.
    http://www.flickr.com/photo_zoom.gne?id=2185600055&size=o
    http://www.flickr.com/photo_zoom.gne?id=2185600049&size=o
    http://www.flickr.com/photo_zoom.gne?id=2185600063&size=o
    http://www.flickr.com/photo_zoom.gne?id=2185600067&size=o
    Results
    http://www.flickr.com/photo_zoom.gne?id=2185600075&size=o

  • Sorting the nodes of a JTree

    Can anyone tell me how to go about sorting the nodes in a JTree?

    The best way to do it is thru the treemodel. Either adjust the order in a DefaultTreeModel, or create your own TreeModel.

  • Is there a way to "mix" the nodes and leaves of the tree so if they are at the same level, they will display in a specified order.

    Is there a way to "mix" the nodes and leaves of the tree so that even if they are at the same level (1,2,3...), they will display in a specified order (via sort sequence, alphabetical, etc.).
    History:
    We are using the Tree UI element to display/manage a material bom interface. We seem to be running into an issue with displaying the nodes/leaves of the tree.. regardless of the order that the context is built (which is currently the order of the exploded BOM from from CS_BOM_EXPL_MAT_V2), the bom is displayed with the nested boms at the top of each level and the single materials below them. For example. If  TK1 contains Material1, Material2, Material3, Kit1(containing component1, comp2, comp3), Material4, Kit2(containing comp4, comp5, comp6), and Material5 (in this order), the tree will display with the A level node as TK1, the next node as Kit1 (with its subleaves of comp1,comp2,comp3), Kit2(with subleaves of comp4,comp5,comp6), THEN Material1, material2, material3, material4, material5.  Our users are adamant about the items displaying in the correct order (which should be alphabetical based on the description for one report and by location for purposes of inventory for another). I've searched but not been able to locate a similar question. If I've missed it, please point me in the right direction. The users want the tree,  not a "tree" table.  This is our first attempt at the tree, so maybe we're missing something basic?
    TK1
    -Mat1
    -Mat2
    -Mat3
    -Kit1
    --Comp1
    --Comp2
    --Comp3
    -Mat4
    -Kit2
    --Comp4
    --comp5
    --comp6
    -Material5
    displays as
    TK1
    -Kit1
    --Comp1
    --Comp2
    --Comp3
    -Kit2
    --Comp4
    --Comp5
    --Comp6
    -Mat1
    -Mat2
    -Mat3
    -Mat4
    -Mat5

    co-workers said example picture is misleading.. we can make the order work if everything is a "folder" but not a mix of "folders" and "files" (if making a visual reference to the windows browser). i.e - a file is represented as an empty folder.
    TK1    
    . Mat1
    . Mat2
    . mat3
    > kit1   
    .. comp1
    .. comp2
    .. comp3
    . mat4
    > kit2
    .. comp4
    .. comp5
    .. comp6
    . mat5
    displays at
    TK1
    > kit1
    .. comp1
    .. comp2
    .. comp3
    > kit2
    .. comp4
    .. comp5
    .. comp6
    . mat1
    . mat2
    . mat3
    . mat4
    . mat5
    we can make it work if everything is a folder. This is our current workaround.
    TK1
    > mat1
    > mat2
    > mat3
    v kit1 (when expanded)
    .. comp1
    .. comp2
    .. comp3
    > mat4
    > kit2 (when not expanded)
    > mat5

  • Sort the Valuenode records in table

    Hi Experts,
    Following is the code I wore to retrive and display Portal roles in a table. The context maintained is as follows and got the results properly. I want to know how to sort the table values by Role_Name?. Could some one help me?
    [Value node]      Role_table
    [Value Attribute] RoleID
    [Value Attribute] Role_Name
    [Value Attribute] PCD_Location
    //Retrive the roles from the Role factory          
    String[] theroles = rolefact.getRolesOfUser(unique_id,true);
    for(int i=0; i<theroles.length; i++ )
    //Retrive user attributes and add to the context attribute values     
    String roleid = rolefact.getRole(theroles<i>).getDisplayName();          
    String rolename = rolefact.getRole(theroles<i>).getDescription();
    String role_desc = rolefact.getRole(theroles<i>).getUniqueName();
    IPrivateUserView.IRole_tableElement rowelement = wdContext.createRole_tableElement();
    rowelement.setAttributeValue("RoleID",roleid);
    rowelement.setAttributeValue("Role_Name",rolename);
    rowelement.setAttributeValue("PCD_Location",role_desc);
    //Append the roles obtained and bind to the rolenode
    al.add(rowelement);
    wdContext.nodeRole_table().bind(al);
    Please help me with some code on how to sort the value node table?. I promise to award the points for the right solution. I appreciate coding help.
    Thank you
    Regards
    Maruti

    Hi Maruti,
    1. Get the size of the node, save it in a variable say <b>si</b>
    int si = wdContext.nodeRole_table().size();
    2. Iterate as follows
    for(int i=0;i<si;i++)   
         for(int j=i+1;j<si;j++)
             if(wdContext.nodeRole_table().getRole_tableElementAt(i).getAttributeAsText("Role_Name").compareToIgnoreCase(wdContext.nodeRole_table().getRole_tableElementAt(j).getAttributeAsText("Role_Name"))<0)
             wdContext.nodeRole_table().swapElements(i,j);
    Regards,
    Mathan MP

  • Creating a KD Tree and only sorting the points once for each axis

    So right now I have some code for creating a KD Tree (2-Dimensions) but I am sorting the x and y values for the node each time I create a new node. Then I am taking the median, setting that as the nodes point, and passing on the left half and right halves of the remaining array to their respective children. I am using Arrays.Sort which I believe takes O(n log(n)) time per sort (once per node), but I have been reading a lot of stuff that states you can get the median in linear time so that the total build time is O(n log(n)). Unfortunately I am having difficulty understanding how. Here is a snippet of an explanation I found.
    Each node has both x-list (ordered in x-coord.) and y-list (ordered in y-coord.)
    Each pi in x-list and y-list is linked to each other.
    Both x-list and y-list can be built in linear time using the two lists of its parent.
    Thus total time to build all x-lists and y-lists is:
    T1 (n) = O(n) + 2T1 (n/2) = O(n log n).
    Since each splitting line can be found in O(1) time (via sorted lists), and there are n &#8722; 1 splitting lines in a kd-tree,
    Thus total time to find all splitting lines is
    T2 (n) = (n &#8722; 1) · O(1) = O(n).
    Hence, total prepossessing time
    = T1 (n) + T2 (n) = O(n log n).My question is, how can I build the arrays in linear time at each node? I have tried working it out on paper for the past few hours but lets say I sort the array using X first and I know that indices 0 - median will be on the left, however even if I had sorted the array by Y also, there is zero guarantee that all the points I need from x[0-median] will be in y[0-median]. They will obviously be included in x[0-median] but they will be sorted by x and not y, forcing me to resort at every single node.
    Any idea?

    swinte1 wrote:
    My question is, how can I build the arrays in linear time at each node? I have tried working it out on paper for the past few hours but lets say I sort the array using X first and I know that indices 0 - median will be on the left, however even if I had sorted the array by Y also, there is zero guarantee that all the points I need from x[0-median] will be in y[0-median]. They will obviously be included in x[0-median] but they will be sorted by x and not y, forcing me to resort at every single node.
    Any idea?So for example, you have 5 points and you sort them by x and y coordinates in two separate arrays:
    x-list: 6 1 4 3 2 5
    y-list: 6 5 1 2 3 4
    Now you want just the points to the right of 4:
    x-list: 3 2 5
    y-list: 5 2 3
    Create the x-list by iterating from the midpoint to the end.
    Add each element in the x-list to a set..
    Iterate through the y-list from left to right:
    If the point in the y-list is contained in the set, add it to the new y-list.
    This creates the arrays in linear time while keeping the points sorted. It does iterate over twice as many points in the y-list as needed though.

  • How to use XmlModify to sort the XML Data?

    Hello,
    I saw some examples explain how to use XmlModify in BDB XML package. I want to sort the XML data by several elements but my Java program could not work correctly.
    <CustomerData>
    <Transaction>
    <DLSFIELDS>
    <ADR_PST_CD>12345</ADR_PST_CD>
    <CLT_IRD_NBR>002</CLT_IRD_NBR>
    </DLSFIELDS>
    </Transaction>
    <Transaction>
    <DLSFIELDS>
    <ADR_PST_CD>12345</ADR_PST_CD>
    <CLT_IRD_NBR>102</CLT_IRD_NBR>
    </DLSFIELDS>
    </Transaction>
    // many nodes like transaction ...
    </CustomerData>
    My XQuery script was executed successfully in the shell. The script looks as follows:
    "for $i in collection('sample.dbxml')/CustomerData/Transaction order by xs:decimal($i//ADR_PST_CD), xs:decimal($i//CLT_IRD_NBR) return $i".
    The Java code :
    // create XmlManager
    XmlManager manager = // ...;
    // open XmlContainer
    XmlContainer container = // ...;
    XmlQueryContext context = manager.createQueryContext(XmlQueryContext.LiveValues, XmlQueryContext.Eager);
    XmlQueryExpression expression = manager.prepare("for $i in collection('sample.dbxml')/CustomerData/Transaction order by xs:decimal($i//ADR_PST_CD),xs:decimal($i//CLT_IRD_NBR) return $i", context);
    XmlModify modify = manager.createModify();
    XmlUpdateContext uc = manager.createUpdateContext();
    XmlDocument xmldoc = container.getDocument("sample.xml");
    XmlValue value = new XmlValue(xmldoc);
    long numMod = modify.execute(value, context, uc);
    System.out.println("Peformed " + numMod     + " modification operations");
    Could you point out the errors above or offer some suggestion?
    Thanks.

    I have other question of the sorting issue. Here are a large XML need to sort so I have to split it to multiple small XML files. After importing these files, I will use the XmlModify and XQuery to sort them. I'm not clear on the multiple XML files processing.
    1. Can the BDB XML ensure that all these XML files were sorted or how to update all documents with same logic.
    2. If I want export all these sorted documents, how can I ensure these files processed in sequence? Which document needs process first?
    The export method:
    public void export(String outputfile)throws Exception{
    final int BLOCK_SIZE = 5 * 1024 * 1024; // 5Mb
    try{
    File theFile = new File(outputfile);
    FileOutputStream fos = new FileOutputStream(theFile);
    byte[] buff= new byte[BLOCK_SIZE];                         
    XmlResults rs = container.getAllDocuments(new XmlDocumentConfig());               
    while(rs.hasNext()){
         XmlDocument xmlDoc = rs.next().asDocument();
         XmlInputStream inputStream = xmlDoc.getContentAsXmlInputStream();                    
         long read=0;
         while(true){
         read = inputStream.readBytes(buff, BLOCK_SIZE);
    fos.write(buff,0,(int)read);                    
         if(read < BLOCK_SIZE) break;
    inputStream.delete();
    xmlDoc.delete();
    rs.delete();
    //MUST CLOSE!
    fos.close();               
    catch(Exception e){
    System.err.println("Error exporting file from container " + container);
    System.err.println(" Message: " + e.getMessage());
    Thanks.

  • Sorting XML nodes in Java

    I have a java code that reads various xml files, filters cetain elements and writes the results of these files to one large xml file. Problem is, when the files are read into the large xml, all the nodes are sorted alphabetically. I tried looking for an API that's responsible for this but I cant find one. Can anyone please help?? Here's the portion of my code that writes the file:
             private static void writeFile(Document doc, ArrayList docIdList,
                   BufferedWriter output) {
              try {
                   Element loElmt = null;
                   NodeList loDocumentList = XMLUtil.getNodeList(doc,
                             "/XML_EXPORT_FILE/DOCUMENT");
                   for (int i = 0; i < loDocumentList.getLength(); i++) {
                        Element loDocument = (Element) loDocumentList.item(i);
                        String lsDocCode = loDocument.getAttribute("DOC");
                        String lsDocId = loDocument.getAttribute("DOCS");
                        //System.out.println(lsDocCode + "\t\t" + lsDocId);
                        // doc identifer is in list
                        if (isDocInList(docIdList, lsDocCode, lsDocId)) {
                             String document = XMLUtil.transformToString(loDocument);
                             System.out.println("Writing " + lsDocCode + "\t\t"
                                       + lsDocId + " to output file");
                             output.write(document);
              } catch (Exception e) {
                   e.printStackTrace();
              }

    I have a java code that reads various xml files, filters cetain elements and writes the results of these files to one large xml file. Problem is, when the files are read into the large xml, all the nodes are sorted alphabetically. I tried looking for an API that's responsible for this but I cant find one. Can anyone please help?? Here's the portion of my code that writes the file:
             private static void writeFile(Document doc, ArrayList docIdList,
                   BufferedWriter output) {
              try {
                   Element loElmt = null;
                   NodeList loDocumentList = XMLUtil.getNodeList(doc,
                             "/XML_EXPORT_FILE/DOCUMENT");
                   for (int i = 0; i < loDocumentList.getLength(); i++) {
                        Element loDocument = (Element) loDocumentList.item(i);
                        String lsDocCode = loDocument.getAttribute("DOC");
                        String lsDocId = loDocument.getAttribute("DOCS");
                        //System.out.println(lsDocCode + "\t\t" + lsDocId);
                        // doc identifer is in list
                        if (isDocInList(docIdList, lsDocCode, lsDocId)) {
                             String document = XMLUtil.transformToString(loDocument);
                             System.out.println("Writing " + lsDocCode + "\t\t"
                                       + lsDocId + " to output file");
                             output.write(document);
              } catch (Exception e) {
                   e.printStackTrace();
              }

  • Sorting FTREE nodes

    is there a way to populate a FTREE object such that the nodes are sorted without loss of hierarchy? I read in a note that the "ORDER BY" clause cannot be used. On the other hand, the items are often "shuffled", and it may be hard for the users to retrieve what they are searching.
    Is there some alternative way to obtain it (for example, by splitting the building process level-by-level instead of using a single query)?

    As Andreas suggested, you can use ORDER SIBLINGS BY in your tree query to order the level 2 and up nodes with a specific order.
    Oracle Forms 10g and 9i does support this SQL syntax.
    sample:
    CONNECT BY PRIOR M.NODE_ID = M.NODE_PARENT
      START WITH M.NODE_PARENT IS NULL
    ORDER SIBLINGS BY M.NODE_ORDERTony

  • Sorting the file in file content conversion.

    Hi all,
    we have a file(xml)-pi-file(flat file) scenario,
    where we need to sort the output file by employee id field.
    Where can we achieve the sorting of file by particular field.
    Do we have any option in Mapping(Functions) ??
    Any option is Reciever File Adapter??
    Reciever File content conversion??
    Any inputs will be of gr8 help.
    Regards.
    santosh.

    Hello,
    Where can we achieve the sorting of file by particular field.
    Do we have any option in Mapping(Functions) ??
    Yes, there is a function in message mapping called sort and sortByKey, these can be found under node functions. To sort the ID, you can use this code
    ID --> removeContext --> sort:(ascending or descending) --> ID
    Use sortByKey to sort the additional details of the flatfile according to ID number e.g.
    ID --> removeContext --> sortByKey:(ascending or descending) --> IDDetails
    Details --> removeContext --> /
    Any option is Reciever File Adapter??
    Reciever File content conversion??
    The receiver file adapter with FCC only converts the structure that is defined in your target message type into, say for example a text file. You have to do the manipulations in the message mapping.
    Hope this helps,
    Mark

  • How to sort Jtree node?

    Now, I want to sort tree node by increasing.
    for example there are three child node:
    [20 -40][
    10 - 20]
    [30- 60].
    they are added to JTree node by different order.but are shown in increasingorder.
    like this:
    [10 - 20]
    [20 -40][
    [30- 60].
    how to control tree node.

    Implement the Comparable interface in t he userobject class and possibly the toString(0 as well.
    Ex.
    public class UserObject implements java.lang.Comparable{
    public int compareTo(Object obj) throws ClassCastException
    public String toString()

  • Problem in sorting the records

    Hi All,
    I have to sort some records based on a key. If the key field is optional then how to sort the records. For example consider the follwing records.
    <row>
          <name>jaya</name>
          <address>hyd</address>
          <material>d</material>
          <units>4</units>
          <price>6</price>
    </row>
      <row>
          <address>ss</address>
          <material>wd</material>
          <units>7</units>
          <price>9</price>
       </row>
    <row>
          <name>radha</name>
          <address>pune</address>
          <material>g</material>
          <units>9</units>
          <price>3</price>
    </row>
    Here name field is used as a key in sorting the records. in the second record name field does'nt exists. All the records that doesnt have the name field shud come on the top and the rest with name field shud come sorted.
    Can anyone please helpout how to solve this problem??

    Jhansi,
    Did u solved the issue? The scenario is lil bit complicated, please consider my below suggestion, if you haven't achieved your results.
    I must really thankful to Michal and all my SDN friends,who guided me to use the logic-using multiple Mapping program in one Interface mapping.
    /people/michal.krawczyk2/blog/2005/11/01/xi-xml-node-into-a-string-with-graphical-mapping
    Ok, let us come to the logic.
    For your problem we need to use two mapping programs.
    <b>Mapping Program 1</b>
    http://www.flickr.com/photo_zoom.gne?id=897495319&size=o
    <b>Mapping Program 2</b>
    http://www.flickr.com/photo_zoom.gne?id=897495327&size=o
    http://www.flickr.com/photo_zoom.gne?id=897495341&size=o
    <b>UDF1 - Testing</b>
    http://www.flickr.com/photo_zoom.gne?id=897495429&size=o
    String temp;
    for(int i=0;i<Name.length;i++)
    for(int j=i1;j<Name.length;j+)
    if(Name<b>[</b>i<b>]</b>.compareToIgnoreCase(Name[j])>0)
               temp = Name<b>[</b>i<b>]</b>;
                Name<b>[</b>i<b>]</b>= Name[j];
                Name[j]=temp;
    for(int i=0;i<Name.length;i++)
    if(Name<b>[</b>i<b>]</b>.equals("0"))
    result.addSuppress();
    result.addContextChange();
    else
    result.addValue(""Name<b>[</b>i<b>]</b>"");
    result.addContextChange();
    <b>UDF 2 - Testin1</b>
    http://www.flickr.com/photo_zoom.gne?id=897495437&size=o
    String temp,temp1;
    for(int i=0;i<Name.length;i++)
    for(int j=i1;j<Name.length;j+)
    if(Name<b>[</b>i<b>]</b>.compareToIgnoreCase(Name[j])>0)
               temp = Name<b>[</b>i<b>]</b>;
                Name<b>[</b>i<b>]</b>= Name[j];
                Name[j]=temp;
          temp = Values<b>[</b>i<b>]</b>;
                Values<b>[</b>i<b>]</b>= Values[j];
                Values[j]=temp;
    for(int i=0;i<Values.length;i++)
    result.addValue(""Values<b>[</b>i<b>]</b>"");
    result.addContextChange();
    <b>Interface Mapping</b>
    http://www.flickr.com/photo_zoom.gne?id=897495361&size=o
    <b>Finally -Results:</b>
    http://www.flickr.com/photo_zoom.gne?id=897498639&size=o (My Data)
    http://www.flickr.com/photo_zoom.gne?id=897498659&size=o (Your Data)
    I hope it helps you!!!!
    I don't know whether this is the correct way or any other simplest way to do so. Also I request our friends to feedback their inpute regarding this logic.
    Jhansi,if you have any doubts in achieving the same, kindly reply back.
    Best regards,
    raj.

  • How to sort master-node in master-detail scenario without losing subnodes?

    Hi,
    I've a master-detail scenario and want to sort my master node.
    How can I sort the master node without losing the detail-subnodes?
    If I take a look in class CL_WDR_TABLE_METHOD_HNDL and method  IF_WD_TABLE_METHOD_HNDL~APPLY_SORTING
    Sorting is done by
    - unload node with context_node->get_static_attributes_table into an internal table
    - keeping node state like lead_selection(s) and attribute_properties
    - sort internal table
    - bind internal table to node
    - set lead_selection and properties
    But all subnodes are gone.
    How do you sort a master node?
    Thanks and Regards
    Carsten

    I think you have to write your own logic for that . May be you can implement IF_WD_TABLE_METHOD_HNDL in your class and extend the current logic to support subnodes.

  • How can I find the node I am dragging over during MouseDragged ?

    It seems that while dragging you only get MouseDragged events on the node where the drag originated. I have a situation where a drag starts on one node and ends on another.. I am having a lot of trouble finding a reasonable way to get the node where the drag leads to.
    E.g. imagine a UI where I am dragging a "connection" from one node to another. I can't use Drag and Drop (which otherwise would report DragEntered andDragExited events), because during a Drag and Drop I don't get any MouseMoved or MouseDragged events, so I can't draw my connection line interactively.
    I was hoping I could get MouseEntered and Exited events somehow during the MouseDrag, but they aren't delivered, and even attaching an EventFilter to the nodes in question didn't work. During the drag all events are reported on the listener registed with the source of the drag, but in the drag event even the event Target is set to the same value as the event Source, regardless of what the mouse is dragged over during the operation.
    If there is no way to get the need events, is there a built-in way to get the "deepest" node in a scene given the scene coordinates?
    Thanks,
    Scott

    Thanks for the response.
    I really think that having target nodes involved with the press-drag-release gesture is important. It seems broken the way it is now. As soon as a drag of any sort begins (MouseDragged, or Drag-and-Drop) suddenly a lot of useful information is unavailable. Why not set the target of the MouseDragged event to what the mouse is actually over? Currently, one the drag is initiated the source and target are fixed forever and no other events are available to find what the mouse is hovering over. (Hmm.. I should check if even the "hover" state is changed on components,as I want my CSS to indicate that a node is the intended destination of the connection that I'm dragging)
    The other ugly bit is that now I have to get other objects involved in the operation, whereas before I could just attach event handlers to my nodes, now I need to have a parent involved just so I can see where the mouse is going. I also need to deal with the mouse cursor, which will be giving the user bad feedback, that a drag and drop is happening, when that's not really the concept that I want to convey.

  • Merging X XML files, sorting the resultlist and finally execute a distinct?

    I have several questions about an XSLT file that I should write:
    1� First, I get X paths to XML files. It can be 2, 3, 4, ... whatever a number. I don't know exactly the total amount of XML files.
    I need to merge them dynamicly to one resultset.
    2� Next, I need to sort them on a specific node (remark: every XML file has the same DOM tree)
    3� Finally, I want to distinct the values because some of the nodes are in file 1, 2, 3 ... So I don't want duplicates.
    I guess this is not possible in XSLT? I can't use Java, so it should be done using XSLT ;;;

    Have a look here:
    [http://www.jenitennison.com/xslt/index.html|http://www.jenitennison.com/xslt/index.html]
    under the "Sorting" and "Grouping" sections. Also consider using XSLT 2.0, which has built-in grouping elements which make the convoluted XSLT 1.0 techniques unnecessary.

Maybe you are looking for