Skip to content

Instantly share code, notes, and snippets.

@jawher
Created December 3, 2010 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jawher/727141 to your computer and use it in GitHub Desktop.
Save jawher/727141 to your computer and use it in GitHub Desktop.
GWT JSNI
import com.google.gwt.core.client.JavaScriptObject;
public final class FsItem extends JavaScriptObject {
protected FsItem() {
}
public native FsItem init(boolean folder, String absoluteName, String name, int size) /*-{
this.folder = folder;
this.absoluteName = absoluteName;
this.name = name;
this.size = size;
return this;
}-*/;
public native boolean isFolder() /*-{ return this.folder }-*/;
public native String getAbsoluteName()/*-{ return this.absoluteName }-*/;
public native String getName() /*-{ return this.name }-*/;
public native int getSize()/*-{ return this.size }-*/;
}
import com.google.gwt.core.client.JavaScriptObject;
public class JsArray<E extends JavaScriptObject> extends JavaScriptObject {
protected JsArray() { }
public final native int length() /*-{ return this.length; }-*/;
public final native E get(int i) /*-{ return this[i]; }-*/;
}
private static final native JsArray<FsItem> fsItems(String json) /*-{
return eval('('+json+')'); //important: wrap the json in ()
}-*/;
public static final native FsItem newItem(boolean folder, String absoluteName, String name, int size) /*-{
return eval('({folder: '+folder+', absoluteName: "'+absoluteName+'", name: "'+name+'", size: '+size+' })');
}-*/;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment