12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- /*
- * Copyright 2009 Google Inc.
- *
- * 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;
-
- import com.google.gwt.dom.client.Element;
- import com.google.gwt.dom.client.NodeList;
- import com.google.gwt.query.client.GQuery;
- import com.google.gwt.query.client.JSArray;
- import com.google.gwt.query.client.Plugin;
- import com.google.gwt.user.client.ui.Button;
- import com.google.gwt.user.client.ui.HTML;
- import com.google.gwt.user.client.ui.TextBox;
- import com.google.gwt.user.client.ui.Widget;
-
- /**
- * Widgets plugin for Gwt Query.
- */
- public class Widgets extends GQueryQueue<Widgets> {
-
- public static final Class<Widgets> Widgets = Widgets.class;
-
- static {
- GQuery.registerPlugin(Widgets.class, new Plugin<Widgets>() {
- public Widgets init(GQuery gq) {
- return new Widgets(gq);
- }
- });
- }
-
- public Widgets(final Element element) {
- super(element);
- }
-
- public Widgets(GQuery gq) {
- super(gq);
- }
-
- public Widgets(final JSArray elements) {
- super(elements);
- }
-
- public Widgets(final NodeList<Element> list) {
- super(list);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- // TODO: consider more widgets
- public <W extends Widget> W widget() {
- Widget w = super.widget();
- if (w == null) {
- Element e = elements.getItem(0);
- if ("div".equalsIgnoreCase(e.getTagName()) || "span".equalsIgnoreCase(e.getTagName())) {
- w = HTML.wrap(e);
- } else if ("button".equalsIgnoreCase(e.getTagName())) {
- w = Button.wrap(e);
- } else if ("text".equalsIgnoreCase(e.getTagName())) {
- w = TextBox.wrap(e);
- } else {
- w = new HTML($(e).toString());
- }
- }
- return (W)w;
- }
-
- }
|