context menu for component within an editor [message #448853] |
Fri, 05 May 2006 06:05  |
Eclipse User |
|
|
|
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 #448975 is a reply to message #448895] |
Mon, 08 May 2006 07:15  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.31564 seconds