Composite cell in gwt application

I am trying to create a CompositeCell that consists of TextCell and ButtonCell. I want to add a CompositeCell to Column, and then Column to CellTable. However, I cannot figure out what the column instance should look like. 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 that creates a CompositeCell for the FilterInfo custom class (is it needed?):

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 appreciate any guidance on adapting the code or other proposal to create the desired CompositeCell and add it to CellTable correctly.

+5
source share
4 answers

Do you need to use a compound cell? This seems like a lot of work to me, and it can be a lot easier to create my own custom cell.

+3

. IDE . " . XXX <C> ", .

CompositeCell N:

private Column<DTO, DTO> getButtonColumn() {
    return new Column<DTO, DTO>(getButtonsCell()) {
        @Override
        public DTO getValue(DTO object) {
            return object;
        }
    };
} 

private CompositeCell getButtonsCell() {
    HasCell<DTO,DTO> button1 = new AbstractActionButton<DTO>() {
                @Override
                public void execute(final DTO object) {
                    //Action on button click
                }

                @Override
                public void render(Context context, DTO data, SafeHtmlBuilder sb) {
                    //
                }
            };
    HasCell<DTO,DTO> button2 = new AbstractActionButton<DTO>(){ 
        //Complete me ...
    }

    List<HasCell<DTO, ?>> cells = new LinkedList<>();
    cells.add(button1);
    cells.add(button2);
    CompositeCell<DTO> compositeCell = new CompositeCell<>(cells);

    return compositeCell;
}


public abstract class AbstractActionButton<DTO> implements HasCell<DTO, DTO> {

@Override
public Cell<DTO> getCell() {
    return new ActionCell<DTO>("Button title", new ActionCell.Delegate<DTO>() {
        @Override
        public void execute(DTO object) {
            AbstractActionButton.this.execute(object);
        }
    }) {
        @Override
        public void render(Context context, DTO data, SafeHtmlBuilder sb) {
            AbstractActionButton.this.render(context, data, sb);
        }
    };
}

//Replaced by delegate but still need to be overriden
@Override
public FieldUpdater<DTO, DTO> getFieldUpdater() {
    return null; 
}

@Override
public DTO getValue(DTO object) {
    return object;
}

/**
 * You can override this method to render your button differently. Not mandatory
 * @param context
 * @param data
 * @param sb
 */
public abstract void render(Context context, DTO data, SafeHtmlBuilder sb);

/**
 * Called when the button is clicked
 * @param object
 */
public abstract void execute(DTO object);
}
+2

CellTable FilterInfo, Cell FilterInfo, IdentityColumn.

+1

(Checkboxcell + TextCell) GXT XTemplate . , GWT, GXT GWT.

https://gist.github.com/Aadi1/4949994

0

All Articles