Simplified widget is in attachment. Mehod createButtons contains the the 
problem code.

Let me know if you need something else.

Stas

On Tuesday, November 1, 2016 at 11:13:41 AM UTC+1, Jens wrote:
>
> Use -style PRETTY as SDM parameter so that the JS code is more readable. 
>
> Looks like a GWT bug either in the compiler because of method references 
> or inside the Stream emulation. If you can provide a minimal, reproducible 
> example then open a bug report.
>
> -- J.
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
package org.jresearch.commons.gwt.client.widget;

import javax.annotation.Nonnull;

import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;

public class MessageTestBox extends DialogBox {

    @Nonnull
    private Label content;
    private Button cancel;
    @Nonnull
    private HTMLPanel panel;

    public MessageTestBox() {
        final FlowPanel main = new FlowPanel();
        setModal(true);
        main.add(content = new Label());
        main.add(panel = new HTMLPanel(""));
        setWidget(main);
        setGlassEnabled(true);
    }

    protected void createButtons(@Nonnull final HTMLPanel p, @Nonnull final Action... actions) {
        p.clear();
        for (final Action action : actions) {
            p.add(createButton(action));
        }
        // Stream.of(actions).map(this::createButton).forEach(p::add);
        if (cancel == null) {
            cancel = createButton(new Action(SafeHtmlUtils.fromTrustedString("Cancel"), this::close));
        }
        p.add(cancel);
    }

    protected Button createButton(final Action action) {
        return new Button(action.getActionName(), e -> close(action.getHandler()));
    }

    private void close(final Command toDo) {
        hide(false);
        toDo.execute();
    }

    public void show(@Nonnull final SafeHtml title, @Nonnull final SafeHtml text, @Nonnull final Action... actions) {
        createButtons(panel, actions);
        setHTML(title);
        content.setText(text.asString());
        center();
    }

    private void close() {
        hide(true);
    }

}
package org.jresearch.commons.gwt.client.widget;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.google.common.base.MoreObjects;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.user.client.Command;

public class Action {

    @Nonnull
    private final SafeHtml actionName;
    @Nullable
    private final Command handler;

    /**
     * @param actionName
     * @param handler
     */
    public Action(@Nonnull final SafeHtml actionName, @Nullable final Command handler) {
        this.actionName = actionName;
        this.handler = handler;
    }

    /**
     * @param actionName
     * @param handler
     */
    public Action(@Nonnull final SafeHtml actionName) {
        this(actionName, null);
    }

    /**
     * @return the actionName
     */
    @Nonnull
    public SafeHtml getActionName() {
        return actionName;
    }

    /**
     * @return the handler
     */
    @Nullable
    public Command getHandler() {
        return handler;
    }

    @SuppressWarnings("nls")
    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .omitNullValues()
                .add("actionName", actionName)
                .add("handler", handler)
                .toString();
    }

}

Reply via email to