Example usage for javax.swing JTree getSelectionPaths

List of usage examples for javax.swing JTree getSelectionPaths

Introduction

In this page you can find the example usage for javax.swing JTree getSelectionPaths.

Prototype

public TreePath[] getSelectionPaths() 

Source Link

Document

Returns the paths of all selected values.

Usage

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

public void setRepresentationCode() {
    JTree tree = theEntityTree;
    TreePath[] paths = tree.getSelectionPaths();
    for (int i = 0; i < paths.length; i++) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
        if ((node.getUserObject() instanceof FileGroup) || (node.getUserObject() instanceof FileSystemObject)
                || ((getEntities().size() > 1) && (node.getUserObject() instanceof FileGroupCollection))) {
            FileGroup group = (FileGroup) node.getUserObject();
            String repCode = manualDepositFrame.getInput("Enter Representation Code",
                    "Enter new representation code", group.getRepresentationCode());
            if (repCode != null) {
                group.setRepresentationCode(repCode);
            }/*  www. ja  va 2  s  .  co  m*/
        }
    }
}

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

public void deleteEntity() {
    if (canDeleteEntityItem()) {
        JTree tree = theEntityTree;
        TreePath[] paths = tree.getSelectionPaths();
        for (int i = 0; i < paths.length; i++) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
            if ((node.getUserObject() instanceof FileGroup)
                    || (node.getUserObject() instanceof FileSystemObject)
                    || ((getEntities().size() > 1) && (node.getUserObject() instanceof FileGroupCollection))) {
                deleteEntityNode(node);/*w  w  w  .j  a  v a  2  s .  c om*/
            }
        }
        ArrayList<FileGroupCollection> entities = getEntities();
        renumberEntityTypes(entities);
        addFileSystemRoot(theFsoRoot, true, false);
        deleteStructMapItemsNotInIE();
        refreshEntityTree();
    }
}

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

public boolean canDeleteStructItem() {
    boolean canMove = false;
    JTree tree = this.getTree(ETreeType.StructMapTree);
    if (tree != null) {
        if (tree.getSelectionCount() > 0) {
            TreePath[] paths = tree.getSelectionPaths();
            for (int i = 0; i < paths.length; i++) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
                if ((node.getUserObject() instanceof StructMap)
                        || (node.getUserObject() instanceof FileSystemObject)) {
                    canMove = true;//w  w  w.ja  v  a2 s . c o m
                    break;
                }
            }
        }
    }
    return canMove;
}

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

public void deleteStructMapItem() {
    if (canDeleteStructItem()) {
        JTree tree = this.getTree(ETreeType.StructMapTree);
        if (tree != null) {
            if (tree.getSelectionCount() > 0) {
                TreePath[] paths = tree.getSelectionPaths();
                for (int i = 0; i < paths.length; i++) {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
                    if ((node.getUserObject() instanceof StructMap)
                            || (node.getUserObject() instanceof FileSystemObject)) {
                        deleteStructMapNode(node);
                    }//www .j  a  va  2  s.c om
                }
            }
        }
    }
}

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

private void treeValueChanged(javax.swing.event.TreeSelectionEvent evt) {
    JTree sourceTree = (JTree) evt.getSource();
    TreePath[] paths = sourceTree.getSelectionPaths();
    if (paths != null) {
        theNodeInClipboard.clear();// www  .j a v  a 2 s.  c  o  m
        for (TreePath path : paths) {
            theNodeInClipboard.add((DefaultMutableTreeNode) path.getLastPathComponent());
        }
    }

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) evt.getPath().getLastPathComponent();
    JTree tree = (JTree) evt.getSource();
    if (getTreeType(tree).equals(ETreeType.FileSystemTree)) {
        if (node.getUserObject() instanceof FileSystemObject) {
            tree.setEditable(false);
        }
    }
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
    while (parent != null && parent.getUserObject() instanceof FileSystemObject) {
        node = parent;
        parent = (DefaultMutableTreeNode) node.getParent();
    }
    tree.setEditable(true);
    if ((parent != null) && (parent.getUserObject() instanceof StructMap)) {
        if (node.getUserObject() instanceof FileSystemObject) {
            tree.setEditable(false);
        }
    }
}

From source file:org.languagetool.gui.ConfigurationDialog.java

@NotNull
private MouseAdapter getMouseAdapter() {
    return new MouseAdapter() {
        private void handlePopupEvent(MouseEvent e) {
            JTree tree = (JTree) e.getSource();
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }/*  w ww.  ja  v  a  2  s .  c o  m*/
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            TreePath[] paths = tree.getSelectionPaths();
            boolean isSelected = false;
            if (paths != null) {
                for (TreePath selectionPath : paths) {
                    if (selectionPath.equals(path)) {
                        isSelected = true;
                    }
                }
            }
            if (!isSelected) {
                tree.setSelectionPath(path);
            }
            if (node.isLeaf()) {
                JPopupMenu popup = new JPopupMenu();
                JMenuItem aboutRuleMenuItem = new JMenuItem(messages.getString("guiAboutRuleMenu"));
                aboutRuleMenuItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        RuleNode node = (RuleNode) tree.getSelectionPath().getLastPathComponent();
                        Rule rule = node.getRule();
                        Language lang = config.getLanguage();
                        if (lang == null) {
                            lang = Languages.getLanguageForLocale(Locale.getDefault());
                        }
                        Tools.showRuleInfoDialog(tree, messages.getString("guiAboutRuleTitle"),
                                rule.getDescription(), rule, rule.getUrl(), messages,
                                lang.getShortCodeWithCountryAndVariant());
                    }
                });
                popup.add(aboutRuleMenuItem);
                popup.show(tree, e.getX(), e.getY());
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopupEvent(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopupEvent(e);
            }
        }
    };
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserControl.java

/** 
 * Reacts to click events in the tree./*from   w w  w  . j  a  v  a 2 s .c  o  m*/
 * 
 *  @param added The collection of added paths.
 */
void onClick(List<TreePath> added) {
    JTree tree = view.getTreeDisplay();
    TreePath[] paths = tree.getSelectionPaths();
    if (paths == null) {
        return;
    }
    TreeImageDisplay node;
    TreePath path;
    List<TreePath> toRemove = new ArrayList<TreePath>();
    TreeImageDisplay[] nodes;
    if (paths.length == 1) {
        Object p = paths[0].getLastPathComponent();
        if (!(p instanceof TreeImageDisplay))
            return;
        node = (TreeImageDisplay) p;
        if (node.isSelectable()) {
            nodes = new TreeImageDisplay[1];
            nodes[0] = node;
            model.setSelectedDisplays(nodes, false);
        } else {
            toRemove.add(paths[0]);
            view.removeTreePaths(toRemove);
            paths = tree.getSelectionPaths();
            nodes = new TreeImageDisplay[paths.length];
            for (int j = 0; j < paths.length; j++) {
                nodes[j] = (TreeImageDisplay) paths[j].getLastPathComponent();
            }
            model.setSelectedDisplays(nodes, false);
        }
        return;
    }
    //more than one node selected.
    TreeImageDisplay previous = model.getLastSelectedDisplay();
    Class<?> ref = null;
    Object ho = null;
    if (previous != null) {
        ho = previous.getUserObject();
        ref = ho.getClass();
    }

    List<TreeImageDisplay> l = new ArrayList<TreeImageDisplay>();
    TagAnnotationData tag;
    String ns = null;
    if (TagAnnotationData.class.equals(ref)) {
        ns = ((TagAnnotationData) ho).getNameSpace();
    }
    if (added != null) {
        Iterator<TreePath> i = added.iterator();
        Object nho;
        String nsNode;
        Object lastPath;
        while (i.hasNext()) {
            path = i.next();
            lastPath = path.getLastPathComponent();
            if (lastPath instanceof TreeImageDisplay) {
                node = (TreeImageDisplay) lastPath;
                nho = node.getUserObject();
                if (nho.getClass().equals(ref) && node.isSelectable()) {
                    if (nho.getClass().equals(TagAnnotationData.class)) {
                        nsNode = ((TagAnnotationData) nho).getNameSpace();
                        if (ns == null && nsNode == null)
                            l.add(node);
                        else if (ns == null && nsNode != null
                                && TagAnnotationData.INSIGHT_TAGSET_NS.equals(nsNode))
                            toRemove.add(path);
                        else if (ns != null && nsNode == null && TagAnnotationData.INSIGHT_TAGSET_NS.equals(ns))
                            toRemove.add(path);
                        else if (ns != null && nsNode != null) {
                            if (ns.equals(nsNode))
                                l.add(node);
                        }
                    } else
                        l.add(node);
                } else
                    toRemove.add(path);
            }
        }
    }

    if (toRemove.size() > 0) {
        String text = null;
        if (ImageData.class.equals(ref))
            text = "Images.";
        else if (ProjectData.class.equals(ref))
            text = "Projects.";
        else if (DatasetData.class.equals(ref))
            text = "Datasets.";
        else if (ScreenData.class.equals(ref))
            text = "Screens.";
        else if (PlateData.class.equals(ref))
            text = "Plates.";
        else if (PlateAcquisitionData.class.equals(ref))
            text = "Acquisitions.";
        else if (TagAnnotationData.class.equals(ref)) {
            tag = (TagAnnotationData) ho;
            if (TagAnnotationData.INSIGHT_TAGSET_NS.equals(tag.getNameSpace()))
                text = "Tag Sets.";
            else
                text = "Tags.";
        } else if (FileAnnotationData.class.equals(ref))
            text = "Files.";
        else if (FileData.class.equals(ref))
            text = "Files.";
        else if (ExperimenterData.class.equals(ref))
            text = "Experimenters";
        else if (GroupData.class.equals(ref))
            text = "User Groups";
        //smart folder selected
        if (text == null)
            text = "nodes of the same type.";
        UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier();
        un.notifyInfo("Tree selection", "You can only select " + text);
        view.removeTreePaths(toRemove);
    }
    paths = tree.getSelectionPaths();

    List<TreeImageDisplay> list = new ArrayList<TreeImageDisplay>();
    if (paths != null) {
        for (int j = 0; j < paths.length; j++) {
            if (paths[j].getLastPathComponent() instanceof TreeImageDisplay)
                list.add((TreeImageDisplay) paths[j].getLastPathComponent());
        }
    }

    if (list.size() > 0) {
        model.setSelectedDisplays(list.toArray(new TreeImageDisplay[list.size()]), false);
    }
}

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

@Override
protected void performAction() {
    File file = super.getOutputFile();
    if (file == null) {
        return;//  w ww.  j  a v a2  s .  c  o m
    }

    JTree siteTree = extension.getView().getSiteTreePanel().getTreeSite();

    super.writeURLs(file, this.getOutputSet(siteTree.getSelectionPaths()));
}

From source file:view.MainWindow.java

private ArrayList<File> getMultipleSelectedFiles(JTree jtree) {
    ArrayList<File> aLSelectedFiles = new ArrayList<>();
    if (jtree == null) {
        return aLSelectedFiles;
    }/*ww  w .j  a  va 2  s.  c o  m*/
    if (jtree.getSelectionPath() == null) {
        return aLSelectedFiles;
    }
    for (TreePath tp : jtree.getSelectionPaths()) {
        String strSelectedFile = "";
        Object[] paths = tp.getPath();
        for (int i = 0; i < paths.length; i++) {
            strSelectedFile += paths[i];
            if (i + 1 < paths.length) {
                strSelectedFile += File.separator;
            }
        }
        aLSelectedFiles.add(new File(strSelectedFile));
    }
    return aLSelectedFiles;
}