-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...faults/src/main/java/org/genericsystem/defaults/tools/ObservableInheritanceComputer2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.genericsystem.defaults.tools; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import org.genericsystem.defaults.DefaultGeneric; | ||
|
||
import javafx.beans.InvalidationListener; | ||
import javafx.beans.Observable; | ||
import javafx.beans.binding.ListBinding; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
|
||
/** | ||
* @author Nicolas Feybesse | ||
* | ||
* @param <T> | ||
*/ | ||
public class ObservableInheritanceComputer2<T extends DefaultGeneric<T>> extends ListBinding<T> { | ||
|
||
private Set<Observable> invalidators = new HashSet<Observable>();; | ||
|
||
private final T base; | ||
private final T origin; | ||
private final int level; | ||
|
||
public ObservableInheritanceComputer2(T base, T origin, int level) { | ||
this.base = base; | ||
this.origin = origin; | ||
this.level = level; | ||
} | ||
|
||
public static int i = 0; | ||
|
||
@Override | ||
protected ObservableList<T> computeValue() { | ||
invalidators.forEach(this::unbind); | ||
invalidators = new HashSet<Observable>(); | ||
List<T> internal = new InheritanceComputer<T>(base, origin, level) { | ||
private static final long serialVersionUID = 4269874133078234506L; | ||
|
||
@Override | ||
protected Inheritings buildInheritings(T superVertex) { | ||
return new Inheritings(superVertex) { | ||
@Override | ||
protected Stream<T> compositesByMeta(T holder) { | ||
ObservableList<T> ol = localBase.getObservableComposites(); | ||
ol.addListener((InvalidationListener) c -> System.out.println("zzzzzzzzzzzzz" + i + " " + localBase + " " + holder)); | ||
ObservableList<T> filtered = ol.filtered(x -> !x.equals(holder) && x.getMeta().equals(holder)); | ||
filtered.addListener((InvalidationListener) c -> System.out.println("ffffffffffff" + i + " " + localBase + " " + holder)); | ||
i++; | ||
invalidators.add(filtered); | ||
return filtered.stream(); | ||
} | ||
|
||
@Override | ||
protected Stream<T> compositesBySuper(T holder) { | ||
ObservableList<T> ol = localBase.getObservableComposites(); | ||
ObservableList<T> filtered = ol.filtered(x -> x.getSupers().contains(holder)); | ||
invalidators.add(filtered); | ||
return filtered.stream(); | ||
} | ||
}; | ||
|
||
}; | ||
}.inheritanceStream().collect(Collectors.toList()); | ||
invalidators.forEach(this::bind); | ||
return FXCollections.unmodifiableObservableList(FXCollections.observableList(internal)); | ||
} | ||
|
||
} |