Commit a9d4dacd authored by legoc's avatar legoc
Browse files

Added Collapse Children on tree cells

parent 112fa2bc
......@@ -19,53 +19,76 @@ import javafx.scene.control.Tooltip;
*
*/
public class HierarchyCell extends CheckBoxTreeCell<Component> {
private Tooltip tooltip = new Tooltip();
public static final Callback<TreeView<Component>,TreeCell<Component>> FACTORY;
public static final Callback<TreeView<Component>, TreeCell<Component>> FACTORY;
static {
FACTORY = new Callback<TreeView<Component>,TreeCell<Component>>(){
@Override
public TreeCell<Component> call(TreeView<Component> p) {
return new HierarchyCell();
}
};
FACTORY = new Callback<TreeView<Component>, TreeCell<Component>>() {
@Override
public TreeCell<Component> call(TreeView<Component> p) {
return new HierarchyCell();
}
};
}
private ContextMenu rigthClickMenu = new ContextMenu();
public HierarchyCell() {
super();
MenuItem printItem = new MenuItem("Print infos");
rigthClickMenu.getItems().add(printItem);
printItem.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
System.out.print(getItem().infoString());
}
});
}
MenuItem printItem = new MenuItem("Collapse Children");
rigthClickMenu.getItems().add(printItem);
printItem.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
// Get the component.
Component component = getItem();
// Iterate the children but do not collapse the component itself.
for (Component child : component.getChildren()) {
collapseAll(child);
}
}
});
}
@Override
public void updateItem(Component item, boolean empty) {
super.updateItem(item, empty);
if (empty || isEditing()) {
return;
}
else {
String text = item.getName();
if (item.getAxis().getController() != null) {
text += " (" + item.getAxis().getController().getName() + ")";
}
setText(text);
setContextMenu(rigthClickMenu);
tooltip.setText(item.getName());
setTooltip(tooltip);
}
}
public void updateItem(Component item, boolean empty) {
super.updateItem(item, empty);
if (empty || isEditing()) {
return;
} else {
String text = item.getName();
if (item.getAxis().getController() != null) {
text += " (" + item.getAxis().getController().getName() + ")";
}
setText(text);
setContextMenu(rigthClickMenu);
tooltip.setText(item.getName());
setTooltip(tooltip);
}
}
/**
* Collapses all the tree item children.
* @param component the component to collapse
*/
private static void collapseAll(Component component) {
// Set expanded to false.
component.getTreeItem().setExpanded(false);
// Iterate the children.
for (Component child : component.getChildren()) {
collapseAll(child);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment