]> source.dussan.org Git - gwtquery.git/commitdiff
Removing Attachable and AttachableComposite and moving WidgetUtils to the gwt Widget...
authorManolo Carrasco <manolo@apache.org>
Wed, 9 Mar 2011 13:37:15 +0000 (13:37 +0000)
committerManolo Carrasco <manolo@apache.org>
Wed, 9 Mar 2011 13:37:15 +0000 (13:37 +0000)
15 files changed:
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/Attachable.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/AttachableComposite.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/DateBoxWidgetFactory.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/DisclosurePanelWidgetFactory.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ListBoxWidgetFactory.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/PasswordTextBoxWidgetFactory.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/RichTextWidgetFactory.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/SuggestBoxWidgetFactory.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TabPanelWidgetFactory.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxWidgetFactory.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/user/client/ui/WidgetsUtils.java [new file with mode: 0644]

index 09db268b8515376f112acf469828ecc4f77d54e2..e7e4cf84066c445333eb8002d769cd412c55c2c9 100644 (file)
  * 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;
@@ -41,9 +30,6 @@ import com.google.gwt.user.client.ui.TabPanel;
 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>{
 
index 21e4e7a0bebe2cf7efa2d197d7f1e03bc19254b3..3df324dce50a83cca11f3b3db9c56e3f436280e0 100755 (executable)
  */\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
@@ -41,11 +43,9 @@ import com.google.gwt.user.client.ui.SuggestBox;
 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
@@ -241,7 +241,7 @@ public class Widgets extends QueuePlugin<Widgets> {
 \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
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/Attachable.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/Attachable.java
deleted file mode 100644 (file)
index 86039ce..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.google.gwt.query.client.plugins.widgets;
-
-public interface Attachable {
-  void attach();
-}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/AttachableComposite.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/AttachableComposite.java
deleted file mode 100644 (file)
index 23e2be4..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-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();
-  }
-  
-}
index e306700fbc4bc11baff66fa97ffde3927351410d..93cc7755ee16483e69eba213dbb58274fd76107d 100644 (file)
@@ -1,9 +1,8 @@
 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
@@ -18,11 +17,11 @@ public class ButtonWidgetFactory implements WidgetFactory<Button> {
       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
index 34a1fef9e3f089521f4ffb7f6baefe43e27db909..829cbe8a36472ed5e4282c9dc26ce3dfdaf5e3bd 100644 (file)
@@ -7,7 +7,7 @@ import java.util.Date;
 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;
 
@@ -18,14 +18,6 @@ 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) {
@@ -55,7 +47,7 @@ public class DateBoxWidgetFactory implements WidgetFactory<DateBox> {
         }
       }
     }
-    DateBox b = new AttachableDateBox();
+    DateBox b = new DateBox();
     b.setValue(d);
     if (f != null) {
       b.setFormat(new DefaultFormat(f));
index 850f234bb0e7547f43c5396301c4a44c72d2e52f..a272ffdcddc596fa37aaf081778c03341077bd18 100644 (file)
@@ -7,6 +7,7 @@ import com.google.gwt.user.client.ui.Button;
 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> {
@@ -53,16 +54,6 @@ public class DisclosurePanelWidgetFactory implements
   }
 
   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){
@@ -71,12 +62,12 @@ public class DisclosurePanelWidgetFactory implements
       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;
   }
 
 }
index 944e5feed80b09076a29240f95550c48cce4de9b..f5b8ad0d885ca75f852e05a2c431377dfe375d39 100644 (file)
@@ -7,6 +7,7 @@ import com.google.gwt.dom.client.Element;
 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.
@@ -77,36 +78,27 @@ public class ListBoxWidgetFactory implements WidgetFactory<ListBox> {
     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
index 42c11556b11f66271471f1adcdbfba28bfd61962..9d6c0fb7157f625df36efc2937d96d9e52d1f573 100644 (file)
@@ -2,11 +2,10 @@ package com.google.gwt.query.client.plugins.widgets;
 
 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
@@ -25,12 +24,9 @@ public class PasswordTextBoxWidgetFactory implements
       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;
 
index 17ba63b8eaaa4bc07582e979f3757824c2f25a0f..b5c5e46c065289f5fa1027ce05fdb1eccc5c7330 100644 (file)
@@ -5,24 +5,16 @@ import static com.google.gwt.query.client.GQuery.$;
 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())) {
@@ -39,7 +31,7 @@ public class RichTextWidgetFactory implements WidgetFactory<RichTextArea> {
   }
 
   private RichTextArea create(String v) {
-    RichTextArea b = new AttachableRichTextArea();
+    RichTextArea b = new RichTextArea();
     b.setHTML(v);
     return b;
   }
index 9cce165b75d2960530347bc70359f7a24fe5cb65..9b85dae39190b83781316ba787ce61fed58795f8 100644 (file)
@@ -9,6 +9,7 @@ import com.google.gwt.query.client.GQuery;
 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.
@@ -85,12 +86,10 @@ public class SuggestBoxWidgetFactory implements WidgetFactory<SuggestBox> {
       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) {
@@ -108,7 +107,6 @@ public class SuggestBoxWidgetFactory implements WidgetFactory<SuggestBox> {
     }
 
     return oracle;
-
   }
 
 }
\ No newline at end of file
index 4f2c3d108e3746c495402a0a0ace902230e13349..1de9c94fbd80a79e8969556da1aba859d691ff85 100644 (file)
@@ -6,9 +6,9 @@ import com.google.gwt.dom.client.Element;
 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
@@ -53,14 +53,6 @@ public class TabPanelWidgetFactory implements WidgetFactory<TabPanel> {
     }
   }
   
-  private static class ExtendedTabPanel extends TabPanel implements Attachable{
-
-    public void attach() {
-      onAttach();
-      RootPanel.detachOnWindowClose(this);
-    }
-  }
-
   private TabPanelOptions options;
 
   public TabPanelWidgetFactory(TabPanelOptions o) {
@@ -68,16 +60,7 @@ public class TabPanelWidgetFactory implements WidgetFactory<TabPanel> {
   }
 
   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);
@@ -95,12 +78,11 @@ public class TabPanelWidgetFactory implements WidgetFactory<TabPanel> {
           ? title.getInnerText() : "Tab " + (i + 1));
 
     }
-
     if (tabs.length() > 0) {
       tabPanel.selectTab(0);
     }
 
     WidgetsUtils.replaceOrAppend(e, tabPanel);
-
+    return tabPanel;
   }
 }
index 603ef007556049d550540f213cdece02f8f37f53..fe389da2ba3db1a7ebd8c1b00d25e1df195f34f8 100644 (file)
@@ -2,11 +2,10 @@ package com.google.gwt.query.client.plugins.widgets;
 
 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
@@ -24,14 +23,10 @@ public class TextBoxWidgetFactory implements WidgetFactory<TextBox> {
       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
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java
deleted file mode 100644 (file)
index 894e81f..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-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();
-     }
-   }
-
-   
-}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/user/client/ui/WidgetsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/user/client/ui/WidgetsUtils.java
new file mode 100644 (file)
index 0000000..445bdc8
--- /dev/null
@@ -0,0 +1,77 @@
+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);
+     }
+   }
+   
+}