Example usage for javax.swing.tree DefaultTreeModel nodeStructureChanged

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

Introduction

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

Prototype

public void nodeStructureChanged(TreeNode node) 

Source Link

Document

Invoke this method if you've totally changed the children of node and its children's children...

Usage

From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java

/**
 *  Description of the Method//w  w w .  ja v a 2  s.  com
 */
void updateTreeNode() {
    DefaultMutableTreeNode selectedNode = getSelectedNode();

    selectedNode
            .setUserObject(new TreeConcept((Concept) Dispatcher.getDispatcher(Concept.class).getValueObject()));

    /*
     * Announcing the node structure change triggers the necessary repaint to
     * display the effects of changes.
     */
    DefaultTreeModel model = (DefaultTreeModel) getModel();

    model.nodeStructureChanged(selectedNode);
}

From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java

/**
 * Sets the parent node of the currently selected node to be the node
 * representing the <code>Concept</code> of the specified name.
 *
 * @param  newParentName   The name of the <code>Concept</code> for which the currently selected
 *  node is to become a child./* w w  w  .j av  a  2s.co  m*/
 */
public void updateTreeNodeParent(String newParentName) {

    // Get the node being moved
    DefaultMutableTreeNode conceptNode = (DefaultMutableTreeNode) getSelectionPath().getLastPathComponent();
    String conceptNodeName = ((TreeConcept) conceptNode.getUserObject()).getName();
    DefaultTreeModel treeModel = (DefaultTreeModel) getModel();

    // Remove node from current parent node and update structure
    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) conceptNode.getParent();

    parentNode.remove(conceptNode);
    treeModel.nodeStructureChanged(parentNode);

    // Get the new parent node
    DefaultMutableTreeNode newParentNode = expandDownToNode(newParentName);
    TreeConcept treeConcept = (TreeConcept) newParentNode.getUserObject();
    boolean parentNeededExpanding = treeConcept.lazyExpand(newParentNode);

    // Branch on whether parent needed expanding:
    // - The parent node needed to be expanded. The call to lazyExpand()
    // updates the parent node's children so we don't need to explicitly add
    // the new child node. Find and select the new child node.
    // - The parent node is already expanded, so insert the new child node in
    // the appropriate slot and select the new child node.
    if (parentNeededExpanding) {
        Enumeration children = newParentNode.children();

        while (children.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
            String nodeName = ((TreeConcept) node.getUserObject()).getName();

            if (nodeName.equals(conceptNodeName)) {
                setSelectionPath(new TreePath(node.getPath()));

                break;
            }
        }
    } else {

        // Insert the node at the appropriate point in the new parent node.
        int insertPosition = 0;
        Enumeration children = newParentNode.children();

        while (children.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
            String nodeName = ((TreeConcept) node.getUserObject()).getName();

            if (0 < nodeName.compareTo(conceptNodeName)) {
                break;
            } else {
                insertPosition++;
            }
        }

        treeModel.insertNodeInto(conceptNode, newParentNode, insertPosition);
        setSelectionPath(new TreePath(conceptNode.getPath()));
    }
}

From source file:org.nuclos.client.explorer.ExplorerNode.java

/**
 * refreshes the current node (and its children) and notifies the given treemodel
 * @param dtm the DefaultTreeModel to notify. Must contain this node.
 * @throws CommonFinderException if the object presented by this node no longer exists.
 *///from  www.j ava 2s  .c om
public void refresh(final JTree tree, boolean fullRefreshCurrent) throws CommonFinderException {
    List<String> lstExpandedPathsResult = new ArrayList<String>();
    ExplorerNode.createExpandendPathsForTree(new TreePath(tree.getModel().getRoot()), tree,
            lstExpandedPathsResult);

    final TreePath selected = tree.getSelectionPath();
    DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel();
    unloadChildren();

    final TN treenode = getTreeNode();
    if (treenode.implementsNewRefreshMethod()) {
        TN refreshed = null;
        if (fullRefreshCurrent && !this.isRoot()) {
            TreeNode parentTreeNode = ((ExplorerNode<TN>) this.getParent()).getTreeNode();
            parentTreeNode.removeSubNodes();
            List<? extends TreeNode> parentSubNodes = parentTreeNode.getSubNodes();
            for (TreeNode parentSubNode : parentSubNodes) {
                if (ObjectUtils.equals(parentSubNode.getId(), treenode.getId()))
                    refreshed = (TN) parentSubNode;
            }
            if (refreshed == null) {
                this.removeFromParent();
                dtm.nodeStructureChanged(this);
                return;
            }
        } else {
            refreshed = (TN) treenode.refreshed();
        }
        setTreeNode(refreshed);
    } else {
        treenode.refresh();
    }
    treenode.removeSubNodes();
    loadChildren(true);

    assert getChildrenHaveBeenLoaded();

    dtm.nodeStructureChanged(this);

    ExplorerNode.expandTreeAsync(lstExpandedPathsResult, tree);

    if (selected != null) {
        List<Object> pathEssence = CollectionUtils.asList(selected.getPath());
        Collections.reverse(pathEssence);
        if (pathEssence.size() > 1) {
            pathEssence = pathEssence.subList(0, pathEssence.size() - 1);
            new Thread(new TreeExpander(tree, pathEssence)).start();
        }
    }
}

From source file:org.nuclos.client.ui.collect.searcheditor.SearchConditionTreeNode.java

/**
 * refreshes the current node (and its children) and notifies the given treemodel
 * @param dtm the DefaultTreeModel to notify. Must contain this node.
 *///from   w w  w  .jav a 2 s  .  c  om
protected void refresh(DefaultTreeModel dtm) {
    dtm.nodeStructureChanged(this);
}

From source file:org.optaplanner.benchmark.impl.aggregator.swingui.BenchmarkAggregatorFrame.java

private void refresh() {
    initPlannerBenchmarkResultList();//from w w w  .j a va2 s .  co m
    solverBenchmarkResultNameMapping = new HashMap<SolverBenchmarkResult, String>();
    resultCheckBoxMapping = new LinkedHashMap<SingleBenchmarkResult, DefaultMutableTreeNode>();
    checkBoxTree.setSelectedSingleBenchmarkNodes(new HashSet<DefaultMutableTreeNode>());
    DefaultMutableTreeNode newCheckBoxRootNode = initBenchmarkHierarchy(true);
    DefaultTreeModel treeModel = new DefaultTreeModel(newCheckBoxRootNode);
    checkBoxTree.setModel(treeModel);
    treeModel.nodeStructureChanged(newCheckBoxRootNode);
    setEnabled(true);
}