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:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private JPanel createAParameterBox(final boolean first) {

    final JLabel runLabel = new JLabel("<html><b>Number of runs:</b> 0</html>");
    final JLabel warningLabel = new JLabel();

    final JButton closeButton = new JButton();
    closeButton.setOpaque(false);//from   w w  w  .  ja v  a 2  s. co  m
    closeButton.setBorder(null);
    closeButton.setFocusable(false);

    if (!first) {
        closeButton.setRolloverIcon(PARAMETER_BOX_REMOVE);
        closeButton.setRolloverEnabled(true);
        closeButton.setIcon(RGBGrayFilter.getDisabledIcon(closeButton, PARAMETER_BOX_REMOVE));
        closeButton.setActionCommand(ACTIONCOMMAND_REMOVE_BOX);
    }

    final JScrollPane treeScrPane = new JScrollPane();
    final DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode();
    final JTree tree = new JTree(treeRoot);
    ToolTipManager.sharedInstance().registerComponent(tree);

    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setCellRenderer(new ParameterBoxTreeRenderer());
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(final TreeSelectionEvent e) {
            final TreePath selectionPath = tree.getSelectionPath();
            boolean success = true;
            if (editedNode != null
                    && (selectionPath == null || !editedNode.equals(selectionPath.getLastPathComponent())))
                success = modify();

            if (success) {
                if (selectionPath != null) {
                    cancelAllSelectionBut(tree);
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath
                            .getLastPathComponent();
                    if (!node.equals(editedNode)) {
                        ParameterInATree userObj = null;
                        final DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
                        if (!node.isRoot()
                                && selectionPath.getPathCount() == model.getPathToRoot(node).length) {
                            userObj = (ParameterInATree) node.getUserObject();
                            final ParameterInfo info = userObj.info;
                            editedNode = node;
                            editedTree = tree;
                            edit(info);
                        } else {
                            tree.setSelectionPath(null);
                            if (cancelButton.isEnabled())
                                cancelButton.doClick();
                            resetSettings();
                            enableDisableSettings(false);
                            editedNode = null;
                            editedTree = null;
                        }

                        updateDescriptionField(userObj);
                    } else
                        updateDescriptionField();

                } else
                    updateDescriptionField();

                enableDisableParameterCombinationButtons();
            } else {
                final DefaultTreeModel model = (DefaultTreeModel) editedTree.getModel();
                final DefaultMutableTreeNode storedEditedNode = editedNode;
                editedNode = null;
                tree.setSelectionPath(null);
                editedNode = storedEditedNode;
                editedTree.setSelectionPath(new TreePath(model.getPathToRoot(editedNode)));
            }
        }
    });

    treeScrPane.setViewportView(tree);
    treeScrPane.setBorder(null);
    treeScrPane.setViewportBorder(null);
    treeScrPane.setPreferredSize(new Dimension(450, 250));

    final JButton upButton = new JButton();
    upButton.setOpaque(false);
    upButton.setRolloverEnabled(true);
    upButton.setIcon(PARAMETER_UP_ICON);
    upButton.setRolloverIcon(PARAMETER_UP_ICON_RO);
    upButton.setDisabledIcon(PARAMETER_UP_ICON_DIS);
    upButton.setBorder(null);
    upButton.setToolTipText("Move up the selected parameter");
    upButton.setActionCommand(ACTIONCOMMAND_MOVE_UP);

    final JButton downButton = new JButton();
    downButton.setOpaque(false);
    downButton.setRolloverEnabled(true);
    downButton.setIcon(PARAMETER_DOWN_ICON);
    downButton.setRolloverIcon(PARAMETER_DOWN_ICON_RO);
    downButton.setDisabledIcon(PARAMETER_DOWN_ICON_DIS);
    downButton.setBorder(null);
    downButton.setToolTipText("Move down the selected parameter");
    downButton.setActionCommand(ACTIONCOMMAND_MOVE_DOWN);

    final JPanel mainPanel = FormsUtils.build("~ f:p:g ~ p ~ r:p",
            "012||" + "333||" + "44_||" + "445||" + "446||" + "44_ f:p:g", runLabel, first ? "" : warningLabel,
            first ? warningLabel : closeButton, new FormsUtils.Separator(""), treeScrPane, upButton, downButton)
            .getPanel();

    mainPanel.setBorder(BorderFactory.createTitledBorder(""));

    final JButton addButton = new JButton();
    addButton.setOpaque(false);
    addButton.setRolloverEnabled(true);
    addButton.setIcon(PARAMETER_ADD_ICON);
    addButton.setRolloverIcon(PARAMETER_ADD_ICON_RO);
    addButton.setDisabledIcon(PARAMETER_ADD_ICON_DIS);
    addButton.setBorder(null);
    addButton.setToolTipText("Add selected parameter");
    addButton.setActionCommand(ACTIONCOMMAND_ADD_PARAM);

    final JButton removeButton = new JButton();
    removeButton.setOpaque(false);
    removeButton.setRolloverEnabled(true);
    removeButton.setIcon(PARAMETER_REMOVE_ICON);
    removeButton.setRolloverIcon(PARAMETER_REMOVE_ICON_RO);
    removeButton.setDisabledIcon(PARAMETER_REMOVE_ICON_DIS);
    removeButton.setBorder(null);
    removeButton.setToolTipText("Remove selected parameter");
    removeButton.setActionCommand(ACTIONCOMMAND_REMOVE_PARAM);

    final JPanel result = FormsUtils.build("p ~ f:p:g", "_0 f:p:g||" + "10 p ||" + "20 p||" + "_0 f:p:g",
            mainPanel, addButton, removeButton).getPanel();

    Style.registerCssClasses(result, Dashboard.CSS_CLASS_COMMON_PANEL);

    final ParameterCombinationGUI pcGUI = new ParameterCombinationGUI(tree, treeRoot, runLabel, warningLabel,
            addButton, removeButton, upButton, downButton);
    parameterTreeBranches.add(pcGUI);

    final ActionListener boxActionListener = new ActionListener() {

        //====================================================================================================
        // methods

        //----------------------------------------------------------------------------------------------------
        public void actionPerformed(final ActionEvent e) {
            final String cmd = e.getActionCommand();

            if (ACTIONCOMMAND_ADD_PARAM.equals(cmd))
                handleAddParameter(pcGUI);
            else if (ACTIONCOMMAND_REMOVE_PARAM.equals(cmd))
                handleRemoveParameter(tree);
            else if (ACTIONCOMMAND_REMOVE_BOX.equals(cmd))
                handleRemoveBox(tree);
            else if (ACTIONCOMMAND_MOVE_UP.equals(cmd))
                handleMoveUp();
            else if (ACTIONCOMMAND_MOVE_DOWN.equals(cmd))
                handleMoveDown();
        }

        //----------------------------------------------------------------------------------------------------
        private void handleAddParameter(final ParameterCombinationGUI pcGUI) {
            final Object[] selectedValues = parameterList.getSelectedValues();
            if (selectedValues != null && selectedValues.length > 0) {
                final AvailableParameter[] params = new AvailableParameter[selectedValues.length];
                System.arraycopy(selectedValues, 0, params, 0, selectedValues.length);
                addParameterToTree(params, pcGUI);
                enableDisableParameterCombinationButtons();
            }
        }

        //----------------------------------------------------------------------------------------------------
        private void handleRemoveParameter(final JTree tree) {
            final TreePath selectionPath = tree.getSelectionPath();
            if (selectionPath != null) {
                cancelButton.doClick();

                final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath
                        .getLastPathComponent();
                if (!node.isRoot()) {
                    final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
                    if (parentNode.isRoot()) {
                        removeParameter(tree, node, parentNode);
                        enableDisableParameterCombinationButtons();
                    }
                }
            }
        }

        //----------------------------------------------------------------------------------------------------
        private void handleRemoveBox(final JTree tree) {
            final int answer = Utilities.askUser(dashboard, false, "Comfirmation",
                    "This operation deletes the combination.",
                    "All related parameter returns back to the list on the left side.", "Are you sure?");
            if (answer == 1) {
                final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();

                if (tree.getSelectionCount() > 0) {
                    editedNode = null;
                    tree.setSelectionPath(null);
                    if (cancelButton.isEnabled())
                        cancelButton.doClick();
                }

                final DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();
                for (int i = 0; i < root.getChildCount(); ++i) {
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i);
                    removeParameter(tree, node, root);
                }

                enableDisableParameterCombinationButtons();

                parameterTreeBranches.remove(pcGUI);
                combinationsPanel.remove(result);
                combinationsPanel.revalidate();

                updateNumberOfRuns();
            }
        }

        //----------------------------------------------------------------------------------------------------
        private void removeParameter(final JTree tree, final DefaultMutableTreeNode node,
                final DefaultMutableTreeNode parentNode) {
            final ParameterInATree userObj = (ParameterInATree) node.getUserObject();
            final ParameterInfo originalInfo = findOriginalInfo(userObj.info);
            if (originalInfo != null) {
                final DefaultListModel model = (DefaultListModel) parameterList.getModel();
                model.addElement(new AvailableParameter(originalInfo, currentModelHandler.getModelClass()));
                final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
                treeModel.removeNodeFromParent(node);
                updateNumberOfRuns();
                tree.expandPath(new TreePath(treeModel.getPathToRoot(parentNode)));
            } else
                throw new IllegalStateException(
                        "Parameter " + userObj.info.getName() + " is not found in the model.");
        }

        //----------------------------------------------------------------------------------------------------
        private void handleMoveUp() {
            final TreePath selectionPath = tree.getSelectionPath();
            if (selectionPath != null) {
                boolean success = true;
                if (editedNode != null)
                    success = modify();

                if (success) {
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath
                            .getLastPathComponent();
                    final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();

                    if (parent == null || parent.getFirstChild().equals(node)) {
                        tree.setSelectionPath(null); // we need this to preserve the state of the parameter settings panel
                        tree.setSelectionPath(new TreePath(node.getPath()));
                        return;
                    }

                    final int index = parent.getIndex(node);
                    final DefaultTreeModel treemodel = (DefaultTreeModel) tree.getModel();
                    treemodel.removeNodeFromParent(node);
                    treemodel.insertNodeInto(node, parent, index - 1);
                    tree.setSelectionPath(new TreePath(node.getPath()));
                }

            }
        }

        //----------------------------------------------------------------------------------------------------
        private void handleMoveDown() {
            final TreePath selectionPath = tree.getSelectionPath();
            if (selectionPath != null) {
                boolean success = true;
                if (editedNode != null)
                    success = modify();

                if (success) {
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath
                            .getLastPathComponent();
                    final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();

                    if (parent == null || parent.getLastChild().equals(node)) {
                        tree.setSelectionPath(null); // we need this to preserve the state of the parameter settings panel
                        tree.setSelectionPath(new TreePath(node.getPath()));
                        return;
                    }

                    final int index = parent.getIndex(node);
                    final DefaultTreeModel treemodel = (DefaultTreeModel) tree.getModel();
                    treemodel.removeNodeFromParent(node);
                    treemodel.insertNodeInto(node, parent, index + 1);
                    tree.setSelectionPath(new TreePath(node.getPath()));
                }
            }
        }
    };

    GUIUtils.addActionListener(boxActionListener, closeButton, upButton, downButton, addButton, removeButton);

    result.setPreferredSize(new Dimension(500, 250));
    enableDisableParameterCombinationButtons();

    Style.apply(result, dashboard.getCssStyle());

    return result;
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java

public void treeExpanded(TreeExpansionEvent event) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    QueryData data = (QueryData) node.getUserObject();

    if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryResultData")) {
        QueryResultData rdata = (QueryResultData) node.getUserObject();
        if (rdata.patientCount().equalsIgnoreCase("0")) {
            return;
            /*/*from w w w.  j  a  va2s.c om*/
             * final JPanel parent = this;
             * java.awt.EventQueue.invokeLater(new Runnable() { public void
             * run() { JOptionPane.showMessageDialog(parent, "There's no
             * patient in this set.", "Message",
             * JOptionPane.INFORMATION_MESSAGE); } });
             */

        }
    }

    jTree1.scrollPathToVisible(new TreePath(node));

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

    if (data.visualAttribute().equals("FA")) {
        data.visualAttribute("FAO");
    } else if (data.visualAttribute().equals("CA")) {
        data.visualAttribute("CAO");
    }

    // 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 (((QueryData) node1.getUserObject()).visualAttribute().equals("LAO")
                && ((QueryData) node1.getUserObject()).name().equals("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);
            QueryData adata = (QueryData) 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.patientSet.ui.PatientSetJPanel.java

public DefaultMutableTreeNode addNode(QueryResultData node, DefaultMutableTreeNode parent) {
    // QueryInstanceData rundata = (QueryInstanceData)
    // parent.getUserObject();

    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

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

    treeModel.insertNodeInto(childNode, parent, parent.getChildCount());
    if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA")
            || node.patientCount().equalsIgnoreCase("0"))) {
        treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    }/*from w ww .  j  a va 2  s .co m*/

    DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) parent.getChildAt(0);
    QueryData tmpdata = (QueryData) tmpnode.getUserObject();
    if (tmpdata.name().equalsIgnoreCase("working ......")) {
        treeModel.removeNodeFromParent(tmpnode);
    }

    return childNode;
}

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

public DefaultMutableTreeNode addNode(PatientData node, DefaultMutableTreeNode parent) {
    // QueryInstanceData rundata = (QueryInstanceData)
    // parent.getUserObject();

    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

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

    treeModel.insertNodeInto(childNode, parent, parent.getChildCount());
    // if(!(node.visualAttribute().startsWith("L") ||
    // node.visualAttribute().equalsIgnoreCase("MA"))) {
    // treeModel.insertNodeInto(tmpNode, childNode,
    // childNode.getChildCount());
    // }//from   www  .  ja va 2 s.co m
    // Make sure the user can see the lovely new node.

    DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) parent.getChildAt(0);
    QueryData tmpdata = (QueryData) tmpnode.getUserObject();
    if (tmpdata.name().equalsIgnoreCase("working ......")) {
        treeModel.removeNodeFromParent(tmpnode);
    }

    return childNode;
}

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

public DefaultMutableTreeNode addNode(QueryInstanceData node, DefaultMutableTreeNode parent) {
    QueryMasterData logicdata = (QueryMasterData) parent.getUserObject();
    logicdata.runs.add(node);//from www  .java2s . c om

    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

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

    treeModel.insertNodeInto(childNode, parent, parent.getChildCount());
    if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) {
        treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    }
    // Make sure the user can see the lovely new node.

    DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) parent.getChildAt(0);
    QueryData tmpdata = (QueryData) tmpnode.getUserObject();
    if (tmpdata.name().equalsIgnoreCase("working ......")) {
        treeModel.removeNodeFromParent(tmpnode);
    }

    return childNode;
}

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

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

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

    treeModel.insertNodeInto(childNode, top, top.getChildCount());
    if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) {
        treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    }//  ww  w .ja v a 2s  .c o  m

    jTree1.expandPath(new TreePath(top.getPath()));

    return childNode;
}

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

private void addParameterToTree(final AvailableParameter[] parameters, final ParameterCombinationGUI pcGUI) {
    final DefaultListModel listModel = (DefaultListModel) parameterList.getModel();
    final DefaultTreeModel treeModel = (DefaultTreeModel) pcGUI.tree.getModel();
    final DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();

    for (final AvailableParameter parameter : parameters) {
        listModel.removeElement(parameter);
        final ParameterInfo selectedInfo = parameter.info;
        final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(
                new ParameterInATree(selectedInfo, currentModelHandler.getModelClass()));
        treeModel.insertNodeInto(newNode, root, root.getChildCount());

        if (selectedInfo instanceof SubmodelInfo) {
            final SubmodelInfo sInfo = (SubmodelInfo) selectedInfo;
            if (sInfo.getActualType() != null) {
                addSubParametersToTree(sInfo, pcGUI.tree, newNode);
                pcGUI.tree.expandPath(new TreePath(treeModel.getPathToRoot(newNode)));
            }/*from   ww w . jav  a2  s . c  o m*/
        }
    }

    updateNumberOfRuns();
    pcGUI.tree.expandPath(new TreePath(treeModel.getPathToRoot(root)));
}

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

public DefaultMutableTreeNode insertNode(QueryMasterData node) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

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

    if (ascending) {
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
    } else {//ww w  .  j ava2  s.  c o  m
        treeModel.insertNodeInto(childNode, top, 0);
    }

    if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) {
        treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    }

    jTree1.expandPath(new TreePath(top.getPath()));
    previousQueries.add(node);

    return childNode;
}

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

private void setDocNodesOnTree(DefaultMutableTreeNode top, List<DocNodeBase> docNodes, DocPath docPath)
        throws ExceptionLP, RepositoryException, Throwable {
    treeModel.reload(top);// w w w .  ja  v a 2s.c  o m
    DefaultMutableTreeNode treeNode = null;
    if (docNodes != null) {
        for (DocNodeBase docNode : docNodes) {
            treeNode = new DefaultMutableTreeNode(docNode);
            boolean bDarfDocSehen = true;
            JCRDocDto jcrDocDto = null;
            if (docNode.getNodeType() == DocNodeBase.FILE)
                jcrDocDto = ((DocNodeFile) docNode).getJcrDocDto();
            if (jcrDocDto != null) {
                int iSicherheitsstufe = (int) jcrDocDto.getlSicherheitsstufe();
                bDarfDocSehen = false;
                switch (iSicherheitsstufe) {
                case (int) JCRDocFac.SECURITY_NONE:
                    if (bHatStufe0) {
                        bDarfDocSehen = true;
                    }
                    break;
                case (int) JCRDocFac.SECURITY_LOW:
                    if (bHatStufe1) {
                        bDarfDocSehen = true;
                    }
                    break;
                case (int) JCRDocFac.SECURITY_MEDIUM:
                    if (bHatStufe2) {
                        bDarfDocSehen = true;
                    }
                    break;
                case (int) JCRDocFac.SECURITY_HIGH:
                    if (bHatStufe3) {
                        bDarfDocSehen = true;
                    }
                    break;
                case (int) JCRDocFac.SECURITY_ARCHIV:
                    if (bHatStufe99) {
                        bDarfDocSehen = true;
                    }
                    break;
                }
            }

            if (bDarfDocSehen) {
                if (jcrDocDto != null) {
                    ArrayList<DocNodeVersion> versions = DelegateFactory.getInstance().getJCRDocDelegate()
                            .getAllDocumentVersions(jcrDocDto);
                    if (versions.size() > 0) {
                        boolean alleVersteckt = true;
                        for (DocNodeVersion version : versions) {
                            if (!version.getJCRDocDto().getbVersteckt()) {
                                alleVersteckt = false;
                                break;
                            }
                        }
                        if (bVersteckteAnzeigen || !alleVersteckt) {
                            treeModel.insertNodeInto(treeNode, top, top.getChildCount());
                        }
                        for (DocNodeVersion version : versions) {
                            if (bVersteckteAnzeigen || !version.getJCRDocDto().getbVersteckt()) {
                                treeModel.insertNodeInto(new DefaultMutableTreeNode(version), treeNode,
                                        treeNode.getChildCount());
                            }
                        }
                    } else if (bVersteckteAnzeigen || !jcrDocDto.getbVersteckt()) {
                        treeModel.insertNodeInto(treeNode, top, top.getChildCount());
                    }
                }
                if (jcrDocDto == null) {
                    if (docNode.getNodeType() == DocNodeBase.SYMBOLIC_LINK) {
                        DocPath path = ((DocNodeSymbolicLink) docNode).getViewPath().getDeepCopy();
                        path.asDocNodeList().remove(path.getLastDocNode());
                        path.add(docNode);
                        addNotExistingNodes(path, top);
                    } else {
                        treeModel.insertNodeInto(treeNode, top, top.getChildCount());
                        treeModel.insertNodeInto(new DefaultMutableTreeNode(MUST_LOAD_CHILDREN), treeNode, 0);
                    }
                }
            }
        }
    }
}

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

private void addSubParametersToTree(final SubmodelInfo sInfo, final JTree tree,
        final DefaultMutableTreeNode node) {
    try {//from www  .  j av  a 2  s .  c o  m
        final List<ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?>> subparameters = ParameterTreeUtils
                .fetchSubparameters(currentModelHandler, sInfo);

        final List<ParameterInfo> convertedSubparameters = new ArrayList<ParameterInfo>(subparameters.size());
        for (ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?> parameterInfo : subparameters) {
            final ParameterInfo converted = InfoConverter.parameterInfo2ParameterInfo(parameterInfo);
            converted.setRuns(0);
            convertedSubparameters.add(converted);
        }
        Collections.sort(convertedSubparameters);

        final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();

        if (node.getChildCount() > 0) {
            node.removeAllChildren();
            treeModel.nodeStructureChanged(node);
        }

        for (final ParameterInfo pInfo : convertedSubparameters) {
            final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(
                    new ParameterInATree(pInfo, currentModelHandler.getModelClass()));
            treeModel.insertNodeInto(newNode, node, node.getChildCount());

            if (pInfo instanceof SubmodelInfo) {
                final SubmodelInfo ssInfo = (SubmodelInfo) pInfo;
                if (ssInfo.getActualType() != null)
                    addSubParametersToTree(ssInfo, tree, newNode);
            }
        }

        //tree.expandPath(new TreePath(treeModel.getPathToRoot(node)));
    } catch (final ModelInformationException e) {
        sInfo.setActualType(null, null);
        JOptionPane.showMessageDialog(wizard, new JLabel(e.getMessage()), "Error while analyizing model",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
        submodelTypeBox.setSelectedIndex(0);
    }
}