Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » brain fog with building a jface tree viewer
brain fog with building a jface tree viewer [message #460294] Tue, 23 August 2005 18:31 Go to next message
Duncan Krebs is currently offline Duncan KrebsFriend
Messages: 79
Registered: July 2009
Member
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
Re: brain fog with building a jface tree viewer [message #460298 is a reply to message #460294] Tue, 23 August 2005 20:17 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: brain fog with building a jface tree viewer [message #460301 is a reply to message #460298] Tue, 23 August 2005 20:20 Go to previous messageGo to next message
Duncan Krebs is currently offline Duncan KrebsFriend
Messages: 79
Registered: July 2009
Member
Thanks so much for taking the time to do that it got me on the right
track. - Duncan
Re: brain fog with building a jface tree viewer [message #460773 is a reply to message #460294] Wed, 07 September 2005 02:49 Go to previous message
Brian Hudson is currently offline Brian HudsonFriend
Messages: 17
Registered: July 2009
Junior Member
I would probably create two 'dummy' classes (Doors, Rooms) to do the
behavior you describe (they could just take in the object[] in their
constructor, these could also even be private classes defined in the
model class)...


Duncan Krebs wrote:
> 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
>
>
>
>
>
Previous Topic:Combo - Showing list on focus
Next Topic:changing icons in a tree
Goto Forum:
  


Current Time: Sat Jul 20 20:17:05 GMT 2019

Powered by FUDForum. Page generated in 0.02050 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top