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 09:34  |
Eclipse User |
|
|
|
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 #70484 is a reply to message #69541] |
Wed, 11 June 2003 03:01   |
Eclipse User |
|
|
|
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 03:02   |
Eclipse User |
|
|
|
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 04:34   |
Eclipse User |
|
|
|
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 07:59  |
Eclipse User |
|
|
|
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.
>
>
|
|
|
Goto Forum:
Current Time: Thu May 08 02:04:29 EDT 2025
Powered by FUDForum. Page generated in 0.13610 seconds
|