]> source.dussan.org Git - gwtquery.git/commitdiff
proof of concept
authorManolo Carrasco <manolo@apache.org>
Wed, 23 Feb 2011 08:05:48 +0000 (08:05 +0000)
committerManolo Carrasco <manolo@apache.org>
Wed, 23 Feb 2011 08:05:48 +0000 (08:05 +0000)
gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java
gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundProperty.java
gwtquery-core/src/main/java/com/google/gwt/query/client/css/EdgePositionProperty.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/Widgets.java
samples/src/main/java/gwtquery/samples/client/GwtQueryWidgetModule.java
samples/src/main/java/gwtquery/samples/public/GwtQueryWidgets.html

index 178deabb44053063de139219f4f7468d96b04193..fd33077eec8ffb1bf655f723fba80aabb6a67d21 100644 (file)
@@ -34,7 +34,9 @@ public class Properties extends JavaScriptObject {
     }-*/;\r
 \r
   protected static String wrapPropertiesString(String s) {\r
-    return "({" + s.replaceFirst("^[({]+", "").replaceFirst("[})]+$", "") + "})";\r
+    String ret = "({" + s.replaceFirst("^[({]+", "").replaceFirst("[})]+$", "") + "})";\r
+    System.out.println("\n" + s + "\n" + ret);\r
+    return ret;\r
   }\r
 \r
   protected Properties() {\r
index b1d3cd1c908ae78e9e6e9482bb64f386175b5d13..1e562e03205d0436a1b20bd730860300c91fa93b 100644 (file)
@@ -17,6 +17,7 @@ package com.google.gwt.query.client.css;
 
 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;
@@ -70,5 +71,16 @@ public class BackgroundProperty
   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);
+  }
 
 }
index 392e9d4c95e2aada5e70a3154520759b348b1fce..965c2a8059f308f0217a41d612b1e4dd7029ddf9 100644 (file)
@@ -15,6 +15,8 @@
  */
 package com.google.gwt.query.client.css;
 
+import com.google.gwt.query.client.Properties;
+
 /**
  * Specify position of element's edges.
  */
@@ -30,4 +32,8 @@ public class EdgePositionProperty extends AbstractCssProperty<Length> {
   private EdgePositionProperty(String value) {
     super(value);
   }
+  
+  public Properties with(Length value) {
+    return Properties.create(getCssName() + ":'" + value.getCssName() + "'");
+  }
 }
index a03857497b6c60c0b4384895d708357c4a7bb306..d71f5d977d74285a501e4c031e2846ab66909a2b 100755 (executable)
@@ -141,14 +141,16 @@ public class Widgets extends GQueryQueue<Widgets> {
 \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
index 65bb2e7c8f329cfb6f2ff8ff8c489c53760cb000..3ce6f9b342d0733879ff059c8a28e3031cc3ac0c 100644 (file)
@@ -19,9 +19,21 @@ import static com.google.gwt.query.client.GQuery.$;
 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
@@ -52,11 +64,38 @@ public class GwtQueryWidgetModule implements EntryPoint {
   }*/\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
index 535eb08ed9f99659a7df8b3d42cfe63a173e8806..0b189ab4cb9e16ca17d07849646a9cfc7eb457d4 100644 (file)
@@ -5,6 +5,7 @@
     src="gwtquery.samples.GwtQueryWidgets.nocache.js"></script>\r
 </head>\r
 <body>\r
+<div id='aaa'>aaa</div>\r
 <div class="outer">\r
 <div class="btn">Make me a button 1!</div>\r
 <a class="btn">Make me a button 2!</a> <span class="btn">Make me\r