Example usage for javax.swing.tree DefaultTreeModel nodeChanged

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

Introduction

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

Prototype

public void nodeChanged(TreeNode node) 

Source Link

Document

Invoke this method after you've changed how node is to be represented in the tree.

Usage

From source file:Main.java

public static void main(String[] args) {

    DefaultMutableTreeNode root = new DefaultMutableTreeNode(Boolean.TRUE);
    DefaultMutableTreeNode child1 = new DefaultMutableTreeNode(Boolean.FALSE);
    DefaultMutableTreeNode child2 = new DefaultMutableTreeNode(Boolean.FALSE);
    root.add(child1);//from  www  .  j  a v a2 s  . c  o  m
    root.add(child2);
    DefaultTreeModel model = new DefaultTreeModel(root);

    JTree tree = new JTree(model);
    tree.setCellRenderer(new TreeRenderer());

    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            TreePath pathForLocation = tree.getPathForLocation(e.getX(), e.getY());
            Object lastPathComponent = pathForLocation.getLastPathComponent();
            if (lastPathComponent instanceof DefaultMutableTreeNode) {
                Boolean oldObject = (Boolean) ((DefaultMutableTreeNode) lastPathComponent).getUserObject();
                ((DefaultMutableTreeNode) lastPathComponent).setUserObject(!oldObject);
                model.nodeChanged((DefaultMutableTreeNode) lastPathComponent);
            }
        }
    });

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(tree, BorderLayout.CENTER);
    frame.setSize(800, 600);
    frame.setVisible(true);
}

From source file:edu.ku.brc.specify.tasks.subpane.security.NavigationTreeContextMenuMgr.java

/**
 * @param node//from   w  w  w .  j a v a 2s . c o  m
 */
private void addToAdminGroup(final DefaultMutableTreeNode node) {
    if (node != null) {
        Object userObject = node.getUserObject();
        if (userObject != null) {
            FormDataObjIFace dmObject = ((DataModelObjBaseWrapper) userObject).getDataObj();
            if (dmObject != null && dmObject instanceof SpecifyUser) {
                SpPrincipal adminPrin = null;
                DataProviderSessionIFace session = null;
                try {
                    session = DataProviderFactory.getInstance().createSession();
                    adminPrin = (SpPrincipal) session.getData(SpPrincipal.class, "name", "Administrator",
                            DataProviderSessionIFace.CompareType.Equals);
                    if (adminPrin != null) {
                        SpecifyUser spUser = session.get(SpecifyUser.class, ((SpecifyUser) dmObject).getId());
                        spUser.addUserToSpPrincipalGroup(adminPrin);

                        session.beginTransaction();
                        session.saveOrUpdate(spUser);
                        session.saveOrUpdate(adminPrin);
                        session.commit();

                        DefaultMutableTreeNode adminNode = getAdminTreeNode(
                                (DefaultMutableTreeNode) treeMgr.getTree().getModel().getRoot());
                        DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(
                                new DataModelObjBaseWrapper(spUser));

                        DefaultTreeModel model = (DefaultTreeModel) getTree().getModel();
                        model.insertNodeInto(newNode, adminNode, adminNode.getChildCount());
                        model.nodeChanged(adminNode);
                        model.nodeChanged(newNode);
                        getTree().repaint();

                        getTree().setSelectionPath(new TreePath(newNode.getPath()));

                        lastClickComp = null;
                        updateBtnUI();
                    }

                } catch (final Exception e1) {
                    e1.printStackTrace();

                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(NavigationTreeMgr.class, e1);
                    session.rollback();

                } finally {
                    if (session != null) {
                        session.close();
                    }
                }
            }
        }
    }
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java

public void propertyChange(PropertyChangeEvent evt) {
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    model.nodeChanged((TreeNode) model.getRoot());

    previewPanel.rebuild(selectedAltView.getMode() == AltViewIFace.CreationMode.EDIT);
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java

/**
 * Tells the tree model that a node hash changed.
 * @param parentNode the parent node/*  w  w  w  . ja  va 2s.  co m*/
 * @param model the tree model
 * @param updateChildren update kids
 */
protected void updateTreeNodes(final DefaultMutableTreeNode parentNode, final DefaultTreeModel model,
        final boolean updateChildren) {
    model.nodeChanged(parentNode);
    if (updateChildren) {
        for (int i = 0; i < parentNode.getChildCount(); i++) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) parentNode.getChildAt(i);
            updateTreeNodes(node, model, true);
        }
    }
}

From source file:src.gui.ItSIMPLE.java

/**
    * This method should be called every time the user changes
    * the names of elements in the project tree.
    *//* w w w. jav  a 2  s.c o m*/
private void updateTreeChanges(DefaultTreeModel treeModel) {
    //1. get tree root
    ItTreeNode problemsPlanTreeRoot = (ItTreeNode) treeModel.getRoot();

    //1.1 for each project...
    for (int projectIndex = 0; projectIndex < problemsPlanTreeRoot.getChildCount(); projectIndex++) {
        ItTreeNode project = (ItTreeNode) problemsPlanTreeRoot.getChildAt(projectIndex);

        //1.2 update project name
        String projectName = project.getData().getChildText("name");
        if (!projectName.equals(project.getUserObject())) {
            project.setUserObject(projectName);
            treeModel.nodeChanged(project);
        }

        //Check if it is a UML project
        if (project.getData().getName().equals("project")) {
            //1.3 for each domain in project...
            for (int domainIndex = 0; domainIndex < project.getChildCount(); domainIndex++) {
                ItTreeNode domain = (ItTreeNode) project.getChildAt(domainIndex);

                // 1.4 update domain name
                String domainName = domain.getData().getChildText("name");
                if (!domainName.equals(domain.getUserObject())) {
                    domain.setUserObject(domainName);
                    treeModel.nodeChanged(domain);
                }

                //1.5 for each problem in domain...
                for (int problemIndex = 0; problemIndex < domain.getChildCount(); problemIndex++) {
                    ItTreeNode problem = (ItTreeNode) domain.getChildAt(problemIndex);

                    //1.6 update problem name
                    String problemName = problem.getData().getChildText("name");
                    if (!problemName.equals(problem.getUserObject())) {
                        problem.setUserObject(problemName);
                        treeModel.nodeChanged(problem);
                    }
                }
            }

        }
        //Check if it is a PDDL project
        else if (project.getData().getName().equals("pddlproject")) {
            //1.3 for each problem instance in project...
            for (int problemIndex = 0; problemIndex < project.getChildCount(); problemIndex++) {
                ItTreeNode problem = (ItTreeNode) project.getChildAt(problemIndex);

                // 1.4 update domain name
                String domainName = problem.getData().getChildText("name");
                if (!domainName.equals(problem.getUserObject())) {
                    problem.setUserObject(domainName);
                    treeModel.nodeChanged(problem);
                }

            }

        }

    }

}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

/**
 * Refreshes Entity tree to expand any labels that may not have rendered fully. Eg. "Som..." instead of "Some Folder" 
 *///from www.  j  av  a 2 s .c  o m
private void refreshEntityTree() {
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) theEntityTree.getModel().getRoot();
    DefaultTreeModel model = (DefaultTreeModel) theEntityTree.getModel();
    if (rootNode.getChildCount() > 0) {
        for (int i = 0; i < rootNode.getChildCount(); i++) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) rootNode.getChildAt(i);
            model.nodeStructureChanged(child);
            model.nodeChanged(child);
        }
        expandNode(theEntityTree, rootNode, true);
    }
}

From source file:org.codinjutsu.tools.jenkins.view.BrowserPanel.java

private void updateJobNode(Job job) {
    final DefaultTreeModel model = (DefaultTreeModel) jobTree.getModel();
    final Object modelRoot = model.getRoot();
    final int childCount = model.getChildCount(modelRoot);
    for (int i = 0; i < childCount; ++i) {
        Object child = model.getChild(modelRoot, i);
        if (child instanceof DefaultMutableTreeNode) {
            DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child;
            if (childNode.getUserObject() == job) {
                model.nodeChanged(childNode);
                break;
            }/*www .jav  a2s. c  o  m*/
        }
    }
}

From source file:org.fseek.simon.swing.util.TreeUtil.java

private static void addFiles(File[] files, final LinkTreeNode root, final DefaultTreeModel model,
        boolean showFiles, boolean showHidden) {
    for (int i = 0; i < files.length; i++) {
        if (Thread.interrupted()) {
            break;
        }//  www. java2 s .  c om
        File f = files[i];
        if (f.isDirectory() || showFiles == true) {
            final LinkTreeNode childNode = new DefaultLinkTreeNode(f, new IconChangedListener() {
                @Override
                public void iconChanged(final LinkTreeNode node, Icon newIcon) {
                    EventQueue.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            model.nodeChanged(node);
                        }
                    });
                }
            });
            final int index = i;
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    model.insertNodeInto(childNode, root, index);
                }
            });
            AddChildsThread create = AddChildsThread.create(model, childNode, false, showFiles, showHidden,
                    true);
            if (create.isAlive() && create.isFake() == false) {
                create.interrupt();
                try {
                    create.join();
                    create = AddChildsThread.create(model, childNode, false, showFiles, showHidden, true);
                    create.start();
                } catch (InterruptedException ex) {
                    return;
                }
            } else if (create.isAlive() == false) {
                create.start();
            }
        }
    }
}

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

/**
 * Update the specified set of nodes./*from w w w.  j av  a 2  s .  c o m*/
 * 
 * @param nodes The collection of nodes to update.
 * @param object The <code>DataObject</code> to update.
 */
void updateNodes(List nodes, DataObject object) {
    DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel();
    Iterator i = nodes.iterator();
    TreeImageDisplay node;
    while (i.hasNext()) {
        node = (TreeImageDisplay) i.next();
        node.setUserObject(object);
        dtm.nodeChanged(node);
    }
}