0

I have a RCP app and a RCP plugin (A) that contributed a Part. There is a TreeViewer (with many items) in the Part. I also defined a popup menu with some menu items (in a file .e4xmi) then registered this menu to the TreeViewer.

I'm writing another RCP plugin (B) that will contribute to the popup menu a menu item and in the handler I want to delete the selected item in the TreeViewer.

The problem is I cannot access the data of the Part (of A) in B. How can A shares the data (TreeViewer) to B? I found a solution is using EventBroker but I want some others. Can you give me some suggestions or hints? Thanks!

aviit
  • 1,957
  • 1
  • 27
  • 50

2 Answers2

1

There are many ways of doing this. For an e4 application the simplest thing to do is have a singleton class containing your data that all plugins can access.

You can specify that a class is a createable singleton to the injection system using:

@Creatable
@Singleton
public class MyDataMananger
{
  ....
}

Classes in plugin can then inject the class:

@Inject
MyDataManager manager;

You can also

  • Use OSGi Services and use a ServiceTracker.
  • Inject classes created using a ContextFunction.
  • Simply have a singleton class accessed via a plugin's activator (like ResourcesPlugin.getWorkspace()).
  • Define an extension point for a service
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Thank about singleton. I also know about this. Can you give me some hints or keywords about others? I have searched about sharing data between plugins but not yet satisfied. Thanks! – aviit Nov 07 '17 at 23:15
  • Added a few more methods – greg-449 Nov 08 '17 at 07:45
1

Another way is to store your data in the right e4 Context
Explanation of E4 eclipse contexts can be found here
Also if you have access to the TreeVieewer itsefdl, data can be stored by using the setData(..) method

titou10
  • 2,814
  • 1
  • 19
  • 42