Skip to content

Instantly share code, notes, and snippets.

@edwardsmatt
Created October 13, 2011 22:02
Show Gist options
  • Save edwardsmatt/1285670 to your computer and use it in GitHub Desktop.
Save edwardsmatt/1285670 to your computer and use it in GitHub Desktop.
Patch the GXT {@link WidgetComponent#setParent(Widget, Widget) } method for gwt-test-utls-gxt
package com.octo.gxt.test.internal.patchers;
import com.extjs.gxt.ui.client.widget.WidgetComponent;
import com.google.gwt.user.client.ui.Widget;
import com.octo.gwt.test.patchers.PatchClass;
import com.octo.gwt.test.patchers.PatchMethod;
import com.octo.gwt.test.utils.GwtReflectionUtils;
/**
* Patch the GXT {@link WidgetComponent#setParent(Widget, Widget) } method.
* Usage that caused error:
* <p>
* <pre>
* final FormPanel panel = new FormPanel();
* panel.add(new Image(Resources.ICONS.formIcon()));
* </pre>
* </p>
* @author Matthew Edwards
* @see com.extjs.gxt.ui.client.widget.LayoutContainer#wrapWidget(Widget)
* @see com.extjs.gxt.ui.client.widget.Container#wrapWidget(Widget)
* @see WidgetComponent#setParent(Widget, Widget)
*/
@PatchClass(WidgetComponent.class)
final class WidgetComponentPatcher {
/** Private Constructor to prevent Instantiation and appease Checkstyle. */
private WidgetComponentPatcher() {
}
/**
* Patch {@link WidgetComponent#setParent(Widget, Widget) } to set the {@code parent} on the {@link child}.
* @param component the component {@link WidgetComponent} to replace the {@code setParent} method on.
* @param parent the parent {@link Widget}.
* @param child the child {@link Widget}.
*/
@PatchMethod
public static void setParent(final WidgetComponent component, final Widget parent, final Widget child) {
GwtReflectionUtils.setPrivateFieldValue(child, "parent", parent);
}
}
@edwardsmatt
Copy link
Author

Fixes UnsatisfiedLinkError when adding an Image to a Panel using GwtTestWithEasyMock.
Dependencies:

  • GXT-2.2.4
  • GWT-2.2.0
  • gwt-test-utils-0.28.7
  • gwt-test-utils-gxt-0.28.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment