Sets the expanded state of this JTree . If state is true, all parents of path and path are marked as expanded. If state is false, all parents of path are marked EXPANDED, but path itself is marked collapsed. This will fa
(TreePath path, boolean state)
| 3551 | * This will fail if a <code>TreeWillExpandListener</code> vetos it. |
| 3552 | */ |
| 3553 | protected void setExpandedState(TreePath path, boolean state) { |
| 3554 | if(path != null) { |
| 3555 | // Make sure all parents of path are expanded. |
| 3556 | Stack<TreePath> stack; |
| 3557 | TreePath parentPath = path.getParentPath(); |
| 3558 | |
| 3559 | if (expandedStack.size() == 0) { |
| 3560 | stack = new Stack<TreePath>(); |
| 3561 | } |
| 3562 | else { |
| 3563 | stack = expandedStack.pop(); |
| 3564 | } |
| 3565 | |
| 3566 | try { |
| 3567 | while(parentPath != null) { |
| 3568 | if(isExpanded(parentPath)) { |
| 3569 | parentPath = null; |
| 3570 | } |
| 3571 | else { |
| 3572 | stack.push(parentPath); |
| 3573 | parentPath = parentPath.getParentPath(); |
| 3574 | } |
| 3575 | } |
| 3576 | for(int counter = stack.size() - 1; counter >= 0; counter--) { |
| 3577 | parentPath = stack.pop(); |
| 3578 | if(!isExpanded(parentPath)) { |
| 3579 | try { |
| 3580 | fireTreeWillExpand(parentPath); |
| 3581 | } catch (ExpandVetoException eve) { |
| 3582 | // Expand vetoed! |
| 3583 | return; |
| 3584 | } |
| 3585 | expandedState.put(parentPath, Boolean.TRUE); |
| 3586 | fireTreeExpanded(parentPath); |
| 3587 | if (accessibleContext != null) { |
| 3588 | ((AccessibleJTree)accessibleContext). |
| 3589 | fireVisibleDataPropertyChange(); |
| 3590 | } |
| 3591 | } |
| 3592 | } |
| 3593 | } |
| 3594 | finally { |
| 3595 | if (expandedStack.size() < TEMP_STACK_SIZE) { |
| 3596 | stack.removeAllElements(); |
| 3597 | expandedStack.push(stack); |
| 3598 | } |
| 3599 | } |
| 3600 | if(!state) { |
| 3601 | // collapse last path. |
| 3602 | Object cValue = expandedState.get(path); |
| 3603 | |
| 3604 | if(cValue != null && ((Boolean)cValue).booleanValue()) { |
| 3605 | try { |
| 3606 | fireTreeWillCollapse(path); |
| 3607 | } |
| 3608 | catch (ExpandVetoException eve) { |
| 3609 | return; |
| 3610 | } |
no test coverage detected