GWT 2:如何将Button添加到CellTable的头部? [英] GWT 2: how can I add Button to the CellTable's header?

查看:166
本文介绍了GWT 2:如何将Button添加到CellTable的头部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是创建一个带有控件的表格以添加新行。这个典型的控件应该包含相应的TextEdits和一个添加新行按钮。



我使用CellTable。

我可以单独创建这个添加小部件,只是在某些面板中梳理按钮和必要的字段,但我想尝试将它绑定到表。我想用CellTable来制作它。为此,我尝试使用CellTable的标题。我创建了一个Header并添加了一个EditCellText和ButtonCell。我有两个问题:


  • 该按钮不显示。显示getValue()方法返回的值。

  • 我不知道如何处理该按钮上的点击。



[1]最后,第一个问题是:如何将一个按钮添加到CellTable的标题中,以及如何处理该按钮上的点击?按钮应该看起来像一个按钮,而不仅仅是点击区域。



[2]可能有另一种方式来完成我的任务。 是否可以创建CellTable,其中不同的行拥有不同的按钮?第一行保存按钮添加,其他所有行保存按钮删除。 GWT可以做到这一点吗?

[3]还有一个问题。目前我使用Java代码描述了我的CellTable的结构。即我在创建父窗口小部件的同时手动创建并添加列和标题对象。 是否可以使用XML表示我的CellTable的结构,即使用一些mySpecialCellTable.ui.xml文件?

解决方案您可以使用ButtonCell:

  Column< MyObject,String> delete = new Column< MyObject,String>(new ButtonCell()){

@Override
public String getValue(final MyObjectobject object){
returndelete;
}
};

delete.setFieldUpdater(new FieldUpdater< MyObject,String>(){

@Override
public void update(final int index,final MyObjectobject object,final String值){

myActivity.delete(object); //如果单击按钮
}
});

这也应该回答第二个问题。据我所知,你必须在你的Java类中添加列。在你的uibinder文件中,你只能添加celltable作为一个整体。

 < p1:CellTable ui:field =table>< / p1:CellTable> 

希望这有助于您。


My task is to create a table with a control to add the new lines. This typical control should consist of corresponding set of TextEdits and an "add new row" Button.

I use CellTable.

I can create this "adding widget" separately just combing button and necessary fields in some panel, but I want to try to bind it to the table. I want to make it using the CellTable. For this purpose I try to utilize the header of the CellTable. I created a Header and added a EditCellText and ButtonCell. I have two problems:

  • The button is not shown. Instead a value returned by getValue() method is shown.
  • I dont know how to handle the click on that button.

[1] Finally, the first question is: how can you add a button into a header of CellTable and how would you process the click on that button? The button should looks like a button, not just some click area.

[2] Probably there is another way to accomplish my task. Is it possible to create CellTable where different rows hold different buttons? I.e. first row holds button "Add", and all other rows hold button "Remove". Can GWT do this?

[3] One more question. At the moment I describe the structure of my CellTable using Java code. I.e. I create and add column and header objects manually while creating the parent widget. Is it possible to express the structure of my CellTable with XML, i.e. using some mySpecialCellTable.ui.xml file?

解决方案

for displaying a button in your table you can use a ButtonCell:

Column<MyObject, String> delete = new Column<MyObject, String>(new ButtonCell()) {

            @Override
            public String getValue(final MyObjectobject object) {
                return "delete";
            }
        };

        delete.setFieldUpdater(new FieldUpdater<MyObject, String>() {

            @Override
            public void update(final int index, final MyObjectobject object, final String value) {

                myActivity.delete(object); // to whatever should happen if button is clicked
            }
        });

This should answer the second question as well. As far as I know you have to add the columns in you java class. In your uibinder file you can only add the celltable as a whole.

<p1:CellTable ui:field="table"></p1:CellTable>

Hope this helps.

这篇关于GWT 2:如何将Button添加到CellTable的头部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆