javagwtcellcelltable

Composite Cell in a gwt application


I am trying to create a CompositeCell which consists of a TextCell and a ButtonCell. I want to add the CompositeCell to Column ordinarily and then the Column to a CellTable. However I am not able to figure out how the instance of the column should be. In particular I cannot find its type parameters in the following code:

 Column<FilterInfo, ?> compositeColumn = new Column<FilterInfo, ?>(createCompositeCell()) {

  @Override
  public Object getValue(Object object) {
    // TODO Auto-generated method stub
    return null;
  }}; 

The method which creates the CompositeCell of the custom class FilterInfo (is it necessary?) is:

private CompositeCell<FilterInfo> createCompositeCell(){

HasCell<FilterInfo, String> filterName = new HasCell<FilterInfo, String>() {

  public Cell<String> getCell() {
    return new TextCell();
  }

  public FieldUpdater<FilterInfo, String> getFieldUpdater() {
    // TODO Auto-generated method stub
    return null;
  }

  public String getValue(FilterInfo object) {
    return object.getFilterName();
  }};

  HasCell<FilterInfo, String> filterButton = new HasCell<FilterInfo,String>(){

    public Cell<String> getCell() {
      return new ButtonCell();
    }

    public FieldUpdater<FilterInfo, String> getFieldUpdater() {
      // TODO Auto-generated method stub
      return null;
    }

    public String getValue(FilterInfo object) {
      // TODO Auto-generated method stub
      return "...";
    }
  };

  List<HasCell<FilterInfo, ?>> cells = new ArrayList<HasCell<FilterInfo, ?>>();
  cells.add(filterName);
  cells.add(filterButton);

  CompositeCell<FilterInfo> compositeCell = new CompositeCell<FilterInfo>(cells);

  return compositeCell;

}

I would be grateful by any indication to adapt the code or another suggestion to create the desired CompositeCell and to add it to the CellTable properly.


Solution

  • Do you have to use a composite cell? To me this seems like a lot of work, and it may be a lot easier to just create your own custom cell.

    Have a read of the documentation on Creating Custom Cells