【发布时间】:2015-08-17 03:53:16
【问题描述】:
我有 ObservableList 和 FilteredList,其中包含带有字段 state 的附件。 FilteredList 设置为 ListView。我想在将字段state更改为State.REMOVED时,已更新FilteredList。
/* class Item */
private final ObservableList<Attached> attaches = FXCollections.observableArrayList();
private final FilteredList<Attached> filteredAttaches = attaches.filtered(attached -> attached.getState() != Attached.State.REMOVED);
/* Controller */
listAttached.setItems(item.getAttachesForDisplay());
/* class Attached */
public class Attached {
public static enum State {
NEW, ATTACHED, REMOVED
}
private State state;
private final String path;
private final String name;
public Attached(State state, String path, String name) {
this.state = state;
this.path = path;
this.name = name;
}
public State getState() {
return state;
}
public void changeState(State state) {
this.state = state;
// Generate some event for update filtered list?
}
public String getPath() {
return path;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}
【问题讨论】: