Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Getting SelectionProvider in an Action
Getting SelectionProvider in an Action [message #445017] Sun, 26 February 2006 07:37 Go to next message
Eclipse UserFriend
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 #445027 is a reply to message #445017] Sun, 26 February 2006 22:39 Go to previous messageGo to next message
Eclipse UserFriend
hi,
i think this is possible without selection listener also.

first create getter mehtod for the tree in the view.

getMyTree()

in run() method of the action you can get the reference of the view like:-

View view1=(View)PlatformUI.getWorkbench().getActiveWorkbenchWind ow().getActivePage().findView(View1.ID);

now you can access the tree viewer like
view1.getMyTree(). and do any operation like add and delete as you want.
Re: Getting SelectionProvider in an Action [message #445029 is a reply to message #445017] Mon, 27 February 2006 02:11 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Getting SelectionProvider in an Action [message #445036 is a reply to message #445027] Mon, 27 February 2006 05:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pverma.gmail.com

Rohit Khariwal wrote:

> View
view1=(View)PlatformUI.getWorkbench().getActiveWorkbenchWind ow().getActivePage().findView(View1.ID);

Hi Rohit,

Thanks, I think this will work. I know (and I know you know) this will
send any semblance to good practices out of the window :-) but this will
help me move forward with my problem and thanks for that!

/p
Re: Getting SelectionProvider in an Action [message #445037 is a reply to message #445029] Mon, 27 February 2006 05:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pverma.gmail.com

Daniel Krügler wrote:
> 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, ...to have a model...

Hi Daniel,

I fully agree with whatever you have said here. And I'm looking for sample
code that will help me design this MVC structure. I'll put in the direct
access method as suggested by Rohit, so that I can move forward with my
implementation, but I'll watch out for any examples of this kind of code.

Thanks!

/p
Re: Getting SelectionProvider in an Action [message #445066 is a reply to message #445037] Mon, 27 February 2006 14:37 Go to previous messageGo to next message
Eclipse UserFriend
Mr Verma

Today I attached a small viewer app as a reply in the thread
posted by Lukasz Grobleny "Tree Viewer= Updating + adding + removing nodes"

I suggest you to do the same as suggested in that tread. The small app has all your questions implemented and you can us it as a model.

Good luck
Re: Getting SelectionProvider in an Action [message #445114 is a reply to message #445037] Mon, 27 February 2006 22:01 Go to previous message
Eclipse UserFriend
Does this http://www.eclipsezone.com/eclipse/forums/t53983.html?start= 20
help to think about organizing C in MVC? You dont have to follow the whole thread though!

Thanks
~Venkat
Previous Topic:Treeviewer = updating + adding + removing nodes
Next Topic:Splash Screen Not Showing
Goto Forum:
  


Current Time: Mon Nov 03 14:59:51 EST 2025

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

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

Back to the top