在单元格列表中添加单击处理程序添加的按钮单元格

时间:2013-09-02 11:29:48

标签: java gwt

我创建了一个cellList: 我想在用户点击“发送”按钮

时添加一个点击处理程序

请帮助。如果用户点击“发送”按钮,FieldUpdater应该可以工作。

以下是代码:

  final String imageHtml =AbstractImagePrototype.create(images.contact()).getHTML();
// first make a list of HasCell type - MyClass is the type of object being displayed in the CellList (could be String for simple labels)
List<HasCell<contactinfo, ?>> hasCells = new ArrayList<HasCell<contactinfo, ?>>();

hasCells.add(new HasCell<contactinfo, String>()
        {
    public ButtonCell cell = new ButtonCell();

    public Cell<String> getCell()
    {
        return cell;
    }

    @Override
    public String getValue(contactinfo object)
    {
        return "Send";
    }

    @Override
    public FieldUpdater<contactinfo, String> getFieldUpdater() {
        FieldUpdater< contactinfo, String > updater=                 new FieldUpdater<contactinfo, String>() {

            @Override
            public void update(int index, contactinfo object, String value) {
                Window.alert("You clicked  "+object.getName());
            }

        };
        return updater;
    }

        }

);

// now construct the actual composite cell using the list (hasCells)
Cell<contactinfo> myClassCell = new CompositeCell<contactinfo>(hasCells)
{
    @Override
    public void render(Context context, contactinfo value, SafeHtmlBuilder sb)
    {
        sb.appendHtmlConstant("<table><tbody><tr>");
        super.render(context, value, sb);
        sb.appendHtmlConstant("</tr></tbody></table>");
    }
    @Override
    protected Element getContainerElement(Element parent)
    {
        // Return the first TR element in the table.
        return parent.getFirstChildElement().getFirstChildElement();
    }
    @Override
    protected <X> void render(Context context, contactinfo contactinfo, SafeHtmlBuilder sb, HasCell<contactinfo, X> hasCell)
    {

这将复合单元格中的每个单元格呈现在一个新的表格单元格中

        // Value can be null, so do a null check..
        if (contactinfo == null) {
            return;
        }

        sb.appendHtmlConstant("<table>");

        // Add the contact image.
        sb.appendHtmlConstant("<tr><td rowspan='3'>");
        sb.appendHtmlConstant(imageHtml);
        sb.appendHtmlConstant("</td>");

        // Add the name and address.
        sb.appendHtmlConstant("<td style='font-size:95%;'>");
        if(contactinfo.getName()!=null)
            sb.appendEscaped(contactinfo.getName());
        sb.appendHtmlConstant("</td></tr><tr><td>");
        if(contactinfo.getAddress()!=null)
            sb.appendEscaped(contactinfo.getRemarks());
        sb.appendHtmlConstant("</td>");
        Cell<X> cell = hasCell.getCell();
        sb.appendHtmlConstant("<td>");
        cell.render(context, hasCell.getValue(contactinfo), sb);
        sb.appendHtmlConstant("</td></tr></table>");
    }
};
// then make the actual cellList, passing the composite cell
cellList =new CellList<contactinfo>(myClassCell,KEY_PROVIDER);
// Add a selection model so we m select cells.
singleselectionModel = new SingleSelectionModel<contactinfo>(
        KEY_PROVIDER);


cellList.setSelectionModel(singleselectionModel);
singleselectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

    @Override
    public void onSelectionChange(SelectionChangeEvent event) {

    }
});

1 个答案:

答案 0 :(得分:1)

另外,我没有在代码中看到处理事件的任何部分。您是否阅读了http://www.gwtproject.org/doc/latest/DevGuideUiCustomCells.html#cell-onBrowserEvent

您是否尝试过GWT提供的代码示例 - http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellSampler。浏览“源代码”!!!

如果您还没有阅读,那么您应该从@ DevGuideUiCustomCells

开始
相关问题