Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Tree: "Good Practice" when base domain doesnŽt represent Tree structure?
Tree: "Good Practice" when base domain doesnŽt represent Tree structure? [message #461072] Thu, 15 September 2005 13:27 Go to next message
Andreas is currently offline AndreasFriend
Messages: 29
Registered: July 2009
Junior Member
Hi everybody,

iŽm having this problem:


I got a domain data model which has no Tree structure, yet.


However, with a little bit of transformation the Domain Model could also
be represented as a tree.
I therefore would mainly need to add the "getParent" and "getChildren"
information (which i then could access in the Content Provider) to the
objects of the domain model.


But now i donŽt know what is the "best practice" on how to do this or
whether there is a certain pattern for it.
Polluting my base domain model with the "getParent" and "getChildren"
information doesnŽt seem like a good idea to me, as the base domain model
would get specific Tree infomration it doesnŽt need.


Is the best practice to establish a seperate Tree Model with the
"getChildren" and "getParent" information?

But then: When a user selects an item in the tree, how can i map this item
(which then would represent an Item of the TreeDataModel) back onto the
"base" domain model?

I hope you understand what iŽm trying to communicate and am happy about
every answer/inspiration/advice on how to do something like this in the
best way.

Greetings
Andreas
Re: Tree: "Good Practice" when base domain doesnŽt represent Tree structure? [message #461076 is a reply to message #461072] Thu, 15 September 2005 13:32 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
Hello,

I would go with a separate TreeModel that simply wraps the domainmodel
it represents and delegates everything needed to the domainmodel.

Something like

class Node{

....
public Node(Object domainModel)
{
this.dm = domainModel;
}
....
// getChild and getParent would go here
}

Regards
Stefan


Andreas wrote:
> Hi everybody,
>
> iŽm having this problem:
>
>
> I got a domain data model which has no Tree structure, yet.
>
>
> However, with a little bit of transformation the Domain Model could also
> be represented as a tree.
> I therefore would mainly need to add the "getParent" and "getChildren"
> information (which i then could access in the Content Provider) to the
> objects of the domain model.
>
>
> But now i donŽt know what is the "best practice" on how to do this or
> whether there is a certain pattern for it.
> Polluting my base domain model with the "getParent" and "getChildren"
> information doesnŽt seem like a good idea to me, as the base domain
> model would get specific Tree infomration it doesnŽt need.
>
>
> Is the best practice to establish a seperate Tree Model with the
> "getChildren" and "getParent" information?
>
> But then: When a user selects an item in the tree, how can i map this
> item (which then would represent an Item of the TreeDataModel) back onto
> the "base" domain model?
>
> I hope you understand what iŽm trying to communicate and am happy about
> every answer/inspiration/advice on how to do something like this in the
> best way.
>
> Greetings
> Andreas
>
Re: Tree: "Good Practice" when base domain doesnŽt represent Tree structure ? [message #461121 is a reply to message #461076] Fri, 16 September 2005 14:28 Go to previous message
Andreas is currently offline AndreasFriend
Messages: 29
Registered: July 2009
Junior Member
Hello,

and thanks again for the help.

I can now display my wrapped domain model as a tree.


However, i donŽt know how i can propagate events from the underlying
domain model to the tree now.

More concrete:

The domain model fires a SELECTION_CHANGED event whenever a selection
occurs on one of the domain model objects.
I already catch this Selection in the TreeViewPartClass, via a
PropertyChange() Method. (I implemented the ViewPartClass as a
PropertyChangeListener).

I now want to select the corresponding object in the Tree, which
represents the object, which was selected in the domain.


From there on i donŽt know how to go further.
I got the Selection Object in the ViewPart from the Tree, but i donŽt know
how to make the tree select the corresponding TreeWrapperObject.

When i try to set the selection via:

TreeViewer.setSelection(...);

I get an

"org.eclipse.swt.SWTException: Invalid thread access"

error.

Furthermore the setSelection wants an object which implements the
ISelection Interface...
What object should i put into this method?
I guess the WrapperObjects for my model, am i right? So i have to
implement the ISelectionInterface for those models to?


Could anybody give me a hint on how to do this best?
Sorry if this posting got a little bit confusing.
But iŽm quite confused at the moment, too, on how to handle this.

Any help/idea is appreciated very much, since this is my first time with
SWT.

Greetings
Andreas
Previous Topic:How is the org.eclipse.draw2d.text.FlowAdapter used?
Next Topic:How do I implement this dialog behavior?
Goto Forum:
  


Current Time: Sat Jul 20 20:41:19 GMT 2019

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

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

Back to the top