Skip to content

Instantly share code, notes, and snippets.

@rdwallis
Forked from christiangoudreau/gist:42e51a2cbb20dd204f4b
Last active January 24, 2016 22:22

Revisions

  1. rdwallis revised this gist Sep 5, 2014. 1 changed file with 13 additions and 2 deletions.
    15 changes: 13 additions & 2 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,14 @@
    /**
    * Copyright 2014 Richard Wallis.
    * All rights reserved.
    */
    package com.wallissoftware.wave.client.widgets;

    import com.google.gwt.user.client.ui.HTMLPanel;
    import com.google.gwt.user.client.ui.IsWidget;
    import com.google.gwt.user.client.ui.SimplePanel;
    import com.google.gwt.user.client.ui.Widget;

    /**
    * Panel that wraps a GWT simple panel to be replaced by the widgetToAttach. This will make sure that the DIV element
    * is being replaced rather than having the widget inserted in it.
    @@ -30,14 +41,14 @@ public void setWidget(final IsWidget widget) {

    @Override
    public void setWidget(final Widget widgetToAttach) {
    final Widget parentAsWidget = widget.asWidget().getParent();
    final Widget parentAsWidget = asWidget().getParent();
    if (!(parentAsWidget instanceof HTMLPanel)) {
    throw new WrongParentTypeException("The parent of ReplacePanel must be of type HTMLPanel");
    }

    final HTMLPanel parent = (HTMLPanel) parentAsWidget;

    parent.addAndReplaceElement(widgetToAttach, widget.asWidget().getElement());
    parent.addAndReplaceElement(widgetToAttach, asWidget().getElement());

    widget = widgetToAttach;
    }
  2. rdwallis revised this gist Sep 2, 2014. 1 changed file with 13 additions and 17 deletions.
    30 changes: 13 additions & 17 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -4,45 +4,41 @@
    * <p/>
    * The result of this will be to have a better, cleaner, dom.
    */
    public class ReplacePanel implements IsWidget, HasOneWidget {
    public class ReplacePanel extends SimplePanel {
    static class WrongParentTypeException extends RuntimeException {
    public WrongParentTypeException(String message) {
    public WrongParentTypeException(final String message) {
    super(message);
    }
    }

    private IsWidget widget;

    public ReplacePanel() {
    widget = new SimplePanel();
    }

    @Override
    public Widget asWidget() {
    return widget.asWidget();
    return widget != null ? widget.asWidget() : super.asWidget();
    }

    @Override
    public Widget getWidget() {
    return widget.asWidget();
    return widget != null ? widget.asWidget() : super.getWidget();
    }

    @Override
    public void setWidget(final IsWidget widget) {
    setWidget(widget.asWidget());
    }

    @Override
    public void setWidget(Widget widgetToAttach) {
    Widget parentAsWidget = widget.asWidget().getParent();
    public void setWidget(final Widget widgetToAttach) {
    final Widget parentAsWidget = widget.asWidget().getParent();
    if (!(parentAsWidget instanceof HTMLPanel)) {
    throw new WrongParentTypeException("The parent of ReplacePanel must be of type HTMLPanel");
    }

    HTMLPanel parent = (HTMLPanel) parentAsWidget;
    final HTMLPanel parent = (HTMLPanel) parentAsWidget;

    parent.addAndReplaceElement(widgetToAttach, widget.asWidget().getElement());

    widget = widgetToAttach;
    }

    @Override
    public void setWidget(IsWidget widget) {
    setWidget(widget.asWidget());
    }
    }
    }
  3. @christiangoudreau christiangoudreau revised this gist Aug 18, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ public WrongParentTypeException(String message) {
    private IsWidget widget;

    public ReplacePanel() {
    widget = new com.google.gwt.user.client.ui.SimplePanel();
    widget = new SimplePanel();
    }

    @Override
  4. @christiangoudreau christiangoudreau revised this gist Aug 12, 2014. 1 changed file with 10 additions and 24 deletions.
    34 changes: 10 additions & 24 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    /**
    * Simple panel that wraps a GWT simple panel to be replaced by the widgetToAttach we set while updating the references.
    * Panel that wraps a GWT simple panel to be replaced by the widgetToAttach. This will make sure that the DIV element
    * is being replaced rather than having the widget inserted in it.
    * <p/>
    * The result of this will be to have a better, cleaner, dom.
    */
    @@ -13,19 +14,7 @@ public WrongParentTypeException(String message) {
    private IsWidget widget;

    public ReplacePanel() {
    SimplePanel simplePanel = new com.google.gwt.user.client.ui.SimplePanel();
    widget = simplePanel;

    simplePanel.addAttachHandler(new Handler() {
    @Override
    public void onAttachOrDetach(AttachEvent event) {
    Widget parentAsWidget = getParent();

    if (!(parentAsWidget instanceof HTMLPanel)) {
    throw new WrongParentTypeException("The parent of ReplacePanel must be of type HTMLPanel");
    }
    }
    });
    widget = new com.google.gwt.user.client.ui.SimplePanel();
    }

    @Override
    @@ -40,23 +29,20 @@ public Widget getWidget() {

    @Override
    public void setWidget(Widget widgetToAttach) {
    Widget parentAsWidget = getParent();
    Widget parentAsWidget = widget.asWidget().getParent();
    if (!(parentAsWidget instanceof HTMLPanel)) {
    throw new WrongParentTypeException("The parent of ReplacePanel must be of type HTMLPanel");
    }

    if (parentAsWidget != null && parentAsWidget instanceof HTMLPanel) {
    HTMLPanel parent = (HTMLPanel) parentAsWidget;
    HTMLPanel parent = (HTMLPanel) parentAsWidget;

    parent.addAndReplaceElement(widgetToAttach, widget.asWidget().getElement());
    parent.addAndReplaceElement(widgetToAttach, widget.asWidget().getElement());

    widget = widgetToAttach;
    }
    widget = widgetToAttach;
    }

    @Override
    public void setWidget(IsWidget widget) {
    setWidget(widget.asWidget());
    }

    private Widget getParent() {
    return widget.asWidget().getParent();
    }
    }
  5. @christiangoudreau christiangoudreau renamed this gist Aug 12, 2014. 1 changed file with 25 additions and 5 deletions.
    30 changes: 25 additions & 5 deletions gistfile1.txt → gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,31 @@
    package com.google.gwt.user.client.ui;

    /**
    * Simple panel that wraps a GWT simple panel to be replaced by the widgetToAttach we set while updating the references.
    * <p/>
    * The result of this will be to have a better, cleaner, dom.
    */
    public class ReplacePanel implements IsWidget, HasOneWidget {
    static class WrongParentTypeException extends RuntimeException {
    public WrongParentTypeException(String message) {
    super(message);
    }
    }

    private IsWidget widget;

    public ReplacePanel() {
    this.widget = new com.google.gwt.user.client.ui.SimplePanel();
    SimplePanel simplePanel = new com.google.gwt.user.client.ui.SimplePanel();
    widget = simplePanel;

    simplePanel.addAttachHandler(new Handler() {
    @Override
    public void onAttachOrDetach(AttachEvent event) {
    Widget parentAsWidget = getParent();

    if (!(parentAsWidget instanceof HTMLPanel)) {
    throw new WrongParentTypeException("The parent of ReplacePanel must be of type HTMLPanel");
    }
    }
    });
    }

    @Override
    @@ -24,7 +40,7 @@ public Widget getWidget() {

    @Override
    public void setWidget(Widget widgetToAttach) {
    Widget parentAsWidget = widget.asWidget().getParent();
    Widget parentAsWidget = getParent();

    if (parentAsWidget != null && parentAsWidget instanceof HTMLPanel) {
    HTMLPanel parent = (HTMLPanel) parentAsWidget;
    @@ -39,4 +55,8 @@ public void setWidget(Widget widgetToAttach) {
    public void setWidget(IsWidget widget) {
    setWidget(widget.asWidget());
    }
    }

    private Widget getParent() {
    return widget.asWidget().getParent();
    }
    }
  6. @christiangoudreau christiangoudreau revised this gist Aug 12, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,6 @@ package com.google.gwt.user.client.ui;

    /**
    * Simple panel that wraps a GWT simple panel to be replaced by the widgetToAttach we set while updating the references.

    * <p/>
    * The result of this will be to have a better, cleaner, dom.
    */
  7. @christiangoudreau christiangoudreau revised this gist Aug 12, 2014. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,7 @@ package com.google.gwt.user.client.ui;

    /**
    * Simple panel that wraps a GWT simple panel to be replaced by the widgetToAttach we set while updating the references.
    * <p/>
    * It is not recommended to apply any type to this container as it is meant to be replaced by it's content in the dom.

    * <p/>
    * The result of this will be to have a better, cleaner, dom.
    */
  8. @christiangoudreau christiangoudreau revised this gist Aug 11, 2014. 1 changed file with 13 additions and 13 deletions.
    26 changes: 13 additions & 13 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,10 @@
    package com.roler.res.client.application.widget;

    import com.google.gwt.user.client.ui.HasOneWidget;
    import com.google.gwt.user.client.ui.IsWidget;
    import com.google.gwt.user.client.ui.Widget;

    import static com.google.gwt.query.client.GQuery.$;
    package com.google.gwt.user.client.ui;

    /**
    * Simple panel that wraps a GWT simple panel to be replaced by the widget we set while updating the references.
    *
    * Simple panel that wraps a GWT simple panel to be replaced by the widgetToAttach we set while updating the references.
    * <p/>
    * It is not recommended to apply any type to this container as it is meant to be replaced by it's content in the dom.
    *
    * <p/>
    * The result of this will be to have a better, cleaner, dom.
    */
    public class ReplacePanel implements IsWidget, HasOneWidget {
    @@ -31,10 +25,16 @@ public class ReplacePanel implements IsWidget, HasOneWidget {
    }

    @Override
    public void setWidget(Widget widget) {
    $(this.widget).replaceWith($(widget));
    public void setWidget(Widget widgetToAttach) {
    Widget parentAsWidget = widget.asWidget().getParent();

    if (parentAsWidget != null && parentAsWidget instanceof HTMLPanel) {
    HTMLPanel parent = (HTMLPanel) parentAsWidget;

    parent.addAndReplaceElement(widgetToAttach, widget.asWidget().getElement());

    this.widget = widget;
    widget = widgetToAttach;
    }
    }

    @Override
  9. @christiangoudreau christiangoudreau created this gist Aug 9, 2014.
    44 changes: 44 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    package com.roler.res.client.application.widget;

    import com.google.gwt.user.client.ui.HasOneWidget;
    import com.google.gwt.user.client.ui.IsWidget;
    import com.google.gwt.user.client.ui.Widget;

    import static com.google.gwt.query.client.GQuery.$;

    /**
    * Simple panel that wraps a GWT simple panel to be replaced by the widget we set while updating the references.
    *
    * It is not recommended to apply any type to this container as it is meant to be replaced by it's content in the dom.
    *
    * The result of this will be to have a better, cleaner, dom.
    */
    public class ReplacePanel implements IsWidget, HasOneWidget {
    private IsWidget widget;

    public ReplacePanel() {
    this.widget = new com.google.gwt.user.client.ui.SimplePanel();
    }

    @Override
    public Widget asWidget() {
    return widget.asWidget();
    }

    @Override
    public Widget getWidget() {
    return widget.asWidget();
    }

    @Override
    public void setWidget(Widget widget) {
    $(this.widget).replaceWith($(widget));

    this.widget = widget;
    }

    @Override
    public void setWidget(IsWidget widget) {
    setWidget(widget.asWidget());
    }
    }