tags:

views:

127

answers:

1

Hello Guys,

I have the following model which makes an element a parent of the element that follows it. For example i get data from a server in an array of arrays like this:

net      Person       age
net      Person       height

net      Address      streetname

org      Company      name

org      Company      location

com      School       color

com      School       number

please kindly read the link below for the message yesterday and see the model classes and the structure. The question i asked in this link is not what i want now. I just want you to see the data model and the structure.

http://stackoverflow.com/questions/1230164/comparing-linked-objects

MY QUESTION NOW IS::

I want to create a table from the model but am finding it difficult to implement the Content and Label providers. So am asking how i can do it. Each column will contain the children of the previous column and etc..

Thanks for your help.

I tried this in the content provider but its not working:

public Object[] getElements(Object parentElement) {

              if(parentElement instanceof cPackage) {
   cPackage pack = (cPackage)parentElement;
   return pack.getChildren().toArray();
  }else if(parentElement instanceof cClass) {
   cClass klas = (cClass)parentElement;
   return klas.getChildren().toArray();
  }else if(parentElement instanceof cMethod) {
   cMethod met = (cMethod)parentElement;
   return met.getChildren().toArray();
  }
  return EMPTY_ARRAY;
}

Thanks for your help.

+1  A: 

If by "not working" you mean it's always returning EMPTY_ARRAY, then I suspect parentElement is not what you think it is. Try adding

System.out.println(parentElement.getClass().getSimpleName());

at the top of the method and seeing what you get.

On a side note, since cPackage, cClass, and cMethod all implement getChildren(), you don't actually need all those if statements -- just

if (parentElement instanceof Model) {
  return ((Model)parentElement).getChildren().toArray();
}

should do it. In fact, if you expect only Model subclasses to be passed in, you could leave out the if statement as well, though you might need to check for null.

David Moles