We got the Jmjrst open source project and should configure and work a bit with it.
Now we never had any of the JMenu, JMenuItem and Listener stuff so this is pretty confusing for me.
I already got my new MenuTab implemented and is working.
My problem is that my Task says the following:
Every plugin should be able to be started and configured.
The configuration should only be implemented if the plugin is configurable.
(translated text)
We got a method for checking if it is configurable.
This is my code right now:
int length = pluginList.size();
int i = 1;
for (Plugins plugIn: pluginList) {
pluginMenuItem = new JMenuItem(plug.getMenuText());
if (plugIn.isConfigurable()) {
pluginMenuItem.addActionListener(new MenuListner(m, this));
}
if (i < length) {
pluginsMenu.addSeparator();
}
pluginsMenu.add(plugin);
i++;
}
newList is just a list containing all available plugins. I think my
if (plug.isConfigurable()) is set incorrectly because every menupoint needs to be able to be clicked. But idk how to manage what is happening when the menu point (plugin) is getting clicked and how to seperate running and configuring.
Edit: every plugin has the following methods: run() and configure()
but how do I add them to the Menu and am able to seperate them?
Edit2:
Plugins ==== The Plugins which should be added to the Menu
pluginsMenu ==== the JMenu Object
plugIn ==== the new JMenuButton Object
This will depend on your user interface design, you can have subMenuItems under each plugin-- one for say "config" and other for "execute/Run",
you can have one menuItem has you have now and then listener can popup the dialog to let user select config/execute -- this will not be the best option as users will have to deal with dialog every time they click the plugin
Another way I can think of is have a top level menuItem for "configuration" and so users clearly can see if they want to configure or change they have to go to "config" menu
SubMenu item is a menuItem itself
//a submenu
pluginsMenu.addSeparator();
submenu = new JMenu("Plugin Name");
//add one submenuItem
menuItem = new JMenuItem("Config");
submenu.add(menuItem);
//add another submenuItem
menuItem = new JMenuItem("Run/Execute");
submenu.add(menuItem);
//add submenu to mainPluginMenu
pluginsMenu.add(submenu);
see actual code here menu
Related
I´m writing an Eclipse plugin to show the contents of an own file type in an own custom editor.
This file basically consists of 1..n IFile´s from the Project Explorer which are shown in a SWT TreeView.
The entries in this TreeView are some Beans organized in a flat List, but i provide an adapter to convert them to IFile´s.
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="de.dstg.delta.collections.model.Collection$Member"
class="de.dstg.delta.collections.CollectionMemberAdapterFactory">
<adapter
type="org.eclipse.ui.views.properties.IPropertySource2">
</adapter>
<adapter
type="org.eclipse.core.resources.IFile">
</adapter>
</factory>
</extension>
Eclipse Screenshot
It´s no problem to show a custom SWT menu but i think the right way is using the Eclipse menu structure, especially by providing default behaviour for Resources.
How can i show the default context popup menu, which is used by right-clicking resources in the Project Explorer, in my SWT TableView?
EDIT second question removed
EDIT2
According to the answer from greg-449, the problem remains that the context menu shows no entries i would like to have for this type of selection.
f.e. i need delete or open with or something like that 'file basics' without implementing it on my own.
We have also some other menus from additional plugins that should be visible here when the appropriate file type is selected. This works in Project Explorer but not in my table view.
I think the problem is the type of the selected element.
Plugin spy shows the following in my table view:
type of the selected element: Collection$Member,
interfaces valid for the selected element: IAdaptable
whereas the Project Explorer shows File and IFile, respectively.
My adapter works generally and delivers the related IFile while being triggered from an unknown Eclipse source.
I think i have to explicitely say, that the context menu should use the IFile type to get the correct menu entries but i dont´t know how.
Or did i miss something?
There isn't really a 'default' menu. Some menu items are defined to be added to all popup menus that define a specific place holder.
To use the place holder you must register your context menu with Eclipse, something like:
private void createContextMenu(Viewer viewer) {
Control menuControl = viewer.getControl();
MenuManager menuMgr = new MenuManager("#PopUp");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
#Override
public void menuAboutToShow(IMenuManager mgr) {
fillContextMenu(mgr);
}
});
Menu menu = menuMgr.createContextMenu(menuControl);
menuControl.setMenu(menu);
// register the context menu such that other plugins may contribute to it
getSite().registerContextMenu(menuMgr, viewer);
}
private void fillContextMenu(IMenuManager menu) {
// TODO add your actions
// Standard additions
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
You will probably also need to set your viewer as the 'selection provider':
getSite().setSelectionProvider(viewer);
Many menu items will check this to see what the type of the current selection is.
There is nothing that will automatically give you things like Open With or Delete, you have to add these yourself in the 'fillContextMenu' section.
You can use org.eclipse.ui.actions.OpenWithMenu for Open With.
IFile file = ... currently selected file
IMenuManager submenu = new MenuManager("Open With...");
submenu.add(new OpenWithMenu(getSite().getPage(), file);
menu.append(submenu);
I am developing an eclipse plugin.I have given my menu,sub menu names and plugin id in plugin.xml.
I want to dynamically rename my plugin id as well my menu and sub menu name.I came across this SOF link.I am using the below code.
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
Menu menu = menuManager.getMenu();
String itemId = "plugin_menu_id";
IContributionItem item = menuManager.find(itemId);
System.out.println("item.getId() --> " + item.getId());
//gives the plugin_menu_id
System.out.println( "menu.getItemCount() ==> "+ menu.getItemCount());
//gives no of menus in eclipse
But unfortunately I am unable to find an option to rename the menu from IContributionItem.
So is there any other way to modify things in eclipse plugin?
I found a temporary solution .Instead of using a MenuManager,I created a dynamic menu using Actions Framework instead of Command Framework though the former is deprecated.
So each time , I create a Menu,I am able to change the Menu name,icon etc.
I am searching for an equivalent in the Command Framework and will post as soon as I found that.
I have a jFace wizard, I am using this to create a new project type eclipse plugin. As you can see from image below, I have one treeviewer on left side, and a SWT group on right side. What I want is when ever user selects one of the item from treeviewer, I should be able to create dynamic controls on right side SWT Group. Say user selects Test One, one right side I should be able to create few controls like label, text and few radio buttons on right side, similarly if user selects Test Two I should be able to create dynamic controls on right side.
Currently I tried below code:
tree.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
for (int i = 0; i < selection.length; i++) {
String tempStr = selection[i].toString();
tempStr = tempStr.replaceAll("TreeItem \\{", "");
String finalStr = tempStr.replaceAll("\\}", "");
if (finalStr.equals("Test One")) {
Button btn = new Button(g2, SWT.NONE); //g2 is right side group
btn.setText("Blaaaa");
btn.setVisible(true);
container.redraw();
}
}
But when I run, I see no changes on right group. Can anyone guide me what I am doing wrong? Any pointers would be very appreciated, since I am new to Eclipse development and SWT.
You probably didn't set a layout on the g2 group. This is the common cause for controls not showing up. You can also try using g2.layout() to ensure that the new controls are correctly laid out after you create them.
Additionally you could look at using a StackLayout so that once you create a set of controls you can just hide them all at once instead of destroying when the selection changes. This is often useful so that if the user comes back to a previous selection, they will find the data they entered in the same state when they switched the selection. Here is an example.
I added the Search Plugin to my RCP application. On addition of this plugin it adds the search menu in main menu bar.
I observed that there is some pixels gap between search menu and its previous menu.
Please see the image.
Does anyone know how this is coming and how I can remove it?
I fixed this issue by modifying postWindowCreate method of ApplicationWorkbenchWindowAdvisor class of RCP application.
IWorkbenchPage page = this.getWindowConfigurer().getWindow().getActivePage();
MenuManager menuBarManager = ((ApplicationWindow)page.getWorkbenchWindow()).getMenuBarManager();
menuBarManager.remove("navigate");
Insert a "navigate" path in your ActionBarAdvisor implementation:
protected void fillMenuBar(IMenuManager menuBar) {
menuBar.add(createFileMenu());
menuBar.add(createEditMenu());
menuBar.add(new GroupMarker(IWorkbenchActionConstants.M_NAVIGATE));
menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
menuBar.add(createHelpMenu());
}
i am trying to capture user selections from the menu bar , for example if the user pressed File in the menu, my plug-in gonna print "File pressed".
i figured out how to listen to view selections by IselectionService , but still has no clue how to do it with the main menu bars(or toolbars).
thanx for help
More details :
I gonna explain my problem a little bit more precisely :
I would like capture top-level menus actions and toolbar, the problem is I really don't know how to create and attach the listener.
Here is the ISelectionListener of the plugin.
My purpose is to listen to the workbench top-level menu selections and toolbar.
Thanx for help
// the listener we register with the selection service
private ISelectionListener listener = new ISelectionListener() {
public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) {
// we ignore our own selections
if (sourcepart != SelectionView.this) {
showSelection(sourcepart, selection);
}
}
};
...
...
public void createPartControl(Composite parent) {
...
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(listener);
P.S : Most what I found about menu listener were SWT stuff for some view or windows I had created, thats not what I meant, I need listener to the main top level menu and toolbars in eclipse workbench.
If you know the location uri (which you can check with a PluginSpy), you can add an handler in order to react to that menu event.
Note: The Menu Contribution article mentions the locationURI for:
main menu is "org.eclipse.ui.main.menu"
main toolbor is "org.eclipse.ui.main.toolbar"
Yuo could try to use the ICommandService:
with this service you can register an IExecutionListener.
This way you can track all the commands wich are executed but I'm afraid that this way you can't track the menu item that activated the command itself.
Hope it helps
i just wanna tell you i got some help from guys who made Smarttutor plugin, which excatly what i need. captures all the actions on the menus. – amir farah 31 secs ago edit i just wanna tell you i got some help from guys who made Smarttutor plugin, which excatly what i need. captures all the actions on the menus.
here is the website:code.google.com/p/smarttutor