Example usage for javax.swing.tree TreePath getLastPathComponent

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

Introduction

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

Prototype

public Object getLastPathComponent() 

Source Link

Document

Returns the last element of this path.

Usage

From source file:org.zaproxy.zap.extension.history.PopupMenuExportSelectedURLs.java

private SortedSet<String> getOutputSet(TreePath[] startingPoints) {
    JTree siteTree = extension.getView().getSiteTreePanel().getTreeSite();
    ArrayList<TreePath> startingPts = new ArrayList<TreePath>();

    if (ArrayUtils.isEmpty(startingPoints)) {
        startingPts.add(new TreePath(siteTree.getModel().getRoot()));
    } else {/* w w  w  .  ja va2 s . c om*/
        startingPts.addAll(Arrays.asList(startingPoints));
    }

    SortedSet<String> outputSet = new TreeSet<String>();
    for (TreePath aPath : startingPts) {
        Enumeration<?> en = (((SiteNode) aPath.getLastPathComponent()).preorderEnumeration());
        while (en.hasMoreElements()) {
            SiteNode node = (SiteNode) en.nextElement();
            if (node.isRoot()) {
                continue;
            }
            HistoryReference nodeHR = node.getHistoryReference();
            if (nodeHR != null && !HistoryReference.getTemporaryTypes().contains(nodeHR.getHistoryType())) {
                outputSet.add(nodeHR.getURI().toString());
            }
        }
    }
    return outputSet;
}

From source file:pcgen.gui2.tabs.CompanionInfoTab.java

private void selectCompanion(CompanionFacade compFacade) {
    TreeTableModel treeTableModel = companionsTable.getTreeTableModel();
    treeTableModel.getRoot();//from   w  w  w. j  a v a 2  s  .  com
    TreePath path = null;

    JTree tree = companionsTable.getTree();
    String companionType = compFacade.getCompanionType();
    for (int i = 0; i < tree.getRowCount(); i++) {
        TreePath pathForRow = tree.getPathForRow(i);
        Object lastPathComponent = pathForRow.getLastPathComponent();
        if (lastPathComponent.toString().startsWith(companionType)) {
            tree.expandRow(i);
        } else if (lastPathComponent instanceof pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) {
            CompanionFacade rowComp = (CompanionFacade) ((pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) lastPathComponent)
                    .getValueAt(0);

            if (rowComp != null && rowComp.getFileRef().get() == compFacade.getFileRef().get()
                    && rowComp.getNameRef().get() == compFacade.getNameRef().get()
                    && rowComp.getRaceRef().get() == compFacade.getRaceRef().get()) {
                path = pathForRow;
            }
        }
    }
    if (path != null) {
        companionsTable.getTree().setSelectionPath(path);
        companionsTable.getTree().scrollPathToVisible(path);
    }
}

From source file:pcgen.gui2.tabs.spells.SpellBooksTab.java

/**
 * Identify the current spell book, being the spell book that spells should
 * be added to. If no books exist then return an empty string.
 *
 * @return The name of the 'current' spell book, or empty string if none
 *         exist.//from w  ww  .j  av  a  2 s .c om
 */
String getCurrentSpellBookName() {
    String spellList = "";
    Object selectedObject = selectedTable.getSelectedObject();
    if (selectedObject != null) {
        if (selectedObject instanceof SpellNode) {
            spellList = ((SpellNode) selectedObject).getRootNode().getName();
        } else if (selectedObject instanceof RootNode) {
            spellList = ((RootNode) selectedObject).getName();
        } else {
            JTree tree = selectedTable.getTree();
            TreePath path = tree.getSelectionPath();
            while (path.getParentPath() != null && (path.getParentPath().getParentPath() != null)) {
                path = path.getParentPath();
            }
            spellList = path.getLastPathComponent().toString();
        }
    }
    if (StringUtils.isEmpty(spellList)) {
        ListFacade<?> data = selectedTable.getTreeViewModel().getDataModel();
        if (!data.isEmpty()) {
            Object firstElem = data.getElementAt(0);
            if (firstElem instanceof SpellNode) {
                spellList = ((SpellNode) firstElem).getRootNode().getName();
            }
        }
    }
    return spellList;
}

From source file:pcgen.gui2.tabs.spells.SpellsPreparedTab.java

/**
 * Identify the current spell list, being the spell list that spell should
 * be added to. If no lists exist then a default one will be created.
 *
 * @param character The character qwe are checking for.
 * @return The name of the 'current' spell list.
 *//* w  ww. j av  a  2s .  c om*/
String getCurrentSpellListName(CharacterFacade character) {
    String spellList = "";
    Object selectedObject = selectedTable.getSelectedObject();
    if (selectedObject != null) {
        if (selectedObject instanceof SpellNode) {
            spellList = ((SpellNode) selectedObject).getRootNode().toString();
        } else {
            JTree tree = selectedTable.getTree();
            TreePath path = tree.getSelectionPath();
            while (path.getParentPath() != null && (path.getParentPath().getParentPath() != null)) {
                path = path.getParentPath();
            }
            spellList = path.getLastPathComponent().toString();
        }
    }
    if (StringUtils.isEmpty(spellList)) {
        spellList = spellListField.getText();
    }
    if (StringUtils.isEmpty(spellList)) {
        ListFacade<?> data = selectedTable.getTreeViewModel().getDataModel();
        if (!data.isEmpty()) {
            Object firstElem = data.getElementAt(0);
            if (firstElem instanceof SpellNode) {
                spellList = ((SpellNode) firstElem).getRootNode().toString();
            }
        }
    }
    if (StringUtils.isEmpty(spellList)) {
        // No lists exist, so create a default one!
        spellList = "Prepared Spells";
        character.getSpellSupport().addSpellList(spellList);
    }
    return spellList;
}

From source file:phex.gui.tabs.library.LibraryTab.java

private LibraryNode getSelectedTreeComponent() {
    TreePath path = mainTree.getSelectionPath();
    if (path == null) {
        return null;
    }//  w ww  . jav  a  2s .  c  om
    LibraryNode node = (LibraryNode) path.getLastPathComponent();
    return node;
}

From source file:phex.gui.tabs.library.LibraryTreePane.java

public LibraryNode getSelectedTreeComponent() {
    TreePath path = mainTree.getSelectionPath();
    if (path == null) {
        return null;
    }/*from   www.j  ava  2  s  .co  m*/
    LibraryNode node = (LibraryNode) path.getLastPathComponent();
    return node;
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

/**
 * @return ArrayList<String> with selected items in the tree
 *//*from   w w w . j a  va 2  s. co  m*/
private ArrayList<String> getSelectedLocalFiles() {
    ArrayList<String> files = new ArrayList<String>();

    TreePath path = jTreeResults.getSelectionPath();

    // Tree Root is not permited
    if (path == null || path.getPathCount() < 2) {
        return null;
    }

    jTreeResults.expandPath(path);

    if (path != null) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();

        // recieves all childs
        ArrayList<DefaultMutableTreeNode> childs = getLocalLeafs(node, path);

        Iterator<DefaultMutableTreeNode> it = childs.iterator();

        // converts TreeNodes to filePaths
        while (it.hasNext()) {
            Object obj = it.next().getUserObject();

            if (SearchResult.class.isInstance(obj)) {
                files.add(obj.toString());
            }
        }
    }

    return files;
}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

private void addMouseDoubleClickListener() {
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            job(e, true);/*w w w.ja v a  2 s . co  m*/
        }

        public void mouseReleased(MouseEvent e) {
            job(e, false);
        }

        private void job(MouseEvent e, boolean pressed) {
            if (e.isPopupTrigger() || (e.getClickCount() == 2)) {
                final TreePath selPath = getPathForLocation(e.getX(), e.getY());
                if (selPath == null) {
                    return;
                }
                setSelectionPath(selPath);
                try {
                    final DBBrowserNode selectedNode = (DBBrowserNode) selPath.getLastPathComponent();
                    if (selectedNode != null) {
                        if (selectedNode.getDBObject().getType() == DBObject.DATASOURCE) {
                            selectionDataSource(e);
                        } else if (selectedNode.getDBObject().getType() == DBObject.QUERIES_GROUP) {
                            selectionQueryGroup(selectedNode, e);
                        } else if (selectedNode.getDBObject().getType() == DBObject.QUERIES) {
                            selectionQuery(selectedNode, e, pressed);
                        } else if (selectedNode.getDBObject().getType() == DBObject.REPORTS_GROUP) {
                            selectionReportGroup(selectedNode, e);
                        } else if (selectedNode.getDBObject().getType() == DBObject.REPORTS) {
                            selectionReport(selectedNode, e, pressed);
                        } else if (selectedNode.getDBObject().getType() == DBObject.CHARTS_GROUP) {
                            selectionChartGroup(selectedNode, e);
                        } else if (selectedNode.getDBObject().getType() == DBObject.CHARTS) {
                            selectionChart(selectedNode, e, pressed);
                        } else if (selectedNode.getDBObject().getType() == DBObject.DATABASE) {
                            selectionDatabase(selPath, selectedNode, e);
                        } else if ((selectedNode.getDBObject().getType() == DBObject.TABLE)
                                || (selectedNode.getDBObject().getType() == DBObject.VIEW)) {
                            selectionTableOrView(selectedNode, e);
                        } else if (selectedNode.getDBObject().getType() == DBObject.PROCEDURES) {
                            selectionProcedure(selectedNode, e);
                        } else if (selectedNode.getDBObject().getType() == DBObject.PROCEDURES_GROUP) {
                            selectionProcedureGroup(selectedNode, e);
                        } else if (selectedNode.getDBObject().getType() == DBObject.TABLES_GROUP) {
                            selectionTablesGroup(selectedNode, e);
                        } else if (selectedNode.getDBObject().getType() == DBObject.VIEWS_GROUP) {
                            selectionViewsGroup(selectedNode, e);
                        } else if (selectedNode.getDBObject().isFolder()) {
                            selectionFolder(selectedNode, e);
                        }
                    }
                } catch (Exception ex) {
                    Show.error(ex);
                }
            }
        }
    });
}

From source file:ro.nextreports.designer.wizpublish.DownloadListWizardPanel.java

private boolean selection(JcrBrowserTree jcrBrowserTree, byte type) {
    TreePath[] paths = jcrBrowserTree.getSelectionPaths();
    if (paths == null) {
        return false;
    }/*from   w  w  w.  j av a  2s  .  c om*/

    for (TreePath selPath : paths) {
        DBBrowserNode selectedNode = (DBBrowserNode) selPath.getLastPathComponent();
        if ((selectedNode.getDBObject().getType() == DBObject.REPORTS)
                || (selectedNode.getDBObject().getType() == DBObject.CHARTS)) {
            if (!listModel.contains(selectedNode.getDBObject().getAbsolutePath())) {
                listModel.addElement(selectedNode.getDBObject().getAbsolutePath());
            }
        }
    }
    if (listModel.size() <= 0) {
        return false;
    }

    return true;
}

From source file:ro.nextreports.designer.wizpublish.JcrBrowserTree.java

public JcrBrowserTree(final byte typeRoot, WebServiceClient client) {
    super();//from w  w w.  j  a  v a 2s  .c o  m
    this.client = client;
    populateTree(typeRoot);

    setCellRenderer(new JcrBrowserTreeRenderer());
    getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    instance = this;

    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            job(e, true);
        }

        public void mouseReleased(MouseEvent e) {
            job(e, false);
        }

        private void job(MouseEvent e, boolean pressed) {
            if (e.isPopupTrigger()) {
                final TreePath selPath = getPathForLocation(e.getX(), e.getY());
                if (selPath == null) {
                    return;
                }
                setSelectionPath(selPath);
                try {
                    final DBBrowserNode selectedNode = (DBBrowserNode) selPath.getLastPathComponent();
                    if (selectedNode != null) {

                        JPopupMenu popupMenu = new JPopupMenu();
                        boolean show = false;
                        if ((selectedNode.getDBObject().getType() == DBObject.FOLDER_REPORT)
                                || (selectedNode.getDBObject().getType() == DBObject.DATABASE)
                                || (selectedNode.getDBObject().getType() == DBObject.REPORTS_GROUP)
                                || (selectedNode.getDBObject().getType() == DBObject.CHARTS_GROUP)) {
                            JMenuItem menuItem = new JMenuItem(new PublishFolderAction(selectedNode));
                            popupMenu.add(menuItem);
                            show = true;
                        }

                        if ((typeRoot == DBObject.DATABASE)
                                && ((selectedNode.getDBObject().getType() == DBObject.FOLDER_REPORT)
                                        || (selectedNode.getDBObject().getType() == DBObject.DATABASE))) {
                            PublishDataSourceAction publishDSAction = new PublishDataSourceAction(selectedNode);

                            JMenuItem menuItem2 = new JMenuItem(publishDSAction);
                            popupMenu.add(menuItem2);
                            show = true;
                        }
                        if (show) {
                            popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
                        }
                    }
                } catch (Exception ex) {
                    Show.error(ex);
                }
            }
        }
    });

}