Example usage for javax.swing JTree setModel

List of usage examples for javax.swing JTree setModel

Introduction

In this page you can find the example usage for javax.swing JTree setModel.

Prototype

@BeanProperty(description = "The TreeModel that will provide the data.")
public void setModel(TreeModel newModel) 

Source Link

Document

Sets the TreeModel that will provide the data.

Usage

From source file:org.kepler.objectmanager.library.LibraryManager.java

/**
 * Refresh and redraw any JTrees that the LibraryManager is keeping track
 * of./* ww w .jav a 2s.c o  m*/
 * 
 *@exception IllegalActionException
 *                Description of the Exception
 */
public void refreshJTrees() throws IllegalActionException {
    if (isDebugging) {
        log.debug("refresh");
    }

    // Iterate over all the registered JTrees and reset their models.
    //Iterator<WeakReference> treeItt = _trees.iterator();

    int size = _trees.size();
    int i = 0;
    while (i < size) {
        WeakReference<JTree> wf = _trees.elementAt(i);
        JTree ptree = (JTree) wf.get();
        if (ptree == null) {
            _trees.remove(wf);
            size--;
        } else {
            ptree.setModel(getTreeModel());

            // stop listening for expansion events since we are going to
            // expand the paths and do not want to modify the list
            ptree.removeTreeExpansionListener(this);

            // expand all the paths that were previously expanded
            final List<TreePath> expansions = _treeExpansionMap.get(ptree);
            for (TreePath path : expansions) {
                //System.out.println("expanding " + path);
                ptree.expandPath(path);
            }

            // start listening again for expansion events
            ptree.addTreeExpansionListener(this);

            /*
            EntityTreeModel etm = (EntityTreeModel) ptree.getModel();
                    
            // Of course this would be easier if
            // ptolemy.vergil.tree.EntityTreeModel
            // had a reload method similar to DefaultTreeModel
            // that did this for us
            // TODO etm.reload()
                    
            ArrayList<NamedObj> path = new ArrayList<NamedObj>();
            path.add(0, (NamedObj) etm.getRoot());
            TreePath tp = new TreePath(path);
            etm.valueForPathChanged(tp, etm.getRoot());
            */
            i++;
        }
    }
}

From source file:org.olivier.ihm.FramePUMLCleanerControler.java

/**
 * Analyser le fichier PUML et initialiser le filtre
 *
 * @param jTextAreaFichier Le contenu du fichier PUML
 * @param jTreeFiltre Le filtre  initialiser
 *///from  w w  w  . j  av a  2s .  c o  m
private void analyserFichier(JTextArea jTextAreaFichier, JTree jTreeFiltre) {
    lines = jTextAreaFichier.getText().split("[\\r\\n]+");

    final DefaultMutableTreeNode newFilter = initaliserNodes();

    // parcours de chaque ligne du fichier pour analyse
    for (String line : lines) {
        if (line.contains(">")) {
            break;
        } else {
            String categ = "";
            String noeud = null;
            // recherche de la catgorie
            for (String categorie : categories) {
                if (line.contains(categorie)) {
                    categ = categorie;
                    noeud = line.replaceFirst(categorie, "").replaceAll(" ", "");
                    // ajout du noeud dans la bonne catgorie de l'arbre
                    for (int i = 0; i < newFilter.getChildCount(); i++) {
                        final DefaultMutableTreeNode dmtr = (DefaultMutableTreeNode) newFilter.getChildAt(i);
                        if (dmtr.toString().equals(categ)) {
                            final DefaultMutableTreeNode node = new DefaultMutableTreeNode(new NodeInfo(noeud));
                            dmtr.add(node);
                        }
                    }
                    break;
                }
            }
        }
    }
    jTreeFiltre.setModel(new DefaultTreeModel(newFilter));
    jTextAreaFichier.requestFocus();
}

From source file:org.openmicroscopy.shoola.agents.util.SelectionWizardUI.java

/**
 * Initializes the specified tree/*from  w  w  w .java  2 s .c om*/
 * 
 * @param tree The tree to handle.
 * @param user The user currently logged in.
 */
private void initializeTree(JTree tree, ExperimenterData user) {
    tree.setVisible(true);
    tree.setRootVisible(false);
    ToolTipManager.sharedInstance().registerComponent(tree);
    tree.setCellRenderer(new TreeCellRenderer(user.getId()));
    tree.setShowsRootHandles(true);
    TreeImageSet root = new TreeImageSet("");
    tree.setModel(new DefaultTreeModel(root));
}