Blog do projektu Open Source JavaHotel

wtorek, 20 września 2011

GWT, editable table

I found very usable a Cell Table which allows to edit its cells (sample). It is quite easy to use it : while adding new column to the table use 'editable' cell in the constructor.
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:
  1. User is browsing through the table. Edit mode is blocked to avoid changing something by accident.
  2. 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.
  3. After finishing editing set off the switch and the row is again in look mode.
So in order to implement this scenario I was forced to create my own 'editable' cells by extending standard editable cell type.
Example - switchable version of 'TextInputCell'
private class EditStringCell extends TextInputCell implements IGetField {

        private final IVField v;

        EditStringCell(IVField v) {
            this.v = v;

        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);
            // 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)) {
                viewData = null;
            String s = (viewData != null) ? viewData.getCurrentValue() : value;
            if (s != null) {
            } else {

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.

niedziela, 11 września 2011

New version Boa tester

New version of Boa test framework.
In order to avoid CR/LF (DOS) and LF (Linux) hell I had to change a method for file comparison. I replaced standard filecmp.cmp function with manual line by line comparison. Source file.

  eq = filecmp.cmp(sou, dest)
  if not eq:"  different")
    res = 0

f1 = open(sou, "r")
 f2 = open(dest, "r")
 li1 = f1.readlines()
 li2 = f2.readlines()
 if len(li1) != len(li2) :" number of lines is different")
    res = 0
 for i in range(0, len(li1))  :
 line1 = li1[i].rstrip()
 line2 = li2[i].rstrip()
 if line1 != line2 :" line number: " + str(i)  + " different")
    res = 0