1

I writed a plugin with prefuse integrated in the view (org.eclipse.ui.views). As a second step, I writed and added a command menu into the context menu of the Package Explorer. When I right click on any package in the Explorer Package View it shows me the menu. When I click on it, the Handler class of the command saves all the Java class paths from the package into a List. My problem is now, how can I pass the updated List to the view where my prefuse class is initialized. I forgot to mention that this is the first time I am writing a eclipse plugin.May be there is a better way to do that.

Thanks

malib5
  • 59
  • 1
  • 7

2 Answers2

2

The plugin.xml of your plugin probably defines two things:

  1. The context menu contribution for the package explorer
  2. The view that should receive the list

When your menu contribution is invoked from the package explorer, your view may already be open, or it may not be. If it's already open, you want to send data from the menu command to the view, so you need to get some reference to the view. If the view is not already open, the command should open the view, and then send the data to the view.

Both cases can be solved the same way.

Following for example the info from Programmatically showing a View from an Eclipse Plug-in you can activate the view, no matter if it was already visible or not. The method IWorkbenchPage#showView(id-of-your-view) will return a reference to your view, so you can cast that to the type of your view and invoke its methods, for example including some method that receives the list that you want to display in the view.

Community
  • 1
  • 1
Kay
  • 527
  • 2
  • 8
1

I would use the Activator class in your plugin. At some point Eclipse will start your plugin by constructing an instance of the Activator class in your plugin. That instance can always be referenced using the getDefault() class method on Activator.

When your View is initialized it can register itself to the Activator instance (have an instance variable to hold a reference to the view object). When your Handler has a list to give to the view, the handler can ask the default instance of the Activator for the view object and can then send the list directly.

If you've put the handler in a different plugin than the view, you can make one plugin a dependency of the other. The second plugin can then access the classes in the first and that includes the first plugin's Activator class.

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59