/** * Adds a new child in the {@linkplain #getChildren() children list}. * The default implementation first checks that this node is not a leaf, * then delegates to the {@code Node(Node)} constructor. * That constructor call has the following implications: * * <ul> * <li>The new node inherits the columns of this node, on the assumption that * they are the same set of columns than other children nodes.</li> * <li>The new node is appended at the end of the children list.</li> * </ul> * * Subclasses may override this method with different behavior. * * @throws UnsupportedOperationException if this node {@linkplain #isLeaf() is a leaf}. */ @Override public Node newChild() { if (isLeaf()) { throw new UnsupportedOperationException(Errors.format(Errors.Keys.NodeIsLeaf_1, this)); } return new Node(this); }
/** * Adds a new child in the {@linkplain #getChildren() children list}. * The default implementation first checks that this node is not a leaf, * then delegates to the {@code Node(Node)} constructor. * That constructor call has the following implications: * * <ul> * <li>The new node inherits the columns of this node, on the assumption that * they are the same set of columns than other children nodes.</li> * <li>The new node is appended at the end of the children list.</li> * </ul> * * Subclasses may override this method with different behavior. * * @throws UnsupportedOperationException if this node {@linkplain #isLeaf() is a leaf}. */ @Override public Node newChild() { if (isLeaf()) { throw new UnsupportedOperationException(Errors.format(Errors.Keys.NodeIsLeaf_1, this)); } return new Node(this); }
final TreeTable.Node node = new DefaultTreeTable.Node(table); matcher.region(indexOfValue, endOfLine); for (int ci=0; ci<columns.length; ci++) {
final TreeTable.Node node = new DefaultTreeTable.Node(table); matcher.region(indexOfValue, endOfLine); for (int ci=0; ci<columns.length; ci++) {
final TableColumn<String> valueB = new TableColumn<>(String .class, "value #2"); final DefaultTreeTable table = new DefaultTreeTable(NAME, valueA, valueB); final TreeTable.Node root = new DefaultTreeTable.Node(table); root.setValue(NAME, "Node #1"); root.setValue(valueA, 10); root.setValue(valueB, "Value #1B"); final TreeTable.Node branch1 = new DefaultTreeTable.Node(table); branch1.setValue(NAME, "Node #2"); branch1.setValue(valueA, 20); root.getChildren().add(branch1); final TreeTable.Node branch2 = new DefaultTreeTable.Node(table); branch2.setValue(NAME, "Node #3"); branch2.setValue(valueB, "Value #3B"); root.getChildren().add(branch2); final TreeTable.Node leaf = new DefaultTreeTable.Node(table); leaf.setValue(NAME, "Node #4"); leaf.setValue(valueA, 40);
assertEquals("titleProperty", -1, children.titleProperty); final DefaultTreeTable.Node toAdd = new DefaultTreeTable.Node(new DefaultTreeTable( TableColumn.IDENTIFIER, TableColumn.VALUE));
final DefaultTreeTable.Node root = new DefaultTreeTable.Node(table); assertSame("Internal table sharing:", table.columnIndices, root.columnIndices); assertTrue("Initial children list:", root.getChildren().isEmpty()); final DefaultTreeTable.Node node2 = new DefaultTreeTable.Node(node1, 0); assertSame("Internal table sharing:", table.columnIndices, node2.columnIndices); assertTrue("Initial children list:", node2.getChildren().isEmpty());
final TableColumn<String> value = new TableColumn<>(String.class, "value"); final DefaultTreeTable table = new DefaultTreeTable(value); final TreeTable.Node root = new DefaultTreeTable.Node(table); root.setValue(value, "Value #1"); final TreeTable.Node branch1 = new DefaultTreeTable.Node(table); branch1.setValue(value, "Value #2"); root.getChildren().add(branch1); final TreeTable.Node branch2 = new DefaultTreeTable.Node(table); branch2.setValue(value, "Value #3"); root.getChildren().add(branch2); final TreeTable.Node leaf = new DefaultTreeTable.Node(table); leaf.setValue(value, "val #4\twith tab\nand a new line"); branch1.getChildren().add(leaf);
/** * Tests the formatting as a tree, with control on the indentation. */ @Test public void testTreeFormat() { final DefaultTreeTable.Node root = new DefaultTreeTable.Node("Node #1"); final DefaultTreeTable.Node branch = new DefaultTreeTable.Node("Node #2"); root.getChildren().add(branch); root.getChildren().add(new DefaultTreeTable.Node("Node #3")); branch.getChildren().add(new DefaultTreeTable.Node("Node #4")); final TreeTableFormat tf = new TreeTableFormat(null, null); tf.setVerticalLinePosition(2); assertMultilinesEquals( "Node #1\n" + " ├─Node #2\n" + " │ └─Node #4\n" + " └─Node #3\n", tf.format(new DefaultTreeTable(root))); }
/** * Tests {@link DefaultTreeTable.Node#setValue(TableColumn, Object)}. */ @Test public void testNodeValues() { final DefaultTreeTable table = new DefaultTreeTable(NAME, TYPE); final TreeTable.Node node = new DefaultTreeTable.Node(table); assertNull(node.getValue(NAME)); assertNull(node.getValue(TYPE)); node.setValue(NAME, "A number"); node.setValue(TYPE, Number.class); assertEquals("A number", node.getValue(NAME)); assertEquals(Number.class, node.getValue(TYPE)); } }
/** * Returns the root node. This method returns the node specified at * {@linkplain #DefaultTreeTable(Node) construction time} or to the * last call of the {@link #setRoot(TreeTable.Node)} method. */ @Override public TreeTable.Node getRoot() { if (root == null) { root = new Node(this); } return root; }
/** * Returns the root node. This method returns the node specified at * {@linkplain #DefaultTreeTable(Node) construction time} or to the * last call of the {@link #setRoot(TreeTable.Node)} method. */ @Override public TreeTable.Node getRoot() { if (root == null) { root = new Node(this); } return root; }