Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to programatically select an Item in a TreeViewer
How to programatically select an Item in a TreeViewer [message #69215] Tue, 10 June 2003 13:34 Go to next message
Eclipse UserFriend
Originally posted by: bodo.t.genion.de

if i have a element Object which corresponds to an TreeViewers TreeItem.
How do I set selection on the Tree of the TreeViewer ?

The 2nd step i have already made: getTree() from the treeviewer and call
setSelection() on it. that was the easy part.

but the problem is, how to find the TreeItem i want to be selected if i
just have the element Object (from my Model ) ?

I tried with findItem(Object element) of the TreeViewer but 1st this
is a protected method , so i have to subclass TreeViewer and 2nd this
method simply does not work, because TreeViewer seems not to use its
internal elementMap.

so do i need to write my own version of findItem() in a subclassed
TreeViewer or did i overlooked something, which would be more easy to do?

Bodo
Re: How to programatically select an Item in a TreeViewer [message #69439 is a reply to message #69215] Tue, 10 June 2003 14:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bodo.t.genion.de

found a partial solution, see below , but now i have the next problem:

if i call
treeviewer.getTree().setSelection(tis);
on a TreeViewer neither the previous registered
selectionChanedListerner of TreeViewer nor the previous
registered selctionListerner of the Tree is called.
i this a Bug or a Feature and how can i force to call the listeners ?

bodo



bodo schrieb:
> if i have a element Object which corresponds to an TreeViewers TreeItem.
> How do I set selection on the Tree of the TreeViewer ?
>
> The 2nd step i have already made: getTree() from the treeviewer and call
> setSelection() on it. that was the easy part.
>
> but the problem is, how to find the TreeItem i want to be selected if i
> just have the element Object (from my Model ) ?
>
> I tried with findItem(Object element) of the TreeViewer but 1st this
> is a protected method , so i have to subclass TreeViewer and 2nd this
> method simply does not work, because TreeViewer seems not to use its
> internal elementMap.
i found, that i need to call setUseHashlookup(true) on the TreeViewer
first.

>
> so do i need to write my own version of findItem() in a subclassed
> TreeViewer or did i overlooked something, which would be more easy to do?
>
> Bodo
>
>
>
Re: How to programatically select an Item in a TreeViewer [message #69541 is a reply to message #69215] Tue, 10 June 2003 15:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lynne_kues.oti.com

You should use the setSelection API defined for the viewer. This will fire
the selection changed event. See:
StructuredViewer>>public void setSelection(ISelection selection, boolean
reveal)

"bodo" <bodo.t@genion.de> wrote in message
news:3EE5DE57.2060303@genion.de...
> if i have a element Object which corresponds to an TreeViewers TreeItem.
> How do I set selection on the Tree of the TreeViewer ?
>
> The 2nd step i have already made: getTree() from the treeviewer and call
> setSelection() on it. that was the easy part.
>
> but the problem is, how to find the TreeItem i want to be selected if i
> just have the element Object (from my Model ) ?
>
> I tried with findItem(Object element) of the TreeViewer but 1st this
> is a protected method , so i have to subclass TreeViewer and 2nd this
> method simply does not work, because TreeViewer seems not to use its
> internal elementMap.
>
> so do i need to write my own version of findItem() in a subclassed
> TreeViewer or did i overlooked something, which would be more easy to do?
>
> Bodo
>
>
>
Re: How to programatically select an Item in a TreeViewer [message #70484 is a reply to message #69541] Wed, 11 June 2003 07:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bodo.t.genion.de

yes , this also was my first thought , but then i did not understand
what the Interface "ISelection" is good for and how to use it. do my
tree-model elements need to implement this?
the point is that my model is a jdom tree, the jdom.Elemenst correspond
to the TreeItems, so if i want a certain jdom-Element to be selcted i
obviousely can not call setSelection(jdom.Element_obj, boolean reveal)
since my the jdom.Elements do not implement ISelection.
hm , i'm confused....

bodo



Lynne Kues schrieb:
> You should use the setSelection API defined for the viewer. This will fire
> the selection changed event. See:
> StructuredViewer>>public void setSelection(ISelection selection, boolean
> reveal)
>
> "bodo" <bodo.t@genion.de> wrote in message
> news:3EE5DE57.2060303@genion.de...
>
>>if i have a element Object which corresponds to an TreeViewers TreeItem.
>>How do I set selection on the Tree of the TreeViewer ?
>>
>>The 2nd step i have already made: getTree() from the treeviewer and call
>>setSelection() on it. that was the easy part.
>>
>>but the problem is, how to find the TreeItem i want to be selected if i
>>just have the element Object (from my Model ) ?
>>
>>I tried with findItem(Object element) of the TreeViewer but 1st this
>>is a protected method , so i have to subclass TreeViewer and 2nd this
>>method simply does not work, because TreeViewer seems not to use its
>>internal elementMap.
>>
>>so do i need to write my own version of findItem() in a subclassed
>>TreeViewer or did i overlooked something, which would be more easy to do?
>>
>>Bodo
>>
>>
>>
>
>
>
Re: How to programatically select an Item in a TreeViewer [message #70502 is a reply to message #70484] Wed, 11 June 2003 07:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: scheglov_ke.nlmk.ru

bodo <bodo.t@genion.de> wrote:

> yes , this also was my first thought , but then i did not understand
> what the Interface "ISelection" is good for and how to use it. do my
> tree-model elements need to implement this?
> the point is that my model is a jdom tree, the jdom.Elemenst correspond
> to the TreeItems, so if i want a certain jdom-Element to be selcted i
> obviousely can not call setSelection(jdom.Element_obj, boolean reveal)
> since my the jdom.Elements do not implement ISelection.
> hm , i'm confused....
Most JFace viewers (including TreeViewer) use IStructuredSelection,
and there is StructuredSelection, which implements this interface.

--
SY, Konstantin.
Re: How to programatically select an Item in a TreeViewer [message #70580 is a reply to message #70502] Wed, 11 June 2003 08:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lauri.pesonen.iki.fi

"Konstantin Scheglov" <scheglov_ke@nlmk.ru> writes:

> bodo <bodo.t@genion.de> wrote:
>
> > yes , this also was my first thought , but then i did not understand
> > what the Interface "ISelection" is good for and how to use it. do my
> > tree-model elements need to implement this?
> > the point is that my model is a jdom tree, the jdom.Elemenst correspond
> > to the TreeItems, so if i want a certain jdom-Element to be selcted i
> > obviousely can not call setSelection(jdom.Element_obj, boolean reveal)
> > since my the jdom.Elements do not implement ISelection.
> > hm , i'm confused....
> Most JFace viewers (including TreeViewer) use IStructuredSelection,
> and there is StructuredSelection, which implements this interface.


And in Bodo's case the code snippet would be:

IStructuredSelection sel = new StructuredSelection(jdom.Element_obj);
tree.setSelection(sel, true);

The important part is that the object given to StructuredSelection must be
equal() to one of the items of the tree for a selection to be shown in the
tree. I.e. either you must use the same objects to create the
StructuredSelection that are in the tree (selectedObj == treeItem) or the
item must implement equals (selectedObj.equals(treeItem)).

> --
> SY, Konstantin.

--
Lauri
Re: How to programatically select an Item in a TreeViewer [message #70664 is a reply to message #70580] Wed, 11 June 2003 11:59 Go to previous message
Eclipse UserFriend
Originally posted by: bodo.t.genion.de

it works! thank you Lauri!
the doc is not very exhausive in this regard, nor are the examples, are
they ? and diggin in the eclipse source is somehow painfull.


bodo


Lauri Pesonen schrieb:
> "Konstantin Scheglov" <scheglov_ke@nlmk.ru> writes:
>
>
>>bodo <bodo.t@genion.de> wrote:
>>
>>
>>>yes , this also was my first thought , but then i did not understand
>>>what the Interface "ISelection" is good for and how to use it. do my
>>>tree-model elements need to implement this?
>>>the point is that my model is a jdom tree, the jdom.Elemenst correspond
>>>to the TreeItems, so if i want a certain jdom-Element to be selcted i
>>>obviousely can not call setSelection(jdom.Element_obj, boolean reveal)
>>>since my the jdom.Elements do not implement ISelection.
>>>hm , i'm confused....
>>
>> Most JFace viewers (including TreeViewer) use IStructuredSelection,
>>and there is StructuredSelection, which implements this interface.
>
>
>
> And in Bodo's case the code snippet would be:
>
> IStructuredSelection sel = new StructuredSelection(jdom.Element_obj);
> tree.setSelection(sel, true);
>
> The important part is that the object given to StructuredSelection must be
> equal() to one of the items of the tree for a selection to be shown in the
> tree. I.e. either you must use the same objects to create the
> StructuredSelection that are in the tree (selectedObj == treeItem) or the
> item must implement equals (selectedObj.equals(treeItem)).
>
>
>>--
>>SY, Konstantin.
>
>
Previous Topic:[Debug] Off by one line problem in debugger (2.1)
Next Topic:Getting "Unknown extension point" warnings
Goto Forum:
  


Current Time: Sat Jul 27 18:23:02 GMT 2024

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

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

Back to the top