Results 1 to 5 of 5

Thread: [2.3.0] Context menu issue

  1. #1
    Ext GWT Premium Member
    Join Date
    Jun 2008
    Location
    Poland
    Posts
    306

    Question [2.3.0] Context menu issue

    Hi,

    I'm trying to disable the default context menu for the whole webapp except the text field.
    I know how to disable the default context menu permanently:

    Document.get().addListener(Events.OnContextMenu, new Listener<ComponentEvent>() {
    public void handleEvent(ComponentEvent be) {
    be.preventDefault();
    }
    });


    But I have no idea how to exclude TextFields, when I try to invoke be.getComponent() I get the exception below, only getTarget() works, but I cannot cast it to TextField

    com.google.gwt.core.client.JavaScriptException: (TypeError): elem.getAttribute is not a function
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
    at sun.reflect.GeneratedMethodAccessor797.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Unknown Source)


    Any help appreciated.

    Thank you,
    Mariusz

  2. #2
    Ext GWT Premium Member
    Join Date
    Jun 2008
    Location
    Poland
    Posts
    306

    Default

    Solution:

    Code:
    		Document.get().addListener(Events.OnContextMenu, new Listener<ComponentEvent>() {
    			public void handleEvent(ComponentEvent e) {
    				Component w = ComponentManager.get().find(e.getTarget());
    				if (w != null && w instanceof TextField<?> && ((TextField<?>) w).isEnabled()) {
    					return;
    				}
    				e.preventDefault();
    			}
    		});
    		Document.get().sinkEvents(Event.ONCONTEXTMENU);

  3. #3
    Sencha Sr Product Manager
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    1,178

    Default

    Nice job!

  4. #4
    Ext GWT Premium Member
    Join Date
    Jun 2008
    Location
    Poland
    Posts
    306

    Default

    Brandon, that's in 90% your job Thank you

  5. #5
    Sencha Sr Product Manager
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    1,178

    Default

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •