Example usage for javax.swing.tree DefaultMutableTreeNode getFirstChild

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

Introduction

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

Prototype

public TreeNode getFirstChild() 

Source Link

Document

Returns this node's first child.

Usage

From source file:FileTree2.java

public boolean expand(DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode flag = (DefaultMutableTreeNode) parent.getFirstChild();
    if (flag == null) // No flag
        return false;
    Object obj = flag.getUserObject();
    if (!(obj instanceof Boolean))
        return false; // Already expanded

    parent.removeAllChildren(); // Remove Flag

    File[] files = listFiles();/*ww  w .  j  a  va  2 s .  c  o  m*/
    if (files == null)
        return true;

    Vector v = new Vector();

    for (int k = 0; k < files.length; k++) {
        File f = files[k];
        if (!(f.isDirectory()))
            continue;

        FileNode newNode = new FileNode(f);

        boolean isAdded = false;
        for (int i = 0; i < v.size(); i++) {
            FileNode nd = (FileNode) v.elementAt(i);
            if (newNode.compareTo(nd) < 0) {
                v.insertElementAt(newNode, i);
                isAdded = true;
                break;
            }
        }
        if (!isAdded)
            v.addElement(newNode);
    }

    for (int i = 0; i < v.size(); i++) {
        FileNode nd = (FileNode) v.elementAt(i);
        IconData idata = new IconData(FileTree2.ICON_FOLDER, FileTree2.ICON_EXPANDEDFOLDER, nd);
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(idata);
        parent.add(node);

        if (nd.hasSubDirs())
            node.add(new DefaultMutableTreeNode(new Boolean(true)));
    }

    return true;
}

From source file:FileTree3.java

public boolean expand(DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode flag = (DefaultMutableTreeNode) parent.getFirstChild();
    if (flag == null) // No flag
        return false;
    Object obj = flag.getUserObject();
    if (!(obj instanceof Boolean))
        return false; // Already expanded

    parent.removeAllChildren(); // Remove Flag

    File[] files = listFiles();//from   w  w w  .j av  a2  s . c o  m
    if (files == null)
        return true;

    Vector v = new Vector();

    for (int k = 0; k < files.length; k++) {
        File f = files[k];
        if (!(f.isDirectory()))
            continue;

        FileNode newNode = new FileNode(f);

        boolean isAdded = false;
        for (int i = 0; i < v.size(); i++) {
            FileNode nd = (FileNode) v.elementAt(i);
            if (newNode.compareTo(nd) < 0) {
                v.insertElementAt(newNode, i);
                isAdded = true;
                break;
            }
        }
        if (!isAdded)
            v.addElement(newNode);
    }

    for (int i = 0; i < v.size(); i++) {
        FileNode nd = (FileNode) v.elementAt(i);
        IconData idata = new IconData(FileTree3.ICON_FOLDER, FileTree3.ICON_EXPANDEDFOLDER, nd);
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(idata);
        parent.add(node);

        if (nd.hasSubDirs())
            node.add(new DefaultMutableTreeNode(new Boolean(true)));
    }

    return true;
}

From source file:com.pironet.tda.SunJDKParser.java

private void reNormalizeBlockingThreadTree(final MonitorMap mmap,
        final Map<String, DefaultMutableTreeNode> directChildMap) {
    Map<String, DefaultMutableTreeNode> allBlockingThreadsMap = new HashMap<>(directChildMap); // All threads that are blocking at least one other thread

    // First, re-normalize based on monitors to get our unique tree
    // Tree will be unique as long as there are no deadlocks aka monitor loops
    for (Iterator iter = mmap.iterOfKeys(); iter.hasNext();) {
        String monitor1 = (String) iter.next();
        Map<String, String>[] threads1 = mmap.getFromMonitorMap(monitor1);

        final DefaultMutableTreeNode thread1Node = allBlockingThreadsMap.get(monitor1);
        if (thread1Node == null) {
            continue;
        }//from w w w .j  a  v a2 s.c  o m

        // Get information on the one thread holding this lock
        Iterator it = threads1[MonitorMap.LOCK_THREAD_POS].keySet().iterator();
        if (!it.hasNext()) {
            continue;
        }
        String threadLine1 = (String) it.next();

        for (Iterator iter2 = mmap.iterOfKeys(); iter2.hasNext();) {
            String monitor2 = (String) iter2.next();
            if (monitor1 == monitor2) {
                continue;
            }

            Map<String, String>[] threads2 = mmap.getFromMonitorMap(monitor2);
            if (threads2[MonitorMap.WAIT_THREAD_POS].containsKey(threadLine1)) {
                // Get the node of the thread that is holding this lock
                DefaultMutableTreeNode thread2Node = (DefaultMutableTreeNode) allBlockingThreadsMap
                        .get(monitor2);
                // Get the node of the monitor itself
                DefaultMutableTreeNode monitor2Node = (DefaultMutableTreeNode) thread2Node.getFirstChild();

                // If a redundant node for thread2 exists with no children, remove it
                // To compare, we have to remove "Thread - " from the front of display strings
                for (int i = 0; i < monitor2Node.getChildCount(); i++) {
                    DefaultMutableTreeNode child2 = (DefaultMutableTreeNode) monitor2Node.getChildAt(i);
                    if (child2.toString().substring(9).equals(threadLine1) && child2.getChildCount() == 0) {
                        monitor2Node.remove(i);
                        break;
                    }
                }

                // Thread1 is blocked by monitor2 held by thread2, so move thread1 under thread2
                monitor2Node.insert(thread1Node, 0);
                directChildMap.remove(monitor1);
                break;
            }
        }
    }

    allBlockingThreadsMap.clear();

    // Second, re-normalize top level based on threads for cases where one thread holds multiple monitors
    boolean changed;
    do {
        changed = false;
        for (final Object o : directChildMap.entrySet()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((Map.Entry) o).getValue();
            if (checkForDuplicateThreadItem(directChildMap, node)) {
                changed = true;
                break;
            }
        }
    } while (changed);

    // Third, renormalize lower levels of the tree based on threads for cases where one thread holds multiple monitors
    for (final Object o : directChildMap.entrySet()) {
        renormalizeThreadDepth((DefaultMutableTreeNode) ((Map.Entry) o).getValue());
    }
}

From source file:com.pironet.tda.SunJDKParser.java

private void renormalizeMonitorDepth(DefaultMutableTreeNode monitorNode, int index) {
    // First, remove all duplicates of the item at index "index"
    DefaultMutableTreeNode threadNode1 = (DefaultMutableTreeNode) monitorNode.getChildAt(index);
    ThreadInfo mi1 = (ThreadInfo) threadNode1.getUserObject();
    int i = index + 1;
    while (i < monitorNode.getChildCount()) {
        DefaultMutableTreeNode threadNode2 = (DefaultMutableTreeNode) monitorNode.getChildAt(i);
        ThreadInfo mi2 = (ThreadInfo) threadNode2.getUserObject();
        if (mi1.getName().equals(mi2.getName())) {
            if (threadNode2.getChildCount() > 0) {
                threadNode1.add((DefaultMutableTreeNode) threadNode2.getFirstChild());
                monitorNode.remove(i);//from  w w  w. j a  v  a 2  s . co m
                continue;
            }
        }
        i++;
    }

    // Second, recurse into item "index"
    renormalizeThreadDepth(threadNode1);
}

From source file:com.pironet.tda.SunJDKParser.java

private boolean checkForDuplicateThreadItem(Map directChildMap, DefaultMutableTreeNode node1) {
    ThreadInfo mi1 = (ThreadInfo) node1.getUserObject();
    String name1 = mi1.getName();

    for (Iterator iter2 = directChildMap.entrySet().iterator(); iter2.hasNext();) {
        DefaultMutableTreeNode node2 = (DefaultMutableTreeNode) ((Map.Entry) iter2.next()).getValue();
        if (node1 == node2) {
            continue;
        }//from w  ww.  j av a 2  s  . c  o m

        ThreadInfo mi2 = (ThreadInfo) node2.getUserObject();
        if (name1.equals(mi2.getName()) && node2.getChildCount() > 0) {
            node1.add((MutableTreeNode) node2.getFirstChild());
            iter2.remove();
            return true;
        }
    }

    return false;
}

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

@Override
public void treeExpanded(TreeExpansionEvent event) {
    if (treeInProgress)
        return;/*  w ww .j  a  v a2 s  .  c  o m*/
    setBusy(true);

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode) node.getFirstChild();
    TreePath selectionPath = tree.getSelectionPath();
    if (MUST_LOAD_CHILDREN.equals(firstChild.getUserObject())) {

        node.removeAllChildren();
        DocPath expandPath = new DocPath();

        for (Object obj : node.getUserObjectPath()) {
            try {
                expandPath.add((DocNodeBase) obj);
            } catch (ClassCastException ex) {
                expandPath.add(new DocNodeLiteral(obj.toString()));
            }
        }

        List<DocNodeBase> childList;
        try {
            childList = DelegateFactory.getInstance().getJCRDocDelegate()
                    .getDocNodeChildrenFromNode(expandPath);
            setDocNodesOnTree(node, childList, expandPath);
        } catch (Throwable e) {
            treeModel.insertNodeInto(new DefaultMutableTreeNode(e), node, 0);
        }
        tree.expandPath(new TreePath(node.getPath()));
        tree.setSelectionPath(selectionPath);
    }
    setBusy(false);
}

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);//w  w w .  j  a v  a 2  s  .  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.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);
                }//from  ww w . j  a va  2  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")) {
                            // 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  ww. j a  v a  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);
                }
            });
        }
    }
}