Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Dynamic hirarchical Menu by object and array list  RSS feed

Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to develop growing menu hirarchical structure.
For that I have created one class, which have one list and different attributes,

If retrived all data from table in one list, how could I manage this data in one list, having objects. Each object contain one list, and further more. Data are growable, Please suggest code for achieving this structue.
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I couldn't get what you mean.
Maybe others are like me too.
Posts: 9521
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gajen, please don't post the same question more than once. It causes confusion and duplication of effort as the community tries to help everyone.
I agree with mohsen. I can't figure out what you are asking. Either you are being too vague with your questions or you are trying to get us to write your code for you.
You would do well to read our FAQ, How To Ask Questions On JavaRanch. The better question you ask, the better we can help you.
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you're talking about is the composite pattern.

The composite is a design structure that allows you to define objects that contain other objects, some of which may in turn contain more objects, and some which may not ("leaf nodes" in your menu tree).

I wish I could draw a UML diagram for you, but This Java World article explains it and has a diagram.

Basically you define a base class that is abstract and defines the contract for a primitive element in your containment structure. then, you extend that base class with two descendants, one that simply implements the contract specified by the base class (this will be your leaf node), and one that is a composite (a node that can contain other nodes).

Just a note too, after seeing your code... adhere to bean standards... no public members unless absolutely necessary... use accessor/mutator pairs. So your code would look something like this:

Base class

Leaf node class:

Composite node class:

Then all you have to do is run your DB query or whatever, and materialize the structure. Your primary containment for your main menu items is a Composite (CompositeMenuItem). Then just start adding components. If the component you're adding has sub-nodes, add a composite. If it doesn't, add a Leaf.

Play with that and see how it works.
Good luck
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!