Browse Source

Merge pull request #349 from manolo/mcm_fix

Some fixes needed to run gquery with gwt-2.8.0-SNAPSHOT
tags/gwtquery-project-1.5-beta1
Manuel Carrasco Moñino 8 years ago
parent
commit
454b3ea3ca

+ 37
- 85
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java View File

@@ -207,59 +207,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return new GQuery(JsNodeArray.create());
}

/**
* Wrap a GQuery around an existing element.
*/
public static GQuery $(Element element) {
return new GQuery(element);
}

/**
* Wrap a GQuery around an event's target element.
*/
public static GQuery $(Event event) {
return event == null ? $() : $((Element) event.getCurrentEventTarget().cast());
}

/**
* Wrap a GQuery around the element of a Function callback.
*/
public static GQuery $(Function f) {
return $(f.getElement());
}

/**
* Wrap a GQuery around an existing javascript element, event, node, nodelist, function or array.
*/
public static GQuery $(JavaScriptObject jso) {
if (jso == null) {
return $();
}
// Execute a native javascript function like jquery does
if (JsUtils.isFunction(jso)) {
new JsUtils.JsFunction(jso).fe();
return $();
}
// Wraps a native array like jquery does
if (!JsUtils.isWindow(jso) && !JsUtils.isElement(jso) && JsUtils.isArray(jso)) {
JsArrayMixed c = jso.cast();
JsNodeArray elms = JsNodeArray.create();
for (int i = 0; i < c.length(); i++) {
Object obj = c.getObject(i);
if (obj instanceof Node) {
elms.addNode((Node) obj);
}
}
return $(elms);
}

return JsUtils.isWindow(jso) ? $(jso.<Element> cast()) :
JsUtils.isElement(jso) ? $(jso.<Element> cast()) :
JsUtils.isEvent(jso) ? $(jso.<Event> cast()) :
JsUtils.isNodeList(jso) ? $(jso.<NodeList<Element>> cast()) :
$(jso.<Element> cast());
}

/**
* Wrap a GQuery around any object, supported objects are:
* String, GQuery, Function, Widget, JavaScriptObject.
@@ -269,7 +216,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* selector is supported in browsers with native xpath engine.
*
* In the case of a JavaScriptObject we handle:
* Element, Event, Node, Nodelist and native functions or arrays.
* Element, Event, Node, Nodelist, Function, and native functions or arrays.
*
* If the case of a native function, we execute it and return empty.
*/
@@ -278,26 +225,52 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
if (o instanceof String) {
return $((String) o);
}
if (o instanceof SafeHtml) {
return $(((SafeHtml) o).asString());
}
if (o instanceof GQuery) {
return (GQuery) o;
}
if (o instanceof Function) {
return $((Function) o);
}
if (JsUtils.isElement(o)) {
return $(JsUtils.<Element> cast(o));
return new GQuery(((Function) o).getElement());
}
if (o instanceof JsonBuilder) {
return new GQuery(((JsonBuilder) o).<Element>getDataImpl());
}
if (o instanceof JavaScriptObject) {
return $((JavaScriptObject) o);
}
if (o instanceof IsWidget) {
return $(Arrays.asList(o));
}
console
.log("Error: GQuery.$(Object o) could not wrap the type : ", o.getClass().getName(), o);
if (o instanceof JavaScriptObject) {
JavaScriptObject jso = (JavaScriptObject) o;
// Execute a native javascript function like jquery does
if (JsUtils.isFunction(jso)) {
new JsUtils.JsFunction(jso).fe();
return $();
}
// Wraps a native array like jquery does
if (!JsUtils.isWindow(jso) && !JsUtils.isElement(jso) && JsUtils.isArray(jso)) {
JsArrayMixed c = jso.cast();
JsNodeArray elms = JsNodeArray.create();
for (int i = 0; i < c.length(); i++) {
Object obj = c.getObject(i);
if (obj instanceof Node) {
elms.addNode((Node) obj);
}
}
return new GQuery(elms);
}
// Wraps a native NodeList
if (JsUtils.isNodeList(jso)) {
return new GQuery(jso.<NodeList<Element>> cast());
}
// Wraps an event
if (JsUtils.isEvent(jso)) {
jso = jso.<Event>cast().getCurrentEventTarget();
}
// Otherwise we wrap it as an element
return new GQuery(jso.<Element> cast());
}
throw new RuntimeException("Error: GQuery.$(Object o) could not wrap the type : " + o.getClass().getName() + " " + o);
}
return $();
}
@@ -320,20 +293,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return new GQuery(elms);
}

/**
* Wrap a GQuery around an existing node.
*/
public static GQuery $(Node n) {
return $((Element) n);
}

/**
* Wrap a GQuery around existing Elements.
*/
public static GQuery $(NodeList<Element> elms) {
return new GQuery(elms);
}

/**
* This function accepts a string containing a CSS selector which is then used to match a set of
* elements, or it accepts raw HTML creating a GQuery element containing those elements. Xpath
@@ -343,13 +302,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return $(selectorOrHtml, document);
}
/**
* This function accepts a SafeHtml creating a GQuery element containing those elements.
*/
public static GQuery $(SafeHtml safeHtml) {
return $(safeHtml.asString());
}

/**
* This function accepts a string containing a CSS selector which is then used to match a set of
* elements, or it accepts raw HTML creating a GQuery element containing those elements. The
@@ -4984,7 +4936,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* its structure -- it is that element that will enwrap everything else.
*/
public GQuery wrap(SafeHtml safeHtml) {
return wrap(safeHtml.asString());
return wrap($(safeHtml));
}

/**

+ 68
- 0
gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java View File

@@ -25,6 +25,7 @@ import com.google.gwt.query.client.js.JsNamedArray;
import com.google.gwt.query.client.js.JsNodeArray;
import com.google.gwt.query.client.plugins.Effects;
import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.user.client.ui.Widget;

import java.util.List;
@@ -78,6 +79,12 @@ public interface LazyGQuery<T> extends LazyBase<T> {
*/
LazyGQuery<T> after(String html);

/**
* Insert content after each of the matched elements. The elements must already be inserted into
* the document (you can't insert an element after another if it's not in the page).
*/
LazyGQuery<T> after(SafeHtml safeHtml);

/**
*
* The animate() method allows you to create animation effects on any numeric HTML Attribute,
@@ -264,6 +271,12 @@ public interface LazyGQuery<T> extends LazyBase<T> {
*/
LazyGQuery<T> append(String html);

/**
* Append content to the inside of every matched element. This operation is similar to doing an
* appendChild to all the specified elements, adding them into the document.
*/
LazyGQuery<T> append(SafeHtml safeHtml);

/**
* All of the matched set of elements will be inserted at the end of the element(s) specified by
* the parameter other.
@@ -291,6 +304,15 @@ public interface LazyGQuery<T> extends LazyBase<T> {
*/
LazyGQuery<T> appendTo(String html);

/**
* All of the matched set of elements will be inserted at the end of the element(s) specified by
* the parameter other.
*
* The operation $(A).appendTo(B) is, essentially, the reverse of doing a regular $(A).append(B),
* instead of appending B to A, you're appending A to B.
*/
LazyGQuery<T> appendTo(SafeHtml safeHtml);

/**
* Convert to Plugin interface provided by Class literal.
*/
@@ -1122,6 +1144,11 @@ public interface LazyGQuery<T> extends LazyBase<T> {
*/
LazyGQuery<T> html(String html);

/**
* Set the innerHTML of every matched element.
*/
LazyGQuery<T> html(SafeHtml safeHtml);

/**
* Get the id of the first matched element.
*/
@@ -1940,6 +1967,16 @@ public interface LazyGQuery<T> extends LazyBase<T> {
*/
LazyGQuery<T> queue(String queueName, Function... f);

/**
* Specify a function to execute when the DOM is fully loaded.
*
* While JavaScript provides the load event for executing code when a page is rendered, this event
* is not seen if we attach an event listener after the document has been loaded.
* This guarantees that our gwt code will be executed either it's executed synchronously before the
* DOM has been rendered (ie: single script linker in header) or asynchronously.
*/
Promise ready(Function... fncs);

/**
* Removes all matched elements from the DOM.
*/
@@ -2489,6 +2526,15 @@ public interface LazyGQuery<T> extends LazyBase<T> {
*/
LazyGQuery<T> wrap(String html);

/**
* Wrap each matched element with the specified SafeHtml content. This wrapping process is most useful
* for injecting additional structure into a document, without ruining the original semantic
* qualities of a document. This works by going through the first element provided (which is
* generated, on the fly, from the provided SafeHtml) and finds the deepest descendant element within
* its structure -- it is that element that will enwrap everything else.
*/
LazyGQuery<T> wrap(SafeHtml safeHtml);

/**
* Wrap all the elements in the matched set into a single wrapper element. This is different from
* .wrap() where each element in the matched set would get wrapped with an element. This wrapping
@@ -2525,6 +2571,18 @@ public interface LazyGQuery<T> extends LazyBase<T> {
*/
LazyGQuery<T> wrapAll(String html);

/**
* Wrap all the elements in the matched set into a single wrapper element. This is different from
* .wrap() where each element in the matched set would get wrapped with an element. This wrapping
* process is most useful for injecting additional structure into a document, without ruining the
* original semantic qualities of a document.
*
* This works by going through the first element provided (which is generated, on the fly, from
* the provided SafeHtml) and finds the deepest descendant element within its structure -- it is that
* element that will enwrap everything else.
*/
LazyGQuery<T> wrapAll(SafeHtml safeHtml);

/**
* Wrap the inner child contents of each matched element (including text nodes) with an HTML
* structure. This wrapping process is most useful for injecting additional structure into a
@@ -2555,4 +2613,14 @@ public interface LazyGQuery<T> extends LazyBase<T> {
*/
LazyGQuery<T> wrapInner(String html);

/**
* Wrap the inner child contents of each matched element (including text nodes) with an SafeHtml
* structure. This wrapping process is most useful for injecting additional structure into a
* document, without ruining the original semantic qualities of a document. This works by going
* through the first element provided (which is generated, on the fly, from the provided SafeHtml) and
* finds the deepest ancestor element within its structure -- it is that element that will enwrap
* everything else.
*/
LazyGQuery<T> wrapInner(SafeHtml safeHtml);

}

+ 14
- 0
gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java View File

@@ -17,6 +17,8 @@ package com.google.gwt.query.client.builders;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.core.client.JsArrayMixed;
import com.google.gwt.query.client.GQ;
import com.google.gwt.query.client.IsProperties;
import com.google.gwt.query.client.Properties;
import com.google.gwt.query.client.js.JsCache;
@@ -107,6 +109,18 @@ public abstract class JsonBuilderBase<J extends JsonBuilderBase<?>> implements J
return r;
}

protected final <T extends JsonBuilder> T[] getIsPropertiesArrayBase(JsArrayMixed js, T[] r, Class<T> clazz) {
JsObjectArray<?> a1 = js.cast();
for (int i = 0; i < r.length; i++) {
r[i] = getIsPropertiesBase(a1.get(i), clazz);
}
return r;
}

protected final <T extends JsonBuilder> T getIsPropertiesBase(Object o, Class<T> clazz) {
return GQ.create(clazz).load(o);
}

protected Properties getPropertiesBase(String n) {
if (p.getJavaScriptObject(n) == null) {
p.set(n, Properties.create());

+ 10
- 2
gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java View File

@@ -228,6 +228,14 @@ public class JsUtils {
}
}

/**
* Execute a native javascript function.
*/
public static <T> T exec(JavaScriptObject jsFunction, Object... args) {
assert isFunction(jsFunction);
return jsni(jsFunction, "call", jsFunction, args);
}

/**
* Assign a function to a property of the window object.
*/
@@ -334,7 +342,7 @@ public class JsUtils {
* present.
*/
public static native boolean hasAttribute(Element o, String name) /*-{
return !!(o && o.getAttribute(name));
return !!(o && o.getAttribute(name) !== null);
}-*/;

/**
@@ -410,7 +418,7 @@ public class JsUtils {
public static native boolean isNodeList(JavaScriptObject o) /*-{
var r = Object.prototype.toString.call(o);
return r == '[object HTMLCollection]' || r == '[object NodeList]'
|| (typeof o == 'object' && o.length && o[0].tagName) ? true : false;
|| (typeof o == 'object' && o.length && o[0] && o[0].tagName) ? true : false;
}-*/;

/**

+ 3
- 12
gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java View File

@@ -183,8 +183,7 @@ public class JsonBuilderGenerator extends Generator {
sw.println("return p.getStr(\"" + name + "\");");
} else if (isTypeAssignableTo(method.getReturnType(), jsonBuilderType)) {
String q = method.getReturnType().getQualifiedSourceName();
sw.println("return " + "((" + q + ")GWT.create(" + q + ".class))"
+ ".load(getPropertiesBase(\"" + name + "\"));");
sw.println("return " + "getIsPropertiesBase(getPropertiesBase(\"" + name + "\")," + q + ".class);");
} else if (isTypeAssignableTo(method.getReturnType(), settingsType)) {
String q = method.getReturnType().getQualifiedSourceName();
sw.println("return " + "((" + q + ")getPropertiesBase(\"" + name + "\"));");
@@ -203,16 +202,7 @@ public class JsonBuilderGenerator extends Generator {
sw.println("int l = a == null ? 0 : a.length();");
String ret;
if (buildType) {
sw.println(t + "[] r = new " + t + "[l];");
sw.println("JsObjectArray<?> a1 = p.getArray(\"" + name
+ "\").cast();");
sw.println("int l1 = r.length;");
sw.println("for (int i = 0 ; i < l1 ; i++) {");
sw.println(" Object w = a1.get(i);");
sw.println(" " + t + " instance = GWT.create(" + t + ".class);");
sw.println(" r[i] = instance.load(w);");
sw.println("}");
ret = "r";
ret = "getIsPropertiesArrayBase(a, new " + t + "[l], " + t + ".class)";
} else {
ret = "getArrayBase(\"" + name + "\", new " + t + "[l], " + t + ".class)";
}
@@ -326,6 +316,7 @@ public class JsonBuilderGenerator extends Generator {
types.add(t);
}
}
sw.println("GQuery.console.error(\"GQ.create: not registered class :\" + clz);");
sw.println("return null;");
sw.outdent();
sw.println("}");

+ 4
- 4
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryJsInteropTestGwt.java View File

@@ -58,23 +58,23 @@ public class GQueryJsInteropTestGwt extends GWTTestCase {
}
}

@JsType(prototype = "Window", isNative = true)
@JsType(prototype = "Window")
public interface HTMLWindow {
@JsProperty String getName();
@JsProperty void setName(String name);
}

@JsType(prototype = "Window", isNative = true)
@JsType(prototype = "Window")
public interface HWindow {
@JsProperty HDocument document();
}

@JsType(prototype = "HTMLDocument", isNative = false)
@JsType(prototype = "HTMLDocument")
public interface HDocument {
HElement createElement(String tag);
}
@JsType(prototype = "HTMLElement", isNative = false)
@JsType(prototype = "HTMLElement")
public interface HElement {
@JsProperty void id(String s);
}

+ 5
- 0
gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java View File

@@ -82,6 +82,8 @@ public class DataBindingTestJre extends GWTTestCase {
Boolean getZ();
String[] getT();
JsonExample setT(String[] strings);
Item[] getIt();
JsonExample setIt(Item[] items);
JsonExample setZ(Boolean b);
JsonExample setD(long l);
List<Item> getItems();
@@ -140,6 +142,9 @@ public class DataBindingTestJre extends GWTTestCase {
Item i2 = GQ.create(Item.class);
i2.setDate(new Date(3000));
Item[] items = new Item[]{i1, i2};
c.setIt(items);
assertEquals(2000l, c.getIt()[0].getDate().getTime());
assertEquals(3000l, c.getIt()[1].getDate().getTime());
c.setItems(Arrays.asList(items));
assertEquals(2000l, c.getItems().get(0).getDate().getTime());
assertEquals(3000l, c.getItems().get(1).getDate().getTime());

+ 8
- 2
pom.xml View File

@@ -139,6 +139,12 @@
<snapshots><enabled>true</enabled></snapshots>
<releases><enabled>false</enabled></releases>
</repository>
<repository>
<id>google-snapshots</id>
<url>http://oss.sonatype.org/content/repositories/google-snapshots</url>
<snapshots><enabled>true</enabled></snapshots>
<releases><enabled>true</enabled></releases>
</repository>
<repository>
<id>gwtquery-plugins</id>
<url>http://gwtquery-plugins.googlecode.com/svn/mavenrepo</url>
@@ -146,8 +152,8 @@
</repositories>

<properties>
<gwtversion>2.7.0</gwtversion>
<gwtmaven>2.7.0</gwtmaven>
<gwtversion>2.8.0-SNAPSHOT</gwtversion>
<gwtmaven>2.8.0-SNAPSHOT</gwtmaven>
<gqueryclassifier />
<gwt.loglevel>INFO</gwt.loglevel>
<gwt.outputstyle>OBF</gwt.outputstyle>

Loading…
Cancel
Save