aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Dramaix <julien.dramaix@gmail.com>2011-03-03 22:45:25 +0000
committerJulien Dramaix <julien.dramaix@gmail.com>2011-03-03 22:45:25 +0000
commit11b54244a60443d7a5a8edd1deb13833e8d24e59 (patch)
tree93d362732362a3ecbdd71e9b2d799834e0b325eb
parent477fb6941d2b99634bbd532e4bf087c13393cccd (diff)
downloadgwtquery-11b54244a60443d7a5a8edd1deb13833e8d24e59.tar.gz
gwtquery-11b54244a60443d7a5a8edd1deb13833e8d24e59.zip
improve widgets plugins
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java56
-rwxr-xr-xgwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java100
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java49
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/PasswordTextBoxWidgetFactory.java40
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TabPanelWidgetFactory.java56
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxWidgetFactory.java39
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetFactory.java4
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java (renamed from gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/AbstractWidgetFactory.java)37
-rw-r--r--samples/src/main/java/gwtquery/samples/client/GwtQueryWidgetModule.java100
-rw-r--r--samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html6
10 files changed, 262 insertions, 225 deletions
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 12df5e3c..fbfee85d 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
@@ -15,15 +15,17 @@
*/
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.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.WidgetOptions;
-import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory.ButtonOptions;
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.TabPanel;
+import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import java.util.ArrayList;
import java.util.List;
@@ -34,65 +36,79 @@ public interface LazyWidgets<T> extends LazyBase<T>{
/**
* Create an return a {@link TabPanel} widget with the first selected
* elements. Each div element will create a tab and the first h3 element
- * inside the div will be used as title
+ * inside the div will be used as title. The <code>initFunctions</code> will
+ * be called on the new {@link TabPanel} created by passing it in parameter.
+ *
*/
- TabPanel tabPanel();
+ TabPanel tabPanel(Function... initFunctions);
/**
* Create an return a {@link TabPanel} widget with the first selected elements
- * by using a {@link TabPanelOptions}
+ * by using a {@link TabPanelOptions}. The <code>initFunctions</code> will be
+ * called on each new {@link Button} created by passing them in parameter.
*/
- TabPanel tabPanel(TabPanelOptions o);
+ TabPanel tabPanel(TabPanelOptions o, Function... initFunctions);
/**
* Create {@link TabPanel} widget for each selected elements. Each div element
* will create a tab and the first h3 element inside the div will be used as
* title
*/
- LazyWidgets<T> tabPanels();
+ LazyWidgets<T> tabPanels(Function... initFunctions);
/**
* 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> tabPanels(TabPanelOptions o);
+ LazyWidgets<T> tabPanels(TabPanelOptions o, Function... initFunctions);
/**
* Create an return a {@link Button} widget with the first element of the
- * query
+ * query.The <code>initFunctions</code> will be called on the new
+ * {@link Button} created by passing it in parameter.
+ *
*/
- Button button();
+ Button button(Function... initFunctions);
/**
- * Create and return a {@link Button} widget with the first element of the
- * query by using a {@link ButtonOptions}
+ * Create a {@link Button} widget for each selected element. The
+ * <code>initFunctions</code> will be called on each new {@link Button}
+ * created by passing them in parameter.
+ *
*/
- Button button(ButtonOptions o);
+ LazyWidgets<T> buttons(Function... initFunctions);
/**
- * Create a {@link Button} widget for each selected element.
+ * Create an return a {@link TextBox} widget with the first element of the
+ * query.The <code>initFunctions</code> will be called on the new
+ * {@link TextBox} created by passing it 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> buttons();
+ TextBox textBox(Function... initFunctions);
/**
- * Create a {@link Button} widget for each selected element by using a
- * {@link ButtonOptions}
- *
+ * Create a {@link TextBox} widget for each selected element. The
+ * <code>initFunctions</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> buttons(ButtonOptions o);
+ LazyWidgets<T> textBoxes(Function... initFunctions);
/**
* Create and return a widget using the given factory and the given options
*/
- <W extends Widget, O extends WidgetOptions> W widget( WidgetFactory<W, O> factory, O options);
+ <W extends Widget> W widget(WidgetFactory<W> factory, Function... initFunctions);
/**
* 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, O extends WidgetOptions> LazyWidgets<T> widgets( WidgetFactory<W, O> factory, O options);
+ <W extends Widget> LazyWidgets<T> widgets(WidgetFactory<W> factory, Function... initFunctions);
}
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 49848cdb..13aaefb0 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
@@ -16,23 +16,25 @@
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.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.WidgetOptions;
-import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory.ButtonOptions;
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.TabPanel;
+import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import java.util.ArrayList;
import java.util.List;
/**
- * Widgets plugin for Gwt Query.
- * Be careful, this plugin is still experimental. The api can change in next releases.
+ * Widgets plugin for Gwt Query. Be careful, this plugin is still experimental.
+ * The api can change in next releases.
*/
public class Widgets extends QueuePlugin<Widgets> {
@@ -53,18 +55,21 @@ public class Widgets extends QueuePlugin<Widgets> {
/**
* Create an return a {@link TabPanel} widget with the first selected
* elements. Each div element will create a tab and the first h3 element
- * inside the div will be used as title
+ * inside the div will be used as title. The <code>initFunctions</code> will
+ * be called on the new {@link TabPanel} created by passing it in parameter.
+ *
*/
- public TabPanel tabPanel() {
+ public TabPanel tabPanel(Function... initFunctions) {
return tabPanel(new TabPanelOptions());
}
/**
* Create an return a {@link TabPanel} widget with the first selected elements
- * by using a {@link TabPanelOptions}
+ * by using a {@link TabPanelOptions}. The <code>initFunctions</code> will be
+ * called on each new {@link Button} created by passing them in parameter.
*/
- public TabPanel tabPanel(TabPanelOptions o) {
- return widget(new TabPanelWidgetFactory(), o);
+ public TabPanel tabPanel(TabPanelOptions o, Function... initFunctions) {
+ return widget(new TabPanelWidgetFactory(o), initFunctions);
}
/**
@@ -72,8 +77,8 @@ public class Widgets extends QueuePlugin<Widgets> {
* will create a tab and the first h3 element inside the div will be used as
* title
*/
- public Widgets tabPanels() {
- return tabPanels(new TabPanelOptions());
+ public Widgets tabPanels(Function... initFunctions) {
+ return tabPanels(new TabPanelOptions(), initFunctions);
}
/**
@@ -81,49 +86,61 @@ public class Widgets extends QueuePlugin<Widgets> {
* element inside a selected element will create a tab and the first h3
* element inside the div will be used as title
*/
- public Widgets tabPanels(TabPanelOptions o) {
- return widgets(new TabPanelWidgetFactory(), o);
+ public Widgets tabPanels(TabPanelOptions o, Function... initFunctions) {
+ return widgets(new TabPanelWidgetFactory(o), initFunctions);
}
/**
* Create an return a {@link Button} widget with the first element of the
- * query
+ * query.The <code>initFunctions</code> will be called on the new
+ * {@link Button} created by passing it in parameter.
+ *
*/
- public Button button() {
- return button(new ButtonOptions());
+ public Button button(Function... initFunctions) {
+ return widget(new ButtonWidgetFactory(), initFunctions);
}
/**
- * Create and return a {@link Button} widget with the first element of the
- * query by using a {@link ButtonOptions}
+ * Create a {@link Button} widget for each selected element. The
+ * <code>initFunctions</code> will be called on each new {@link Button}
+ * created by passing them in parameter.
+ *
*/
- public Button button(ButtonOptions o) {
- return widget(new ButtonWidgetFactory(), o);
+ public Widgets buttons(Function... initFunctions) {
+ return widgets(new ButtonWidgetFactory(), initFunctions);
}
/**
- * Create a {@link Button} widget for each selected element.
+ * Create an return a {@link TextBox} widget with the first element of the
+ * query.The <code>initFunctions</code> will be called on the new
+ * {@link TextBox} created by passing it 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.
*/
- public Widgets buttons() {
- return buttons(new ButtonOptions());
+ public TextBox textBox(Function... initFunctions) {
+ return widget(new TextBoxWidgetFactory(), initFunctions);
}
/**
- * Create a {@link Button} widget for each selected element by using a
- * {@link ButtonOptions}
- *
+ * Create a {@link TextBox} widget for each selected element. The
+ * <code>initFunctions</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.
*/
- public Widgets buttons(ButtonOptions o) {
- return widgets(new ButtonWidgetFactory(), o);
+ public Widgets textBoxes(Function... initFunctions) {
+ return widgets(new TextBoxWidgetFactory(), initFunctions);
}
/**
* Create and return a widget using the given factory and the given options
*/
- public <W extends Widget, O extends WidgetOptions> W widget(
- WidgetFactory<W, O> factory, O options) {
- return widget(get(0), factory, options);
+ public <W extends Widget> W widget(WidgetFactory<W> factory,
+ Function... initFunctions) {
+
+ return widget(get(0), factory, initFunctions);
}
/**
@@ -131,12 +148,15 @@ public class Widgets extends QueuePlugin<Widgets> {
* each element of the query. Returns a new gquery set of elements with the
* new widgets created.
*/
- public <W extends Widget, O extends WidgetOptions> Widgets widgets(
- WidgetFactory<W, O> factory, O options) {
+ public <W extends Widget> Widgets widgets(WidgetFactory<W> factory,
+ Function... initFunctions) {
+
List<Element> result = new ArrayList<Element>();
+
for (Element e : elements()) {
- result.add(widget(e, factory, options).getElement());
+ result.add(widget(e, factory, initFunctions).getElement());
}
+
return $(result).as(Widgets);
}
@@ -144,8 +164,18 @@ public class Widgets extends QueuePlugin<Widgets> {
* Create and return a widget using the given factory and the given options
*/
protected <W extends Widget, O extends WidgetOptions> W widget(Element e,
- WidgetFactory<W, O> factory, O options) {
- return factory.create(e, options);
+ WidgetFactory<W> factory, Function... initFunctions) {
+
+ W widget = factory.create(e);
+
+ if (initFunctions != null) {
+ for (Function initFunction : initFunctions) {
+ initFunction.f(widget);
+ }
+ }
+
+ return widget;
+
}
}
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
index 9cafbe22..f0482857 100644
--- 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
@@ -3,64 +3,25 @@ package com.google.gwt.query.client.plugins.widgets;
import com.google.gwt.dom.client.ButtonElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
-import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* 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 extends
- AbstractWidgetFactory<Button, ButtonWidgetFactory.ButtonOptions> {
-
- /**
- * Options used to initialize new {@link Button}
- *
- */
- public static class ButtonOptions implements WidgetOptions {
-
- private List<ClickHandler> clickHandlers;
-
- public ButtonOptions() {
- clickHandlers = new ArrayList<ClickHandler>();
- }
-
- public void addClickHandler(ClickHandler clickHandler) {
- clickHandlers.add(clickHandler);
- }
-
- public List<ClickHandler> getClickHandlers() {
- return clickHandlers;
- }
- }
-
- protected void initialize(Button button, ButtonOptions options, Element e) {
- if (button == null || options == null) {
- return;
- }
-
- for (ClickHandler handler : options.getClickHandlers()) {
- button.addClickHandler(handler);
- }
-
- }
+public class ButtonWidgetFactory implements WidgetFactory<Button> {
- protected Button createWidget(Element e) {
+ public Button create(Element e) {
if ("button".equalsIgnoreCase(e.getTagName())) {
return Button.wrap(e);
}
- if (matchesTags(e, "div", "span", "a")) {
+ if (WidgetsUtils.matchesTags(e, "div", "span", "a")) {
ButtonElement buttonElement = Document.get().createPushButtonElement();
- e.getParentElement().insertAfter(buttonElement, e);
- // detach the original element (can be maybe hidden instead of detach
- // it?)
- e.removeFromParent();
+
+ WidgetsUtils.replace(e, buttonElement);
Button b = Button.wrap(buttonElement);
b.setHTML(e.getInnerHTML()); // maybe use setText and getInnerText
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..ce28bada
--- /dev/null
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/PasswordTextBoxWidgetFactory.java
@@ -0,0 +1,40 @@
+package com.google.gwt.query.client.plugins.widgets;
+
+import static com.google.gwt.query.client.GQuery.$;
+
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.InputElement;
+import com.google.gwt.query.client.GQuery;
+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 implements WidgetFactory<PasswordTextBox> {
+
+ public PasswordTextBox create(Element e) {
+
+ GQuery input = $(e).filter("input[type='passowrd']");
+
+ if (input.get(0) != null) {
+ return PasswordTextBox.wrap(e);
+ }
+
+ if (WidgetsUtils.matchesTags(e, "div", "span")) {
+ InputElement inputElement = Document.get().createPasswordInputElement();
+
+ WidgetsUtils.replace(e, inputElement);
+
+
+ PasswordTextBox textBox = PasswordTextBox.wrap(inputElement);
+ textBox.setValue(e.getInnerText()); // maybe use setText and getInnerText
+
+ return textBox;
+ }
+
+ return null;
+ }
+} \ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TabPanelWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TabPanelWidgetFactory.java
index 9fafebbc..928a5486 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TabPanelWidgetFactory.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TabPanelWidgetFactory.java
@@ -9,23 +9,13 @@ import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TabPanel;
-
/**
* 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 TabPanelWidgetFactory extends
- AbstractWidgetFactory<TabPanel, TabPanelWidgetFactory.TabPanelOptions> {
-
- public static class ExtendedTabPanel extends TabPanel{
-
-
- void attach(){
- onAttach();
- RootPanel.detachOnWindowClose(this);
- }
- }
+public class TabPanelWidgetFactory implements WidgetFactory<TabPanel> {
+
/**
* Options used to initialize new {@link Button}
@@ -61,8 +51,31 @@ public class TabPanelWidgetFactory extends
titleSelector = "h3";
}
}
+
+ private static class ExtendedTabPanel extends TabPanel {
+
+ void attach() {
+ onAttach();
+ RootPanel.detachOnWindowClose(this);
+ }
+ }
+
+ private TabPanelOptions options;
+
+ public TabPanelWidgetFactory(TabPanelOptions o) {
+ this.options = o;
+ }
+
+ public TabPanel create(Element e) {
+ ExtendedTabPanel tabPanel = new ExtendedTabPanel();
+
+ initialize(tabPanel, options, e);
+
+ return tabPanel;
+ }
+
- protected void initialize(TabPanel tabPanel, TabPanelOptions options,
+ protected void initialize(ExtendedTabPanel tabPanel, TabPanelOptions options,
Element e) {
GQuery tabs = $(options.getTabSelector(), e);
@@ -74,24 +87,15 @@ public class TabPanelWidgetFactory extends
tabPanel.add(new HTMLPanel(tab.getString()), title != null
? title.getInnerText() : "Tab " + (i + 1));
-
-
}
-
- if (tabs.length() > 0){
+
+ if (tabs.length() > 0) {
tabPanel.selectTab(0);
}
- // the tab panel is initialized, attach it to the dom ;
- e.getParentElement().insertBefore(tabPanel.getElement(), e);
- ((ExtendedTabPanel)tabPanel).attach();
-
- // detach the element as it is replaced by the tab panel !
- e.removeFromParent();
- }
+ WidgetsUtils.replace(e, tabPanel.getElement());
- protected TabPanel createWidget(Element e) {
- return new ExtendedTabPanel();
+ tabPanel.attach();
}
}
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..3efc5d82
--- /dev/null
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxWidgetFactory.java
@@ -0,0 +1,39 @@
+package com.google.gwt.query.client.plugins.widgets;
+
+import static com.google.gwt.query.client.GQuery.$;
+
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.InputElement;
+import com.google.gwt.query.client.GQuery;
+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 implements WidgetFactory<TextBox> {
+
+ public TextBox create(Element e) {
+
+ GQuery input = $(e).filter("input[type='text']");
+
+ if (input.get(0) != null) {
+ return TextBox.wrap(e);
+ }
+
+ if (WidgetsUtils.matchesTags(e, "div", "span")) {
+ InputElement inputElement = Document.get().createTextInputElement();
+
+ WidgetsUtils.replace(e, inputElement);
+
+ TextBox textBox = TextBox.wrap(inputElement);
+ textBox.setValue(e.getInnerText()); // maybe use setText and getInnerText
+
+ return textBox;
+ }
+
+ return null;
+ }
+} \ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetFactory.java
index 41c23ed5..9b434fdf 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetFactory.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetFactory.java
@@ -9,6 +9,6 @@ import com.google.gwt.user.client.ui.Widget;
* @param <W>
* @param <O>
*/
- public interface WidgetFactory<W extends Widget, O extends WidgetOptions> {
- public W create(Element e, O options);
+ public interface WidgetFactory<W extends Widget> {
+ public W create(Element e);
} \ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/AbstractWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java
index 928301e1..360afcff 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/AbstractWidgetFactory.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java
@@ -1,26 +1,9 @@
package com.google.gwt.query.client.plugins.widgets;
import com.google.gwt.dom.client.Element;
-import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.query.client.GQuery;
-/**
- * Abstract factory containing useful methods for widget creation
- *
- */
-public abstract class AbstractWidgetFactory<W extends Widget, O extends WidgetOptions>
- implements WidgetFactory<W, O> {
-
- public W create(Element e, O options) {
- W w = createWidget(e);
-
- initialize(w, options, e);
-
- return w;
- }
-
- protected abstract void initialize(W widget, O options, Element e);
-
- protected abstract W createWidget(Element e);
+public class WidgetsUtils {
/**
* Test if the tag name of the element is one of tag names given in parameter
@@ -28,7 +11,7 @@ public abstract class AbstractWidgetFactory<W extends Widget, O extends WidgetOp
* @param tagNames
* @return
*/
- protected boolean matchesTags(Element e, String... tagNames) {
+ static boolean matchesTags(Element e, String... tagNames) {
assert e != null : "Element cannot be null";
@@ -46,4 +29,16 @@ public abstract class AbstractWidgetFactory<W extends Widget, O extends WidgetOp
}
-} \ No newline at end of file
+ /**
+ * replace the <code>oldElement</code> by the <code>newElement</code>
+ *
+ * @param oldElement
+ * @param newElement
+ */
+ static void replace(Element oldElement, Element newElement) {
+ assert oldElement != null && newElement != null;
+
+ GQuery.$(oldElement).replaceWith(newElement);
+
+ }
+}
diff --git a/samples/src/main/java/gwtquery/samples/client/GwtQueryWidgetModule.java b/samples/src/main/java/gwtquery/samples/client/GwtQueryWidgetModule.java
index e2bb19dc..cff828dd 100644
--- a/samples/src/main/java/gwtquery/samples/client/GwtQueryWidgetModule.java
+++ b/samples/src/main/java/gwtquery/samples/client/GwtQueryWidgetModule.java
@@ -22,94 +22,42 @@ import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.query.client.Function;
-import com.google.gwt.query.client.GQuery;
-import com.google.gwt.query.client.css.CSS;
-import com.google.gwt.query.client.css.Length;
-import com.google.gwt.query.client.css.RGBColor;
-import com.google.gwt.query.client.css.UriValue;
-import com.google.gwt.query.client.css.BackgroundAttachmentProperty.BackgroundAttachment;
-import com.google.gwt.query.client.css.BackgroundPositionProperty.BackgroundPosition;
-import com.google.gwt.query.client.css.BackgroundRepeatProperty.BackgroundRepeat;
-import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory.ButtonOptions;
-import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
+import com.google.gwt.user.client.ui.Widget;
public class GwtQueryWidgetModule implements EntryPoint {
-/* public void onModuleLoad() {
- $("<button>Enhance</button>").appendTo(".outer").one(Event.ONCLICK, null, new Function() {
- public boolean f(Event e) {
- $(".btn:nth-child(odd)").each(new Function(){
- public void f(Element el) {
- // Replace odd labels by a button
- GQuery g = $("<button/>");
- $(el).hide().after(g);
-
- // Use the Widgets plugin to convert the button element to a button.
- Button b = g.as(Widgets.Widgets).widget();
- b.setText("Foo");
- b.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent clickEvent) {
- Window.alert("You Clicked the Button");
- }
- });
- }
- });
- return true;
- }
- });
- }*/
-
public void onModuleLoad() {
+
+ $(".inputText").as(Widgets).textBoxes();
-
- // Let gquery syntax to help gwt developers.
- GQuery buttons = $(".btn").as(Widgets).buttons().click(new Function() {
- public void f() {
- Label l = new Label("You click on a GWT Button !");
- PopupPanel panel = new PopupPanel(true, true);
- panel.setGlassEnabled(true);
- panel.add(l);
- panel.center();
- }
- });
-
- // The user use a widget in the traditional way
- buttons.eq(0).<Button>widget().addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- Window.alert("You clicked in the first button");
- }
- });
-
- $("#tabs").as(Widgets).tabPanel();
-
- // IDE suggestions are not available with this syntax. -> I agree
- // Also it implies that the css method in GQuery needs more overloads
- // $("#aaa").css(CSS.POSITION, Position.ABSOLUTE);
- // $("#aaa").css(CSS.TOP, Length.cm(15));
- // $("#aaa").css(CSS.BACKGROUND, RGBColor.RED, ImageValue.url(""), BackgroundRepeat.NO_REPEAT, BackgroundAttachment.FIXED, BackgroundPosition.CENTER);
-
- $("#aaa").css(CSS.TOP.with(Length.cm(15)));
- $("#aaa").css(CSS.BACKGROUND.with(RGBColor.SILVER, UriValue.url(""), BackgroundRepeat.NO_REPEAT, BackgroundAttachment.FIXED, BackgroundPosition.CENTER));
- $("#aaa").css(CSS.BACKGROUND_ATTACHMENT.with(BackgroundAttachment.FIXED));
- }
-
- private ButtonOptions createButtonOptions(){
- ButtonOptions options = new ButtonOptions();
- options.addClickHandler(new ClickHandler() {
+ $(".btn").as(Widgets).buttons(new Function() {
- public void onClick(ClickEvent event) {
- Label l = new Label("You click on a GWT Button !");
- PopupPanel panel = new PopupPanel(true, true);
- panel.setGlassEnabled(true);
- panel.add(l);
- panel.center();
+ public void f(Widget w) {
+ Button button = (Button) w;
+ button.addClickHandler(new ClickHandler() {
+
+ public void onClick(ClickEvent event) {
+ Label l = new Label("You click on a GWT Button !");
+ PopupPanel panel = new PopupPanel(true, true);
+ panel.setGlassEnabled(true);
+ panel.add(l);
+ panel.center();
+
+ }
+ });
+
}
+
});
+
+ $("#tabs").as(Widgets).tabPanel();
- return options;
+
+
}
+
}
diff --git a/samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html b/samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html
index 0b189ab4..8e95b165 100644
--- a/samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html
+++ b/samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html
@@ -5,7 +5,7 @@
src="gwtquery.samples.GwtQueryWidgets.nocache.js"></script>
</head>
<body>
-<div id='aaa'>aaa</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
@@ -15,6 +15,10 @@ a button 3!</span>
<div class="btn">Make me a button 6!</div>
</div>
+<div class="inputText">I will be an Input</div>
+<span class="inputText">I will be an Input</span>
+<input class="inputText" type="text"></input>
+
<div id="tabs">
<h3>First tab</h3>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut