public class JavaApiElement extends FlowPanel {


	public JavaApiElement() {
        HeadingElement h2 = Document.get().createHElement(2);
        h2.setInnerText("Java API using Elements");
        this.getElement().appendChild(h2);

        PaperDialogElement dialog = Polymer.createElement(PaperDialogElement.TAG);
        dialog.innerHTML = "<div>Welcome Polymer to GWT</div>";
        dialog.setEntryAnimation("scale-up-animation");
        this.getElement().appendChild(Js.cast(dialog));

        PaperFabElement iconElem = Polymer.createElement(PaperFabElement.TAG);
        iconElem.setIcon("open-in-browser");
        iconElem.setAttribute("title", "Click to say Hello");
        iconElem.addEventListener("click", new EventListener() {
            public void handleEvent(Event event) {
                dialog.open();
            }
        });

        this.getElement().appendChild(Js.cast(iconElem));
    }
} public class JavaApiWidget extends FlowPanel {

    public JavaApiWidget() {


        PaperMaterial main = new PaperMaterial("<h2>Java API using Widgets</h2>");
        main.setElevation("4");
        main.setSize("80%", "150px");
        main.getElement().getStyle().setPadding(30, Unit.PX);

        this.add(main);

        PaperDialog dialog = new PaperDialog();
        dialog.setSize("400px", "100px");
        dialog.setEntryAnimation("slide-down-animation");
        dialog.setExitAnimation("slide-up-animation");
        dialog.add(new Label("Welcome Polymer to GWT"));
        this.add(dialog);

        PaperFab button = new PaperFab();
        button.setIcon("open-in-browser");
        button.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                dialog.open();
            }
        });
        main.add(button);
    }
} public class UiBinderElement extends Widget {
    interface PaperTabsViewUiBinder extends UiBinder<DivElement, UiBinderElement> {}
    private static PaperTabsViewUiBinder ourUiBinder = GWT.create(PaperTabsViewUiBinder.class);

    @UiField PaperTabsElement paperTabs;
    @UiField PaperToastElement toast;

    public UiBinderElement() {
        setElement(ourUiBinder.createAndBindUi(this));

        // Since we are using pure elements in UiBinder, they are created via
        // DOM.createElement instead of Polymer.createElement, so we need to
        // import web components hrefs by hand, and continue the flow
        // asynchronously
        Polymer.importHref(Arrays.asList(PaperTabsElement.SRC, PaperTabElement.SRC, PaperToastElement.SRC), o -> {
            paperTabs.addEventListener(IronSelectEvent.NAME, new EventListener() {
                public void handleEvent(Event event) {
                    PaperTabElement tab = Js.cast(((IronSelectEvent)event).getDetail().getItem());
                    toast.close();
                    toast.setText("Tab \"" + tab.textContent + "\" has been selected");
                    toast.open();
                }
            });
            return null;
        });
    }
} public class UiBinderWidget extends Composite {
    interface PaperTabsWidgetUiBinder extends UiBinder<HTMLPanel, UiBinderWidget> {
    }

    private static PaperTabsWidgetUiBinder ourUiBinder = GWT.create(PaperTabsWidgetUiBinder.class);

    @UiField PaperTabs tabs;
    @UiField PaperToast toast;
    @UiField Button button1;
    @UiField Button button2;

    public UiBinderWidget() {
        initWidget(ourUiBinder.createAndBindUi(this));

        PaperTab tab = new PaperTab("dynamically created item");
        tabs.add(tab);

        // wait until toast has been loaded and initialized
        toast.ready((o) -> {
            tabs.setSelected("0");
            return null;
        });
    }

    @UiHandler("tabs")
    void tabSelected(IronSelectEvent event) {
        PaperTabElement tab = Js.cast(event.getItem());
        toast.setText("widget event handler:" + tab.textContent);
        toast.open();
    }

    @UiHandler({"button1", "button2"})
    void buttonClicked(ClickEvent event) {
        toast.close();
        toast.setText("widget event handler:" + ((Button)event.getSource()).getElement().getInnerText());
        toast.open();
    }
} public abstract class JsHighlight implements JsniBundle {

  interface CssHighlight extends ClientBundle  {
    CssHighlight INSTANCE =  GWT.create(CssHighlight.class);

    @Source("idea.css")
    CssResource idea();
  }

  private static boolean initialized;
  public static final JsHighlight INSTANCE = GWT.create(JsHighlight.class);

  @LibrarySource("highlight.pack.js")
  abstract void loadHighlight();

  public void initialize() {
    if (!initialized) {
      initialized = true;
      CssHighlight.INSTANCE.idea().ensureInjected();
      loadHighlight();
    }
  }

  public native void highlightBlock(Element e) /*-{
    e && $wnd.hljs && $wnd.hljs.highlightBlock(e);
  }-*/;
} public class IronAjaxSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, IronAjaxSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    @UiField IronAjax ajax;
    @UiField PolymerTemplate repeat;

    public IronAjaxSample() {
        initWidget(ourUiBinder.createAndBindUi(this));
    }
    
    @UiHandler("ajax")
    void onResponse(ResponseEvent e) {
        repeat.setItems(Polymer.property(ajax.getLastResponse(), "items"));
    }
} public class IronCollapseSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, IronCollapseSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    @UiField Button heading1;
    @UiField IronCollapse collapse1;
    @UiField Button heading2;
    @UiField IronCollapse collapse2;
    @UiField Button heading3;
    @UiField IronCollapse collapse3;

    public IronCollapseSample() {
        initWidget(ourUiBinder.createAndBindUi(this));

        heading1.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                collapse1.toggle();
            }
        });

        heading2.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                collapse2.toggle();
            }
        });

        heading3.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                collapse3.toggle();
            }
        });
    }
} public class IronImageSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, IronImageSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    @UiField
    Button button1a;
    @UiField
    IronImage image1a;
    @UiField
    Button button1b;
    @UiField
    IronImage image1b;
    @UiField
    Button button1c;
    @UiField
    IronImage image1c;

    @UiField
    Button button3a;
    @UiField
    IronImage image3a;
    @UiField
    Button button3b;
    @UiField
    IronImage image3b;
    @UiField
    Button button3c;
    @UiField
    IronImage image3c;

    @UiField
    Button button3aFade;
    @UiField
    IronImage image3aFade;
    @UiField
    Button button3bFade;
    @UiField
    IronImage image3bFade;
    @UiField
    Button button3cFade;
    @UiField
    IronImage image3cFade;

    public IronImageSample() {
        initWidget(ourUiBinder.createAndBindUi(this));

        button1a.addClickHandler(event -> onButtonClick(button1a, image1a));
        button1b.addClickHandler(event -> onButtonClick(button1b, image1b));
        button1c.addClickHandler(event -> onButtonClick(button1c, image1c));

        button3a.addClickHandler(event -> onButtonClick(button3a, image3a));
        button3b.addClickHandler(event -> onButtonClick(button3b, image3b));
        button3c.addClickHandler(event -> onButtonClick(button3c, image3c));

        button3aFade.addClickHandler(event -> onButtonClick(button3aFade, image3aFade));
        button3bFade.addClickHandler(event -> onButtonClick(button3bFade, image3bFade));
        button3cFade.addClickHandler(event -> onButtonClick(button3cFade, image3cFade));
    }

    private void onButtonClick(Button button, IronImage image) {
        image.setSrc("gwtPolymerDemo/polymer.svg?" + Math.random());
        button.setText("Reload image");
    }
} public class IronInputSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, IronInputSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    @UiField PolymerTemplate bindTemplate;

    // NOTE: @UiField on poly-filled browsers only works for the
    // top level template. In chrome everything works as expected though.
    // We will get references to these elements once they are in the dom.
    IronInputElement ironInput;
    HTMLInputElement input1;
    HTMLInputElement input2;

    public IronInputSample() {
        // We can import elements before we create the UIBinder instance
        Polymer.importHref(IronInputElement.SRC);

        initWidget(ourUiBinder.createAndBindUi(this));

        // Wait until the template has been rendered by polymer to query the dom.
        Polymer.ready(bindTemplate, o -> {
            NodeList<Element> inputs = Js.<PolymerElement>cast(getElement()).querySelectorAll("input");
            ironInput = (IronInputElement)inputs.item(0);
            input1 = (HTMLInputElement)inputs.item(1);
            input2 = (HTMLInputElement)inputs.item(2);
            return null;
        });

        // Bind functions to the template
        Polymer.function(bindTemplate, "function1", o -> {
            ironInput.setBindValue(input1.value);
            return null;
        });
        Polymer.function(bindTemplate, "function2", o -> {
            // TODO: casting because api-generator does not support extending
            // native elements yet, hence we cast to elemental2 input.
            Js.<HTMLInputElement>cast(ironInput).value = input2.value;
            return null;
        });
    }
} public class IronListSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, IronListSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    @UiField IronList list;

    public IronListSample() {
        initWidget(ourUiBinder.createAndBindUi(this));

        list.setItems(Sampler.contacts);
    }
} public class IronSelectorSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, IronSelectorSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    @UiField IronSelector selector1;
    @UiField IronSelector selector2;
    @UiField IronSelector selector3;
    @UiField PaperToast toast;

    public IronSelectorSample() {
        initWidget(ourUiBinder.createAndBindUi(this));

        selector1.addIronSelectHandler(e -> {
            Element elem = e.getItem().cast();
            show(elem.getInnerText());
        });

        selector2.getPolymerElement().addEventListener(IronSelectEvent.NAME, e -> {
            Array<Object> selected = selector2.getSelectedValues();
            String s = "";
            for (int i = 0; i < selected.length; i++) {
                s += selected.getAt(i) + " ";
            }
            show(s);
        });

        selector3.getPolymerElement().addEventListener(IronSelectEvent.NAME, e -> {
            show((String)selector3.getSelected());
        });

    }

    private void show(String message) {
        if (!message.isEmpty()) {
            toast.close();
            toast.setText("Value: " + message);
            toast.open();
        }
    }
} public class ButtonSample extends Composite {
    interface ButtonSampleUiBinder extends UiBinder<HTMLPanel, ButtonSample> {
    }

    private static ButtonSampleUiBinder ourUiBinder = GWT.create(ButtonSampleUiBinder.class);

    public ButtonSample() {
        initWidget(ourUiBinder.createAndBindUi(ButtonSample.this));
    }
} public class CheckboxSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, CheckboxSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    public CheckboxSample() {
        initWidget(ourUiBinder.createAndBindUi(CheckboxSample.this));
    }
} public class DialogSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, DialogSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);
    
    @UiField PaperButton dialogBtn;
    @UiField PaperButton scrollingBtn;
    @UiField PaperButton actionsBtn;
    @UiField PaperButton modalBtn;
    
    @UiField PaperDialog dialog;
    @UiField PaperDialog scrollingDlg;
    @UiField PaperDialog actionsDlg;
    @UiField PaperDialog modalDlg;
    
    @UiField PaperButton colorsBtn;
    @UiField PaperButton positionBtn;    
    
    @UiField PaperDialog colorsDlg;
    @UiField PaperDialog positionDlg;
    
    @UiField PaperButton animatedBtn;
    
    @UiField PaperDialog animatedDlg;

    public DialogSample() {
        initWidget(ourUiBinder.createAndBindUi(DialogSample.this));
        
        dialogBtn.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                dialog.open();
            }
        });

        scrollingBtn.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                scrollingDlg.open();
            }
        });

        actionsBtn.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                actionsDlg.open();
            }
        });

        modalBtn.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                modalDlg.open();
            }
        });

        colorsBtn.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                colorsDlg.open();
            }
        });

        positionBtn.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                positionDlg.open();
            }
        });

        animatedBtn.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                animatedDlg.open();
            }
        });
    }
} public class DropdownMenuSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, DropdownMenuSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    private static String[] letters = { "alpha", "beta", "gamma", "delta",
            "epsilon" };

    private static String[] dinosaurs = { "allosaurus", "brontosaurus",
            "carcharodontosaurus", "diplodocus", "ekrixinatosaurus",
            "fukuiraptor", "gallimimus", "hadrosaurus", "iguanodon",
            "jainosaurus", "kritosaurus", "liaoceratops", "megalosaurus",
            "nemegtosaurus", "ornithomimus", "protoceratops", "quetecsaurus",
            "rajasaurus", "stegosaurus", "triceratops", "utahraptor",
            "vulcanodon", "wannanosaurus", "xenoceratops", "yandusaurus",
            "zephyrosaurus" };

    @UiField PaperMenu menu1;
    @UiField PaperMenu menu2;
    @UiField PaperMenu menu3;
    @UiField PaperTabs tabs1;
    @UiField PaperMenu menu4;
    @UiField PaperMenu menu5;

    public DropdownMenuSample() {
        initWidget(ourUiBinder.createAndBindUi(this));

        for (String dinosaur : dinosaurs) {
            menu1.add(new PaperItem(dinosaur));
            menu2.add(new PaperItem(dinosaur));
            menu5.add(new PaperItem(dinosaur));
        }

        for (String letter : letters) {
            menu3.add(new PaperItem(letter));
            tabs1.add(new PaperTab(letter));
            menu4.add(new PaperItem(letter));
        }
    }
} public class FabSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, FabSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    public FabSample() {
        initWidget(ourUiBinder.createAndBindUi(this));
    }
} public class HeaderPanelSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, HeaderPanelSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);
    
    public HeaderPanelSample() {
        initWidget(ourUiBinder.createAndBindUi(HeaderPanelSample.this));
    }
} public class IconButtonSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, IconButtonSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    public IconButtonSample() {
        initWidget(ourUiBinder.createAndBindUi(this));
    }
} public class InputSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, InputSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    @UiField PaperInput inputForValidation;
    @UiField Button validateButton;

    public InputSample() {
        initWidget(ourUiBinder.createAndBindUi(this));

        validateButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent clickEvent) {
                inputForValidation.validate();
            }
        });
    }
} public class MaterialSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, MaterialSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    @UiField PaperMaterial material;
    @UiField PaperMaterial fabMaterial;

    public MaterialSample() {
        initWidget(ourUiBinder.createAndBindUi(this));

        material.addClickHandler(new MyClickHandler());
        fabMaterial.addClickHandler(new MyClickHandler());
    }

    private class MyClickHandler implements ClickHandler {
        private boolean down;

        @Override
        public void onClick(ClickEvent event) {
            PaperMaterial source = (PaperMaterial) event.getSource();
            if (!down) {
                source.setElevation(source.getElevation() + 1);
                if (source.getElevation() == 5) {
                    down = true;
                }
            } else {
                source.setElevation(source.getElevation() - 1);
                if (source.getElevation() == 0) {
                    down = false;
                }
            }
        }
    }
} public class MenuSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, MenuSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    public MenuSample() {
        initWidget(ourUiBinder.createAndBindUi(this));
    }
} public class ProgressSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, ProgressSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    @UiField PaperButton startButton;
    @UiField PaperProgress progress;

    public ProgressSample() {
        initWidget(ourUiBinder.createAndBindUi(this));
    }

    @UiHandler("startButton")
    public void onStartClick(ClickEvent clickEvent) {
        new Animation() {
            protected double interpolate(double p) {
                return p;
            }
            public void run(int duration) {
                startButton.setDisabled(true);
                super.run(duration);
            }
            protected void onUpdate(double p) {
                progress.setValue((int)(p * 5 * 100) % 100);
            }
            protected void onComplete() {
                super.onComplete();
                startButton.setDisabled(false);
            }
        }.run(5000);
    }
} public class SliderSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, SliderSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    @UiField PaperSlider ratings;
    @UiField SpanElement ratingsLabel;


    public SliderSample() {
        initWidget(ourUiBinder.createAndBindUi(this));

        ratings.addValueChangeHandler(new ValueChangeEventHandler() {
            @Override
            public void onValueChange(ValueChangeEvent event) {
                ratingsLabel.setInnerText("" + ratings.getValue());
            }
        });
    }
} public class TabsSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, TabsSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    public TabsSample() {
        initWidget(ourUiBinder.createAndBindUi(this));
    }
} public class ToastSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, ToastSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    @UiField PaperButton button1;
    @UiField PaperButton button2;
    @UiField PaperToast toast1;
    @UiField PaperToast toast2;

    public ToastSample() {
        initWidget(ourUiBinder.createAndBindUi(this));

        button1.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent clickEvent) {
                toast1.open();
            }
        });

        button2.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent clickEvent) {
                toast2.open();
            }
        });
    }
} public class ToggleButtonSample extends Composite {
    interface ToggleButtonSampleUiBinder extends UiBinder<HTMLPanel, ToggleButtonSample> {
    }

    private static ToggleButtonSampleUiBinder ourUiBinder = GWT.create(ToggleButtonSampleUiBinder.class);

    public ToggleButtonSample() {
        initWidget(ourUiBinder.createAndBindUi(ToggleButtonSample.this));
    }
} public class ToolbarSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, ToolbarSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);

    public ToolbarSample() {
        initWidget(ourUiBinder.createAndBindUi(ToolbarSample.this));
    }
} public class VaadinComboBoxSample extends Composite {

    interface MyUiBinder extends UiBinder<HTMLPanel, VaadinComboBoxSample> {
    }
    private static MyUiBinder myUiBinder = GWT.create(MyUiBinder.class);

    @UiField VaadinComboBox comboBox;
    @UiField VaadinComboBox comboBox2;
    @UiField IronAjax ironAjax;
    @UiField PaperToast toast;

    public static Array<Object> elements;

    public VaadinComboBoxSample() {
        initWidget(myUiBinder.createAndBindUi(this));

        ironAjax.addResponseHandler(event -> {
            elements = Js.cast(ironAjax.getLastResponse());
            comboBox.setItems(elements);
            comboBox2.setItems(elements);
            comboBox2.setValue("Bohrium");
        });
    }

    private void show(String message) {
        if (!message.isEmpty()) {
            toast.close();
            toast.setText("Value: " + message);
            toast.open();
        }
    }

    @UiHandler("comboBox")
    public void valueChanged(ValueChangedEvent e) {
        show(comboBox.getValue());
    }

    @UiHandler("comboBox2")
    public void valueChanged2(ValueChangedEvent e) {
        show(comboBox2.getValue());
    }
} public class VaadinContextMenuSample extends Composite {

    interface MyUiBinder extends UiBinder<HTMLPanel, VaadinContextMenuSample> {
    }

    private static MyUiBinder myUiBinder = GWT.create(MyUiBinder.class);

    @UiField VaadinGrid grid;
    @UiField VaadinContextMenu gridcontext;
    @UiField VaadinContextMenu basiccontext;
    @UiField HTMLElement opener;
    @UiField PaperToast toast;

    // ui:field do not work here because it's in a template that is not attached to the dom.
    PaperMenuElement gridmenu;

    public VaadinContextMenuSample() {
        Polymer.importHref(Arrays.asList("vaadin-context-menu", "paper-menu", "paper-item", "paper-item/paper-item-body"));

        initWidget(myUiBinder.createAndBindUi(this));

        // Demo 1
        basiccontext.setListenOn(opener);
        basiccontext.getPolymerElement().addEventListener(IronSelectEvent.NAME, e -> {
            HTMLElement item = Polymer.property(((IronSelectEvent)e).getDetail(), "item");
            show(item.getAttribute("value"));
        });

        // Demo 2
        // We have a global list of contacts
        grid.setItems(Sampler.contacts);
        gridcontext.setListenOn(Js.<HTMLElement>cast(grid.getElement()));

        // We have to wait until the overlay is attached to the DOM.
        // vaadin-contex-menu, lacks for an API able to realize when the overlay is opened
        Scheduler.get().scheduleFixedPeriod(() -> {
            gridmenu = Polymer.dom(gridcontext.getPolymerElement().root).querySelector("paper-menu");
            if (gridmenu != null) {

                // First time we select all items
                Array<Integer> all = new Array<>(0,1,2,3,4);
                gridmenu.setSelectedValues(all);

                gridmenu.addEventListener("selected-values-changed", e -> {
                    gridcontext.getPolymerElement().debounce("values-changed", o -> {
                        for (int i = 0; i < 5; i++) {
                            ((Column)grid.getColumns().getAt(i)).setHidden(true);
                        }
                        Array<Number> selected = gridmenu.getSelectedValues();
                        for (int i = 0; i < selected.length; i++) {
                            final Array<Column> columns = grid.getColumns();
                            (columns.getAt(selected.getAt(i).intValue())).setHidden(false);
                        }
                        return null;
                    }, 1);
                });
            }
            return gridmenu == null;
        }, 100);
    }


    private void show(String message) {
        if (!message.isEmpty()) {
            toast.close();
            toast.setText("Value: " + message);
            toast.open();
        }
    }
} public class VaadinDatePickerSample extends Composite {

    interface MyUiBinder extends UiBinder<HTMLPanel, VaadinDatePickerSample> {
    }
    private static MyUiBinder myUiBinder = GWT.create(MyUiBinder.class);

    @UiField VaadinDatePicker datePicker;

    public VaadinDatePickerSample() {
        initWidget(myUiBinder.createAndBindUi(this));
    }
    
    @UiHandler("datePicker")
    public void valueChanged(ValueChangedEvent e) {
    }
    
} public class VaadinGridSample extends Composite {

    interface MyUiBinder extends UiBinder<HTMLPanel, VaadinGridSample> {
    }

    private static MyUiBinder myUiBinder = GWT.create(MyUiBinder.class);

    @UiField VaadinGrid grid;
    @UiField PaperMaterial info;
    @UiField ImageElement img;
    @UiField SpanElement txt;
    @UiField PaperInput filter;

    private double opened = -1;
    private List<Properties> original;
    private Array<Properties> items;
    private List<Properties> list;

    public VaadinGridSample() {
        initWidget(myUiBinder.createAndBindUi(this));

        // info and filter will be used later.
        info.removeFromParent();
        filter.removeFromParent();

        // We have a global list of contacts
        items = Sampler.contacts;
        list = Arrays.asList(items.asArray());
        grid.setItems(items);
        // Save a copy to use in filters.
        original = new ArrayList<>(list);

        Polymer.ready(grid.getElement(), arg -> {

            // Feature: frozenColumns
            // Configure two columns at left to be always visible
            grid.setFrozenColumns(2);

            // Feature: custom renders
            // Custom renderer for cell
            Array<Column> columns= grid.getColumns();
            Column column = columns.getAt(0);
            column.setRenderer(cell -> {
                Cell c = (Cell)cell;

                int n = Integer.valueOf("" + c.getData()) % 4;
                String icon = n == 2 ? "star-half" : n == 1 ? "star" : "star-border";

                // Reuse elements in the cell to improve performance
                HTMLElement cellElm = c.getElement();
                IronIconElement iconElm = (IronIconElement)cellElm.firstChild;
                if (iconElm == null) {
                  iconElm = (IronIconElement)DomGlobal.document.createElement("iron-icon");
                  cellElm.appendChild(iconElm);
                }

                iconElm.setIcon(icon);
                return null;
            });

            // Feature: class names
            // Generate different class names per row
            grid.setRowClassGenerator(row -> {
                Row r = (Row)row;
                Properties u = r.getData().cast();
                return "color-" + u.getStr("longText").length() % 4;
            });

            // Feature: row details
            // Generate a widget to show the details of a row
            grid.setRowDetailsGenerator(index -> {
                Properties u = items.getAt(((Double)index).intValue());
                img.setSrc(u.get("image"));
                txt.setInnerText(u.get("mediumText"));
                return info.getPolymerElement();
            });
            // Open the row details on grid selection
            grid.getPolymerElement().addEventListener(SelectedItemsChangedEvent.NAME, evnt -> {
                Array<Number> n = grid.getSelection().selected(null, 0, 200);
                grid.setRowDetailsVisible(opened, false);
                if (n.length == 1) {
                    grid.setRowDetailsVisible(opened = n.getAt(0).doubleValue(), true);
                }
            });

            // Feature: sorting data
            // Reorder data when clicking on the header sort arrows
            grid.getPolymerElement().addEventListener(SortOrderChangedEvent.NAME, evnt -> {
                SortOrder order =  Js.cast(grid.getSortOrder().getAt(0));

                int i = (int)order.getColumn();
                String col = i == 1 ? "name" : i == 3 ? "city" : i == 5 ? "state" : "country";

                boolean asc = order.getDirection() == "asc";

                Comparator<Properties> compare = (p1, p2) -> p1.getStr(col).compareTo(p2.get(col));
                Collections.sort(list, asc ? compare : Collections.reverseOrder(compare));
            });

            // Feature: widgets in headers
            // Add a Paper input to the header to use for filtering
            grid.getHeader().getCell(0, 0).setColspan(2);
            grid.getHeader().getCell(0, 0).setContent(filter.getElement());
            // Change grid items based on filter
            filter.getPolymerElement().addEventListener("keyup", evnt -> {
                list.clear();
                String search = filter.getValue().toLowerCase();
                for (Properties p : original) {
                    if (p.getStr("name").toLowerCase().contains(search)) {
                        list.add(p);
                    }
                }
                items = Polymer.asJsArray(list);
                grid.setItems(items);
            });

            return null;
        });

    }
} public class VaadinIconsSample extends Composite {
    interface SampleUiBinder extends UiBinder<HTMLPanel, VaadinIconsSample> {
    }

    private static SampleUiBinder ourUiBinder = GWT.create(SampleUiBinder.class);
    
    @UiField PolymerTemplate bindTemplate;

    public VaadinIconsSample() {
        initWidget(ourUiBinder.createAndBindUi(this));

        Polymer.property(bindTemplate, "getIconNames",
                (PolymerFunction<?,?>) iconSet -> Polymer.apply(iconSet, "getIconNames"));

        Polymer.property(bindTemplate, "filterIconset",
                (PolymerFunction<?,?>) iconSet -> Polymer.property(iconSet, "name") == "vaadin-icons");
    }
} public class VaadinUploadSample extends Composite {

    interface MyUiBinder extends UiBinder<HTMLPanel, VaadinUploadSample> {
    }
    private static MyUiBinder myUiBinder = GWT.create(MyUiBinder.class);

    @UiField VaadinUpload uploader;

    public VaadinUploadSample() {
        Polymer.importHref("vaadin-mock-xhr");

        initWidget(myUiBinder.createAndBindUi(this));
    }


}
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.HeadingElement;
import com.google.gwt.dom.client.PreElement;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.query.client.GQ;
import com.google.gwt.query.client.Properties;
import com.google.gwt.query.client.plugins.ajax.Ajax;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.polymer.Polymer;
import com.vaadin.polymer.demo.client.sampler.gwt.JavaApiElement;
import com.vaadin.polymer.demo.client.sampler.gwt.JavaApiWidget;
import com.vaadin.polymer.demo.client.sampler.gwt.UiBinderElement;
import com.vaadin.polymer.demo.client.sampler.gwt.UiBinderWidget;
import com.vaadin.polymer.demo.client.sampler.highlight.JsHighlight;
import com.vaadin.polymer.demo.client.sampler.iron.IronAjaxSample;
import com.vaadin.polymer.demo.client.sampler.iron.IronCollapseSample;
import com.vaadin.polymer.demo.client.sampler.iron.IronIconsSample;
import com.vaadin.polymer.demo.client.sampler.iron.IronImageSample;
import com.vaadin.polymer.demo.client.sampler.iron.IronInputSample;
import com.vaadin.polymer.demo.client.sampler.iron.IronListSample;
import com.vaadin.polymer.demo.client.sampler.iron.IronSelectorSample;
import com.vaadin.polymer.demo.client.sampler.paper.ButtonSample;
import com.vaadin.polymer.demo.client.sampler.paper.CheckboxSample;
import com.vaadin.polymer.demo.client.sampler.paper.DialogSample;
import com.vaadin.polymer.demo.client.sampler.paper.DropdownMenuSample;
import com.vaadin.polymer.demo.client.sampler.paper.FabSample;
import com.vaadin.polymer.demo.client.sampler.paper.HeaderPanelSample;
import com.vaadin.polymer.demo.client.sampler.paper.IconButtonSample;
import com.vaadin.polymer.demo.client.sampler.paper.InputSample;
import com.vaadin.polymer.demo.client.sampler.paper.ItemSample;
import com.vaadin.polymer.demo.client.sampler.paper.MaterialSample;
import com.vaadin.polymer.demo.client.sampler.paper.MenuSample;
import com.vaadin.polymer.demo.client.sampler.paper.ProgressSample;
import com.vaadin.polymer.demo.client.sampler.paper.RadioButtonSample;
import com.vaadin.polymer.demo.client.sampler.paper.RadioGroupSample;
import com.vaadin.polymer.demo.client.sampler.paper.RippleSample;
import com.vaadin.polymer.demo.client.sampler.paper.SliderSample;
import com.vaadin.polymer.demo.client.sampler.paper.SpinnerSample;
import com.vaadin.polymer.demo.client.sampler.paper.TabsSample;
import com.vaadin.polymer.demo.client.sampler.paper.ToastSample;
import com.vaadin.polymer.demo.client.sampler.paper.ToggleButtonSample;
import com.vaadin.polymer.demo.client.sampler.paper.ToolbarSample;
import com.vaadin.polymer.demo.client.sampler.paper.TooltipSample;
import com.vaadin.polymer.demo.client.sampler.vaadin.VaadinComboBoxSample;
import com.vaadin.polymer.demo.client.sampler.vaadin.VaadinContextMenuSample;
import com.vaadin.polymer.demo.client.sampler.vaadin.VaadinDatePickerSample;
import com.vaadin.polymer.demo.client.sampler.vaadin.VaadinGridSample;
import com.vaadin.polymer.demo.client.sampler.vaadin.VaadinIconsSample;
import com.vaadin.polymer.demo.client.sampler.vaadin.VaadinSplitLayoutSample;
import com.vaadin.polymer.demo.client.sampler.vaadin.VaadinUploadSample;
import com.vaadin.polymer.iron.widget.IronAjax;
import com.vaadin.polymer.iron.widget.IronCollapse;
import com.vaadin.polymer.iron.widget.IronSelector;
import com.vaadin.polymer.paper.widget.PaperButton;
import com.vaadin.polymer.paper.widget.PaperDialog;
import com.vaadin.polymer.paper.widget.PaperDrawerPanel;
import com.vaadin.polymer.paper.widget.PaperItem;
import elemental2.core.Array;
import jsinterop.base.Js;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
package com.vaadin.polymer.demo.client.sampler;




public class Sampler extends Composite {

    public static final String API_PATH = "https://api.github.com/repos/vaadin/gwt-polymer-elements/contents/demo/src/main/java/com/vaadin/polymer/demo/client/sampler/";

    interface SamplerUiBinder extends UiBinder<HTMLPanel, Sampler> {
    }

    interface Style extends CssResource {
        String toolbar();
        String category();
        String item();
        String current();
        String buttons();
        String list();
    }

    private static SamplerUiBinder ourUiBinder = GWT.create(SamplerUiBinder.class);

    private Map<String, IronSelector> selectorMap = new HashMap<>();
    private TreeMap<String, IronCollapse> collapseMap = new TreeMap<>();
    private List<Item> items = new ArrayList<>();
    private Item currentItem;

    @UiField Style style;

    @UiField PaperDrawerPanel drawerPanel;
    @UiField FlowPanel listPanel;
    @UiField HTMLPanel content;
    @UiField SpanElement currentLabel;
    @UiField PaperDialog about;
    @UiField PaperButton xmlButton;

    @UiField PaperDialog source;
    @UiField HeadingElement sourceTitle;
    @UiField PreElement sourceContent;
    @UiField IronAjax ironAjax;

    public static Array<Properties> contacts;

    private Widget createWidget(String name) {
        switch (name) {
        case "JavaApiWidget": return new JavaApiWidget();
        case "JavaApiElement": return new JavaApiElement();
        case "UiBinderWidget": return new UiBinderWidget();
        case "UiBinderElement": return new UiBinderElement();
        case "ButtonSample": return new ButtonSample();
        case "CheckboxSample": return new CheckboxSample();
        case "DialogSample": return new DialogSample();
        case "DropdownMenuSample": return new DropdownMenuSample();