0

I am looking for a way to to force Eclipse to refresh/rebuild its own main menu or even the whole view on runtime programmatically.

The reason why i need it this way is, because i have a plugin that iterates through a project and depending on the configuration of the selected project it loads a project specific plugin at runtime with:

FrameworkUtil.getBundle(this.getClass()).getBundleContext().installBundle(String).start()

Now the loaded plugin contributes to the org.eclipse.ui.main.menu extension point and even though the plugin is installed I don't see the new menu entry.

FYI: I am using Eclipse 3.x and E4 Tools

Now my questions are:

  • Is there acutally a way to refresh/rebuild parts of the Eclipse ui or maybe even the whole ui?
  • If not, can someone think of another approach? I thought of having a plugin which contributes only the menu and add the menu items programmatically. But i couldn't believe that there is no way to refresh the view so i am asking this question.

I checked whether MMenu had a refresh method itself so i could get the object and just call the refresh method.

But in the end i didn't find a way to do this.

P.S. I am pretty new to Plugin Development and RCP so please don't blame me if the solution was obvious but i didn't realize it

Lii
  • 11,553
  • 8
  • 64
  • 88
Illya
  • 13
  • 2
  • It is very unusual to install plugins dynamically. If you have a fixed set of plugins it would be better just to enable/disable their menu items using the normal mechanisms. – greg-449 Feb 02 '16 at 16:38
  • Yeah probably it is a unusual approach and if there are no intergrated mechanisms to refresh the ui, i will have to do it as you said. But the actual and main question i have is, whether it is possible to refresh the ui programmatically. :) – Illya Feb 02 '16 at 16:59

1 Answers1

0

Refresh/Rebuild UI

Short answer: no

In many places Eclipse extension points are loaded and information is stored in static fields (often in a Singleton). The plugin.xml data is not reloaded during the lifetime of the application, and certainly these bundles do not listen bundle events that would allow them to detect such changes.

Therefore, even if there were some method to call refresh on the whole UI, at least some (most?) of the code handling extension points would not see the effects of the new plugin.xmls.

Another Approach

To answer what you are trying to do, the "normal" thing to do would be to have each menu contribution's visibility be dependent on some expression, e.g. if the current selection adapts to MySpecialProject you could have it visible.

When you do it the normal way, and you leave everything to be lazily loaded, the java code for all those project type plug-ins will not be loaded until the commands are actually invoked for the first time.

To go the next step, you would probably have a main ui plug-in that defined a bunch of commands (e.g. build project, flash leds, format file, etc), but have no command handlers associated in that main plug-in. In each project type plug-in, have command handlers that are enabled when only the correct project type is active.

Assuming you have already worked through a basic tutorial on commands in Eclipse, there is a good advanced one on vogella.com that covers many useful features for being properly dynamic.

Jonah Graham
  • 7,890
  • 23
  • 55