Example usage for javax.swing.tree DefaultMutableTreeNode setUserObject

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

Introduction

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

Prototype

public void setUserObject(Object userObject) 

Source Link

Document

Sets the user object for this node to userObject.

Usage

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

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equalsIgnoreCase("Rename ...")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        QueryMasterData ndata = (QueryMasterData) node.getUserObject();
        Object inputValue = JOptionPane.showInputDialog(this, "Rename this query to: ", "Rename Query Dialog",
                JOptionPane.PLAIN_MESSAGE, null, null,
                ndata.name().substring(0, ndata.name().lastIndexOf("[") - 1));

        if (inputValue != null) {
            String newQueryName = (String) inputValue;
            String requestXml = ndata.writeRenameQueryXML(newQueryName);

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                // TO DO
                // response =
                // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
            } else {
                response = QueryListNamesClient.sendQueryRequestREST(requestXml);
            }//  w  w w  .j  a  v a2  s . co  m

            if (response.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);
                    }
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }

            if (response != null) {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();

                    if (status.equalsIgnoreCase("DONE")) {
                        ndata.name(newQueryName + " [" + ndata.userId() + "]");
                        node.setUserObject(ndata);
                        // DefaultMutableTreeNode parent =
                        // (DefaultMutableTreeNode) node.getParent();

                        jTree1.repaint();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
    } else if (e.getActionCommand().equalsIgnoreCase("Delete")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        QueryMasterData ndata = (QueryMasterData) node.getUserObject();
        Object selectedValue = JOptionPane.showConfirmDialog(this, "Delete Query \"" + ndata.name() + "\"?",
                "Delete Query Dialog", JOptionPane.YES_NO_OPTION);
        if (selectedValue.equals(JOptionPane.YES_OPTION)) {
            System.out.println("delete " + ndata.name());
            String requestXml = ndata.writeDeleteQueryXML();
            // System.out.println(requestXml);

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                // TO DO
                // response =
                // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
            } else {
                response = QueryListNamesClient.sendQueryRequestREST(requestXml);
            }

            if (response.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);
                    }
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }

            if (response != null) {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();

                    if (status.equalsIgnoreCase("DONE")) {
                        treeModel.removeNodeFromParent(node);

                        // jTree1.repaint();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
    } else if (e.getActionCommand().equalsIgnoreCase("Refresh All")) {
        String status = loadPreviousQueries(false);
        if (status.equalsIgnoreCase("")) {
            reset(200, false);
        } else if (status.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);
                }
            });
        }
    }
}

From source file:lcmc.gui.resources.ServiceInfo.java

/** Change type to Master, Clone or Primitive. */
protected final void changeType(final String value) {
    boolean masterSlave = false;
    boolean clone = false;
    if (MASTER_SLAVE_TYPE_STRING.equals(value)) {
        masterSlave = true;//from ww  w.  j  av a  2  s . c  o m
        clone = true;
    } else if (CLONE_TYPE_STRING.equals(value)) {
        clone = true;
    }

    final ServiceInfo thisClass = this;
    if (clone) {
        final CRMXML crmXML = getBrowser().getCRMXML();
        final CloneInfo oldCI = getCloneInfo();
        String title = ConfigData.PM_CLONE_SET_NAME;
        if (masterSlave) {
            title = ConfigData.PM_MASTER_SLAVE_SET_NAME;
        }
        final CloneInfo ci = new CloneInfo(crmXML.getHbClone(), title, masterSlave, getBrowser());
        setCloneInfo(ci);
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                if (oldCI == null) {
                    getBrowser().getCRMGraph().exchangeObjectInTheVertex(ci, thisClass);
                    ci.setPingComboBox(pingComboBox);
                    for (final HostInfo hi : scoreComboBoxHash.keySet()) {
                        ci.getScoreComboBoxHash().put(hi, scoreComboBoxHash.get(hi));
                    }
                    final Widget prevWi = getWidget(GUI_ID, null);
                    if (prevWi != null) {
                        ci.getService().setId(getName() + "_" + prevWi.getStringValue());
                    }
                } else {
                    oldCI.removeNode();
                    getBrowser().getCRMGraph().exchangeObjectInTheVertex(ci, oldCI);
                    cleanup();
                    oldCI.cleanup();
                    ci.setPingComboBox(oldCI.getPingComboBox());
                    for (final HostInfo hi : oldCI.getScoreComboBoxHash().keySet()) {
                        ci.getScoreComboBoxHash().put(hi, oldCI.getScoreComboBoxHash().get(hi));
                    }
                    getBrowser().removeFromServiceInfoHash(oldCI);
                    getBrowser().mHeartbeatIdToServiceLock();
                    getBrowser().getHeartbeatIdToServiceInfo().remove(oldCI.getService().getHeartbeatId());
                    getBrowser().mHeartbeatIdToServiceUnlock();
                    final DefaultMutableTreeNode oldCINode = oldCI.getNode();
                    if (oldCINode != null) {
                        oldCINode.setUserObject(null); /* would leak
                                                          without it*/
                    }
                    ci.getService().setId(oldCI.getWidget(GUI_ID, null).getStringValue());
                }
                ci.setCloneServicePanel(thisClass);
                infoPanel = null;
            }
        });
    } else if (PRIMITIVE_TYPE_STRING.equals(value)) {
        final CloneInfo ci = getCloneInfo();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                setPingComboBox(ci.getPingComboBox());
                for (final HostInfo hi : ci.getScoreComboBoxHash().keySet()) {
                    scoreComboBoxHash.put(hi, ci.getScoreComboBoxHash().get(hi));
                }
                final DefaultMutableTreeNode node = getNode();
                final DefaultMutableTreeNode ciNode = ci.getNode();
                removeNode();
                ci.removeNode();
                cleanup();
                ci.cleanup();
                setNode(node);
                getBrowser().getServicesNode().add(node);
                getBrowser().getCRMGraph().exchangeObjectInTheVertex(thisClass, ci);
                getBrowser().mHeartbeatIdToServiceLock();
                getBrowser().getHeartbeatIdToServiceInfo().remove(ci.getService().getHeartbeatId());
                getBrowser().mHeartbeatIdToServiceUnlock();
                getBrowser().removeFromServiceInfoHash(ci);
                infoPanel = null;
                setCloneInfo(null);
                selectMyself();
                ciNode.setUserObject(null); /* would leak without it */
            }
        });
    }
}

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

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equalsIgnoreCase("Rename ...")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {

            QueryMasterData ndata = (QueryMasterData) node.getUserObject();
            Object inputValue = JOptionPane.showInputDialog(this, "Rename this query to: ",
                    "Rename Query Dialog", JOptionPane.PLAIN_MESSAGE, null, null,
                    ndata.name().substring(0, ndata.name().indexOf("[") - 1));

            if (inputValue != null) {
                String newQueryName = (String) inputValue;
                String requestXml = ndata.writeRenameQueryXML(newQueryName);

                setCursor(new Cursor(Cursor.WAIT_CURSOR));

                String response = null;
                if (System.getProperty("webServiceMethod").equals("SOAP")) {
                    // TO DO
                    // response =
                    // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
                } else {
                    response = QueryListNamesClient.sendQueryRequestREST(requestXml);
                }/*  ww  w.jav  a2s  . co  m*/

                if (response.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);
                        }
                    });
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                    return;
                }

                if (response != null) {
                    JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                    try {
                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                        StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                        String status = statusType.getType();

                        if (status.equalsIgnoreCase("DONE")) {
                            // XMLGregorianCalendar cldr =
                            // //queryMasterType.getCreateDate();
                            Calendar cldr = Calendar.getInstance(Locale.getDefault());
                            ndata.name(newQueryName + " [" + addZero(cldr.get(Calendar.MONTH) + 1) + "-"
                                    + addZero(cldr.get(Calendar.DAY_OF_MONTH)) + "-"
                                    + addZero(cldr.get(Calendar.YEAR)) + " ]" + " [" + ndata.userId() + "]");
                            // ndata.name(newQueryName + " [" +
                            // ndata.userId()
                            // + "]");
                            node.setUserObject(ndata);
                            // DefaultMutableTreeNode parent =
                            // (DefaultMutableTreeNode) node.getParent();

                            jTree1.repaint();
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryResultData")) {

            QueryResultData rdata = (QueryResultData) node.getUserObject();
            // if(!rdata.type().equalsIgnoreCase("PatientSet")) {
            // return;
            // }

            Object inputValue1 = JOptionPane.showInputDialog(this, "Rename this to: ", "Renaming Dialog",
                    JOptionPane.PLAIN_MESSAGE, null, null, rdata.name());
            // .substring(0, rdata.name().lastIndexOf("[") - 1));

            if (inputValue1 != null) {
                String newQueryName = (String) inputValue1;
                String requestXml = rdata.writeRenameQueryXML(newQueryName);

                setCursor(new Cursor(Cursor.WAIT_CURSOR));

                String response = null;
                if (System.getProperty("webServiceMethod").equals("SOAP")) {
                    // TO DO
                    // response =
                    // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
                } else {
                    response = QueryListNamesClient.sendQueryRequestREST(requestXml);
                }

                if (response.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);

                        }
                    });
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                    return;
                }

                if (response != null) {
                    JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                    try {
                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                        StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                        String status = statusType.getType();

                        if (status.equalsIgnoreCase("DONE")) {
                            rdata.name(newQueryName);// + " [" +
                            // rdata.userId()
                            // + "]");
                            node.setUserObject(rdata);
                            // DefaultMutableTreeNode parent =
                            // (DefaultMutableTreeNode) node.getParent();

                            jTree1.repaint();
                        } else {
                            final String tmp = response;
                            final JPanel parent = this;
                            java.awt.EventQueue.invokeLater(new Runnable() {
                                public void run() {
                                    JOptionPane.showMessageDialog(parent,
                                            "Error message delivered from the remote server, "
                                                    + "you may wish to retry your last action",
                                            "Server Error", JOptionPane.INFORMATION_MESSAGE);
                                    log.error(tmp);
                                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                                }

                            });

                            return;
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    } else if (e.getActionCommand().equalsIgnoreCase("Cancel")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {
            DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getFirstChild();
            if (node1.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent, "Please expand this node then try to cancel it.",
                                "Message", JOptionPane.INFORMATION_MESSAGE);

                    }
                });
                return;
            }
            QueryInstanceData rdata = (QueryInstanceData) node1.getUserObject();

            String requestXml = rdata.writeCancelQueryXML();

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                // TO DO
                // response =
                // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
            } else {
                response = QueryListNamesClient.sendQueryRequestREST(requestXml);
            }

            if (response.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);

                    }
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }

            if (response != null) {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();
                    final JPanel parent = this;
                    if (status.equalsIgnoreCase("DONE")) {
                        java.awt.EventQueue.invokeLater(new Runnable() {
                            public void run() {
                                JOptionPane.showMessageDialog(parent, "The query is finished.", "Message",
                                        JOptionPane.INFORMATION_MESSAGE);
                                // log.error(tmp);
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                            }

                        });
                        rdata.name(rdata.name().substring(0, rdata.name().indexOf("-")));// + " [" +
                        // rdata
                        // .userId()
                        // + "]");
                        node.setUserObject(rdata);
                        // DefaultMutableTreeNode parent =
                        // (DefaultMutableTreeNode) node.getParent();

                        jTree1.repaint();
                    } else {
                        final String tmp = response;
                        // final JPanel parent = this;
                        java.awt.EventQueue.invokeLater(new Runnable() {
                            public void run() {
                                JOptionPane.showMessageDialog(parent,
                                        "Error message delivered from the remote server, "
                                                + "you may wish to retry your last action",
                                        "Server Error", JOptionPane.INFORMATION_MESSAGE);
                                log.error(tmp);
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                            }

                        });

                        return;
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                // }
            }
        } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryInstanceData")) {

            QueryInstanceData rdata = (QueryInstanceData) node.getUserObject();

            String requestXml = rdata.writeCancelQueryXML();

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                // TO DO
                // response =
                // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
            } else {
                response = QueryListNamesClient.sendQueryRequestREST(requestXml);
            }

            if (response.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);

                    }
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }

            if (response != null) {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();
                    final JPanel parent = this;
                    if (status.equalsIgnoreCase("DONE")) {
                        java.awt.EventQueue.invokeLater(new Runnable() {
                            public void run() {
                                JOptionPane.showMessageDialog(parent, "The query is finished.", "Message",
                                        JOptionPane.INFORMATION_MESSAGE);
                                // log.error(tmp);
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                            }

                        });
                        rdata.name(rdata.name().substring(0, rdata.name().indexOf("-")));// + " [" +
                        // rdata
                        // .userId()
                        // + "]");
                        node.setUserObject(rdata);
                        // DefaultMutableTreeNode parent =
                        // (DefaultMutableTreeNode) node.getParent();

                        jTree1.repaint();
                    } else {
                        final String tmp = response;
                        // final JPanel parent = this;
                        java.awt.EventQueue.invokeLater(new Runnable() {
                            public void run() {
                                JOptionPane.showMessageDialog(parent,
                                        "Error message delivered from the remote server, "
                                                + "you may wish to retry your last action",
                                        "Server Error", JOptionPane.INFORMATION_MESSAGE);
                                log.error(tmp);
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                            }

                        });

                        return;
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                // }
            }
        } else {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {

                public void run() {
                    JOptionPane.showMessageDialog(parent, "Cancel action is not supported on this level",
                            "Message", JOptionPane.INFORMATION_MESSAGE);
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                }

            });
        }
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    } else if (e.getActionCommand().equalsIgnoreCase("Delete")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        QueryMasterData ndata = (QueryMasterData) node.getUserObject();
        Object selectedValue = JOptionPane.showConfirmDialog(this, "Delete Query \"" + ndata.name() + "\"?",
                "Delete Query Dialog", JOptionPane.YES_NO_OPTION);
        if (selectedValue.equals(JOptionPane.YES_OPTION)) {
            System.out.println("delete " + ndata.name());
            String requestXml = ndata.writeDeleteQueryXML();
            // System.out.println(requestXml);

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                // TO DO
                // response =
                // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
            } else {
                response = QueryListNamesClient.sendQueryRequestREST(requestXml);
            }

            if (response.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);
                    }
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }

            if (response != null) {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();

                    if (status.equalsIgnoreCase("DONE")) {
                        treeModel.removeNodeFromParent(node);

                        // jTree1.repaint();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
    } else if (e.getActionCommand().equalsIgnoreCase("Refresh All")) {
        String status = "";
        if (isManager) {
            status = loadPreviousQueries("all users");
        } else {
            status = loadPreviousQueries(UserInfoBean.getInstance().getUserName());
        }
        if (status.equalsIgnoreCase("")) {
            reset(200, false, false);
        } else if (status.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);
                }
            });
        }
    }
}

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

@SuppressWarnings("rawtypes")
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equalsIgnoreCase("Rename ...")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {

            QueryMasterData ndata = (QueryMasterData) node.getUserObject();
            Object inputValue = JOptionPane.showInputDialog(this, "Rename this query to: ",
                    "Rename Query Dialog", JOptionPane.PLAIN_MESSAGE, null, null,
                    ndata.name().substring(0, ndata.name().indexOf("[") - 1));

            if (inputValue != null) {
                String newQueryName = (String) inputValue;
                String requestXml = ndata.writeRenameQueryXML(newQueryName);

                setCursor(new Cursor(Cursor.WAIT_CURSOR));

                String response = null;
                if (System.getProperty("webServiceMethod").equals("SOAP")) {
                    // TO DO
                    // response =
                    // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
                } else {
                    response = QueryListNamesClient.sendQueryRequestREST(requestXml, true);
                }/*  w w  w . j ava  2  s  .  c o m*/

                if (response.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);
                        }
                    });
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                    return;
                }

                if (response != null) {
                    JAXBUtil jaxbUtil = PatientSetJAXBUtil.getJAXBUtil();

                    try {
                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                        StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                        String status = statusType.getType();

                        if (status.equalsIgnoreCase("DONE")) {
                            // XMLGregorianCalendar cldr =
                            // //queryMasterType.getCreateDate();
                            Calendar cldr = Calendar.getInstance(Locale.getDefault());
                            ndata.name(newQueryName + " [" + addZero(cldr.get(Calendar.MONTH) + 1) + "-"
                                    + addZero(cldr.get(Calendar.DAY_OF_MONTH)) + "-"
                                    + addZero(cldr.get(Calendar.YEAR)) + " ]" + " [" + ndata.userId() + "]");
                            // ndata.name(newQueryName + " [" +
                            // ndata.userId()
                            // + "]");
                            node.setUserObject(ndata);
                            // DefaultMutableTreeNode parent =
                            // (DefaultMutableTreeNode) node.getParent();

                            jTree1.repaint();
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryResultData")) {

            QueryResultData rdata = (QueryResultData) node.getUserObject();
            // if(!rdata.type().equalsIgnoreCase("PatientSet")) {
            // return;
            // }

            Object inputValue1 = JOptionPane.showInputDialog(this, "Rename this to: ", "Renaming Dialog",
                    JOptionPane.PLAIN_MESSAGE, null, null, rdata.name());
            // .substring(0, rdata.name().lastIndexOf("[") - 1));

            if (inputValue1 != null) {
                String newQueryName = (String) inputValue1;
                String requestXml = rdata.writeRenameQueryXML(newQueryName);

                setCursor(new Cursor(Cursor.WAIT_CURSOR));

                String response = null;
                if (System.getProperty("webServiceMethod").equals("SOAP")) {
                    // TO DO
                    // response =
                    // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
                } else {
                    response = QueryListNamesClient.sendQueryRequestREST(requestXml, true);
                }

                if (response.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);

                        }
                    });
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                    return;
                }

                if (response != null) {
                    JAXBUtil jaxbUtil = PatientSetJAXBUtil.getJAXBUtil();

                    try {
                        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                        StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                        String status = statusType.getType();

                        if (status.equalsIgnoreCase("DONE")) {
                            rdata.name(newQueryName);// + " [" +
                            // rdata.userId()
                            // + "]");
                            node.setUserObject(rdata);
                            // DefaultMutableTreeNode parent =
                            // (DefaultMutableTreeNode) node.getParent();

                            jTree1.repaint();
                        } else {
                            final String tmp = response;
                            final JPanel parent = this;
                            java.awt.EventQueue.invokeLater(new Runnable() {
                                public void run() {
                                    JOptionPane.showMessageDialog(parent,
                                            "Error message delivered from the remote server, "
                                                    + "you may wish to retry your last action",
                                            "Server Error", JOptionPane.INFORMATION_MESSAGE);
                                    log.error(tmp);
                                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                                }

                            });

                            return;
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    } else if (e.getActionCommand().equalsIgnoreCase("Cancel")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {
            DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getFirstChild();
            if (node1.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent, "Please expand this node then try to cancel it.",
                                "Message", JOptionPane.INFORMATION_MESSAGE);

                    }
                });
                return;
            }
            QueryInstanceData rdata = (QueryInstanceData) node1.getUserObject();

            String requestXml = rdata.writeCancelQueryXML();

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                // TO DO
                // response =
                // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
            } else {
                response = QueryListNamesClient.sendQueryRequestREST(requestXml, true);
            }

            if (response.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);

                    }
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }

            if (response != null) {
                JAXBUtil jaxbUtil = PatientSetJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();
                    final JPanel parent = this;
                    if (status.equalsIgnoreCase("DONE")) {
                        java.awt.EventQueue.invokeLater(new Runnable() {
                            public void run() {
                                JOptionPane.showMessageDialog(parent, "The query is finished.", "Message",
                                        JOptionPane.INFORMATION_MESSAGE);
                                // log.error(tmp);
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                            }

                        });
                        rdata.name(rdata.name().substring(0, rdata.name().indexOf("-")));// + " [" +
                        // rdata
                        // .userId()
                        // + "]");
                        node.setUserObject(rdata);
                        // DefaultMutableTreeNode parent =
                        // (DefaultMutableTreeNode) node.getParent();

                        jTree1.repaint();
                    } else {
                        final String tmp = response;
                        // final JPanel parent = this;
                        java.awt.EventQueue.invokeLater(new Runnable() {
                            public void run() {
                                JOptionPane.showMessageDialog(parent,
                                        "Error message delivered from the remote server, "
                                                + "you may wish to retry your last action",
                                        "Server Error", JOptionPane.INFORMATION_MESSAGE);
                                log.error(tmp);
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                            }

                        });

                        return;
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                // }
            }
        } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryInstanceData")) {

            QueryInstanceData rdata = (QueryInstanceData) node.getUserObject();

            String requestXml = rdata.writeCancelQueryXML();

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                // TO DO
                // response =
                // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
            } else {
                response = QueryListNamesClient.sendQueryRequestREST(requestXml, true);
            }

            if (response.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);

                    }
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }

            if (response != null) {
                JAXBUtil jaxbUtil = PatientSetJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();
                    final JPanel parent = this;
                    if (status.equalsIgnoreCase("DONE")) {
                        java.awt.EventQueue.invokeLater(new Runnable() {
                            public void run() {
                                JOptionPane.showMessageDialog(parent, "The query is finished.", "Message",
                                        JOptionPane.INFORMATION_MESSAGE);
                                // log.error(tmp);
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                            }

                        });
                        rdata.name(rdata.name().substring(0, rdata.name().indexOf("-")));// + " [" +
                        // rdata
                        // .userId()
                        // + "]");
                        node.setUserObject(rdata);
                        // DefaultMutableTreeNode parent =
                        // (DefaultMutableTreeNode) node.getParent();

                        jTree1.repaint();
                    } else {
                        final String tmp = response;
                        // final JPanel parent = this;
                        java.awt.EventQueue.invokeLater(new Runnable() {
                            public void run() {
                                JOptionPane.showMessageDialog(parent,
                                        "Error message delivered from the remote server, "
                                                + "you may wish to retry your last action",
                                        "Server Error", JOptionPane.INFORMATION_MESSAGE);
                                log.error(tmp);
                                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                            }

                        });

                        return;
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                // }
            }
        } else {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {

                public void run() {
                    JOptionPane.showMessageDialog(parent, "Cancel action is not supported on this level",
                            "Message", JOptionPane.INFORMATION_MESSAGE);
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                }

            });
        }
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    } else if (e.getActionCommand().equalsIgnoreCase("Delete")) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        QueryMasterData ndata = (QueryMasterData) node.getUserObject();
        Object selectedValue = JOptionPane.showConfirmDialog(this, "Delete Query \"" + ndata.name() + "\"?",
                "Delete Query Dialog", JOptionPane.YES_NO_OPTION);
        if (selectedValue.equals(JOptionPane.YES_OPTION)) {
            System.out.println("delete " + ndata.name());
            String requestXml = ndata.writeDeleteQueryXML();
            // System.out.println(requestXml);

            setCursor(new Cursor(Cursor.WAIT_CURSOR));

            String response = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                // TO DO
                // response =
                // QueryListNamesClient.sendQueryRequestSOAP(requestXml);
            } else {
                response = QueryListNamesClient.sendQueryRequestREST(requestXml, true);
            }

            if (response.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);
                    }
                });
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                return;
            }

            if (response != null) {
                JAXBUtil jaxbUtil = PatientSetJAXBUtil.getJAXBUtil();

                try {
                    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response);
                    ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
                    StatusType statusType = messageType.getResponseHeader().getResultStatus().getStatus();
                    String status = statusType.getType();

                    if (status.equalsIgnoreCase("DONE")) {
                        treeModel.removeNodeFromParent(node);

                        // jTree1.repaint();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
    } else if (e.getActionCommand().equalsIgnoreCase("Refresh All")) {
        String status = "";
        if (isManager) {
            status = loadPreviousQueries(true);
        } else {
            status = loadPreviousQueries(false);
        }
        loadPatientSets();
        if (status.equalsIgnoreCase("")) {
            reset(200, false, false);
        } else if (status.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);
                }
            });
        }
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

public void addChildFiles(DefaultMutableTreeNode rootNode, FSOCollection children, DepositTreeModel model,
        String pathToDisplay, JTree whichTree) {
    LOG.debug("addChildFiles, root: " + rootNode.getUserObject());
    model.reload(rootNode);/* w w  w. ja v  a 2  s . c o m*/
    /*      for (FileSystemObject fso : children) {
             if (fso.getFile() == null) {
    LOG.debug("add child (file is null): " + fso.getDescription());
             } else {
    LOG.debug("add child (file is not null): "
          + fso.getDescription());
             }
             if ((!model.getTreeType().equals(ETreeType.FileSystemTree))
       || (!fso.getIsFile()) || (!fileIsInEntity(fso))) {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode();
    node.setUserObject(fso);
    model.insertNodeInto(node, rootNode, rootNode.getChildCount());
    addChildFiles(node, fso.getChildren(), model, pathToDisplay,
          whichTree);
    if ((pathToDisplay != null)
          && (pathToDisplay.equals(fso.getFullPath()))) {
       expandNode(whichTree, node, false);
       whichTree.scrollPathToVisible(new TreePath(node.getPath()));
    }
             }
          }*/
    for (int i = 0; i < children.size(); i++) {
        FileSystemObject fso = children.get(i);
        if (fso.getFile() == null) {
            LOG.debug("add child (file is null): " + fso.getDescription());
        } else {
            LOG.debug("add child (file is not null): " + fso.getDescription());
        }
        if ((!model.getTreeType().equals(ETreeType.FileSystemTree)) || (!fso.getIsFile())
                || (!fileIsInEntity(fso))) {
            DefaultMutableTreeNode node = new DefaultMutableTreeNode();
            node.setUserObject(fso);
            model.insertNodeInto(node, rootNode, rootNode.getChildCount());
            addChildFiles(node, fso.getChildren(), model, pathToDisplay, whichTree);
            if ((pathToDisplay != null) && (pathToDisplay.equals(fso.getFullPath()))) {
                expandNode(whichTree, node, false);
                whichTree.scrollPathToVisible(new TreePath(node.getPath()));
            }
        }
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

public void addFileSystemRoot(FileSystemObject fso, boolean recursive, boolean isEditingEntity,
        String pathToDisplay) {//  www . ja  v  a2  s.  c om
    fso.setSortBy(manualDepositFrame.getCurrentSortBy());
    String pathWanted = pathToDisplay;
    if (pathWanted != null) {
        File fileWanted = new File(pathWanted);
        while (fileWanted != null && !fileWanted.exists()) {
            fileWanted = fileWanted.getParentFile();
        }
        if (fileWanted != null) {
            pathWanted = fileWanted.getAbsolutePath();
        }
    }
    manualDepositFrame.setCurrentDirectory(pathWanted);
    manualDepositFrame.checkButtons();
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    rootNode.setUserObject(fso);
    DepositTreeModel model;
    if (theFileSystemTree.getModel() instanceof DepositTreeModel) {
        model = (DepositTreeModel) theFileSystemTree.getModel();
        model.setRoot(rootNode);
    } else {
        model = new DepositTreeModel(rootNode, ETreeType.FileSystemTree);
        theFileSystemTree.setModel(model);
    }
    LOG.debug("addFileSystemRoot");
    addChildFiles(rootNode, fso.getChildren(), model, pathWanted, theFileSystemTree);
    if (buildIE_Worker == null) {
        expandNode(theFileSystemTree, rootNode, recursive);
    }
    updateWorkerProgress(80);
    theFileSystemTree.repaint();
    theEntityTree.repaint();
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

public DefaultMutableTreeNode addIntellectualEntity(DefaultMutableTreeNode rootNode, FileGroup entity,
        boolean editEntry) {
    DepositTreeModel model = (DepositTreeModel) theEntityTree.getModel();
    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();
    newNode.setUserObject(entity);
    model.insertNodeInto(newNode, rootNode, rootNode.getChildCount());
    if (entity.getChildren() == null) {
        entity.setChildren(FSOCollection.create());
    }//  ww  w .j  a  v  a 2s.c  om
    addChildFiles(newNode, entity.getChildren(), model, null, null);
    TreePath newPath = new TreePath(newNode.getPath());
    theEntityTree.scrollPathToVisible(newPath);
    theEntityTree.setSelectionPath(newPath);
    theEntityTree.repaint();
    if (editEntry) {
        editEntity();
    }
    return newNode;
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

public void addIntellectualEntities(List<FileGroupCollection> entities) {
    updateWorkerProgress(50);//from   w  w w.ja  v  a 2s . co  m
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    DepositTreeModel model;
    if (theEntityTree.getModel() instanceof DepositTreeModel) {
        model = (DepositTreeModel) theEntityTree.getModel();
        model.setRoot(rootNode);
    } else {
        model = new DepositTreeModel(rootNode, ETreeType.EntityTree);
        theEntityTree.setModel(model);
    }
    if (entities == null) {
        rootNode.setUserObject("Intellectual Entity");
    } else {
        // Set folder as Root
        if (entities.size() == 1) {
            FileGroupCollection collection = entities.get(0);
            rootNode.setUserObject(collection);
            for (int i = 0; collection.getFileGroupList() != null
                    && i < collection.getFileGroupList().size(); i++) {
                addIntellectualEntity(rootNode, collection.getFileGroupList().get(i), false);
            }
        }
        // Set each file as IE
        else {
            rootNode.setUserObject(theFsoRoot.getDescription());
            for (FileGroupCollection entity : entities) {
                DefaultMutableTreeNode childNode = new DefaultMutableTreeNode();
                childNode.setUserObject(entity);
                model.insertNodeInto(childNode, rootNode, rootNode.getChildCount());
                for (int i = 0; entity.getFileGroupList() != null
                        && i < entity.getFileGroupList().size(); i++) {
                    addIntellectualEntity(childNode, entity.getFileGroupList().get(i), false);
                }
            }
        }
    }
    // When the Swing Worker is used, expanding the leaf nodes has been moved to the end of the IE building process. Now located in the Swing Worker's Done() method.
    if (buildIE_Worker == null) {
        expandNode(theEntityTree, rootNode, true);
    }
    updateWorkerProgress(60);
    theEntityTree.repaint();
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

public void addStructMapItem(StructMap structMapItem, DefaultMutableTreeNode rootNode, boolean editEntry) {
    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();
    newNode.setUserObject(structMapItem);
    DepositTreeModel model = (DepositTreeModel) theStructMapTree.getModel();
    model.insertNodeInto(newNode, rootNode, rootNode.getChildCount());
    for (int i = 0; structMapItem.getChildren() != null && i < structMapItem.getChildren().size(); i++) {
        addStructMapItem(structMapItem.getChildren().get(i), newNode, false);
    }/*  ww  w .  j  av a  2s.co m*/
    for (int i = 0; structMapItem.getFiles() != null && i < structMapItem.getFiles().size(); i++) {
        DefaultMutableTreeNode newFileNode = new DefaultMutableTreeNode();
        newFileNode.setUserObject(structMapItem.getFiles().get(i));
        model.insertNodeInto(newFileNode, newNode, newNode.getChildCount());
    }
    TreePath newPath = new TreePath(newNode.getPath());
    theStructMapTree.scrollPathToVisible(newPath);
    theStructMapTree.setSelectionPath(newPath);
    if (editEntry) {
        editStructMap();
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

public void addFileToStructMap(FileSystemObject fso, DefaultMutableTreeNode rootNode, int nodeIndex,
        boolean editEntry) {
    // Assumes that the structure has already been created - this is just UI
    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();
    newNode.setUserObject(fso);
    DepositTreeModel model = (DepositTreeModel) theStructMapTree.getModel();
    // The specified index is now passed to insertNodeInto, to put the newNode into the correct position
    //model.insertNodeInto(newNode, rootNode, rootNode.getChildCount());
    model.insertNodeInto(newNode, rootNode, nodeIndex);
    TreePath newPath = new TreePath(newNode.getPath());
    theStructMapTree.scrollPathToVisible(newPath);
    theStructMapTree.setSelectionPath(newPath);
    if (editEntry) {
        editStructMap();// ww  w  .j  a  v  a 2s .c  o m
    }
}