You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GwtQueryWidgetModule.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright 2011, The gwtquery team.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package gwtquery.samples.client;
  17. import static com.google.gwt.query.client.GQuery.$;
  18. import static com.google.gwt.query.client.plugins.widgets.Widgets.Widgets;
  19. import com.google.gwt.core.client.EntryPoint;
  20. import com.google.gwt.event.dom.client.ClickEvent;
  21. import com.google.gwt.event.dom.client.ClickHandler;
  22. import com.google.gwt.query.client.Function;
  23. import com.google.gwt.query.client.GQuery;
  24. import com.google.gwt.query.client.css.CSS;
  25. import com.google.gwt.query.client.css.UriValue;
  26. import com.google.gwt.query.client.css.Length;
  27. import com.google.gwt.query.client.css.RGBColor;
  28. import com.google.gwt.query.client.css.BackgroundAttachmentProperty.BackgroundAttachment;
  29. import com.google.gwt.query.client.css.BackgroundPositionProperty.BackgroundPosition;
  30. import com.google.gwt.query.client.css.BackgroundRepeatProperty.BackgroundRepeat;
  31. import com.google.gwt.query.client.plugins.widgets.widgetfactory.ButtonWidgetFactory.ButtonOptions;
  32. import com.google.gwt.user.client.Window;
  33. import com.google.gwt.user.client.ui.Button;
  34. import com.google.gwt.user.client.ui.Label;
  35. import com.google.gwt.user.client.ui.PopupPanel;
  36. public class GwtQueryWidgetModule implements EntryPoint {
  37. /* public void onModuleLoad() {
  38. $("<button>Enhance</button>").appendTo(".outer").one(Event.ONCLICK, null, new Function() {
  39. public boolean f(Event e) {
  40. $(".btn:nth-child(odd)").each(new Function(){
  41. public void f(Element el) {
  42. // Replace odd labels by a button
  43. GQuery g = $("<button/>");
  44. $(el).hide().after(g);
  45. // Use the Widgets plugin to convert the button element to a button.
  46. Button b = g.as(Widgets.Widgets).widget();
  47. b.setText("Foo");
  48. b.addClickHandler(new ClickHandler() {
  49. public void onClick(ClickEvent clickEvent) {
  50. Window.alert("You Clicked the Button");
  51. }
  52. });
  53. }
  54. });
  55. return true;
  56. }
  57. });
  58. }*/
  59. public void onModuleLoad() {
  60. // Let gquery syntax to help gwt developers.
  61. GQuery buttons = $(".btn").as(Widgets).buttons().click(new Function() {
  62. public void f() {
  63. Label l = new Label("You click on a GWT Button !");
  64. PopupPanel panel = new PopupPanel(true, true);
  65. panel.setGlassEnabled(true);
  66. panel.add(l);
  67. panel.center();
  68. }
  69. });
  70. // The user use a widget in the traditional way
  71. buttons.eq(0).<Button>widget().addClickHandler(new ClickHandler() {
  72. public void onClick(ClickEvent event) {
  73. Window.alert("You clicked in the first button");
  74. }
  75. });
  76. $("#tabs").as(Widgets).tabPanel();
  77. // IDE suggestions are not available with this syntax. -> I agree
  78. // Also it implies that the css method in GQuery needs more overloads
  79. // $("#aaa").css(CSS.POSITION, Position.ABSOLUTE);
  80. // $("#aaa").css(CSS.TOP, Length.cm(15));
  81. // $("#aaa").css(CSS.BACKGROUND, RGBColor.RED, ImageValue.url(""), BackgroundRepeat.NO_REPEAT, BackgroundAttachment.FIXED, BackgroundPosition.CENTER);
  82. $("#aaa").css(CSS.TOP.with(Length.cm(15)));
  83. $("#aaa").css(CSS.BACKGROUND.with(RGBColor.SILVER, UriValue.url(""), BackgroundRepeat.NO_REPEAT, BackgroundAttachment.FIXED, BackgroundPosition.CENTER));
  84. $("#aaa").css(CSS.BACKGROUND_ATTACHMENT.with(BackgroundAttachment.FIXED));
  85. }
  86. private ButtonOptions createButtonOptions(){
  87. ButtonOptions options = new ButtonOptions();
  88. options.addClickHandler(new ClickHandler() {
  89. public void onClick(ClickEvent event) {
  90. Label l = new Label("You click on a GWT Button !");
  91. PopupPanel panel = new PopupPanel(true, true);
  92. panel.setGlassEnabled(true);
  93. panel.add(l);
  94. panel.center();
  95. }
  96. });
  97. return options;
  98. }
  99. }