2011-08-11 28 views
4

我想讓我的一個表列有一個deleteButton。在CellTable列中創建自定義ActionCell

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

好,但此行生成錯誤:

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

「無法實例化類型列」

你覺得呢?

回答

0

在這裏,您去工作代碼:

假設:

TYPE - 是類中的數據,你在單元表的行表現出來,因爲同我假設你想要參照實例數據時,你要刪除它

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; 
    } 
}; 
+0

以及如何將其添加到CellTable? 我設法做到了,但是當我點擊動作單元格時,我得到一個ClassCastException – Ben

+0

@UiField CellTable listTable; listTable.addColumn(new DeleteColumn(),「Delete」); –

0

從數獨:

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

所以,你必須declar它是這樣的:

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

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

不過我不知道究竟如何實現刪除按鈕,所以這將是如果你可以給我們剩下的代碼,那很好。

0

這工作

//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));