Thursday, August 8, 2013

Custom cell in CellTable with TextCell and SelectionCell

Hi everybody,

I am trying to implement a custom cell for my CellTable showing a TextCell or a SelectionCell. The decision is made by an enum value in my model. 

To add the cell to my table I made a custom column, source under the cell. The Last snippets shows how I add the cell to my table. 

Problem / question:
Rendering is working well. But the cell doesn't react on changes.
When I try to add a FieldUpdater to the cell, eclipse says I need to provide a FieldUpdater in my column class. I have no idea how it looks like.

Is there a proper way to add FieldUpdater<Model, C> to my class? Sources below.

Thanks a lot in advance. When it works, I am going to publish a simplified example and will share the link here.

Best regards

Jochen


CustomStatusCell
public class CustomStatusCell<C> extends AbstractCell<C> {    public static final MasterDataConstants CONSTANTS = (MasterDataConstants) GWT.create(MasterDataConstants.class);    private TextCell textCell;  private SelectionCell selectCell;    private String text = "";    public CustomStatusCell() {      textCell = new TextCell();  }    @Override  public void render(com.google.gwt.cell.client.Cell.Context context, C object, SafeHtmlBuilder sb) {        if (shouldRenderInput(object)) {          selectCell.render(context, text, sb);      } else {          textCell.render(context, text, sb);      }  }    @Override  public void onBrowserEvent(Context context, Element parent, final C object, NativeEvent event, final ValueUpdater<C> valueUpdater) {      if (shouldRenderInput(object)) {          selectCell.onBrowserEvent(context, parent, (String) object, event, new ValueUpdater<String>() {                @Override              public void update(String value) {                  updateValue(value, object);              }          });      } else {          textCell.onBrowserEvent(context, parent, (String) object, event, new ValueUpdater<String>() {                @Override              public void update(String value) {                  updateValue(value, object);              }          });      }  }    protected void updateValue(String value, C object) {  }    boolean shouldRenderInput(C object) {        Model model = (Model) object;        switch (m.getStatus()) {      case NEW: {          List<String> list = new ArrayList<String>();          list.add(CONSTANTS.statusValueNewNew());          list.add(CONSTANTS.statusValueNewReleased());          list.add(CONSTANTS.statusValueNewNoImport());            selectCell = new SelectionCell(list);          return true;      }      case RELEASED: {          text = CONSTANTS.statusValueReleased();          return false;      }      case ERROR: {          text = CONSTANTS.statusValueError();          return false;      }      default: {          return false;      }      }  }
Column

CustomStatusColumn<Model> statusColumn = new CustomStatusColumn<Model>() {
@Override
public ImportModel getValue(Model model) {
return model;
}
};

CellTable

CustomStatusColumn<Model> statusColumn = new CustomStatusColumn<Model>() {  	@Override  	public ImportModel getValue(Model model) {  		return model;  	}  };  statusColumn.setDataStoreName(ImportDataStoreConstants.getStatus());  statusColumn.setSortable(true);  this.addColumn(statusColumn, CONSTANTS.statusLabel());
 

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment