Search code examples
javaeclipsepluginsviewpackage-explorer

Eclipse Plugin: Pass values from one View to other View


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


Solution

  • 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.