From 99c595608e0b17561366234fa2bb4a621857697b Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Tue, 19 Apr 2011 07:22:52 +0000 Subject: [PATCH] widgets plugin has a just set of basic factories, the rest will be in the enhance plugin or others --- .../com/google/gwt/query/client/GQuery.java | 3 +- .../google/gwt/query/client/LazyGQuery.java | 3 +- .../client/impl/SelectorEngineCssToXPath.java | 5 +- .../client/impl/SelectorEngineNative.java | 26 ++++- .../google/gwt/query/client/js/JsUtils.java | 2 +- .../gwt/query/client/plugins/LazyWidgets.java | 75 +++++++++++++++ .../gwt/query/client/plugins/Widgets.java | 96 +++++++++++++++++++ .../plugins/widgets/ButtonWidgetFactory.java | 50 ++++++++++ .../plugins/widgets/LabelWidgetFactory.java | 30 ++++++ .../widgets/PasswordTextBoxWidgetFactory.java | 32 +++++++ .../widgets/TextAreaWidgetFactory.java | 52 ++++++++++ .../widgets/TextBoxBaseWidgetFactory.java | 65 +++++++++++++ .../plugins/widgets/TextBoxWidgetFactory.java | 31 ++++++ .../samples/client/GwtQuerySampleModule.java | 30 +++++- .../samples/public/GwtQuerySample.html | 48 ++++++++-- 15 files changed, 528 insertions(+), 20 deletions(-) create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/LabelWidgetFactory.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/PasswordTextBoxWidgetFactory.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextAreaWidgetFactory.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxBaseWidgetFactory.java create mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxWidgetFactory.java diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index 6e6ee04a..587edbf6 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -1204,12 +1204,13 @@ public class GQuery implements Lazy { /** * 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. + * matched elements. You can use either js maps or pure css syntax. * * Example: * *
    *  $(".item").css(Properties.create("color: 'red', background:'blue'"))
+   *  $(".item").css(Properties.create("color: red; background: blue;"))
    * 
*/ public GQuery css(Properties properties) { 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 index 2dfdd958..2553bb4f 100644 --- 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 @@ -518,12 +518,13 @@ public interface LazyGQuery extends LazyBase{ /** * 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. + * matched elements. You can use either js maps or pure css syntax. * * Example: * *
    *  $(".item").css(Properties.create("color: 'red', background:'blue'"))
+   *  $(".item").css(Properties.create("color: red; background: blue;"))
    * 
*/ LazyGQuery css(Properties properties); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java index 5d7c8050..c2109dfe 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java @@ -34,7 +34,7 @@ import com.google.gwt.query.client.js.JsUtils; */ public class SelectorEngineCssToXPath extends SelectorEngineImpl { - JsNamedArray cache = JsNamedArray.create(); + JsNamedArray cache; /** * Interface for callbacks in replaceAll operations. @@ -187,6 +187,9 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { } public NodeList select(String sel, Node ctx) { + if (cache == null) { + JsNamedArray.create(); + } JsNodeArray elm = JsNodeArray.create(); String xsel = cache.get(sel); if (xsel == null) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java index c7aa2101..f8d2cd6c 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java @@ -16,6 +16,7 @@ package com.google.gwt.query.client.impl; import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.RunAsyncCallback; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; @@ -30,20 +31,37 @@ public class SelectorEngineNative extends SelectorEngineImpl { private static HasSelector impl; + NodeList result = null; + public SelectorEngineNative() { - if (impl == null) { - impl = GWT.create(HasSelector.class); + } + + RunAsyncCallback callBack = new RunAsyncCallback() { + public void onSuccess() { + if (impl == null) { + impl=GWT.create(HasSelector.class); + } + } + public void onFailure(Throwable reason) { } + }; + + private NodeList jsFallbackSelect (String selector, Node ctx) { + if (impl == null) { + GWT.runAsync(callBack); + while (impl == null); + } + return impl.select(selector, ctx); } public NodeList select(String selector, Node ctx) { if (!SelectorEngine.hasQuerySelector || selector.matches(NATIVE_EXCEPTIONS_REGEXP)) { - return impl.select(selector, ctx); + return jsFallbackSelect(selector, ctx); } else { try { return SelectorEngine.querySelectorAllImpl(selector, ctx); } catch (Exception e) { - return impl.select(selector, ctx); + return jsFallbackSelect(selector, ctx); } } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java index d3c3f019..b504d6e4 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java @@ -104,7 +104,7 @@ public class JsUtils { Element e = a.get(i); int id = e.hashCode(); if (!cache.exists(id)) { - cache.put(id, true); + cache.put(id, 1); ret.push(e); } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java index 21822380..29f33b28 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java @@ -18,9 +18,19 @@ import java.util.ArrayList; import java.util.List; import com.google.gwt.dom.client.Element; import com.google.gwt.query.client.GQuery; +import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory; +import com.google.gwt.query.client.plugins.widgets.LabelWidgetFactory; +import com.google.gwt.query.client.plugins.widgets.PasswordTextBoxWidgetFactory; +import com.google.gwt.query.client.plugins.widgets.TextAreaWidgetFactory; +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.WidgetsUtils; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.PasswordTextBox; +import com.google.gwt.user.client.ui.TextArea; +import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.Widget; import com.google.gwt.query.client.LazyBase; @@ -33,4 +43,69 @@ public interface LazyWidgets extends LazyBase{ */ LazyWidgets widgets(WidgetFactory factory, WidgetInitializer initializers); + /** + * Create a {@link Button} widget for each selected element. The + * initializers will be called on each new {@link Button} created + * by passing them in parameter. + * + */ + LazyWidgets button(); + + /** + * Create a {@link Button} widget for each selected element. The + * initializers will be called on each new {@link Button} created + * by passing them in parameter. + * + */ + LazyWidgets button(WidgetInitializer