Example usage for javax.swing.tree DefaultMutableTreeNode getChildCount

List of usage examples for javax.swing.tree DefaultMutableTreeNode getChildCount

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode getChildCount.

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children of this node.

Usage

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

public DefaultMutableTreeNode addNode(QueryConceptTreeNodeData node) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData();
    tmpData.name("working ......");
    tmpData.tooltip("A tmp node");
    tmpData.visualAttribute("LAO");
    DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData);

    treeModel.insertNodeInto(childNode, top, top.getChildCount());
    treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    // Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    return childNode;
}

From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java

/**
 * @param node//ww  w  .j a  v a 2  s  .com
 * @param containersToBeDeleted
 * @param colObjsToBeUpdated
 */
private void recursePrune(final DefaultMutableTreeNode node, final ArrayList<Container> containersToBeDeleted,
        final ArrayList<CollectionObject> colObjsToBeUpdated) {
    if (node.getUserObject() instanceof Container) {
        Container cn = (Container) node.getUserObject();
        if (cn.getId() != null) {
            containersToBeDeleted.add(cn);
            containerIdHash.remove(cn.getId());

            CollectionObject co = cn.getCollectionObject();
            if (co != null) {
                cn.getCollectionObjects().clear();
                co.setContainer(null);
                colObjsToBeUpdated.add(cn.getCollectionObject());
                colObjIdHash.remove(co.getId());
            }

            for (int i = 0; i < node.getChildCount(); i++) {
                recursePrune((DefaultMutableTreeNode) node.getChildAt(i), containersToBeDeleted,
                        colObjsToBeUpdated);
            }
            cn.getChildren().clear();

            for (CollectionObject coKid : cn.getCollectionObjectKids()) {
                coKid.setContainerOwner(null);
                colObjsToBeUpdated.add(coKid);
                colObjIdHash.remove(coKid.getId());
            }
            cn.getCollectionObjectKids().clear();
        }
    } else {
        CollectionObject co = (CollectionObject) node.getUserObject();
        co.setContainer(null);
        co.setContainerOwner(null);
        colObjsToBeUpdated.add(co);
        colObjIdHash.remove(co.getId());
    }
    node.setUserObject(null);
    model.removeNodeFromParent(node);
}

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    QueryConceptTreeNodeData data = (QueryConceptTreeNodeData) node.getUserObject();

    // System.out.println("Node will expand: "+data.dimcode());

    if (data.visualAttribute().equals("FA")) {
        data.visualAttribute("FAO");
    } else if (data.visualAttribute().equals("CA")) {
        data.visualAttribute("CAO");
    }/*ww  w.  ja  v  a  2s  .  c  om*/

    // check to see if child is a placeholder ('working...')
    // if so, make Web Service call to update children of node
    if (node.getChildCount() == 1
            && !(node.getChildAt(0).toString().equalsIgnoreCase("Over 300 child nodes"))) {
        DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getChildAt(0);
        if (((QueryConceptTreeNodeData) node1.getUserObject()).visualAttribute().equals("LAO")) {
            populateChildNodes(node);
        }
    } else {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode anode = (DefaultMutableTreeNode) node.getChildAt(0);
            QueryConceptTreeNodeData adata = (QueryConceptTreeNodeData) anode.getUserObject();
            if (adata.visualAttribute().equals("FAO")) {
                adata.visualAttribute("FA");
            } else if (adata.visualAttribute().equals("CAO")) {
                adata.visualAttribute("CA");
            }
        }
    }
}

From source file:edu.harvard.i2b2.query.ui.QueryConceptTreePanel.java

public void treeExpanded(TreeExpansionEvent event) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    QueryConceptTreeNodeData data = (QueryConceptTreeNodeData) node.getUserObject();
    jTree1.scrollPathToVisible(new TreePath(node));

    //System.out.println("Node expanded: "+data.dimcode());   

    if (data.visualAttribute().equals("FA")) {
        data.visualAttribute("FAO");
    } else if (data.visualAttribute().equals("CA")) {
        data.visualAttribute("CAO");
    }/*  w w  w  .j  ava 2  s  .c o m*/

    // check to see if child is a placeholder ('working...')
    //   if so, make Web Service call to update children of node
    if (node.getChildCount() == 1) {
        final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getChildAt(0);
        if (((QueryConceptTreeNodeData) node1.getUserObject()).name().equalsIgnoreCase("working ......")) {
            final DefaultMutableTreeNode anode = node;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    populateChildNodes(anode);
                }
            });
        }
    } else {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode anode = (DefaultMutableTreeNode) node.getChildAt(0);
            QueryConceptTreeNodeData adata = (QueryConceptTreeNodeData) anode.getUserObject();
            if (adata.visualAttribute().equals("FAO")) {
                //adata.visualAttribute("FA");
            } else if (adata.visualAttribute().equals("CAO")) {
                //adata.visualAttribute("CA");   
            }
        }
    }
}

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

public void treeExpanded(TreeExpansionEvent event) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    QueryConceptTreeNodeData data = (QueryConceptTreeNodeData) node.getUserObject();
    jTree1.scrollPathToVisible(new TreePath(node));

    // System.out.println("Node expanded: "+data.dimcode());

    if (data.visualAttribute().equals("FA")) {
        data.visualAttribute("FAO");
    } else if (data.visualAttribute().equals("CA")) {
        data.visualAttribute("CAO");
    }//w  w w  .j a v  a  2 s. co m

    // check to see if child is a placeholder ('working...')
    // if so, make Web Service call to update children of node
    if (node.getChildCount() == 1) {
        final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getChildAt(0);
        if (((QueryConceptTreeNodeData) node1.getUserObject()).name().equalsIgnoreCase("working ......")) {
            final DefaultMutableTreeNode anode = node;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    populateChildNodes(anode);
                }
            });
        }
    } else {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode anode = (DefaultMutableTreeNode) node.getChildAt(0);
            QueryConceptTreeNodeData adata = (QueryConceptTreeNodeData) anode.getUserObject();
            if (adata.visualAttribute().equals("FAO")) {
                // adata.visualAttribute("FA");
            } else if (adata.visualAttribute().equals("CAO")) {
                // adata.visualAttribute("CA");
            }
        }
    }
}

From source file:eu.crisis_economics.abm.dashboard.GASearchHandler.java

private void loadChromosomeTreeLevel(final DefaultMutableTreeNode parent, final List<ParameterInfo> infos,
        final List<Parameter> parameters, final List<SubmodelParameter> submodelParameters,
        final List<eu.crisis_economics.abm.dashboard.generated.Gene> genes) throws ModelInformationException {

    for (final eu.crisis_economics.abm.dashboard.generated.Gene gene : genes) {
        final ParameterInfo info = findParameterInfo(infos, gene.getName());
        if (info == null)
            throw new ModelInformationException("Unrecognized parameter: " + gene.getName() + ".");

        //initializeParent(info,parent);
        final ParameterOrGene userObj = initializeUserObjectFromGene(gene, info);
        final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(userObj);
        getChromosomeTree().insertNodeInto(newNode, parent, parent.getChildCount());

    }/*from  ww  w.  j a  v a2  s  . c  o m*/

    for (final SubmodelParameter parameter : submodelParameters) {
        final ParameterInfo info = findParameterInfo(infos, parameter.getName());
        if (info == null)
            throw new ModelInformationException("Unrecognized parameter: " + parameter.getName() + ".");

        //initializeParent(info,parent);
        final SubmodelInfo submodelInfo = (SubmodelInfo) info;
        final String strType = parameter.getType();
        try {
            final Class<?> clazz = Class.forName(strType, true, currentModelHandler.getCustomClassLoader());
            if (submodelInfo.getActualType() == null
                    || !strType.equals(submodelInfo.getActualType().getName())) {
                submodelInfo.setActualType(clazz, null);
            }

            final ParameterOrGene userObj = new ParameterOrGene(info);
            final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(userObj);
            getChromosomeTree().insertNodeInto(newNode, parent, parent.getChildCount());

            final List<ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?>> batchSubparameters = ParameterTreeUtils
                    .fetchSubparameters(currentModelHandler, submodelInfo);
            final List<ParameterInfo> subparameters = new ArrayList<ParameterInfo>(batchSubparameters.size());
            for (final ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?> parameterInfo : batchSubparameters)
                subparameters.add(InfoConverter.parameterInfo2ParameterInfo(parameterInfo));

            loadChromosomeTreeLevel(newNode, subparameters, parameter.getParameterList(),
                    parameter.getSubmodelParameterList(), parameter.getGeneList());
        } catch (final ClassNotFoundException e) {
            throw new ModelInformationException(
                    "Invalid actual type " + strType + " for submodel parameter: " + submodelInfo.getName(), e);
        }
    }

    for (final Parameter parameter : parameters) {
        final ParameterInfo info = findParameterInfo(infos, parameter.getName());
        if (info == null)
            throw new ModelInformationException("Unrecognized parameter: " + parameter.getName() + ".");

        //initializeParent(info,parent);
        info.setDefinitionType(ParameterInfo.CONST_DEF);
        String parameterValue = ParameterUtil.getParameterValue(parameter);
        Object value;
        if (info.getType().equals("File") && parameterValue == null) {
            value = new File("");
        } else {
            value = ParameterInfo.getValue(parameterValue, info.getJavaType());
        }
        info.setValue(value);

        final ParameterOrGene userObj = new ParameterOrGene(info);
        final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(userObj);
        getChromosomeTree().insertNodeInto(newNode, parent, parent.getChildCount());
    }

}

From source file:GUI.MainWindow.java

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
    System.out.println("file -> Open clicked");

    this.fileChooser.setMultiSelectionEnabled(false);
    int returnVal = this.fileChooser.showOpenDialog(this); // Disable people should only import RC Files here

    if (returnVal == JFileChooser.APPROVE_OPTION) {

        File impFile = this.fileChooser.getSelectedFile();
        // Update the properties files
        this.properties.setProperty("Last_Accessed_Directory", impFile.getParent());
        System.out.println("Last_Accessed_Directory Updated: " + impFile.getParent());
        ImportReportCompiler imprc = new ImportReportCompiler();
        if (imprc.isValid(impFile)) {
            System.out.println("Valid RC XML file: " + impFile.getAbsoluteFile());
            DefaultMutableTreeNode newroot = imprc.readFile(impFile);
            DefaultTreeModel dtm = (DefaultTreeModel) this.VulnTree.getModel();
            DefaultMutableTreeNode currentroot = (DefaultMutableTreeNode) dtm.getRoot();
            if (currentroot.getChildCount() == 0) {
                // No existing nodes so don't merge.
                dtm.setRoot(newroot);/*  www.jav  a 2 s.co m*/
            } else {

            }
        } else {
            JOptionPane.showMessageDialog(null,
                    "The file -> Open menu only accepts ReportCompiler XML files. If you want to import scans try Vulnerabilities -> Import");
        }
    }
    this.fileChooser.setMultiSelectionEnabled(true);

}

From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java

private void loadGene(final NodeList geneList, final List<ParameterInfo> params,
        final DefaultMutableTreeNode root) throws WizardLoadingException {
    if (geneList != null) {
        for (int i = 0; i < geneList.getLength(); ++i) {
            final Element geneElement = (Element) geneList.item(i);
            final String geneName = geneElement.getAttribute(WizardSettingsManager.NAME);

            if (geneName == null || geneName.trim().isEmpty()) {
                throw new WizardLoadingException(true,
                        "missing attribute '" + WizardSettingsManager.NAME + "' at node: " + GENE);
            }/*from ww w  .java  2s.  c  o  m*/

            final ParameterInfo info = findParameterInfo(params, geneName.trim());
            if (info != null) {
                final ParameterOrGene userObj = initializeUserObjectFromGene(geneElement, info);
                final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(userObj);
                getChromosomeTree().insertNodeInto(newNode, root, root.getChildCount());
            } else {
                throw new WizardLoadingException(false, "Unrecognized gene: " + geneName + " (ignored)");
            }
        }
    }
}

From source file:GUI.MainWindow.java

private void ImportScanScreenWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_ImportScanScreenWindowActivated

    Object obj = ImportFile.getModel().getElementAt(0);
    if (obj != null && obj instanceof ImportFile) {
        ImportFile imFile = (ImportFile) obj;
        System.out.println("Importing File: " + imFile.getAbsolutePath());
        ProgressBar.setIndeterminate(true);

        ImportScanTask ist = new ImportScanTask(ProgressBar, imFile, ImportScanScreen);
        ist.addPropertyChangeListener(new PropertyChangeListener() {
            @Override//from   w  w  w  .j a va  2s .  c  o  m
            public void propertyChange(PropertyChangeEvent e) {
                if ("progress".equals(e.getPropertyName())) {
                    ProgressBar.setIndeterminate(false);
                    ProgressBar.setValue((Integer) e.getNewValue());
                    System.out.println("**: " + e.getNewValue());
                }
            }
        });
        ist.execute();

        try {
            DefaultMutableTreeNode new_root = ist.get();
            System.out.println("Import Finished");
            DefaultMutableTreeNode existing_root = (DefaultMutableTreeNode) VulnTree.getModel().getRoot();
            if (existing_root.getChildCount() == 0) {
                // The tree was empty so simply set the importe one into the model
                VulnTree.setModel(new DefaultTreeModel(new_root));
            } else {
                // The tree had existing children so we need to merge them
                VulnTree.setModel(new DefaultTreeModel(new TreeUtils().mergeTrees(existing_root, new_root)));
            }

        } catch (InterruptedException ex) {
            //Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println(ex.getStackTrace());
        } catch (ExecutionException ex) {
            //Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println(ex.getStackTrace());
        }

    }
}

From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java

/**
 * //from  www.j av  a2 s . c  o  m
 */
private void addContainer(final boolean doSearch) {
    if (checkForChanges()) {
        DefaultMutableTreeNode parentNode = getSelectedTreeNode();
        if (parentNode != null) {
            Container parentContainer = (Container) parentNode.getUserObject();
            Container newContainer = doSearch ? (Container) searchForDataObj(Container.class)
                    : createContainer(parentContainer);
            if (newContainer != null) {
                if (doSearch) {
                    // check here to see if they are already parented.
                    newContainer.setParent(parentContainer);
                    parentContainer.getChildren().add(newContainer);
                    saveObjs(newContainer, parentContainer);
                }

                DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();
                newNode.setUserObject(newContainer);
                if (newContainer.getId() != null) {
                    containerIdHash.add(newContainer.getId());
                }

                int inx = parentNode.getChildCount();
                model.insertNodeInto(newNode, parentNode, inx);
                model.nodesWereInserted(parentNode, new int[] { inx });
                model.nodeChanged(parentNode);
                model.reload();
                tree.restoreTree();

                expandToNode(newNode); // invokedLater
            }
        }
    }
}