* the License.
*/
package com.google.gwt.query.client.plugins;
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.query.client.GQuery;
-import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory;
-import com.google.gwt.query.client.plugins.widgets.DateBoxWidgetFactory;
-import com.google.gwt.query.client.plugins.widgets.DisclosurePanelWidgetFactory;
-import com.google.gwt.query.client.plugins.widgets.ListBoxWidgetFactory;
-import com.google.gwt.query.client.plugins.widgets.PasswordTextBoxWidgetFactory;
-import com.google.gwt.query.client.plugins.widgets.RichTextWidgetFactory;
-import com.google.gwt.query.client.plugins.widgets.SuggestBoxWidgetFactory;
-import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory;
-import com.google.gwt.query.client.plugins.widgets.TextBoxWidgetFactory;
-import com.google.gwt.query.client.plugins.widgets.WidgetFactory;
-import com.google.gwt.query.client.plugins.widgets.WidgetInitializer;
-import com.google.gwt.query.client.plugins.widgets.WidgetsUtils;
+import com.google.gwt.query.client.LazyBase;
import com.google.gwt.query.client.plugins.widgets.DisclosurePanelWidgetFactory.DisclosurePanelOptions;
import com.google.gwt.query.client.plugins.widgets.ListBoxWidgetFactory.ListBoxOptions;
import com.google.gwt.query.client.plugins.widgets.SuggestBoxWidgetFactory.SuggestBoxOptions;
import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory.TabPanelOptions;
+import com.google.gwt.query.client.plugins.widgets.WidgetFactory;
+import com.google.gwt.query.client.plugins.widgets.WidgetInitializer;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.datepicker.client.DateBox;
-import java.util.ArrayList;
-import java.util.List;
-import com.google.gwt.query.client.LazyBase;
public interface LazyWidgets<T> extends LazyBase<T>{
*/\r
package com.google.gwt.query.client.plugins;\r
\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
import com.google.gwt.dom.client.Element;\r
import com.google.gwt.query.client.GQuery;\r
import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory;\r
import com.google.gwt.query.client.plugins.widgets.DateBoxWidgetFactory;\r
import com.google.gwt.query.client.plugins.widgets.DisclosurePanelWidgetFactory;\r
+import com.google.gwt.query.client.plugins.widgets.DisclosurePanelWidgetFactory.DisclosurePanelOptions;\r
import com.google.gwt.query.client.plugins.widgets.ListBoxWidgetFactory;\r
+import com.google.gwt.query.client.plugins.widgets.ListBoxWidgetFactory.ListBoxOptions;\r
import com.google.gwt.query.client.plugins.widgets.PasswordTextBoxWidgetFactory;\r
import com.google.gwt.query.client.plugins.widgets.RichTextWidgetFactory;\r
import com.google.gwt.query.client.plugins.widgets.SuggestBoxWidgetFactory;\r
+import com.google.gwt.query.client.plugins.widgets.SuggestBoxWidgetFactory.SuggestBoxOptions;\r
import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory;\r
+import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory.TabPanelOptions;\r
import com.google.gwt.query.client.plugins.widgets.TextBoxWidgetFactory;\r
import com.google.gwt.query.client.plugins.widgets.WidgetFactory;\r
import com.google.gwt.query.client.plugins.widgets.WidgetInitializer;\r
-import com.google.gwt.query.client.plugins.widgets.WidgetsUtils;\r
-import com.google.gwt.query.client.plugins.widgets.DisclosurePanelWidgetFactory.DisclosurePanelOptions;\r
-import com.google.gwt.query.client.plugins.widgets.ListBoxWidgetFactory.ListBoxOptions;\r
-import com.google.gwt.query.client.plugins.widgets.SuggestBoxWidgetFactory.SuggestBoxOptions;\r
-import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory.TabPanelOptions;\r
import com.google.gwt.user.client.ui.Button;\r
import com.google.gwt.user.client.ui.DisclosurePanel;\r
import com.google.gwt.user.client.ui.ListBox;\r
import com.google.gwt.user.client.ui.TabPanel;\r
import com.google.gwt.user.client.ui.TextBox;\r
import com.google.gwt.user.client.ui.Widget;\r
+import com.google.gwt.user.client.ui.WidgetsUtils;\r
import com.google.gwt.user.datepicker.client.DateBox;\r
\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
/**\r
* Widgets plugin for Gwt Query. Be careful, this plugin is still experimental.\r
* The api can change in next releases.\r
\r
return widget(get(0), factory, initializers);\r
}\r
-\r
+ \r
protected boolean isWidgetCreationAuthorizedFrom(Element e) {\r
return $(e).widget() == null && !WidgetsUtils.matchesTags(e, excludedTags);\r
}\r
+++ /dev/null
-package com.google.gwt.query.client.plugins.widgets;
-
-public interface Attachable {
- void attach();
-}
+++ /dev/null
-package com.google.gwt.query.client.plugins.widgets;
-
-import com.google.gwt.user.client.ui.RootPanel;
-import com.google.gwt.user.client.ui.Widget;
-
-import com.google.gwt.user.client.ui.Composite;
-
-/**
- * Provide a way to subclass widget class that cannot be subclassed directly in
- * order to provide a way to call onAttach method on it
- *
- *
- * @param <W>
- */
-public class AttachableComposite<W extends Widget> extends Composite implements
- Attachable {
-
-
- public AttachableComposite(W widget) {
- initWidget(widget);
- }
-
-
- public void attach() {
- onAttach();
- RootPanel.detachOnWindowClose(this);
-
- }
-
- @SuppressWarnings("unchecked")
- public W getOriginalWidget(){
- return (W) getWidget();
- }
-
-}
package com.google.gwt.query.client.plugins.widgets;
-import com.google.gwt.dom.client.ButtonElement;
-import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.WidgetsUtils;
/**
* Factory used to create a {@link Button} widget. A {@link Button} is created
return Button.wrap(e);
}
- ButtonElement buttonElement = Document.get().createPushButtonElement();
- buttonElement.setInnerText(e.getInnerText());
- WidgetsUtils.replaceOrAppend(e, buttonElement);
-
- return Button.wrap(buttonElement);
-
+
+ Button button = new Button();
+ button.getElement().setInnerText(e.getInnerText());
+
+ WidgetsUtils.replaceOrAppend(e, button);
+ return button;
}
}
\ No newline at end of file
import com.google.gwt.dom.client.Element;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.query.client.GQuery;
-import com.google.gwt.user.client.ui.RootPanel;
+import com.google.gwt.user.client.ui.WidgetsUtils;
import com.google.gwt.user.datepicker.client.DateBox;
import com.google.gwt.user.datepicker.client.DateBox.DefaultFormat;
*/
public class DateBoxWidgetFactory implements WidgetFactory<DateBox> {
- // DateBox needs to call the onAttach method
- public static class AttachableDateBox extends DateBox implements Attachable {
- public void attach(){
- onAttach();
- RootPanel.detachOnWindowClose(this);
- }
- }
-
public DateBox create(Element e) {
String v = null;
if ($(e).filter("input[type='text']").size() == 1) {
}
}
}
- DateBox b = new AttachableDateBox();
+ DateBox b = new DateBox();
b.setValue(d);
if (f != null) {
b.setFormat(new DefaultFormat(f));
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.WidgetsUtils;
public class DisclosurePanelWidgetFactory implements
WidgetFactory<DisclosurePanel> {
}
public DisclosurePanel create(Element e) {
- AttachableComposite<DisclosurePanel> attachableDisclosurePanel = new AttachableComposite<DisclosurePanel>(
- new DisclosurePanel());
-
- initialize(attachableDisclosurePanel, e);
-
- return attachableDisclosurePanel.getOriginalWidget();
- }
-
- protected void initialize(AttachableComposite<DisclosurePanel> widget,
- Element e) {
String headerValue = "";
if (options.getHeaderTitle() != null){
headerValue = $(options.getHeaderSelector(), e).first().remove().text();
}
- DisclosurePanel disclosurePanel = widget.getOriginalWidget();
-
+ DisclosurePanel disclosurePanel = new DisclosurePanel();
disclosurePanel.setHeader(new Label(headerValue));
disclosurePanel.add(new HTMLPanel(e.getString()));
- WidgetsUtils.replaceOrAppend(e, widget);
-
+
+ WidgetsUtils.replaceOrAppend(e, disclosurePanel);
+ return disclosurePanel;
}
}
import com.google.gwt.dom.client.SelectElement;
import com.google.gwt.query.client.GQuery;
import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.WidgetsUtils;
/**
* Factory used to create a {@link ListBox} widget.
if (WidgetsUtils.matchesTags(e, "select")) {
SelectElement selectElement = e.cast();
-
if (selectElement.isMultiple() != options.isMultipleSelect()) {
selectElement.setMultiple(options.isMultipleSelect());
}
-
return ListBox.wrap(e);
}
- SelectElement selectElement = Document.get().createSelectElement(
- options.isMultipleSelect());
+ ListBox listBox = new ListBox(options.isMultipleSelect());
GQuery itemsList = getItemsList(e);
-
- WidgetsUtils.replaceOrAppend(e, selectElement);
-
- ListBox listBox = ListBox.wrap(selectElement);
-
for (Element item : itemsList.elements()) {
listBox.addItem(item.getInnerText());
}
+ WidgetsUtils.replaceOrAppend(e, listBox);
return listBox;
-
}
private GQuery getItemsList(Element e) {
if (options.getOptionsSelector() != null) {
return $(options.getOptionsSelector(), e);
}
-
return $(e).children();
}
}
\ No newline at end of file
import static com.google.gwt.query.client.GQuery.$;
-import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
-import com.google.gwt.dom.client.InputElement;
import com.google.gwt.query.client.GQuery;
import com.google.gwt.user.client.ui.PasswordTextBox;
+import com.google.gwt.user.client.ui.WidgetsUtils;
/**
* Factory used to create a {@link PasswordTextBox} widget. A
return PasswordTextBox.wrap(e);
}
- InputElement inputElement = Document.get().createPasswordInputElement();
- inputElement.setValue(e.getInnerText());
-
- WidgetsUtils.replaceOrAppend(e, inputElement);
-
- PasswordTextBox textBox = PasswordTextBox.wrap(inputElement);
+ PasswordTextBox textBox = new PasswordTextBox();
+ textBox.setValue(e.getInnerText());
+ WidgetsUtils.replaceOrAppend(e, textBox);
return textBox;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RichTextArea;
+import com.google.gwt.user.client.ui.WidgetsUtils;
/**
* Factory used to create a {@link RichTextArea} widget.
* A {@link Button} is created if the element is a <i>textarea</i>, <i>div></i> or <i>span</i>.
* The content of the element will be copied to the rich text area.
*/
-// TODO: inject page styles to the iframe. Provide a Toolbar.
public class RichTextWidgetFactory implements WidgetFactory<RichTextArea> {
- public static class AttachableRichTextArea extends RichTextArea implements Attachable {
- public void attach(){
- onAttach();
- // This fails with richtextarea,
- // RootPanel.detachOnWindowClose(this);
- }
- }
-
public RichTextArea create(Element e) {
String v = null;
if ("textarea".equalsIgnoreCase(e.getTagName())) {
}
private RichTextArea create(String v) {
- RichTextArea b = new AttachableRichTextArea();
+ RichTextArea b = new RichTextArea();
b.setHTML(v);
return b;
}
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.SuggestOracle;
+import com.google.gwt.user.client.ui.WidgetsUtils;
/**
* Factory used to create a {@link SuggestBox} widget.
return SuggestBox.wrap(suggestOracle, e);
}
- InputElement inputElement = Document.get().createTextInputElement();
-
- WidgetsUtils.replaceOrAppend(e, inputElement);
-
- return SuggestBox.wrap(suggestOracle, inputElement);
+ SuggestBox sbox = new SuggestBox(suggestOracle);
+ WidgetsUtils.replaceOrAppend(e, sbox);
+ return sbox;
}
private SuggestOracle createOracle(Element e) {
}
return oracle;
-
}
}
\ No newline at end of file
import com.google.gwt.query.client.GQuery;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTMLPanel;
-import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.ui.WidgetsUtils;
/**
* Factory used to create a {@link Button} widget. A {@link Button} is created
}
}
- private static class ExtendedTabPanel extends TabPanel implements Attachable{
-
- public void attach() {
- onAttach();
- RootPanel.detachOnWindowClose(this);
- }
- }
-
private TabPanelOptions options;
public TabPanelWidgetFactory(TabPanelOptions o) {
}
public TabPanel create(Element e) {
- ExtendedTabPanel tabPanel = new ExtendedTabPanel();
-
- initialize(tabPanel, options, e);
-
- return tabPanel;
- }
-
-
- protected void initialize(ExtendedTabPanel tabPanel, TabPanelOptions options,
- Element e) {
+ TabPanel tabPanel = new TabPanel();
GQuery tabs = $(options.getTabSelector(), e);
GQuery titles = $(options.getTitleSelector(), e);
? title.getInnerText() : "Tab " + (i + 1));
}
-
if (tabs.length() > 0) {
tabPanel.selectTab(0);
}
WidgetsUtils.replaceOrAppend(e, tabPanel);
-
+ return tabPanel;
}
}
import static com.google.gwt.query.client.GQuery.$;
-import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
-import com.google.gwt.dom.client.InputElement;
import com.google.gwt.query.client.GQuery;
import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.WidgetsUtils;
/**
* Factory used to create a {@link TextBox} widget. A {@link TextBox} is created
return TextBox.wrap(e);
}
- InputElement inputElement = Document.get().createTextInputElement();
- inputElement.setValue(e.getInnerText());
-
- WidgetsUtils.replaceOrAppend(e, inputElement);
-
- TextBox textBox = TextBox.wrap(inputElement);
+ TextBox textBox = new TextBox();
+ textBox.setValue(e.getInnerText());
+ WidgetsUtils.replaceOrAppend(e, textBox);
return textBox;
-
}
}
\ No newline at end of file
+++ /dev/null
-package com.google.gwt.query.client.plugins.widgets;
-
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.query.client.GQuery;
-import com.google.gwt.user.client.ui.Widget;
-
-public class WidgetsUtils {
-
- private static final String[] appendingTags = {
- "td", "th", "li"};
-
-
- /**
- * Test if the tag name of the element is one of tag names given in parameter
- *
- * @param tagNames
- * @return
- */
- public static boolean matchesTags(Element e, String... tagNames) {
-
- assert e != null : "Element cannot be null";
-
- StringBuilder regExp = new StringBuilder("^(");
- int tagNameLenght = tagNames != null ? tagNames.length : 0;
- for (int i = 0; i < tagNameLenght; i++) {
- regExp.append(tagNames[i].toUpperCase());
- if (i < tagNameLenght - 1) {
- regExp.append("|");
- }
- }
- regExp.append(")$");
-
- return e.getTagName().toUpperCase().matches(regExp.toString());
-
- }
-
- /**
- * If the <code>oldElement</code> is a td, th, li tags, the new element will replaced its content.
- * In other cases, the <code>oldElement</code> will be replaced by the <code>newElement</code>
- * and the old element classes will be copied to the new element.
- */
- public static void replaceOrAppend(Element oldElement, Element newElement) {
- assert oldElement != null && newElement != null;
-
- if(matchesTags(oldElement, appendingTags)){
- GQuery.$(oldElement).html("").append(newElement);
- }else{
- GQuery.$(oldElement).replaceWith(newElement);
-
- String c = oldElement.getClassName();
- if (!c.isEmpty()) {
- newElement.addClassName(c);
- }
- }
- }
-
- /**
- * Replace a dom element by a widget.
- * If the widget implements Attachable the method attach will be called.
- * Old element classes will be copied to the new widget.
- */
- public static void replaceOrAppend(Element e, Widget widget) {
- assert e != null && widget != null;
- replaceOrAppend(e, widget.getElement());
-
- if (widget instanceof Attachable) {
- ((Attachable)widget).attach();
- }
- }
-
-
-}
--- /dev/null
+package com.google.gwt.user.client.ui;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.query.client.GQuery;
+
+public class WidgetsUtils {
+
+ private static final String[] appendingTags = {
+ "td", "th", "li"};
+
+
+ /**
+ * Test if the tag name of the element is one of tag names given in parameter
+ *
+ * @param tagNames
+ * @return
+ */
+ public static boolean matchesTags(Element e, String... tagNames) {
+
+ assert e != null : "Element cannot be null";
+
+ StringBuilder regExp = new StringBuilder("^(");
+ int tagNameLenght = tagNames != null ? tagNames.length : 0;
+ for (int i = 0; i < tagNameLenght; i++) {
+ regExp.append(tagNames[i].toUpperCase());
+ if (i < tagNameLenght - 1) {
+ regExp.append("|");
+ }
+ }
+ regExp.append(")$");
+
+ return e.getTagName().toUpperCase().matches(regExp.toString());
+
+ }
+
+ /**
+ * If the <code>oldElement</code> is a td, th, li tags, the new element will replaced its content.
+ * In other cases, the <code>oldElement</code> will be replaced by the <code>newElement</code>
+ * and the old element classes will be copied to the new element.
+ */
+ private static void replaceOrAppend(Element oldElement, Element newElement) {
+ assert oldElement != null && newElement != null;
+
+ if(matchesTags(oldElement, appendingTags)){
+ GQuery.$(oldElement).html("").append(newElement);
+ }else{
+ GQuery.$(oldElement).replaceWith(newElement);
+
+ String c = oldElement.getClassName();
+ if (!c.isEmpty()) {
+ newElement.addClassName(c);
+ }
+ }
+ }
+
+ /**
+ * Replace a dom element by a widget.
+ * If the widget implements Attachable the method attach will be called.
+ * Old element classes will be copied to the new widget.
+ */
+ public static void replaceOrAppend(Element e, Widget widget) {
+ assert e != null && widget != null;
+
+ if (widget.isAttached()) {
+ widget.removeFromParent();
+ }
+
+ replaceOrAppend(e, widget.getElement());
+
+ widget.onAttach();
+
+ if (widget instanceof RichTextArea != true) {
+ RootPanel.detachOnWindowClose(widget);
+ }
+ }
+
+}