1

I want to add an action on the Project Explorer context menu. Is is possible to display different labels according to the nature of the project selected if the action is defined via org.eclipse.ui.popupMenus? I tryied defining 2 contributions and try to hide one according to the nature, but I did'n find a way to test the project nature.

catalina
  • 223
  • 2
  • 8

1 Answers1

0

You can try the method outlined in http://timezra.blogspot.com/2007/12/dynamic-labels-for-eclipse-context.html
Which is simply to create a dynamic contribution where you will get a method to return the IMenuContribution[] list, and in the code you can check on whatever condition you want and return the appropriate contribution.

Another approach is outlined in http://wiki.eclipse.org/Menu_Contributions#State_associated_with_the_command_is_propogated_to_UI_visible_elements
to have a NAME state associated with the command and update it as needed, I haven't tried it, but it seems more inline with what you ask.
<state id="NAME" class="org.eclipse.jface.menus.TextState" />

mhussein
  • 615
  • 5
  • 7
  • Thanks for your answer. The reason I asked if it is possible to do this using org.eclipse.ui.popupMenus is because I need to display my action in a submenu of the contextmenu and I cannot figure out how to do that using org.eclipse.ui.menus (see my other question [link](http://stackoverflow.com/questions/12617898/how-to-add-a-submenu-entry-to-eclipse-package-explorer-context-menu-item-using-o). So your post is really helpul but only if I figure out that. – catalina Sep 27 '12 at 10:32
  • Now that I succeeded to add a submenu using org.eclipse.ui.menus your answer really helped. Though, I am not sure if this is how I should do it. As an alternative, I could contribute two commands both having the same ID (so same handler) setting for each the visible state according to the project nature using visibleWhen. Using the link you suggested I have to programatically check the nature of the project selected, inside the contribution item. Which one you think would be better? – catalina Sep 28 '12 at 09:07
  • This is a tough question :) I am not sure, I would personally go for the programmatic approach as it would be more "debuggable", may be I am too old school for eclipse :) Having to handlers for the same command with exclusive visibleWhen should work fine, and would be easier to implement, so this might be your better option. I hope I had a more definite answer, I am sorry. – mhussein Sep 30 '12 at 08:55