Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

java - How to remove a row from the Cell Table

At first I used the Grid. After creating a new version of the GWT, I want to replace the Grid on the CellTable.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Check out the javadoc for details. My example is like the one you'll find there (just a little extended):

public void onModuleLoad() {
    final CellTable<Row> table = new CellTable<Row>();

    TextColumn<Row> firstColumn = new TextColumn<Starter.Row>() {

        @Override
        public String getValue(Row object) {
            return object.firstColumn;
        }
    };
    table.addColumn(firstColumn, "header one");

    TextColumn<Row> secondColumn = new TextColumn<Starter.Row>() {

        @Override
        public String getValue(Row object) {
            return object.secondColumn;
        }
    };
    table.addColumn(secondColumn, "header two");

    TextColumn<Row> thirdColumn = new TextColumn<Starter.Row>() {

        @Override
        public String getValue(Row object) {
            return object.thirdColumn;
        }
    };
    table.addColumn(thirdColumn, "header three");

    table.setRowCount(getList().size());
    final ListDataProvider<Row> dataProvider = new ListDataProvider<Starter.Row>(getList());
    dataProvider.addDataDisplay(table);

    final SingleSelectionModel<Row> selectionModel = new SingleSelectionModel<Starter.Row>();
    table.setSelectionModel(selectionModel);

    Button btn = new Button("delete entry");
    btn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Row selected = selectionModel.getSelectedObject();
            if (selected != null) {
                dataProvider.getList().remove(selected);
            }
        }
    });

    RootPanel.get().add(table);
    RootPanel.get().add(btn);

}

private class Row {

    private String firstColumn;
    private String secondColumn;
    private String thirdColumn;

    public Row(String firstColumn, String secondColumn, String thirdColumn) {
        this.firstColumn = firstColumn;
        this.secondColumn = secondColumn;
        this.thirdColumn = thirdColumn;
    }

}

private LinkedList<Row> getList() {
    LinkedList<Row> list = new LinkedList<Row>();
    list.add(new Row("first", "entry", "foo"));
    list.add(new Row("second", "entry", "foo"));
    list.add(new Row("third", "entry", "foo"));
    list.add(new Row("fourth", "entry", "foo"));
    return list;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...