/** Expand a tree path */ public void expandPath (TreePath path) { getTreePathSupport().expandPath (path); }
public void collapsePath (TreePath path) { getTreePathSupport().collapsePath (path); }
/** Expand a path. Notifies the layout cache of the change, * stores the expanded path info (so reexpanding a parent node also reexpands * this path if a parent node containing it is later collapsed). Fires * TreeWillExpand and TreeExpansion events. */ public void expandPath (TreePath path) { if (Boolean.TRUE.equals(expandedPaths.get(path))) { //It's already expanded, don't waste cycles firing bogus events return; } TreeExpansionEvent e = new TreeExpansionEvent (this, path); try { fireTreeWillExpand(e, true); expandedPaths.put(path, Boolean.TRUE); layout.setExpandedState(path, true); fireTreeExpansion(e, true); } catch (ExpandVetoException eve) { fireTreeExpansionVetoed (e, eve); } }
/** 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. */ 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); } }
getTreePathSupport().expandPath(path); getTreePathSupport().collapsePath(path);
mdl.getTreePathSupport().addTreeWillExpandListener(expandingTreeListener);
public void addTreeExpansionListener( TreeExpansionListener l ) { TreePathSupport tps = getOutline().getOutlineModel().getTreePathSupport(); if( tps != null ) tps.addTreeExpansionListener(l); }
protected void removeDescendantToggledPaths(Enumeration toRemove) { if(toRemove != null) { while(toRemove.hasMoreElements()) { TreePath[] descendants = getDescendantToggledPaths( (TreePath) toRemove.nextElement()); for (int i=0; i < descendants.length; i++) { expandedPaths.remove(descendants[i]); } } } }
/** Process a structural change event from the user-supplied tree model. * This will result in a generic "something changed" * TableModelEvent being fired. */ public void treeStructureChanged(TreeModelEvent e) { assert SwingUtilities.isEventDispatchThread(); getLayout().treeStructureChanged(e); fireTreeChange (translateEvent(e), STRUCTURE_CHANGED); //If it's a structural change, we need to dump all our info about the //existing tree structure - it can be bogus now. Similar to JTree, //this will have the effect of collapsing all expanded paths. The //TreePathSupport takes care of dumping the layout cache's copy of //such data getTreePathSupport().clear(); //We will just fire a "Something happened. Go figure out what." event. fireTableChange (new TableModelEvent (getModel())); }
mdl.getTreePathSupport().addTreeWillExpandListener(expandingTreeListener);
/** Collapse a path. Notifies the layout cache of the change, * stores the expanded path info (so reexpanding a parent node also reexpands * this path if a parent node containing it is later collapsed). Fires * TreeWillExpand and TreeExpansion events. */ public void collapsePath (TreePath path) { if (Boolean.FALSE.equals(expandedPaths.get(path))) { //It's already collapsed, don't waste cycles firing bogus events return; } TreeExpansionEvent e = new TreeExpansionEvent (this, path); try { fireTreeWillExpand(e, false); expandedPaths.put(path, Boolean.FALSE); layout.setExpandedState(path, false); fireTreeExpansion(e, false); } catch (ExpandVetoException eve) { fireTreeExpansionVetoed (e, eve); } }
private void expandNode(DefaultMutableTreeNode treeNode, boolean recursive, int level) { if (treeNode.getAllowsChildren()) { if (treeNode.getChildCount() == 0) { TreePath path = new TreePath(treeNode.getPath()); mdl.getTreePathSupport().expandPath(path); } if (recursive && level <= MAX_LEVELS_TO_EXPAND) { for (int childIndex = 0; childIndex < treeNode.getChildCount(); childIndex++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) treeNode.getChildAt(childIndex); expandNode(child, recursive, level + 1); } } } }
private void expandNode(DefaultMutableTreeNode treeNode, boolean recursive, int level) { if (treeNode.getAllowsChildren()) { if (treeNode.getChildCount() == 0) { TreePath path = new TreePath(treeNode.getPath()); mdl.getTreePathSupport().expandPath(path); } if (recursive && level <= MAX_LEVELS_TO_EXPAND) { for (int childIndex = 0; childIndex < treeNode.getChildCount(); childIndex++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) treeNode.getChildAt(childIndex); expandNode(child, recursive, level + 1); } } } }