Java Code Examples for javax.swing.event.TreeModelEvent#getTreePath()

The following examples show how to use javax.swing.event.TreeModelEvent#getTreePath() . 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: 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 2
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 3
Source File: StructureViewComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void treeNodesInserted(TreeModelEvent e) {
  TreePath parentPath = e.getTreePath();
  if (Boolean.TRUE.equals(UIUtil.getClientProperty(tree, STRUCTURE_VIEW_STATE_RESTORED_KEY))) return;
  if (parentPath == null || parentPath.getPathCount() > autoExpandDepth.asInteger() - 1) return;
  Object[] children = e.getChildren();
  if (smartExpand && children.length == 1) {
    expandLater(parentPath, children[0]);
  }
  else {
    for (Object o : children) {
      NodeDescriptor descriptor = TreeUtil.getUserObject(NodeDescriptor.class, o);
      if (descriptor != null && isAutoExpandNode(descriptor)) {
        expandLater(parentPath, o);
      }
    }
  }
}
 
Example 4
Source File: TodoPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void treeNodesInserted(TreeModelEvent e) {
  TreePath parentPath = e.getTreePath();
  if (parentPath == null || parentPath.getPathCount() > 2) return;
  Object[] children = e.getChildren();
  for (Object o : children) {
    NodeDescriptor descriptor = TreeUtil.getUserObject(NodeDescriptor.class, o);
    if (descriptor != null && myBuilder.isAutoExpandNode(descriptor)) {
      ApplicationManager.getApplication().invokeLater(() -> {
        if (myTree.isVisible(parentPath) && myTree.isExpanded(parentPath)) {
          myTree.expandPath(parentPath.pathByAddingChild(o));
        }
      }, myBuilder.myProject.getDisposed());
    }
  }
}
 
Example 5
Source File: SelectionSaver.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void treeNodesRemoved(TreeModelEvent treeModelEvent) {
  TreePath pathToDelete = treeModelEvent.getTreePath();
  Object[] children = treeModelEvent.getChildren();

  for (int i = 0; i < children.length; i++) {
    Object nodeToDelete = children[i];
    if (myCurrentSelection.contains(nodeToDelete)){
      int deletedRow = myTree.getRowForPath(pathToDelete.pathByAddingChild(nodeToDelete));
      if (deletedRow == 0) return;
      TreePath treePath = new TreePath(myTree.getPathForRow(deletedRow - 1));
      myTree.getSelectionModel().addSelectionPath((TreePath)treePath.getLastPathComponent());
    }
  }

}
 
Example 6
Source File: DebuggingViewComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void treeNodesInserted(TreeModelEvent e) {
    TreePath path = e.getTreePath();
    checkIfWeShouldScrollToCurrentThread(path);
    refreshView(true);
}
 
Example 7
Source File: DefaultTreeCheckingModel.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
/**
        * Updates the check of the just inserted nodes.
        */
public void treeNodesInserted(TreeModelEvent e) {
    TreePath path = e.getTreePath();
    DefaultTreeCheckingModel.this.checkingMode.updateCheckAfterChildrenInserted(path);
}
 
Example 8
Source File: DefaultTreeCheckingModel.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
/**
        * Nothing to do if nodes were removed.
        */
public void treeNodesRemoved(TreeModelEvent e) {
    TreePath path = e.getTreePath();
    DefaultTreeCheckingModel.this.checkingMode.updateCheckAfterChildrenRemoved(path);
}
 
Example 9
Source File: DefaultTreeCheckingModel.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
/**
        * Updates the tree greyness in case of nodes changes.
        */
public void treeNodesChanged(TreeModelEvent e) {
    TreePath path = e.getTreePath();
    updateSubTreeGreyness(path);
    updateAncestorsGreyness(path);
}
 
Example 10
Source File: DefaultTreeCheckingModel.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
/**
        * Updates the tree greyness in case of structure changes.
        */
public void treeStructureChanged(TreeModelEvent e) {
    TreePath path = e.getTreePath();
    DefaultTreeCheckingModel.this.checkingMode.updateCheckAfterStructureChanged(path);
}
 
Example 11
Source File: AsyncTreeModel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void process(@Nonnull TreeModelEvent event, @Nonnull EventType type) {
  TreePath path = event.getTreePath();
  if (path == null) {
    // request a new root from model according to the specification
    processor.process(new CmdGetRoot("Reload root", null));
    return;
  }
  Object object = path.getLastPathComponent();
  if (object == null) {
    LOG.warn("unsupported path: " + path);
    return;
  }
  if (path.getParentPath() == null && type == EventType.StructureChanged) {
    // set a new root object according to the specification
    processor.process(new CmdGetRoot("Update root", object));
    return;
  }
  onValidThread(() -> {
    Node node = tree.map.get(object);
    if (node == null) {
      LOG.debug("ignore updating of nonexistent node: ", object);
    }
    else if (type == EventType.NodesChanged) {
      // the object is already updated, so we should not start additional command to update
      AsyncTreeModel.this.treeNodesChanged(event.getTreePath(), event.getChildIndices(), event.getChildren());
    }
    else if (node.isLoadingRequired()) {
      // update the object presentation only, if its children are not requested yet
      AsyncTreeModel.this.treeNodesChanged(event.getTreePath(), null, null);
    }
    else if (type == EventType.NodesInserted) {
      processor.process(new CmdGetChildren("Insert children", node, false));
    }
    else if (type == EventType.NodesRemoved) {
      processor.process(new CmdGetChildren("Remove children", node, false));
    }
    else {
      processor.process(new CmdGetChildren("Update children", node, true));
    }
  });
}