Example usage for javax.swing.tree DefaultTreeModel reload

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

Introduction

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

Prototype

public void reload() 

Source Link

Document

Invoke this method if you've modified the TreeNode s upon which this model depends.

Usage

From source file:com.SE.myPlayer.MusicPlayerGUI.java

private void treeReferesh() {
        DefaultTreeModel myModel = (DefaultTreeModel) folder_Playlist_Tree.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) myModel.getRoot();
        root.removeAllChildren();// www . j  a  v  a2  s.c o m

        DefaultMutableTreeNode library = new DefaultMutableTreeNode("library");
        DefaultMutableTreeNode playlist = new DefaultMutableTreeNode("playlist");

        myModel.insertNodeInto(library, root, root.getChildCount());
        myModel.insertNodeInto(playlist, root, root.getChildCount());

        try {
            con = db.getCon();
            stmt = con.createStatement();
            String node;

            ResultSet rs = stmt.executeQuery("select pn_name from playlist_name");

            while (rs.next()) {
                node = rs.getString(1);
                DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(node);
                myModel.insertNodeInto(newNode, playlist, playlist.getChildCount());
            }

            if (con != null) {
                stmt.close();
                con.close();
            }
        } catch (SQLException e) {
            System.out.println("Error in Stmt " + e);
        }

        myModel.reload();
        folder_Playlist_Tree.setModel(myModel);
    }

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

/**
 * Refreshes the folder hosting the file.
 * /*  ww w  .  j a  va 2  s  . c om*/
 * @param expNode   The experimenter node to refresh.
 * @param r         The data to display.
 */
private void refreshFileFolder(TreeImageDisplay expNode, Map<Integer, Set> r) {
    DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel();
    expNode.setChildrenLoaded(Boolean.valueOf(true));
    expNode.setExpanded(Boolean.valueOf(true));
    if (r == null || r.size() == 0)
        return;
    Iterator i = r.keySet().iterator();
    int index;
    int n = expNode.getChildCount();
    TreeFileSet node;
    dtm.reload();
    while (i.hasNext()) {
        index = (Integer) i.next();
        for (int j = 0; j < n; j++) {
            node = (TreeFileSet) expNode.getChildAt(j);
            if (node.getType() == index)
                refreshFolderNode(node, r.get(index));
        }
    }
    setExpandedParent(expNode, true);
}

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

/**
 * Refreshes the folder hosting the time.
 * // w w  w  .j  a va 2 s .  co m
 * @param expNode   The experimenter node to refresh.
 * @param r         The data to display.
 */
private void refreshTimeFolder(TreeImageDisplay expNode, Map<Integer, Set> r) {
    DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel();
    expNode.setChildrenLoaded(Boolean.TRUE);
    expNode.setExpanded(true);
    if (r == null || r.size() == 0)
        return;
    Iterator i = r.keySet().iterator();
    int index;
    int n = expNode.getChildCount();
    TreeImageTimeSet node, child;
    dtm.reload();
    int nodeType;
    List children;
    Iterator s;
    while (i.hasNext()) {
        index = (Integer) i.next();
        for (int j = 0; j < n; j++) {
            node = (TreeImageTimeSet) expNode.getChildAt(j);
            nodeType = node.getType();
            switch (nodeType) {
            case TreeImageTimeSet.YEAR:
            case TreeImageTimeSet.YEAR_BEFORE:
                children = node.getChildrenDisplay();
                s = children.iterator();
                while (s.hasNext()) {
                    child = (TreeImageTimeSet) s.next();
                    if (child.getIndex() == index)
                        refreshFolderNode(child, r.get(index));
                }
            default:
                if (node.getIndex() == index)
                    refreshFolderNode(node, r.get(index));
                break;
            }
        }
    }
    setExpandedParent(expNode, true);
}

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

/**
 * Sets the nodes hosting the groups to manage.
 * /*from  w  ww . j av  a  2  s . com*/
 * @param nodes The nodes to display
 * @param expanded The list of nodes previously expanded.
 */
void setGroups(Set nodes, List expanded) {
    DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel();
    TreeImageDisplay root = getTreeRoot();
    root.removeAllChildren();
    root.removeAllChildrenDisplay();
    root.setChildrenLoaded(Boolean.valueOf(true));
    root.setExpanded(true);
    dtm.reload();
    if (nodes.size() != 0) {
        Iterator i = nodes.iterator();
        while (i.hasNext()) {
            root.addChildDisplay((TreeImageDisplay) i.next());
        }
        buildTreeNode(root, prepareSortedList(sorter.sort(nodes)), dtm);
        i = nodes.iterator();
        while (i.hasNext()) {
            ((TreeImageDisplay) i.next()).setExpanded(false);
        }
        if (expanded != null && expanded.size() > 0) {
            i = nodes.iterator();
            TreeImageDisplay display;
            GroupData group;
            Object ho;
            Set l;
            GroupData g;
            while (i.hasNext()) {
                display = (TreeImageDisplay) i.next();
                ho = display.getUserObject();
                if (ho instanceof GroupData) {
                    g = (GroupData) ho;
                    if (expanded.contains(g.getId())) {
                        expandNode(display);
                    }
                }
            }
        }
    }
    if (TreeViewerAgent.isAdministrator()) {
        SmartFolder folder = new SmartFolder(GroupData.class, "Experimenters w/o groups");
        buildEmptyNode(folder);
        //root.addChildDisplay(folder);
        //dtm.insertNodeInto(folder, root, root.getChildCount());
    }
}

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

/**
 * Removes the specified group from the tree.
 * //from  w  w w.j a  va2 s . co m
 * @param group The data to remove.
 */
void removeGroup(GroupData group) {
    if (model.getBrowserType() == Browser.ADMIN_EXPLORER)
        return;
    TreeImageDisplay root = getTreeRoot();
    List<TreeImageDisplay> nodesToKeep;
    List l = root.getChildrenDisplay();
    if (l == null || l.size() == 0)
        return;
    Iterator j = l.iterator();
    TreeImageDisplay element, n, node;
    Object ho;
    ExperimenterData expElement;
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    Iterator k;
    GroupData g;
    nodesToKeep = new ArrayList<TreeImageDisplay>();
    node = null;
    while (j.hasNext()) {
        element = (TreeImageDisplay) j.next();
        if (element.getUserObject() instanceof GroupData) {
            g = (GroupData) element.getUserObject();
            if (g.getId() == group.getId())
                node = element;
            else
                nodesToKeep.add(element);
        }
    }

    if (node != null)
        root.removeChildDisplay(node);
    k = nodesToKeep.iterator();
    root.removeAllChildren();
    while (k.hasNext()) {
        tm.insertNodeInto((TreeImageSet) k.next(), root, root.getChildCount());
    }
    tm.reload();
}

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

/** Reactivates the tree. */
void reActivate() {
    clear();//from   ww w.  j  a va 2  s . c  o m
    treeDisplay.reset(model.getUserID(), TreeViewerAgent.isAdministrator());
    TreeCellRenderer renderer = (TreeCellRenderer) treeDisplay.getCellRenderer();
    renderer.reset(model.getUserID());
    if (model.getBrowserType() != Browser.ADMIN_EXPLORER) {
        ExperimenterData exp = model.getUserDetails();
        TreeImageDisplay node = buildTreeNodes(exp);
        if (model.isSelected() && node != null) {
            expandNode(node, true);
        }
    }
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    tm.reload();
}

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

/** Clear the tree.*/
void clear() {/*w w w .j a va 2s.  c om*/
    TreeImageDisplay root = getTreeRoot();
    root.removeAllChildren();
    root.removeAllChildrenDisplay();
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    tm.reload();
}

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

/** 
 * Reloads the specified node.//from   w  w  w .j a  v a  2s  .com
 * 
 * @param node The node to reload.
 */
void reloadNode(TreeImageDisplay node) {
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    if (node == null)
        tm.reload();
    else
        tm.reload(node);
}

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

/**
* Adds the specified groups to the tree.
* 
* @param group The group to add./*  w w w. j a v  a2 s  . c  o m*/
*/
void setUserGroup(List<GroupData> groups) {
    if (groups == null || groups.size() == 0)
        return;
    ExperimenterData exp = model.getUserDetails();
    TreeImageSet node;
    Iterator<GroupData> i = groups.iterator();
    while (i.hasNext()) {
        node = createGroup(i.next());
        node = createExperimenterNode(exp, node);

    }
    DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel();
    dtm.reload();

}

From source file:org.openmicroscopy.shoola.agents.treeviewer.util.MoveGroupSelectionDialog.java

/**
 * Sets the values where to import the data.
 * //from  w  w  w.  ja  va  2 s  .  co  m
 * @param targets The values to display.
 */
public void setTargets(Collection<DataObject> targets) {
    Container c = getContentPane();
    c.remove(body);
    c.remove(1);
    treeDisplay = new JTree();
    treeDisplay.setVisible(true);
    treeDisplay.setRootVisible(false);
    ToolTipManager.sharedInstance().registerComponent(treeDisplay);
    treeDisplay.setCellRenderer(new TreeCellRenderer(userID));
    treeDisplay.setShowsRootHandles(true);
    TreeImageSet root = new TreeImageSet("");
    treeDisplay.setModel(new DefaultTreeModel(root));
    treeDisplay.addTreeSelectionListener(this);
    if (CollectionUtils.isEmpty(targets)) {
        buildNoContentPane();
        return;
    }
    Set<TreeImageDisplay> nodes = TreeViewerTranslator.transformHierarchy(new ArrayList<Object>(targets));
    List<TreeImageDisplay> transformedNodes = prepareSortedList(sorter.sort(nodes));
    if (transformedNodes.size() == 0) {
        buildNoContentPane();
        return;
    }
    DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel();
    buildTreeNode(root, transformedNodes, dtm);
    dtm.reload();
    c.add(new JScrollPane(treeDisplay), BorderLayout.CENTER);
    c.add(buildToolBar(), BorderLayout.SOUTH);
    validate();
    repaint();
}