Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » context menu for component within an editor
context menu for component within an editor [message #448853] Fri, 05 May 2006 06:05 Go to next message
Eclipse UserFriend
Hello,

I try to create a context menu for only one component (TableViewer)
within an editor. This is the code so far:

(within the editor class)
....
private void hookContextMenu(Composite composite) {

MenuManager menuMgr = new MenuManager("#PopupMenu",
"de.myEditorId.menu1");

menuMgr.setRemoveAllWhenShown(true);

menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
});

Menu attributeTabMenu = menuMgr.createContextMenu(composite);
attributeTableViewer.getControl().setMenu(attributeTabMenu);

getSite().registerContextMenu("de.myEditorId.menu1", menuMgr,
attributeTableViewer);
}
....

And this is the interesting part of the plugin.xml:
....
<extension
point="org.eclipse.ui.popupMenus">
<viewerContribution
id="de.myEditorId.viewerContribution1"
targetID="de.myEditorId">
<action
class="de.myAction"
enablesFor="*"
icon="icons/attribute_add.gif"
id="de.myAction"
label="Attribut anlegen"
menubarPath="de.myEditorId.menu1/attribute"
style="push"/>
</viewerContribution>
</extension>
....

Neither is the menu showing, nor is any error message in the log, if I
rightclick the component.

Do I have to configure a corresponding menu in the plugin.xml? Where do
I have to put in the id from the editor and where the id from the menu?

I was wondering if anybody got an example?

Thanks in advance!

Alex
Re: context menu for component within an editor [message #448895 is a reply to message #448853] Sat, 06 May 2006 11:19 Go to previous messageGo to next message
Eclipse UserFriend
Alexander Grigo wrote:
> Hello,
>
> I try to create a context menu for only one component (TableViewer)
> within an editor. This is the code so far:
>
> (within the editor class)
> ...
> private void hookContextMenu(Composite composite) {
>
> MenuManager menuMgr = new MenuManager("#PopupMenu",
> "de.myEditorId.menu1");
>
> menuMgr.setRemoveAllWhenShown(true);
>
> menuMgr.addMenuListener(new IMenuListener() {
> public void menuAboutToShow(IMenuManager manager) {
> manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
> }
> });
>
> Menu attributeTabMenu = menuMgr.createContextMenu(composite);
> attributeTableViewer.getControl().setMenu(attributeTabMenu);
>
> getSite().registerContextMenu("de.myEditorId.menu1", menuMgr,
> attributeTableViewer);
> }
> ...
>
> And this is the interesting part of the plugin.xml:
> ...
> <extension
> point="org.eclipse.ui.popupMenus">
> <viewerContribution
> id="de.myEditorId.viewerContribution1"
> targetID="de.myEditorId">
> <action
> class="de.myAction"
> enablesFor="*"
> icon="icons/attribute_add.gif"
> id="de.myAction"
> label="Attribut anlegen"
> menubarPath="de.myEditorId.menu1/attribute"
> style="push"/>
> </viewerContribution>
> </extension>
> ...

AFAIK, you need to have your target ID match your context menu id that
it was registered with, de.myEditorId.menu1

and your menubarPath is then w.r.t your context menu ... I'd use "additions"

Later,
PW
Re: context menu for component within an editor [message #448975 is a reply to message #448895] Mon, 08 May 2006 07:15 Go to previous message
Eclipse UserFriend
Paul Webster schrieb:
> Alexander Grigo wrote:
>> Hello,
>>
>> I try to create a context menu for only one component (TableViewer)
>> within an editor. This is the code so far:
>>
>> (within the editor class)
>> ...
>> private void hookContextMenu(Composite composite) {
>>
>> MenuManager menuMgr = new MenuManager("#PopupMenu",
>> "de.myEditorId.menu1");
>> menuMgr.setRemoveAllWhenShown(true);
>> menuMgr.addMenuListener(new IMenuListener() {
>> public void menuAboutToShow(IMenuManager manager) {
>> manager.add(new
>> Separator(IWorkbenchActionConstants.MB_ADDITIONS)); }
>> });
>>
>> Menu attributeTabMenu = menuMgr.createContextMenu(composite);
>> attributeTableViewer.getControl().setMenu(attributeTabMenu);
>> getSite().registerContextMenu("de.myEditorId.menu1",
>> menuMgr, attributeTableViewer);
>> }
>> ...
>>
>> And this is the interesting part of the plugin.xml:
>> ...
>> <extension
>> point="org.eclipse.ui.popupMenus">
>> <viewerContribution
>> id="de.myEditorId.viewerContribution1"
>> targetID="de.myEditorId">
>> <action
>> class="de.myAction"
>> enablesFor="*"
>> icon="icons/attribute_add.gif"
>> id="de.myAction"
>> label="Attribut anlegen"
>> menubarPath="de.myEditorId.menu1/attribute"
>> style="push"/>
>> </viewerContribution>
>> </extension>
>> ...
>
> AFAIK, you need to have your target ID match your context menu id that
> it was registered with, de.myEditorId.menu1
>
> and your menubarPath is then w.r.t your context menu ... I'd use
> "additions"
>
> Later,
> PW
Hello,

thanks for your help. You were absolutely right. I just put in
"de.myEditorId.menu1" as the targetID and "additions" as the
menubarPath" and it worked.

Alex
Previous Topic:Making another project into a plugin
Next Topic:How to programmatically add a shortcut to the perspective switching bar ...
Goto Forum:
  


Current Time: Sat Aug 30 13:44:58 EDT 2025

Powered by FUDForum. Page generated in 0.31564 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top