Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Tree: How to cast from IStructuredSelection to Model objects?
Tree: How to cast from IStructuredSelection to Model objects? [message #460961] Tue, 13 September 2005 11:25 Go to next message
Andreas is currently offline AndreasFriend
Messages: 29
Registered: July 2009
Junior Member
Hi everybody,

i have a JFace tree which is displaying my model.

When a selection occurs within the Tree i want to get the type of the
object which the label of the Tree represents and then propagate this
selection to other views.

I therefore implemented the "selectionChanged" method.
The selections are already caught, but i donŽt know how i can cast the
IStructuredSelection back into the model objects they represents.

When i try something like this (similar to the MovingBox example in the
SWT articles):

Object domain = (MyModel) selection;

I get a "Error in JDT Core during reconcile" in the error log.

I donŽt know which object i have to cast the Selection to. Do i have to
use the same type i used for TreeViewer.setInput(type)???


Could anybody provide help or information or ideas?

Thanks a lot.
Andreas
Re: Tree: How to cast from IStructuredSelection to Model objects? [message #460963 is a reply to message #460961] Tue, 13 September 2005 11:48 Go to previous messageGo to next message
michael is currently offline michaelFriend
Messages: 44
Registered: July 2009
Member
Am Tue, 13 Sep 2005 13:25:31 +0200 schrieb Andreas
<andreas.a.fleck@eads.net>:

> Hi everybody,
>
> i have a JFace tree which is displaying my model.
>
> When a selection occurs within the Tree i want to get the type of the
> object which the label of the Tree represents and then propagate this
> selection to other views.
>
> I therefore implemented the "selectionChanged" method.
> The selections are already caught, but i donŽt know how i can cast the
> IStructuredSelection back into the model objects they represents.
>
> When i try something like this (similar to the MovingBox example in the
> SWT articles):
>
> Object domain = (MyModel) selection;
>
> I get a "Error in JDT Core during reconcile" in the error log.
>
> I donŽt know which object i have to cast the Selection to. Do i have to
> use the same type i used for TreeViewer.setInput(type)???
>
>
> Could anybody provide help or information or ideas?
>
> Thanks a lot.
> Andreas
>
>

Hi Andreas,

If you are only interested in the first selected object (e.g. because the
unedrlying Tree was initialized with SWT.SINGLE), you can do the following:
IStructuredSelection selection =
(IStructuredSelection)treeViewer.getSelection();
Object domain = selection.getFirstElemenet();

If you are interested in all selected elements, you'ld do
IStructuredSelection selection =
(IStructuredSelection)treeViewer.getSelection();
if (selection != null) for (Iterator it=selection.iterator();
it.hasNext();) {
Object domain = it.next();
// .. work with it
}

hope this helps,
Michael



--
Erstellt mit M2, Operas revolutionärem E-Mail-Modul:
http://www.opera.com/m2/
Re: Tree: How to cast from IStructuredSelection to Model objects? [message #460965 is a reply to message #460963] Tue, 13 September 2005 12:49 Go to previous message
Andreas is currently offline AndreasFriend
Messages: 29
Registered: July 2009
Junior Member
Hi Michael,

thanks for your help.
I messed up with the FirstElement thing.

Now it runs.

Thanks again.
Andreas
Previous Topic:Scrollbar freezes when dragging a sashbar
Next Topic:TableTree details help
Goto Forum:
  


Current Time: Sat Dec 07 02:31:17 GMT 2019

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

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

Back to the top