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(TreeNode node) 

Source Link

Document

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

Usage

From source file:com.imaginea.betterdocs.BetterDocsAction.java

public void runAction(final AnActionEvent e) throws IOException {
    final Editor projectEditor = DataKeys.EDITOR.getData(e.getDataContext());

    if (projectEditor != null) {

        Set<String> imports = getImports(projectEditor.getDocument());
        Set<String> lines = getLines(projectEditor, projectEditor.getDocument());
        Set<String> importsInLines = importsInLines(lines, imports);

        DefaultTreeModel model = (DefaultTreeModel) jTree.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
        root.removeAllChildren();/*from   ww w  .ja  v a2  s  .  c  om*/

        if (!importsInLines.isEmpty()) {
            jTree.setVisible(true);
            String esQueryJson = getESQueryJson(importsInLines);
            String esResultJson = getESResultJson(esQueryJson, esURL + BETTERDOCS_SEARCH);

            if (!esResultJson.equals(EMPTY_ES_URL)) {
                Map<String, String> fileTokensMap = getFileTokens(esResultJson);
                Map<String, ArrayList<CodeInfo>> projectNodes = new HashMap<String, ArrayList<CodeInfo>>();

                updateProjectNodes(imports, fileTokensMap, projectNodes);
                updateRoot(root, projectNodes);

                model.reload(root);
                jTree.addTreeSelectionListener(getTreeSelectionListener(root));
            } else {
                Messages.showInfoMessage(EMPTY_ES_URL, INFO);
            }
        } else {
            jTree.updateUI();
        }
    }
}

From source file:GUI.MainWindow.java

private void ViewModeTabPaneStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_ViewModeTabPaneStateChanged
    JTabbedPane sourceTabbedPane = (JTabbedPane) evt.getSource();
    int index = sourceTabbedPane.getSelectedIndex();
    String title = sourceTabbedPane.getTitleAt(index);
    System.out.println("Tab changed to: " + sourceTabbedPane.getTitleAt(index));

    Object layout = RightPanelCardLayout.getLayout();
    if (layout instanceof java.awt.CardLayout) {
        java.awt.CardLayout cl = (java.awt.CardLayout) layout;
        if (title.equalsIgnoreCase("Vuln View")) {
            // Show the vuln view card
            cl.show(RightPanelCardLayout, "vulnView");

        } else if (title.equalsIgnoreCase("Host View")) {
            DefaultMutableTreeNode hostRoot = new TreeUtils()
                    .convertVulnViewToHostView((DefaultMutableTreeNode) this.VulnTree.getModel().getRoot());
            DefaultTreeModel dtm = ((DefaultTreeModel) this.HostTree.getModel());
            dtm.setRoot(hostRoot);// w  w w  .j  a  va2  s .  c  o m
            dtm.reload(hostRoot);
            // Expand all nodes to make everything visible
            new TreeUtils().expandAll(this.HostTree);
            // Show the host view card
            cl.show(RightPanelCardLayout, "hostView");
        }
    }

    //cardLayout.show(cardPanel, "CardToShow");
    //java.awt.CardLayout cl = (java.awt.CardLayout)(RightPanelCardLayout.getLayout()) ;
    //        

}

From source file:org.codinjutsu.tools.mongo.view.MongoEditionPanel.java

public void addKey(String key, Object value) {

    List<TreeNode> node = new LinkedList<TreeNode>();
    JsonTreeNode treeNode = new JsonTreeNode(MongoKeyValueDescriptor.createDescriptor(key, value));

    if (value instanceof DBObject) {
        JsonTreeModel.processDbObject(treeNode, (DBObject) value);
    }// w  ww  . j av  a2  s . c  om

    node.add(treeNode);

    DefaultTreeModel treeModel = (DefaultTreeModel) editTableView.getTree().getModel();
    JsonTreeNode parentNode = getParentNode();
    if (parentNode == null) {
        parentNode = (JsonTreeNode) treeModel.getRoot();
    }
    TreeUtil.addChildrenTo(parentNode, node);
    treeModel.reload(parentNode);
}

From source file:org.codinjutsu.tools.mongo.view.MongoEditionPanel.java

public void addValue(Object value) {
    List<TreeNode> node = new LinkedList<TreeNode>();

    JsonTreeNode parentNode = getParentNode();

    JsonTreeNode treeNode = new JsonTreeNode(
            MongoValueDescriptor.createDescriptor(parentNode.getChildCount(), value));
    if (value instanceof DBObject) {
        JsonTreeModel.processDbObject(treeNode, (DBObject) value);
    }/*from www.  j  a v  a2  s  . c om*/

    node.add(treeNode);

    DefaultTreeModel treeModel = (DefaultTreeModel) editTableView.getTree().getModel();
    TreeUtil.addChildrenTo(parentNode, node);
    treeModel.reload(parentNode);
}

From source file:org.codinjutsu.tools.nosql.mongo.view.MongoEditionPanel.java

public void addKey(String key, Object value) {

    List<TreeNode> node = new LinkedList<>();
    NoSqlTreeNode treeNode = new NoSqlTreeNode(MongoKeyValueDescriptor.createDescriptor(key, value));

    if (value instanceof Document || value instanceof List) {
        JsonTreeModel.processDocument(treeNode, value);
    }//from   w ww  .j  a va2s.c  om

    node.add(treeNode);

    DefaultTreeModel treeModel = (DefaultTreeModel) editTableView.getTree().getModel();
    NoSqlTreeNode parentNode = getParentNode();
    if (parentNode == null) {
        parentNode = (NoSqlTreeNode) treeModel.getRoot();
    }
    TreeUtil.addChildrenTo(parentNode, node);
    treeModel.reload(parentNode);
}

From source file:org.codinjutsu.tools.nosql.mongo.view.MongoEditionPanel.java

public void addValue(Object value) {
    List<TreeNode> node = new LinkedList<>();

    NoSqlTreeNode parentNode = getParentNode();

    assert parentNode != null;

    NoSqlTreeNode treeNode = new NoSqlTreeNode(
            MongoValueDescriptor.createDescriptor(parentNode.getChildCount(), value));
    if (value instanceof Document || value instanceof List) {
        JsonTreeModel.processDocument(treeNode, value);
    }/*from   w w  w.ja  va2  s .c om*/

    node.add(treeNode);

    DefaultTreeModel treeModel = (DefaultTreeModel) editTableView.getTree().getModel();
    TreeUtil.addChildrenTo(parentNode, node);
    treeModel.reload(parentNode);
}

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

/**
 * Loads the branch of a particular concept. This method does the following
 * <ol>/*ww  w  .ja  v  a2 s  . c  o  m*/
 *      <li>Walks from the concept up the tree to the root concept, storing
 *      the concepts in a list. (This is very fast)</li>
 *  <li>Starts walking from the root down (using lazyExpand), searching each
 *      childnode for a matching primary name (which was stored in the first
 *      step</li>
 *  <li>If a matching primary name is found this stops otherwise
 *              it opens the next level and searches for the next mathc in the list.</li>
 *  <li></li>
 * </ol>
 * @param concept
 */
private void openNode(final Concept concept) {
    if (log.isDebugEnabled()) {
        log.debug("Opening node containing " + concept);
    }

    if (concept == null) {
        return;
    }

    // Get the list of concepts up to root
    final LinkedList conceptList = new LinkedList();
    Concept c = concept;

    while (c != null) {
        conceptList.add(c);
        c = (Concept) c.getParentConcept();
    }

    // Walk the tree from root on down opening nodes as we go
    final ListIterator i = conceptList.listIterator(conceptList.size());

    // Skip the root
    i.previous();

    final JTree tree = getJTree();
    final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
    final DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot();
    TreePath path = new TreePath(rootNode.getPath());

    tree.setSelectionPath(path);

    DefaultMutableTreeNode parentNode = rootNode;

    while (i.hasPrevious()) {
        c = (Concept) i.previous();

        final TreeConcept parentTreeConcept = (TreeConcept) parentNode.getUserObject();

        parentTreeConcept.lazyExpand(parentNode);

        // treeModel.reload(parentNode);
        final Enumeration enm = parentNode.children();

        while (enm.hasMoreElements()) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) enm.nextElement();
            final TreeConcept tc = (TreeConcept) node.getUserObject();

            if (tc.getName().equals(c.getPrimaryConceptNameAsString())) {
                parentNode = node;

                break;
            }
        }
    }

    final TreeNode _parentNode = parentNode;

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            treeModel.reload(_parentNode);
            tree.scrollPathToVisible(new TreePath(_parentNode));
        }
    });
}

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

/**
 * Adds the nodes to the specified parent.
 * //from  w w w .j a  v  a  2 s.c o  m
 * @param parent    The parent node.
 * @param nodes     The list of nodes to add.
 * @param tm        The  tree model.
 */
private void buildTreeNode(TreeImageDisplay parent, Collection nodes, DefaultTreeModel tm) {
    if (nodes.size() == 0) {
        tm.insertNodeInto(new DefaultMutableTreeNode(Browser.EMPTY_MSG), parent, parent.getChildCount());
        return;
    }
    Iterator i = nodes.iterator();
    TreeImageDisplay display;
    List children;
    parent.removeAllChildren();
    int browserType = model.getBrowserType();
    Object uo;
    while (i.hasNext()) {
        display = (TreeImageDisplay) i.next();
        tm.insertNodeInto(display, parent, parent.getChildCount());

        if (display instanceof TreeImageSet) {
            children = display.getChildrenDisplay();
            if (children.size() > 0) {
                if (display.containsImages()) {
                    display.setExpanded(true);
                    setExpandedParent(display, false);
                    nodesToReset.add(display);
                    buildTreeNode(display, prepareSortedList(sorter.sort(children)), tm);
                    expandNode(display);
                    tm.reload(display);
                } else {
                    if (browserType == Browser.TAGS_EXPLORER) {
                        if (display.isExpanded()) {
                            setExpandedParent(display, false);
                            nodesToReset.add(display);
                        }
                        buildTreeNode(display, prepareSortedList(sorter.sort(children)), tm);
                        if (display.isExpanded()) {
                            expandNode(display);
                            tm.reload(display);
                        }
                    } else {
                        if (display.isExpanded()) {
                            setExpandedParent(display, true);
                            nodesToReset.add(display);
                        }
                        buildTreeNode(display, prepareSortedList(sorter.sort(children)), tm);
                    }
                }
            } else {
                uo = display.getUserObject();
                if (uo instanceof DatasetData) {
                    tm.insertNodeInto(new DefaultMutableTreeNode(Browser.EMPTY_MSG), display,
                            display.getChildCount());
                } else if (uo instanceof TagAnnotationData) {
                    TagAnnotationData tag = (TagAnnotationData) uo;
                    if (!(TagAnnotationData.INSIGHT_TAGSET_NS.equals(tag.getNameSpace()))) {
                        tm.insertNodeInto(new DefaultMutableTreeNode(Browser.EMPTY_MSG), display,
                                display.getChildCount());
                    }
                } else if (uo instanceof GroupData) {
                    tm.insertNodeInto(new DefaultMutableTreeNode(Browser.EMPTY_MSG), display,
                            display.getChildCount());
                } else if (uo instanceof FileAnnotationData) {
                    if (browserType == Browser.SCREENS_EXPLORER) {
                        TreeImageSet n = new TreeImageSet(uo);
                        tm.insertNodeInto(new DefaultMutableTreeNode(Browser.EMPTY_MSG), n, n.getChildCount());
                    }
                }
            }
        }
    }
    if (parent.isExpanded()) {
        expandNode(parent);
        tm.reload(parent);
    }
}

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

/**
 * Sorts the children of the passed node.
 * /*from w ww  .j  av  a 2 s.c o m*/
 * @param node The node to handle.
 */
private void sortNode(TreeImageSet node) {
    DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel();
    List children = node.getChildrenDisplay();
    Iterator j;
    if (node.containsImages()) {
        node.removeAllChildren();
        dtm.reload(node);
        if (children.size() != 0) {
            buildTreeNode(node, sorter.sort(children), dtm);
        } else
            buildEmptyNode(node);
        j = nodesToReset.iterator();
        while (j.hasNext()) {
            setExpandedParent((TreeImageDisplay) j.next(), true);
        }
    } else {
        if (children.size() != 0) {
            j = children.iterator();
            while (j.hasNext())
                sortNode((TreeImageSet) j.next());
        } else
            buildEmptyNode(node);
    }
}

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

/**
 * Creates a dummy loading node whose parent is the specified node.
 * // w ww .  j  a  va2 s . co m
 * @param parent The parent node.
 */
void loadAction(TreeImageDisplay parent) {
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    parent.removeAllChildren();
    tm.insertNodeInto(new DefaultMutableTreeNode(Browser.LOADING_MSG), parent, parent.getChildCount());
    tm.reload(parent);
}