Example usage for javax.swing.tree TreePath TreePath

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

Introduction

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

Prototype

public TreePath(Object lastPathComponent) 

Source Link

Document

Creates a TreePath containing a single element.

Usage

From source file:it.imtech.metadata.MetaUtility.java

/**
 * Aggiunge il pannello delle classificazioni all'interfaccia dei metadati
 *
 * @param innerPanel Pannello sul quale aggiungere i metadati
 * @param kv Valori dei metadati/*from w  w  w .  j  a v a  2  s.  c o m*/
 */
private void addClassification(JPanel innerPanel, Integer kv, final String sequence, final String panelname)
        throws Exception {
    try {
        ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE,
                Globals.loader);

        DefaultMutableTreeNode hierarchy = new DefaultMutableTreeNode("root");
        selected = null;
        String selectedPath = "";

        String link = selectedClassificationList.get(panelname + "---" + sequence);

        recursiveOefosTreeviewBuild(hierarchy, oefos.get(link), sequence, panelname);
        DefaultTreeModel model = new DefaultTreeModel(hierarchy);

        final JTree tree = new JTree(model);
        tree.setRootVisible(false);

        if (selected != null) {
            TreePath selpath = new TreePath(selected.getPath());
            tree.setSelectionPath(selpath);

            Object[] nodes = selpath.getPath();

            for (int i = 1; i < nodes.length; i++) {
                selectedPath += nodes[i].toString();
                selectedPath += (i != nodes.length - 1) ? "/" : "";
            }
        }

        tree.setName("MID_" + Integer.toString(kv) + "---" + sequence);
        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

        tree.addTreeSelectionListener(new TreeSelectionListener() {

            public void valueChanged(TreeSelectionEvent e) {
                try {
                    setOEFOS(tree, sequence, panelname);
                } catch (Exception ex) {
                    logger.error(ex.getMessage());
                }
            }
        });

        javax.swing.JScrollPane tree_scroller = new javax.swing.JScrollPane();
        tree_scroller
                .setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        tree_scroller.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        tree_scroller.setViewportView(tree);
        tree_scroller.setBorder(null);

        innerPanel.add(tree_scroller, "wrap, width 100:800:800");

        JPanel iPanel = new JPanel(new MigLayout());
        iPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
                Utility.getBundleString("choose2", bundle), TitledBorder.LEFT, TitledBorder.TOP));
        JLabel label = new JLabel();
        label.setName("classification_path" + "---" + sequence);
        label.setText(selectedPath);
        iPanel.add(label, "wrap, growx, height 30:30:30");

        innerPanel.add(iPanel, "wrap, width 100:800:800");

        findLastClassification(panelname);

    } catch (Exception ex) {
        logger.error(ex.getMessage());
        throw new Exception("Exception in addClassification: " + ex.getStackTrace() + "\n");
    }
}

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

private List getConceptsFromTerm(QueryConceptTreeNodeData data, DefaultMutableTreeNode tmpnode) {

    // QueryConceptTreeNodeData data = (QueryConceptTreeNodeData)
    // node.getUserObject();
    try {//from  ww  w  . j av a  2  s.c  o m
        GetTermInfoType parentType = new GetTermInfoType();

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

        parentType.setMax(parentPanel.max_child());

        parentType.setBlob(true);

        parentType.setSelf(data.fullname());
        GetChildrenResponseMessage msg = new GetChildrenResponseMessage();
        StatusType procStatus = null;
        String response = OntServiceDriver.getTermInfo(parentType, "");
        procStatus = msg.processResult(response);
        int result;
        if (procStatus.getValue().equals("MAX_EXCEEDED") && tmpnode != null) {
            result = JOptionPane.showConfirmDialog(parentPanel,
                    "The node has exceeded maximum number of children.\n" + "Do you want to continue?",
                    "Please note ...", JOptionPane.YES_NO_OPTION);

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

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

        ConceptsType allConcepts = msg.doReadConcepts();
        return allConcepts.getConcept();

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

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

private void deleteSelectedNode(boolean codeTemplate) {
    stopTableEditing();/*from w w  w.  j  a  va  2s. c o  m*/
    setSaveEnabled(true);
    TreePath selectedPath = templateTreeTable.getTreeSelectionModel().getSelectionPath();

    if (selectedPath != null) {
        CodeTemplateTreeTableModel model = (CodeTemplateTreeTableModel) templateTreeTable.getTreeTableModel();
        MutableTreeTableNode selectedNode = (MutableTreeTableNode) selectedPath.getLastPathComponent();
        MutableTreeTableNode parent = (MutableTreeTableNode) selectedNode.getParent();
        int selectedNodeIndex = parent.getIndex(selectedNode);
        MutableTreeTableNode newSelectedNode = null;

        if (!codeTemplate && selectedNode.getChildCount() > 0) {
            if (!this.parent.alertOkCancel(this.parent, "The selected library contains "
                    + selectedNode.getChildCount()
                    + " code templates. If you delete the library, the code templates will be deleted as well. Are you sure you wish to continue?")) {
                return;
            }

            for (MutableTreeTableNode codeTemplateNode : Collections.list(selectedNode.children())) {
                model.removeNodeFromParent(codeTemplateNode);

                if (model.getRoot() != fullModel.getRoot()) {
                    AbstractSortableTreeTableNode fullCodeTemplateNode = findFullNode(
                            (AbstractSortableTreeTableNode) codeTemplateNode);
                    fullModel.removeNodeFromParent(fullCodeTemplateNode);
                }
            }
        }

        updateCurrentNode.set(false);
        selectedNode = (MutableTreeTableNode) selectedPath.getLastPathComponent();
        model.removeNodeFromParent(selectedNode);

        if (model.getRoot() != fullModel.getRoot()) {
            fullModel.removeNodeFromParent(findFullNode((AbstractSortableTreeTableNode) selectedNode));
        }

        if (selectedNodeIndex < parent.getChildCount()) {
            newSelectedNode = (MutableTreeTableNode) parent.getChildAt(selectedNodeIndex);
        } else if (parent.getChildCount() > 0) {
            newSelectedNode = (MutableTreeTableNode) parent.getChildAt(parent.getChildCount() - 1);
        } else if (codeTemplate) {
            newSelectedNode = parent;
        }

        if (newSelectedNode != null) {
            final TreePath newSelectedPath = new TreePath(
                    ((CodeTemplateTreeTableModel) templateTreeTable.getTreeTableModel())
                            .getPathToRoot(newSelectedNode));
            selectTemplatePath(newSelectedPath);

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    selectTemplatePath(newSelectedPath);
                    updateCurrentNode.set(true);
                }
            });
        } else {
            switchSplitPaneComponent(blankPanel);
            updateCurrentNode.set(true);
        }

        updateFilterNotification();
    }
}

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

private List getConceptsFromChildren(QueryConceptTreeNodeData data, DefaultMutableTreeNode tmpnode) {

    //      QueryConceptTreeNodeData data = (QueryConceptTreeNodeData) node.getUserObject();
    try {//from  w  w  w .  ja v  a 2s  .c o m
        GetChildrenType parentType = new GetChildrenType();

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

        parentType.setMax(parentPanel.max_child());

        parentType.setBlob(true);

        parentType.setParent(data.fullname());
        GetChildrenResponseMessage msg = new GetChildrenResponseMessage();
        StatusType procStatus = null;
        String response = OntServiceDriver.getChildren(parentType, "");
        procStatus = msg.processResult(response);
        int result;
        if (procStatus.getValue().equals("MAX_EXCEEDED") && tmpnode != null) {
            result = JOptionPane.showConfirmDialog(parentPanel,
                    "The node has exceeded maximum number of children.\n" + "Do you want to continue?",
                    "Please note ...", JOptionPane.YES_NO_OPTION);

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

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

        ConceptsType allConcepts = msg.doReadConcepts();
        return allConcepts.getConcept();

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

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

private List getConceptsFromChildren(QueryConceptTreeNodeData data, DefaultMutableTreeNode tmpnode) {

    // QueryConceptTreeNodeData data = (QueryConceptTreeNodeData)
    // node.getUserObject();
    try {//from w w  w .ja  va 2s . com
        GetChildrenType parentType = new GetChildrenType();

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

        parentType.setMax(parentPanel.max_child());

        parentType.setBlob(true);

        parentType.setParent(data.fullname());
        GetChildrenResponseMessage msg = new GetChildrenResponseMessage();
        StatusType procStatus = null;
        String response = OntServiceDriver.getChildren(parentType, "");
        procStatus = msg.processResult(response);
        int result;
        if (procStatus.getValue().equals("MAX_EXCEEDED") && tmpnode != null) {
            result = JOptionPane.showConfirmDialog(parentPanel,
                    "The node has exceeded maximum number of children.\n" + "Do you want to continue?",
                    "Please note ...", JOptionPane.YES_NO_OPTION);

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

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

        ConceptsType allConcepts = msg.doReadConcepts();
        return allConcepts.getConcept();

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

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

private void populateChildNodes(DefaultMutableTreeNode node) {

    List concepts = getConceptsFromChildren((QueryConceptTreeNodeData) node.getUserObject(),
            (DefaultMutableTreeNode) node.getChildAt(0));
    if (concepts != null) {
        addNodesFromOntXML(concepts, node);
        DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) node.getChildAt(0);
        treeModel.removeNodeFromParent(tmpnode);
        jTree1.scrollPathToVisible(new TreePath(node.getPath()));
    }//from ww w.  j av  a 2 s .c  om

}

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

@Action
    public void addService() throws DocumentException {
        // ?  ?  ?     ?,  
        String serviceName = "";
        boolean flag = true;
        while (flag) {
            serviceName = (String) JOptionPane.showInputDialog(this,
                    getLocaleMessage("admin.add_service_dialog.title"),
                    getLocaleMessage("admin.add_service_dialog.caption"), 3, null, null, serviceName);
            if (serviceName == null) {
                return;
            }/*from  www.j av  a  2s. c om*/
            if ("".equals(serviceName)) {
                JOptionPane.showConfirmDialog(this, getLocaleMessage("admin.add_service_dialog.err1.title"),
                        getLocaleMessage("admin.add_service_dialog.err1.caption"), JOptionPane.DEFAULT_OPTION,
                        JOptionPane.ERROR_MESSAGE);
            } else if (QServiceTree.getInstance().hasByName(serviceName)) {
                JOptionPane.showConfirmDialog(this, getLocaleMessage("admin.add_service_dialog.err2.title"),
                        getLocaleMessage("admin.add_service_dialog.err2.caption"), JOptionPane.DEFAULT_OPTION,
                        JOptionPane.ERROR_MESSAGE);
            } else if (serviceName.indexOf('\"') != -1) {
                JOptionPane.showConfirmDialog(this, getLocaleMessage("admin.add_service_dialog.err3.title"),
                        getLocaleMessage("admin.add_service_dialog.err2.caption"), JOptionPane.DEFAULT_OPTION,
                        JOptionPane.ERROR_MESSAGE);
            } else if (serviceName.length() > 2001) {
                JOptionPane.showConfirmDialog(this, getLocaleMessage("admin.add_service_dialog.err4.title"),
                        getLocaleMessage("admin.add_service_dialog.err2.caption"), JOptionPane.DEFAULT_OPTION,
                        JOptionPane.ERROR_MESSAGE);
            } else {
                flag = false;
            }
        }
        //   ?     
        final QService newService = new QService();
        newService.setName(serviceName);
        newService.setDescription(serviceName);
        newService.setStatus(1);
        newService.setSoundTemplate("021111");
        newService.setAdvanceTimePeriod(60);
        newService.setCalendar(QCalendarList.getInstance().getById(1));
        if (QScheduleList.getInstance().getSize() != 0) {
            newService.setSchedule(QScheduleList.getInstance().getElementAt(0));
        }
        newService.setButtonText(
                "<html><b><p align=center><span style='font-size:20.0pt;color:red'>" + serviceName + "</span></b>");
        //? 
        newService.setPrefix("A");
        QServiceTree.sailToStorm(QServiceTree.getInstance().getRoot(), (TreeNode service) -> {
            if (service.isLeaf()) {
                String pr = ((QService) service).getPrefix();
                if (!pr.isEmpty()) {
                    if (pr.substring(pr.length() - 1).compareToIgnoreCase(
                            newService.getPrefix().substring(newService.getPrefix().length() - 1)) >= 0) {
                        newService.setPrefix(
                                String.valueOf((char) (pr.substring(pr.length() - 1).charAt(0) + 1)).toUpperCase());
                    }
                }
            }
        });

        final QService parentService = (QService) treeServices.getLastSelectedPathComponent();
        QServiceTree.getInstance().insertNodeInto(newService, parentService, parentService.getChildCount());
        final TreeNode[] nodes = QServiceTree.getInstance().getPathToRoot(newService);
        final TreePath path = new TreePath(nodes);
        treeServices.scrollPathToVisible(path);
        treeServices.setSelectionPath(path);
        // ? ?   ?  ?  ?? ?  , ..  ? 
        deleteServiceFromUsers(parentService);

        QLog.l().logger().debug(" ? \"" + serviceName + "\"   \""
                + parentService.getName() + "\"");
    }

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

@Action
    public void deleteService() {
        final QService service = (QService) treeServices.getLastSelectedPathComponent();
        if (service != null && !service.isRoot()) {
            if (JOptionPane.showConfirmDialog(this,
                    getLocaleMessage("admin.remove_service_dialog.title") + " "
                            + (service.isLeaf() ? getLocaleMessage("admin.remove_service_dialog.title_1")
                                    : getLocaleMessage("admin.remove_service_dialog.title_2"))
                            + "\n\""
                            + (service.getName().length() > 85 ? service.getName().substring(0, 85) + " ..."
                                    : service.getName())
                            + "\"?",
                    getLocaleMessage("admin.remove_service_dialog.caption"), JOptionPane.YES_NO_OPTION) == 1) {
                return;
            }//from  w w w . j av a2 s. c om
            //  ? ? ?  
            deleteServicesFromUsers(service);
            //  ? ?
            final int del = service.getParent().getIndex(service);
            final int col = service.getParent().getChildCount();
            ((QServiceTree) treeServices.getModel()).removeNodeFromParent(service);
            //   ?  
            if (col == 1) {
                treeServices.setSelectionPath(
                        new TreePath(((QServiceTree) treeServices.getModel()).getPathToRoot(service.getParent())));
            } else if (col == del + 1) {
                treeServices.setSelectionPath(new TreePath(((QServiceTree) treeServices.getModel())
                        .getPathToRoot(service.getParent().getChildAt(del - 1))));
            } else if (col > del + 1) {
                treeServices.setSelectionPath(new TreePath(((QServiceTree) treeServices.getModel())
                        .getPathToRoot(service.getParent().getChildAt(del))));
            }
            QLog.l().logger().debug(" ? \"" + service.getName() + "\"   \""
                    + service.getParent().getName() + "\"");
        }
    }

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

@Action
    public void addInfoItem() {
        // ?    ?     ?,  
        String infoName = getLocaleMessage("admin.add_info_dialog.info");
        boolean flag = true;
        while (flag) {
            infoName = (String) JOptionPane.showInputDialog(this, getLocaleMessage("admin.add_info_dialog.title"),
                    getLocaleMessage("admin.add_info_dialog.caption"), 3, null, null, infoName);
            if (infoName == null) {
                return;
            }/* www  .  j a va  2s. com*/
            if ("".equals(infoName)) {
                JOptionPane.showConfirmDialog(this, getLocaleMessage("admin.add_info_dialog.err1.title"),
                        getLocaleMessage("admin.add_info_dialog.err1.caption"), JOptionPane.DEFAULT_OPTION,
                        JOptionPane.ERROR_MESSAGE);
            } else if (infoName.indexOf('\"') != -1) {
                JOptionPane.showConfirmDialog(this, getLocaleMessage("admin.add_info_dialog.err2.title"),
                        getLocaleMessage("admin.add_info_dialog.err2.caption"), JOptionPane.DEFAULT_OPTION,
                        JOptionPane.ERROR_MESSAGE);
            } else if (infoName.length() > 100) {
                JOptionPane.showConfirmDialog(this, getLocaleMessage("admin.add_info_dialog.err3.title"),
                        getLocaleMessage("admin.add_info_dialog.err3.caption"), JOptionPane.DEFAULT_OPTION,
                        JOptionPane.ERROR_MESSAGE);
            } else {
                flag = false;
            }
        }
        //   ?     
        final QInfoItem newItem = new QInfoItem();
        newItem.setName(infoName);
        newItem.setHTMLText(
                "<html><b><p align=center><span style='font-size:20.0pt;color:green'>" + infoName + "</span></b>");
        newItem.setTextPrint("");
        final QInfoItem parentItem = (QInfoItem) treeInfo.getLastSelectedPathComponent();
        ((QInfoTree) treeInfo.getModel()).insertNodeInto(newItem, parentItem, parentItem.getChildCount());
        final TreeNode[] nodes = ((QInfoTree) treeInfo.getModel()).getPathToRoot(newItem);
        final TreePath path = new TreePath(nodes);
        treeInfo.scrollPathToVisible(path);
        treeInfo.setSelectionPath(path);
        textFieldInfoItemName.setEnabled(true);
        //textPaneInfoItem.setEnabled(true);
        //textPaneInfoPrint.setEnabled(true);

        QLog.l().logger().debug("  \"" + infoName + "\"   \""
                + parentItem.getName() + "\"");
    }

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

@Action
    public void deleteInfoItem() {
        final QInfoItem item = (QInfoItem) treeInfo.getLastSelectedPathComponent();
        if (item != null && !item.isRoot()) {
            if (JOptionPane.showConfirmDialog(this, getLocaleMessage("admin.remove_info_dialog.title") + " "
                    + (item.isLeaf() ? getLocaleMessage("admin.remove_info_dialog.title_1")
                            : getLocaleMessage("admin.remove_info_dialog.title_2"))
                    + "\""
                    + (item.getName().length() > 85 ? item.getName().substring(0, 85) + " ..." : item.getName())
                    + "\"?", getLocaleMessage("admin.remove_info_dialog.caption"),
                    JOptionPane.YES_NO_OPTION) == 1) {
                return;
            }/*  ww w.jav a  2s  .  c o m*/
            //  ? 
            final int del = item.getParent().getIndex(item);
            final int col = item.getParent().getChildCount();
            QInfoTree.getInstance().removeNodeFromParent(item);
            //     
            if (col == 1) {
                treeInfo.setSelectionPath(
                        new TreePath(((QInfoTree) treeInfo.getModel()).getPathToRoot(item.getParent())));
            } else if (col == del + 1) {
                treeInfo.setSelectionPath(new TreePath(
                        ((QInfoTree) treeInfo.getModel()).getPathToRoot(item.getParent().getChildAt(del - 1))));
            } else if (col > del + 1) {
                treeInfo.setSelectionPath(new TreePath(
                        ((QInfoTree) treeInfo.getModel()).getPathToRoot(item.getParent().getChildAt(del))));
            }
            QLog.l().logger().debug("  \"" + item.getName() + "\"   \""
                    + item.getParent().getName() + "\"");
        }
    }