Custom gxt Cell which may take Widget

为君一笑 提交于 2019-12-02 08:56:00

See here for a number of examples of AbstractCell implementations.

To answer your question regarding a GWT button:

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.Widget;

public class WidgetGridCell extends AbstractCell<Widget> {

  Widget widget;

  public WidgetGridCell(Widget widget) {
      this.widget = widget;
  }

  @Override
  public void render(Context paramContext,
          Widget param, SafeHtmlBuilder pb) {
    Button aButton = new Button();
    // add text to the button, etc...
    pb.append(SafeHtmlUtils.fromTrustedString(aButton.toString()));
  }
}

It's largely not feasible (and not advisable) to try and render an entire widget within a cell element but it sounds as though you are really trying to render a button from within the cell.

AbstractCell is an implementation of the Cell interface which allows you to define the HTML to render within the cell. If you need a button which can respond to events you'll need to define your custom cell to handle browser events (such as the click event). Google does a good job in their documentation on custom cells explaining how you can go about doing that.

See this link: http://www.gwtproject.org/doc/latest/DevGuideUiCustomCells.html

I have a post on adding a widget to a cell. Have a look and see if it helps you out.

http://mpickell.com/blog/2013/01/28/widgets-in-gwt-cell-tables/

Like Colin says, changes on the widget won't be used unless the HTML of the widget is pushed again to the page. I have some notes in the comments of this post on some ways you might handle events as well. Read the comments to see how to use the class I have in the post.

And also like Colin says here, be careful and make sure you understand what you're doing and how the widget is never actually attached to its HTML in the page.

By the way.. You mention you want a button. Why not use the GWT ButtonCell?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!