|
Re: brain fog with building a jface tree viewer [message #460298 is a reply to message #460294] |
Tue, 23 August 2005 20:17 |
Eclipse User |
|
|
|
Originally posted by: sunil_kamath.nohotspammail.com
"Duncan Krebs" <duncan@krebsnet.com> wrote in message
news:8c3a2dd0ca01eec52e0c78e1ab791b74$1@www.eclipse.org...
> Hi,
> I'm having a tough time mapping my domain model to a jface tree viewer.
> Best way to describe it is with an example.
> I have a house and my house has a collection of doors and rooms, these two
> collections are implemented as object arrays. In my tree I want the user
> to be able to expand the house node and see two child nodes one for the
> rooms and one for the doors.
>
> I'm stuck at trying to implement this when my collections are represnted
> as object arrays instead of a single objects that wrap the underlying
> collection. For example, if changed my domain model so that the house
> collection and door collection are each represented by thier own class (eg
> HouseCollection and DoorCollection) then I could this because in the
> getChildren[] method of JfaceContent Provider I'd return the two
> collection objects.
> But if the collections are arrays then I can't define the two collections
> as two child nodes as I'd be returning a joined object array containing
> both the doors and the rooms (atleast thats what I think I would do)
>
> I can live with having to create an object to wrap all my collections but
> the pain of changing my hibernate domain model seems to be a real pain.
> There has to be a way, can anyone help clear the fog? - Duncan
In your content provider:
public Object[] getChildren(Object parentElement)
{
if(parentElement instanceof House) {
return new
Object[]{((House)parentElement).getRooms(),((House)parentEle ment).getDoors()};
}
else if(parentElement != null &&
parentElement.getClass().isArray()) {
Class clasz =
parentElement.getClass().getComponentType();
if(Door.class.isAssignableFrom(clasz)) {
return (Door[])parentElement;
}
if(Room.class.isAssignableFrom(clasz)) {
return (Room[])parentElement;
}
}
return null;
}
In your label provider:
public String getText(Object element)
{
if(element instanceof House) {
return "House";
}
else if(element != null && element.getClass().isArray()) {
Class clasz =
parentElement.getClass().getComponentType();
if(Door.class.isAssignableFrom(clasz)) {
return "Doors";
}
if(Room.class.isAssignableFrom(clasz)) {
return "Rooms";
}
}
else if(element instanceof Room) {
return "Room";
}
else if(element instanceof Door) {
return "Door";
}
return null;
}
Or something like that. I haven't tested this, but this is what I would do.
---
Sunil
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03922 seconds