Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    help copying to clipboard?

    SmartClient Version: SC_SNAPSHOT-2012-02-23_v8.2p/Pro Deployment (built 2012-02-23)
    FireFox 10.0.1

    I not been able to find documentation but I have seen this notation as an acceptable/compilable approach to using JavaScript in Java code. I am attempting to use this to copy to the clipboard:

    private static native JavaScriptObject copyToClipBoard(String guid)/*
    if (window.clipboardData) // Internet Explorer
    {
    window.clipboardData.setData("Text", guid);
    }
    else
    {
    unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
    clipboardHelper.copyString(guid);
    }
    return(copyToClipBoard);
    }*/;

    This compiles but causes an umbrella exception on the declaration line.

    #2
    It would be very helpful to get a pointer to some documentation on the use of native code. This looks like the only solution for working with several browser specific capabilities. Suggestions would be appreciated. Thank you.

    Comment


      #3
      I took your code and I put it in a stand-alone test case.
      When it pops up in devmode, I get this in the GWT Console:
      Code:
      00:18:19.856 [ERROR] Line 57: Native methods require a JavaScript implementation enclosed with /*-{ and }-*/
      Which is pretty clear.

      Also, window needs to be referenced via the gwt var $wnd.

      So, try something like this:
      Code:
      private static native void copyToClipBoard (final String text) /*-{
      
          if ($wnd.clipboardData) {
            // Internet Explorer
            $wnd.clipboardData.setData("Text", text);
          }
          else {
            $wnd.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
            clipboardHelper.copyString(text);
          }
        }-*/;
      But I think you will have to work on the netscape implementation a bit.

      Please post your solution when you have it...

      Comment

      Working...
      X