Addition of items to the "NEW" button in eclipse toolbar - java

I'm developing a custom project plugin wizard.
Currently the custom project wizard option shows up when I press "CTRL+N"
Or when I navigate from toolbar "New -> (drop down list) -> other.
Instead I want my selection to my newprojectwizard in the dropdown list that is generated for the "New" button on toolbar.
We see that the new button on toolbar has the following format.
A list of perspective controlled options.
Dotted lines and "Example"
Dotted line and "other"
I want to put my custom project wizard either in the section along with "example" or "other"
Any help or code snippet highly appreciated.

Use the org.eclipse.ui.perspectiveExtensions extension point to add to the top level new menu. The newWizardShortcut adds the shortcut.
For example:
<extension point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension targetID="org.eclipse.pde.ui.PDEPerspective">
<newWizardShortcut id="org.eclipse.pde.ds.ui.wizard"/>
</perspectiveExtension>
</extension>

Related

Moving custom menuManager at the end of existing RCP app menu

I am working with an RCP application menu. As seen in the image below I am trying to move my newly added Help menu at the end of the freebies menus that come with my RCP application. Currently the code just adds it to the menubar by using a class that was created derived from ActionBarAdvisor .
public class ApplicationActionBarAdvisor extends ActionBarAdvisor
Looking at the other methods available I see an appendToGroup method that might be interesting to use. Only thing is that it requires a groupName and I don't have one. The menu ids I have been using don't seem to suffice as a groupName.
Here is my code
#Override protected void fillMenuBar(IMenuManager menuBar)
{
MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);
//menuBar.appendToGroup(menuBar.getId(), helpMenu);
menuBar.add(helpMenu);
helpMenu.add(aboutAction);
}
Fixed it
If you are adding to an RCP which uses the normal Eclipse ActionBarAdvisor (WindowActionBuilder) then there is a group marker with id IWorkbenchActionConstants.MB_ADDITIONS positioned before the existing Window and Help menus.
There is an existing Help menu which has id IWorkbenchActionConstants.M_HELP so you can find this menu using:
IMenuManager helpMenu = menuBar.findMenuUsingPath(IWorkbenchActionConstants.M_HELP);
If you are writing your own action bar builder based on ActionBarBuilder then there are no groups defined in the menu manager and you can't use appendToGroup. You just call add in the order you want the menus to appear.
Creating a custom menu programmatically is not the best way to go about this. Use the plugin.xml extensions tab to create menus then you can easily use the up and down buttons at the right of the text field with All Extensions to rearrange where you want each menu to be. So in this case, it's much easier to use the built-in Help menu of Eclipse. This whole action is resumed by adding the help menu right after the other menus in the plugin.xml file
``` <extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu">
<menu
label="File">
<command
commandId="org.eclipse.ui.file.exit"
label="Exit">
</command>
<command
commandId="org.eclipse.ui.file.save"
label="Save"
style="push">
</command>
</menu>
<menu
label="Help">
<command
commandId="org.eclipse.ui.help.aboutAction"
label="About">
</command>
<command
commandId="org.eclipse.ui.help.helpSearch"
label="Search">
</command>
</menu>
</menuContribution>```
Final Result picture in question area :) I can't load it here

add dynamically items to a menu and make them appear at next restart

I have been developing an app in Android. I have created a menu with some static elements:
<menu
android:id="#+id/submenu">
<item android:id="#+id/create_new"
android:title="eganaude" />
<item android:id="#+id/open"
android:title="skema" />
</menu>
and I have a rule to add other elements dynamically:
menu_global.add(0, new_hash_value, 0, text);
However, this way each time I restart the app, I should add again the elements to the menu. So I would like the new elements added dynamically to appear at each restart. Is there a way to implement this behaviour?
I recommend you to use an internal database to keep your information, is easy to implement it, look at this link with information:
https://developer.android.com/guide/topics/data/data-storage.html#db
The only way to do that is to save the new added menu items to database or shared preferences or in a file and then later read/load the items and add them to the menu

Java plugin pop-up menu

I have a plugin which adds a view. This view contains a table which contains on each row some informations. I would like to have a popup menu when I press the right mouse click.
How can I add the extension org.eclipse.ui.menus and after creating the menuContribution to see it in the view ?
In your ViewPart use this code:
MenuManager contextMenu = new MenuManager();
contextMenu.setRemoveAllWhenShown(true);
getSite().registerContextMenu(contextMenu, viewer);
Control control = viewer.getControl();
Menu menu = contextMenu.createContextMenu(control);
control.setMenu(menu);
where viewer is your TableViewer.
The context menu this creates has the same id as your view so you contribute to it with:
<menuContribution
locationURI="popup:your.view.id">
....
</menuContribution>

pulldown command menu options

I've added a pulldown command to my toolbar
<command
commandId="my.uri.Options"
label="%Options.label"
icon="icons/properties.png"
style="pulldown">
</command>
that under a pull down menu have some toggle options.
I would like to get to those option by pushing the button as well, and not just the menu triangle. Is that possible? Or my approach is all wrong?
Perhaps you could use the onclick event handler, or the you could explore the addEventListener() to change the action for when the menu is clicked.

add the same menu contribution to two registered context menus(in different views)

I have two views in my application.there are treeviewer in both the views on which i want to add context menus.
I registered the context menues using
getsite().registerCOntextMenu(menu,treeviewer);
in both the views
Now i added the menu contribution in plugin.xml file as
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?before=editions">
<command
commandId="com.eclipse.command1"
label="action"
style="push">
</command>
</menuContribution>
but this menu is shown in only one of the context menu not in both.
so is there any way to add this menu to all the registered context menus or using the id for menu so that they can be identified.
If you are referring to a group in locationURI then this group has to be present in the menu.
In general:
Any pop-up menu which is registered with the workbench should also define a GroupMarker in the registered menu with id IWorkbenchActionConstants.MB_ADDITIONS[="additions"].
In your case, the group should be named "editions".

Categories

Resources