]> source.dussan.org Git - gwtquery.git/commitdiff
use a initializer object instead of Function
authorJulien Dramaix <julien.dramaix@gmail.com>
Sun, 6 Mar 2011 08:07:46 +0000 (08:07 +0000)
committerJulien Dramaix <julien.dramaix@gmail.com>
Sun, 6 Mar 2011 08:07:46 +0000 (08:07 +0000)
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetInitializer.java [new file with mode: 0644]

index 3f28013386e17e080b6d864dd0f4c07192c76a04..9d5e7dd5cf1e056f6a29c8500f0deb1f2a2d684f 100644 (file)
@@ -15,7 +15,6 @@
  */
 package com.google.gwt.query.client.plugins;
 import com.google.gwt.dom.client.Element;
-import com.google.gwt.query.client.Function;
 import com.google.gwt.query.client.GQuery;
 import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory;
 import com.google.gwt.query.client.plugins.widgets.DateBoxWidgetFactory;
@@ -26,11 +25,13 @@ import com.google.gwt.query.client.plugins.widgets.RichTextWidgetFactory;
 import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory;
 import com.google.gwt.query.client.plugins.widgets.TextBoxWidgetFactory;
 import com.google.gwt.query.client.plugins.widgets.WidgetFactory;
+import com.google.gwt.query.client.plugins.widgets.WidgetInitializer;
 import com.google.gwt.query.client.plugins.widgets.DisclosurePanelWidgetFactory.DisclosurePanelOptions;
 import com.google.gwt.query.client.plugins.widgets.ListBoxWidgetFactory.ListBoxOptions;
 import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory.TabPanelOptions;
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.DisclosurePanel;
+import com.google.gwt.user.client.ui.ListBox;
 import com.google.gwt.user.client.ui.PasswordTextBox;
 import com.google.gwt.user.client.ui.TabPanel;
 import com.google.gwt.user.client.ui.TextBox;
@@ -47,87 +48,87 @@ public interface LazyWidgets<T> extends LazyBase<T>{
    * will create a tab and the first h3 element inside the div will be used as
    * title
    */
-  LazyWidgets<T> tabPanel(Function... initFunctions);
+  LazyWidgets<T> tabPanel(WidgetInitializer... initializers);
 
   /**
-   * Create a {@link DisclosurePanel} widget for each selected elements. 
+   * Create a {@link DisclosurePanel} widget for each selected elements.
    */
-  LazyWidgets<T> disclosurePanel(DisclosurePanelOptions o, Function... initFunctions);
+  LazyWidgets<T> disclosurePanel(DisclosurePanelOptions o, WidgetInitializer... initializers);
 
   /**
-   * Create {@link DisclosurePanel} widget for each selected elements. 
+   * Create {@link DisclosurePanel} widget for each selected elements.
    */
-  LazyWidgets<T> disclosurePanel(Function... initFunctions);
+  LazyWidgets<T> disclosurePanel(WidgetInitializer... initializers);
 
   /**
    * Create a {@link TabPanel} widget for each selected elements. Each div
    * element inside a selected element will create a tab and the first h3
    * element inside the div will be used as title
    */
-  LazyWidgets<T> tabPanel(TabPanelOptions o, Function... initFunctions);
+  LazyWidgets<T> tabPanel(TabPanelOptions o, WidgetInitializer... initializers);
 
   /**
    * Create a {@link Button} widget for each selected element. The
-   * <code>initFunctions</code> will be called on each new {@link Button}
+   * <code>initializers</code> will be called on each new {@link Button}
    * created by passing them in parameter.
    * 
    */
-  LazyWidgets<T> button(Function... initFunctions);
+  LazyWidgets<T> button(WidgetInitializer... initializers);
 
   /**
    * Create a {@link DateBox} widget for each selected element. The
-   * <code>initFunctions</code> will be called on each new {@link Button}
+   * <code>initializers</code> will be called on each new {@link Button}
    * created by passing them in parameter.
    */
-  LazyWidgets<T> datebox(Function... initFunctions);
+  LazyWidgets<T> datebox(WidgetInitializer... initializers);
 
-  LazyWidgets<T> richtext(Function... initFunctions);
+  LazyWidgets<T> richtext(WidgetInitializer... initializers);
 
   /**
    * Create a {@link TextBox} widget for each selected element. The
-   * <code>initFunctions</code> will be called on each new {@link TextBox}
+   * <code>initializers</code> will be called on each new {@link TextBox}
    * created by passing them in parameter.
-   *
+   * 
    * A {@link TextBox} is created if the element is a <i>input</i> with type
    * text, a <i>div</i> or a<i>span</i> element.
    */
-  LazyWidgets<T> textBox(Function... initFunctions);
+  LazyWidgets<T> textBox(WidgetInitializer... initializers);
 
   /**
    * Create a {@link PasswordTextBox} widget for each selected element. The
-   * <code>initFunctions</code> will be called on each new {@link PasswordTextBox}
-   * created by passing them in parameter.
-   *
-   * A {@link PasswordTextBox} is created if the element is a <i>input</i> with type
-   * <i>password</i>, a <i>div</i> or a<i>span</i> element.
+   * <code>initializers</code> will be called on each new
+   * {@link PasswordTextBox} created by passing them in parameter.
+   * 
+   * A {@link PasswordTextBox} is created if the element is a <i>input</i> with
+   * type <i>password</i>, a <i>div</i> or a<i>span</i> element.
    */
-  LazyWidgets<T> passwordBox(Function... initFunctions);
+  LazyWidgets<T> passwordBox(WidgetInitializer... initializers);
 
   /**
    * Create a {@link ListBox} widget for each selected element. The
-   * <code>initFunctions</code> will be called on each new {@link ListBox}
+   * <code>initializers</code> will be called on each new {@link ListBox}
    * created by passing them in parameter.
-   *
+   * 
    * A {@link ListBox} is created if the element is a <i>input</i> with type
    * <i>password</i>, a <i>div</i> or a<i>span</i> element.
    */
-  LazyWidgets<T> listBox(Function... initFunctions);
+  LazyWidgets<T> listBox(WidgetInitializer... initializers);
 
   /**
    * Create a {@link ListBox} widget for each selected element. The
-   * <code>initFunctions</code> will be called on each new {@link ListBox}
+   * <code>initializers</code> will be called on each new {@link ListBox}
    * created by passing them in parameter.
-   *
+   * 
    * A {@link ListBox} is created if the element is a <i>input</i> with type
    * <i>password</i>, a <i>div</i> or a<i>span</i> element.
    */
-  LazyWidgets<T> listBox(ListBoxOptions options, Function... initFunctions);
+  LazyWidgets<T> listBox(ListBoxOptions options, WidgetInitializer... initializers);
 
   /**
    * Try to create a widget using the given factory and the given options for
    * each element of the query. Returns a new gquery set of elements with the
    * new widgets created.
    */
-  <W extends Widget> LazyWidgets<T> widgets(WidgetFactory<W> factory, Function... initFunctions);
+  <W extends Widget> LazyWidgets<T> widgets(WidgetFactory<W> factory, WidgetInitializer... initializers);
 
 }
index f238fb3200a7f0d0e90b5f81c681e5de354febbd..124dc225857c791d736c117c7e5d5a6e83af9f70 100755 (executable)
@@ -16,7 +16,6 @@
 package com.google.gwt.query.client.plugins;\r
 \r
 import com.google.gwt.dom.client.Element;\r
-import com.google.gwt.query.client.Function;\r
 import com.google.gwt.query.client.GQuery;\r
 import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory;\r
 import com.google.gwt.query.client.plugins.widgets.DateBoxWidgetFactory;\r
@@ -27,11 +26,13 @@ import com.google.gwt.query.client.plugins.widgets.RichTextWidgetFactory;
 import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory;\r
 import com.google.gwt.query.client.plugins.widgets.TextBoxWidgetFactory;\r
 import com.google.gwt.query.client.plugins.widgets.WidgetFactory;\r
+import com.google.gwt.query.client.plugins.widgets.WidgetInitializer;\r
 import com.google.gwt.query.client.plugins.widgets.DisclosurePanelWidgetFactory.DisclosurePanelOptions;\r
 import com.google.gwt.query.client.plugins.widgets.ListBoxWidgetFactory.ListBoxOptions;\r
 import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory.TabPanelOptions;\r
 import com.google.gwt.user.client.ui.Button;\r
 import com.google.gwt.user.client.ui.DisclosurePanel;\r
+import com.google.gwt.user.client.ui.ListBox;\r
 import com.google.gwt.user.client.ui.PasswordTextBox;\r
 import com.google.gwt.user.client.ui.TabPanel;\r
 import com.google.gwt.user.client.ui.TextBox;\r
@@ -47,6 +48,7 @@ import java.util.List;
  */\r
 public class Widgets extends QueuePlugin<Widgets> {\r
 \r
+  \r
   public static final Class<Widgets> Widgets = Widgets.class;\r
 \r
   static {\r
@@ -61,28 +63,28 @@ public class Widgets extends QueuePlugin<Widgets> {
     super(gq);\r
   }\r
 \r
-\r
   /**\r
    * Create {@link TabPanel} widget for each selected elements. Each div element\r
    * will create a tab and the first h3 element inside the div will be used as\r
    * title\r
    */\r
-  public Widgets tabPanel(Function... initFunctions) {\r
-    return tabPanel(new TabPanelOptions(), initFunctions);\r
+  public Widgets tabPanel(WidgetInitializer... initializers) {\r
+    return tabPanel(new TabPanelOptions(), initializers);\r
   }\r
 \r
   /**\r
-   * Create a {@link DisclosurePanel} widget for each selected elements. \r
+   * Create a {@link DisclosurePanel} widget for each selected elements.\r
    */\r
-  public Widgets disclosurePanel(DisclosurePanelOptions o, Function... initFunctions) {\r
-    return widgets(new DisclosurePanelWidgetFactory(o), initFunctions);\r
+  public Widgets disclosurePanel(DisclosurePanelOptions o,\r
+      WidgetInitializer... initializers) {\r
+    return widgets(new DisclosurePanelWidgetFactory(o), initializers);\r
   }\r
-  \r
+\r
   /**\r
-   * Create {@link DisclosurePanel} widget for each selected elements. \r
+   * Create {@link DisclosurePanel} widget for each selected elements.\r
    */\r
-  public Widgets disclosurePanel(Function... initFunctions) {\r
-    return disclosurePanel(new DisclosurePanelOptions(), initFunctions);\r
+  public Widgets disclosurePanel(WidgetInitializer... initializers) {\r
+    return disclosurePanel(new DisclosurePanelOptions(), initializers);\r
   }\r
 \r
   /**\r
@@ -90,90 +92,88 @@ public class Widgets extends QueuePlugin<Widgets> {
    * element inside a selected element will create a tab and the first h3\r
    * element inside the div will be used as title\r
    */\r
-  public Widgets tabPanel(TabPanelOptions o, Function... initFunctions) {\r
-    return widgets(new TabPanelWidgetFactory(o), initFunctions);\r
+  public Widgets tabPanel(TabPanelOptions o, WidgetInitializer... initializers) {\r
+    return widgets(new TabPanelWidgetFactory(o), initializers);\r
   }\r
 \r
-\r
   /**\r
    * Create a {@link Button} widget for each selected element. The\r
-   * <code>initFunctions</code> will be called on each new {@link Button}\r
+   * <code>initializers</code> will be called on each new {@link Button}\r
    * created by passing them in parameter.\r
    * \r
    */\r
-  public Widgets button(Function... initFunctions) {\r
-    return widgets(new ButtonWidgetFactory(), initFunctions);\r
+  public Widgets button(WidgetInitializer... initializers) {\r
+    return widgets(new ButtonWidgetFactory(), initializers);\r
   }\r
 \r
   /**\r
    * Create a {@link DateBox} widget for each selected element. The\r
-   * <code>initFunctions</code> will be called on each new {@link Button}\r
+   * <code>initializers</code> will be called on each new {@link Button}\r
    * created by passing them in parameter.\r
    */\r
-  public Widgets datebox(Function... initFunctions) {\r
-    return widgets(new DateBoxWidgetFactory(), initFunctions);\r
+  public Widgets datebox(WidgetInitializer... initializers) {\r
+    return widgets(new DateBoxWidgetFactory(), initializers);\r
   }\r
-  \r
-  public Widgets richtext(Function... initFunctions) {\r
-    return widgets(new RichTextWidgetFactory(), initFunctions);\r
+\r
+  public Widgets richtext(WidgetInitializer... initializers) {\r
+    return widgets(new RichTextWidgetFactory(), initializers);\r
   }\r
-  \r
+\r
   /**\r
    * Create a {@link TextBox} widget for each selected element. The\r
-   * <code>initFunctions</code> will be called on each new {@link TextBox}\r
+   * <code>initializers</code> will be called on each new {@link TextBox}\r
    * created by passing them in parameter.\r
-   *\r
+   * \r
    * A {@link TextBox} is created if the element is a <i>input</i> with type\r
    * text, a <i>div</i> or a<i>span</i> element.\r
    */\r
-  public Widgets textBox(Function... initFunctions) {\r
-    return widgets(new TextBoxWidgetFactory(), initFunctions);\r
+  public Widgets textBox(WidgetInitializer... initializers) {\r
+    return widgets(new TextBoxWidgetFactory(), initializers);\r
   }\r
 \r
   /**\r
    * Create a {@link PasswordTextBox} widget for each selected element. The\r
-   * <code>initFunctions</code> will be called on each new {@link PasswordTextBox}\r
-   * created by passing them in parameter.\r
-   *\r
-   * A {@link PasswordTextBox} is created if the element is a <i>input</i> with type\r
-   * <i>password</i>, a <i>div</i> or a<i>span</i> element.\r
+   * <code>initializers</code> will be called on each new\r
+   * {@link PasswordTextBox} created by passing them in parameter.\r
+   * \r
+   * A {@link PasswordTextBox} is created if the element is a <i>input</i> with\r
+   * type <i>password</i>, a <i>div</i> or a<i>span</i> element.\r
    */\r
-  public Widgets passwordBox(Function... initFunctions) {\r
-    return widgets(new PasswordTextBoxWidgetFactory(), initFunctions);\r
+  public Widgets passwordBox(WidgetInitializer... initializers) {\r
+    return widgets(new PasswordTextBoxWidgetFactory(), initializers);\r
   }\r
-  \r
+\r
   /**\r
    * Create a {@link ListBox} widget for each selected element. The\r
-   * <code>initFunctions</code> will be called on each new {@link ListBox}\r
+   * <code>initializers</code> will be called on each new {@link ListBox}\r
    * created by passing them in parameter.\r
-   *\r
+   * \r
    * A {@link ListBox} is created if the element is a <i>input</i> with type\r
    * <i>password</i>, a <i>div</i> or a<i>span</i> element.\r
    */\r
-  public Widgets listBox(Function... initFunctions) {\r
-    return listBox(new ListBoxOptions(), initFunctions);\r
+  public Widgets listBox(WidgetInitializer... initializers) {\r
+    return listBox(new ListBoxOptions(), initializers);\r
   }\r
-  \r
+\r
   /**\r
    * Create a {@link ListBox} widget for each selected element. The\r
-   * <code>initFunctions</code> will be called on each new {@link ListBox}\r
+   * <code>initializers</code> will be called on each new {@link ListBox}\r
    * created by passing them in parameter.\r
-   *\r
+   * \r
    * A {@link ListBox} is created if the element is a <i>input</i> with type\r
    * <i>password</i>, a <i>div</i> or a<i>span</i> element.\r
    */\r
-  public Widgets listBox(ListBoxOptions options, Function... initFunctions) {\r
-    return widgets(new ListBoxWidgetFactory(options), initFunctions);\r
+  public Widgets listBox(ListBoxOptions options, WidgetInitializer... initializers) {\r
+    return widgets(new ListBoxWidgetFactory(options), initializers);\r
   }\r
 \r
-  \r
   /**\r
    * Create and return a widget using the given factory and the given options\r
    */\r
   protected <W extends Widget> W widget(WidgetFactory<W> factory,\r
-      Function... initFunctions) {\r
+      WidgetInitializer... initializers) {\r
 \r
-    return widget(get(0), factory, initFunctions);\r
+    return widget(get(0), factory, initializers);\r
   }\r
 \r
   /**\r
@@ -182,10 +182,10 @@ public class Widgets extends QueuePlugin<Widgets> {
    * new widgets created.\r
    */\r
   public <W extends Widget> Widgets widgets(WidgetFactory<W> factory,\r
-      Function... initFunctions) {\r
+      WidgetInitializer... initializers) {\r
     List<Element> result = new ArrayList<Element>();\r
     for (Element e : elements()) {\r
-      W w = widget(e, factory, initFunctions);\r
+      W w = widget(e, factory, initializers);\r
       if (w != null) {\r
         result.add(w.getElement());\r
       }\r
@@ -196,19 +196,19 @@ public class Widgets extends QueuePlugin<Widgets> {
   /**\r
    * Create and return a widget using the given factory and the given options\r
    */\r
-  protected <W extends Widget> W widget(Element e,\r
-      WidgetFactory<W> factory, Function... initFunctions) {\r
-    \r
-    if ($(e).widget() != null){\r
-      //a widget is already attached on this element !!\r
+  protected <W extends Widget> W widget(Element e, WidgetFactory<W> factory,\r
+      WidgetInitializer... initializers) {\r
+\r
+    if ($(e).widget() != null) {\r
+      // a widget is already attached on this element !!\r
       return null;\r
     }\r
-    \r
+\r
     W widget = factory.create(e);\r
 \r
-    if (initFunctions != null) {\r
-      for (Function initFunction : initFunctions) {\r
-        initFunction.f(widget);\r
+    if (initializers != null) {\r
+      for (WidgetInitializer initializer : initializers) {\r
+        initializer.initialize(widget, e);\r
       }\r
     }\r
 \r
@@ -216,5 +216,4 @@ public class Widgets extends QueuePlugin<Widgets> {
 \r
   }\r
 \r
-\r
 }\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetInitializer.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetInitializer.java
new file mode 100644 (file)
index 0000000..ae131e8
--- /dev/null
@@ -0,0 +1,13 @@
+package com.google.gwt.query.client.plugins.widgets;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.user.client.ui.Widget;
+
+public interface WidgetInitializer {
+    /**
+     * Initialize the newly created widget <code>w</code>. The element <code>e</code>
+     * is the element used to construct the widget.
+     *
+     */
+    void initialize(Widget w, Element e);
+  }