/** Creates a new instance of DefaultOutlineModel. <strong><b>Note</b> * Do not fire table structure changes from the wrapped TableModel (value * changes are okay). Changes that affect the number of rows must come * from the TreeModel. * @param treeModel The tree model * @param tableModel The table model * @param largeModel <code>true</code> if it's a large model tree, <code>false</code> otherwise. * @param nodesColumnLabel Label of the node's column */ protected DefaultOutlineModel(TreeModel treeModel, TableModel tableModel, boolean largeModel, String nodesColumnLabel) { this.treeModel = treeModel; this.tableModel = tableModel; if (nodesColumnLabel != null) { this.nodesColumnLabel = nodesColumnLabel; } layout = largeModel ? (AbstractLayoutCache) new FixedHeightLayoutCache() : (AbstractLayoutCache) new VariableHeightLayoutCache(); broadcaster = new EventBroadcaster (this); layout.setRootVisible(true); layout.setModel(this); treePathSupport = new TreePathSupport(this, layout); treePathSupport.addTreeExpansionListener(broadcaster); treePathSupport.addTreeWillExpandListener(broadcaster); treeModel.addTreeModelListener(broadcaster); tableModel.addTableModelListener(broadcaster); if (tableModel instanceof ProxyTableModel) { ((ProxyTableModel) tableModel).setOutlineModel(this); } }
public void testGetPathForRow() { TreePath p = new TreePath(new Object[] { root, node2 }); assertTrue(tree.isRootVisible()); assertNull(ui.getPathForRow(tree, 7)); assertEquals(p, ui.treeState.getPathForRow(2)); assertEquals(p, ui.getPathForRow(new JTree(), 2)); tree.expandPath(p); assertEquals(new TreePath(new Object[] { root, node2, node22 }), ui.getPathForRow(tree, 4)); assertEquals(new TreePath(new Object[] { root, node3 }), ui.getPathForRow(tree, 5)); ui.treeState = new VariableHeightLayoutCache() { @Override public TreePath getPathForRow(final int row) { return new TreePath(new Object[] { node3 }); } }; assertEquals(new TreePath(new Object[] { node3 }), ui.getPathForRow(tree, -400)); assertEquals(ui.treeState.getPathForRow(2), ui.getPathForRow(tree, 5)); }
public void testGetRowCount() { assertTrue(tree.isRootVisible()); assertEquals(4, ui.treeState.getRowCount()); assertEquals(4, ui.getRowCount(new JTree())); TreePath p = new TreePath(new Object[] { root, node2 }); tree.expandPath(p); assertEquals(6, ui.getRowCount(tree)); ui.treeState = new VariableHeightLayoutCache() { @Override public int getRowCount() { return -200; } }; assertEquals(ui.getRowCount(new JTree()), ui.treeState.getRowCount()); assertEquals(-200, ui.getRowCount(tree)); }
public void testCreateLayoutCache() { tree.setRowHeight(0); assertNotNull(ui.createLayoutCache()); assertNotSame(ui.createLayoutCache(), ui.createLayoutCache()); assertTrue(ui.createLayoutCache() instanceof VariableHeightLayoutCache); assertTrue(ui.treeState instanceof VariableHeightLayoutCache); tree.setRowHeight(10); assertTrue(ui.createLayoutCache() instanceof VariableHeightLayoutCache); assertTrue(ui.treeState instanceof VariableHeightLayoutCache); tree.setRowHeight(0); tree.setLargeModel(true); assertTrue(ui.createLayoutCache() instanceof VariableHeightLayoutCache); assertTrue(ui.treeState instanceof VariableHeightLayoutCache); tree.setRowHeight(10); assertTrue(ui.createLayoutCache() instanceof FixedHeightLayoutCache); assertTrue(ui.treeState instanceof FixedHeightLayoutCache); }
public void testUpdateExpandedDescendants() { TreePath pathToExpand = new TreePath(tree.getModel().getRoot()) .pathByAddingChild(node1); tree.expandPath(pathToExpand); assertTrue(ui.treeState.isExpanded(pathToExpand)); ui.treeState = new VariableHeightLayoutCache(); ui.treeState.setModel(tree.getModel()); assertFalse(ui.treeState.isExpanded(pathToExpand)); ui.updateExpandedDescendants(new TreePath(tree.getModel().getRoot())); assertTrue(ui.treeState.isExpanded(pathToExpand)); }
public void testConfigureLayoutCache() { TreePath expandedPath = new TreePath(tree.getModel().getRoot()) .pathByAddingChild(node1); tree.expandPath(expandedPath); ui.treeState = new VariableHeightLayoutCache(); ui.configureLayoutCache(); assertSame(tree.getModel(), ui.treeState.getModel()); assertSame(tree.getSelectionModel(), ui.treeState.getSelectionModel()); assertSame(ui.nodeDimensions, ui.treeState.getNodeDimensions()); assertEquals(tree.getRowHeight(), ui.treeState.getRowHeight()); assertTrue(ui.treeState.isExpanded(expandedPath)); assertTrue(ui.treeState.isRootVisible()); }
protected AbstractLayoutCache createLayoutCache() { return rowHeight > 0 && largeModel ? (AbstractLayoutCache)new FixedHeightLayoutCache() : (AbstractLayoutCache)new VariableHeightLayoutCache(); }
/** * Creates the object responsible for managing what is expanded, as well as * the size of nodes. * * @return the object responsible for managing what is expanded. */ protected AbstractLayoutCache createLayoutCache() { return new VariableHeightLayoutCache(); }