Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Questions regarding context menus(Need to show a dynamic context menu in our RAP application)
Questions regarding context menus [message #1732817] Fri, 20 May 2016 12:35 Go to next message
Gunnar Adams is currently offline Gunnar AdamsFriend
Messages: 49
Registered: May 2016
Member
Hi,
I am new to the RAP framework and am just learning JavaScript.

The final application will act as a web client for our server application, which is implemented in C++.
All of the user interface items are determined dynamically by the server application.
This also includes application context menus, which are built dynamically by the server and sent in a descriptive format to the client application.

This means, that on a MenuDetectEvent, the client application sends a message to the server "Context Menu for object xy should be shown".
The server responds, asynchronously, with a command "display the context menu with the following menu items".
This works fine for any UI widgets not based on Text or Label (e.g. Button).

For Text widgets, either the default Menu, as determined by the browser, ist shown, or, if I set an empty dummy Menu on the widget (Text.setMenu(dummyMenu)Wink , this Menu, even though it is actually empty, is shown with dimensions other than (0,0) before my actual popup menu is displayed.

Question:
How can I prevent the Browser Context Menu from showing, if there is no Menu set for the widget?
I have seen, that there is a call to _allowContextMenu() in _onmouseevent_post, which handles the prevention of the (additional) browser-owned menu, if a menu has been set for the widget, by calling _allowContextMenu().
I assume, that it should be possible to call setAllowContextMenu() and replace the callback function by one, which always returns false.
What is the best way to do this? How can I inject the necessary Javascript code?
Client Scripting? Custom Widget?

Any pointers would be appreciated.

Best regards,
Gunnar Adams
Re: Questions regarding context menus [message #1733121 is a reply to message #1732817] Tue, 24 May 2016 14:32 Go to previous message
Sebastian Habenicht is currently offline Sebastian HabenichtFriend
Messages: 42
Registered: January 2013
Member
Hi,

when I do this:
public final class HelloWorldEntryPoint extends AbstractEntryPoint {

	@Override
	protected void createContents(final Composite parent) {
		final Text text = new Text(parent, SWT.BORDER);
		text.setMenu(new Menu(text));
	}
}

the framework's context menu is never shown when I right click the text field (tested in FF, Chrome and IE10). Did you do it just like that?

But anyway, you may want to consider using the functionality provided by the framework instead, e.g. org.eclipse.jface.action.MenuManager:

final Text text = new Text(parent, SWT.BORDER);
final MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(new IMenuListener() {
	@Override
	public void menuAboutToShow(IMenuManager manager) {
            // use manager.add to add actions
	   // use manager.updateAll afterwards to update UI, if reply handling is asynchronous
	}
});
text.setMenu(menuManager.createContextMenu(text));

Thus, you do not have to suppress the framework's context menu in the first place, plus you do not have to do client scripting or to create custom widgets.

Regards,
Sebastian

[Updated on: Tue, 24 May 2016 14:39]

Report message to a moderator

Previous Topic:[ANN] RAP 3.1 RC1 published
Next Topic:best way to distinguish main ui thread and background threads
Goto Forum:
  


Current Time: Tue Mar 19 09:58:41 GMT 2024

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

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

Back to the top