I think that's part of it, Fabiano, and I think the other part is
reconciling what 'this' means between the JavaScript event handler function
and the GWT TextBox.  I've got it working like this (still using
StockWatcher as a test-bed -- note that this the Window.confirm here is for
testing; my actual app does something different):

public class StockWatcher implements EntryPoint {

    private static Map<Element, TextBox> m_elementToWidget =
newHashMap<Element, TextBox>();
...
At the end of onModuleLoad():

    registerOnCut(nameField.getElement());

    m_elementToWidget.put(nameField.getElement(), nameField);
...
Changed the event handler functions to be static, then reconcile the Element
back to the corresponding Widget:


    public native void registerOnCut(Element element)

    /*-{

        element.oncut = function(e)

        {

            if (!e) var e = window.event;

            $entry(
@com.google.gwt.sample.stockwatcher.client.StockWatcher::doCut
(Lcom/google/gwt/dom/client/NativeEvent;)(e));

            return false;

        };

    }-*/;


    public static void doCut(NativeEvent event)

    {

        EventTarget target = event.getEventTarget();

        if (Element.is(target))

        {

            Element element = Element.as(target);

            TextBox textbox = m_elementToWidget.get(element);

            String text = textbox.getText();

            int cursorPos = textbox.getCursorPos();

            int selectionLength = textbox.getSelectionLength();

            String selectedText = textbox.getSelectedText();

            String msg = "OK to cut selected text '"+selectedText+"' @ "
+cursorPos+","+selectionLength+"?";

            if (Window.confirm(msg))

            {

                text = text.substring(0, cursorPos) +
text.substring(cursorPos+selectionLength);

                textbox.setText(text);

            }

        }

    }


And for cleanup, I added this to the subclassed TextBox:


    @Override

    protected void onDetach()

    {

        super.onDetach();

        m_elementToWidget.remove(getElement());

    }


On Mon, Feb 15, 2010 at 12:29 AM, Fabiano <[email protected]> wrote:

> On 14 Feb, 23:19, Jim Douglas <[email protected]> wrote:
>
> > $entry([email protected]
> ::doCut());
> Hi,
> I'm a bit nood but I have the impression that the problem could be
> related to the function argument, my proposal, not tested:
>
> $entry([email protected]
> ::doCut(D));
>
> I don't know the reason but I have found this example
>
> http://googlewebtoolkit.blogspot.com/2008/07/getting-to-really-know-gwt-part-1-jsni.html
> about functions with empty arguments:
>
> // Set up the JS-callable signature as a global JS function.
>  private native void publish() /*-{
>    $wnd.formatAsCurrency =
>
> @org.example.yourcode.format.client.DateFormatterLib::formatAsCurrency(D);
>  }-*/;
>
> it lacks $entry , but I don't think this is an issue.
> I have the impression that sometimes gwt documentation in a bit
> ambiguous about syntax and left too much to the user intuition.
> In the main documentation there is no an example about functions with
> no arguments.
> Regards
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to