Eclipse RCP: how to extend GUI component in a different plugin? - eclipse

I am adding a plugin to my application to extend functionality of an existing plugin (for advanced reporting). The application already has a preference page in place. I need to "refresh" the reporting of the new plugin when the user changes the preferences for the existing plugin.
My thought is to "extend" the preference page of the existing plugin to add a checkbox to "propagate changes to open reports" and cause a refresh. This refresh is only applicable when the new plugin is in use (it is optional and the existing plugin can be used standalone). How can I extend the preference page to add the checkbox and load THAT preference page instead of the existing one when the new plugin is loaded?
This question also applies to extend views and editors, but I'm unsure how to extend (in the Java definition) GUI components from different plugins. I can only see how to contribute new interfaces.

You can use an OSGi fragment for this. In a nutshell, a fragment is added to the host bundle (i.e. the one which "hosts" the fragment) and it can overwrite anything in the host bundle. If you think in terms of a classpath, then the fragment always comes first and then the host bundle.
That means you can take the existing preferences page, copy this single source file into a fragment, change it as needed and then compile it into a fragment.

Related

How to refresh the Eclipse main menu programmatically on runtime

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.

How do I create and deploy custom settings for Salesforce, in Eclipse?

I have some custom settings in my org, but I do not appear to be able to synchronise them with my project in Eclipse. I've scanned the 'Add/Remove Metadata Components', but I can't find anything related to custom settings. Nor can I find a new Force.com object of type Custom Settingngs.
I want to deploy my changes from Eclipse, to a different sandbox, but of course the custom settings are missing.
Is this just not possible or am I missing something?
The custom settings should be available as a custom object on the object's list.
Did you refresh your metadata definition from server? (take a look to marked button on the screenshot below)

Integrating community plugins into a ready Eclipse RCP app?

I already have a standalone Eclipse RCP application. The next task is to integrate the plugins which are widely used in the Eclipse community like CDT or say PyDev to provide the editing and debugging facilities in respective programming languages inside the already developed RCP app. Just wondering how do i go about accomplishing this task. Should i start with playing around the extension points of the plugins and adding it to the MANIFEST.MF ?
What are the various ways of achieving this ? Which one to pick over the other?
The most important thing you should consider (besides the technical) is a conceptional.
Plugins like CDT are making a lot of assumptations about their environment they are integrated into. That means your RCP should have a very similar user-interface and behavior like the normal Eclipse SDK so that the integration of other "IDE-ish" plugins is not a break of the interface principles of your RCP.
If your RCP is not based on a common navigator, projects, files (in general the Workspace) and several editors the integration of Plugins like CDT will be a nightmare for your users and will feel like another application within your RCP.
Make also sure that ui-contributions from third-party-plugins are visible (e.g. if the third-party-plugin is contributing a preference page, make sure that your RCP has the menu-item to open the preference-window)
First you have to load the new features/plugins in your existing RCP application. For this you have to adapt your product definition and load the new feature.xml files. or you enhance your own feature.xml and place the new plugins into.
Afterwards you have to decide, whether the new functions/view/perspectives are contributions to an already existing RCP extension point and whether you use this extension point in your RCP product.
If you want to use the new functions in another way (because the default is not enough) you have to point to specific views/actions in the new plugins and call them by your self. Fot his you have to adapt the MANIFEST.MF of your own plugin and point to the new plugins. If you do it, you can not switch off the added features, because you do have a jard link to these plugins.
Your RCP product already depends on the RCP feature (org.eclipse.rcp) or a subset of its plug-ins. This means, it already includes the plug-ins defining the basic extension points.
To include functionality (extensions) from additional features, just add these features to your product configuration dependencies. For example, you would have to add the feature org.eclipse.cdt for CDT and org.python.pydev.feature for PyDev.
The hard part begins when you need to include only some of the features' plug-ins.
You'll have to isolate the plug-in(s) providing the functionality you require.
For UI contributions, you can use the plug-in selection spy by selecting the required UI part and clicking alt+shift+F1.
For non-UI contributions, information for contributed extensions can be found in the plugin.xml files in the plug-in sources.
These plug-ins, along with their dependencies can be added to a custom feature, which can be included in your product.
Although dated, the article Building a CDT-based editor might also be of help.

How can I enable or disable the eclipse new wizard?

My RCP application (based on the Eclipse infrastructure) has several modules. These modules can be enabled or disabled depending on the status of the application, and this information is available via variables (you can think about the active perspective).
Additionally, each module contribute to the new wizards (extension point "org.eclipse.ui.newWizards") to provide the user with the ability to create certain elements. But this is allowed only if the module is enabled...
Is there a way to enable or disable "new wizard"s depending on the status of the RCP application?
I think you are looking for Activities and Contexts in Eclipse.
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fworkbench_advext_activities.htm
In my experience, that's accomplished automatically. That is, if the plugin which your wizard belongs to is not loaded, your wizard will automatically be ruled out of the RCP active extensions.

How to make a new Eclipse project template?

I am using a kind of framework where every time I make a new Java project. I have to arrange the files in the appropriate packages and reference the appropriate external JAR libraries. How do I make a new project template like in the New Project dialog under a new folder?
I've just done a bit of research on this for our own nefarious purposes, and found the answer.
You need to create an Eclipse plugin that uses the org.eclipse.ui.newWizards package. You can define your own category or use an existing one once you find the category ID. To create a new project wizard rather than a new resource wizard, you need to set the "project=true".
Also, your plugin must contain a class that implement org.eclipse.ui.INewWizard. Clicking on the class link from the plugin.xml editor will do the trick.
That class must do all the work in the performFinish override, and must return true to indicate that it actually did its thing and the wizard can close. This is where you create files, directories, set natures, and so forth.
You need to write an Eclipse plugin for that, and concentrate on New Project Wizard.
Writing Eclipse plugins is covered in Stack Overflow question How to write a plugin for Eclipse?.