Java 8 TreeModel - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 TreeModel class.

This code example shows how to use the following methods:isLeaf
	@Override 
	protected Icon getIcon(IModel<I> model)
	{ 
		TreeModel treeModel = (TreeModel)getTreeGrid().getTree().getDefaultModelObject();
		Object node = model.getObject();
		if (treeModel.isLeaf(node))
		{ 
			return Icons.ITEM; 
		} 
		else if (getTreeGrid().getTreeState().isNodeExpanded(node)) 
		{ 
			return Icons.FOLDER_OPEN; 
		} 
		else 
		{ 
			return Icons.FOLDER_CLOSED; 
		} 
	} 
 
	/** 
5
CodeRank
This code example shows how to use the following methods:isLeaf
        TreeCellRenderer renderer = tree.getCellRenderer();
        boolean isSelected = tree.isPathSelected(treePath);
        boolean isExpanded = tree.isExpanded(treePath);
        boolean hasFocus = tree.hasFocus() && rowIndex == tree.getLeadSelectionRow();
        Object item = treePath.getLastPathComponent();
        boolean isLeaf = treeModel.isLeaf(item);
        Component component = renderer.getTreeCellRendererComponent(tree, item, isSelected, isExpanded, isLeaf, rowIndex, hasFocus);
        component.setFont(tree.getFont());
        return component;
    } 
 
    public boolean equals(Object o) { 
        if(this == o) {
            return true; 
        } 
        if(o == null || getClass() != o.getClass()) {
            return false; 
        } 
 
        TreeDataTipCell treeDataTipCell = (TreeDataTipCell) o;
4
CodeRank
This code example shows how to use the following methods:getChild
 
    public Object nextElement() { 
        if (!hasMoreElements()) { 
            throw new NoSuchElementException();
        } 
        return path.pathByAddingChild(model.getChild(path.getLastPathComponent(), position++));
    } 
} 
4
CodeRank
This code example shows how to use the following methods:getRoot
		model.setRoot(null);
	} 
 
	public void sendRefreshedMessage() 
	{ 
		Object root = treeModel.getRoot();
		Item rootItem = objectToItemWithCache(root);
		addChildren(root, rootItem);
		model.setRoot(rootItem);
	} 
 
	private void addChildren(Object parent, Item parentItem)
	{ 
		for (int i = 0; i < treeModel.getChildCount(parent); i++)
		{ 
			Object child = treeModel.getChild(parent, i);
			Item childItem = objectToItemWithCache(child);
			parentItem.addChild(childItem);
			childItem.setParent(parentItem);
			addChildren(child, childItem);
4
CodeRank
This code example shows how to use the following methods:isLeaf
		return model.getRoot();
	} 
 
	@Override 
	public boolean isLeaf(Object node) { 
		return model.isLeaf(node);
	} 
 
	@Override 
	public void valueForPathChanged(TreePath path, Object newValue) {
		model.valueForPathChanged(path, newValue);
	} 
 
        /** 
         * Return true if the element leaf has been filtered. 
         * @param element 
         * @return  
         */ 
	protected boolean isFiltered(Object element) { 
		if (isFiltered()) { 
3
CodeRank
This code example shows how to use the following methods:getChild
     * @param node the parent node 
     * @param i    the child index 
     * @return the child node 
     */ 
    protected Object getChild(Object node, int i) {
        return _model.getChild(node, i);
    } 
 
    /** 
     * Get the children count 
     * 
     * @param node the parent node 
     * @return the children count of the parent node. 
     */ 
    protected int getChildrenCount(Object node) { 
        return _model.getChildCount(node);
    } 
 
    private void addToExistingSet(Set<TreePath> pathHasOperated, TreePath pathToOperate) {
        if (pathHasOperated.contains(pathToOperate)) {
4
CodeRank
This code example shows how to use the following methods:getChild
            // must fire an event to refresh the view 
            super.fireContentsChanged(MultiColumnBrowser.this, 0, Math.max(oldChildren, children));
        } 
 
        public Object getElementAt(int index) {
            return model.getChild(treeNode, index);
        } 
 
        public int getSize() { 
            return children;
        } 
    } 
 
    // ==================================================== 
    // Represents a single browser column 
    // ==================================================== 
    protected final class BrowserPanel extends JList {
        BrowserPanel() { 
            BrowserPanel.this.setModel(new ColumnListModel());
            BrowserPanel.this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
3
CodeRank
This code example shows how to use the following methods:getChildCount
 
    public PreorderEnumeration(TreePath path, TreeModel model) {
        this(Collections.enumeration(Collections.singletonList(path)), model);
    } 
 
    public PreorderEnumeration(Enumeration enumer, TreeModel model) {
        this.model = model;
        stack.push(enumer);
    } 
 
    public boolean hasMoreElements() { 
        return (!stack.empty() &&
                ((Enumeration) stack.peek()).hasMoreElements());
    } 
 
    public Object nextElement() { 
        Enumeration enumer = (Enumeration) stack.peek();
        TreePath path = (TreePath) enumer.nextElement();
 
        if (!enumer.hasMoreElements()) {

4
CodeRank
This code example shows how to use the following methods:getChildCount
	 * @see JTree#expandPath(TreePath) 
	 */ 
	protected void expandAllPaths(TreePath path, TreeModel treeModel) {
		expandPath(path);
		final Object node = path.getLastPathComponent();
		final int n = treeModel.getChildCount(node);
		for (int index = 0; index < n; index++) {
			final Object child = treeModel.getChild(node, index);
			expandAllPaths(path.pathByAddingChild(child));
		} 
	} 
	 
	@Override 
	public void setTransferHandler(TransferHandler newHandler) {
		if(newHandler instanceof PlotConfigurationTreeTransferHandler) {
			DragListener cellRenderer = (DragListener) getCellRenderer();
			PlotConfigurationTreeTransferHandler plotConfigurationTreeTransferHandler = (PlotConfigurationTreeTransferHandler) newHandler;
			if(cellRenderer != null) {
				plotConfigurationTreeTransferHandler.removeDragListener(cellRenderer);
			} 
3
CodeRank
This code example shows how to use the following methods:getChildCount
            public void treeStructureChanged(TreeModelEvent e) {
                updateRootVisibility(); 
            } 
             
            private void updateRootVisibility() { 
	            if (getModel().getChildCount(getModel().getRoot()) == 0) {
	                setRootVisible(false);
	            } 
	            else { 
	                setRootVisible(true);
	            } 
            } 
       }); 
	} 
} 
3
CodeRank
See Code Examples for Java 8 TreeModel Methods: