aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManolo Carrasco <manolo@apache.org>2011-04-19 07:22:52 +0000
committerManolo Carrasco <manolo@apache.org>2011-04-19 07:22:52 +0000
commit99c595608e0b17561366234fa2bb4a621857697b (patch)
treeb356fe82d7207e56aa60c3d472b8e39f5d2a9ba4
parentcf4f6348162b6f4c7f7dfa79064bfa6d062b81f6 (diff)
downloadgwtquery-99c595608e0b17561366234fa2bb4a621857697b.tar.gz
gwtquery-99c595608e0b17561366234fa2bb4a621857697b.zip
widgets plugin has a just set of basic factories, the rest will be in the enhance plugin or others
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java3
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java3
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java5
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java26
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java2
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java75
-rwxr-xr-xgwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java96
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java50
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/LabelWidgetFactory.java30
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/PasswordTextBoxWidgetFactory.java32
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextAreaWidgetFactory.java52
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxBaseWidgetFactory.java65
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxWidgetFactory.java31
-rw-r--r--samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java30
-rw-r--r--samples/src/main/java/gwtquery/samples/public/GwtQuerySample.html48
15 files changed, 528 insertions, 20 deletions
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<GQuery, LazyGQuery> {
/**
* 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:
*
* <pre class="code">
* $(".item").css(Properties.create("color: 'red', background:'blue'"))
+ * $(".item").css(Properties.create("color: red; background: blue;"))
* </pre>
*/
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<T> extends LazyBase<T>{
/**
* 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:
*
* <pre class="code">
* $(".item").css(Properties.create("color: 'red', background:'blue'"))
+ * $(".item").css(Properties.create("color: red; background: blue;"))
* </pre>
*/
LazyGQuery<T> 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<String> cache = JsNamedArray.create();
+ JsNamedArray<String> cache;
/**
* Interface for callbacks in replaceAll operations.
@@ -187,6 +187,9 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl {
}
public NodeList<Element> 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<Element> 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<Element> jsFallbackSelect (String selector, Node ctx) {
+ if (impl == null) {
+ GWT.runAsync(callBack);
+ while (impl == null);
+ }
+ return impl.select(selector, ctx);
}
public NodeList<Element> 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<T> extends LazyBase<T>{
*/
<W extends Widget> LazyWidgets<T> widgets(WidgetFactory<W> factory, WidgetInitializer<W> initializers);
+ /**
+ * Create a {@link Button} widget for each selected element. The
+ * <code>initializers</code> will be called on each new {@link Button} created
+ * by passing them in parameter.
+ *
+ */
+ LazyWidgets<T> button();
+
+ /**
+ * Create a {@link Button} widget for each selected element. The
+ * <code>initializers</code> will be called on each new {@link Button} created
+ * by passing them in parameter.
+ *
+ */
+ LazyWidgets<T> button(WidgetInitializer<Button> initializers);
+
+ LazyWidgets<T> label();
+
+ LazyWidgets<T> label(WidgetInitializer<Label> initializers);
+
+ /**
+ * Create a {@link PasswordTextBox} widget for each selected element.
+ */
+ LazyWidgets<T> passwordBox();
+
+ /**
+ * Create a {@link PasswordTextBox} widget for each selected element. The
+ * <code>initializers</code> will be called on each new
+ * {@link PasswordTextBox} created by passing them in parameter.
+ *
+ */
+ LazyWidgets<T> passwordBox(WidgetInitializer<PasswordTextBox> initializers);
+
+ /**
+ * Create a {@link TextBox} widget for each selected element. The
+ * <code>initializers</code> will be called on each new {@link TextBox}
+ * created by passing them in parameter.
+ *
+ */
+ LazyWidgets<T> textBox();
+
+ /**
+ * Create a {@link TextBox} widget for each selected element. The
+ * <code>initializers</code> will be called on each new {@link TextBox}
+ * created by passing them in parameter.
+ *
+ */
+ LazyWidgets<T> textBox(WidgetInitializer<TextBox> initializers);
+
+ /**
+ * Create a {@link TextArea} widget for each selected element. The
+ * <code>initializers</code> will be called on each new {@link TextBox}
+ * created by passing them in parameter.
+ *
+ */
+ LazyWidgets<T> textArea();
+
+ /**
+ * Create a {@link TextArea} widget for each selected element. The
+ * <code>initializers</code> will be called on each new {@link TextBox}
+ * created by passing them in parameter.
+ *
+ */
+ LazyWidgets<T> textArea(WidgetInitializer<TextArea> initializers);
+
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java
index ebaaa733..804c42ed 100755
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java
@@ -20,9 +20,19 @@ 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;
/**
@@ -97,5 +107,91 @@ public class Widgets extends QueuePlugin<Widgets> {
WidgetInitializer<W> initializers) {
return widget(get(0), factory, initializers);
}
+
+ /**
+ * Create a {@link Button} widget for each selected element. The
+ * <code>initializers</code> will be called on each new {@link Button} created
+ * by passing them in parameter.
+ *
+ */
+ public Widgets button() {
+ return widgets(new ButtonWidgetFactory(), null);
+ }
+
+ /**
+ * Create a {@link Button} widget for each selected element. The
+ * <code>initializers</code> will be called on each new {@link Button} created
+ * by passing them in parameter.
+ *
+ */
+ public Widgets button(WidgetInitializer<Button> initializers) {
+ return widgets(new ButtonWidgetFactory(), initializers);
+ }
+
+ public Widgets label() {
+ return widgets(new LabelWidgetFactory(), null);
+ }
+
+ public Widgets label(WidgetInitializer<Label> initializers) {
+ return widgets(new LabelWidgetFactory(), initializers);
+ }
+
+ /**
+ * Create a {@link PasswordTextBox} widget for each selected element.
+ */
+ public Widgets passwordBox() {
+ return widgets(new PasswordTextBoxWidgetFactory(), null);
+ }
+
+ /**
+ * Create a {@link PasswordTextBox} widget for each selected element. The
+ * <code>initializers</code> will be called on each new
+ * {@link PasswordTextBox} created by passing them in parameter.
+ *
+ */
+ public Widgets passwordBox(WidgetInitializer<PasswordTextBox> initializers) {
+ return widgets(new PasswordTextBoxWidgetFactory(), initializers);
+ }
+
+
+ /**
+ * Create a {@link TextBox} widget for each selected element. The
+ * <code>initializers</code> will be called on each new {@link TextBox}
+ * created by passing them in parameter.
+ *
+ */
+ public Widgets textBox() {
+ return widgets(new TextBoxWidgetFactory(), null);
+ }
+
+ /**
+ * Create a {@link TextBox} widget for each selected element. The
+ * <code>initializers</code> will be called on each new {@link TextBox}
+ * created by passing them in parameter.
+ *
+ */
+ public Widgets textBox(WidgetInitializer<TextBox> initializers) {
+ return widgets(new TextBoxWidgetFactory(), initializers);
+ }
+
+ /**
+ * Create a {@link TextArea} widget for each selected element. The
+ * <code>initializers</code> will be called on each new {@link TextBox}
+ * created by passing them in parameter.
+ *
+ */
+ public Widgets textArea() {
+ return widgets(new TextAreaWidgetFactory(), null);
+ }
+
+ /**
+ * Create a {@link TextArea} widget for each selected element. The
+ * <code>initializers</code> will be called on each new {@link TextBox}
+ * created by passing them in parameter.
+ *
+ */
+ public Widgets textArea(WidgetInitializer<TextArea> initializers) {
+ return widgets(new TextAreaWidgetFactory(), initializers);
+ }
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java
new file mode 100644
index 00000000..36d076f6
--- /dev/null
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2011, The gwtquery team.
+ *
+ * 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.client.plugins.widgets;
+
+
+import com.google.gwt.dom.client.ButtonElement;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.query.client.plugins.widgets.WidgetFactory;
+import com.google.gwt.query.client.plugins.widgets.WidgetsUtils;
+import com.google.gwt.user.client.ui.Button;
+
+/**
+ * Factory used to create a {@link Button} widget. A {@link Button} is created
+ * if the element is a <i>button</i>, <i>div></i>, <i>span</i> or <i>a</i>
+ * element (should be extends to other element).
+ */
+public class ButtonWidgetFactory implements WidgetFactory<Button> {
+
+ public Button create(Element e) {
+ Button button = new Button();
+ button.getElement().setInnerText(e.getInnerText());
+
+ if ("button".equalsIgnoreCase(e.getTagName())){
+ copyAttributes((ButtonElement)e.cast(), (ButtonElement)button.getElement().cast());
+ }
+
+ WidgetsUtils.replaceOrAppend(e, button);
+ return button;
+ }
+
+ protected void copyAttributes(ButtonElement source,ButtonElement destination) {
+ destination.setAccessKey(source.getAccessKey());
+ destination.setDisabled(source.isDisabled());
+ destination.setName(source.getName());
+ destination.setValue(source.getValue());
+ }
+} \ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/LabelWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/LabelWidgetFactory.java
new file mode 100644
index 00000000..61636672
--- /dev/null
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/LabelWidgetFactory.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2011, The gwtquery team.
+ *
+ * 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.client.plugins.widgets;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.user.client.ui.Label;
+
+public class LabelWidgetFactory implements WidgetFactory<Label> {
+
+ public Label create(Element e) {
+ Label label = new Label();
+ label.setText(e.getInnerText());
+ WidgetsUtils.replaceOrAppend(e, label);
+ return label;
+ }
+
+} \ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/PasswordTextBoxWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/PasswordTextBoxWidgetFactory.java
new file mode 100644
index 00000000..2d98e941
--- /dev/null
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/PasswordTextBoxWidgetFactory.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2011, The gwtquery team.
+ *
+ * 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.client.plugins.widgets;
+
+import com.google.gwt.user.client.ui.PasswordTextBox;
+
+/**
+ * Factory used to create a {@link PasswordTextBox} widget. 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.
+ *
+ */
+public class PasswordTextBoxWidgetFactory extends
+ TextBoxBaseWidgetFactory<PasswordTextBox> {
+
+ protected PasswordTextBox createWidget() {
+ return new PasswordTextBox();
+ }
+}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextAreaWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextAreaWidgetFactory.java
new file mode 100644
index 00000000..2fab94c9
--- /dev/null
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextAreaWidgetFactory.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2011, The gwtquery team.
+ *
+ * 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.client.plugins.widgets;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.TextAreaElement;
+import com.google.gwt.user.client.ui.TextArea;
+
+/**
+ * Factory used to create a {@link TextArea} widget.
+ *
+ */
+public class TextAreaWidgetFactory extends TextBoxBaseWidgetFactory<TextArea> {
+
+ @Override
+ protected void copyAttributes(Element src, Element dest) {
+ TextAreaElement source= src.cast();
+ TextAreaElement destination = dest.cast();
+
+ destination.setAccessKey(source.getAccessKey());
+ destination.setCols(source.getCols());
+ destination.setDefaultValue(source.getDefaultValue());
+ destination.setDisabled(source.isDisabled());
+ destination.setName(source.getName());
+ destination.setReadOnly(source.isReadOnly());
+ destination.setRows(source.getRows());
+ destination.setValue(source.getValue());
+ }
+
+ @Override
+ protected String getEquivalentTagName() {
+ return "textarea";
+ }
+
+
+ protected TextArea createWidget() {
+ return new TextArea();
+ }
+} \ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxBaseWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxBaseWidgetFactory.java
new file mode 100644
index 00000000..50ffb209
--- /dev/null
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxBaseWidgetFactory.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2011, The gwtquery team.
+ *
+ * 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.client.plugins.widgets;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.InputElement;
+import com.google.gwt.query.client.plugins.widgets.WidgetFactory;
+import com.google.gwt.query.client.plugins.widgets.WidgetsUtils;
+import com.google.gwt.user.client.ui.TextBoxBase;
+
+/**
+ *
+ *
+ */
+public abstract class TextBoxBaseWidgetFactory<T extends TextBoxBase>
+ implements WidgetFactory<T> {
+
+ public T create(Element e) {
+ T textBox = createWidget();
+
+ if (getEquivalentTagName().equalsIgnoreCase(e.getTagName())) {
+ copyAttributes((InputElement) e.cast(),
+ (InputElement) textBox.getElement().cast());
+ } else {
+ textBox.setValue(e.getInnerText());
+ }
+ WidgetsUtils.replaceOrAppend(e, textBox);
+
+ return (T) textBox;
+ }
+
+ protected String getEquivalentTagName(){
+ return "input";
+ }
+
+ protected void copyAttributes(Element src, Element dest) {
+ InputElement source = src.cast();
+ InputElement destination = dest.cast();
+
+ destination.setAccessKey(source.getAccessKey());
+ destination.setDefaultValue(source.getDefaultValue());
+ destination.setDisabled(source.isDisabled());
+ destination.setMaxLength(source.getMaxLength());
+ destination.setReadOnly(source.isReadOnly());
+ destination.setSize(source.getSize());
+ destination.setName(source.getName());
+ destination.setValue(source.getValue());
+
+ }
+
+ protected abstract T createWidget();
+} \ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxWidgetFactory.java
new file mode 100644
index 00000000..4cbe5c54
--- /dev/null
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxWidgetFactory.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2011, The gwtquery team.
+ *
+ * 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.client.plugins.widgets;
+
+import com.google.gwt.user.client.ui.TextBox;
+
+/**
+ * Factory used to create a {@link TextBox} widget. 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.
+ *
+ */
+public class TextBoxWidgetFactory extends TextBoxBaseWidgetFactory<TextBox> {
+
+ protected TextBox createWidget() {
+ return new TextBox();
+ }
+} \ No newline at end of file
diff --git a/samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java b/samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java
index c72f7f50..581d34ae 100644
--- a/samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java
+++ b/samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java
@@ -18,16 +18,23 @@ package gwtquery.samples.client;
import static com.google.gwt.query.client.GQuery.$;
import static com.google.gwt.query.client.GQuery.document;
import static com.google.gwt.query.client.GQuery.lazy;
+import static com.google.gwt.query.client.plugins.Widgets.Widgets;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.Cursor;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.query.client.GQuery;
import com.google.gwt.query.client.Selector;
import com.google.gwt.query.client.Selectors;
import com.google.gwt.query.client.css.CSS;
import com.google.gwt.query.client.css.RGBColor;
+import com.google.gwt.query.client.plugins.widgets.WidgetInitializer;
import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.Label;
public class GwtQuerySampleModule implements EntryPoint {
@@ -47,8 +54,27 @@ public class GwtQuerySampleModule implements EntryPoint {
lazy().css(CSS.COLOR.with(RGBColor.RED)).done(),
lazy().css(CSS.COLOR.with(null)).done()
);
-
// Cascade effects
$("<div id='id' style='font-size: 150%;'>Cascade Efects</div>").appendTo(document).hide().fadeIn(5000).fadeOut(3000);
+
+ // Widgets
+ $(".btn").as(Widgets).button(new WidgetInitializer<Button>() {
+ public void initialize(Button button, Element e) {
+ final String tag = e.getTagName();
+ button.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent event) {
+ Window.alert("You click on a GWT Button created from a " + tag);
+ }
+ });
+ }
+ });
+ $(".inputText").as(Widgets).textBox();
+ $(".inputPsw").as(Widgets).passwordBox();
+ $(".textArea").as(Widgets).textArea();
+ $(".label").as(Widgets).label(new WidgetInitializer<Label>() {
+ public void initialize(Label label, Element e) {
+ label.setText("I'm a gwt label, created from a " + e.getTagName());
+ }
+ });
}
-}
+}
diff --git a/samples/src/main/java/gwtquery/samples/public/GwtQuerySample.html b/samples/src/main/java/gwtquery/samples/public/GwtQuerySample.html
index 1477c1d1..352a2c2c 100644
--- a/samples/src/main/java/gwtquery/samples/public/GwtQuerySample.html
+++ b/samples/src/main/java/gwtquery/samples/public/GwtQuerySample.html
@@ -4,16 +4,44 @@
<script language="javascript" src="gwtquery.samples.GwtQuerySample.nocache.js"></script>
</head>
<body>
-<div class="outer" style='border: 4px solid red; padding: 25px; width: auto; height: 150px' >
- <div>Foo <span class="note">bar</span> baz</div>
- <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
- <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
- <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
- <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
- <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
- <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
- <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
-</div>
+ <div class="outer">
+ <div>Foo <span class="note">bar</span> baz</div>
+ <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
+ <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
+ <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
+ <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
+ <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
+ <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
+ <div>Foo <span class="note">bar</span> <span class="xyz">baz</span></div>
+ </div>
+ <div class="outer">
+ <div class="btn">Make me a button 1!</div>
+ <a class="btn">Make me a button 2!</a>
+ <span class="btn">Make me a button 3!</span>
+ <button class="btn">Make me a button 4!</button>
+ <div class="btn">Make me a button 5!</div>
+ <div class="btn">Make me a button 6!</div>
+ </div>
+ <div class="outer">
+ <div class="inputText">I will be a text input</div>
+ <span class="inputText">I will be a text input</span>
+ <input class="inputText" type="text" value="I will be a text input"></input>
+ </div>
+ <div class="outer">
+ <div class="inputPsw">I will be an password input</div>
+ <span class="inputPsw">I will be an password input</span>
+ <input class="inputPsw" type="password" value="I will be an password input"></input>
+ </div>
+ <div class="outer">
+ <div class="textArea">I will be a text area</div>
+ <span class="textArea">I will be a text area</span>
+ <textarea class="textArea">I will be a text area</textarea>
+ </div>
+ <div class="outer">
+ <div class="label">I will be a label</div>
+ <span class="label">I will be a label</span>
+ <h1 class="label">I will be a label</h1>
+ </div>
</body>
<script>
</script>