Craig Raw
5 years ago
13 changed files with 189 additions and 31 deletions
@ -1 +1 @@ |
|||
Subproject commit 7871413573e67ed7539cf03d6deadd1a2c4abafa |
|||
Subproject commit 11978e1f48851cd964f1c5f52a29a8e2ea432432 |
@ -0,0 +1,72 @@ |
|||
package com.sparrowwallet.sparrow.control; |
|||
|
|||
import javafx.collections.ListChangeListener; |
|||
import javafx.collections.ObservableList; |
|||
import javafx.scene.Node; |
|||
import javafx.scene.control.TreeItem; |
|||
import javafx.util.Callback; |
|||
|
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
public class RecursiveTreeItem<T> extends TreeItem<T> { |
|||
private final Callback<T, ObservableList<T>> childrenFactory; |
|||
private final Callback<T, Node> graphicsFactory; |
|||
|
|||
public RecursiveTreeItem(Callback<T, ObservableList<T>> childrenFactory){ |
|||
this(null, childrenFactory); |
|||
} |
|||
|
|||
public RecursiveTreeItem(final T value, Callback<T, ObservableList<T>> childrenFactory){ |
|||
this(value, (item) -> null, childrenFactory); |
|||
} |
|||
|
|||
public RecursiveTreeItem(final T value, Callback<T, Node> graphicsFactory, Callback<T, ObservableList<T>> childrenFactory){ |
|||
super(value, graphicsFactory.call(value)); |
|||
|
|||
this.graphicsFactory = graphicsFactory; |
|||
this.childrenFactory = childrenFactory; |
|||
|
|||
if(value != null) { |
|||
addChildrenListener(value); |
|||
} |
|||
|
|||
valueProperty().addListener((obs, oldValue, newValue)->{ |
|||
if(newValue != null){ |
|||
addChildrenListener(newValue); |
|||
} |
|||
}); |
|||
|
|||
this.setExpanded(true); |
|||
} |
|||
|
|||
private void addChildrenListener(T value){ |
|||
final ObservableList<T> children = childrenFactory.call(value); |
|||
|
|||
children.forEach(child -> RecursiveTreeItem.this.getChildren().add( |
|||
new RecursiveTreeItem<>(child, this.graphicsFactory, childrenFactory))); |
|||
|
|||
children.addListener((ListChangeListener<T>) change -> { |
|||
while(change.next()){ |
|||
|
|||
if(change.wasAdded()){ |
|||
change.getAddedSubList().forEach(t-> RecursiveTreeItem.this.getChildren().add( |
|||
new RecursiveTreeItem<>(t, this.graphicsFactory, childrenFactory))); |
|||
} |
|||
|
|||
if(change.wasRemoved()){ |
|||
change.getRemoved().forEach(t->{ |
|||
final List<TreeItem<T>> itemsToRemove = RecursiveTreeItem.this |
|||
.getChildren() |
|||
.stream() |
|||
.filter(treeItem -> treeItem.getValue().equals(t)) |
|||
.collect(Collectors.toList()); |
|||
|
|||
RecursiveTreeItem.this.getChildren().removeAll(itemsToRemove); |
|||
}); |
|||
} |
|||
|
|||
} |
|||
}); |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
package com.sparrowwallet.sparrow.event; |
|||
|
|||
import com.sparrowwallet.sparrow.wallet.NodeEntry; |
|||
|
|||
public class ReceiveToEvent { |
|||
private final NodeEntry receiveEntry; |
|||
|
|||
public ReceiveToEvent(NodeEntry receiveEntry) { |
|||
this.receiveEntry = receiveEntry; |
|||
} |
|||
|
|||
public NodeEntry getReceiveEntry() { |
|||
return receiveEntry; |
|||
} |
|||
} |
Loading…
Reference in new issue