java - JavaFX updating FilteredList when item field has changed -


i have observablelist , filteredlist contains attached files field state. filteredlist set listview. want when changed field state state.removed, has been updated 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 event update filtered list?  }  public string getpath() {     return path; }  public string getname() {     return name; }  @override public string tostring() {     return name; } 

}

create model class (attached) using javafx properties pattern.

public class attached {      public static enum state {         new, attached, removed     }      private final objectproperty<state> state = new simpleobjectproperty<>();     private final stringproperty path = new simplestringproperty();     private final stringproperty name = new simplestringproperty();      public attached(state state, string path, string name) {         setstate(state);         setpath(path);         setname(name);     }      public objectproperty<state> stateproperty() {         return state ;     }      public final state getstate() {         return stateproperty().get();     }      public final void setstate(state state) {        stateproperty().set(state);     }      public stringproperty pathproperty() {         return path ;     }      public final string getpath() {         return pathproperty.get();     }      public final void setpath(string path) {         pathproperty().set(path);     }      public stringproperty nameproperty() {         return name ;     }      public final string getname() {         return nameproperty().get();     }      public final void setname(string name) {         nameproperty().set(name);     }      @override     public string tostring() {         return getname();     }  } 

now create underlying list extractor, fires update events when stateproperty changes:

private final observablelist<attached> attaches =      fxcollections.observablearraylist(attached -> new observable[]{attached.stateproperty()}); private final filteredlist<attached> filteredattaches =      attaches.filtered(attached -> attached.getstate() != attached.state.removed); 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -