IContributionItems Access details [message #330198] |
Sat, 19 July 2008 00: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 #330207 is a reply to message #330198] |
Mon, 21 July 2008 01:59 |
Eclipse User |
|
|
|
Originally posted by: paulin.spextreme.com
Well I did this a different way but now this leads me into another
question.
I have an CommandContributionItem. When I look at it in the debugger view
and click on the command (paramaterizedCommand) it shows the name as my
menu items name. This is great because I want the name.
However the CommandContributionItem doesn't have a get command or get name
method. SO I use the command service to get the command which has the get
name.
Anyway it gets the command fine (IDs match). However the command doesn't
have the name anymore.
So what am I doing wrong or how do I get the text/name that represents the
label of the menu?
Steve
PS I'll also eventually need the tooltip. So that insight would be
helpful as well.
|
|
|
Re: IContributionItems Access details [message #330236 is a reply to message #330198] |
Tue, 22 July 2008 15:12 |
|
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
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Powered by
FUDForum. Page generated in 0.03652 seconds