1
我嘗試了以下示例,http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTree,並在CompositeCell內部添加了兩個ActionCell,但沒有運氣。 ActionCell的onBrowserEvent()不會被觸發。有沒有人有一個ActionCells在CompositeCell內工作的例子?
我嘗試了以下示例,http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTree,並在CompositeCell內部添加了兩個ActionCell,但沒有運氣。 ActionCell的onBrowserEvent()不會被觸發。有沒有人有一個ActionCells在CompositeCell內工作的例子?
這個簡單的例子適合我。既然你沒有提供任何代碼或進一步解釋你想要達到什麼目的,我不知道我的例子是否有幫助。
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;
}
}