javax.swing.event.TreeModelEvent Java Examples

The following examples show how to use javax.swing.event.TreeModelEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BugTreeModel.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void sortBranch(TreePath pathToBranch) {
    BugSet bs = bugSet.query((BugAspects) pathToBranch.getLastPathComponent());
    bs.sortList();
    Debug.println("Data in sorted branch: " + pathToBranch.getLastPathComponent());
    for (BugLeafNode b : bs) {
        Debug.println(b);
    }

    Object[] children = new Object[getChildCount(pathToBranch.getLastPathComponent())];
    int[] childIndices = new int[children.length];
    for (int x = 0; x < children.length; x++) {
        children[x] = getChild(pathToBranch.getLastPathComponent(), x);
        childIndices[x] = x;
    }
    for (TreeModelListener l : listeners) {
        TreeModelEvent event = new TreeModelEvent(this, pathToBranch, childIndices, children);
        l.treeNodesChanged(event);
    }

}
 
Example #2
Source File: MasterReportDataTreeModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void fireParameterRemoved( final ParameterDefinitionEntry parameter ) {
  final TreePath pathForNode = new TreePath( new Object[] { getRoot(), getReportParametersNode() } );
  final TreeModelListener[] treeModelListeners = getListeners();
  final int index = findParameterInCache( parameter );
  if ( index == -1 ) {
    return;
  }

  final TreeModelEvent treeEvent = new TreeModelEvent( this, pathForNode,
    new int[] { index }, new Object[] { parameter } );
  for ( int i = treeModelListeners.length - 1; i >= 0; i -= 1 ) {
    final TreeModelListener listener = treeModelListeners[ i ];
    listener.treeNodesRemoved( treeEvent );
  }

  refreshParameterCache();
}
 
Example #3
Source File: NodeProjectGroup.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Nonnull
public NodeProject addProjectFolder(@Nonnull final File folder) throws IOException {
  NodeProject newProject = findForFolder(folder);
  if (newProject == null) {
    newProject = new NodeProject(this, folder);

    final int index = this.children.size();
    this.children.add(newProject);

    final TreeModelEvent event = new TreeModelEvent(this, new Object[]{this}, new int[]{index}, new Object[]{newProject});
    for (final TreeModelListener l : this.listeners) {
      l.treeNodesInserted(event);
    }
  }
  return newProject;
}
 
Example #4
Source File: ProgramTreeModelListener.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Method called when nodes are being inserted into the tree; update the treePath and the 
 * group path fields in the ProgramNode object.
 */
@Override
public void treeNodesInserted(TreeModelEvent e) {

	Object[] path = e.getPath();
	Object[] me = e.getChildren();

	// build the tree path for the node being inserted
	Object[] childPath = new Object[path.length + 1];
	System.arraycopy(path, 0, childPath, 0, path.length);
	childPath[childPath.length - 1] = me[0];

	ProgramNode node = (ProgramNode) me[0];

	node.setTreePath(new TreePath(childPath));

	// set up GroupPath
	tree.setGroupPath(node);
}
 
Example #5
Source File: JTreeTable.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void treeNodesChanged(TreeModelEvent e)
{
	TreePath parentPath = e.getTreePath();
	int leadingRow = Integer.MAX_VALUE;
	int trailingRow = -1;
	if (e.getChildren() != null)
	{
		for (Object node : e.getChildren())
		{
			TreePath childPath = parentPath.pathByAddingChild(node);
			int row = tree.getRowForPath(childPath);
			leadingRow = Math.min(leadingRow, row);
			trailingRow = Math.max(trailingRow, row);
		}
	}
	fireTableRowsUpdated(leadingRow, trailingRow);
}
 
Example #6
Source File: GTreeModel.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private TreeModelEvent getChangedNodeEvent(GTreeNode changedNode) {
	GTreeNode parentNode = changedNode.getParent();
	if (parentNode == null) { // tree requires different event form when it is the root that changes
		return new TreeModelEvent(this, root.getTreePath(), null, null);
	}

	GTreeNode node = convertToViewNode(changedNode);
	if (node == null) {
		return null;
	}

	int indexInParent = node.getIndexInParent();
	if (indexInParent < 0) {
		return null;
	}

	return new TreeModelEvent(this, node.getParent().getTreePath(), new int[] { indexInParent },
		new Object[] { changedNode });

}
 
Example #7
Source File: GTreeModel.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public void fireNodeAdded(final GTreeNode parentNode, final GTreeNode newNode) {
	if (!eventsEnabled) {
		return;
	}
	SystemUtilities.assertThisIsTheSwingThread(
		"GTreeModel.fireNodeAdded() must be " + "called from the AWT thread");

	GTreeNode parent = convertToViewNode(parentNode);
	if (parent == null) {  // it will be null if filtered out
		return;
	}

	int index = parent.getIndexOfChild(newNode);
	if (index < 0) {
		// the index will be -1 if filtered out
		return;
	}
	TreeModelEvent event = new TreeModelEvent(this, parent.getTreePath(), new int[] { index },
		new Object[] { newNode });
	for (TreeModelListener listener : listeners) {
		listener.treeNodesInserted(event);
	}
}
 
Example #8
Source File: FixedHeightLayoutCache.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Invoked after nodes have been removed from the tree.  Note that
 * if a subtree is removed from the tree, this method may only be
 * invoked once for the root of the removed subtree, not once for
 * each individual set of siblings removed.</p>
 *
 * <p>e.path() returns the former parent of the deleted nodes.</p>
 *
 * <p>e.childIndices() returns the indices the nodes had before they were deleted in ascending order.</p>
 */
public void treeNodesRemoved(TreeModelEvent e) {
    if(e != null) {
        int                  changedIndexs[];
        int                  maxCounter;
        TreePath             parentPath = SwingUtilities2.getTreePath(e, getModel());
        FHTreeStateNode      changedParentNode = getNodeForPath
                                   (parentPath, false, false);

        changedIndexs = e.getChildIndices();
        // PENDING(scott): make sure that changedIndexs are sorted in
        // ascending order.
        if(changedParentNode != null && changedIndexs != null &&
           (maxCounter = changedIndexs.length) > 0) {
            Object[]           children = e.getChildren();
            boolean            isVisible =
                (changedParentNode.isVisible() &&
                 changedParentNode.isExpanded());

            for(int counter = maxCounter - 1; counter >= 0; counter--) {
                changedParentNode.removeChildAtModelIndex
                                 (changedIndexs[counter], isVisible);
            }
            if(isVisible) {
                if(treeSelectionModel != null)
                    treeSelectionModel.resetRowSelection();
                if (treeModel.getChildCount(changedParentNode.
                                            getUserObject()) == 0 &&
                              changedParentNode.isLeaf()) {
                    // Node has become a leaf, collapse it.
                    changedParentNode.collapse(false);
                }
                visibleNodesChanged();
            }
            else if(changedParentNode.isVisible())
                visibleNodesChanged();
        }
    }
}
 
Example #9
Source File: WidgetTreeModel.java    From DroidUIBuilder with Apache License 2.0 5 votes vote down vote up
public void removeWidget(Widget w)
{
	Layout parent = w.getParent();
	Object[] path = findPath(parent);
	int index = parent.getWidgets().indexOf(w);
	fireNodeRemovedEvent(new TreeModelEvent(this, path,
			new int[] { index }, new Object[] { w }));
}
 
Example #10
Source File: LookTreeModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void fireDisplayChange(LookTreeNode source) {
    if (listeners.isEmpty()) {
        return;
    }
    LookTreeNode parent = source.getParent();
    TreePath path = findPath(parent != null ? parent : source);
    int[] childIndices = parent != null ? new int[] {getIndexOfChild(parent, source)} : null;
    Object[] children = parent != null ? new Object[] {source} : null;
    TreeModelEvent ev = new TreeModelEvent(this, path, childIndices, children);
    for (TreeModelListener l : listeners) {
        l.treeNodesChanged(ev);
    }
}
 
Example #11
Source File: LayerTreeModel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
protected void fireTreeNodesRemoved(Layer parentLayer) {
    TreeModelEvent event = createTreeModelEvent(parentLayer);
    if (event == null) {
        return;
    }
    for (TreeModelListener treeModelListener : treeModelListeners.keySet()) {
        treeModelListener.treeNodesRemoved(event);
    }
}
 
Example #12
Source File: FixedHeightLayoutCache.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Invoked after nodes have been removed from the tree.  Note that
 * if a subtree is removed from the tree, this method may only be
 * invoked once for the root of the removed subtree, not once for
 * each individual set of siblings removed.</p>
 *
 * <p>e.path() returns the former parent of the deleted nodes.</p>
 *
 * <p>e.childIndices() returns the indices the nodes had before they were deleted in ascending order.</p>
 */
public void treeNodesRemoved(TreeModelEvent e) {
    if(e != null) {
        int                  changedIndexs[];
        int                  maxCounter;
        TreePath             parentPath = SwingUtilities2.getTreePath(e, getModel());
        FHTreeStateNode      changedParentNode = getNodeForPath
                                   (parentPath, false, false);

        changedIndexs = e.getChildIndices();
        // PENDING(scott): make sure that changedIndexs are sorted in
        // ascending order.
        if(changedParentNode != null && changedIndexs != null &&
           (maxCounter = changedIndexs.length) > 0) {
            Object[]           children = e.getChildren();
            boolean            isVisible =
                (changedParentNode.isVisible() &&
                 changedParentNode.isExpanded());

            for(int counter = maxCounter - 1; counter >= 0; counter--) {
                changedParentNode.removeChildAtModelIndex
                                 (changedIndexs[counter], isVisible);
            }
            if(isVisible) {
                if(treeSelectionModel != null)
                    treeSelectionModel.resetRowSelection();
                if (treeModel.getChildCount(changedParentNode.
                                            getUserObject()) == 0 &&
                              changedParentNode.isLeaf()) {
                    // Node has become a leaf, collapse it.
                    changedParentNode.collapse(false);
                }
                visibleNodesChanged();
            }
            else if(changedParentNode.isVisible())
                visibleNodesChanged();
        }
    }
}
 
Example #13
Source File: LanguagesNavigatorModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void fireRemove(ASTNavigatorNode node, int[] indices, ASTNavigatorNode[] children,
        LinkedList<ASTNavigatorNode> nodePath) {
    TreeModelListener[] listeners = listenerList.getListeners (TreeModelListener.class);
    if (listeners.length == 0) return;
    TreePath path = new TreePath(nodePath.toArray());
    TreeModelEvent e = new TreeModelEvent (this, path, indices, children);
    for (int i = 0; i < listeners.length; i++)
        listeners [i].treeNodesRemoved (e);
}
 
Example #14
Source File: NodeProjectGroup.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
public boolean deleteNode(@Nonnull final NodeFileOrFolder node, final boolean notifyListeners) {
  final NodeFileOrFolder parentNode = node.getNodeParent();
  if (parentNode != null) {
    final TreeModelEvent event = new TreeModelEvent(this, parentNode.makeTreePath(), new int[]{node.getIndexAtParent()}, new Object[]{node});
    if (parentNode.deleteChild(node)) {
      if (notifyListeners) {
        for (final TreeModelListener l : this.listeners) {
          l.treeNodesRemoved(event);
        }
      }
      return true;
    }
  }
  return false;
}
 
Example #15
Source File: LayerTreeModel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
protected void fireTreeNodeChanged(Layer layer) {
    TreeModelEvent event = createTreeModelEvent(layer);
    if (event == null) {
        return;
    }
    for (TreeModelListener treeModelListener : treeModelListeners.keySet()) {
        treeModelListener.treeNodesChanged(event);
    }
}
 
Example #16
Source File: EventBroadcaster.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates an identical TreeModelEvent with the model we are proxying
 * as the event source */
private TreeModelEvent translateEvent (TreeModelEvent e) {
    //Create a new TreeModelEvent with us as the source
    TreeModelEvent nue = new TreeModelEvent (getModel(), e.getPath(), 
        e.getChildIndices(), e.getChildren());
    return nue;
}
 
Example #17
Source File: FixedHeightLayoutCache.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Invoked after nodes have been inserted into the tree.</p>
 *
 * <p>e.path() returns the parent of the new nodes
 * <p>e.childIndices() returns the indices of the new nodes in
 * ascending order.
 */
public void treeNodesInserted(TreeModelEvent e) {
    if(e != null) {
        int[]               changedIndexs;
        FHTreeStateNode     changedParent = getNodeForPath
                              (SwingUtilities2.getTreePath(e, getModel()), false, false);
        int                 maxCounter;

        changedIndexs = e.getChildIndices();
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if(changedParent != null && changedIndexs != null &&
           (maxCounter = changedIndexs.length) > 0) {
            boolean          isVisible =
                (changedParent.isVisible() &&
                 changedParent.isExpanded());

            for(int counter = 0; counter < maxCounter; counter++) {
                changedParent.childInsertedAtModelIndex
                    (changedIndexs[counter], isVisible);
            }
            if(isVisible && treeSelectionModel != null)
                treeSelectionModel.resetRowSelection();
            if(changedParent.isVisible())
                this.visibleNodesChanged();
        }
    }
}
 
Example #18
Source File: ScoreTree.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void refreshPath (TreePath path)
{
    TreeModelEvent modelEvent = new TreeModelEvent(this, path);

    for (TreeModelListener listener : listeners) {
        listener.treeStructureChanged(modelEvent);
    }
}
 
Example #19
Source File: FixedHeightLayoutCache.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Invoked after nodes have been removed from the tree.  Note that
 * if a subtree is removed from the tree, this method may only be
 * invoked once for the root of the removed subtree, not once for
 * each individual set of siblings removed.</p>
 *
 * <p>e.path() returns the former parent of the deleted nodes.</p>
 *
 * <p>e.childIndices() returns the indices the nodes had before they were deleted in ascending order.</p>
 */
public void treeNodesRemoved(TreeModelEvent e) {
    if(e != null) {
        int                  changedIndexs[];
        int                  maxCounter;
        TreePath             parentPath = SwingUtilities2.getTreePath(e, getModel());
        FHTreeStateNode      changedParentNode = getNodeForPath
                                   (parentPath, false, false);

        changedIndexs = e.getChildIndices();
        // PENDING(scott): make sure that changedIndexs are sorted in
        // ascending order.
        if(changedParentNode != null && changedIndexs != null &&
           (maxCounter = changedIndexs.length) > 0) {
            Object[]           children = e.getChildren();
            boolean            isVisible =
                (changedParentNode.isVisible() &&
                 changedParentNode.isExpanded());

            for(int counter = maxCounter - 1; counter >= 0; counter--) {
                changedParentNode.removeChildAtModelIndex
                                 (changedIndexs[counter], isVisible);
            }
            if(isVisible) {
                if(treeSelectionModel != null)
                    treeSelectionModel.resetRowSelection();
                if (treeModel.getChildCount(changedParentNode.
                                            getUserObject()) == 0 &&
                              changedParentNode.isLeaf()) {
                    // Node has become a leaf, collapse it.
                    changedParentNode.collapse(false);
                }
                visibleNodesChanged();
            }
            else if(changedParentNode.isVisible())
                visibleNodesChanged();
        }
    }
}
 
Example #20
Source File: FixedHeightLayoutCache.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Invoked after a node (or a set of siblings) has changed in some
 * way. The node(s) have not changed locations in the tree or
 * altered their children arrays, but other attributes have
 * changed and may affect presentation. Example: the name of a
 * file has changed, but it is in the same location in the file
 * system.</p>
 *
 * <p>e.path() returns the path the parent of the changed node(s).</p>
 *
 * <p>e.childIndices() returns the index(es) of the changed node(s).</p>
 */
public void treeNodesChanged(TreeModelEvent e) {
    if(e != null) {
        int                 changedIndexs[];
        FHTreeStateNode     changedParent = getNodeForPath
                              (SwingUtilities2.getTreePath(e, getModel()), false, false);
        int                 maxCounter;

        changedIndexs = e.getChildIndices();
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if (changedParent != null) {
            if (changedIndexs != null &&
                (maxCounter = changedIndexs.length) > 0) {
                Object       parentValue = changedParent.getUserObject();

                for(int counter = 0; counter < maxCounter; counter++) {
                    FHTreeStateNode    child = changedParent.
                             getChildAtModelIndex(changedIndexs[counter]);

                    if(child != null) {
                        child.setUserObject(treeModel.getChild(parentValue,
                                                 changedIndexs[counter]));
                    }
                }
                if(changedParent.isVisible() && changedParent.isExpanded())
                    visibleNodesChanged();
            }
            // Null for root indicates it changed.
            else if (changedParent == root && changedParent.isVisible() &&
                     changedParent.isExpanded()) {
                visibleNodesChanged();
            }
        }
    }
}
 
Example #21
Source File: FixedHeightLayoutCache.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Invoked after nodes have been inserted into the tree.</p>
 *
 * <p>e.path() returns the parent of the new nodes
 * <p>e.childIndices() returns the indices of the new nodes in
 * ascending order.
 */
public void treeNodesInserted(TreeModelEvent e) {
    if(e != null) {
        int                 changedIndexs[];
        FHTreeStateNode     changedParent = getNodeForPath
                              (SwingUtilities2.getTreePath(e, getModel()), false, false);
        int                 maxCounter;

        changedIndexs = e.getChildIndices();
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if(changedParent != null && changedIndexs != null &&
           (maxCounter = changedIndexs.length) > 0) {
            boolean          isVisible =
                (changedParent.isVisible() &&
                 changedParent.isExpanded());

            for(int counter = 0; counter < maxCounter; counter++) {
                changedParent.childInsertedAtModelIndex
                    (changedIndexs[counter], isVisible);
            }
            if(isVisible && treeSelectionModel != null)
                treeSelectionModel.resetRowSelection();
            if(changedParent.isVisible())
                this.visibleNodesChanged();
        }
    }
}
 
Example #22
Source File: FixedHeightLayoutCache.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Invoked after a node (or a set of siblings) has changed in some
 * way. The node(s) have not changed locations in the tree or
 * altered their children arrays, but other attributes have
 * changed and may affect presentation. Example: the name of a
 * file has changed, but it is in the same location in the file
 * system.</p>
 *
 * <p>e.path() returns the path the parent of the changed node(s).</p>
 *
 * <p>e.childIndices() returns the index(es) of the changed node(s).</p>
 */
public void treeNodesChanged(TreeModelEvent e) {
    if(e != null) {
        int                 changedIndexs[];
        FHTreeStateNode     changedParent = getNodeForPath
                              (SwingUtilities2.getTreePath(e, getModel()), false, false);
        int                 maxCounter;

        changedIndexs = e.getChildIndices();
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if (changedParent != null) {
            if (changedIndexs != null &&
                (maxCounter = changedIndexs.length) > 0) {
                Object       parentValue = changedParent.getUserObject();

                for(int counter = 0; counter < maxCounter; counter++) {
                    FHTreeStateNode    child = changedParent.
                             getChildAtModelIndex(changedIndexs[counter]);

                    if(child != null) {
                        child.setUserObject(treeModel.getChild(parentValue,
                                                 changedIndexs[counter]));
                    }
                }
                if(changedParent.isVisible() && changedParent.isExpanded())
                    visibleNodesChanged();
            }
            // Null for root indicates it changed.
            else if (changedParent == root && changedParent.isVisible() &&
                     changedParent.isExpanded()) {
                visibleNodesChanged();
            }
        }
    }
}
 
Example #23
Source File: FixedHeightLayoutCache.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Invoked after nodes have been inserted into the tree.</p>
 *
 * <p>e.path() returns the parent of the new nodes
 * <p>e.childIndices() returns the indices of the new nodes in
 * ascending order.
 */
public void treeNodesInserted(TreeModelEvent e) {
    if(e != null) {
        int                 changedIndexs[];
        FHTreeStateNode     changedParent = getNodeForPath
                              (SwingUtilities2.getTreePath(e, getModel()), false, false);
        int                 maxCounter;

        changedIndexs = e.getChildIndices();
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if(changedParent != null && changedIndexs != null &&
           (maxCounter = changedIndexs.length) > 0) {
            boolean          isVisible =
                (changedParent.isVisible() &&
                 changedParent.isExpanded());

            for(int counter = 0; counter < maxCounter; counter++) {
                changedParent.childInsertedAtModelIndex
                    (changedIndexs[counter], isVisible);
            }
            if(isVisible && treeSelectionModel != null)
                treeSelectionModel.resetRowSelection();
            if(changedParent.isVisible())
                this.visibleNodesChanged();
        }
    }
}
 
Example #24
Source File: ConfigTreeModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Informs all listeners, that the tree's contents have changed.
 */
private void fireTreeModelChanged() {
  for ( int i = 0; i < listeners.size(); i++ ) {
    final TreeModelListener l = listeners.get( i );
    l.treeStructureChanged( new TreeModelEvent( this, new TreePath( root ) ) );
  }
}
 
Example #25
Source File: ScoreTree.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void refreshAll ()
{
    nodeMap.clear();

    TreeModelEvent modelEvent = new TreeModelEvent(
            this,
            new Object[]{score});

    for (TreeModelListener listener : listeners) {
        listener.treeStructureChanged(modelEvent);
    }
}
 
Example #26
Source File: FixedHeightLayoutCache.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Invoked after nodes have been removed from the tree.  Note that
 * if a subtree is removed from the tree, this method may only be
 * invoked once for the root of the removed subtree, not once for
 * each individual set of siblings removed.</p>
 *
 * <p>e.path() returns the former parent of the deleted nodes.</p>
 *
 * <p>e.childIndices() returns the indices the nodes had before they were deleted in ascending order.</p>
 */
public void treeNodesRemoved(TreeModelEvent e) {
    if(e != null) {
        int                  changedIndexs[];
        int                  maxCounter;
        TreePath             parentPath = SwingUtilities2.getTreePath(e, getModel());
        FHTreeStateNode      changedParentNode = getNodeForPath
                                   (parentPath, false, false);

        changedIndexs = e.getChildIndices();
        // PENDING(scott): make sure that changedIndexs are sorted in
        // ascending order.
        if(changedParentNode != null && changedIndexs != null &&
           (maxCounter = changedIndexs.length) > 0) {
            Object[]           children = e.getChildren();
            boolean            isVisible =
                (changedParentNode.isVisible() &&
                 changedParentNode.isExpanded());

            for(int counter = maxCounter - 1; counter >= 0; counter--) {
                changedParentNode.removeChildAtModelIndex
                                 (changedIndexs[counter], isVisible);
            }
            if(isVisible) {
                if(treeSelectionModel != null)
                    treeSelectionModel.resetRowSelection();
                if (treeModel.getChildCount(changedParentNode.
                                            getUserObject()) == 0 &&
                              changedParentNode.isLeaf()) {
                    // Node has become a leaf, collapse it.
                    changedParentNode.collapse(false);
                }
                visibleNodesChanged();
            }
            else if(changedParentNode.isVisible())
                visibleNodesChanged();
        }
    }
}
 
Example #27
Source File: ProfilerTreeTable.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public void treeStructureChanged(TreeModelEvent e) {
    tree.setChangingModel(true);
    try { notifyTable(); }
    finally { tree.setChangingModel(false); }
}
 
Example #28
Source File: VariableHeightLayoutCache.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invoked after the tree has drastically changed structure from a
 * given node down.  If the path returned by <code>e.getPath</code>
 * is of length one and the first element does not identify the
 * current root node the first element should become the new root
 * of the tree.
 *
 * <p><code>e.path</code> holds the path to the node.
 * <p><code>e.childIndices</code> returns <code>null</code>.
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeStructureChanged(TreeModelEvent e) {
    if(e != null)
    {
        TreePath          changedPath = SwingUtilities2.getTreePath(e, getModel());
        TreeStateNode     changedNode;

        changedNode = getNodeForPath(changedPath, false, false);

        // Check if root has changed, either to a null root, or
        // to an entirely new root.
        if(changedNode == root ||
           (changedNode == null &&
            ((changedPath == null && treeModel != null &&
              treeModel.getRoot() == null) ||
             (changedPath != null && changedPath.getPathCount() == 1)))) {
            rebuild(true);
        }
        else if(changedNode != null) {
            int                              nodeIndex, oldRow;
            TreeStateNode                    newNode, parent;
            boolean                          wasExpanded, wasVisible;
            int                              newIndex;

            wasExpanded = changedNode.isExpanded();
            wasVisible = (changedNode.getRow() != -1);
            /* Remove the current node and recreate a new one. */
            parent = (TreeStateNode)changedNode.getParent();
            nodeIndex = parent.getIndex(changedNode);
            if(wasVisible && wasExpanded) {
                changedNode.collapse(false);
            }
            if(wasVisible)
                visibleNodes.removeElement(changedNode);
            changedNode.removeFromParent();
            createNodeAt(parent, nodeIndex);
            newNode = (TreeStateNode)parent.getChildAt(nodeIndex);
            if(wasVisible && wasExpanded)
                newNode.expand(false);
            newIndex = newNode.getRow();
            if(!isFixedRowHeight() && wasVisible) {
                if(newIndex == 0)
                    updateYLocationsFrom(newIndex);
                else
                    updateYLocationsFrom(newIndex - 1);
                this.visibleNodesChanged();
            }
            else if(wasVisible)
                this.visibleNodesChanged();
        }
    }
}
 
Example #29
Source File: VariableHeightLayoutCache.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Invoked after the tree has drastically changed structure from a
 * given node down.  If the path returned by <code>e.getPath</code>
 * is of length one and the first element does not identify the
 * current root node the first element should become the new root
 * of the tree.
 *
 * <p><code>e.path</code> holds the path to the node.
 * <p><code>e.childIndices</code> returns <code>null</code>.
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeStructureChanged(TreeModelEvent e) {
    if(e != null)
    {
        TreePath          changedPath = SwingUtilities2.getTreePath(e, getModel());
        TreeStateNode     changedNode;

        changedNode = getNodeForPath(changedPath, false, false);

        // Check if root has changed, either to a null root, or
        // to an entirely new root.
        if(changedNode == root ||
           (changedNode == null &&
            ((changedPath == null && treeModel != null &&
              treeModel.getRoot() == null) ||
             (changedPath != null && changedPath.getPathCount() == 1)))) {
            rebuild(true);
        }
        else if(changedNode != null) {
            int                              nodeIndex, oldRow;
            TreeStateNode                    newNode, parent;
            boolean                          wasExpanded, wasVisible;
            int                              newIndex;

            wasExpanded = changedNode.isExpanded();
            wasVisible = (changedNode.getRow() != -1);
            /* Remove the current node and recreate a new one. */
            parent = (TreeStateNode)changedNode.getParent();
            nodeIndex = parent.getIndex(changedNode);
            if(wasVisible && wasExpanded) {
                changedNode.collapse(false);
            }
            if(wasVisible)
                visibleNodes.removeElement(changedNode);
            changedNode.removeFromParent();
            createNodeAt(parent, nodeIndex);
            newNode = (TreeStateNode)parent.getChildAt(nodeIndex);
            if(wasVisible && wasExpanded)
                newNode.expand(false);
            newIndex = newNode.getRow();
            if(!isFixedRowHeight() && wasVisible) {
                if(newIndex == 0)
                    updateYLocationsFrom(newIndex);
                else
                    updateYLocationsFrom(newIndex - 1);
                this.visibleNodesChanged();
            }
            else if(wasVisible)
                this.visibleNodesChanged();
        }
    }
}
 
Example #30
Source File: FilterTreeModel.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private void fireTreeNodesInserted(TreeModelEvent treeModelEvent) {
    for (TreeModelListener listener : listeners) {
        listener.treeNodesInserted(treeModelEvent);
    }
}