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:org.olivier.ihm.FramePUMLCleanerControler.java

/**
 * Slectionne les noeuds dans l'arbre de filtrage corespondant au motif
 * @param motif Le motif pour slectionner les noeuds
 * @param jTreeFiltre L'arbre de filtrage
 *///from w  w  w  .  java2  s.  c  o  m
public void selectionnerNoeud(String motif, JTree jTreeFiltre) {
    // TODO :  finir

    TreePath[] allPath = Util.getPaths(jTreeFiltre, true);
    // parcours des categories
    for (TreePath path : allPath) {
        // recup de la racine
        final DefaultMutableTreeNode root = (DefaultMutableTreeNode) path.getLastPathComponent();

        // parcours des catgories
        for (int j = 0; j < root.getChildCount(); j++) {
            final TreeNode categ = root.getChildAt(j);

            // parcours des noeuds
            for (j = 0; j < categ.getChildCount(); j++) {
                final TreeNode unNoeudSelectionner = categ.getChildAt(j);
                if (!unNoeudSelectionner.toString().contains(motif)) {

                }
            }
        }
    }
    checkTreeManager.getSelectionModel().setSelectionPaths(allPath);
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorUtilities.java

/**
 * Sorts all Nodes and children of these Nodes by the name of their OIDObjects
 * //from   w w  w.  ja  v  a  2s .  co  m
 * @param root
 */
public void sortTree(DefaultMutableTreeNode root) {

    Vector<DefaultMutableTreeNode> childrenV = new Vector<DefaultMutableTreeNode>();

    if (root.getChildCount() > 1) {

        for (int i = 0; i < root.getChildCount(); i++) {

            childrenV.add((DefaultMutableTreeNode) root.getChildAt(i));

        }

        root.removeAllChildren();

        boolean swapped = true;

        while (swapped) {
            swapped = false;

            for (int i = 0; i < childrenV.size() - 1; i++) {

                if (childrenV.elementAt(i).getChildCount() > 0) {
                    sortTree(childrenV.elementAt(i));
                }

                OIDObject oo1 = (OIDObject) childrenV.elementAt(i).getUserObject();
                OIDObject oo2 = (OIDObject) childrenV.elementAt(i + 1).getUserObject();

                DefaultMutableTreeNode node1 = childrenV.elementAt(i);
                DefaultMutableTreeNode node2 = childrenV.elementAt(i + 1);

                if (oo1.getName().compareTo(oo2.getName()) > 0) {

                    childrenV.setElementAt(node2, i);
                    childrenV.setElementAt(node1, i + 1);

                    swapped = true;
                }
            }
        }
        for (int i = 0; i < childrenV.size(); i++) {

            root.add(childrenV.elementAt(i));

        }
    }
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorUtilities.java

/**
 * Constructs a Vector from the given Node and it's sub-Nodes
 * /*  www .  j  av  a  2  s  . co m*/
 * @param node
 * @return
 */
public Vector<JSONObject> traverseTreeForExpand(DefaultMutableTreeNode node) {

    try {

        Vector<JSONObject> vjbo = new Vector<JSONObject>();

        for (Enumeration e = node.children(); e.hasMoreElements();) {

            DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement();
            JSONObject jso = new JSONObject();
            jso.put("name", ((OIDObject) n.getUserObject()).getName());
            jso.put("identifier", ((OIDObject) n.getUserObject()).getIdentifier());
            jso.put("hasChildren", !n.isLeaf());
            jso.put("isActive", ((OIDObject) n.getUserObject()).isActive());

            if (n.getChildCount() != 0) {
                Vector<JSONObject> retvjo = traverseTreeForExpand(n);
                jso.put("children", retvjo);
            }
            vjbo.add(jso);
        }
        return vjbo;

    } catch (Exception e) {
        Logger.getLogger(this.getClass()).error(e);
    }
    return null;

}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorUtilities.java

/**
 * Searches for the given oid in the given node and it's children.
 * If the node is found, it is returned.
 * /*from  ww  w.j ava2  s . c o  m*/
 * @param oid
 * @param node
 * @return
 */
@SuppressWarnings("rawtypes")
public DefaultMutableTreeNode traverseTreeString(String query, DefaultMutableTreeNode searchNode,
        DefaultMutableTreeNode realNode) {
    DefaultMutableTreeNode ret = null;

    Enumeration e = realNode.children();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement();
        if (((OIDObject) n.getUserObject()).getName().toLowerCase().contains(query)) {
            ret = n;
            TreeNode[] path = n.getPath();
            addNodeToModel(path, searchNode, 1);

        }
        if (n.getChildCount() != 0) {
            traverseTreeString(query, searchNode, n);
        }
    }
    return ret;
}

From source file:org.openengsb.ui.admin.testClient.TestClient.java

private DefaultMutableTreeNode findService(DefaultMutableTreeNode node, ServiceId jumpToService) {
    if (node.isLeaf()) {
        Object userObject = node.getUserObject();
        if (jumpToService.equals(userObject)) {
            return node;
        }//from   ww w. j av a 2  s.c  o  m
    } else {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode result = findService((DefaultMutableTreeNode) node.getChildAt(i),
                    jumpToService);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}

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

/**
 * Adds a dummy node to the specified node.
 * /*from   ww w .j a v a2s  . c  om*/
 * @param node The parent node.
 */
private void buildEmptyNode(DefaultMutableTreeNode node) {
    DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel();
    tm.insertNodeInto(new DefaultMutableTreeNode(Browser.EMPTY_MSG), node, node.getChildCount());
}

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

/** 
 * Collapses the node when an on-going data loading is cancelled.
 * //  ww  w . jav a  2  s. c om
 * @param node The node to collapse.
 */
void cancel(DefaultMutableTreeNode node) {
    if (node == null)
        return;
    if (node.getChildCount() <= 1) {
        if (node.getUserObject() instanceof String) {
            node.removeAllChildren();
            buildEmptyNode(node);
        }
    }
    //in this order otherwise the node is not collapsed.
    ((DefaultTreeModel) treeDisplay.getModel()).reload(node);
    collapsePath(node);
}

From source file:org.parosproxy.paros.extension.scanner.ExtensionScanner.java

public void sessionChanged(Session session) {
    AlertTreeModel tree = (AlertTreeModel) getAlertPanel().getTreeAlert().getModel();

    DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getRoot();

    while (root.getChildCount() > 0) {
        tree.removeNodeFromParent((MutableTreeNode) root.getChildAt(0));
    }//from   w  ww. j  av a  2 s . c  o m

    try {
        refreshAlert(session);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:ropes.MainWindow.java

private void jButton_writeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_writeActionPerformed

    String storeSpace_option = null;
    File encrypted_file = null;//w  ww.j a v a  2  s  .c o  m
    List<File> files = new ArrayList<File>();

    if (!validateFileds()) {
        JOptionPane.showMessageDialog(this, "Some fileds are invalid", "Error", JOptionPane.WARNING_MESSAGE);
        return;
    }

    if (jRadioButton_allSpace.isSelected()) {
        storeSpace_option = "all avalible space";
    } else {
        storeSpace_option = String.valueOf(jSlider_size_select.getValue()) + " Mb of space";
    }

    int dialogResult = JOptionPane
            .showConfirmDialog(null,
                    "Are you sure you want to fill\n" + storeSpace_option + " at the media you selected:\n"
                            + jComboBox_media.getSelectedItem().toString(),
                    "Warning", JOptionPane.YES_NO_OPTION);
    if (dialogResult == JOptionPane.YES_OPTION) {
        //get all added files and perent directories 
        DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) jTree_fileList.getModel().getRoot();
        int chiledCount = rootNode.getChildCount();
        for (int i = 0; i < chiledCount; i++) {
            String path = jTree_fileList.getModel().getChild(rootNode, i).toString();
            files.add(new File(path));
            System.out.println(path);
        }
        if (validateFileds()) {
            encrypted_file = compressAndEncrypt(String.valueOf(jPasswordField_master_password.getPassword()),
                    files);
        } else {
            System.err.println("some fields are invalid");
            return;
        }

        Double size_select_bytes = jSlider_size_select.getValue() * Math.pow(1024, 2);
        Long size_select = size_select_bytes.longValue();
        if (encrypted_file.exists()) {
            Long fileSize = encrypted_file.length();
            if (jRadioButton_allSpace.isSelected()) {
                size_select_bytes = jSlider_size_select.getMaximum() * Math.pow(1024, 2);
                createIso(encrypted_file, size_select_bytes.longValue(), initIv, salt);
            } else if (size_select > 0 && size_select > fileSize)
                createIso(encrypted_file, size_select, initIv, salt);
        }

    }

}

From source file:seleniumAutomation.flowControls.java

public static void parseNodes(javax.swing.tree.DefaultMutableTreeNode nodes) {
    for (int i = 0; i < nodes.getChildCount(); i++) {
        parseNodes((javax.swing.tree.DefaultMutableTreeNode) nodes.getChildAt(i));
    }//  w ww.j a  v a2  s .  c  om
    if (nodes.getChildCount() == 0) {
        if (!testStep.isEmpty()) {
            if (!((javax.swing.tree.DefaultMutableTreeNode) nodes.getParent()).getLastChild().equals(nodes)) {
                testStep.add(nodes.getUserObject().toString());
            } else {
                testStep.add(nodes.getUserObject().toString());
                testSuite.put(testStep.get(0), testStep);
                testStep = new ArrayList<String>();
            }
        } else {
            testStep = new ArrayList();
            testStep.add(nodes.getUserObject().toString());
            testSuite.put(testStep.get(0), testStep);
        }
    }
}