| Getting SelectionProvider in an Action [message #445017] |
Sun, 26 February 2006 07:37  |
Eclipse User |
|
|
|
Originally posted by: pverma.gmail.com
Hi,
A view in my application contains a TreeViewer which is set as a selection
provider, like this:
public class MyView extends ViewPart {
private TreeViewer viewer;
...
...
public void createPartControl(Composite parent) {
viewer = new TreeViewer(...);
...
...
getSite().setSelectionProvider(viewer);
...
...
}
}
On performing an action, from the context menu of the view, or from the
menu bar, I need to add or remove elements to the Tree which is part of
the viewer. After that, I need to call viewer.refresh() from the action to
refresh the view. Could anyone tell me what patterns I need to use to
implement this?
I think if I can get access to the SelectionProvider (i.e. the TreeViewer)
in my Action code, the rest of it could be implemented. Any suggestions on
how to get access to the SelectionProvider in the Action?
Thanks.
|
|
|
|
| Re: Getting SelectionProvider in an Action [message #445029 is a reply to message #445017] |
Mon, 27 February 2006 02:11   |
Eclipse User |
|
|
|
P Verma wrote:
> Hi,
>
> A view in my application contains a TreeViewer which is set as a
> selection provider, like this:
>
> public class MyView extends ViewPart {
> private TreeViewer viewer;
> ..
> ..
> public void createPartControl(Composite parent) {
> viewer = new TreeViewer(...);
> ..
> ..
> getSite().setSelectionProvider(viewer);
> ..
> ..
> }
> }
>
> On performing an action, from the context menu of the view, or from the
> menu bar, I need to add or remove elements to the Tree which is part of
> the viewer. After that, I need to call viewer.refresh() from the action
> to refresh the view. Could anyone tell me what patterns I need to use to
> implement this?
>
> I think if I can get access to the SelectionProvider (i.e. the
> TreeViewer) in my Action code, the rest of it could be implemented. Any
> suggestions on how to get access to the SelectionProvider in the Action?
IMHO its a bad idea to allow direct access to you tree, at least if you
have a data model, which is presented by the tree. If you allow others
to modify you tree, your model will be out-of-sync with the tree. My
proposal is, given that you have a model that is represented by the tree:
1) Let actions modify you model, **not the tree**.
2) Let the model inform the content provider of the tree via some
internal notification, which and what has been changed (kind of resource
change listener).
3) The content provider of the tree is listener to those notifications
and starts an asyncExec to update the necessary parts of the tree.
Greetings from Bremen,
Daniel Krügler
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04557 seconds