How to contribute a context menu to the Outline view [message #325955] |
Tue, 04 March 2008 04:27  |
Eclipse User |
|
|
|
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 #326004 is a reply to message #326001] |
Wed, 05 March 2008 09:19  |
Eclipse User |
|
|
|
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. :-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. I'm not sure which magical things are
key to making it work. 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"> </font><font
color="#7f0055"><b>protected </b></font><font color="#7f0055"><b>void </b></font><font
color="#000000">createContextMenuFor</font><font color="#000000">(</font><font
color="#000000">StructuredViewer viewer</font><font color="#000000">)</font><br>
<font color="#ffffff"> </font><font color="#000000">{</font><br>
<font color="#ffffff"> </font ><font color="#000000">MenuManager contextMenu = </font><font
color="#7f0055"><b>new </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"> </font ><font color="#000000">contextMenu.add</font><font
color="#000000">(</font><font color="#7f0055"><b>new </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"> </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"> </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"> </font ><font color="#000000">Menu menu= 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"> </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"> </font ><font color="#000000">getSite</font><font
color="#000000">()</font><font color="#000000">.registerContextMenu</font><font
color="#000000">(</font><font color="#000000">contextMenu, </font><font
color="#7f0055"><b>new </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"> </font ><font color="#7f0055"><b>int </b></font><font
color="#000000"> dndOperations = DND.DROP_COPY |&a mp;nbsp;DND.DROP_MOVE | DND.DROP_LINK; </font><br>
<font color="#ffffff"> </font ><font color="#000000">Transfer</font><font
color="#000000">[] </font><font color="#000000">transfers = </font><font
color="#7f0055"><b>new </b></font><font color="#000000">Transfer</font><font
color="#000000">[] { </font><font color="#000000">LocalTransfer.getInstance</font><font
color="#000000">() }</font><font color="#000000">;</font><br>
<font color="#ffffff"> </font ><font color="#000000">viewer.addDragSupport</font><font
color="#000000">(</font><font color="#000000">dndOperations, transfers, </font><font
color="#7f0055"><b>new </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"> </font ><font color="#000000">viewer.addDropSupport</font><font
color="#000000">(</font><font color="#000000">dndOperations, transfers, </font><font
color="#7f0055"><b>new </b></font><font color="#000000">EditingDomainViewerDropAdapter</font><font
color="#000000">(</font><font color="#000000">editingDomain, viewer</font><font
color="#000000">))</font><font color="#000000">;</font><br>
<font color="#ffffff"> </font><font color="#000000">}</font></code>
</td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== --></blockquote>
</body>
</html>
--------------090809040806090500000706--
|
|
|
Powered by
FUDForum. Page generated in 0.08766 seconds