Example usage for javax.swing.event TreeSelectionEvent TreeSelectionEvent

List of usage examples for javax.swing.event TreeSelectionEvent TreeSelectionEvent

Introduction

In this page you can find the example usage for javax.swing.event TreeSelectionEvent TreeSelectionEvent.

Prototype

public TreeSelectionEvent(Object source, TreePath path, boolean isNew, TreePath oldLeadSelectionPath,
        TreePath newLeadSelectionPath) 

Source Link

Document

Represents a change in the selection of a TreeSelectionModel .

Usage

From source file:com.lp.client.frame.component.PanelDokumentenablage.java

private void refresh() throws ExceptionLP, Throwable {
    List<DocNodeBase> parts = fullDocPath.getDeepCopy().asDocNodeList();
    boolean isSuche = wtfSuche.getText() != null && !"".equals(wtfSuche.getText());

    DefaultMutableTreeNode dmtNode = null;
    Object[] toSelect = new Object[parts.size()];
    if (parts.size() > 0) {
        dmtNode = new DefaultMutableTreeNode(parts.get(0));
        toSelect[0] = dmtNode;//from   www  . ja  v a  2 s  .  c  om
        treeModel = new DefaultTreeModel(dmtNode);
        treeModel.addTreeModelListener(this);
    }
    for (int i = 1; i < parts.size() && !isSuche; i++) {
        DefaultMutableTreeNode toAdd = new DefaultMutableTreeNode(parts.get(i));
        toSelect[i] = toAdd;
        treeModel.insertNodeInto(toAdd, dmtNode, dmtNode.getChildCount());
        dmtNode = toAdd;
    }
    TreePath treePath = new TreePath(toSelect);
    TreePath treePathOld = null;
    if (toSelect.length >= 2) {
        treePathOld = new TreePath(toSelect[toSelect.length - 2]);
    } else {
        treePathOld = new TreePath(toSelect);
    }
    // Value Changed damit die Buttons korrekt angezeigt werden
    valueChanged(new TreeSelectionEvent(tree, treePath, true, treePathOld, treePath));
    if (isSuche) {
        setSearchedDocumentsOnTree(dmtNode,
                DelegateFactory.getInstance().getJCRDocDelegate().searchDocNodes(wtfSuche.getText()));
        for (int i = tree.getRowCount(); i > 0; i--) {
            tree.collapseRow(i);
        }
    } else if (dmtNode.getChildCount() == 0) {
        List<DocNodeBase> childDocNodes = DelegateFactory.getInstance().getJCRDocDelegate()
                .getDocNodeChildrenFromNode(fullDocPath);
        if (childDocNodes != null) {
            setDocNodesOnTree(dmtNode, childDocNodes, fullDocPath);
            tree.expandPath(treePath);
        }
    }
    tree.setSelectionPath(treePath);
}