IContributionItems Access details [message #330198] |
Fri, 18 July 2008 20:16  |
Eclipse User |
|
|
|
Originally posted by: paulin.spextreme.com
I'm attempting to work on the SWTBot product
(http://swtbot.sourceforge.net/index.html) and in the process I'm working
to try and access the View menus and Toolbars.
Anyway I've been able to run a command when I give the ID to the handler
service. I've also been able to programatically get a list of all the
contribution items for a view.
Well now here is my problem. I need to either get physical menu item
widgets to trigger them as if being pressed, or I need to get the command
id. My problem is I haven't been able to get either of these. Personally
I like to be able to get both.
Any help would be appreciated.
steve
PS I'm hoping Paul Webster will respond on this as he seems to be the
master of all around this topic.
|
|
|
|
Re: IContributionItems Access details [message #330236 is a reply to message #330198] |
Tue, 22 July 2008 11:12  |
Eclipse User |
|
|
|
Hmmm. If you can get the MenuManager or ToolBarManager for the view,
you can get a list of IContributionItems. Depending on the view, some
of them are ActionContributionItems, and aci.getAction().run() will run
them (most of the time). CommandContributionItem doesn't have getters
for most of its information, there isn't a general purpose need for them
(although I can see why swtbot could use them). As a matter of fact,
CommandContributionItem has no useful API above IContributionItem. The
only way to access information for CommandContributionItem would be to
use reflection to yank it out of the private member variables (messy at
the best of times).
The other option is to walk the SWT Menu/MenuItem hierarchy, but you
have to get it first (and I'm not sure where you are starting from, an
active IWorkbenchPart?). Once you have the menu item, executing is
straight forward (for non-dynamic menu cases):
item.notifyListeners(SWT.Selection, null);
But that won't handle the general case, only the 80% case. Is there a
specific direction you are trying to take?
Later,
PW
--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm
|
|
|
Powered by
FUDForum. Page generated in 0.03102 seconds