1

I have a plugin which contains class A that brings up a view defined in class B via the following line of code:

(VideoLogView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("Videolog.VideoLogView");

What I need to do in the createPartControl() method of the view (class B object) is access a method in the class A object.

How can this be done?

Thanks.

Dr. Faust
  • 1,021
  • 3
  • 14
  • 22
  • @Dr. Faust: glad you have worked it out. Could you post an answer in this post detailing the relevant extract of your code does what you want? You can even select that as the official answer (no rep gain involved though) – VonC Jun 25 '09 at 16:18

1 Answers1

2

Look like you are facing the classic issue of "how do I pass arguments to my view" ?
This thread illustrates it best:

I was facing the same problem at the beggining of my RCP project. I was getting weird about the fact that there was no way to pass an argument to a view as the viewed model.

Why? Because (emphasis mine):

You are on an opened, pluggable platform. You contribute to existing developments, others should be able to contribute to yours.

Therefore you will not "pass" arguments to a view, this would lock the whole thing into a non-opened design.
Instead, your view will ask the platform (or will listen to the platform) to determine which information to manage.
Other views (from other plugins that don't yet exist) might also want to manage the same information on the same event.

What you should do then is to ask the workbench for the current selection. I guess your view is opening on a double click action or simple selection so the object you want to manage in your view will be currently selected.
This is how you could retrieve the workbench selection from your view :

ISelection s = this.getSite().getWorkbenchWindow().getSelectionService().getSelection();

where "this" is a ViewPart.

Then you have to make your initial view (the one initiating the view creation from a given event like DoubleClick) a selection provider. A JFace viewer is a selection provider, so you can use it if you're using jface, or you can implement the ISelectionProvider interface when you're using custom SWT controls (that was my case).


The article "Eclipse Workbench: Using the Selection Service" can also give you some pointers.

alt text

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks. Passing parameters to my view is exactly the issue. I will start reading the article immediately. – Dr. Faust Jun 24 '09 at 23:23
  • VonC - I have read the article, "Using the Selection Service." This doesn't seem to be what I am looking for. I need to access a method of class A when my view (class B) gets created and the createPartControl method is called. It seems the Selection Service comes into play once your view is created and displayed. Any other ideas? – Dr. Faust Jun 25 '09 at 13:35
  • Please disregard above comment. I got it to work after reading: this – Dr. Faust Jun 25 '09 at 16:05
  • 1
    Please disregard the above comment. I got it to work. I found the answer to [this][1] question very helpful. [1]: http://stackoverflow.com/questions/585802/how-to-get-the-selected-node-in-the-package-explorer-from-an-eclipse-plugin – Dr. Faust Jun 25 '09 at 16:10