Home » Eclipse Projects » Remote Application Platform (RAP) » How to hide the context menu in a customized viewer?
How to hide the context menu in a customized viewer? [message #519247] |
Mon, 08 March 2010 09:34 |
tingel christian Messages: 46 Registered: December 2009 |
Member |
|
|
Hi, All experts:
Long time no see and Long time no questions
I created a new RAP project based on the mail template existing in the new project wizard and had some modification on it and it's now something like this:
public class View extends ViewPart {
public static final String ID = "org.eclipse.rap.sample.view";
MenuManager menuManager = new MenuManager();
public void createPartControl(Composite parent) {
MailViewer viewer = new MailViewer(parent);
this.getSite().registerContextMenu(menuManager, viewer);
this.getSite().setSelectionProvider(viewer);
}
public void setFocus() {
}
private class MailViewer extends Viewer
{
Composite topComposite;
MailViewer(Composite parent)
{
topComposite = new Composite(parent, SWT.None);
topComposite.setLayout(new FillLayout());
Composite top = new Composite(topComposite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
top.setLayout(layout);
// top banner
Composite banner = new Composite(top, SWT.NONE);
banner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL, GridData.VERTICAL_ALIGN_BEGINNING, true, false));
layout = new GridLayout();
layout.marginHeight = 5;
layout.marginWidth = 10;
layout.numColumns = 2;
banner.setLayout(layout);
// setup bold font
Font boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFA ULT_FONT);
Label l = new Label(banner, SWT.WRAP);
l.setText("Subject:");
l.setFont(boldFont);
l = new Label(banner, SWT.WRAP);
l.setText("This is a message about the cool Eclipse RCP!");
l = new Label(banner, SWT.WRAP);
l.setText("From:");
l.setFont(boldFont);
final Link link = new Link(banner, SWT.NONE);
link.setText("<a>nicole@mail.org</a>");
l = new Label(banner, SWT.WRAP);
l.setText("Date:");
l.setFont(boldFont);
l = new Label(banner, SWT.WRAP);
l.setText("10:34 am");
// message contents
Text text = new Text(top, SWT.MULTI | SWT.WRAP);
text.setText("This RCP Application was generated from the PDE Plug-in Project wizard. This sample shows how to:\n");
text.setLayoutData(new GridData(GridData.FILL_BOTH));
banner.setMenu(menuManager.createContextMenu(banner));
}
public Control getControl()
{
return this.topComposite;
}
public Object getInput()
{
return null;
}
public ISelection getSelection()
{
return new StructuredSelection(new Object());
}
public void refresh()
{
}
public void setInput(Object input)
{
}
public void setSelection(ISelection selection, boolean reveal)
{
}
}
}
(Sorry for my stupid-looking modification but actually my purpose is just to simplify the question)
As you see, I added a context menu to the banner composite.
When I start a new session, the context menu poped up as I had experted, but when I clicked at somewhere else that was blank on the banner composite, the context menu did not get hiden.
So, could you please tell me how to hide the context menu by clicking elsewhere on the parent control as Table does(We can hide the context menu of a Table by clicking anywhere else except the point where the context menu starts)?
Great thanks and Best Regards!
Tingel Christian
[Updated on: Mon, 08 March 2010 09:36] Report message to a moderator
|
|
|
Re: How to hide the context menu in a customized viewer? [message #519376 is a reply to message #519247] |
Mon, 08 March 2010 16:26 |
Ivan Furnadjiev Messages: 2427 Registered: July 2009 Location: Sofia, Bulgaria |
Senior Member |
|
|
Hi Christian,
I've just checked your code with RAP from CVS HEAD and it's working as
expected - context menu gets hidden when I click somewhere in the banner
composite. Maybe you run into this bug:
287314: [Menu] Context-menu does not always close on click
https://bugs.eclipse.org/bugs/show_bug.cgi?id=287314
which has been fixed in 1.3M3. Which version of RAP are you using?
Best,
Ivan
On 03/08/2010 11:34 AM, tingel christian wrote:
> Hi, All experts:
>
> Long time no see and Long time no questions :)
> I created a new RAP project based on the mail template existing in the
> new project wizard and had some modification on it and it's now
> something like this:
>
> public class View extends ViewPart {
>
> public static final String ID = "org.eclipse.rap.sample.view";
>
> MenuManager menuManager = new MenuManager();
>
> public void createPartControl(Composite parent) {
> MailViewer viewer = new MailViewer(parent);
> this.getSite().registerContextMenu(menuManager, viewer);
> this.getSite().setSelectionProvider(viewer);
> }
>
> public void setFocus() {
> }
>
> private class MailViewer extends Viewer
> {
> Composite topComposite;
> MailViewer(Composite parent)
> {
> topComposite = new Composite(parent, SWT.None);
> topComposite.setLayout(new FillLayout());
> Composite top = new Composite(topComposite,
> SWT.NONE);
> GridLayout layout = new GridLayout();
> layout.marginHeight = 0;
> layout.marginWidth = 0;
> top.setLayout(layout);
> // top banner
> Composite banner = new Composite(top, SWT.NONE);
> banner.setLayoutData(new
> GridData(GridData.HORIZONTAL_ALIGN_FILL,
> GridData.VERTICAL_ALIGN_BEGINNING, true, false));
> layout = new GridLayout();
> layout.marginHeight = 5;
> layout.marginWidth = 10;
> layout.numColumns = 2;
> banner.setLayout(layout);
> // setup bold font
> Font boldFont =
> JFaceResources.getFontRegistry().getBold(JFaceResources.DEFA
> ULT_FONT); Label l = new Label(banner,
> SWT.WRAP);
> l.setText("Subject:");
> l.setFont(boldFont);
> l = new Label(banner, SWT.WRAP);
> l.setText("This is a message about the cool Eclipse RCP!");
> l = new Label(banner, SWT.WRAP);
> l.setText("From:");
> l.setFont(boldFont);
> final Link link = new Link(banner, SWT.NONE);
> link.setText("<a>mailto:nicole@mail.org</a>");
> l = new Label(banner, SWT.WRAP);
> l.setText("Date:");
> l.setFont(boldFont);
> l = new Label(banner, SWT.WRAP);
> l.setText("10:34 am");
> // message contents
> Text text = new Text(top, SWT.MULTI | SWT.WRAP);
> text.setText("This RCP Application was generated from the
> PDE Plug-in Project wizard. This sample shows how to:\n");
> text.setLayoutData(new GridData(GridData.FILL_BOTH));
>
> banner.setMenu(menuManager.createContextMenu(banner));
> }
> public Control getControl()
> {
> return this.topComposite;
> }
>
> public Object getInput()
> {
> return null;
> }
>
> public ISelection getSelection()
> {
> return new StructuredSelection(new Object());
> }
>
> public void refresh()
> {
> }
>
> public void setInput(Object input)
> {
> }
>
> public void setSelection(ISelection selection, boolean reveal)
> {
> }
> }
> }
>
> (Sorry for the stupid-looking code)
>
> As you see, I added a context menu to the banner composite.
>
> When I start a new session, the context menu poped up as I had
> experted, but when I clicked at somewhere else that was blank on the
> banner composite, the context menu did not get hiden.
>
> So, could you please tell me how to hide the context menu by clicking
> elsewhere on the parent control as Table does(We can hide the context
> menu of a Table by clicking anywhere else except the point where the
> context menu starts)?
>
> Great thanks and Best Regards!
>
> Tingel Christian
|
|
| | | |
Goto Forum:
Current Time: Sat Oct 12 09:57:17 GMT 2024
Powered by FUDForum. Page generated in 0.04381 seconds
|