Disable row editing in Grid based on criteria

Hi

Currently I’m using vaadin 7.4.3 and migrating from the old table to the new Grid component but i have one really specific requirement that I’m not sure how to implement.

We need to be able to edit few columns in a grid when the user double click a row in the grid but the editing shouldn’t been enable to all rows in the grid based on a status in the row. I already tried to listen to the ItemClickListener to cancel the editor in a read only row but that didn’t work. Also i was thinking on passing a FieldListFactory with null values but the editor is showed and got a NPE when trying to create the fields. Any ideas?

How about using ItemClickListener to both enable the editor and open it with editItem() (if the user clicked on any of the allowed rows)? Obviously, you need to disable the editor after it’s closed.

I tried this but you need to setEditorEnabled to true to be able to edit the item.

Mmm…yes you need to, but you first set it in the ItemClickListener to be enabled, and after that you can call editItem().

I haven’t actually tried that, but I’d think it should work. What problem did you have with it?

Ok so my error was that i was trying to disable the edit on the commit handler and i was getting an exception that being now i tried doing it in the itemClick listener and its working as expected. I appreciate your help on this and sharing some code just for reference , it’s still need some clean up but this is working as expected.

 public void itemClick(ItemClickEvent event) {                
        if( ((BeanItem<Book>)event.getItem()).getBean().getAuthor().equals("AUthor2") ){
            grid.setEditorEnabled(true);                        
        }else{
            grid.setEditorEnabled(false);
        }
        if(event.isDoubleClick() && grid.isEditorEnabled()){
            grid.editItem(event.getItemId());
        }
        
    }