But standard editable cell types (EditTextCell, TextInputCell, DatePickerCell) have one limitation : these columns in all rows are eligible to edit. So I found impossible to implement the following scenario:
- User is browsing through the table. Edit mode is blocked to avoid changing something by accident.
- Decides to edit one row. Set on the switch 'edit this row' and this row is transformed to edit mode. But edit mode for all other rows is blocked.
- After finishing editing set off the switch and the row is again in look mode.
Example - switchable version of 'TextInputCell'
private class EditStringCell extends TextInputCell implements IGetField { private final IVField v; EditStringCell(IVField v) { this.v = v; } @Override public void render(Context context, String value, SafeHtmlBuilder sb) { Object key = context.getKey(); Integer i = (Integer) key; boolean editenabled = eCol.isEditable(i, v); if (editenabled) { super.render(context, value, sb); return; } // Get the view data. // copy and paste from TextInputCell // the only difference is different HTML for displaying value TemplateDisplay template = GWT.create(TemplateDisplay.class); ViewData viewData = getViewData(key); if (viewData != null && viewData.getCurrentValue().equals(value)) { clearViewData(key); viewData = null; } String s = (viewData != null) ? viewData.getCurrentValue() : value; if (s != null) { sb.append(template.input(s)); } else { sb.appendHtmlConstant(""); } }The difference is only in 'render' method. If 'edit mode' is on it simply invokes standard method. If 'edit mode' is off it overrides standard and displays the content. In order to have it working correctly I had to copy and modify the body of standard method to deal with specific way of storing value of the cell in 'ViewData' type.
Although I'm not very happy with that is seems working for me.
The all 'switchable' edit cell I'm using are implemented in this source.
Brak komentarzy:
Prześlij komentarz