Java 我们可以动态更改GWT引导程序3按钮ll图标吗?

Java 我们可以动态更改GWT引导程序3按钮ll图标吗?,java,css,twitter-bootstrap,gwt,gwtbootstrap3,Java,Css,Twitter Bootstrap,Gwt,Gwtbootstrap3,我有一个GWT bootstrap 3按钮,作为使用IconType和ButtonType创建的按钮: public abstract class ButtonColumn<T> extends Column<T, String> { public ButtonColumn(IconType iconType, ButtonType buttonType) { this(new ButtonCell(buttonType, iconType));

我有一个GWT bootstrap 3按钮,作为使用IconType和ButtonType创建的按钮:

public abstract class ButtonColumn<T> extends Column<T, String> {
    public ButtonColumn(IconType iconType, ButtonType buttonType) {
        this(new ButtonCell(buttonType, iconType));
    }
}
公共抽象类按钮列扩展列{
公共按钮列(IconType IconType,ButtonType ButtonType){
这个(新的ButtonCell(ButtonCype,iCountype));
}
}
所以当我创建按钮时,我会

new ButtonColumn<Object>(IconType.PLAY, ButtonType.SUCCESS) {
  @Override
  public void onClick(Object obj) {
    doStuff(obj);
  }
};
newbuttoncolumn(IconType.PLAY,buttonype.SUCCESS){
@凌驾
公共void onClick(对象对象对象){
多斯塔夫(obj);
}
};
我想在单击时更改我的按钮图标。有可能实现吗?
我可以创建一个扩展GWT的自定义IconType吗?我想放置一个动画图标(如a)。

好吧,您不能更改一行中按钮的图标,尤其是当您使用已指定的图标创建整个列时。但是您可以
redraw()
一行,这可能是实现所需的一种方法

我使用渲染按钮和:

  • 首先在
    consumedEvents
    参数中使用
    ClickEvent
    创建一个抽象单元格
  • render()
    方法中,根据单击的状态渲染按钮
  • onBrowserEvent()
    方法中,更改单击的状态并重新呈现行
单击的状态最好保存在表的基础数据类型中,以便对每一行都可用

下面是一个完整的工作示例代码:

final CellTable<TableType> table = new CellTable<TableType>();

AbstractCell<TableType> buttonCell = new AbstractCell<ButtonCellTest.TableType>(ClickEvent.getType().getName()) {
    @Override
    public void render(Context context, TableType value, SafeHtmlBuilder sb) {
        Button button = new Button();
        button.setType(ButtonType.SUCCESS);
        button.setSize(ButtonSize.SMALL);
        button.add(new Icon(value.isClicked() ? IconType.CHECK : IconType.TIMES));
        sb.append(SafeHtmlUtils.fromTrustedString(button.toString()));
    }

    @Override
    public void onBrowserEvent(Context context, Element parent, TableType value, NativeEvent event, ValueUpdater<TableType> valueUpdater) {
        value.setClicked(!value.isClicked());
        // ... do stuff...
        table.redrawRow(context.getIndex());
    }
};
table.addColumn(new Column<TableType, TableType>(buttonCell) {
    @Override
    public TableType getValue(TableType object) {
        return object;
    }
});

ArrayList<TableType> rowData = new ArrayList<TableType>();
rowData.add(new TableType("row 1"));
rowData.add(new TableType("row 2"));
...
table.setRowData(rowData);

至于扩展
IconType
enum-否,您不能在Java中扩展enum。例如,请参见此问题:

您可以尝试添加自己的
CSS
类,但这应该作为另一个问题来提问,以获得准确答案。

table.redrawRow(context.getIndex())为我工作。我没有使用OnBrowserEvent(),而是使用onClick,在click事件上传递行id。这可能是因为我们有自己的类扩展AbstractCell。非常感谢。
public class TableType {
    String text;
    boolean clicked = false;

    public TableType(String text) {
        this.text = text;
    }

    public String getText() {
        return text;
    }

    public boolean isClicked() {
        return clicked;
    }

    public void setClicked(boolean clicked) {
        this.clicked = clicked;
    }
}