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:com.peter.mavenrunner.MavenRunnerTopComponent.java

public void expandAll(JTree tree, boolean expand, int maxLevel) {
    MyTreeNode tempRoot = (MyTreeNode) treeModel.getRoot();
    if (tempRoot != null) {
        //         log(" ---------- tempRoot 2 = " + tempRoot.getChildCount() + " , " + tempRoot);
        //         for (int x = 0; x < tempRoot.getChildCount(); x++) {
        //            log("                --------> " + x + " = " + tempRoot.getChildAt(x));
        //         }
        expandAll(tree, new TreePath(tempRoot), expand, maxLevel, 0);
        tree.expandPath(new TreePath(tempRoot));
    }/*from   ww w .  j  av  a 2 s .c  o  m*/
}

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

private void handleUpdateSummary(Map<String, CodeTemplateLibrary> libraries,
        Map<String, CodeTemplate> updatedCodeTemplates, Map<String, CodeTemplate> removedCodeTemplates,
        boolean override, TreeTableNode selectedNode, Set<String> expandedLibraryIds,
        CodeTemplateLibrarySaveResult updateSummary) {
    try {//from   w ww .ja  v a 2s .  co  m
        if (!updateSummary.isOverrideNeeded()) {
            if (updateSummary.isLibrariesSuccess()) {
                Set<String> assignedCodeTemplateIds = new HashSet<String>();
                List<String> libraryNames = new ArrayList<String>();

                // Replace the cached libraries
                codeTemplateLibraries.clear();
                for (CodeTemplateLibrary library : libraries.values()) {
                    LibraryUpdateResult result = updateSummary.getLibraryResults().get(library.getId());
                    library.setRevision(result.getNewRevision());
                    library.setLastModified(result.getNewLastModified());
                    codeTemplateLibraries.put(library.getId(), library);

                    for (CodeTemplate codeTemplate : library.getCodeTemplates()) {
                        assignedCodeTemplateIds.add(codeTemplate.getId());
                    }

                    libraryNames.add(library.getName());
                }

                int numFailed = 0;
                Throwable firstCause = null;
                Set<String> successfulIds = new HashSet<String>();

                // Update any cached code templates that were successfully saved
                for (Entry<String, CodeTemplateUpdateResult> entry : updateSummary.getCodeTemplateResults()
                        .entrySet()) {
                    String codeTemplateId = entry.getKey();
                    CodeTemplateUpdateResult result = entry.getValue();

                    if (result.isSuccess()) {
                        CodeTemplate updatedCodeTemplate = updatedCodeTemplates.get(codeTemplateId);

                        if (updatedCodeTemplate != null) {
                            updatedCodeTemplate.setRevision(result.getNewRevision());
                            updatedCodeTemplate.setLastModified(result.getNewLastModified());
                            codeTemplates.put(codeTemplateId, updatedCodeTemplate);
                        } else {
                            codeTemplates.remove(codeTemplateId);
                        }

                        successfulIds.add(codeTemplateId);
                    } else {
                        numFailed++;
                        if (firstCause == null && result.getCause() != null) {
                            firstCause = result.getCause();
                        }
                    }
                }

                // Create a new table model
                CodeTemplateRootTreeTableNode root = new CodeTemplateRootTreeTableNode();

                // Create each library node
                for (CodeTemplateLibrary library : codeTemplateLibraries.values()) {
                    CodeTemplateLibraryTreeTableNode libraryNode = new CodeTemplateLibraryTreeTableNode(
                            library);

                    for (CodeTemplate codeTemplate : library.getCodeTemplates()) {
                        String codeTemplateId = codeTemplate.getId();

                        if (successfulIds.contains(codeTemplateId)) {
                            // If the update was successful, add the new code template. If the remove was successful, don't add anything.
                            if (updatedCodeTemplates.containsKey(codeTemplateId)) {
                                CodeTemplateTreeTableNode newCodeTemplateNode = new CodeTemplateTreeTableNode(
                                        codeTemplates.get(codeTemplate.getId()));
                                libraryNode.add(newCodeTemplateNode);
                            }
                        } else {
                            // The update or removal wasn't successful, so add the old template
                            CodeTemplateTreeTableNode codeTemplateNode = getCodeTemplateNodeById(
                                    codeTemplateId);
                            if (codeTemplateNode != null) {
                                CodeTemplateTreeTableNode newCodeTemplateNode = new CodeTemplateTreeTableNode(
                                        codeTemplateNode.getCodeTemplate());
                                libraryNode.add(newCodeTemplateNode);
                            }
                        }
                    }

                    root.add(libraryNode);
                }

                // Update the actual table model
                CodeTemplateTreeTableModel model = (CodeTemplateTreeTableModel) templateTreeTable
                        .getTreeTableModel();

                updateCurrentNode.set(false);
                fullModel.setRoot(root);
                fullModel.sort();
                if (StringUtils.isNotBlank(templateFilterField.getText())) {
                    root = getFilteredRootNode(root);
                }
                model.setRoot(root);
                model.sort();
                updateFilterNotification();

                saveAdjusting.set(true);
                ReferenceListFactory.getInstance().updateUserCodeTemplates();
                updateTasks();
                updateLibrariesComboBox();
                expandLibraryNodes(expandedLibraryIds);

                // Re-select the previously selected node if applicable
                TreePath selectedPath = null;
                if (selectedNode != null) {

                    for (Enumeration<? extends MutableTreeTableNode> libraryNodes = root
                            .children(); libraryNodes.hasMoreElements();) {
                        CodeTemplateLibraryTreeTableNode libraryNode = (CodeTemplateLibraryTreeTableNode) libraryNodes
                                .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);
                    }
                }

                if (numFailed > 0) {
                    if (firstCause != null) {
                        parent.alertThrowable(parent, firstCause,
                                numFailed + " code templates failed to be updated or removed. First cause: "
                                        + firstCause.getMessage());
                    } else {
                        parent.alertError(parent,
                                numFailed + " code templates failed to be updated or removed.");
                    }
                } else {
                    setSaveEnabled(false);
                }

                final TreePath finalPath = selectedPath;
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        if (finalPath != null) {
                            selectTemplatePath(finalPath);
                        }
                        saveAdjusting.set(false);
                        updateCurrentNode.set(true);
                    }
                });
            } else {
                if (updateSummary.getLibrariesCause() != null) {
                    parent.alertThrowable(parent, updateSummary.getLibrariesCause(),
                            "Unable to save code template libraries: "
                                    + updateSummary.getLibrariesCause().getMessage());
                } else {
                    parent.alertError(parent, "Unable to save code template libraries.");
                }
            }
        }
    } catch (Exception e) {
        Throwable cause = e;
        if (cause instanceof ExecutionException) {
            cause = e.getCause();
        }
        parent.alertThrowable(parent, cause,
                "Unable to save code templates or libraries: " + cause.getMessage());
    }
}

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

/**
 * @param bottomNode/*from ww w  .  j  av  a  2  s.  co m*/
 */
private void expandToNode(final DefaultMutableTreeNode bottomNode) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            if (model != null && bottomNode != null && bottomNode.getParent() != null) {
                TreeNode[] path = model.getPathToRoot(bottomNode);
                if (path != null && path.length > 0) {
                    tree.expandPath(new TreePath(path));
                }
            }
        }
    });
}

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  va2s .c  o  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.QueryPreviousRunsPanel.java

public void treeExpanded(TreeExpansionEvent event) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    QueryData data = (QueryData) node.getUserObject();
    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");
    }/*from   w  ww  .ja v a2  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 (((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:com.mirth.connect.client.ui.ChannelPanel.java

public void doAssignChannelToGroup() {
    ChannelTreeTableModel model = (ChannelTreeTableModel) channelTable.getTreeTableModel();
    int[] rows = channelTable.getSelectedModelRows();

    if (model.isGroupModeEnabled() && rows.length > 0) {
        for (int row : rows) {
            if (((AbstractChannelTableNode) channelTable.getPathForRow(row).getLastPathComponent())
                    .isGroupNode()) {//from   w w  w.j  av  a  2  s  .c  o m
                return;
            }
        }

        GroupAssignmentDialog dialog = new GroupAssignmentDialog();

        if (dialog.wasSaved()) {
            AbstractChannelTableNode groupNode = null;
            for (Enumeration<? extends MutableTreeTableNode> groupNodes = ((MutableTreeTableNode) model
                    .getRoot()).children(); groupNodes.hasMoreElements();) {
                AbstractChannelTableNode node = (AbstractChannelTableNode) groupNodes.nextElement();
                if (StringUtils.equals(node.getGroupStatus().getGroup().getId(), dialog.getSelectedGroupId())) {
                    groupNode = node;
                    break;
                }
            }

            if (groupNode != null) {
                TableState tableState = getCurrentTableState();
                tableState.getExpandedGroupIds().add(groupNode.getGroupStatus().getGroup().getId());

                ListSelectionListener[] listeners = ((DefaultListSelectionModel) channelTable
                        .getSelectionModel()).getListSelectionListeners();
                for (ListSelectionListener listener : listeners) {
                    channelTable.getSelectionModel().removeListSelectionListener(listener);
                }

                try {
                    List<AbstractChannelTableNode> channelNodes = new ArrayList<AbstractChannelTableNode>();
                    for (int row : rows) {
                        channelNodes.add((AbstractChannelTableNode) channelTable.getPathForRow(row)
                                .getLastPathComponent());
                    }
                    for (AbstractChannelTableNode channelNode : channelNodes) {
                        model.addChannelToGroup(groupNode, channelNode.getChannelStatus().getChannel().getId());
                    }
                    channelTable.expandPath(new TreePath(
                            new Object[] { channelTable.getTreeTableModel().getRoot(), groupNode }));

                    parent.setSaveEnabled(true);
                } finally {
                    for (ListSelectionListener listener : listeners) {
                        channelTable.getSelectionModel().addListSelectionListener(listener);
                    }

                    restoreTableState(tableState);
                }
            }
        }
    }
}

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

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

    java.awt.GridBagConstraints gridBagConstraints;
    System.setProperty("PQSortByTimeCheckBox", "true");
    System.setProperty("PatientSetMaxQueryNumber", "20");
    System.setProperty("PatientSetMaxPatientsNumber", "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(20, 10));

    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", "Patient Set", "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);

    QueryResultData tmpData = new QueryResultData();
    tmpData.name("Pateint Sets by " + UserInfoBean.getInstance().getUserName());
    tmpData.tooltip("Patient Sets");
    tmpData.visualAttribute("CA");
    tmpData.type("PATIENTSET");
    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<QueryResultData> queries = patientSets;
    if (queries != null) {
        for (int i = 0; i < queries.size(); i++) {
            addNode(patientSets.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:GUI.MainWindow.java

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

    // Create a new vuln
    Vulnerability vuln = new Vulnerability();
    vuln.setTitle("NEW");
    vuln.setIs_custom_risk(true);/*from   w w  w  . jav a2  s. c  o m*/
    vuln.setRisk_category("None");
    vuln.setImport_tool("ReportCompiler");
    vuln.setIdentifier();
    // Add it to the tree
    DefaultTreeModel dtm = (DefaultTreeModel) VulnTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot();
    DefaultMutableTreeNode new_vuln = new DefaultMutableTreeNode(vuln);
    root.add(new_vuln);
    // Refresh the GUI
    dtm.reload();
    // Now select 
    TreePath path = new TreePath(new_vuln.getPath());
    VulnTree.setSelectionPath(path);
    // Set focus on the title field
    this.VulnTitleTextField.requestFocus();
    this.VulnTitleTextField.selectAll();
}

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

private void populateChildNodes(DefaultMutableTreeNode node) {
    if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {
        QueryMasterData data = (QueryMasterData) node.getUserObject();
        try {/*from  w  ww.  j a  va 2 s.  c o m*/
            String xmlRequest = data.writeContentQueryXML();
            lastRequestMessage = xmlRequest;
            //System.out.println(xmlRequest);
            String xmlResponse = QueryListNamesClient.sendQueryRequestREST(xmlRequest);
            if (xmlResponse.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }
                });
                return;
            }
            lastResponseMessage = xmlResponse;

            try {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
                JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();

                BodyType bt = messageType.getMessageBody();
                InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper()
                        .getObjectByClass(bt.getAny(), InstanceResponseType.class);

                for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) {
                    //change later for working with new xml schema
                    //RunQuery runQuery = queryInstanceType.getResult().get(i).getRunQuery().get(0);

                    QueryInstanceData runData = new QueryInstanceData();

                    runData.visualAttribute("FA");
                    runData.tooltip("The results of the query run");
                    runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString());
                    //runData.patientRefId(new Integer(queryInstanceType.getRefId()).toString());
                    //runData.patientCount(new Long(queryInstanceType.getCount()).toString());
                    XMLGregorianCalendar cldr = queryInstanceType.getStartDate();
                    runData.name("Results of " + "[" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " " + addZero(cldr.getHour()) + ":"
                            + addZero(cldr.getMinute()) + ":" + addZero(cldr.getSecond()) + "]");

                    data.runs.add(runData);
                    addNode(runData, node);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            jTree1.scrollPathToVisible(new TreePath(node.getPath()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryInstanceData")) {
        QueryInstanceData data = (QueryInstanceData) node.getUserObject();

        try {
            String xmlRequest = data.writeContentQueryXML();
            lastRequestMessage = xmlRequest;
            //System.out.println(xmlRequest);

            String xmlResponse = QueryListNamesClient.sendQueryRequestREST(xmlRequest);
            if (xmlResponse.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }
                });
                return;
            }
            lastResponseMessage = xmlResponse;

            JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

            JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
            ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
            BodyType bt = messageType.getMessageBody();
            ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper()
                    .getObjectByClass(bt.getAny(), ResultResponseType.class);

            for (QueryResultInstanceType queryResultInstanceType : resultResponseType
                    .getQueryResultInstance()) {
                String status = queryResultInstanceType.getQueryStatusType().getName();

                QueryResultData resultData = new QueryResultData();
                resultData.visualAttribute("LAO");
                resultData.tooltip("A patient set of the query run");
                //resultData.queryId(data.queryId());
                resultData.patientRefId(new Integer(queryResultInstanceType.getResultInstanceId()).toString());//data.patientRefId());
                resultData.patientCount(new Integer(queryResultInstanceType.getSetSize()).toString());//data.patientCount());
                if (status.equalsIgnoreCase("FINISHED")) {
                    resultData.name("Patient Set - " + resultData.patientCount() + " Patients");
                } else {
                    resultData.name("Patient Set - " + status);
                }
                resultData.xmlContent(xmlResponse);

                addNode(resultData, node);
            }

            jTree1.scrollPathToVisible(new TreePath(node.getPath()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //implement for other type of nodes later!!!
}

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

public TableState getCurrentTableState() {
    Set<String> selectedIds = new HashSet<String>();
    Map<String, Set<Integer>> selectedConnectors = new HashMap<String, Set<Integer>>();
    Set<String> expandedIds = new HashSet<String>();
    Set<String> collapsedIds = new HashSet<String>();

    int[] selectedRows = dashboardTable.getSelectedModelRows();
    for (int row : selectedRows) {
        AbstractDashboardTableNode node = (AbstractDashboardTableNode) dashboardTable.getPathForRow(row)
                .getLastPathComponent();

        if (node.isGroupNode()) {
            selectedIds.add(node.getGroupStatus().getGroup().getId());
        } else {//from   www .j av  a2  s  .c om
            DashboardStatus status = node.getDashboardStatus();

            if (status.getStatusType() == StatusType.CHANNEL) {
                selectedIds.add(status.getChannelId());
            } else if (status.getStatusType() == StatusType.SOURCE_CONNECTOR
                    || status.getStatusType() == StatusType.DESTINATION_CONNECTOR) {
                Set<Integer> selectedMetaDataIds = selectedConnectors.get(status.getChannelId());
                if (selectedMetaDataIds == null) {
                    selectedMetaDataIds = new HashSet<Integer>();
                    selectedConnectors.put(status.getChannelId(), selectedMetaDataIds);
                }
                selectedMetaDataIds.add(status.getMetaDataId());
            }
        }
    }

    DashboardTreeTableModel model = (DashboardTreeTableModel) dashboardTable.getTreeTableModel();
    MutableTreeTableNode root = (MutableTreeTableNode) model.getRoot();

    if (root != null) {
        if (model.isGroupModeEnabled()) {
            for (Enumeration<? extends MutableTreeTableNode> groupNodes = root.children(); groupNodes
                    .hasMoreElements();) {
                AbstractDashboardTableNode groupNode = (AbstractDashboardTableNode) groupNodes.nextElement();

                if (dashboardTable.isExpanded(new TreePath(new Object[] { root, groupNode }))) {
                    expandedIds.add(groupNode.getGroupStatus().getGroup().getId());
                } else if (groupNode.getChildCount() > 0) {
                    collapsedIds.add(groupNode.getGroupStatus().getGroup().getId());
                }

                addChannelNodeExpansionStates(groupNode, expandedIds, collapsedIds);
            }
        } else {
            addChannelNodeExpansionStates(root, expandedIds, collapsedIds);
        }
    }

    return new TableState(selectedIds, selectedConnectors, expandedIds, collapsedIds);
}