Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » selections in TableTree or TableTreeViewer
selections in TableTree or TableTreeViewer [message #442480] Fri, 03 September 2004 14:17 Go to next message
Eclipse UserFriend
Originally posted by: kfiles.masergy.com

I don't know if this is the right place for questions involving JFace
as well, but I'm open to either a Viewer or Table solution to this
problem.

I am trying to use a TableTreeViewer where my model from time to time
needs to set the current selection on the TableTree. For example, when
the model containing a list of currently displayed objects (let's say
of type MyObject), it needs to tell the TableTreeViewer to find the
TableTreeItem associated with this object, and set the current selection.

I have tried the following, and it works about 25% of the time
(perhaps luck?):

//MyObject obj
viewer.setSelection(new StructuredSelection(obj), true);

From this, I assume (although the API is silent on the subject) that a
StructuredSelection constructor expects objects of type Item or
TableTreeItem.

So now I'm looking for any way to find the associated Item for a given
object currently displayed in the receiver. Unfortunately, potentially
helpful methods like StructuredViewer.findItem(Object obj) are protected.

Can anyone suggest an easy way to reach my goal (even if it involves
using the underlying TableTree to set the selection, followed by a
setSelectionToWidget). What I don't want to do is to use
TableTree.getItems(), walk the Items, and compare by
TableTreeItem.getText(int index). I want some way to do true Object
comparisons.

Thanks,
--kirby
Re: selections in TableTree or TableTreeViewer [message #442520 is a reply to message #442480] Tue, 07 September 2004 11:18 Go to previous message
Richard Moore is currently offline Richard MooreFriend
Messages: 71
Registered: July 2009
Member
Hi Kirkby,

We use the following line of code to set the selection in our tree.....
((StructuredViewer) viewer).setSelection((IStructuredSelection) new
StructuredSelection(Application.getNewestModel()), true);

The above works for me 100%, forever you must write an extra class for the
comparsion of models... the underlaying data in your tree.... this involves
telling the tree the comparer to use... e.g.

((StructuredViewer) viewer).setComparer(new ModelComparer());

the class ModelComparer implements IElementComparer interface..... The tree
will then call your equals method to determine where to set the focus...

Hopes this helps.

Cheers

Richard









"Kirby Files" <kfiles@masergy.com> wrote in message
news:ch9u6g$25h$1@eclipse.org...
>I don't know if this is the right place for questions involving JFace
> as well, but I'm open to either a Viewer or Table solution to this
> problem.
>
> I am trying to use a TableTreeViewer where my model from time to time
> needs to set the current selection on the TableTree. For example, when
> the model containing a list of currently displayed objects (let's say
> of type MyObject), it needs to tell the TableTreeViewer to find the
> TableTreeItem associated with this object, and set the current selection.
>
> I have tried the following, and it works about 25% of the time
> (perhaps luck?):
>
> //MyObject obj
> viewer.setSelection(new StructuredSelection(obj), true);
>
> From this, I assume (although the API is silent on the subject) that a
> StructuredSelection constructor expects objects of type Item or
> TableTreeItem.
>
> So now I'm looking for any way to find the associated Item for a given
> object currently displayed in the receiver. Unfortunately, potentially
> helpful methods like StructuredViewer.findItem(Object obj) are protected.
>
> Can anyone suggest an easy way to reach my goal (even if it involves
> using the underlying TableTree to set the selection, followed by a
> setSelectionToWidget). What I don't want to do is to use
> TableTree.getItems(), walk the Items, and compare by
> TableTreeItem.getText(int index). I want some way to do true Object
> comparisons.
>
> Thanks,
> --kirby
Previous Topic:using JMF within SWT?
Next Topic:Where can I get the swt resource?
Goto Forum:
  


Current Time: Fri Apr 26 11:28:59 GMT 2024

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

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

Back to the top