Java Code Examples for javax.swing.tree.TreeNode

The following are top voted examples for showing how to use javax.swing.tree.TreeNode. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: hml   File: TreePanel.java   Source Code and License 6 votes vote down vote up
private void expandAll(JTree tree, TreePath path, boolean expand) {
    TreeNode node = (TreeNode) path.getLastPathComponent();

    if (node.getChildCount() >= 0) {
        Enumeration enumeration = node.children();
        while (enumeration.hasMoreElements()) {
            TreeNode n = (TreeNode) enumeration.nextElement();
            TreePath p = path.pathByAddingChild(n);

            expandAll(tree, p, expand);
        }
    }

    if (expand) {
        tree.expandPath(path);
    } else {
        tree.collapsePath(path);
    }
}
 
Example 2
Project: incubator-netbeans   File: ASTBrowserTopComponent.java   Source Code and License 6 votes vote down vote up
private void initChildren () {
    if (children != null) return;
    children = new ArrayList<TreeNode> ();
    map = new HashMap<ASTItem,TreeNode> ();
    if (astItem == null) return;
    List<ASTItem> chList = astItem.getChildren ();
    
    if (chList != null) {
        Iterator<ASTItem> it = chList.iterator ();
        while (it.hasNext ()) {
            ASTItem item = it.next ();
            TreeNode tn = new TNode (this, item);
            children.add (tn);
            map.put (item, tn);
        }
    }
}
 
Example 3
Project: incubator-netbeans   File: ProfilerTreeTable.java   Source Code and License 6 votes vote down vote up
private Comparator getComparator() {
    SortOrder sortOrder = getSortOrder();
    if (SortOrder.UNSORTED.equals(sortOrder)) return null;
    
    final boolean ascending = SortOrder.ASCENDING.equals(sortOrder);
    final int sortColumn = getSortColumn();
    boolean sortingTree = JTree.class.equals(model.getColumnClass(sortColumn));
    final Comparator comparator = sortingTree ? null : getComparator(sortColumn);
    
    return new Comparator() {
        public int compare(Object o1, Object o2) {
            int result;
            if (comparator == null) {
                String s1 = o1.toString();
                String s2 = o2.toString();
                result = s1.compareTo(s2);
            } else {
                Object v1 = model.getValueAt((TreeNode)o1, sortColumn);
                Object v2 = model.getValueAt((TreeNode)o2, sortColumn);
                result = comparator.compare(v1, v2);
            }
            
            return ascending ? result : result * -1;
        }
    };
}
 
Example 4
Project: incubator-netbeans   File: ASTBrowserTopComponent.java   Source Code and License 6 votes vote down vote up
public void caretUpdate (CaretEvent e) {
    if (rootNode == null) return;
    ASTPath path = rootNode.findPath (e.getDot ());
    if (path == null) return;
    TreeNode tNode = (TreeNode) tree.getModel ().getRoot ();
    List<TreeNode> treePath = new ArrayList<TreeNode> ();
    Iterator it = path.listIterator ();
    if (!it.hasNext ()) return;
    it.next ();
    treePath.add (tNode);
    while (tNode instanceof TNode && it.hasNext ()) {
        tNode = ((TNode) tNode).getTreeNode (it.next ());
        if (tNode == null) throw new NullPointerException ();
        treePath.add (tNode);
    }
    TreePath treePath2 = new TreePath (treePath.toArray ());
    DefaultTreeModel model = new DefaultTreeModel ((TreeNode) tree.getModel ().getRoot ());
    tree.setModel (model);
    tree.setSelectionPath (treePath2);
    tree.scrollPathToVisible (treePath2);
}
 
Example 5
Project: openjdk-jdk10   File: ElementTreePanel.java   Source Code and License 6 votes vote down vote up
/**
 * Invoke this method after you've changed how node is to be
 * represented in the tree.
 */
@Override
public void nodeChanged(TreeNode node) {
    if (listenerList != null && node != null) {
        TreeNode parent = node.getParent();

        if (parent == null && node != root) {
            parent = root;
        }
        if (parent != null) {
            int anIndex = getIndexOfChild(parent, node);

            if (anIndex != -1) {
                int[] cIndexs = new int[1];

                cIndexs[0] = anIndex;
                nodesChanged(parent, cIndexs);
            }
        }
    }
}
 
Example 6
Project: marathonv5   File: AssertionTreeNode.java   Source Code and License 6 votes vote down vote up
@Override public TreeNode getChildAt(int index) {
    if (object instanceof List) {
        return getNodeForList((List<?>) object, index);
    }
    if (object instanceof Map) {
        return getNodeForMap((Map<?, ?>) object, index);
    }
    Method method;
    if (object instanceof RComponent) {
        Method o = ((RComponent) object).getMethods().get(index);
        method = o;
    } else {
        method = getMethods(object).get(index);
    }
    return getNodeForMethod(method);
}
 
Example 7
Project: Luyten4Forge   File: Model.java   Source Code and License 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 8
Project: incubator-netbeans   File: OutlineView152857Test.java   Source Code and License 6 votes vote down vote up
public void testRemoveNodeInOutlineView () throws InterruptedException {
    StringKeys children = new StringKeys (true);
    children.doSetKeys (new String [] {"1", "3", "2"});
    Node root = new TestNode (children, "root");
    comp = new OutlineViewComponent (root);
    ETableColumnModel etcm = (ETableColumnModel) comp.getOutlineView ().getOutline ().getColumnModel ();
    ETableColumn etc = (ETableColumn) etcm.getColumn (0); // tree column
    etcm.setColumnSorted (etc, true, 1); // ascending order

    TreeNode ta = Visualizer.findVisualizer(root);

    DialogDescriptor dd = new DialogDescriptor (comp, "", false, null);
    Dialog d = DialogDisplayer.getDefault ().createDialog (dd);
    d.setVisible (true);

    Thread.sleep (1000);
    ((StringKeys) root.getChildren ()).doSetKeys (new String [] {"1", "2"});
    Thread.sleep (1000);
    
    assertEquals ("Node on 0nd position is '1'", "1", ta.getChildAt (0).toString ());
    assertEquals ("Node on 1st position is '2'", "2", ta.getChildAt (1).toString ());

    d.setVisible (false);
}
 
Example 9
Project: incubator-netbeans   File: TreeTableView152857Test.java   Source Code and License 6 votes vote down vote up
public void testRemoveNodeInTTV () throws InterruptedException {
    StringKeys children = new StringKeys (true);
    children.doSetKeys (new String [] {"1", "3", "2"});
    Node root = new TestNode (children, "root");
    view = new TTV (root);
    TreeNode ta = Visualizer.findVisualizer(root);

    DialogDescriptor dd = new DialogDescriptor (view, "", false, null);
    Dialog d = DialogDisplayer.getDefault ().createDialog (dd);
    makeVisible(d);
    ((StringKeys) root.getChildren ()).doSetKeys (new String [] {"1", "2"});
    Thread.sleep (1000);

    assertEquals ("Node on 0nd position is '1'", "1", ta.getChildAt (0).toString ());
    assertEquals ("Node on 1st position is '2'", "2", ta.getChildAt (1).toString ());

    d.setVisible (false);
}
 
Example 10
Project: Cognizant-Intelligent-Test-Scripter   File: JCheckBoxTree.java   Source Code and License 6 votes vote down vote up
/**
 * iterate through every child and do the action
 *
 * @param parent
 * @param expand
 */
private void expandAll(TreePath parent, boolean expand) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (getChildCount(node) >= 0) {
        for (int i = 0; i < getChildCount(node); i++) {
            TreePath path = parent.pathByAddingChild(getChildAt(node, i));
            expandAll(path, expand);
        }
    }
    if (expand) {
        expandPath(parent);
    } else {
        collapsePath(parent);
    }

}
 
Example 11
Project: JavaGraph   File: StateTree.java   Source Code and License 6 votes vote down vote up
/**
 * Retrieves the child of a given parent node that is
 * a numbered tree node with a given number, if any.
 * @return the correctly numbered child, or {@code null} if there
 * is none such
 */
private NumberedTreeNode find(TreeNode parent, int number) {
    NumberedTreeNode result = null;
    int lower = 0;
    int upper = parent.getChildCount() - 1;
    boolean found = false;
    while (!found && lower <= upper) {
        int mid = (lower + upper) / 2;
        result = (NumberedTreeNode) parent.getChildAt(mid);
        int resultNumber = result.getNumber();
        if (result.contains(number)) {
            found = true;
        } else if (resultNumber < number) {
            lower = mid + 1;
        } else if (resultNumber > number) {
            upper = mid - 1;
        }
    }
    return found ? result : null;
}
 
Example 12
Project: incubator-netbeans   File: ManageInspectionsOperatot.java   Source Code and License 6 votes vote down vote up
private TreeNode[] getPath(Object node, String deap, String item, boolean debug) {
    if (node instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) node;
        if (debug) {
            System.out.println(deap + dmtn.toString());
        }
        if (dmtn.toString().equals(item)) {
            if (debug) {
                System.out.println("EQUAL!!! <" + item + ">");
            }
            return dmtn.getPath();
        }
        TreeNode[] curPath;
        for (int i = 0; i < dmtn.getChildCount(); i++) {
            curPath = getPath(dmtn.getChildAt(i), deap + "__", item, debug);
            if (curPath != null) {
                return curPath;
            }
        }
    }
    return null;
}
 
Example 13
Project: incubator-netbeans   File: Tab.java   Source Code and License 6 votes vote down vote up
private void scrollNodeToVisible( final Node n ) {
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            TreeNode tn = Visualizer.findVisualizer(n);
            if (tn == null) {
                return;
            }
            TreeModel model = tree.getModel();
            if (!(model instanceof DefaultTreeModel)) {
                return;
            }
            TreePath path = new TreePath(((DefaultTreeModel) model).getPathToRoot(tn));
            if( null == path )
                return;
            Rectangle r = tree.getPathBounds(path);
            if (r != null) {
                tree.scrollRectToVisible(r);
            }
        }
    });
}
 
Example 14
Project: incubator-netbeans   File: DirectoryChooserUI.java   Source Code and License 6 votes vote down vote up
private void applyEdit(DirectoryNode node) {
    TreeNode[] nodes = model.getPathToRoot(node);
    TreePath editingPath = new TreePath(nodes);
    tree.setEditable(true);
    tree.makeVisible(editingPath);
    tree.scrollPathToVisible(editingPath);
    tree.setSelectionPath(editingPath);
    tree.startEditingAtPath(editingPath);
    
    JTextField editField = DirectoryCellEditor.getTextField();
    editField.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    editField.setRequestFocusEnabled(true);
    editField.requestFocus();
    editField.setSelectionStart(0);
    editField.setSelectionEnd(editField.getText().length());
}
 
Example 15
Project: incubator-netbeans   File: AllocTreeTableView.java   Source Code and License 6 votes vote down vote up
protected SearchUtils.TreeHelper getSearchHelper() {
    return new SearchUtils.TreeHelper() {
        public int getNodeType(TreeNode tnode) {
            PresoObjAllocCCTNode node = (PresoObjAllocCCTNode)tnode;
            CCTNode parent = node.getParent();
            if (parent == null) return SearchUtils.TreeHelper.NODE_SKIP_DOWN; // invisible root
            
            if (parent.getParent() == null) {
                if (searchObjects) {
                    return searchAllocations ? SearchUtils.TreeHelper.NODE_SEARCH_DOWN :
                                               SearchUtils.TreeHelper.NODE_SEARCH_NEXT;
                } else {
                    return searchAllocations ? SearchUtils.TreeHelper.NODE_SKIP_DOWN :
                                               SearchUtils.TreeHelper.NODE_SKIP_NEXT;
                }
            }
            
            return searchAllocations ? SearchUtils.TreeHelper.NODE_SEARCH_DOWN :
                                       SearchUtils.TreeHelper.NODE_SKIP_NEXT;
        }
    };
}
 
Example 16
Project: Cognizant-Intelligent-Test-Scripter   File: JCheckBoxTree.java   Source Code and License 6 votes vote down vote up
private void resetCheckingState() {
    nodesCheckingState = new HashMap<>();
    checkedPaths = new ArrayList<TreePath>() {
        @Override
        public boolean add(TreePath e) {
            if (!contains(e)) {
                return super.add(e);
            }
            return false;
        }

    };
    if (getModel() == null) {
        return;
    }
    TreeNode node = (TreeNode) getModel().getRoot();
    if (node == null) {
        return;
    }
    addSubtreeToCheckingStateTracking(node);
}
 
Example 17
Project: incubator-netbeans   File: LivenessTreeTableView.java   Source Code and License 6 votes vote down vote up
protected SearchUtils.TreeHelper getSearchHelper() {
    return new SearchUtils.TreeHelper() {
        public int getNodeType(TreeNode tnode) {
            PresoObjAllocCCTNode node = (PresoObjAllocCCTNode)tnode;
            CCTNode parent = node.getParent();
            if (parent == null) return SearchUtils.TreeHelper.NODE_SKIP_DOWN; // invisible root
            
            if (parent.getParent() == null) {
                if (searchObjects) {
                    return searchAllocations ? SearchUtils.TreeHelper.NODE_SEARCH_DOWN :
                                               SearchUtils.TreeHelper.NODE_SEARCH_NEXT;
                } else {
                    return searchAllocations ? SearchUtils.TreeHelper.NODE_SKIP_DOWN :
                                               SearchUtils.TreeHelper.NODE_SKIP_NEXT;
                }
            }
            
            return searchAllocations ? SearchUtils.TreeHelper.NODE_SEARCH_DOWN :
                                       SearchUtils.TreeHelper.NODE_SKIP_NEXT;
        }
    };
}
 
Example 18
Project: incubator-netbeans   File: LivenessTreeTableView.java   Source Code and License 6 votes vote down vote up
public Object getValueAt(TreeNode node, int columnIndex) {
    PresoObjLivenessCCTNode livenessNode = (PresoObjLivenessCCTNode)node;
    
    if (selection == null) columnIndex++;
    
    if (columnIndex == 1) {
        return livenessNode.getNodeName();
    } else if (columnIndex == 2) {
        return livenessNode.totalObjSize;
    } else if (columnIndex == 3) {
        return livenessNode.nLiveObjects;
    } else if (columnIndex == 4) {
        return livenessNode.nCalls;
    } else if (columnIndex == 5) {
        return livenessNode.avgObjectAge;
    } else if (columnIndex == 6) {
        return livenessNode.survGen;
    } else if (columnIndex == 7) {
        return livenessNode.nTotalAllocObjects;
    } else if (columnIndex == 0) {
        if (selection.isEmpty()) return Boolean.FALSE;
        return selection.contains(nodesMap.get(node));
    }

    return null;
}
 
Example 19
Project: rapidminer   File: PlotConfigurationTreeTransferHandler.java   Source Code and License 6 votes vote down vote up
/**
 * @param container
 * @param comp
 * @param childIndex
 * @param container2
 */
private String canImportRangeAxis(Component container, TreeNode treeNode, int childIndex, Component container2) {
	String importAction = I18N.getGUILabel("plotter.drag_and_drop.axis_drop.move_axis");

	// RangeAxisConfigTreeNode can only be dropped on PlotConfigTreeNodes
	if (!(treeNode instanceof PlotConfigurationTreeNode)) {
		updateToolTip(container, I18N.getGUILabel("plotter.drag_and_drop.axis_drop.cant_drop_axis_config"));
		return null;
	}
	// can only be dropped below static dimension configs
	if (childIndex > -1 && childIndex < PlotConfigurationTreeModel.NUMBER_OF_PERMANENT_DIMENSIONS) {
		updateToolTip(container, I18N.getGUILabel("plotter.drag_and_drop.axis_drop.only_below_dims"));
		return null;
	}

	if (childIndex == -1) {
		return I18N.getGUILabel("plotter.drag_and_drop.axis_drop.move_to_end");
	}

	return importAction;
}
 
Example 20
Project: OpenJSharp   File: ElementTreePanel.java   Source Code and License 6 votes vote down vote up
/**
 * Invoke this method after you've changed how node is to be
 * represented in the tree.
 */
@Override
public void nodeChanged(TreeNode node) {
    if (listenerList != null && node != null) {
        TreeNode parent = node.getParent();

        if (parent == null && node != root) {
            parent = root;
        }
        if (parent != null) {
            int anIndex = getIndexOfChild(parent, node);

            if (anIndex != -1) {
                int[] cIndexs = new int[1];

                cIndexs[0] = anIndex;
                nodesChanged(parent, cIndexs);
            }
        }
    }
}
 
Example 21
Project: JavaGraph   File: DisplayTreeNode.java   Source Code and License 6 votes vote down vote up
@Override
public int compare(TreeNode o1, TreeNode o2) {
    int result = compare(o1 instanceof RecipeTreeNode, o2 instanceof RecipeTreeNode);
    if (result != 0) {
        return result;
    }
    result = compare(o1 instanceof ActionTreeNode, o2 instanceof ActionTreeNode);
    if (result != 0) {
        return result;
    }
    if (o1 instanceof ActionTreeNode) {
        result =
            compare(((ActionTreeNode) o2).isProperty(), ((ActionTreeNode) o1).isProperty());
        if (result != 0) {
            return result;
        }
    }
    return stringComparator.compare(o1.toString(), o2.toString());
}
 
Example 22
Project: Cognizant-Intelligent-Test-Scripter   File: JCheckBoxTree.java   Source Code and License 6 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
        boolean selected, boolean expanded, boolean leaf, int row,
        boolean hasFocus) {
    TreeNode node = (TreeNode) value;
    TreePath tp = new TreePath(getPath(node));
    CheckedNode cn = nodesCheckingState.get(tp);
    checkBox.setIcon(getIcon(value));
    if (cn == null) {
        return this;
    }
    checkBox.setSelected(cn.isSelected);
    checkBox.setText(node.toString());
    checkBox.setOpaque(cn.isSelected && cn.hasChildren && !cn.allChildrenSelected);
    return this;
}
 
Example 23
Project: incubator-netbeans   File: ProfilerTreeTable.java   Source Code and License 6 votes vote down vote up
TreePath getNextPath(TreePath path, boolean down) {
    TreeModel _model = model.treeModel;
    TreeNode node = (TreeNode)path.getLastPathComponent();
    if (down && _model.getChildCount(node) > 0)
        return path.pathByAddingChild(_model.getChild(node, 0));

    TreePath parentPath = path.getParentPath();
    if (!down && parentPath == null)
        return path.pathByAddingChild(_model.getChild(node, 0));
    
    TreeNode parent = (TreeNode)parentPath.getLastPathComponent();
    int idx = _model.getIndexOfChild(parent, node) + 1;

    if (_model.getChildCount(parent) > idx)
        return parentPath.pathByAddingChild(_model.getChild(parent, idx));

    if (!down && parentPath.getParentPath() == null) {
        return parentPath.pathByAddingChild(_model.getChild(parent, 0));
    } else {
        return getNextPath(parentPath, false);
    }
}
 
Example 24
Project: alevin-svn2   File: DefaultSelectionTreeModel.java   Source Code and License 5 votes vote down vote up
@Override
public Object getChild(Object parent, int index) {
	if (parent instanceof IProxy)
		return ((IProxy) parent).getChildAt(index);
	else if (parent instanceof TreeNode)
		return ((TreeNode) parent).getChildAt(index);
	else
		return null;
}
 
Example 25
Project: alevin-svn2   File: DefaultSelectionTreeModel.java   Source Code and License 5 votes vote down vote up
@Override
public int getChildCount(Object parent) {
	if (parent instanceof IProxy)
		return ((IProxy) parent).getChildCount();
	else if (parent instanceof TreeNode)
		return ((TreeNode) parent).getChildCount();
	else
		return 0;
}
 
Example 26
Project: JavaGraph   File: ResourceTree.java   Source Code and License 5 votes vote down vote up
@Override
public void mouseReleased(MouseEvent evt) {

    // find the node that belongs to this event
    TreeNode selected = getMousedNode(evt);

    // show popup menu
    if (evt.isPopupTrigger()) {
        showPopupMenu(selected, evt);
    }
}
 
Example 27
Project: incubator-netbeans   File: ProfilerTreeTable.java   Source Code and License 5 votes vote down vote up
public final boolean equals(Object o) {
    if (o == this) return true;
    if (!(o instanceof TreePathKey)) return false;
    
    TreeNode[] _pathToRoot = ((TreePathKey)o).pathToRoot;
    if (pathToRoot.length != _pathToRoot.length) return false;
    for (int i = pathToRoot.length - 1; i >= 0 ; i--)
        if (!pathToRoot[i].equals(_pathToRoot[i])) return false;
    
    return true;
}
 
Example 28
Project: incubator-netbeans   File: TreeView.java   Source Code and License 5 votes vote down vote up
/** Expands all paths.
*/
public void expandAll() {
    try {
        tree.setUI(null);
        TreeNode root = (TreeNode) tree.getModel().getRoot();
        expandOrCollapseAll(new TreePath(root), true);
    } finally {
        tree.updateUI();
    }
}
 
Example 29
Project: marathonv5   File: AssertionTreeNode.java   Source Code and License 5 votes vote down vote up
private TreeNode getNodeForMethod(Method method) {
    Object r = null;
    try {
        method.setAccessible(true);
        r = method.invoke(object, new Object[] {});
    } catch (Throwable t) {
    }
    String p = getPropertyName(method.getName());
    return getNewNode(r, p);
}
 
Example 30
Project: incubator-netbeans   File: VisualizerSpeed95364Test.java   Source Code and License 5 votes vote down vote up
private void doTest() {
    TreeNode tn = null;
    for (int i = 0; i < 100000; i++) {
        tn = toCheck.getChildAt(size/2);
    }
    assertEquals("One node created + 50 at begining", 51, chK.cnt);
}
 
Example 31
Project: JavaGraph   File: StateTree.java   Source Code and License 5 votes vote down vote up
private void maybeShowPopup(MouseEvent evt) {
    if (evt.isPopupTrigger()) {
        TreePath selectedPath = getPathForLocation(evt.getX(), evt.getY());
        TreeNode selectedNode =
            selectedPath == null ? null : (TreeNode) selectedPath.getLastPathComponent();
        StateTree.this.requestFocus();
        createPopupMenu(selectedNode).show(evt.getComponent(), evt.getX(), evt.getY());
    }
}
 
Example 32
Project: Logisim   File: ComponentSelector.java   Source Code and License 5 votes vote down vote up
@Override
public int getIndex(TreeNode n) {
	for (int i = 0; i < opts.length; i++) {
		if (opts[i] == n)
			return i;
	}
	return -1;
}
 
Example 33
Project: incubator-netbeans   File: VisualizerNodeTest.java   Source Code and License 5 votes vote down vote up
public void testIndexOfProvidesResultsEvenIfTheVisualizerIsComputedViaDifferentMeans() throws Exception {
    AbstractNode a = new AbstractNode(new Children.Array());
    AbstractNode m = new AbstractNode(Children.LEAF);
    a.getChildren().add(new Node[] { Node.EMPTY.cloneNode(), m, Node.EMPTY.cloneNode() });
    
    TreeNode ta = Visualizer.findVisualizer(a);
    TreeNode tm = Visualizer.findVisualizer(m);
    
    assertEquals("Index is 1", 1, ta.getIndex(tm));
}
 
Example 34
Project: sbc-qsystem   File: FAdmin.java   Source Code and License 5 votes vote down vote up
/**
 * Из привязок к услугам всех юзеров убрать привязку к данной услуге и всех ее вложенных.
 *
 * @param service удаляемая услуга
 */
private void deleteServicesFromUsers(QService service) {

    QServiceTree.sailToStorm(service, (TreeNode service1) -> {
        deleteServiceFromUsers((QService) service1);
    });
}
 
Example 35
Project: Logisim   File: SimulationTreeModel.java   Source Code and License 5 votes vote down vote up
@Override
public int getChildCount(Object parent) {
	if (parent instanceof TreeNode) {
		return ((TreeNode) parent).getChildCount();
	} else {
		return 0;
	}
}
 
Example 36
Project: Cognizant-Intelligent-Test-Scripter   File: JCheckBoxTree.java   Source Code and License 5 votes vote down vote up
protected void updatePredecessorsWithCheckMode(TreePath tp, boolean check) {
    TreePath parentPath = tp.getParentPath();
    // If it is the root, stop the recursive calls and return
    if (parentPath == null) {
        return;
    }
    CheckedNode parentCheckedNode = nodesCheckingState.get(parentPath);
    TreeNode parentNode = (TreeNode) parentPath.getLastPathComponent();
    parentCheckedNode.allChildrenSelected = true;
    parentCheckedNode.isSelected = false;
    for (int i = 0; i < getChildCount(parentNode); i++) {
        TreePath childPath = parentPath.pathByAddingChild(getChildAt(parentNode, i));
        CheckedNode childCheckedNode = nodesCheckingState.get(childPath);
        // It is enough that even one subtree is not fully selected
        // to determine that the parent is not fully selected
        if (!childCheckedNode.allChildrenSelected) {
            parentCheckedNode.allChildrenSelected = false;
        }
        // If at least one child is selected, selecting also the parent
        if (childCheckedNode.isSelected) {
            parentCheckedNode.isSelected = true;
        }
    }
    if (parentCheckedNode.isSelected) {
        checkedPaths.add(parentPath);
    } else {
        checkedPaths.remove(parentPath);
    }
    // Go to upper predecessor
    updatePredecessorsWithCheckMode(parentPath, check);
}
 
Example 37
Project: fuck_zookeeper   File: ZooInspectorTreeViewer.java   Source Code and License 5 votes vote down vote up
public TreeNode getChildAt(int childIndex) {
    String child = zooInspectorManager.getNodeChild(this.nodePath,
            childIndex);
    if (child != null) {
        return new ZooInspectorTreeNode((this.nodePath.equals("/") ? ""
                : this.nodePath)
                + "/" + child, this);
    }
    return null;
}
 
Example 38
Project: incubator-netbeans   File: ExcludeDependencyPanel.java   Source Code and License 5 votes vote down vote up
private TreeNode createTransitiveDependenciesList() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(null, true);
    Set<Artifact> artifacts = project.getArtifacts();
    Icon icn = ImageUtilities.image2Icon(ImageUtilities.loadImage(IconResources.TRANSITIVE_DEPENDENCY_ICON, true)); //NOI18N
    for (Artifact a : artifacts) {
        if (a.getDependencyTrail().size() > 2) {
            String label = a.getGroupId() + ":" + a.getArtifactId();
            root.add(new CheckNode(a, label, icn));
        }
    }
    return root;
}
 
Example 39
Project: Cognizant-Intelligent-Test-Scripter   File: XpathGenerator.java   Source Code and License 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 40
Project: Logisim   File: ComponentSelector.java   Source Code and License 5 votes vote down vote up
public CircuitNode(CircuitNode parent, CircuitState circuitState, Component subcircComp) {
	this.parent = parent;
	this.circuitState = circuitState;
	this.subcircComp = subcircComp;
	this.children = new ArrayList<TreeNode>();
	circuitState.getCircuit().addCircuitListener(this);
	computeChildren();
}