views:

99

answers:

2

Hello Guys,

I am haveing this problem with my application and need help. I have data from the server in this form

Food Apple Fruit Seed etc..

Table Chair pen School et..

...

Food Mango Peer Melon etc..

Reading from the left, i want to make for eg; in the first row,

Food parent of Apple

Apple parent of Fruit

Fruit parent of Seed

and if there are more data then etc.. I will itereate over the above data from the server with loop; Example:::

+Food
  Apple
       Fruit
            Seed
                etc..

+Table
    Chair
        Pen
           School
                 etc..

The data will be shown in Tree like form in eclipse views. In the above code, "Food" and "Table" belong to the same level. My problem is how do i begin. I have googled the whole day but can't find something that i really understand. How can i for instance make "Food" parent and make Apple its child and then make Fruit the child of apple and so forth.

Need your help.

Thanks

+2  A: 

For the beginning read some theory Composite Design Pattern

Boris Pavlović
+1  A: 

In eclipse, you will use a TreeViewer to display the tree. This article explains how to use it.

You may be confused because you're finding a lot of articles talking about how to model a parent/child relationship with subclassing. You do not want that here; you want a single class that represents a node in your tree that contains a number of other instances of the same class as child nodes.

Michael Borgwardt