Generate rich:menu hierarchical structure from rich:tree - java

What i want to do:
I want to make the menu of my application customizable, giving the user the possibility of changing the order of the menus. For this i have build a tree (rich:tree) representing the menus in my application. By drag-n-drop the user can change the order of the menus.
The menus are kept in a xhtml file (a hierarchical structure of rich:menuGroup and rich:menuItems)
What my problem is:
When the user finishes drag-n-drop, on save i should generate xhtml code corresponding to my tree. More concrete: For each parent node in the tree generate a rich:menuGroup and for each leaf node generate a rich:menuItem. By traversing the tree i should build a hierarchical structure with menu groups containing other menu groups and/or menu items.
Is there any tool or easy way for doing this?
It would be a real pain to traverse the tree and manually concatenate hard-coded strings or something like that.
Thanks

You can use ui:repeat tag, and create menuGroups from an array in the backing bean that you created according to the tree structure. In the array, properties of each menuGroup should be provided.

Related

Is there a way to retrieve the tab order of HTML elements in Java?

Right now we have an element on the page that is not allowing users to tab out of it. The element was created in Java as a GWT component, I don't really know too much about GWT so I can't really describe it further.
Anyways, I know where I need to tell the component to tab to the next element in the tab order, but I don't know what commands to use to do so. Is there a way to retrieve the tab order of HTML elements in Java? If there is, I can just pick the next element in the list and set it to be focussed.
Using GWT com.google.gwt.dom.client.Element you can access and set the tabIndex value of any GWT component (i.e. html element). If you're using a Widget class you can use myWidget.getElement().getTabIndex() and setTabIndex(1).
In HTML you cannot just pick the next element with the tab out of the box, you can however maintain the tab indexes order in the order you expect.

Uniquely representing tree elements

I want to make my TreeView remember the selected items after refresh/setInput. (Let's pretend the Java TreeView doesn't remember the state). Since the TreeView will get setInput, so the element reference won't persist.
I am thinking to store the selected element by its full path in an ArrayList<String>. (e.g. it looks like ["root_name", "2nd_level_name", "3rd_level_name", "node_name"]). With the full path, I can locate the same element in the refreshed TreeView again.
I was wondering if there's any better way doing this? Or any existing libraries in Java can do this?

how to get the list of parents in hierarchy

I am working in the java swings application and in the application we have the front menu that contain the list of the other button and the drop down menus. in the application we have the various events that are associated to one another and leads to the opening of the various frames. i want to get the list of the parents through which the particular page is open as i am right now using parent-of-parent but that will give me reference to the two level above the hierarchy but not the entire list. please help...

Custom Java Swing XML Editor

I need to show an xml as a tree structure in a java swing application. When I click on any node in the swing tree its attribute should list in a window (like a properties editor) and from that I need to update the attributes. Also I need to hide some nodes in the xml in the tree.
I am planning to use JTree to populate and show the xml as tree. But bit confused about what approach need to take to read/update the xml.
Currently I have the below options:
Using JAXB create the corresponding objects and populate the JTree
Use any parser DOM or SAX and populate the JTree using the DefaultMutableTreeNode
Please advice what approach I need to proceed? or is there any other better way for doing this?

Finding the node where an instance belong

I generated a decision tree based on a set of data, then I converted this data to a xml file, after that I put it into a JTree. This part works fine but now I have to take a new instance(which contains the data received from the user), find it's place in the decision tree and change that node's color. And I can't find a way to do that. I am using weka and the J48 classifier to generate the decision tree. The xml is created in the Luc Sorel style: http://www.lucsorel.com/media/downloads/sample_decision_tree.xml
The first thing I tried was to classify the instance using the algorithm but that gets me only the class where it belongs, and I don't know how to locate it in the JTree.
What should I do? Any ideeas?
Like JTable, JTree uses a flyweight renderer to draw nodes. As the default renderer is a JLabel, you can set the foreground color or make the label opaque and set the background color. This related example changes the icon for emphasis. More examples may be found here.
Addendum: I cannot find … the node that I should color.
When getTreeCellRendererComponent() is called, value is a reference to the node to be rendered, and the tree parameter allows access to the TreeModel as a whole via getModel(). This example shows how to search a tree.

Categories