4

I want one of my table columns to have a deleteButton.

ActionCell<Entrata> deleteCell = new ActionCell<Entrata>("x",new Delegate<Entrata>() {
            @Override
            public void execute(Entrata object) {
                // rpc stuff.... 
            }
        });

Ok but this line generates an error:

Column<Entrata,Entrata> deleteColumn = new Column<Entrata, Entrata>(deleteCell);

"Cannot instantiate the type Column"

What do you think?

Fabio B.
  • 9,138
  • 25
  • 105
  • 177

3 Answers3

1

Here you go with working code:

Assumptions:

TYPE - Is the class of the data you show in rows of Cell Table it the same because I assume you want reference to the instance of data when you going to delete it

public class DeleteColumn extends Column<TYPE, TYPE>
{
    public DeleteColumn()
    {

        super(new ActionCell<TYPE>("Delete", new ActionCell.Delegate<TYPE>() {
            @Override
            public void execute(TYPE record)
            {
                /**
                  *Here you go. You got a reference to an object in a row that delete was clicked. Put your "delete" code here
                  */
            }
        }));
    }

    @Override
    public TYPE getValue(TYPE object)
    {
        return object;
    }
};
Boris Daich
  • 2,431
  • 3
  • 23
  • 27
  • And how to add it to the CellTable? I managed to do it but when i click the action cell i get a ClassCastException – Ben Jun 21 '12 at 09:56
  • @UiField CellTable listTable; listTable.addColumn(new DeleteColumn(), "Delete"); – Boris Daich Jun 25 '12 at 00:31
0

This works

//table = initialized CellTable with content already loaded 

ActionCell editCell = new ActionCell<EmployeeObject>("remove", new ActionCell.Delegate<EmployeeObject>() {
            public void execute(EmployeeObject object){
                List<EmployeeObject> list = new ArrayList<EmployeeObject>(table.getVisibleItems());
                for(int i = 0; i < list.size(); i ++){
                    if(object.getFirstname().equals(list.get(i).getFirstname())){
                        list.remove(i);
                        break;
                    }
                }
                table.setRowData(list);
            }
        });

Column<EmployeeObject, ActionCell> editColumn = (new IdentityColumn(editCell));
Ben
  • 6,107
  • 6
  • 29
  • 40
0

From the doku:

A representation of a column in a table. The column may maintain view data for each cell on demand. New view data, if needed, is created by the cell's onBrowserEvent method, stored in the Column, and passed to future calls to Cell's

So you have to declar it something like this:

    Column<String, String> colum = new Column<String, String>(null) {

        @Override
        public String getValue(String object) {
            // TODO Auto-generated method stub
            return null;
        }
    };

Still I don't exactly know how you implement the delete button, so it would be nice if you can give us the rest of your code.

Stefan
  • 14,826
  • 17
  • 80
  • 143