Creating SWT context menu in Swing Controls. [message #467455] |
Fri, 04 May 2007 00:50  |
Eclipse User |
|
|
|
Originally posted by: freakycreak.yahoo.com
Hi frnds,
I've got an editor and in its createPartControl method Im creating a
Swing Frame, Panel and adding a context menu.
But, the context menu doesn't pop up when i do a right click.
I know that the menu works cause if i remove the Frame and leave just
the parent composite, the menu shows.
I dont want to create my popupmenu using Swing controls because i would
like to have my context menu extensable
by other plugins.
So, Is there some way I could get the context menu to show in the Frame
and also be extensable?
Here's my createPartControl and plugin.xml:
public void createPartControl(Composite parent) {
final Composite composite = new Composite(container, SWT.EMBEDDED);
final Frame frame = SWT_AWT.new_Frame(composite);
Panel panel = new java.awt.Panel(BorderLayout());
frame.add(panel);
JPanel jpanel = new JPanel(BorderLayout());
panel.add(jpanel); jpanel.add(view); //View is a JComponent with
a Canvas
// Create menu manager.
MenuManager menuMgr = new MenuManager();
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager mgr) {
mgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
}
});
// Create menu.
Menu menu = menuMgr.createContextMenu(composite);
composite.setMenu(menu);
// Register menu for extension.
getSite().registerContextMenu("test.menuid",menuMgr,getSite().getSelectionProvider());
}
And in my plugin.xml I'm creating a popupmenu:
<extension point="org.eclipse.ui.popupMenus">
<viewerContribution
id="test.viewerContribution"
targetID="test.menuid">
<menu
label="New Submenu"
path="additions"
id="test.popupMenu.submenu">
<separator
name="additions">
</separator>
</menu>
<action id="test.ZoomInAction"
label="Zoom In"
icon="icons/sample.gif"
menubarPath="test.popupMenu.submenu/additions"
class="test.ZoomInAction"> </action>
</viewerContribution> </extension>
--
Can anyone please guide me on this. Is it posiible to create such swt
context menu on that swing controls ??
Thanks in advance.
|
|
|
|
Powered by
FUDForum. Page generated in 1.03327 seconds