Example usage for javax.swing.tree DefaultTreeModel insertNodeInto

List of usage examples for javax.swing.tree DefaultTreeModel insertNodeInto

Introduction

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

Prototype

public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index) 

Source Link

Document

Invoked this to insert newChild at location index in parents children.

Usage

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Creates and returns a {@link TreeImageTimeSet}.
 * /*from w  ww . j  a v  a 2  s. c  o  m*/
 * @param index    One of the following constants: 
 *                {@link TreeImageTimeSet#YEAR} or 
 *                {@link TreeImageTimeSet#YEAR_BEFORE}.
 * @param month      The index of the month.
 * @param parent   The parent of the new node.
 * @return See above.
 */
private TreeImageTimeSet createTimeNode(int index, int month, TreeImageSet parent) {
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    TreeImageTimeSet date = new TreeImageTimeSet(index, month);
    buildEmptyNode(date);
    parent.addChildDisplay(date);
    tm.insertNodeInto(date, parent, parent.getChildCount());
    parent.setChildrenLoaded(true);
    return date;
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Creates the group nodes.//from   w  w  w  .  ja  v a 2  s.  c o m
 * 
 * @param defaultGroup The default group
 * @return See above.
 */
private List<TreeImageSet> createGroups(GroupData defaultGroup) {
    TreeImageDisplay root = getTreeRoot();
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    //root.addChildDisplay(node);
    //tm.insertNodeInto(node, root, root.getChildCount());

    List<TreeImageSet> l = new ArrayList<TreeImageSet>();
    List groups = sorter.sort(TreeViewerAgent.getAvailableUserGroups());
    //sort the group first.
    Iterator i = groups.iterator();
    GroupData group;
    TreeImageSet n = new TreeImageSet(defaultGroup);
    TreeViewerTranslator.formatToolTipFor(n);
    l.add(n);
    root.addChildDisplay(n);
    tm.insertNodeInto(n, root, root.getChildCount());
    while (i.hasNext()) {
        group = (GroupData) i.next();
        if (group.getId() != defaultGroup.getId()) {
            n = new TreeImageSet(group);
            TreeViewerTranslator.formatToolTipFor(n);
            l.add(n);
            root.addChildDisplay(n);
            tm.insertNodeInto(n, root, root.getChildCount());
        }
    }
    return l;
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Creates the group node./* w  w w. ja  v a  2 s  .c  om*/
 * 
 * @param group The group to add.
 * @return See above.
 */
private TreeImageSet createGroup(GroupData group) {
    TreeImageDisplay root = getTreeRoot();
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    //root.addChildDisplay(node);
    //tm.insertNodeInto(node, root, root.getChildCount());
    TreeImageSet n = new TreeImageSet(group);
    TreeViewerTranslator.formatToolTipFor(n);
    root.addChildDisplay(n);
    tm.insertNodeInto(n, root, root.getChildCount());
    return n;
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Adds the nodes to the specified parent.
 * /*from  ww w. j a  va  2 s  .  c  o m*/
 * @param parent    The parent node.
 * @param nodes     The list of nodes to add.
 * @param tm        The  tree model.
 */
private void buildTreeNode(TreeImageDisplay parent, Collection nodes, DefaultTreeModel tm) {
    if (nodes.size() == 0) {
        tm.insertNodeInto(new DefaultMutableTreeNode(Browser.EMPTY_MSG), parent, parent.getChildCount());
        return;
    }
    Iterator i = nodes.iterator();
    TreeImageDisplay display;
    List children;
    parent.removeAllChildren();
    int browserType = model.getBrowserType();
    Object uo;
    while (i.hasNext()) {
        display = (TreeImageDisplay) i.next();
        tm.insertNodeInto(display, parent, parent.getChildCount());

        if (display instanceof TreeImageSet) {
            children = display.getChildrenDisplay();
            if (children.size() > 0) {
                if (display.containsImages()) {
                    display.setExpanded(true);
                    setExpandedParent(display, false);
                    nodesToReset.add(display);
                    buildTreeNode(display, prepareSortedList(sorter.sort(children)), tm);
                    expandNode(display);
                    tm.reload(display);
                } else {
                    if (browserType == Browser.TAGS_EXPLORER) {
                        if (display.isExpanded()) {
                            setExpandedParent(display, false);
                            nodesToReset.add(display);
                        }
                        buildTreeNode(display, prepareSortedList(sorter.sort(children)), tm);
                        if (display.isExpanded()) {
                            expandNode(display);
                            tm.reload(display);
                        }
                    } else {
                        if (display.isExpanded()) {
                            setExpandedParent(display, true);
                            nodesToReset.add(display);
                        }
                        buildTreeNode(display, prepareSortedList(sorter.sort(children)), tm);
                    }
                }
            } else {
                uo = display.getUserObject();
                if (uo instanceof DatasetData) {
                    tm.insertNodeInto(new DefaultMutableTreeNode(Browser.EMPTY_MSG), display,
                            display.getChildCount());
                } else if (uo instanceof TagAnnotationData) {
                    TagAnnotationData tag = (TagAnnotationData) uo;
                    if (!(TagAnnotationData.INSIGHT_TAGSET_NS.equals(tag.getNameSpace()))) {
                        tm.insertNodeInto(new DefaultMutableTreeNode(Browser.EMPTY_MSG), display,
                                display.getChildCount());
                    }
                } else if (uo instanceof GroupData) {
                    tm.insertNodeInto(new DefaultMutableTreeNode(Browser.EMPTY_MSG), display,
                            display.getChildCount());
                } else if (uo instanceof FileAnnotationData) {
                    if (browserType == Browser.SCREENS_EXPLORER) {
                        TreeImageSet n = new TreeImageSet(uo);
                        tm.insertNodeInto(new DefaultMutableTreeNode(Browser.EMPTY_MSG), n, n.getChildCount());
                    }
                }
            }
        }
    }
    if (parent.isExpanded()) {
        expandNode(parent);
        tm.reload(parent);
    }
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Adds a dummy node to the specified node.
 * /*  w  ww .  j  a  v a2s .  com*/
 * @param node The parent node.
 */
private void buildEmptyNode(DefaultMutableTreeNode node) {
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    tm.insertNodeInto(new DefaultMutableTreeNode(Browser.EMPTY_MSG), node, node.getChildCount());
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Creates the smart folders added to the passed node.
 * //w  ww  .  j a va  2  s .c om
 * @param parent The parent of the smart folder.
 */
private void buildOrphanImagesNode(TreeImageDisplay parent) {
    Registry reg = TreeViewerAgent.getRegistry();
    //First check if we had the orphaned images node
    Boolean value = Boolean.parseBoolean((String) reg.lookup(LookupNames.ORPHANED_IMAGE_ENABLED));
    if (value != null && !value.booleanValue()) {
        boolean enabled = false;
        if (TreeViewerAgent.isAdministrator()) {
            enabled = true;
        } else {
            //check group owner.
            long expID = TreeViewerAgent.getUserDetails().getId();
            if (expID == parent.getUserObjectId()) {
                enabled = true;
            } else {
                TreeImageDisplay node = parent.getParentDisplay();
                long id = -1;
                if (node != null) {
                    id = node.getUserObjectId();
                    if (id == -1) { //only in one group
                        id = TreeViewerAgent.getUserDetails().getGroupId();
                    }
                }
                Set leaders = TreeViewerAgent.getGroupsLeaderOf();
                if (CollectionUtils.isNotEmpty(leaders)) {
                    Iterator i = leaders.iterator();
                    while (i.hasNext()) {
                        GroupData type = (GroupData) i.next();
                        if (id == type.getId()) {
                            enabled = true;
                        }
                    }
                }
            }
        }
        if (!enabled) {
            return;
        }
    }
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    TreeFileSet node = new TreeFileSet(TreeFileSet.ORPHANED_IMAGES);

    String v = (String) reg.lookup(LookupNames.ORPHANED_IMAGE_NAME);
    if (CommonsLangUtils.isNotBlank(v)) {
        node.setUserObject(v);
    }
    v = (String) reg.lookup(LookupNames.ORPHANED_IMAGE_DESCRIPTION);
    if (CommonsLangUtils.isNotBlank(v)) {
        node.setToolTip(v);
    }
    buildEmptyNode(node);
    node.setNumberItems(-1);
    parent.addChildDisplay(node);
    tm.insertNodeInto(node, parent, parent.getChildCount());
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Creates a dummy loading node whose parent is the specified node.
 * /*from ww w. j a va2 s .  c  o  m*/
 * @param parent The parent node.
 */
void loadAction(TreeImageDisplay parent) {
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    parent.removeAllChildren();
    tm.insertNodeInto(new DefaultMutableTreeNode(Browser.LOADING_MSG), parent, parent.getChildCount());
    tm.reload(parent);
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Adds the newly created node to the tree.
 * /*from  w ww .j av a 2s  .c  o  m*/
 * @param nodes         The collection of the parent nodes.
 * @param newNode       The node to add to the parent.
 * @param parentDisplay The selected parent.
 */
void createNodes(List nodes, TreeImageDisplay newNode, TreeImageDisplay parentDisplay) {
    if (parentDisplay == null)
        parentDisplay = getTreeRoot();
    Iterator i = nodes.iterator();
    TreeImageDisplay parent;
    List list;
    Iterator j;
    DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel();
    //buildEmptyNode(newNode);
    boolean toLoad = false;
    TreeImageDisplay n;
    while (i.hasNext()) {
        parent = (TreeImageDisplay) i.next();
        //problem will come when we have images
        if (parent.isChildrenLoaded()) {
            parent.addChildDisplay(newNode);
            list = prepareSortedList(sorter.sort(parent.getChildrenDisplay()));
            parent.removeAllChildren();
            j = list.iterator();
            while (j.hasNext()) {
                n = (TreeImageDisplay) j.next();
                if (!n.isChildrenLoaded()) {
                    n.removeAllChildren();
                    buildEmptyNode(n);
                }
                dtm.insertNodeInto(n, parent, parent.getChildCount());
            }
            dtm.reload(parent);
            expandNode(parent);
            if (parent.equals(parentDisplay))
                treeDisplay.setSelectionPath(new TreePath(newNode.getPath()));
        } else { //Only the currently selected one will be loaded.
            if (parent.equals(parentDisplay))
                toLoad = true;
        }
    }
    //should be leaves. Need to review that code.
    if (toLoad) { //TO BE MODIFIED
        //if (parentDisplay.getParentDisplay() == null) //root
        //    controller.loadData();
        //else controller.loadLeaves();
    }
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Sets the number of items imported during a period of time.
 * /*from  w  w  w .ja va  2  s .co  m*/
 * @param expNode    The node hosting the experimenter.
 * @param index      The index of the time node.
 * @param value      The value to set.
 */
void setCountValues(TreeImageDisplay expNode, int index, Object value) {
    DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel();
    if (model.getBrowserType() != Browser.TAGS_EXPLORER)
        expNode.setChildrenLoaded(Boolean.valueOf(true));
    int n = expNode.getChildCount();
    TreeImageSet node;
    List l;
    Iterator i, k;
    TreeImageTimeSet child;
    //Test
    List<TreeImageSet> toRemove = new ArrayList<TreeImageSet>();
    List<TreeImageSet> toKeep = new ArrayList<TreeImageSet>();
    int number;
    int total;
    DefaultMutableTreeNode childNode;
    List<DefaultMutableTreeNode> remove = new ArrayList<DefaultMutableTreeNode>();
    for (int j = 0; j < n; j++) {
        childNode = (DefaultMutableTreeNode) expNode.getChildAt(j);
        Object o = childNode.getUserObject();
        if (o instanceof String) {
            String s = (String) o;
            if (Browser.EMPTY_MSG.equals(s)) {
                remove.add(childNode);
            }
        }
        if (childNode instanceof TreeImageTimeSet) {
            node = (TreeImageTimeSet) childNode;
            if (((TreeImageTimeSet) node).getType() == index) {
                if (value instanceof Integer) {
                    //Check if the number is 0
                    int vv = ((Integer) value).intValue();
                    long v = node.getNumberItems();
                    node.setNumberItems(vv);
                    if (v == 0 && vv > 0) {
                        buildEmptyNode(node);
                        node.setChildrenLoaded(Boolean.valueOf(false));
                    }
                } else if (value instanceof List) {
                    l = (List) value;
                    total = 0;
                    i = node.getChildrenDisplay().iterator();
                    while (i.hasNext()) {
                        child = (TreeImageTimeSet) i.next();
                        number = child.countTime(l);
                        total += number;
                        if (number > 0) {
                            child.setNumberItems(number);
                            toKeep.add(child);
                        } else {
                            toRemove.add(child);
                        }
                    }
                    node.removeAllChildren();
                    node.removeChildrenDisplay(toRemove);
                    node.setNumberItems(total);
                    k = toKeep.iterator();
                    while (k.hasNext()) {
                        dtm.insertNodeInto((TreeImageTimeSet) k.next(), node, node.getChildCount());
                    }
                }
                dtm.reload(node);
            }
        } else if (childNode instanceof TreeFileSet) {
            node = (TreeFileSet) childNode;
            if (((TreeFileSet) node).getType() == index) {
                if (value instanceof Long)
                    node.setNumberItems((Long) value);
            }
        }
    }
    if (remove.size() > 0) {
        Iterator<DefaultMutableTreeNode> j = remove.iterator();
        while (j.hasNext()) {
            expNode.remove(j.next());
            dtm.reload(expNode);
        }

    }
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Removes the specified experimenter from the tree.
 * /*from   www .j av  a2  s. c  om*/
 * @param exp The experimenter data to remove.
 * @param refNode The node to remove the experimenter from.
 */
void removeExperimenter(ExperimenterData exp, TreeImageDisplay refNode) {
    if (model.getBrowserType() == Browser.ADMIN_EXPLORER)
        return;
    if (refNode == null)
        refNode = getTreeRoot();

    List<TreeImageDisplay> nodesToKeep;
    List l = refNode.getChildrenDisplay();
    if (l == null || l.size() == 0)
        return;
    Iterator j = l.iterator();
    TreeImageDisplay element, node;
    Object ho;
    ExperimenterData expElement;
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    Iterator k;
    node = null;
    nodesToKeep = new ArrayList<TreeImageDisplay>();
    List<TreeImageDisplay> toExpand = new ArrayList<TreeImageDisplay>();
    while (j.hasNext()) {
        element = (TreeImageDisplay) j.next();
        ho = element.getUserObject();
        if (ho instanceof ExperimenterData) {
            expElement = (ExperimenterData) ho;
            if (expElement.getId() == exp.getId())
                node = element;
            else {
                nodesToKeep.add(element);
                if (element.isExpanded())
                    toExpand.add(element);
            }
        }
    }
    if (node != null)
        refNode.removeChildDisplay(node);
    k = nodesToKeep.iterator();
    refNode.removeAllChildren();
    while (k.hasNext()) {
        tm.insertNodeInto((TreeImageSet) k.next(), refNode, refNode.getChildCount());
    }

    tm.reload(refNode);
    k = toExpand.iterator();
    while (k.hasNext()) {
        expandNode((TreeImageSet) k.next(), false);
    }
}