Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Widgets.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2009 Google Inc.
  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 com.google.gwt.query.client.plugins;
  17. import com.google.gwt.dom.client.Element;
  18. import com.google.gwt.dom.client.NodeList;
  19. import com.google.gwt.query.client.GQuery;
  20. import com.google.gwt.query.client.JSArray;
  21. import com.google.gwt.query.client.Plugin;
  22. import com.google.gwt.user.client.ui.Button;
  23. import com.google.gwt.user.client.ui.HTML;
  24. import com.google.gwt.user.client.ui.TextBox;
  25. import com.google.gwt.user.client.ui.Widget;
  26. /**
  27. * Widgets plugin for Gwt Query.
  28. */
  29. public class Widgets extends GQueryQueue<Widgets> {
  30. public static final Class<Widgets> Widgets = Widgets.class;
  31. static {
  32. GQuery.registerPlugin(Widgets.class, new Plugin<Widgets>() {
  33. public Widgets init(GQuery gq) {
  34. return new Widgets(gq);
  35. }
  36. });
  37. }
  38. public Widgets(final Element element) {
  39. super(element);
  40. }
  41. public Widgets(GQuery gq) {
  42. super(gq);
  43. }
  44. public Widgets(final JSArray elements) {
  45. super(elements);
  46. }
  47. public Widgets(final NodeList<Element> list) {
  48. super(list);
  49. }
  50. @SuppressWarnings("unchecked")
  51. @Override
  52. // TODO: consider more widgets
  53. public <W extends Widget> W widget() {
  54. Widget w = super.widget();
  55. if (w == null) {
  56. Element e = elements.getItem(0);
  57. if ("div".equalsIgnoreCase(e.getTagName()) || "span".equalsIgnoreCase(e.getTagName())) {
  58. w = HTML.wrap(e);
  59. } else if ("button".equalsIgnoreCase(e.getTagName())) {
  60. w = Button.wrap(e);
  61. } else if ("text".equalsIgnoreCase(e.getTagName())) {
  62. w = TextBox.wrap(e);
  63. } else {
  64. w = new HTML($(e).toString());
  65. }
  66. }
  67. return (W)w;
  68. }
  69. }