import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.HasCssName;
+import com.google.gwt.query.client.Properties;
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;
private String notNull(HasCssName value) {
return value != null ? value.getCssName() + " " : "";
}
+
+ public Properties with(RGBColor backgroundColor,
+ ImageValue backgroundImage, BackgroundRepeat backgroundRepeat,
+ BackgroundAttachment backgroundAttachment,
+ BackgroundPosition backgroundPosition) {
+ String s = getCssName() + ": \""
+ + notNull(backgroundColor) + notNull(backgroundImage)
+ + notNull(backgroundRepeat) + notNull(backgroundAttachment)
+ + notNull(backgroundPosition).trim() + "\"";
+ return Properties.create(s);
+ }
}
\r
/**\r
* Try to create a widget using the given factory and the given options for\r
- * each element of the query\r
+ * each element of the query.\r
+ * Returns a new gquery set of elements with the new widgets created.\r
*/\r
public <W extends Widget, O extends WidgetOptions> Widgets widgets(\r
WidgetFactory<W, O> factory, O options) {\r
+ JSArray result = JSArray.create();\r
for (Element e : elements()) {\r
- widget(e, factory, options);\r
+ result.addNode(widget(e, factory, options).getElement());\r
}\r
- return this;\r
+ return new Widgets(result);\r
}\r
\r
/**\r
import static com.google.gwt.query.client.plugins.widgets.Widgets.Widgets;\r
\r
import com.google.gwt.core.client.EntryPoint;\r
+import com.google.gwt.dom.client.Style.Position;\r
import com.google.gwt.event.dom.client.ClickEvent;\r
import com.google.gwt.event.dom.client.ClickHandler;\r
+import com.google.gwt.query.client.Function;\r
+import com.google.gwt.query.client.GQuery;\r
+import com.google.gwt.query.client.css.BackgroundAttachmentProperty.BackgroundAttachment;\r
+import com.google.gwt.query.client.css.BackgroundPositionProperty.BackgroundPosition;\r
+import com.google.gwt.query.client.css.BackgroundRepeatProperty.BackgroundRepeat;\r
+import com.google.gwt.query.client.css.CSS;\r
+import com.google.gwt.query.client.css.ImageValue;\r
+import com.google.gwt.query.client.css.Length;\r
+import com.google.gwt.query.client.css.RGBColor;\r
import com.google.gwt.query.client.plugins.widgets.widgetfactory.ButtonWidgetFactory.ButtonOptions;\r
+import com.google.gwt.user.client.Window;\r
+import com.google.gwt.user.client.ui.Button;\r
import com.google.gwt.user.client.ui.Label;\r
import com.google.gwt.user.client.ui.PopupPanel;\r
\r
}*/\r
\r
public void onModuleLoad() {\r
- \r
\r
- $(".btn").as(Widgets).buttons(createButtonOptions());\r
+ \r
+ // Let gquery syntax to help gwt developers. \r
+ GQuery buttons = $(".btn").as(Widgets).buttons().click(new Function() {\r
+ public void f() {\r
+ Label l = new Label("You click on a GWT Button !");\r
+ PopupPanel panel = new PopupPanel(true, true);\r
+ panel.setGlassEnabled(true);\r
+ panel.add(l);\r
+ panel.center();\r
+ }\r
+ });\r
+ \r
+ // The user use a widget in the traditional way\r
+ buttons.eq(0).<Button>widget().addClickHandler(new ClickHandler() {\r
+ public void onClick(ClickEvent event) {\r
+ Window.alert("You clicked in the first button");\r
+ }\r
+ });\r
+ \r
$("#tabs").as(Widgets).tabPanel();\r
\r
+ // IDE suggestions are not available with this syntax. \r
+ // Also it implies that the css method in GQuery needs more overloads\r
+ $("#aaa").css(CSS.POSITION, Position.ABSOLUTE);\r
+ $("#aaa").css(CSS.TOP, Length.cm(15));\r
+ $("#aaa").css(CSS.BACKGROUND, RGBColor.RED, ImageValue.url(""), BackgroundRepeat.NO_REPEAT, BackgroundAttachment.FIXED, BackgroundPosition.CENTER);\r
+ \r
+ // With this syntax IDE gives more help\r
+ // We could overload the with method in each CssProperty without adding more methods to GQuery\r
+ $("#aaa").css(CSS.TOP.with(Length.cm(15)));\r
+ $("#aaa").css(CSS.BACKGROUND.with(RGBColor.SILVER, ImageValue.url(""), BackgroundRepeat.NO_REPEAT, BackgroundAttachment.FIXED, BackgroundPosition.CENTER)); \r
}\r
\r
private ButtonOptions createButtonOptions(){\r