Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to contribute a context menu to the Outline view
How to contribute a context menu to the Outline view [message #325955] Tue, 04 March 2008 04:27 Go to next message
Eclipse UserFriend
I need to add a context menu to the Outline view. Here is what i did: I extended the popupMenu extention point with a objectContribution -> I created a menu and an action -> the good thing is that this works, however it shows the context menu only in the package explorer and not in the Outline view. As a ObjectClass I use the -> org.eclipse.core.resources.IResource.
Then I tried the Viewer contribution which doesn't even work. I used as a targetId -> org.eclipse.ui.views.ContentOutline. I hope that this is the correct one for the Outline View. I want to ask how should I proceed. I actualy need a an objectContribution, I was only experementing with the viewerContribution. If I manage to make atleast one of them to work for me will be great -> any ideas what might be the problem?
Re: How to contribute a context menu to the Outline view [message #325960 is a reply to message #325955] Tue, 04 March 2008 06:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Peter,

Which outline view displays IResources? Editors themselves create those
things. Are you sure the view is really showing objects of that type?
Pop up menus will generally work for any view that's registered itself
to receive object contributions (using
IWorkbenchPartSite.registerContextMenu).


peterM wrote:
> I need to add a context menu to the Outline view. Here is what i did: I extended the popupMenu extention point with a objectContribution -> I created a menu and an action -> the good thing is that this works, however it shows the context menu only in the package explorer and not in the Outline view. As a ObjectClass I use the -> org.eclipse.core.resources.IResource.
> Then I tried the Viewer contribution which doesn't even work. I used as a targetId -> org.eclipse.ui.views.ContentOutline. I hope that this is the correct one for the Outline View. I want to ask how should I proceed. I actualy need a an objectContribution, I was only experementing with the viewerContribution. If I manage to make atleast one of them to work for me will be great -> any ideas what might be the problem?
>
Re: How to contribute a context menu to the Outline view [message #325987 is a reply to message #325960] Wed, 05 March 2008 04:52 Go to previous messageGo to next message
Eclipse UserFriend
Well the truth is I didn't know what was the type of the object within the outline view, but even when I used as an objectClass the java.lang.Object there was nothing shown in the outline view. How can I get an instance of the IWorkbenchPartSite? Where must I regester the Context menu, because I definetly haven't done that.
Thanks,
Peter
Re: How to contribute a context menu to the Outline view [message #325990 is a reply to message #325987] Wed, 05 March 2008 06:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Peter,

It is your outline view? I.e., one that you've provided by code you've
written? If someone else provides it, they might simply not have
registered for popup contributions and there's not much you can do about
that externally.


peterM wrote:
> Well the truth is I didn't know what was the type of the object within the outline view, but even when I used as an objectClass the java.lang.Object there was nothing shown in the outline view. How can I get an instance of the IWorkbenchPartSite? Where must I regester the Context menu, because I definetly haven't done that.
> Thanks,
> Peter
>
Re: How to contribute a context menu to the Outline view [message #326001 is a reply to message #325990] Wed, 05 March 2008 08:57 Go to previous messageGo to next message
Eclipse UserFriend
Well yeah, it is mine. It is within a custom perspective, but even after I've regestered the outline view, it still doesn't want to show anything. That is what confuses me. I've programaticly added the menu to the tree. The strange thig is that in debug mode it seems to work, but still it doesn't want to show my context view. Here is the code I am using. this pointer is refuring to my ContentOutlinePage:
private void regesterMenuToOutlineView()
{
final IWorkbench workbench = PlatformUI.getWorkbench();
final MenuManager menuManager = new MenuManager();
menuManager.addMenuListener(new IMenuListener(){
public void menuAboutToShow(IMenuManager manager)
{
System.out.println("Shuoul open the menu");
//menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
//menuManager.add(new OpenWithMenu(workbench.getActiveWorkbenchWindow().getActiveP age()));
}
});
Menu menu = menuManager.createContextMenu(this.getTreeViewer().getTree() );
this.getControl().setMenu(menu);
menuManager.setRemoveAllWhenShown(true);
menu.setVisible(true);
menu.setEnabled(true);
this.getSite().registerContextMenu(MENU_ID, menuManager, this);
//menuManager.setRemoveAllWhenShown(true);
//workbench.getActiveWorkbenchWindow().getActivePage().getAc tivePart().getSite().registerContextMenu(menuManager, this);
}
Re: How to contribute a context menu to the Outline view [message #326004 is a reply to message #326001] Wed, 05 March 2008 09:19 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------090809040806090500000706
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Peter,

Comments below.

peterM wrote:
> Well yeah, it is mine.
That helps. :-P
> It is within a custom perspective, but even after I've regestered the outline view, it still doesn't want to show anything. That is what confuses me. I've programaticly added the menu to the tree. The strange thig is that in debug mode it seems to work, but still it doesn't want to show my context view. Here is the code I am using. this pointer is refuring to my ContentOutlinePage:
> private void regesterMenuToOutlineView()
> {
> final IWorkbench workbench = PlatformUI.getWorkbench();
> final MenuManager menuManager = new MenuManager();
> menuManager.addMenuListener(new IMenuListener(){
> public void menuAboutToShow(IMenuManager manager)
> {
> System.out.println("Shuoul open the menu");
> //menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
> //menuManager.add(new OpenWithMenu(workbench.getActiveWorkbenchWindow().getActiveP age()));
> }
> });
> Menu menu = menuManager.createContextMenu(this.getTreeViewer().getTree() );
> this.getControl().setMenu(menu);
> menuManager.setRemoveAllWhenShown(true);
> menu.setVisible(true);
> menu.setEnabled(true);
> this.getSite().registerContextMenu(MENU_ID, menuManager, this);
> //menuManager.setRemoveAllWhenShown(true);
> //workbench.getActiveWorkbenchWindow().getActivePage().getAc tivePart().getSite().registerContextMenu(menuManager, this);
> }
>
Here's what we do in an EMF generated editor for which object
contributions definitely work. I'm not sure which magical things are
key to making it work. I think the additions separator is very import.

| *protected **void *createContextMenuFor(StructuredViewer viewer)
{
MenuManager contextMenu = *new *MenuManager("#PopUp");
contextMenu.add(*new *Separator("additions"));
contextMenu.setRemoveAllWhenShown(*true*);
contextMenu.addMenuListener(*this*);
Menu menu= contextMenu.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(contextMenu, *new *UnwrappingSelectionProvider(viewer));

*int *dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
Transfer[] transfers = *new *Transfer[] { LocalTransfer.getInstance() };
viewer.addDragSupport(dndOperations, transfers, *new *ViewerDragAdapter(viewer));
viewer.addDropSupport(dndOperations, transfers, *new *EditingDomainViewerDropAdapter(editingDomain, viewer));
}|


--------------090809040806090500000706
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Peter,<br>
<br>
Comments below.<br>
<br>
peterM wrote:
<blockquote
cite="mid:972503.29981204725459652.JavaMail.root@cp1.dzone.com"
type="cite">
<pre wrap="">Well yeah, it is mine.</pre>
</blockquote>
That helps.&nbsp; :-P<br>
<blockquote
cite="mid:972503.29981204725459652.JavaMail.root@cp1.dzone.com"
type="cite">
<pre wrap=""> It is within a custom perspective, but even after I've regestered the outline view, it still doesn't want to show anything. That is what confuses me. I've programaticly added the menu to the tree. The strange thig is that in debug mode it seems to work, but still it doesn't want to show my context view. Here is the code I am using. this pointer is refuring to my ContentOutlinePage:
private void regesterMenuToOutlineView()
{
final IWorkbench workbench = PlatformUI.getWorkbench();
final MenuManager menuManager = new MenuManager();
menuManager.addMenuListener(new IMenuListener(){
public void menuAboutToShow(IMenuManager manager)
{
System.out.println("Shuoul open the menu");
//menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
//menuManager.add(new OpenWithMenu(workbench.getActiveWorkbenchWindow().getActiveP age()));
}
});
Menu menu = menuManager.createContextMenu(this.getTreeViewer().getTree() );
this.getControl().setMenu(menu);
menuManager.setRemoveAllWhenShown(true);
menu.setVisible(true);
menu.setEnabled(true);
this.getSite().registerContextMenu(MENU_ID, menuManager, this);
//menuManager.setRemoveAllWhenShown(true);
//workbench.getActiveWorkbenchWindow().getActivePage().getAc tivePart().getSite().registerContextMenu(menuManager, this);
}
</pre>
</blockquote>
Here's what we do in an EMF generated editor for which object
contributions definitely work.&nbsp; I'm not sure which magical things are
key to making it work.&nbsp; I think the additions separator is very import.<br>
<blockquote>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td align="left" nowrap="nowrap"
valign="top"> <code><font color="#ffffff">&nbsp;&nbsp;</font><font
color="#7f0055"><b>protected&nbsp;</b></font><font color="#7f0055"><b>void&nbsp;</b></font><font
color="#000000">createContextMenuFor</font><font color="#000000">(</font><font
color="#000000">StructuredViewer&nbsp;viewer</font><font color="#000000">)</font><br>
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">{</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">MenuManager&nbsp;contextMenu&nbsp;=&nbsp; </font><font
color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">MenuManager</font><font
color="#000000">(</font><font color="#2a00ff">"#PopUp"</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">contextMenu.add</font><font
color="#000000">(</font><font color="#7f0055"><b>new&nbsp;</b></font><font
color="#000000">Separator</font><font color="#000000">(</font><font
color="#2a00ff">"additions"</font><font color="#000000">))</font><font
color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">contextMenu.setRemoveAllWhenShown</font><font
color="#000000">(</font><font color="#7f0055"><b>true</b></font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">contextMenu.addMenuListener</font><font
color="#000000">(</font><font color="#7f0055"><b>this</b></font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">Menu&nbsp;menu=&nbsp;contextMenu.createContextMenu </font><font
color="#000000">(</font><font color="#000000">viewer.getControl</font><font
color="#000000">())</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">viewer.getControl</font><font
color="#000000">()</font><font color="#000000">.setMenu</font><font
color="#000000">(</font><font color="#000000">menu</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">getSite</font><font
color="#000000">()</font><font color="#000000">.registerContextMenu</font><font
color="#000000">(</font><font color="#000000">contextMenu,&nbsp;</font><font
color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">UnwrappingSelectionProvider</font><font
color="#000000">(</font><font color="#000000">viewer</font><font
color="#000000">))</font><font color="#000000">;</font><br>
<font color="#ffffff"></font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#7f0055"><b>int&nbsp;</b></font><font
color="#000000"> dndOperations&nbsp;=&nbsp;DND.DROP_COPY&nbsp;|&a mp;nbsp;DND.DROP_MOVE&nbsp;|&nbsp;DND.DROP_LINK; </font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">Transfer</font><font
color="#000000">[]&nbsp;</font><font color="#000000">transfers&nbsp;=&nbsp;</font><font
color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">Transfer</font><font
color="#000000">[]&nbsp;{&nbsp;</font><font color="#000000">LocalTransfer.getInstance</font><font
color="#000000">()&nbsp;}</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">viewer.addDragSupport</font><font
color="#000000">(</font><font color="#000000">dndOperations,&nbsp;transfers,&nbsp; </font><font
color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">ViewerDragAdapter</font><font
color="#000000">(</font><font color="#000000">viewer</font><font
color="#000000">))</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">viewer.addDropSupport</font><font
color="#000000">(</font><font color="#000000">dndOperations,&nbsp;transfers,&nbsp; </font><font
color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">EditingDomainViewerDropAdapter</font><font
color="#000000">(</font><font color="#000000">editingDomain,&nbsp;viewer</font><font
color="#000000">))</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font></code>
</td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== --></blockquote>
</body>
</html>

--------------090809040806090500000706--
Previous Topic:Perspectives and Views
Next Topic:get the standard context menu on custom objects
Goto Forum:
  


Current Time: Fri Apr 25 18:00:12 EDT 2025

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

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

Back to the top