use of javafx.scene.control.TreeItem in project ariADDna by StnetixDevTeam.
the class TreeViewFactory method get.
/**
* temporary method
*
* @return
*/
public TreeView get() {
TreeView<String> tree = new TreeView<>();
tree.setShowRoot(false);
TreeItem<String> root = new TreeItem<>("");
tree.setRoot(root);
ChangeListener<Boolean> expandedListener = (obs, wasExpanded, isNowExpanded) -> {
if (isNowExpanded) {
System.out.println("expand");
ReadOnlyProperty<?> expandedProperty = (ReadOnlyProperty<?>) obs;
Object itemThatWasJustExpanded = expandedProperty.getBean();
for (TreeItem<String> item : tree.getRoot().getChildren()) {
if (item != itemThatWasJustExpanded) {
item.setExpanded(false);
}
}
}
};
for (int i = 1; i <= 4; i++) {
TreeItem<String> item = new TreeItem<>("Top level " + i);
item.expandedProperty().addListener(expandedListener);
root.getChildren().add(item);
for (int j = 1; j <= 4; j++) {
TreeItem<String> subItem = new TreeItem<>("Sub item " + i + ":" + j);
item.getChildren().add(subItem);
}
}
PseudoClass subElementPseudoClass = PseudoClass.getPseudoClass("sub-tree-item");
tree.setCellFactory((TreeView<String> tv) -> {
TreeCell<String> cell = new TreeCell<String>() {
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setDisclosureNode(null);
if (empty) {
setText("");
setGraphic(null);
} else {
// appropriate text for item
setText(item);
}
}
};
cell.treeItemProperty().addListener((obs, oldTreeItem, newTreeItem) -> {
cell.pseudoClassStateChanged(subElementPseudoClass, newTreeItem != null && newTreeItem.getParent() != cell.getTreeView().getRoot());
});
return cell;
});
return tree;
}
use of javafx.scene.control.TreeItem in project DistributedFractalNetwork by Budder21.
the class FractalEditor method moveUp.
/**
* @param item
*/
private static void moveUp(TreeItem item) {
// TODO move layers up
System.out.println("moveUp");
if (item.getParent() instanceof TreeItem) {
TreeItem parent = item.getParent();
List<TreeItem> list = new ArrayList<TreeItem>();
Object prev = null;
for (Object child : parent.getChildren()) {
if (child == item) {
list.add((TreeItem) child);
} else {
if (prev != null)
list.add((TreeItem) prev);
prev = child;
}
}
if (prev != null)
list.add((TreeItem) prev);
parent.getChildren().clear();
parent.getChildren().addAll(list);
}
}
use of javafx.scene.control.TreeItem in project dwoss by gg-net.
the class TreeTableController method getCategoryProducts.
private ObservableList<TreeItem<DataWrapper>> getCategoryProducts(TradeName tradeName, ProductGroup group) {
ObservableList<TreeItem<DataWrapper>> result = FXCollections.observableArrayList();
for (CategoryProduct cp : loadCp(group, tradeName)) {
TreeItem<DataWrapper> item = new TreeItem<>();
CategoryProductWrapper categoryProductWrapper = new CategoryProductWrapper(item, cp);
item.setValue(categoryProductWrapper);
item.getChildren().add(loading);
item.expandedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if (categoryProductWrapper.isLoading()) {
return;
}
categoryProductWrapper.setLoading(true);
new Thread(new Runnable() {
@Override
public void run() {
item.getChildren().addAll(getProducts(cp));
item.getChildren().remove(loading);
}
}).start();
}
});
result.add(item);
}
return result;
}
use of javafx.scene.control.TreeItem in project dwoss by gg-net.
the class TreeTableController method getProducts.
private ObservableList<TreeItem<DataWrapper>> getProducts(CategoryProduct cp) {
ObservableList<TreeItem<DataWrapper>> result = FXCollections.observableArrayList();
for (Product product : loadProducts(cp)) {
TreeItem<DataWrapper> item = new TreeItem<>();
ProductWrapper productWrapper = new ProductWrapper(item, product);
item.setValue(productWrapper);
item.getChildren().add(loading);
item.expandedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if (productWrapper.isLoading()) {
return;
}
productWrapper.setLoading(true);
new Thread(new Runnable() {
@Override
public void run() {
item.getChildren().addAll(getUnitCollections(product));
item.getChildren().remove(loading);
}
}).start();
}
});
result.add(item);
}
return result;
}
use of javafx.scene.control.TreeItem in project dwoss by gg-net.
the class TreeTableController method getTradeNames.
private ObservableList<TreeItem<DataWrapper>> getTradeNames() {
ObservableList<TreeItem<DataWrapper>> result = FXCollections.observableArrayList();
for (TradeName tradeName : TradeName.values()) {
TreeItem<DataWrapper> item = new TreeItem<>(new TradeNameWrapper(tradeName));
item.getChildren().addAll(getProductGroups(tradeName));
result.add(item);
}
return result;
}
Aggregations