diff options
12 files changed, 274 insertions, 35 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 467cb6c7..d2e4857b 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 @@ -17,10 +17,12 @@ package com.google.gwt.query.client.plugins; 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.CheckBoxWidgetFactory; import com.google.gwt.query.client.plugins.widgets.DateBoxWidgetFactory; import com.google.gwt.query.client.plugins.widgets.DisclosurePanelWidgetFactory; import com.google.gwt.query.client.plugins.widgets.ListBoxWidgetFactory; import com.google.gwt.query.client.plugins.widgets.PasswordTextBoxWidgetFactory; +import com.google.gwt.query.client.plugins.widgets.RadioButtonWidgetFactory; import com.google.gwt.query.client.plugins.widgets.StackPanelWidgetFactory; import com.google.gwt.query.client.plugins.widgets.SuggestBoxWidgetFactory; import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory; @@ -31,13 +33,16 @@ import com.google.gwt.query.client.plugins.widgets.WidgetInitializer; import com.google.gwt.query.client.plugins.widgets.WidgetsUtils; 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.RadioButtonWidgetFactory.RadioButtonOption; import com.google.gwt.query.client.plugins.widgets.StackPanelWidgetFactory.StackPanelOptions; import com.google.gwt.query.client.plugins.widgets.SuggestBoxWidgetFactory.SuggestBoxOptions; 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.CheckBox; 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.RadioButton; import com.google.gwt.user.client.ui.StackPanel; import com.google.gwt.user.client.ui.SuggestBox; import com.google.gwt.user.client.ui.TabPanel; @@ -135,6 +140,16 @@ public interface LazyWidgets<T> extends LazyBase<T>{ LazyWidgets<T> passwordBox(); /** + * Create a {@link CheckBox} widget for each selected element. + */ + LazyWidgets<T> checkBox(WidgetInitializer<CheckBox> initializers); + + /** + * Create a {@link CheckBox} widget for each selected element. + */ + LazyWidgets<T> checkBox(); + + /** * 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. @@ -171,6 +186,32 @@ public interface LazyWidgets<T> extends LazyBase<T>{ LazyWidgets<T> stackPanel(); /** + * Create {@link RadioButton} widget for each selected elements. All + * {@link RadioButton} created will be group under the same name specified in + * the {@link RadioButtonOption o} + */ + LazyWidgets<T> radioButton(RadioButtonOption o, WidgetInitializer<RadioButton> initializers); + + /** + * Create {@link RadioButton} widget for each selected elements. All + * {@link RadioButton} created will be group under the same name specified in + * the {@link RadioButtonOption o} + */ + LazyWidgets<T> radioButton(RadioButtonOption o); + + /** + * Create {@link RadioButton} widget for each selected elements. All + * {@link RadioButton} created will be group under the same name + */ + LazyWidgets<T> radioButton(WidgetInitializer<RadioButton> initializers); + + /** + * Create {@link RadioButton} widget for each selected elements. All + * {@link RadioButton} created will be group under the same name + */ + LazyWidgets<T> radioButton(); + + /** * Create a {@link SuggestBox} widget for each selected element. The * <code>initializers</code> will be called on each new {@link SuggestBox} * created by passing them in parameter. 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 9137cf73..2c001c0f 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 @@ -18,10 +18,12 @@ package com.google.gwt.query.client.plugins; 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.CheckBoxWidgetFactory;
import com.google.gwt.query.client.plugins.widgets.DateBoxWidgetFactory;
import com.google.gwt.query.client.plugins.widgets.DisclosurePanelWidgetFactory;
import com.google.gwt.query.client.plugins.widgets.ListBoxWidgetFactory;
import com.google.gwt.query.client.plugins.widgets.PasswordTextBoxWidgetFactory;
+import com.google.gwt.query.client.plugins.widgets.RadioButtonWidgetFactory;
import com.google.gwt.query.client.plugins.widgets.StackPanelWidgetFactory;
import com.google.gwt.query.client.plugins.widgets.SuggestBoxWidgetFactory;
import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory;
@@ -32,13 +34,16 @@ import com.google.gwt.query.client.plugins.widgets.WidgetInitializer; import com.google.gwt.query.client.plugins.widgets.WidgetsUtils;
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.RadioButtonWidgetFactory.RadioButtonOption;
import com.google.gwt.query.client.plugins.widgets.StackPanelWidgetFactory.StackPanelOptions;
import com.google.gwt.query.client.plugins.widgets.SuggestBoxWidgetFactory.SuggestBoxOptions;
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.CheckBox;
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.RadioButton;
import com.google.gwt.user.client.ui.StackPanel;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.TabPanel;
@@ -128,7 +133,7 @@ public class Widgets extends QueuePlugin<Widgets> { WidgetInitializer<DisclosurePanel> initializers) {
return widgets(new DisclosurePanelWidgetFactory(o), initializers);
}
-
+
/**
* Create a {@link DisclosurePanel} widget for each selected elements.
*/
@@ -153,7 +158,7 @@ public class Widgets extends QueuePlugin<Widgets> { WidgetInitializer<ListBox> initializers) {
return widgets(new ListBoxWidgetFactory(options), initializers);
}
-
+
/**
* Create a {@link ListBox} widget for each selected element. The
* <code>initializers</code> will be called on each new {@link ListBox}
@@ -188,6 +193,20 @@ public class Widgets extends QueuePlugin<Widgets> { }
/**
+ * Create a {@link CheckBox} widget for each selected element.
+ */
+ public Widgets checkBox(WidgetInitializer<CheckBox> initializers) {
+ return widgets(new CheckBoxWidgetFactory(), initializers);
+ }
+
+ /**
+ * Create a {@link CheckBox} widget for each selected element.
+ */
+ public Widgets checkBox() {
+ return widgets(new CheckBoxWidgetFactory(), 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.
@@ -211,7 +230,7 @@ public class Widgets extends QueuePlugin<Widgets> { WidgetInitializer<StackPanel> initializers) {
return widgets(new StackPanelWidgetFactory(o), initializers);
}
-
+
/**
* Create a {@link StackPanel} widget for each selected elements. Each div
* element inside a selected element will create a tab and the first h3
@@ -240,6 +259,41 @@ public class Widgets extends QueuePlugin<Widgets> { }
/**
+ * Create {@link RadioButton} widget for each selected elements. All
+ * {@link RadioButton} created will be group under the same name specified in
+ * the {@link RadioButtonOption o}
+ */
+ public Widgets radioButton(RadioButtonOption o,
+ WidgetInitializer<RadioButton> initializers) {
+ return widgets(new RadioButtonWidgetFactory(o), initializers);
+ }
+
+ /**
+ * Create {@link RadioButton} widget for each selected elements. All
+ * {@link RadioButton} created will be group under the same name specified in
+ * the {@link RadioButtonOption o}
+ */
+ public Widgets radioButton(RadioButtonOption o) {
+ return widgets(new RadioButtonWidgetFactory(o), null);
+ }
+
+ /**
+ * Create {@link RadioButton} widget for each selected elements. All
+ * {@link RadioButton} created will be group under the same name
+ */
+ public Widgets radioButton(WidgetInitializer<RadioButton> initializers) {
+ return radioButton(new RadioButtonOption(), initializers);
+ }
+
+ /**
+ * Create {@link RadioButton} widget for each selected elements. All
+ * {@link RadioButton} created will be group under the same name
+ */
+ public Widgets radioButton() {
+ return radioButton(new RadioButtonOption(), null);
+ }
+
+ /**
* Create a {@link SuggestBox} widget for each selected element. The
* <code>initializers</code> will be called on each new {@link SuggestBox}
* created by passing them in parameter.
@@ -249,7 +303,7 @@ public class Widgets extends QueuePlugin<Widgets> { WidgetInitializer<SuggestBox> initializers) {
return widgets(new SuggestBoxWidgetFactory(options), initializers);
}
-
+
/**
* Create a {@link SuggestBox} widget for each selected element. The
* <code>initializers</code> will be called on each new {@link SuggestBox}
@@ -286,7 +340,7 @@ public class Widgets extends QueuePlugin<Widgets> { WidgetInitializer<TabPanel> initializers) {
return widgets(new TabPanelWidgetFactory(o), 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
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/CheckBoxWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/CheckBoxWidgetFactory.java new file mode 100644 index 00000000..2debaae4 --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/CheckBoxWidgetFactory.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.InputElement; +import com.google.gwt.user.client.ui.CheckBox; + +/** + * + * + */ +public class CheckBoxWidgetFactory implements WidgetFactory<CheckBox> { + + public CheckBox create(Element e) { + + CheckBox checkBox = new CheckBox(e.getInnerText()); + if ("input".equalsIgnoreCase(e.getTagName())){ + copyAttributes((InputElement) e.cast(), (InputElement) checkBox.getElement().cast()); + } + WidgetsUtils.replaceOrAppend(e, checkBox); + return checkBox; + + } + + protected String getEquivalentTagName(){ + return "input"; + } + + protected void copyAttributes(InputElement source, InputElement destination) { + + destination.setAccessKey(source.getAccessKey()); + destination.setDisabled(source.isDisabled()); + destination.setSize(source.getSize()); + 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/DisclosurePanelWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/DisclosurePanelWidgetFactory.java index 48378a3d..e4e92f68 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/DisclosurePanelWidgetFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/DisclosurePanelWidgetFactory.java @@ -29,7 +29,7 @@ public class DisclosurePanelWidgetFactory implements * Options used to initialize new {@link Button} * */ - public static class DisclosurePanelOptions implements WidgetOptions { + public static class DisclosurePanelOptions { private String headerSelector; //private String headerTitle; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ListBoxWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ListBoxWidgetFactory.java index 87078344..75008816 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ListBoxWidgetFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ListBoxWidgetFactory.java @@ -32,7 +32,7 @@ public class ListBoxWidgetFactory implements WidgetFactory<ListBox> { * Options used to create a {@link ListBox} * */ - public static class ListBoxOptions implements WidgetOptions { + public static class ListBoxOptions { private String optionsSelector; private boolean multipleSelect; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/RadioButtonWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/RadioButtonWidgetFactory.java new file mode 100644 index 00000000..d30d489e --- /dev/null +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/RadioButtonWidgetFactory.java @@ -0,0 +1,103 @@ +/* + * 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.user.client.DOM; +import com.google.gwt.user.client.ui.RadioButton; + +/** + * + * + */ +public class RadioButtonWidgetFactory implements WidgetFactory<RadioButton> { + + public static class RadioButtonOption{ + + private String name; + + public RadioButtonOption() { + } + + public RadioButtonOption(String name){ + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + } + + private RadioButtonOption option; + private String radioName; + + public RadioButtonWidgetFactory(RadioButtonOption option) { + this.option = option; + } + + + public RadioButton create(Element e) { + resolveName(e); + + RadioButton radioButton = new RadioButton(radioName); + if ("input".equalsIgnoreCase(e.getTagName())){ + copyAttributes((InputElement) e, (InputElement) radioButton.getElement().cast()); + }else{ + radioButton.setText(e.getInnerText()); + } + + WidgetsUtils.replaceOrAppend(e, radioButton); + + return radioButton; + + } + + protected void resolveName(Element e) { + if (radioName != null){ + return; + } + if (option.getName() != null){ + radioName = option.getName(); + }else if ("input".equals(e.getTagName()) && "radio".equals(((InputElement)e).getType())){ + radioName = ((InputElement)e).getName(); + }else{ + //create an unique string via DOM.createUniqueId... + radioName = DOM.createUniqueId(); + } + } + + + protected String getEquivalentTagName(){ + return "input"; + } + + protected void copyAttributes(InputElement source, InputElement destination) { + + destination.setAccessKey(source.getAccessKey()); + destination.setDisabled(source.isDisabled()); + destination.setSize(source.getSize()); + 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/StackPanelWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/StackPanelWidgetFactory.java index 92d2794a..8172d2dc 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/StackPanelWidgetFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/StackPanelWidgetFactory.java @@ -30,7 +30,7 @@ public class StackPanelWidgetFactory implements WidgetFactory<StackPanel> { * Options used to initialize new {@link Button} * */ - public static class StackPanelOptions implements WidgetOptions { + public static class StackPanelOptions { private String headerSelector; private String contentSelector; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/SuggestBoxWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/SuggestBoxWidgetFactory.java index 12f11406..006f4e90 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/SuggestBoxWidgetFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/SuggestBoxWidgetFactory.java @@ -33,7 +33,7 @@ public class SuggestBoxWidgetFactory implements WidgetFactory<SuggestBox> { * Options used to create a {@link SuggestBox} * */ - public static class SuggestBoxOptions implements WidgetOptions { + public static class SuggestBoxOptions { private String suggestionsSelector; private SuggestOracle suggestOracle; 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 56219cc0..97009b2d 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 @@ -35,7 +35,7 @@ public class TabPanelWidgetFactory implements WidgetFactory<TabPanel> { * Options used to initialize new {@link Button} * */ - public static class TabPanelOptions implements WidgetOptions { + public static class TabPanelOptions { private String tabSelector; private String titleSelector; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetOptions.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetOptions.java deleted file mode 100644 index d5ca9aac..00000000 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetOptions.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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; - -/** - * Marker interface for factory options. All options should extend - * {@link WidgetOptions}. - * - */ -public interface WidgetOptions { - -}
\ No newline at end of file diff --git a/samples/src/main/java/gwtquery/samples/client/GwtQueryWidgetModule.java b/samples/src/main/java/gwtquery/samples/client/GwtQueryWidgetModule.java index 70c4aac1..83d0169d 100644 --- a/samples/src/main/java/gwtquery/samples/client/GwtQueryWidgetModule.java +++ b/samples/src/main/java/gwtquery/samples/client/GwtQueryWidgetModule.java @@ -82,6 +82,8 @@ public class GwtQueryWidgetModule implements EntryPoint { $("#suggestBox1").as(Widgets).suggestBox(new SuggestBoxOptions("div"));
$("#suggestBox2").as(Widgets).suggestBox(new SuggestBoxOptions("li"));
$(".stack").as(Widgets).stackPanel();
+ $(".checkBox").as(Widgets).checkBox();
+ $(".radio").as(Widgets).radioButton();
GWT.log("Found " + $(".btn").widgets().size() + " buttons widget");
diff --git a/samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html b/samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html index 1b15c341..0a6eb9d5 100644 --- a/samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html +++ b/samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html @@ -114,6 +114,18 @@ <li>suggestion y</li>
<li>suggestion z</li>
</ul>
+
+ <div class="outer">
+ <div class="checkBox">Checkbox</div>
+ <div class="checkBox">created</div>
+ <div class="checkBox">from div</div>
+ </div>
+
+ <div class="outer">
+ <div class="radio">RadioButton</div>
+ <div class="radio">created</div>
+ <div class="radio">from div</div>
+ </div>
</div>
|