Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add or remove a single element from/to CellList?

Tags:

java

gwt

How to add/remove a single element to/from CellList ?

like image 470
Łukasz Bownik Avatar asked Nov 19 '10 09:11

Łukasz Bownik


1 Answers

If you use a ListDataProvider<T> get the wrapped list and simply add or remove an element.

A really simple example:

public void onModuleLoad() {
    final ListDataProvider<String> provider = new ListDataProvider<String>(getList());
    CellList<String> list = new CellList<String>(new TextCell());
    provider.addDataDisplay(list);

    Button btn = new Button("add more");
    btn.addClickHandler(new ClickHandler() {

        private int counter = 0;

        @Override
        public void onClick(ClickEvent event) {
            provider.getList().add(++counter + " more");
        }
    });

    RootPanel.get().add(list);
    RootPanel.get().add(btn);
}

private LinkedList<String> getList() {
    LinkedList<String> list = new LinkedList<String>();
    list.add("1st");
    list.add("2nd");
    list.add("3rd");
    list.add("4th");
    list.add("5th");
    return list;
}
like image 127
z00bs Avatar answered Sep 19 '22 20:09

z00bs