manolo / gwt-polymer-elements

Polymer Web Components for GWT. A collection of Material Design widgets for desktop and mobile.
Apache License 2.0
155 stars 49 forks source link

Vaadin-Grid getItem is wrong defined and not usable #91

Closed frankstolle closed 7 years ago

frankstolle commented 8 years ago

If I want to use grid.getItem(..) I have to define a callback-Method.

    public void getItem(double rowIndex, Function callback, boolean onlyCached);

The callback of type function allows only one argument, but the grid expects two arguments. Here the type Function seems to be wrong and an individual type should be used. As workaround I have written a Wrapper, because extending Function is not possible:

public abstract class GetItemHelper<R> {

    public abstract void handleCallback(Object error, R item);

    public native Function getCallback() /*-{
        var that=this;
        return function(err, item) {
            that.@GetItemHelper::handleCallback(*)(err, item);
        }
    }-*/;
}

The call is then:

VaadinGrid grid;
...
grid.getItem(0, new GetItemHelper<Object>() { 
@Override
                public void handleCallback(Object err, R item) {

                }
}.getCallback(), true);
manolo commented 7 years ago

Unfortunatelly, gwt-api-generator does not handle this kind of cases, it is difficult to handle in this project without introducing a hack for this case.

There are two options for you:

interface VGrid extends VaadinGridElement {
    @JsFunction
    interface ItemCallback {
        void call(JavaScriptObject error, JavaScriptObject item);
    }
    @JsMethod
    void getItem(double rowIndex, ItemCallback callback, boolean onlyCached);
}

((VGrid) grid.getPolymerElement()).getItem(idx, (err, item) -> { ... }, false);
manolo commented 7 years ago

Reopening since gwt-api-generator allows extending base classes with java code.