I have a method that generates pop-up menu with many submenus. Basically these menus given dynamically so I have to have algorithm to handle creating submenus using below string.
In order to do it I will need to transform this string into Java Tree by splitting using the delimiter. I am stuck on how to handle splitted string data and translate to the Java Tree Model according to Parent and children nodes.
An Example of Dynamic String Values that I need to parse:
String str = ” Menu1; Menu2; [Menu2A; Menu2B; [Menu2B-A; Menu2B-B];]; Menu3; “;
After Handling operation The output should be:
Pop-up Menu
/ | \
Menu1 Menu2 Menu3
/ |
Menu2A Menu2B
| \
| \
Menu2B-A Menu2B-B
You could do something like:
;put the current string in a data structure holding(level, array of menu entries for level).[call recursively with the rest of the string and level + 1.]return.Some approximate Java code: