]> source.dussan.org Git - gwtquery.git/commitdiff
Added lazy generator
authorRay Cromwell <cromwellian@gmail.com>
Tue, 5 May 2009 00:12:58 +0000 (00:12 +0000)
committerRay Cromwell <cromwellian@gmail.com>
Tue, 5 May 2009 00:12:58 +0000 (00:12 +0000)
18 files changed:
gwtquery-core/src/main/java/com/google/gwt/query/Query.gwt.xml
gwtquery-core/src/main/java/com/google/gwt/query/client/$.java
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
gwtquery-core/src/main/java/com/google/gwt/query/client/JsClosure.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/Lazy.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/LazyBase.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/Widgets.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineXPath.java
gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorBase.java
gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJSOptimal.java
gwtquery-core/src/test/java/com/google/gwt/query/client/GwtQueryCoreTest.java
samples/src/main/java/gwtquery/samples/GwtQueryBench.gwt.xml
samples/src/main/java/gwtquery/samples/GwtQueryDemo.gwt.xml
samples/src/main/java/gwtquery/samples/GwtQuerySample.gwt.xml
samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java

index a09eeafc61f9c8606ab10deeba321eaedcca64b1..0b503ae6b5b0abd0cb8b127574a225c2157bea2d 100644 (file)
      ]]>\r
     </property-provider>\r
 \r
+    <generate-with class="com.google.gwt.query.rebind.LazyGenerator">\r
+        <when-type-assignable class="com.google.gwt.query.client.Lazy"/>\r
+    </generate-with>\r
+\r
     <generate-with class="com.google.gwt.query.rebind.SelectorGeneratorJS">\r
         <when-type-assignable class="com.google.gwt.query.client.Selectors"/>\r
         <any>\r
@@ -78,4 +82,4 @@
         </all>\r
     </replace-with>\r
 \r
-</module>
\ No newline at end of file
+</module>\r
index c57777dc0c0a2fb69f277c595ac0a15860c43ef8..a3c56323fb60b28c4a55e9a0e82c29bbe682035d 100644 (file)
@@ -18,13 +18,18 @@ package com.google.gwt.query.client;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.Node;
 import com.google.gwt.dom.client.NodeList;
+import com.google.gwt.user.client.Event;
 
 /**
- * A facade class of forwarding functions which allow end users to refer to
- * the GQuery class as '$' if they desire.
+ * A facade class of forwarding functions which allow end users to refer to the
+ * GQuery class as '$' if they desire.
  */
 public class $ {
 
+  public static LazyGQuery lazy() {
+    return GQuery.$().lazy();
+  }
+  
   public static GQuery $(String selectorOrHtml) {
     return GQuery.$(selectorOrHtml);
   }
@@ -87,8 +92,6 @@ public class $ {
 
   /**
    * Registers a GQuery plugin.
-   * @param plugin
-   * @param pluginFactory
    */
   public static void registerPlugin(Class<? extends GQuery> plugin,
       Plugin<? extends GQuery> pluginFactory) {
index 127b451ed9c4645418dfe2cb0e0fd51140e0b0a5..574ab8c79ef6c4eb5dd13fa5e7a6caf6d174be92 100644 (file)
@@ -45,10 +45,9 @@ import java.util.Map;
 /**\r
  * Gwt Query is a GWT clone of the popular jQuery library.\r
  */\r
-public class GQuery {\r
+public class GQuery implements Lazy<GQuery, LazyGQuery> {\r
 \r
   /**\r
-   * \r
    * A POJO used to store the top/left CSS positioning values of an element.\r
    */\r
   public static class Offset {\r
@@ -86,9 +85,7 @@ public class GQuery {
 \r
     public native JavaScriptObject get(int id) /*-{\r
       return this[id];\r
-    }-*/; /*-{\r
-      delete this[name];\r
-    }-*/\r
+    }-*/;\r
 \r
     public DataCache getCache(int id) {\r
       return get(id).cast();\r
@@ -206,6 +203,13 @@ public class GQuery {
   private static final int FUNC_PREPEND = 0, FUNC_APPEND = 1, FUNC_AFTER = 2,\r
       FUNC_BEFORE = 3;\r
 \r
+  /**\r
+   * Create an empty GQuery object.\r
+   */\r
+  public static GQuery $() {\r
+    return new GQuery(JSArray.create());\r
+  }\r
+\r
   /**\r
    * This function accepts a string containing a CSS selector which is then used\r
    * to match a set of elements, or it accepts raw HTML creating a GQuery\r
@@ -740,6 +744,22 @@ public class GQuery {
     return new GQuery(unique(result));\r
   }\r
 \r
+  /**\r
+   * Set a single style property to a value, on all matched elements using\r
+   * type-safe overhead-free enumerations.\r
+   *\r
+   * @param property a CSS property type\r
+   * @param value a legal value from the type T\r
+   * @param <T> inferred from the CSS property type\r
+   * @return\r
+   */\r
+//  public <T> GQuery css(CssProperty<T> property, T value) {\r
+//    for(Element e : elements()) {\r
+//      property.set(e.getStyle(), value);\r
+//    }\r
+//    return this;\r
+\r
+  //  }\r
   /**\r
    * Return a style property on the first matched element.\r
    */\r
@@ -873,6 +893,10 @@ public class GQuery {
     return this;\r
   }\r
 \r
+  public LazyGQuery lazy() {\r
+    return GWT.create(GQuery.class);\r
+  }\r
+\r
   /**\r
    * Revert the most recent 'destructive' operation, changing the set of matched\r
    * elements to its previous state (right before the destructive operation).\r
@@ -921,7 +945,7 @@ public class GQuery {
    * Fade out all matched elements by adjusting their opacity.\r
    */\r
   public GQuery fadeOut(int millisecs) {\r
-    return $(as(Effects).fadeOut(millisecs));\r
+    return as(Effects).fadeOut(millisecs);\r
   }\r
 \r
   /**\r
@@ -2219,10 +2243,11 @@ public class GQuery {
     }\r
     for (Element e : wrap.elements()) {\r
       Node n = e;\r
-      while (n.getFirstChild() != null) {\r
+      while (n.getFirstChild() != null\r
+          && n.getFirstChild().getNodeType() == Node.ELEMENT_NODE) {\r
         n = n.getFirstChild();\r
-        $((Element) n).append(this);\r
       }\r
+      $((Element) n).append(this);\r
     }\r
     return this;\r
   }\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/JsClosure.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/JsClosure.java
new file mode 100644 (file)
index 0000000..b8d51f3
--- /dev/null
@@ -0,0 +1,20 @@
+package com.google.gwt.query.client;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+/**
+ * Overlay type representing a Javascript closure.
+ */
+public class JsClosure extends JavaScriptObject {
+
+  protected JsClosure() {
+  }
+
+  /**
+   * Invoke the closure with no arguments and expecting no return value.
+   */
+  public final native void invoke() /*-{
+     return this();
+  }-*/;
+
+}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Lazy.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Lazy.java
new file mode 100644 (file)
index 0000000..5f2347b
--- /dev/null
@@ -0,0 +1,18 @@
+package com.google.gwt.query.client;
+
+/**
+ * A tagging interface which triggers the LazyGenerator for type T.
+ * LazyGenerator creates an implementation of Type T for the class by
+ * forwarding method calls to the class which implements the Lazy interface.
+ * Methods in the generated class do not execute but instead queue up a
+ * deferred execution of the method.
+ */
+public interface Lazy<S, T extends LazyBase<S>> {
+
+  /**
+   * Create a lazy instance of the current class. Most implementing classes
+   * will automate this by simply invoking GWT.create().
+   * @return
+   */
+   T lazy();
+}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyBase.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyBase.java
new file mode 100644 (file)
index 0000000..2f34bbd
--- /dev/null
@@ -0,0 +1,9 @@
+package com.google.gwt.query.client;
+
+/**
+ * All lazy interfaces must extend this baseclass. This ensures the done()
+ * method exists and returns an executable function. 
+ */
+public interface LazyBase<S> {
+   Function done();
+}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java
new file mode 100644 (file)
index 0000000..c30773f
--- /dev/null
@@ -0,0 +1,907 @@
+package com.google.gwt.query.client;
+
+import com.google.gwt.dom.client.Node;
+import com.google.gwt.dom.client.Element;
+//import com.google.gwt.query.client.css.CssProperty;
+
+/**
+ * Created by IntelliJ IDEA. User: ray Date: May 2, 2009 Time: 10:48:07 PM To
+ * change this template use File | Settings | File Templates.
+ */
+public interface LazyGQuery extends LazyBase<GQuery>  {
+
+  /**
+   * Add elements to the set of matched elements if they are not included yet.
+   */
+
+  LazyGQuery add(String selector);
+
+  /**
+   * Adds the specified classes to each matched element. Add elements to the set
+   * of matched elements if they are not included yet.
+   */
+  LazyGQuery add(GQuery previousObject);
+
+  /**
+   * Adds the specified classes to each matched element.
+   */
+  LazyGQuery addClass(String... classes);
+
+  /**
+   * 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 after(Node n);
+
+  /**
+   * 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 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 after(GQuery query);
+
+  /**
+   * Add the previous selection to the current selection. Useful for traversing
+   * elements, and then adding something that was matched before the last
+   * traversal.
+   */
+  LazyGQuery andSelf();
+
+  /**
+   * 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 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 append(Node n);
+
+  /**
+   * 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 append(GQuery query);
+
+  /**
+   * Append all of the matched elements to another, specified, set of elements.
+   * This operation is, essentially, the reverse of doing a regular
+   * $(A).append(B), in that instead of appending B to A, you're appending A to
+   * B.
+   */
+  LazyGQuery appendTo(GQuery other);
+
+  /**
+   * Convert to Plugin interface provided by Class literal.
+   */
+  <T extends LazyGQuery> T as(Class<T> plugin);
+
+  /**
+   * Set a single property to a value, on all matched elements.
+   */
+  LazyGQuery attr(String key, String value);
+
+  /**
+   * Set a key/value object as properties to all matched elements.
+   *
+   * Example: $("img").attr(new Properties("src: 'test.jpg', alt: 'Test
+   * Image'"))
+   */
+  LazyGQuery attr(Properties properties);
+
+  /**
+   * Set a single property to a computed value, on all matched elements.
+   */
+  LazyGQuery attr(String key, Function closure);
+
+  /**
+   * Insert content before each of the matched elements. The elements must
+   * already be inserted into the document (you can't insert an element before
+   * another if it's not in the page).
+   */
+  LazyGQuery before(Node n);
+
+  /**
+   * Insert content before each of the matched elements. The elements must
+   * already be inserted into the document (you can't insert an element before
+   * another if it's not in the page).
+   */
+  LazyGQuery before(GQuery query);
+
+  /**
+   * Insert content before each of the matched elements. The elements must
+   * already be inserted into the document (you can't insert an element before
+   * another if it's not in the page).
+   */
+  LazyGQuery before(String html);
+
+  /**
+   * Binds a handler to a particular Event (like Event.ONCLICK) for each matched
+   * element.
+   *
+   * The event handler is passed as a Function that you can use to prevent
+   * default behaviour. To stop both default action and event bubbling, the
+   * function event handler has to return false.
+   *
+   * You can pass an additional Object data to your Function as the second
+   * parameter
+   */
+  LazyGQuery bind(int eventbits, Object data, Function f);
+
+  /**
+   * Bind a function to the blur event of each matched element.
+   */
+  LazyGQuery blur(Function f);
+
+  /**
+   * Trigger a blur event.
+   */
+  LazyGQuery blur();
+
+  /**
+   * Bind a function to the change event of each matched element.
+   */
+  LazyGQuery change(Function f);
+
+  /**
+   * Trigger a change event.
+   */
+  LazyGQuery change();
+
+  /**
+   * Get a set of elements containing all of the unique children of each of the
+   * matched set of elements. This set is filtered with the expressions that
+   * will cause only elements matching any of the selectors to be collected.
+   */
+  LazyGQuery children(String... filters);
+
+  /**
+   * Get a set of elements containing all of the unique immediate children of
+   * each of the matched set of elements. Also note: while parents() will look
+   * at all ancestors, children() will only consider immediate child elements.
+   */
+  LazyGQuery children();
+
+  /**
+   * Trigger a click event.
+   */
+  LazyGQuery click();
+
+  /**
+   * Triggers the click event of each matched element. Causes all of the
+   * functions that have been bound to that click event to be executed.
+   */
+  LazyGQuery click(Function f);
+
+  /**
+   * Clone matched DOM Elements and select the clones. This is useful for moving
+   * copies of the elements to another location in the DOM.
+   */
+  LazyGQuery clone();
+
+  /**
+   * Filter the set of elements to those that contain the specified text.
+   */
+  LazyGQuery contains(String text);
+
+  /**
+   * Find all the child nodes inside the matched elements (including text
+   * nodes), or the content document, if the element is an iframe.
+   */
+  LazyGQuery contents();
+
+  /**
+   * Set a single style property to a value, on all matched elements using
+   * type-safe overhead-free enumerations.
+   *
+   * @param property a CSS property type
+   * @param value a legal value from the type T
+   * @param <T> inferred from the CSS property type
+   * @return
+   */
+//  <T> LazyGQuery css(CssProperty<T> property, T value);
+
+  /**
+   * Set a key/value object as style properties to all matched elements. This
+   * serves as the best way to set a large number of style properties on all
+   * matched elements.
+   *
+   * Example: $(".item").css(Properties.create("color: 'red', background:
+   * 'blue'"))
+   */
+  LazyGQuery css(Properties properties);
+
+  /**
+   * Set a single style property to a value, on all matched elements.
+   */
+  LazyGQuery css(String prop, String val);
+
+  /**
+   * Trigger a double click event.
+   */
+  LazyGQuery dblclick();
+
+  /**
+   * Bind a function to the dblclick event of each matched element.
+   */
+  LazyGQuery dblclick(Function f);
+
+  /**
+   * Removes a queued function from the front of the queue and executes it.
+   */
+  LazyGQuery dequeue(String type);
+
+  /**
+   * Removes a queued function from the front of the FX queue and executes it.
+   */
+  LazyGQuery dequeue();
+
+  /**
+   * Run one or more Functions over each element of the GQuery.
+   */
+  LazyGQuery each(Function... f);
+
+  /**
+   * Remove all child nodes from the set of matched elements.
+   */
+  LazyGQuery empty();
+
+  /**
+   * Revert the most recent 'destructive' operation, changing the set of matched
+   * elements to its previous state (right before the destructive operation).
+   */
+  LazyGQuery end();
+
+  /**
+   * Reduce GQuery to element in the specified position.
+   */
+  LazyGQuery eq(int pos);
+
+  /**
+   * Trigger an error event.
+   */
+  LazyGQuery error();
+
+  /**
+   * Bind a function to the error event of each matched element.
+   */
+  LazyGQuery error(Function f);
+
+  /**
+   * Fade in all matched elements by adjusting their opacity.
+   */
+  LazyGQuery fadeIn(int millisecs);
+
+  /**
+   * Fade in all matched elements by adjusting their opacity. The effect will
+   * take 1000 milliseconds to complete
+   */
+  LazyGQuery fadeIn();
+
+  /**
+   * Fade out all matched elements by adjusting their opacity.
+   */
+  LazyGQuery fadeOut(int millisecs);
+
+  /**
+   * Fade out all matched elements by adjusting their opacity. The effect will
+   * take 1000 milliseconds to complete
+   */
+  LazyGQuery fadeOut();
+
+  /**
+   * Removes all elements from the set of matched elements that do not match the
+   * specified function. The function is called with a context equal to the
+   * current element. If the function returns false, then the element is removed
+   * - anything else and the element is kept.
+   */
+  LazyGQuery filter(Predicate filterFn);
+
+  /**
+   * Removes all elements from the set of matched elements that do not pass the
+   * specified css expression. This method is used to narrow down the results of
+   * a search. Provide a comma-separated list of expressions to apply multiple
+   * filters at once.
+   */
+  LazyGQuery filter(String... filters);
+
+  /**
+   * Searches for all elements that match the specified css expression. This
+   * method is a good way to find additional descendant elements with which to
+   * process.
+   *
+   * Provide a comma-separated list of expressions to apply multiple filters at
+   * once.
+   */
+  LazyGQuery find(String... filters);
+
+  /**
+   * Trigger a focus event.
+   */
+  LazyGQuery focus();
+
+  /**
+   * Bind a function to the focus event of each matched element.
+   */
+
+  LazyGQuery focus(Function f);
+
+  /**
+   * Return the previous set of matched elements prior to the last destructive
+   * operation (e.g. query)
+   */
+  LazyGQuery getPreviousObject();
+
+  /**
+   * Returns true any of the specified classes are present on any of the matched
+   * Reduce the set of matched elements to all elements after a given position.
+   * The position of the element in the set of matched elements starts at 0 and
+   * goes to length - 1.
+   */
+  LazyGQuery gt(int pos);
+
+  /**
+   * Set the height of every element in the matched set.
+   */
+  LazyGQuery height(int height);
+
+  /**
+   * Set the height style property of every matched element. It's useful for
+   * using 'percent' or 'em' units Example: $(".a").width("100%")
+   */
+  LazyGQuery height(String height);
+
+  /**
+   * Make invisible all matched elements.
+   */
+  LazyGQuery hide();
+
+  /**
+   * Bind a function to the mouseover event of each matched element. A method
+   * for simulating hovering (moving the mouse on, and off, an object). This is
+   * a custom method which provides an 'in' to a frequent task. Whenever the
+   * mouse cursor is moved over a matched element, the first specified function
+   * is fired. Whenever the mouse moves off of the element, the second specified
+   * function fires.
+   */
+  LazyGQuery hover(Function fover, Function fout);
+
+  /**
+   * Set the innerHTML of every matched element.
+   */
+  LazyGQuery html(String html);
+
+  /**
+   * Insert all of the matched elements after another, specified, set of
+   * elements.
+   */
+  LazyGQuery insertAfter(String selector);
+
+  /**
+   * Insert all of the matched elements after another, specified, set of
+   * elements.
+   */
+  LazyGQuery insertAfter(Element elem);
+
+  /**
+   * Insert all of the matched elements after another, specified, set of
+   * elements.
+   */
+  LazyGQuery insertAfter(GQuery query);
+
+  /**
+   * Insert all of the matched elements before another, specified, set of
+   * 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 insertBefore(Element item);
+
+  /**
+   * Insert all of the matched elements before another, specified, set of
+   * 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 insertBefore(GQuery query);
+
+  /**
+   * Insert all of the matched elements before another, specified, set of
+   * 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 insertBefore(String selector);
+
+  /**
+   * Trigger a keydown event.
+   */
+  LazyGQuery keydown();
+
+  /**
+   * Trigger a keypress event.
+   */
+  LazyGQuery keypress();
+
+  /**
+   * Bind a function to the keypress event of each matched element.
+   */
+  LazyGQuery keypressed(Function f);
+
+  /**
+   * Trigger a keyup event.
+   */
+  LazyGQuery keyup();
+
+  /**
+   * Bind a function to the keyup event of each matched element.
+   */
+  LazyGQuery keyup(Function f);
+
+  /**
+   * Bind a function to the load event of each matched element.
+   */
+  LazyGQuery load(Function f);
+
+  /**
+   * Reduce the set of matched elements to all elements before a given position.
+   * The position of the element in the set of matched elements starts at 0 and
+   * goes to length - 1.
+   */
+  LazyGQuery lt(int pos);
+
+  /**
+   * Bind a function to the mousedown event of each matched element.
+   */
+  LazyGQuery mousedown(Function f);
+
+  /**
+   * Bind a function to the mousemove event of each matched element.
+   */
+  LazyGQuery mousemove(Function f);
+
+  /**
+   * Bind a function to the mouseout event of each matched element.
+   */
+  LazyGQuery mouseout(Function f);
+
+  /**
+   * Bind a function to the mouseover event of each matched element.
+   */
+  LazyGQuery mouseover(Function f);
+
+  /**
+   * Bind a function to the mouseup event of each matched element.
+   */
+  LazyGQuery mouseup(Function f);
+
+  /**
+   * Get a set of elements containing the unique next siblings of each of the
+   * given set of elements. next only returns the very next sibling for each
+   * element, not all next siblings see {#nextAll}.
+   */
+  LazyGQuery next();
+
+  /**
+   * Get a set of elements containing the unique next siblings of each of the
+   * given set of elements filtered by 1 or more selectors. next only returns
+   * the very next sibling for each element, not all next siblings see
+   * {#nextAll}.
+   */
+  LazyGQuery next(String... selectors);
+
+  /**
+   * Find all sibling elements after the current element.
+   */
+  LazyGQuery nextAll();
+
+  /**
+   * Removes the specified Element from the set of matched elements. This method
+   * is used to remove a single Element from a jQuery object.
+   */
+  LazyGQuery not(Element elem);
+
+  /**
+   * Removes any elements inside the passed set of elements from the set of
+   * matched elements.
+   */
+  LazyGQuery not(GQuery gq);
+
+  /**
+   * Removes elements matching the specified expression from the set of matched
+   * elements.
+   */
+  LazyGQuery not(String... filters);
+
+  /**
+   * Returns a GQuery collection with the positioned parent of the first matched
+   * element. This is the first parent of the element that has position (as in
+   * relative or absolute). This method only works with visible elements.
+   */
+  LazyGQuery offsetParent();
+
+  /**
+   * Binds a handler to a particular Event (like Event.ONCLICK) for each matched
+   * element. The handler is executed only once for each element.
+   *
+   * The event handler is passed as a Function that you can use to prevent
+   * default behaviour. To stop both default action and event bubbling, the
+   * function event handler has to return false.
+   *
+   * You can pass an additional Object data to your Function as the second
+   * parameter
+   */
+  LazyGQuery one(int eventbits, Object data, Function f);
+
+  /**
+   * Get a set of elements containing the unique parents of the matched set of
+   * elements.
+   */
+  LazyGQuery parent();
+
+  /**
+   * Get a set of elements containing the unique parents of the matched set of
+   * elements. You may use an optional expressions to filter the set of parent
+   * elements that will match one of them.
+   */
+  LazyGQuery parent(String... filters);
+
+  /**
+   * Get a set of elements containing the unique ancestors of the matched set of
+   * elements (except for the root element). The matched elements are filtered,
+   * returning those that match any of the filters.
+   */
+  LazyGQuery parents(String... filters);
+
+  /**
+   * Get a set of elements containing the unique ancestors of the matched set of
+   * elements (except for the root element).
+   */
+  LazyGQuery parents();
+
+  /**
+   * Prepend content to the inside of every matched element. This operation is
+   * the best way to insert elements inside, at the beginning, of all matched
+   * elements.
+   */
+  LazyGQuery prepend(String html);
+
+  /**
+   * Prepend content to the inside of every matched element. This operation is
+   * the best way to insert elements inside, at the beginning, of all matched
+   * elements.
+   */
+  LazyGQuery prepend(GQuery query);
+
+  /**
+   * Prepend content to the inside of every matched element. This operation is
+   * the best way to insert elements inside, at the beginning, of all matched
+   * elements.
+   */
+  LazyGQuery prepend(Node n);
+
+  /**
+   * Prepend all of the matched elements to another, specified, set of elements.
+   * This operation is, essentially, the reverse of doing a regular
+   * $(A).prepend(B), in that instead of prepending B to A, you're prepending A
+   * to B.
+   */
+  LazyGQuery prependTo(GQuery elms);
+
+  /**
+   * Get a set of elements containing the unique previous siblings of each of
+   * the matched set of elements. Only the immediately previous sibling is
+   * returned, not all previous siblings.
+   */
+  LazyGQuery prev();
+
+  /**
+   * Get a set of elements containing the unique previous siblings of each of
+   * the matched set of elements filtered by selector. Only the immediately
+   * previous sibling is returned, not all previous siblings.
+   */
+  LazyGQuery prev(String... selectors);
+
+  /**
+   * Find all sibling elements in front of the current element.
+   */
+  LazyGQuery prevAll();
+
+  /**
+   * Adds a new function, to be executed, onto the end of the queue of all
+   * matched elements.
+   */
+  LazyGQuery queue(String type, Function data);
+
+  /**
+   * Adds a new function, to be executed, onto the end of the queue of all
+   * matched elements in the FX queue.
+   */
+  LazyGQuery queue(Function data);
+
+  /**
+   * Removes all matched elements from the DOM.
+   */
+  LazyGQuery remove();
+
+  /**
+   * Remove the named attribute from every element in the matched set.
+   */
+  LazyGQuery removeAttr(String key);
+
+  /**
+   * Removes the specified classes to each matched element.
+   */
+  LazyGQuery removeClass(String... classes);
+
+  /**
+   * Removes named data store from an element.
+   */
+  LazyGQuery removeData(String name);
+
+  /**
+   * Replaces the elements matched by the specified selector with the matched
+   * elements. This function is the complement to replaceWith() which does the
+   * same task with the parameters reversed.
+   */
+  LazyGQuery replaceAll(GQuery query);
+
+  /**
+   * Replaces the elements matched by the specified selector with the matched
+   * elements. This function is the complement to replaceWith() which does the
+   * same task with the parameters reversed.
+   */
+  LazyGQuery replaceAll(String html);
+
+  /**
+   * Replaces the elements matched by the specified selector with the matched
+   * elements. This function is the complement to replaceWith() which does the
+   * same task with the parameters reversed.
+   */
+  LazyGQuery replaceAll(Element elem);
+
+  /**
+   * Replaces all matched elements with the specified HTML or DOM elements. This
+   * returns the GQuery element that was just replaced, which has been removed
+   * from the DOM.
+   */
+  LazyGQuery replaceWith(GQuery query);
+
+  /**
+   * Replaces all matched elements with the specified HTML or DOM elements. This
+   * returns the GQuery element that was just replaced, which has been removed
+   * from the DOM.
+   */
+  LazyGQuery replaceWith(String html);
+
+  /**
+   * Replaces all matched elements with the specified HTML or DOM elements. This
+   * returns the GQuery element that was just replaced, which has been removed
+   * from the DOM.
+   */
+  LazyGQuery replaceWith(Element elem);
+
+  /**
+   * Bind a function to the scroll event of each matched element.
+   */
+  LazyGQuery scroll(Function f);
+
+  /**
+   * When a value is passed in, the scroll left offset is set to that value on
+   * all matched elements. This method works for both visible and hidden
+   * elements.
+   */
+  LazyGQuery scrollLeft(int left);
+
+  /**
+   * Gets the scroll left offset of the first matched element. This method works
+   * for both visible and hidden elements.
+   */
+  int scrollLeft();
+
+  /**
+   * When a value is passed in, the scroll top offset is set to that value on
+   * all matched elements. This method works for both visible and hidden
+   * elements.
+   */
+  LazyGQuery scrollTop(int top);
+
+  /**
+   * Gets the scroll top offset of the first matched element. This method works
+   * for both visible and hidden elements.
+   */
+  int scrollTop();
+
+  LazyGQuery select();
+
+  /**
+   * Return the number of elements in the matched set. Make visible all mached
+   * elements
+   */
+  LazyGQuery show();
+
+  /**
+   * Get a set of elements containing all of the unique siblings of each of the
+   * matched set of elements.
+   */
+  LazyGQuery siblings();
+
+  /**
+   * Get a set of elements containing all of the unique siblings of each of the
+   * matched set of elements filtered by the provided set of selectors.
+   */
+  LazyGQuery siblings(String... selectors);
+
+  /**
+   * Selects a subset of the matched elements.
+   */
+  LazyGQuery slice(int start, int end);
+
+  LazyGQuery submit();
+
+  /**
+   * Set the innerText of every matched element.
+   */
+  LazyGQuery text(String txt);
+
+  /**
+   * Toggle among two or more function calls every other click.
+   */
+  LazyGQuery toggle(Function... fn);
+
+  /**
+   * Adds or removes the specified classes to each matched element.
+   */
+  LazyGQuery toggleClass(String... classes);
+
+  /**
+   * Adds or removes the specified classes to each matched element.
+   */
+  LazyGQuery toggleClass(String clz, boolean sw);
+
+  /**
+   * Trigger an event of type eventbits on every matched element.
+   */
+  LazyGQuery trigger(int eventbits, int... keys);
+
+  /**
+   * Removes all events that match the eventbits.
+   */
+  LazyGQuery unbind(int eventbits);
+
+  /**
+   * Sets the value attribute of every matched element In the case of multivalue
+   * elements, all values are setted for other elements, only the first value is
+   * considered.
+   */
+  LazyGQuery val(String... values);
+
+  /**
+   * Set the width of every matched element.
+   */
+  LazyGQuery width(int width);
+
+  /**
+   * Wrap each matched element with the specified HTML 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 HTML) and finds the deepest descendant element
+   * within its structure -- it is that element that will enwrap everything
+   * else.
+   */
+  LazyGQuery wrap(GQuery query);
+
+  /**
+   * Wrap each matched element with the specified HTML 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 HTML) and finds the deepest descendant element
+   * within its structure -- it is that element that will enwrap everything
+   * else.
+   */
+  LazyGQuery wrap(Element elem);
+
+  /**
+   * Wrap each matched element with the specified HTML 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 HTML) and finds the deepest descendant element
+   * within its structure -- it is that element that will enwrap everything
+   * else.
+   */
+  LazyGQuery wrap(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 HTML) and finds the deepest descendant
+   * element within its structure -- it is that element that will enwrap
+   * everything else.
+   */
+  LazyGQuery 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 HTML) and finds the deepest descendant
+   * element within its structure -- it is that element that will enwrap
+   * everything else.
+   */
+  LazyGQuery wrapAll(Element elem);
+
+  /**
+   * 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 HTML) and finds the deepest descendant
+   * element within its structure -- it is that element that will enwrap
+   * everything else.
+   */
+  LazyGQuery wrapAll(GQuery query);
+
+  /**
+   * 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 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
+   * HTML) and finds the deepest ancestor element within its structure -- it is
+   * that element that will enwrap everything else.
+   */
+  LazyGQuery wrapInner(GQuery query);
+
+  /**
+   * 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 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
+   * HTML) and finds the deepest ancestor element within its structure -- it is
+   * that element that will enwrap everything else.
+   */
+  LazyGQuery wrapInner(String html);
+
+  /**
+   * 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 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
+   * HTML) and finds the deepest ancestor element within its structure -- it is
+   * that element that will enwrap everything else.
+   */
+  LazyGQuery wrapInner(Element elem);
+}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Widgets.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Widgets.java
new file mode 100644 (file)
index 0000000..6fa411c
--- /dev/null
@@ -0,0 +1,75 @@
+package com.google.gwt.query.client;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.NodeList;
+import com.google.gwt.user.client.ui.Button;
+
+/**
+ * Experimental Gwt Query plugin for integrating Gwt Widgets.
+ */
+public class Widgets extends GQuery  {
+  /**
+   * Used to register the plugin.
+   */
+  private static class WidgetsPlugin implements Plugin<Widgets> {
+
+    public Widgets init(GQuery gq) {
+      return new Widgets(gq.get());
+    }
+  }
+
+  public static final Class<Widgets> Widgets = Widgets.class;
+
+  static {
+    GQuery.registerPlugin(Widgets.class, new WidgetsPlugin());
+  }
+
+  public Widgets(Element element) {
+    super(element);
+  }
+
+  public Widgets(JSArray elements) {
+    super(elements);
+  }
+
+  public Widgets(NodeList list) {
+    super(list);
+  }
+
+  /**
+   * Create a builder capable of instantiating a GWT Button object over
+   * every matched element. Call end() to execute builder and return to the
+   * current query object.
+   * @return a ButtonBuilder
+   */
+  public ButtonBuilder button() {
+    return new ButtonBuilder("*");
+  }
+
+  public class ButtonBuilder {
+
+    private String selector;
+
+    private String label;
+
+    private String labelSelector;
+
+    public ButtonBuilder(String selector) {
+      this.selector=selector;
+    }
+
+    public ButtonBuilder label(String label) {
+      this.labelSelector = label;
+      return this;
+    }
+
+    public Widgets end() {
+      for(Element e: elements()) {
+        Button b = Button.wrap(e);
+        b.setText($(labelSelector, e).text());
+
+      }
+      return Widgets.this;
+    }
+  }
+}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java
new file mode 100644 (file)
index 0000000..4099fe8
--- /dev/null
@@ -0,0 +1,39 @@
+package com.google.gwt.query.client.css;
+
+/**
+ * Created by IntelliJ IDEA. User: ray Date: May 2, 2009 Time: 12:56:09 AM To
+ * change this template use File | Settings | File Templates.
+ */
+public class CSS {
+//  public static VerticalAlign VERTICAL_ALIGN;
+//
+//  /**
+//   * Align the top of the aligned subtree with the top of the line box.
+//   */
+//  public static TextAlign.TAlignValue LEFT;
+//
+//  public static TextAlign.TAlignValue RIGHT;
+//
+//  public static TextAlign TEXT_ALIGN;
+//
+//  /**
+//   * Align the top of the aligned subtree with the top of the line box.
+//   */
+//  public static VerticalAlign.VAlignValue TOP;
+//
+//  public static VerticalAlign.VAlignValue BOTTOM;
+//
+//  public static VerticalAlign.VAlignValue BASELINE;
+//
+//  public static VerticalAlign.VAlignValue SUB;
+//
+//  public static VerticalAlign.VAlignValue SUPER;
+//
+//  public static VerticalAlign.VAlignValue TEXT_TOP;
+//
+//  public static VerticalAlign.VAlignValue MIDDLE;
+//
+//  public static VerticalAlign.VAlignValue TEXT_BOTTOM;
+//
+//  public static VerticalAlign.VAlignValue INHERIT;
+}
index dafed4e4c605c5cc6593e9573bc831e4f25072c7..b08a598bffb6b073361cadb0189175546df884ba 100644 (file)
@@ -234,7 +234,7 @@ public class SelectorEngineXPath extends SelectorEngineImpl {
         if(!allAttr) return "";\r
         return allAttr.replace(/(\w+)(\^|\$|\*|\||~)?=?([\w\u00C0-\uFFFF\s\-_\.]+)?/g, \r
             function(a,b,c,d) {\r
-              return @gwtquery.client.impl.SelectorEngineXPath::attrToXPath(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)(a,b || "",c || "",d || "");\r
+              return @com.google.gwt.query.client.impl.SelectorEngineXPath::attrToXPath(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)(a,b || "",c || "",d || "");\r
             });\r
             \r
     }-*/;\r
@@ -243,4 +243,4 @@ public class SelectorEngineXPath extends SelectorEngineImpl {
         if(!allAttr) return "";\r
         return allAttr.replace(/\[(\w+)(\^|\$|\*|\||~)?=?([\w\u00C0-\uFFFF\s\-_\.]+)?\]/g, @com.google.gwt.query.client.impl.SelectorEngineXPath::attrToXPath(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;));\r
     }-*/;\r
-}
\ No newline at end of file
+}\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java
new file mode 100644 (file)
index 0000000..5ce1d82
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2009 Google Inc.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.rebind;
+
+import com.google.gwt.core.ext.Generator;
+import com.google.gwt.core.ext.GeneratorContext;
+import com.google.gwt.core.ext.TreeLogger;
+import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.core.ext.typeinfo.JClassType;
+import com.google.gwt.core.ext.typeinfo.JMethod;
+import com.google.gwt.core.ext.typeinfo.JParameter;
+import com.google.gwt.core.ext.typeinfo.TypeOracle;
+import com.google.gwt.core.ext.typeinfo.JGenericType;
+import com.google.gwt.core.ext.typeinfo.JTypeParameter;
+import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
+import com.google.gwt.user.rebind.SourceWriter;
+
+import java.io.PrintWriter;
+
+/**
+ * Generate lazy implementations for interface delegated to parameterized type.
+ * The originating type implements Lazy<T> where T extends LazyBase<OriginType>.
+ * The generator generates an implementation of T where each method returns type
+ * T and queues up a closure which delegates execution of the method to the
+ * OriginType.
+ */
+public class LazyGenerator extends Generator {
+
+  private JClassType lazyType = null;
+
+  private JClassType lazyBaseType = null;
+
+  public String generate(TreeLogger treeLogger,
+      GeneratorContext generatorContext, String requestedClass)
+      throws UnableToCompleteException {
+    TypeOracle oracle = generatorContext.getTypeOracle();
+    lazyType = oracle.findType("com.google.gwt.query.client.Lazy");
+    lazyBaseType = oracle.findType("com.google.gwt.query.client.LazyBase");
+
+    assert lazyType != null : "Can't find Lazy interface type";
+    assert lazyBaseType != null : "Can't find LazyBase interface type";
+
+    JClassType requestedType = oracle.findType(requestedClass);
+    JClassType targetType = null;
+    JClassType nonLazyType = null;
+
+    for (JClassType inf : requestedType.getImplementedInterfaces()) {
+      if (inf.isAssignableTo(lazyType)) {
+        nonLazyType = inf.isParameterized().getTypeArgs()[0];
+        targetType = inf.isParameterized().getTypeArgs()[1];
+        break;
+      }
+    }
+
+    assert targetType != null : "Parameter of Lazy<T> not found";
+    String genClass = targetType.getPackage().getName() + "."
+        + targetType.getSimpleSourceName() + getImplSuffix();
+
+    SourceWriter sw = getSourceWriter(treeLogger, generatorContext,
+        requestedType.getPackage().getName(),
+        targetType.getSimpleSourceName() + getImplSuffix(),
+        targetType.getQualifiedSourceName());
+    if (sw != null) {
+      generatePreamble(sw, nonLazyType.getQualifiedSourceName(), treeLogger);
+      sw.indent();
+      for (JMethod method : targetType.getMethods()) {
+        generateMethod(sw, method, nonLazyType.getQualifiedSourceName(),
+            genClass, treeLogger);
+      }
+      sw.outdent();
+      generateDoneMethod(sw, nonLazyType.getQualifiedSourceName(), treeLogger);
+      sw.commit(treeLogger);
+    }
+
+    return genClass;
+  }
+
+  private void generatePreamble(SourceWriter sw, String nonLazyClass,
+      TreeLogger treeLogger) {
+    sw.indent();
+    sw.println(
+        "private JsArray<JsClosure> closures = JsArray.createArray().cast();");
+    sw.println("private " + nonLazyClass + "  ctx;");
+    sw.outdent();
+  }
+
+  public String getJSNIParams(JMethod method) {
+
+    String reference = "(";
+    JParameter[] params = method.getParameters();
+    for (int i = 0; i < params.length; i++) {
+      reference += params[i].getType().getJNISignature();
+    }
+    reference += ")";
+    return reference;
+  }
+
+  public void generateMethod(SourceWriter sw, JMethod method,
+      String nonLazyClass, String genClass, TreeLogger logger)
+      throws UnableToCompleteException {
+
+    JParameter[] params = method.getParameters();
+    String thisClass = method.getEnclosingType().getQualifiedSourceName();
+    JTypeParameter gType = method.getReturnType().isTypeParameter();
+
+    String retType = method.getReturnType()
+        .getParameterizedQualifiedSourceName();
+    if (gType != null) {
+      retType = "<" + gType.getParameterizedQualifiedSourceName() + " extends "
+          + gType.getFirstBound().getQualifiedSourceName() + "> " + retType;
+    }
+    sw.print("public final native " + retType + " " + method.getName());
+    sw.print("(");
+    int argNum = 0;
+    for (JParameter param : params) {
+      sw.print((argNum == 0 ? "" : ", ")
+          + param.getType().getParameterizedQualifiedSourceName() + " arg"
+          + argNum);
+      argNum++;
+    }
+    sw.println(") /*-{");
+
+    sw.indent();
+    sw.println("var self=this;");
+    sw.println("this.@" + genClass + "::closures.push(");
+    sw.indent();
+    sw.println("function() {");
+    sw.indent();
+    sw.print("self.@" + genClass + "::ctx=self.@" + genClass + "::ctx.@"
+        + nonLazyClass + "::" + method.getName());
+    sw.print(getJSNIParams(method));
+    sw.print("(");
+    for (int i = 0; i < argNum; i++) {
+      sw.print("arg" + i + (i < argNum - 1 ? "," : ""));
+    }
+
+    sw.println(");");
+    sw.outdent();
+    sw.println("}");
+    sw.outdent();
+    sw.println(");");
+    sw.println("return this;");
+    sw.outdent();
+    sw.println("}-*/;");
+  }
+
+  protected String getImplSuffix() {
+    return "Impl";
+  }
+
+  protected SourceWriter getSourceWriter(TreeLogger logger,
+      GeneratorContext context, String packageName, String className,
+      String... interfaceNames) {
+    PrintWriter printWriter = context.tryCreate(logger, packageName, className);
+    if (printWriter == null) {
+      return null;
+    }
+    ClassSourceFileComposerFactory composerFactory
+        = new ClassSourceFileComposerFactory(packageName, className);
+    composerFactory.addImport("com.google.gwt.core.client.*");
+    composerFactory.addImport("com.google.gwt.query.client.*");
+    composerFactory.addImport("com.google.gwt.dom.client.Element");
+    composerFactory.addImport("com.google.gwt.user.client.Event");
+    composerFactory.addImport("com.google.gwt.query.client.Function");
+    composerFactory.addImport("com.google.gwt.query.client.JsClosure");
+
+    for (String interfaceName : interfaceNames) {
+      composerFactory.addImplementedInterface(interfaceName);
+    }
+
+    return composerFactory.createSourceWriter(context, printWriter);
+  }
+
+  // used by benchmark harness
+  private void generateDoneMethod(SourceWriter sw, String nonLazyType,
+      TreeLogger treeLogger) {
+    sw.indent();
+    sw.println("public Function done() {");
+    sw.println("return new Function() {");
+    sw.indent();
+
+    sw.println("public void f(Element e) {");
+    sw.indent();
+    sw.println("ctx = GQuery.$(e).as(" + nonLazyType + ".class);");
+    sw.println("for (int i = 0; i < closures.length(); i++) {");
+    sw.indent();
+    sw.println("closures.get(i).invoke();");
+    sw.outdent();
+    sw.println("}");
+    sw.outdent();
+    sw.println("}");
+    sw.println("public boolean f(Event e, Object data) {");
+    sw.indent();
+    sw.println("ctx = GQuery.$(e.getCurrentTarget());");
+    sw.println("for (int i = 0; i < closures.length(); i++) {");
+    sw.indent();
+    sw.println("closures.get(i).invoke();");
+    sw.outdent();
+    sw.println("}");
+    sw.outdent();
+    sw.println("return true;");
+    sw.println("}");
+    sw.outdent();
+    sw.println("};");
+    sw.outdent();
+    sw.println("}");
+  }
+}
index eeb90e2d11e1177e18a3fd20536c578205c52d47..7701efc7458c1e89f058a574086aefb37dc04d94 100644 (file)
@@ -136,7 +136,7 @@ public abstract class SelectorGeneratorBase extends Generator {
         = new ClassSourceFileComposerFactory(packageName, className);\r
     composerFactory.setSuperclass("com.google.gwt.query.client.SelectorEngine");\r
     composerFactory.addImport("com.google.gwt.core.client.GWT");\r
-    composerFactory.addImport("gwtquery.client.*");\r
+    composerFactory.addImport("com.google.gwt.query.client.*");\r
 //    composerFactory.addImport("com.google.gwt.query.client.JSArray");\r
 \r
     composerFactory.addImport("com.google.gwt.dom.client.*");\r
index 442648ac80e568332b87bf601d6bfc366099881c..b21bf16db6b0102ea1fc45d3408797266bc25d89 100644 (file)
@@ -18,8 +18,8 @@ package com.google.gwt.query.rebind;
 import com.google.gwt.core.ext.TreeLogger;\r
 import com.google.gwt.core.ext.UnableToCompleteException;\r
 import com.google.gwt.core.ext.typeinfo.JMethod;\r
-import com.google.gwt.user.rebind.SourceWriter;\r
 import com.google.gwt.query.client.Selector;\r
+import com.google.gwt.user.rebind.SourceWriter;\r
 \r
 import java.util.regex.Pattern;\r
 \r
@@ -43,6 +43,8 @@ public class SelectorGeneratorJSOptimal extends SelectorGeneratorBase {
 \r
   protected static Pattern nonSpace = Pattern.compile("\\S/");\r
 \r
+  private static final String trimReStr = "^\\s+|\\s+$";\r
+\r
   protected static Pattern trimRe = Pattern.compile(trimReStr);\r
 \r
   protected static Pattern tplRe = Pattern.compile("\\{(\\d+)\\}");\r
@@ -66,7 +68,6 @@ public class SelectorGeneratorJSOptimal extends SelectorGeneratorBase {
           "n = byAttribute(n, \"{1}\", \"{3}\", \"{2}\", \"{0}\");"),\r
       new RuleMatcher("^#([a-zA-Z_0-9-]+)", "n = byId(n, null, \"{0}\");")};\r
 \r
-  private static final String trimReStr = "^\\s+|\\s+$";\r
 \r
   protected void generateMethodBody(SourceWriter sw, JMethod method,\r
       TreeLogger treeLogger, boolean hasContext)\r
@@ -190,4 +191,4 @@ public class SelectorGeneratorJSOptimal extends SelectorGeneratorBase {
   protected String getImplSuffix() {\r
     return "JS" + super.getImplSuffix();\r
   }\r
-}
\ No newline at end of file
+}\r
index 27ea88a3bab71ccf9a268c861401c0bd9751c338..2882f6a2e9487459589a59243d0c8ffbdd7f95f6 100644 (file)
@@ -562,17 +562,18 @@ public class GwtQueryCoreTest extends GWTTestCase {
   }
 
   public void testWrapMethod() {
-    String content = "<p>Test Paragraph.</p><div id=\"content\">Content</div>";
+    String content = "<p>Test Paragraph.</p>";
+    String wrapper = "<div id=\"content\">Content</div>";
 
     String expected = "<div id=\"content\">Content<p>Test Paragraph.</p></div>";
     $(e).html(content);
 
-    $("p", e).wrap($("div", e).get(0));
+    $("p", e).wrap(wrapper);
     assertEquals(expected, $(e).html());
 
+    $(e).html(content+wrapper);
     expected
         = "<b><p>Test Paragraph.</p></b><b><div id=\"content\">Content</div></b>";
-    $(e).html(content);
     $("*", e).wrap("<b></b>");
     assertEquals(expected, $(e).html());
   }
index a655154ef22ef8e79134cbd22abb37be992fda40..921732a77dd365c8c1092e3cfcd073a8fc472992 100644 (file)
@@ -1,5 +1,5 @@
 <module>
-    <inherits name='gwtquery.GwtQuery'/>
+    <inherits name='com.google.gwt.query.Query'/>
     <entry-point class='gwtquery.samples.client.GwtQueryBenchModule'/>
 </module>
     
index 3569b0b5d89ba8109ee8f1448828082e7d6b3ff4..d496d5f6e35c85838337e561e5ba6cea2ff0777e 100644 (file)
@@ -1,5 +1,5 @@
 <module>
-    <inherits name='gwtquery.GwtQuery'/>
+    <inherits name='com.google.gwt.query.Query'/>
     <entry-point class='gwtquery.samples.client.GwtQueryDemoModule'/>
  
     
index 7e09e39e9fe17567a1cdc0ccd5d64ea6f9b1e943..11e8bc711bc6d59bd4ee393dcb938b2481e3f982 100644 (file)
@@ -1,5 +1,5 @@
 <module>
-    <inherits name='gwtquery.GwtQuery'/>
+    <inherits name='com.google.gwt.query.Query'/>
     <entry-point class='gwtquery.samples.client.GwtQuerySampleModule'/>
   
   
index 98ab6e4300fbaf355bdee241c182ed787b345b26..f86fa89ba1f98571715bacb01527fad6b57ae04b 100644 (file)
@@ -1,23 +1,23 @@
 package gwtquery.samples.client;\r
 \r
 import com.google.gwt.core.client.EntryPoint;\r
-import com.google.gwt.core.client.GWT;\r
-import com.google.gwt.core.client.JavaScriptObject;\r
-import com.google.gwt.dom.client.Element;\r
-import com.google.gwt.user.client.Window;\r
-import gwtquery.client.*;\r
+import com.google.gwt.query.client.$;\r
+import com.google.gwt.query.client.GQuery;\r
+import com.google.gwt.query.client.Widgets;\r
+import com.google.gwt.query.client.Function;\r
+import static com.google.gwt.query.client.Widgets.*;\r
+import static com.google.gwt.query.client.$.$;\r
+import com.google.gwt.user.client.Event;\r
 \r
 /**\r
- * Copyright 2007 Timepedia.org\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
+ * Copyright 2007 Timepedia.org Licensed under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with the\r
+ * License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\r
  * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
+ * License for the specific language governing permissions and limitations under\r
+ * the License.\r
  *\r
  * @author Ray Cromwell <ray@timepedia.log>\r
  */\r
@@ -25,29 +25,24 @@ public class GwtQuerySampleModule implements EntryPoint {
 //    public interface Sample extends Selectors {\r
 //      @Selector(".note")\r
 //      GQuery allNotes();\r
-//    }\r
-    public void onModuleLoad() {\r
-      Window.alert(Builder.newInstance().setFoo("Hello").setBar("World").setBaz("!").toString());\r
-    }\r
-  \r
-  static final class Builder extends JavaScriptObject {\r
-    protected Builder() {}\r
-    public static Builder newInstance() {\r
-      return createObject().cast();\r
-    }\r
-    \r
-    public native Builder setFoo(String x) /*-{\r
-      return x=this.foo=x, this;\r
-    }-*/;\r
-    \r
-    public native Builder setBar(String x) /*-{\r
-      this.bar = x;\r
-      return this;\r
-    }-*/;\r
+\r
+  //    }\r
+\r
+  public void onModuleLoad() {\r
+    $("div").hover(\r
+        $.lazy().                   \r
+          css("color", "red").\r
+        done(),                                \r
+        $.lazy().\r
+          css("color", "blue").\r
+        done());\r
     \r
-     public native Builder setBaz(String x) /*-{\r
-      this.baz = x;\r
-      return this;\r
-    }-*/;\r
+    $(".note").dblclick(\r
+        $.lazy().\r
+            fadeOut().\r
+        done());\r
+    $("div").wrapAll("<table border=2><tr><td></td></tr></table>").fadeOut(10000);\r
   }\r
+\r
+\r
 }\r