Search code examples
javagwtgridgxt

Custom gxt Cell which may take Widget


I need a Column in which it was possible to put a Widget. I have this:

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) {

    }
}

But I do not know how to include the widget in HTML

P.S. Or not Widget, only GWT Button will suit me.


Solution

  • 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