Example usage for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode

List of usage examples for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode.

Prototype

public DefaultMutableTreeNode(Object userObject) 

Source Link

Document

Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.

Usage

From source file:org.apache.directory.fortress.web.panel.UserListPanel.java

private DefaultTreeModel createTreeModel(List<T> users) {
    DefaultTreeModel model;/*from  www  .  j av a 2s . c  o  m*/
    rootNode = new DefaultMutableTreeNode(null);
    model = new DefaultTreeModel(rootNode);
    if (users == null) {
        LOG.debug("no Users found");
    } else {
        LOG.debug(".createTreeModel Users found:" + users.size());
        for (T user : users) {
            rootNode.add(new DefaultMutableTreeNode(user));
        }
    }
    return model;
}

From source file:org.apache.directory.fortress.web.panel.UserListPanel.java

public void add(FortEntity entity) {
    if (getDefaultModelObject() != null) {
        List<User> users = ((List<User>) getDefaultModelObject());
        users.add((User) entity);/*from   w w  w.j  ava2s . c  o m*/
        LOG.debug("UserListPanel.add tree depth: " + rootNode.getChildCount());
        treeModel.insertNodeInto(new DefaultMutableTreeNode(entity), rootNode, rootNode.getChildCount());
        //treeModel.insertNodeInto(new DefaultMutableTreeNode(entity), rootNode, users.size());
    }
}

From source file:org.apache.jetspeed.portlets.site.PortalSiteManager.java

private DefaultMutableTreeNode retrieveFolders(String folderPath, DefaultMutableTreeNode rootNode,
        boolean cleanBeforeRetrieve) {
    try {//  w ww .j  av a2 s. c o m
        Link link;
        Folder folder;
        DefaultMutableTreeNode tmpNode;
        Page page;
        Folder rootfolder = getServiceLocator().getPageManager().getFolder(folderPath);

        if (rootNode == null) {
            rootNode = new DefaultMutableTreeNode(new SiteTreeNode(rootfolder, true));
        }

        if (cleanBeforeRetrieve) {
            rootNode.removeAllChildren();
        }

        Iterator folders = rootfolder.getFolders().iterator();
        while (folders.hasNext()) {
            folder = (Folder) folders.next();

            if (rootfolder.getPath().equals("/_user")) {
                if (folder.getName().startsWith("template")) {
                    rootNode.add(new DefaultMutableTreeNode(new SiteTreeNode(folder)));
                }
            } else {
                rootNode.add(new DefaultMutableTreeNode(new SiteTreeNode(folder)));
            }
        }

        Iterator pages = rootfolder.getPages().iterator();
        while (pages.hasNext()) {
            page = (Page) pages.next();
            tmpNode = new DefaultMutableTreeNode(new SiteTreeNode(page));
            tmpNode.setAllowsChildren(false);
            rootNode.add(tmpNode);
        }

        Iterator links = rootfolder.getLinks().iterator();
        while (links.hasNext()) {
            link = (Link) links.next();
            tmpNode = new DefaultMutableTreeNode(new SiteTreeNode(link));
            tmpNode.setAllowsChildren(false);
            rootNode.add(tmpNode);
        }
    } catch (Exception e) {
        log.error("Failed to retrieve folders ", e);
    }

    return rootNode;
}

From source file:org.apache.jetspeed.portlets.site.PortalSiteManager.java

private DefaultMutableTreeNode retrieveCopyFolders(String folderPath, DefaultMutableTreeNode rootNode) {
    try {/*  w ww .  j  a v  a 2  s  . com*/
        Folder folder;
        Folder rootfolder = getServiceLocator().getPageManager().getFolder(folderPath);
        if (rootNode == null) {
            rootNode = new DefaultMutableTreeNode(new SiteTreeNode(rootfolder, true));
        }
        Iterator folders = rootfolder.getFolders().iterator();
        while (folders.hasNext()) {
            folder = (Folder) folders.next();
            if (rootfolder.getPath().equals("/_user")) {
                if (folder.getName().startsWith("template")) {
                    rootNode.add(new DefaultMutableTreeNode(new SiteTreeNode(folder)));
                }
            } else {
                rootNode.add(new DefaultMutableTreeNode(new SiteTreeNode(folder)));
            }
        }
    } catch (Exception e) {
        log.error("Failed to retrieve folders ", e);
    }
    return rootNode;
}

From source file:org.apache.jetspeed.portlets.site.PortalSiteManager.java

private DefaultMutableTreeNode getSelectedNode() {
    PortalTree tree = (PortalTree) getPage().get("siteTree");
    Collection selectedNodes = tree.getTreeState().getSelectedNodes();
    DefaultMutableTreeNode treeNode = null;

    if (selectedNodes != null) {
        Iterator selectedNode = selectedNodes.iterator();
        while (selectedNode.hasNext()) {
            treeNode = (DefaultMutableTreeNode) selectedNode.next();
            break;
        }/* w  ww .j  a  v a  2  s.c om*/
    }

    if (treeNode == null) {
        TreeModel treeModel = tree.getModelObject();

        if (treeModel != null && treeModel.getRoot() != null) {
            treeNode = (DefaultMutableTreeNode) treeModel.getRoot();
        }
    }

    if (treeNode == null) {
        treeNode = new DefaultMutableTreeNode(new SiteTreeNode("root", "/", FileType.Folder));
    }

    return treeNode;
}