Last active
June 17, 2017 01:17
-
-
Save foreverdeepak/0bc6618270c412fc60f3 to your computer and use it in GitHub Desktop.
Polymer and GWT integration with JS Interop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PolymerEntryPoint implements EntryPoint { | |
@Override | |
public void onModuleLoad() { | |
PaperButton paperButton = Browser.createPaperButton(); | |
FlowPanel panel = new FlowPanel(); | |
RootPanel.get().add(panel); | |
UiBinderExample paperbuttonUiExample = new UiBinderExample(); | |
panel.add(paperbuttonUiExample); | |
Browser.append(panel.getElement(), paperButton); | |
} | |
} | |
public class UiBinderExample extends Composite { | |
private static UiBinderExampleBinder uiBinder = GWT.create(UiBinderExampleBinder.class); | |
interface UiBinderExampleBinder extends UiBinder<Widget, UiBinderExample> { | |
} | |
public UiBinderExample() { | |
initWidget(uiBinder.createAndBindUi(this)); | |
paperButton.setInnerText("through binder"); | |
} | |
@UiField PaperButton paperButton; | |
} | |
/** | |
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> | |
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" | |
xmlns:g="urn:import:com.google.gwt.user.client.ui"> | |
<g:HTMLPanel> | |
<paper-button ui:field="paperButton"></paper-button> | |
</g:HTMLPanel> | |
</ui:UiBinder> | |
**/ | |
public class Browser { | |
public static native Document getDocument() /*-{ | |
return $doc; | |
}-*/; | |
public static native void append(com.google.gwt.dom.client.Element parent, HTMLElement child) /*-{ | |
parent.appendChild(child); | |
}-*/; | |
public static PaperButton createPaperButton() { | |
PaperButton paperButton = (PaperButton) Browser.getDocument().createElement("paper-button"); | |
paperButton.setInnerText("PAPER BUTTON"); | |
return paperButton; | |
} | |
} | |
@JsType | |
public interface PaperButton extends HTMLElement { | |
} | |
@JsType(prototype = "HTMLElement") | |
public interface HTMLElement extends Element { | |
public void setAttribute(String id, String value); | |
public String getAttribute(String id); | |
public void appendChild(HTMLElement element); | |
@JsProperty | |
public void setInnerHTML(String text); | |
@JsProperty | |
public void setInnerText(String text); | |
} | |
@JsType(isNative = true, prototype = "Document") | |
public interface Document { | |
public HTMLElement createElement(String div); | |
public HTMLElement getElementById(String id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment