• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

really need some help here concerning treeNode data types and the like. (data type issues really)

 
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I need a crash course in using TreeNode data types or HtmlRecursiveTreeNodesAdaptor data types or something,. I dont even realy friggin know.

I have some xml on a web service, I need to transform this xml into a tree (rich:tree). I have it pretty much working, but now it turns out it might need to be changed

I have xml for a project like this:




I need the project name to be the tp most node. Then you can see there are devices and channels there as well, but they are the IDs. I can already convert these IDs to the device or channel name as needed so that isnt the problem.

At first I created an Object that had a String projectName, and a Lisst for all the devices, and that works fine. But I cant just make another List for channels, because each device has its own channels, so each channel List would need to be unique to the device it belongs to. Apparently this isnt possible from what EVERYONE is telling me, so I need to use some other data type to do this. TreeNode data types or HtmlRecursiveTreeNodesAdaptor data types have been recommended, but I cannot figure out how to use these. I don't even know how they hold data and in what form or anything.

Is there a data type that will hold data in a tree form? Something I can populate with a project name at the top, then devices under that project, then channels under each device? Then I can just recursively bind this to the rich:Tree so it does this for every instance of a project.

Someone please help me here, I am on the brink here, and all the people who were supposed to help during this have been essentially useless or unavailable.



heres the advice I was given to do this btw -

research how tree node works
then figure out how htmlrecursivetreenode works
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matt Kohanek wrote:if I had some f-ing team mates who were worth a crap, or if the company hadnt delayed me 3-4 weeks from the beginning I would have this crap done, but now I am where I am and it is looking bad....


Even though your team mates may not be here, I would still like to ask you to Be Nice.

At first I created an Object that had a String projectName, and a Lisst for all the devices, and that works fine. But I cant just make another List for channels, because each device has its own channels, so each channel List would need to be unique to the device it belongs to. Apparently this isnt possible from what EVERYONE is telling me, so I need to use some other data type to do this.


Who has told you that? Because if you make the List an instance field, each object has its own List:

TreeNode data types or HtmlRecursiveTreeNodesAdaptor data types have been recommended, but I cannot figure out how to use these.


At first I saw TreeNode and thought you were talking about Swing TreeNode, but then the other classes lead me to the conclusion that this is a JSF / RichFaces issue. Therefore, I will move this thread to our JSF forum. However, not without giving you http://facestutorials.icefaces.org/tutorial/tree-tutorial.html and http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/html/rich_recursiveTreeNodesAdaptor.html

Is there a data type that will hold data in a tree form? Something I can populate with a project name at the top, then devices under that project, then channels under each device? Then I can just recursively bind this to the rich:Tree so it does this for every instance of a project.


In Swing, TreeNode and its most used implementation DefaultMutableTreeNode do just that. See http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My apologies, frustration got the better of me, I will edit that.



The problem with one channelList is each Object will have one instance of each projectName and deviceList, which is fine, but it will need multiple instances of the channelList, because each device from the deviceList will have its own channelList all in the same Object.
Would there still be a way to do it in this manner, that would make this sooo much easier for me. Like if I put the channel for loop inside the device for loop so it creates the channelList for every device it finds, will my program recognize the different instances of this List, or will it just keep adding channels to the List, until it gets back to the chanelList.clear(); line at the start of the entire process? If there is a way to make it recognze multiple instances of this same channelList in each Object it would solve all my problems
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I see it, a project has multiple devices, and a device has multiple channels. Right?

If so, just move the List<Channel> from class Project to class Device.
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is exactly what I have been playing with doing, but I don't know how to get that to work with the rich:tree correctly.

When I had an Object that has the projectName and the List of devices, it is easy to create an instance of the Object and bind a List of that Object to a tree and just iterate through it.

But if two Object are involved, Im not sure how to work that with the tree unfortunately.

I will have the original ProjectHolder Object which will now just hold the String projectName. And I will also have a DeviceHolder Object which has String value for deviceName, and a channelsList.

I can populate that DeviceHolder Object with the deviceName, and then easily fill the ChannelList with the cooresponding channels, but that leaves me with two separate Objects that are not linked together, the ProjectHolder Object that holds the projectName, and the DeviceHolder Object that holds the deviceName and the List of that devices Channels, if that makes sense.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll help you out with those implementing TreeNode then.
Although you must have noticed that I have left out the getParent implementations. You must somehow give each element a reference to its "parent", and return that. For project, there must be some root object that also implements TreeNode.


Perhaps it is possible to use a javax.swing.tree.TreeModel instead. That way you don't need to return parents or enumerations, but only children:
You'll notice how the tree model is its own root; that way you won't need to create a separate root object. Also, the empty bodies are ok because those are only for editable JTrees. The first one is used when you're editing a tree cell, the other two for notifying the tree if the tree model's structure changes.


Now I must admit, my knowledge of JSF is severely lacking, so I can't tell you how to convert these into a JSF tree. I'm sure there are other people around here who can help you with that.
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is kind of some pseudocode I came up with I think might help me figure this out, does it seem to be on the right track>?

 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh definitely. If you use DefaultMutableTreeNode, that pseudo code can quite easily be translated into real code. The creation and adding of a node will be like this:
The only thing is "tree" - that should be the root DefaultMutableTreeNode.

One more note: DefaultMutableTreeNode can store any user object, not just Strings. Perhaps it is an idea to store device, not device.getDeviceName().
reply
    Bookmark Topic Watch Topic
  • New Topic