Java Code Examples for javax.swing.tree.TreeNode#getChildAt()

The following examples show how to use javax.swing.tree.TreeNode#getChildAt() . 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: SdkListConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void apply() throws ConfigurationException {
  boolean modifiedSdks = false;
  for (int i = 0; i < myRoot.getChildCount(); i++) {
    final TreeNode groupNode = myRoot.getChildAt(i);

    for (int k = 0; k < groupNode.getChildCount(); k++) {
      final MyNode sdkNode = (MyNode)groupNode.getChildAt(k);
      final NamedConfigurable configurable = sdkNode.getConfigurable();
      if (configurable.isModified()) {
        configurable.apply();
        modifiedSdks = true;
      }
    }
  }

  if (mySdksModel.isModified() || modifiedSdks) mySdksModel.apply(this);
}
 
Example 2
Source File: VisualizerNodeTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testLazyFilterGet() throws Exception {
    LazyChildren lch = new LazyChildren();
    AbstractNode a = new AbstractNode(lch);
    FilterNode fnode = new FilterNode(a);
    
    TreeNode ta = Visualizer.findVisualizer(fnode);
    
    assertEquals("Child check", "c", ta.getChildAt(2).toString());
    assertEquals("Counter should be 1", 1, lch.cnt);

    VisualizerNode vn = (VisualizerNode)ta.getChildAt(2);
    String msg = ((VisualizerNode)ta).getChildren().dumpIndexes(vn);
    if (msg.indexOf("'c'") == -1) {
        fail("Missing note about visualizer node 'c': " + msg);
    }
}
 
Example 3
Source File: CheckTreeNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean areSiblingsFullyChecked() {
    TreeNode parent = getParent();

    for (int i = 0; i < parent.getChildCount(); i++) {
        TreeNode node = parent.getChildAt(i);

        if (node == this) {
            continue;
        }

        if (!(node instanceof CheckTreeNode) || (((CheckTreeNode) node).getCheckState() != STATE_CHECKED)) {
            return false;
        }
    }

    return true;
}
 
Example 4
Source File: CheckTreeNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean areSiblingsUnchecked() {
    TreeNode parent = getParent();

    for (int i = 0; i < parent.getChildCount(); i++) {
        TreeNode node = parent.getChildAt(i);

        if (node == this) {
            continue;
        }

        if (!(node instanceof CheckTreeNode) || (((CheckTreeNode) node).getCheckState() != STATE_UNCHECKED)) {
            return false;
        }
    }

    return true;
}
 
Example 5
Source File: StandardTreePopupMenu.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
private boolean showAll(TreePath root, TreePath sub, boolean expand) {
	TreeNode node = (TreeNode)sub.getLastPathComponent();
	
	for (int i = 0; i < node.getChildCount(); ++i) {
		TreeNode child = node.getChildAt(i);
		if (child.isLeaf())
			continue;
		
		if (showAll(root, sub.pathByAddingChild(child), expand))
			return true;
	}
	
	if (root == sub)
		return false;
	
	return expand ? tree.isCollapsed(sub) : tree.isExpanded(sub);
}
 
Example 6
Source File: Model.java    From Luyten with Apache License 2.0 6 votes vote down vote up
@Override
public void treeExpanded(final TreeExpansionEvent event) {
	final TreePath treePath = event.getPath();

	final Object expandedTreePathObject = treePath.getLastPathComponent();
	if (!(expandedTreePathObject instanceof TreeNode)) {
		return;
	}

	final TreeNode expandedTreeNode = (TreeNode) expandedTreePathObject;
	if (expandedTreeNode.getChildCount() == 1) {
		final TreeNode descendantTreeNode = expandedTreeNode.getChildAt(0);

		if (descendantTreeNode.isLeaf()) {
			return;
		}

		final TreePath nextTreePath = treePath.pathByAddingChild(descendantTreeNode);
		tree.expandPath(nextTreePath);
	}
}
 
Example 7
Source File: MainView.java    From HiJson with Apache License 2.0 6 votes vote down vote up
/**
 * 复制相似路径节点键值对.
 * @param treeNode
 * @return 
 */
public String copySimilarPathKeyValue(TreeNode treeNode){
    String str = "";
    String key = Kit.pstr(treeNode.toString())[1];
    TreeNode node = treeNode.getParent();
    if(node==null) return "";
    node = node.getParent();
    if(node == null) return "";
    int count = node.getChildCount();
    int size = 0;
    for(int i = 0; i < count; i++){
        TreeNode child = node.getChildAt(i);
        if(child==null) continue;
        size = child.getChildCount();
        for(int i2 = 0; i2 < size; i2++){
            TreeNode tmp = child.getChildAt(i2);
            if(tmp==null)continue;
            String arr[] = Kit.pstr(tmp.toString());
            if(key!=null && key.equals(arr[1])){
                str += arr[2] + "\n";
            }
        }
    }
    return str;
}
 
Example 8
Source File: AquaLocationSourceList.java    From pumpernickel with MIT License 6 votes vote down vote up
protected static DefaultMutableTreeNode findNode(TreeNode node,
		Object userObject) {
	if (node instanceof DefaultMutableTreeNode) {
		Object obj = ((DefaultMutableTreeNode) node).getUserObject();
		if (obj == null && userObject == null)
			return (DefaultMutableTreeNode) node;
		if (obj.equals(userObject))
			return (DefaultMutableTreeNode) node;
	}
	for (int a = 0; a < node.getChildCount(); a++) {
		TreeNode child = node.getChildAt(a);
		DefaultMutableTreeNode hit = findNode(child, userObject);
		if (hit != null)
			return hit;
	}
	return null;
}
 
Example 9
Source File: CheckTreeNode.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private boolean areSiblingsUnchecked() {
    TreeNode parent = getParent();

    for (int i = 0; i < parent.getChildCount(); i++) {
        TreeNode node = parent.getChildAt(i);

        if (node == this) {
            continue;
        }

        if (!(node instanceof CheckTreeNode) || (((CheckTreeNode) node).getCheckState() != STATE_UNCHECKED)) {
            return false;
        }
    }

    return true;
}
 
Example 10
Source File: CheckTreeNode.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private boolean areSiblingsFullyChecked() {
    TreeNode parent = getParent();

    for (int i = 0; i < parent.getChildCount(); i++) {
        TreeNode node = parent.getChildAt(i);

        if (node == this) {
            continue;
        }

        if (!(node instanceof CheckTreeNode) || (((CheckTreeNode) node).getCheckState() != STATE_CHECKED)) {
            return false;
        }
    }

    return true;
}
 
Example 11
Source File: ProjectLibraryEditor.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
protected void saveMenus(TreeNode e) {
  if (e instanceof MenuEditor)
    getProjectLibrary().activityBag.addActivity(((MenuEditor) e).getMenu());
  for (int i = 0; i < e.getChildCount(); i++)
    if (e.getChildAt(i) instanceof MenuEditor)
      saveMenus(e.getChildAt(i));
}
 
Example 12
Source File: TreePanel.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void expandAll(JTree tree, TreePath path) {
	TreeNode node = (TreeNode) path.getLastPathComponent();
	for (int i = 0; i < node.getChildCount(); i++) {
		TreeNode child = node.getChildAt(i);
		expandAll(tree, path.pathByAddingChild(child));
	}
	tree.expandPath(path);
}
 
Example 13
Source File: MainWindow.java    From jadx with Apache License 2.0 5 votes vote down vote up
public static void getExpandedPaths(JTree tree, TreePath path, List<TreePath> list) {
	if (tree.isExpanded(path)) {
		list.add(path);

		TreeNode node = (TreeNode) path.getLastPathComponent();
		for (int i = node.getChildCount() - 1; i >= 0; i--) {
			TreeNode n = node.getChildAt(i);
			TreePath child = path.pathByAddingChild(n);
			getExpandedPaths(tree, child, list);
		}
	}
}
 
Example 14
Source File: UsageViewTreeModelBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static TreeNode getFirstChildOfType(TreeNode parent, final Class type) {
  final int childCount = parent.getChildCount();
  for (int idx = 0; idx < childCount; idx++) {
    final TreeNode child = parent.getChildAt(idx);
    if (type.isAssignableFrom(child.getClass())) {
      return child;
    }
    final TreeNode firstChildOfType = getFirstChildOfType(child, type);
    if (firstChildOfType != null) {
      return firstChildOfType;
    }
  }
  return null;
}
 
Example 15
Source File: XpathGenerator.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private static String getPosition(IOSTreeNode node) {
    int count = 0;
    TreeNode parent = node.getParent();
    String nodeName = node.getAttribute("tag");
    for (int i = 0; i < parent.getChildCount(); i++) {
        IOSTreeNode currNode = (IOSTreeNode) parent.getChildAt(i);
        if (currNode.getAttribute("tag").equals(nodeName)) {
            count++;
            if (currNode.equals(node)) {
                return nodeName + "[" + count + "]";
            }
        }
    }
    return nodeName;
}
 
Example 16
Source File: XpathGenerator.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private static String getPosition(AndroidTreeNode node) {
    int count = 0;
    TreeNode parent = node.getParent();
    String nodeName = node.getClassName();
    for (int i = 0; i < parent.getChildCount(); i++) {
        AndroidTreeNode currNode = (AndroidTreeNode) parent.getChildAt(i);
        if (currNode.getClassName().equals(nodeName)) {
            count++;
            if (currNode.equals(node)) {
                return nodeName + "[" + count + "]";
            }
        }
    }
    return nodeName;
}
 
Example 17
Source File: RevertDeletedAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<StoreEntryNode> getSelectedNodes(TreeNode node) {
    List<StoreEntryNode> ret = new LinkedList<StoreEntryNode>();
    int count = node.getChildCount();
    for (int i = 0; i < count; i++) {
        TreeNode child = node.getChildAt(i);
        if(child instanceof StoreEntryNode) {
            StoreEntryNode sen = (StoreEntryNode) child;
            if(sen.isSelected()) {
                ret.add(sen);
            }
        }
        ret.addAll(getSelectedNodes(child));
    }
    return ret;
}
 
Example 18
Source File: JCheckBoxTree.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 4 votes vote down vote up
public TreeNode getChildAt(TreeNode parent, int index) {
    return parent.getChildAt(index);
}
 
Example 19
Source File: ConfigTreeModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Returns the child of <code>parent</code> at index <code>index</code> in the parent's child array.
 * <code>parent</code> must be a node previously obtained from this data source. This should not return
 * <code>null</code> if <code>index</code> is a valid index for <code>parent</code> (that is <code>index >= 0 && index
 * < getChildCount(parent</code>)).
 *
 * @param parent a node in the tree, obtained from this data source
 * @param index  the index from where to read the child.
 * @return the child of <code>parent</code> at index <code>index</code>
 */
public Object getChild( final Object parent, final int index ) {
  final TreeNode node = (TreeNode) parent;
  return node.getChildAt( index );
}
 
Example 20
Source File: SwingExtensions.java    From groovy with Apache License 2.0 2 votes vote down vote up
/**
 * Support the subscript operator for TreeNode.
 *
 * @param self  a TreeNode
 * @param index the index of the child node to get
 * @return the child node at the given index
 * @since 1.6.4
 */
public static TreeNode getAt(TreeNode self, int index) {
    return self.getChildAt(index);
}