开发者

Does anyone have a working examples of ActionCells working within a CompositeCell?

I tried following the example, http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTree , and added two ActionCells inside of the CompositeCell with no luck. The ActionCell's onBrowserEvent() 开发者_JS百科does not get triggered.


This simple example works for me. Since you didn't provide any code or further explanation on what exactly you're trying to achieve, I have no idea whether my example is of any help or not.

public void onModuleLoad() {
    CellTable<Person> table = new CellTable<Starter.Person>();

    List<HasCell<Person, ?>> cells = new LinkedList<HasCell<Person, ?>>();
    cells.add(new HasCellImpl("first name", new Delegate<Person>() {

        @Override
        public void execute(Person object) {
            Window.alert(object.getFirstName());
        }
    }));
    cells.add(new HasCellImpl("last name", new Delegate<Starter.Person>() {

        @Override
        public void execute(Person object) {
            Window.alert(object.getLastName());
        }
    }));

    CompositeCell<Person> cell = new CompositeCell<Person>(cells);
    table.addColumn(new TextColumn<Starter.Person>() {

        @Override
        public String getValue(Person object) {
            return object.getFirstName() + " " + object.getLastName();
        }
    }, "name");

    table.addColumn(new Column<Person, Person>(cell) {

        @Override
        public Person getValue(Person object) {
            return object;
        }
    }, "composite");

    LinkedList<Person> data = new LinkedList<Starter.Person>();
    data.add(new Person("Amy", "Reed"));
    data.add(new Person("Tim", "Gardner"));
    table.setRowData(data);

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

private class HasCellImpl implements HasCell<Person, Person> {
    private ActionCell<Person> fCell;

    public HasCellImpl(String text, Delegate<Person> delegate) {
        fCell = new ActionCell<Person>(text, delegate);
    }

    @Override
    public Cell<Person> getCell() {
        return fCell;
    }

    @Override
    public FieldUpdater<Person, Person> getFieldUpdater() {
        return null;
    }

    @Override
    public Person getValue(Person object) {
        return object;
    }
}

private class Person {
    private String fFirstName;
    private String fLastName;

    public Person(String first, String last) {
        fFirstName = first;
        fLastName = last;
    }

    public String getFirstName() {
        return fFirstName;
    }

    public String getLastName() {
        return fLastName;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜