How to refresh the Eclipse main menu programmatically on runtime - eclipse

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

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.

Related

Eclipse 4 RCP How to launch another plug in in a new window

I have an e4 RCP which needs all the screen real estate. I have developed a second RCP that is in effect a relatively simple single-function plug-in, with currently only one part. I want the user to be able to launch the second from the first, then terminate it, all on demand.
As I understand it, I have 3 options:
Launch a new workbench for the second, written as a plug-in. I assume this uses more resources and also has the problem that I need to track and distinguish events which will go to both.
Write the second as a model fragment plug-in that extends the first. This has the advantage that I can keep on adding to the second plug-in by declaration in the model editor. However, I believe this requires attaching to an existing container in the main model. I could add a new container to the main model and write code to flip containers in and out but it is all done in the model editor currently, and more importantly the functions carried out by the second plug-in are quite different from those of the first (main) RCP, so I fear the user will find the UI change confusing.
Use EModelService and write code to create a new TrimmedWindow and then child PartStack, and Part, and all the Handlers. I have not yet found enough documentation to fully understand the implications, advantages and disadvantages of this - aside from the obvious ones that the former declarations now have to be programmed and coupling is tighter.
It looks to me like Eclipse itself uses approach 1 for two of its menu items:
Help Contents
Eclipse Marketplace
From the UI perspective, the kind of UI separation of functions that I want to achieve is very much like these two items. Hence I am leaning to option 1.
Any corrections or alternatives?
You could possibly use a PerspectiveStack with two perspectives containing the windows for your two apps. The second app can be in model fragment.
You can then just use EPartService.switchPerspective to switch between them.

eclipse - load plugin "on demand"

I have a lot of plugins installed on Eclipse Luna (including Spring, JBoss, Android, Genymobile, Tomcat, Apache, Axis, ...).
However, as you can argue, I don't use them all at the same time. Also, it seems that they slow down Eclipse in many ways.
So, what I'd like to do is to prevent eclipse to load them at the startup and instead only as needed.
Is there any way to achieve this goal?
Eclipse is lazy start by default. It will read all plugins manifest to determine their dependencies and if they add themselves to the UI and things like that. But they will only be started if they are actually used.
Say a plugin adds a view. It will be selectable in the show view dialog, but no code will have been loaded until you choose to use it. I believe it's the same thing with buttons on the toolbar and menu items, but if they require code to determine their enabled state (as many do) that will most likely require a full load of the plugin.
You can install the Plugin functionality in Eclipse to get the Plugin Registry view. From there you can see which plugins are actually active. The list will probably be smaller than you think.
However, to make it even smaller:
Uninstall plugins you never use
Customize your perspective to remove views you never use
Customize toolbar and menu to remove buttons and functionality you never use
Removing plugins from automatic startup is not a good idea, since they may rely on some functionality having executed at startup.
Some plugins have a tendency to completely take over your Eclipse installation and load themselves regardless of what you would be doing. I used Aptana as an Eclipse plugin some years ago, and it did just that. I had to create a separate installation just for it.
If you are using "heavy weight" plugins that adds a lot of functionality it might be a good idea to keep separate Eclipse installations for them.
In Windows->Preferences->General->Startup and Shutdown dialog box, there will be a list of installed plugins,select the plugins you want to activate on startup.

How to debug a plugin in Eclipse - i.e. a Java project without a Main method

I am currently trying to modify the behavior of an existing open-source plug-in for Eclipse.
I'm trying to understand how the plugin works. To do so, I opened it in "Debug" mode as an Eclipse application and I am testing it out after having inserted many breakpoints.
However, sine Eclipse plugins do not have a Main method, it's still really difficult for me to keep track of everything that is going on. The calls seem to jump arbitrarily (which I quickly realized was happening through all the interfaces and superclasses the plugin is inheriting) and I can't see exactly what's doing what.
What is the proper (read: BEST) way to debug a program with no Main method? How can I test, tweak, and explore and program - in this case a plugin - whose modus operandi I'm uncertain of?
You need to run your plugin in a runtime workbench. This (simplistically) starts a new instance of Eclipse with all existing plugins installed, plus the plugin you want to debug. Make sure that you have the PDE tools installed in your Eclipse instance and then in the debug configurations area, double-click on Eclipse Application to generate a default runtime workbench launch config.
I'd also recommend that you read up on PDE (plugin development environment), and you can get an overview here: http://wiki.eclipse.org/PDE/FAQ. And you can read up on plugins in general here: http://eclipsepluginsite.com/. There are many tutorials and lots of information all over the web. So, google is your friend.
Along with using breakpoints in Debug method you can even try printing stack trace using Thread.currentThread().getStackTrace() method to know the starting point of a Thread.

Mapping between resource file and model object in Eclipse plugin app

Please anyone help me understand and use IDE.openEditor(IWorkbenchPage, IFile).
I have a resource file (xml format), it contains my model objects. I'm writing a wizard to create it, save it into workspace, view it inside a tree view (I use CommonNavigator) and open it in an editor. I need to know the control flow of this all. How to map between resource file and model objects, how the navigator can show that objects and how to open editor that associated with my resource file.
I'm sorry, I'm a newbie in Eclipse field. I know I need too much, but please give me at least an idea.
Thanks a lot.
A great character once said... "You have much to learn young padawan".
Here's a great place to start your journey though the basics of Eclipse plug-in / RCP development...
http://www.vogella.com/eclipse.html
If you really want to get down and dirty into the bowels of Eclipse, you can use Eclipse itself to teach you the dirty details about what's really going on.
Figure out how to view Eclipse source code inside of Eclipse.
Set break points at interesting points in Eclipse source code that you want to know more about.
Use the 'Eclipse Application' run configuration to run an instance of Eclipse from within your main Eclipse.
Use your newly launched Eclipse to preform the tasks you want to mimic and hopefully, you'll hit one of your break points and see how the Eclipse developers did what you want to do.

How can one use the Web Page Editor in custom RCP application?

I want to use the "Web Tools Editor" that is part of the Web Tools Plattform in my own RCP-Application. I think i have got some understanding on the RCP plattform by now, but I still have no clue how to access the functionality of the pagedesigner (org.eclipse.jst.pagedesigner) after adding it as a dependency to my project. Has anyone some experience in adding components of the web tools plattform into an RCP-Application and can give me a hint or something?
There's a difficulty with these sorts of requests (I am, myself, trying to include this or that feature that I saw in the Eclipse IDE, every so often).
The trick is to try and identify the component you want to bring in, and then try and pull it into your project, without bringing in too many dependencies.
The first step used to be quite hard, but since 3.4 it is a matter of using the Plug-In Spy - hold down Alt-Shift-F1 on whilst your desired component is in focus should give you a tooltip showing you the class, the bundle, etc etc.
The second step is altogether more tricky and is where I usuaully fail to get any results:
if you are lucky then you can just include the bundle in the launch configuration/.product of your app. Once you hit Add Required Bundles, you are not left with 3000 bundles (i.e. your RCP is now Eclipse).
usually, this is not the case, because the Eclipse team haven't refactored the bit of code you're interested in out into an RCP safe bundle. If so, then you're going to have to do that yourself.
Again, if you are lucky then that will mean moving some classes out of the eclipse bundle into your own, including internal classes, and that will be the end of it - i.e. the dependencies of your desired functionality are all within the bundle.
If you're unlucky, then you need to isolate/reimplement the bit of functionality that is required, and change your version of the copied code.
It is hard laborious, and pretty difficult to upgrade. I realise that none of this is what you want to hear.