Example usage for javax.swing.tree TreePath TreePath

List of usage examples for javax.swing.tree TreePath TreePath

Introduction

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

Prototype

public TreePath(Object lastPathComponent) 

Source Link

Document

Creates a TreePath containing a single element.

Usage

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

/**
 * This method is called from within the constructor to initialize the form.
 *///w w  w.  j a  v  a 2s. com
private void initComponents() {

    System.setProperty("PQSortByTimeCheckBox", "true");
    System.setProperty("QueryToolMaxQueryNumber", "20");
    System.setProperty("PQMaxPatientsNumber", "200");
    System.setProperty("PQSortByNameCheckBox", "false");

    jScrollPane1 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();

    setLayout(new java.awt.BorderLayout());

    QueryMasterData tmpData = new QueryMasterData();
    tmpData.name("Queries by " + UserInfoBean.getInstance().getUserName());
    tmpData.tooltip("Previous query runs");
    tmpData.visualAttribute("CA");
    top = new DefaultMutableTreeNode(tmpData);
    // top = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(top);
    // treeModel.addTreeModelListener(new MyTreeModelListener());

    jTree1 = new JTree(treeModel);
    jTree1.setEditable(false);

    // jTree1.getSelectionModel().setSelectionMode
    // (TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setShowsRootHandles(true);
    // JScrollPane treeView = new JScrollPane(jTree1);
    jTree1.setRootVisible(false);
    jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setCellRenderer(new MyRenderer());
    ToolTipManager.sharedInstance().registerComponent(jTree1);

    if (cellStatus.equalsIgnoreCase("CellDown")) {
        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode("Data Repository Cell is unavailable");
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
        // Make sure the user can see the lovely new node.
        jTree1.expandPath(new TreePath(top.getPath()));
    }

    ArrayList<QueryMasterData> queries = previousQueries;
    if (queries != null) {
        for (int i = 0; i < queries.size(); i++) {
            addNode(queries.get(i));
        }
    }

    jScrollPane1.setViewportView(jTree1);
    add(jScrollPane1, java.awt.BorderLayout.CENTER);

    jTree1.setTransferHandler(new NodeCopyTransferHandler());
    jTree1.addTreeExpansionListener(this);
    jTree1.addTreeWillExpandListener(this);
}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java

private TreePath selectPathFromNodeId(TreeTableNode selectedNode, CodeTemplateRootTreeTableNode root) {
    TreePath selectedPath = null;
    if (selectedNode != null) {
        CodeTemplateTreeTableModel model = (CodeTemplateTreeTableModel) templateTreeTable.getTreeTableModel();

        for (Enumeration<? extends MutableTreeTableNode> libraries = root.children(); libraries
                .hasMoreElements();) {//from  ww  w .  j  a  v  a  2  s  .c  om
            CodeTemplateLibraryTreeTableNode libraryNode = (CodeTemplateLibraryTreeTableNode) libraries
                    .nextElement();

            if (selectedNode instanceof CodeTemplateLibraryTreeTableNode
                    && ((CodeTemplateLibraryTreeTableNode) selectedNode).getLibraryId()
                            .equals(libraryNode.getLibraryId())) {
                selectedPath = new TreePath(model.getPathToRoot(libraryNode));
                break;
            }

            for (Enumeration<? extends MutableTreeTableNode> codeTemplates = libraryNode
                    .children(); codeTemplates.hasMoreElements();) {
                CodeTemplateTreeTableNode codeTemplateNode = (CodeTemplateTreeTableNode) codeTemplates
                        .nextElement();

                if (selectedNode instanceof CodeTemplateTreeTableNode
                        && ((CodeTemplateTreeTableNode) selectedNode).getCodeTemplateId()
                                .equals(codeTemplateNode.getCodeTemplateId())) {
                    selectedPath = new TreePath(model.getPathToRoot(codeTemplateNode));
                    break;
                }
            }

            if (selectedPath != null) {
                break;
            }
        }

        if (selectedPath != null) {
            selectTemplatePath(selectedPath);
        }
    }

    return selectedPath;
}

From source file:gdt.jgui.entity.index.JIndexPanel.java

private void select(String selectedNodeKey$) {

    try {/*  w  w w. j  a  v  a  2  s .  c  o m*/

        DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
        Enumeration en = root.preorderEnumeration();
        DefaultMutableTreeNode node;
        // System.out.println("EntityDigestDisplay:select:selection node="+selectedNodeKey$);
        String nodeLocator$;
        Properties locator;
        while (en.hasMoreElements()) {
            node = (DefaultMutableTreeNode) en.nextElement();
            nodeLocator$ = (String) node.getUserObject();
            locator = Locator.toProperties(nodeLocator$);
            //System.out.println("EntityDigestDisplay:select:node number="+nodeNumber$);
            if (selectedNodeKey$.equals(locator.getProperty(NODE_KEY))) {
                TreeNode[] nodes = ((DefaultTreeModel) tree.getModel()).getPathToRoot(node);
                TreePath tpath = new TreePath(nodes);
                tree.scrollPathToVisible(tpath);
                tree.setSelectionPath(tpath);
                break;
            }
        }
    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
    }

}

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

private void populateChildNodes(DefaultMutableTreeNode node) {
    QueryConceptTreeNodeData data = (QueryConceptTreeNodeData) node.getUserObject();
    try {/*from   w  ww  . j av  a2s  . co  m*/
        GetChildrenType parentType = new GetChildrenType();

        parentType.setMax(null);//Integer.parseInt(System.getProperty("OntMax")));
        parentType.setHiddens(Boolean.parseBoolean(System.getProperty("OntHiddens")));
        parentType.setSynonyms(Boolean.parseBoolean(System.getProperty("OntSynonyms")));

        //   log.info("sent : " + parentType.getMax() + System.getProperty("OntMax") + System.getProperty("OntHiddens")
        //      + System.getProperty("OntSynonyms") );

        parentType.setMax(parentPanel.max_child());
        //System.out.println("Max children set to: "+parentPanel.max_child());

        parentType.setBlob(true);
        //   parentType.setType("all");

        parentType.setParent(data.fullname());
        //System.out.println(parentType.getParent());

        //Long time = System.currentTimeMillis();
        //log.info("making web service call " + time);
        GetChildrenResponseMessage msg = new GetChildrenResponseMessage();
        StatusType procStatus = null;
        //while(procStatus == null || !procStatus.getType().equals("DONE")){
        String response = OntServiceDriver.getChildren(parentType, "");
        //System.out.println("Ontology service getchildren response: "+response);
        parentPanel.parentPanel.lastResponseMessage(response);
        //         Long time2 = System.currentTimeMillis();
        //         log.info("returned from 1st web service call " + (time2 - time));         
        procStatus = msg.processResult(response);
        //         log.info(procStatus.getType());
        //         log.info(procStatus.getValue());
        int result;
        if (procStatus.getValue().equals("MAX_EXCEEDED")) {
            result = JOptionPane.showConfirmDialog(parentPanel,
                    "The node has exceeded maximum number of children.\n" + "Do you want to continue?",
                    "Please note ...", JOptionPane.YES_NO_OPTION);

            if (result == JOptionPane.NO_OPTION) {
                DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) node.getChildAt(0);
                QueryConceptTreeNodeData tmpdata = (QueryConceptTreeNodeData) tmpnode.getUserObject();
                tmpdata.name("Over maximum number of child nodes");
                //procStatus.setType("DONE");
                jTree1.repaint();
                jTree1.scrollPathToVisible(new TreePath(tmpnode.getPath()));
                return;
            } else {
                parentType.setMax(null);
                response = OntServiceDriver.getChildren(parentType, "");
                procStatus = msg.processResult(response);
            }
        }

        if (!procStatus.getType().equals("DONE")) {
            JOptionPane.showMessageDialog(parentPanel, "Error message delivered from the remote server, "
                    + "you may wish to retry your last action");
            return;
        }

        ConceptsType allConcepts = msg.doReadConcepts();
        List concepts = allConcepts.getConcept();
        if (concepts != null) {
            addNodesFromOntXML(concepts, node);
            DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) node.getChildAt(0);
            treeModel.removeNodeFromParent(tmpnode);
            jTree1.scrollPathToVisible(new TreePath(node.getPath()));
        }

    } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(parentPanel,
                "Response delivered from the remote server could not be understood,\n"
                        + "you may wish to retry your last action.");
        return;
    }
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java

/**
 * @param selectedControl//from w w w  . j  a  v  a  2 s .c o  m
 * @param selectedCell
 */
protected void addControl(final ControlIFace selectedControl,
        @SuppressWarnings("hiding") final FormCell selectedCell) {
    int position = 0;
    if (selectedCell != null) {
        position = selectedRow.getCells().indexOf(selectedCell);
    }

    if (selectedControl instanceof RowControl) {
        addRow();
        return;
    }

    @SuppressWarnings("hiding")
    EditorPropPanel panel = new EditorPropPanel(controlHash, subcontrolHash, getAvailableFieldCells(), false,
            this);
    //panel.setFormViewDef(formViewDef);

    FormCell formCell = null;
    boolean skip = false;
    if (selectedControl instanceof Control) {
        Control control = (Control) selectedControl;

        if (control.getType().equals("label")) //$NON-NLS-1$
        {
            formCell = new FormCellLabel();
            formCell.setIdent(Integer.toString(getNextId()));
        }

        if (formCell != null) {
            formCell.setType(FormCellIFace.CellType.valueOf(control.getType()));

            //System.out.println(formCell.getType() + "  "+ formCell.getClass().getSimpleName());

            panel.loadView(formCell.getType().toString(), selectedViewDef.getClassName());
            panel.setDataIntoUI(formViewDef, formCell, (formViewDef.getRows().size() * 2) - 1,
                    formViewDef.getRowDefItem().getNumItems(), selectedRow.getRowNumber(),
                    (selectedRow.getCells().size() * 2) - 1, formViewDef.getColumnDefItem().getNumItems(),
                    position);
        }

    } else {
        SubControl subControl = (SubControl) selectedControl;

        FormCellField fcf = null;
        if (subControl.getType().equals("combobox")) //$NON-NLS-1$
        {
            fcf = new FormCellField(FormCell.CellType.field, Integer.toString(getNextId()), "", 1, 1); //$NON-NLS-1$
            fcf.setUiType(FormCellFieldIFace.FieldType.combobox);
            setDefaultDspUIType(fcf);
            formCell = fcf;
        }
        //System.out.println("* ["+fcf.getUiType().toString() + "]  "+ fcf.getClass().getSimpleName());
        //SubControl subcontrol = subcontrolHash.get(fcf.getUiType().toString());
        //System.out.println("SC: "+subcontrol);

        panel.loadView(fcf.getUiType().toString(), selectedViewDef.getClassName());
        panel.setDataIntoUI(formViewDef, fcf, (formViewDef.getRows().size() * 2) - 1,
                formViewDef.getRowDefItem().getNumItems(), selectedRow.getRowNumber(),
                (selectedRow.getCells().size() * 2) - 1, formViewDef.getColumnDefItem().getNumItems(),
                position);

    }

    if (!skip && formCell != null) {
        CustomDialog propDlg = new CustomDialog((Frame) UIRegistry.getTopWindow(),
                getResourceString("ViewSetSelectorPanel.CREATE"), true, panel); //$NON-NLS-1$
        propDlg.createUI();
        //panel.getViewDefMultiView().getCurrentView().getValidator().addEnableItem(propDlg.getOkBtn());
        propDlg.pack();
        Rectangle r = propDlg.getBounds();
        r.width += 60;
        r.height += 30;
        propDlg.setBounds(r);
        propDlg.setVisible(true);

        if (!propDlg.isCancelled()) {
            if (selectedControl instanceof Control) {
                panel.getDataFromUI(formCell);
            } else {
                panel.getDataFromUI((FormCellField) formCell);
            }

            DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(formCell);
            newNode.setUserObject(formCell);

            DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) tree.getSelectionModel()
                    .getSelectionPath().getLastPathComponent();
            if (!(parentNode.getUserObject() instanceof FormRow)) {
                parentNode = (DefaultMutableTreeNode) parentNode.getParent();
            }

            TreePath treePath = tree.getSelectionModel().getSelectionPath();
            Object[] path = treePath.getPath();

            Object[] newPath = new Object[path.length + (selectedCell == null ? 1 : 0)];
            for (int i = 0; i < path.length; i++) {
                newPath[i] = path[i];
            }
            newPath[newPath.length - 1] = newNode;

            if (selectedRow.getCells().size() == 0) {
                selectedRow.getCells().add(formCell);
                ((DefaultTreeModel) tree.getModel()).insertNodeInto(newNode, parentNode, 0);

            } else if (position == selectedRow.getCells().size() - 1) {
                //System.out.println("Adding New Cell at position["+(position+1)+"] number of nodes["+nodeParent.getChildCount()+"] rowCells "+selectedRow.getCells().size());
                selectedRow.getCells().add(formCell);
                ((DefaultTreeModel) tree.getModel()).insertNodeInto(newNode, parentNode, position + 1);

            } else {
                //System.out.println("Adding New Cell at position["+position+"] number of nodes["+nodeParent.getChildCount()+"] rowCells "+selectedRow.getCells().size());
                selectedRow.getCells().insertElementAt(formCell, position + 1);
                ((DefaultTreeModel) tree.getModel()).insertNodeInto(newNode, parentNode, position + 1);
            }

            //System.out.println("******* ADDING ["+formCell.getIdent()+"]"); //$NON-NLS-1$ //$NON-NLS-2$

            idHash.put(formCell.getIdent(), true);

            final TreePath newTreePath = new TreePath(newPath);
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    tree.setSelectionPath(newTreePath);
                }
            });

            previewPanel.rebuild(false);
        }
    }

}

From source file:de.erdesignerng.visual.common.OutlineComponent.java

/**
 * Create the PopupMenu actions correlating to a specific tree node.
 *
 * @param aNode     - the node/*  w  w  w.  j a  v a 2s.co m*/
 * @param aMenu     - the menu to add the actions to
 * @param aRecursive - recursive
 */
private void initializeActionsFor(final DefaultMutableTreeNode aNode, JPopupMenu aMenu, boolean aRecursive) {

    Object theUserObject = aNode.getUserObject();

    if (!aRecursive) {
        JMenuItem theExpandAllItem = new JMenuItem();
        theExpandAllItem.setText(getResourceHelper().getFormattedText(ERDesignerBundle.EXPANDALL));
        theExpandAllItem
                .addActionListener(e -> expandOrCollapseAllChildrenOfNode(new TreePath(aNode.getPath()), true));
        aMenu.add(theExpandAllItem);

        JMenuItem theCollapseAllItem = new JMenuItem();
        theCollapseAllItem.setText(getResourceHelper().getFormattedText(ERDesignerBundle.COLLAPSEALL));
        theCollapseAllItem.addActionListener(
                e -> expandOrCollapseAllChildrenOfNode(new TreePath(aNode.getPath()), false));

        aMenu.add(theCollapseAllItem);
        aMenu.addSeparator();
    }

    List<ModelItem> theItemList = new ArrayList<>();
    if (theUserObject instanceof ModelItem) {
        theItemList.add((ModelItem) theUserObject);
        ContextMenuFactory.addActionsToMenu(ERDesignerComponent.getDefault().getEditor(), aMenu, theItemList);
    }

    if (aNode.getParent() != null) {
        initializeActionsFor((DefaultMutableTreeNode) aNode.getParent(), aMenu, true);
    }
}

From source file:de.erdesignerng.visual.common.OutlineComponent.java

/**
 * Set the currently selected item./*from  w  w  w  .ja  v a  2  s . c  o  m*/
 *
 * @param aSelection the selection
 */
public void setSelectedItem(ModelItem aSelection) {

    TreePath theSelected = tree.getSelectionPath();
    if (theSelected != null) {
        DefaultMutableTreeNode theNode = (DefaultMutableTreeNode) theSelected.getLastPathComponent();
        if (theNode.getUserObject().equals(aSelection)) {
            // The object is already selected, so keep the selection
            return;
        }
    }

    DefaultMutableTreeNode theNode = userObjectMap.get(aSelection);
    if (theNode != null) {
        TreePath thePath = new TreePath(theNode.getPath());
        tree.setSelectionPath(thePath);
        tree.scrollPathToVisible(thePath);
    } else {
        tree.clearSelection();
    }

    tree.invalidate();
    tree.repaint();
}

From source file:net.sf.jabref.groups.GroupSelector.java

/**
 * Revalidate the groups tree (e.g. after the data stored in the model has been changed) and set the specified
 * selection and expansion state./* www. j a va  2 s.com*/
 *
 * @param node If this is non-null, the view is scrolled to make it visible.
 */
private void revalidateGroups(TreePath[] selectionPaths, Enumeration<TreePath> expandedNodes,
        GroupTreeNode node) {
    groupsTreeModel.reload();
    groupsTree.clearSelection();
    if (selectionPaths != null) {
        groupsTree.setSelectionPaths(selectionPaths);
    }
    // tree is completely collapsed here
    if (expandedNodes != null) {
        while (expandedNodes.hasMoreElements()) {
            groupsTree.expandPath(expandedNodes.nextElement());
        }
    }
    groupsTree.revalidate();
    if (node != null) {
        groupsTree.scrollPathToVisible(new TreePath(node.getPath()));
    }
}

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

/**
 * This method is called from within the constructor to initialize the form.
 *//*  w ww .j  a  v a2s .  c  o  m*/
private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;
    System.setProperty("PQSortByTimeCheckBox", "true");
    System.setProperty("QueryToolMaxQueryNumber", "20");
    System.setProperty("PQMaxPatientsNumber", "200");
    System.setProperty("PQSortByNameCheckBox", "false");

    jPanel1 = new javax.swing.JPanel();
    jContainComboBox = new javax.swing.JComboBox();
    jCategoryComboBox = new javax.swing.JComboBox();
    jSearchStringTextField = new javax.swing.JTextField();
    jFindButton = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();
    jPanel2 = new javax.swing.JPanel();
    jStartTimeTextField = new javax.swing.JTextField();
    jBackwardButton = new javax.swing.JButton();
    jForwardButton = new javax.swing.JButton();
    jLabel2 = new javax.swing.JLabel();

    //setLayout(new java.awt.BorderLayout());
    setLayout(new java.awt.BorderLayout(20, 4));

    jPanel1.setLayout(new java.awt.GridBagLayout());

    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Search By Name"));
    jPanel1.setMinimumSize(new java.awt.Dimension(0, 50));
    jPanel1.setPreferredSize(new java.awt.Dimension(400, 80));
    jContainComboBox.setModel(new javax.swing.DefaultComboBoxModel(
            new String[] { "Containing", "Start With", "End With", "Exact" }));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.ipadx = 32;
    gridBagConstraints.ipady = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 2);
    jPanel1.add(jContainComboBox, gridBagConstraints);

    jCategoryComboBox.setModel(new javax.swing.DefaultComboBoxModel(
            new String[] { "Any Category", "Previous Query", "Previous Query Result", "Patient" }));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.ipadx = 14;
    gridBagConstraints.ipady = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.6;
    gridBagConstraints.insets = new java.awt.Insets(4, 2, 0, 2);
    jPanel1.add(jCategoryComboBox, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.ipadx = 11;
    gridBagConstraints.ipady = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.9;
    gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
    jPanel1.add(jSearchStringTextField, gridBagConstraints);

    jFindButton.setText("Find");
    jFindButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jFindButtonActionPerformed(evt);
        }
    });

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.ipadx = 19;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(4, 4, 2, 2);
    jPanel1.add(jFindButton, gridBagConstraints);

    add(jPanel1, java.awt.BorderLayout.NORTH);

    QueryMasterData tmpData = new QueryMasterData();
    tmpData.name("Queries by " + UserInfoBean.getInstance().getUserName());
    tmpData.tooltip("Previous query runs");
    tmpData.visualAttribute("CA");
    top = new DefaultMutableTreeNode(tmpData);
    // top = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(top);
    // treeModel.addTreeModelListener(new MyTreeModelListener());

    jTree1 = new JTree(treeModel);
    jTree1.setEditable(false);

    // jTree1.getSelectionModel().setSelectionMode
    // (TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setShowsRootHandles(true);
    // JScrollPane treeView = new JScrollPane(jTree1);
    jTree1.setRootVisible(false);
    jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setCellRenderer(new MyRenderer());
    ToolTipManager.sharedInstance().registerComponent(jTree1);

    if (cellStatus.equalsIgnoreCase("CellDown")) {
        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode("Data Repository Cell is unavailable");
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
        // Make sure the user can see the lovely new node.
        jTree1.expandPath(new TreePath(top.getPath()));
    }

    ArrayList<QueryMasterData> queries = previousQueries;
    if (queries != null) {
        for (int i = 0; i < queries.size(); i++) {
            addNode(queries.get(i));
        }
    }

    jScrollPane1.setViewportView(jTree1);
    add(jScrollPane1, java.awt.BorderLayout.CENTER);

    jTree1.setTransferHandler(new NodeCopyTransferHandler());
    jTree1.addTreeExpansionListener(this);
    jTree1.addTreeWillExpandListener(this);

    jPanel2.setLayout(new java.awt.GridBagLayout());

    jPanel2.setMinimumSize(new java.awt.Dimension(92, 20));
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.ipadx = 244;
    gridBagConstraints.ipady = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.9;
    gridBagConstraints.insets = new java.awt.Insets(0, 3, 0, 0);
    jPanel2.add(jStartTimeTextField, gridBagConstraints);

    jBackwardButton.setText("<");
    jBackwardButton.setMaximumSize(new java.awt.Dimension(43, 22));
    jBackwardButton.setMinimumSize(new java.awt.Dimension(43, 22));
    jBackwardButton.setPreferredSize(new java.awt.Dimension(43, 22));
    jBackwardButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jBackwardButtonActionPerformed(evt);
        }
    });

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 2);
    jPanel2.add(jBackwardButton, gridBagConstraints);

    jForwardButton.setText(">");
    jForwardButton.setMaximumSize(new java.awt.Dimension(43, 22));
    jForwardButton.setMinimumSize(new java.awt.Dimension(43, 22));
    jForwardButton.setPreferredSize(new java.awt.Dimension(43, 22));
    jForwardButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jForwardButtonActionPerformed(evt);
        }
    });

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 3;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(0, 43, 0, 3);
    jPanel2.add(jForwardButton, gridBagConstraints);

    jLabel2.setText("Begin:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.01;
    gridBagConstraints.insets = new java.awt.Insets(3, 7, 0, 2);
    jPanel2.add(jLabel2, gridBagConstraints);

    add(jPanel2, java.awt.BorderLayout.SOUTH);
}

From source file:com.mirth.connect.client.ui.ChannelPanel.java

public void doNewGroup() {
    if (parent.getChannelTagInfo(false).isEnabled()) {
        return;/*from  www.j ava2  s.c  o m*/
    }

    ChannelTreeTableModel model = (ChannelTreeTableModel) channelTable.getTreeTableModel();
    MutableTreeTableNode root = (MutableTreeTableNode) model.getRoot();
    if (root == null) {
        return;
    }

    GroupDetailsDialog dialog = new GroupDetailsDialog(true);

    if (dialog.wasSaved()) {
        AbstractChannelTableNode groupNode = model
                .addNewGroup(new ChannelGroup(dialog.getGroupName(), dialog.getGroupDescription()));

        parent.setSaveEnabled(true);

        final TreePath path = new TreePath(new Object[] { root, groupNode });
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                channelTable.getTreeSelectionModel().setSelectionPath(path);
            }
        });
    }
}