List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
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 v a2 s. c o m*/ 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:org.zaproxy.zap.view.ContextTechnologyPanel.java
private JCheckBoxTree getTechTree() { if (techTree == null) { techTree = new JCheckBoxTree() { private static final long serialVersionUID = 1L; @Override/*from ww w . j a v a 2 s .c o m*/ protected void setExpandedState(TreePath path, boolean state) { // Ignore all collapse requests; collapse events will not be fired if (state) { super.setExpandedState(path, state); } } }; // Initialise the structure based on all the tech we know about TechSet ts = new TechSet(Tech.builtInTech); Iterator<Tech> iter = ts.getIncludeTech().iterator(); DefaultMutableTreeNode root = new DefaultMutableTreeNode( Constant.messages.getString("context.technology.tree.root")); Tech tech; DefaultMutableTreeNode parent; DefaultMutableTreeNode node; while (iter.hasNext()) { tech = iter.next(); if (tech.getParent() != null) { parent = techToNodeMap.get(tech.getParent()); } else { parent = null; } if (parent == null) { parent = root; } node = new DefaultMutableTreeNode(tech.getUiName()); parent.add(node); techToNodeMap.put(tech, node); } model = new DefaultTreeModel(root); techTree.setModel(model); techTree.expandAll(); techTree.setCheckBoxEnabled(new TreePath(root), false); } return techTree; }
From source file:org.zaproxy.zap.view.NodeSelectDialog.java
public SiteNode showDialog(SiteNode defaultNode) { // Assume Contexts cant be selected this.getTreeContext().setVisible(false); SiteNode siteRoot = (SiteNode) Model.getSingleton().getSession().getSiteTree().getRoot(); populateNode(siteRoot, (SiteNode) this.siteTree.getRoot(), defaultNode); if (selectedSiteNode != null) { // Found the default node, select it TreePath path = new TreePath(this.siteTree.getPathToRoot(selectedSiteNode)); this.getTreeSite().setExpandsSelectedPaths(true); this.getTreeSite().setSelectionPath(path); this.getTreeSite().scrollPathToVisible(path); this.getTreeSite().expandPath(path); } else {/*w w w .j a v a2s .c o m*/ // no default path, just expand the top level TreePath path = new TreePath(this.siteTree.getPathToRoot((TreeNode) this.siteTree.getRoot())); this.getTreeSite().expandPath(path); } this.setVisible(true); // The dialog is modal so this wont return until the dialog visibility is unset return selectedSiteNode; }
From source file:org.zaproxy.zap.view.NodeSelectDialog.java
public Target showDialog(Target defaultTarget) { // Assume Contexts can be selected this.getTreeContext().setVisible(true); SiteNode siteRoot = (SiteNode) Model.getSingleton().getSession().getSiteTree().getRoot(); populateContexts((SiteNode) this.contextTree.getRoot()); if (defaultTarget != null) { populateNode(siteRoot, (SiteNode) this.siteTree.getRoot(), defaultTarget.getStartNode()); } else {/*from w ww . j a v a2s . c o m*/ populateNode(siteRoot, (SiteNode) this.siteTree.getRoot(), null); } if (selectedSiteNode != null) { // Found the default node, select it TreePath path = new TreePath(this.siteTree.getPathToRoot(selectedSiteNode)); this.getTreeSite().setExpandsSelectedPaths(true); this.getTreeSite().setSelectionPath(path); this.getTreeSite().scrollPathToVisible(path); this.getTreeSite().expandPath(path); } else { // no default path, just expand the top level TreePath path = new TreePath(this.siteTree.getPathToRoot((TreeNode) this.siteTree.getRoot())); this.getTreeSite().expandPath(path); } this.setVisible(true); // The dialog is modal so this wont return until the dialog visibility is unset if (selectedSiteNode != null) { return new Target(selectedSiteNode); } return selectedTarget; }
From source file:org.zaproxy.zap.view.TechnologyTreePanel.java
public TechnologyTreePanel(String nameRootNode) { setLayout(new BorderLayout()); techToNodeMap = new HashMap<>(); techTree = new JCheckBoxTree() { private static final long serialVersionUID = 1L; @Override/*from w w w .ja va 2 s . co m*/ protected void setExpandedState(TreePath path, boolean state) { // Ignore all collapse requests; collapse events will not be fired if (state) { super.setExpandedState(path, state); } } }; // Initialise the structure based on all the tech we know about TechSet ts = new TechSet(Tech.builtInTech); Iterator<Tech> iter = ts.getIncludeTech().iterator(); DefaultMutableTreeNode root = new DefaultMutableTreeNode(nameRootNode); Tech tech; DefaultMutableTreeNode parent; DefaultMutableTreeNode node; while (iter.hasNext()) { tech = iter.next(); if (tech.getParent() != null) { parent = techToNodeMap.get(tech.getParent()); } else { parent = null; } if (parent == null) { parent = root; } node = new DefaultMutableTreeNode(tech.getUiName()); parent.add(node); techToNodeMap.put(tech, node); } techTree.setModel(new DefaultTreeModel(root)); techTree.expandAll(); techTree.setCheckBoxEnabled(new TreePath(root), false); reset(); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(techTree); scrollPane.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED)); add(scrollPane, BorderLayout.CENTER); }
From source file:phex.gui.tabs.library.LibraryTab.java
private JPanel createTreePanel(MouseHandler mouseHandler) { JPanel panel = new JPanel(); CellConstraints cc = new CellConstraints(); FormLayout layout = new FormLayout("fill:d:grow", // columns "fill:d:grow, 1dlu, p"); //rows PanelBuilder tabBuilder = new PanelBuilder(layout, panel); sharingTreeModel = new SharingTreeModel(); mainTree = new JTree(sharingTreeModel); mainTree.setMinimumSize(new Dimension(0, 0)); mainTree.setRowHeight(0);//from w w w . ja v a 2 s . co m mainTree.setCellRenderer(new SharingTreeRenderer()); mainTree.addMouseListener(mouseHandler); mainTree.getSelectionModel().addTreeSelectionListener(new SelectionHandler()); ToolTipManager.sharedInstance().registerComponent(mainTree); // open up first level of nodes TreeNode root = (TreeNode) sharingTreeModel.getRoot(); int count = root.getChildCount(); for (int i = 0; i < count; i++) { mainTree.expandPath(new TreePath(new Object[] { root, root.getChildAt(i) })); } JScrollPane treeScrollPane = new JScrollPane(mainTree); tabBuilder.add(treeScrollPane, cc.xywh(1, 1, 1, 1)); FWToolBar shareToolbar = new FWToolBar(FWToolBar.HORIZONTAL); shareToolbar.setBorderPainted(false); shareToolbar.setFloatable(false); tabBuilder.add(shareToolbar, cc.xy(1, 3)); FWAction action = new AddShareFolderAction(); addTabAction(ADD_SHARE_FOLDER_ACTION_KEY, action); shareToolbar.addAction(action); action = new RemoveShareFolderAction(); addTabAction(REMOVE_SHARE_FOLDER_ACTION_KEY, action); shareToolbar.addAction(action); if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) { action = new ExploreFolderAction(); addTabAction(EXPLORE_FOLDER_ACTION_KEY, action); } return panel; }
From source file:phex.gui.tabs.library.LibraryTreePane.java
private void prepareComponent() { CellConstraints cc = new CellConstraints(); FormLayout layout = new FormLayout("fill:d:grow", // columns "fill:d:grow, 1dlu, p"); //rows PanelBuilder tabBuilder = new PanelBuilder(layout, this); sharingTreeModel = new SharingTreeModel(); mainTree = new JTree(sharingTreeModel); mainTree.setMinimumSize(new Dimension(0, 0)); mainTree.setRowHeight(0);/*w ww .j av a 2 s .com*/ mainTree.setCellRenderer(new SharingTreeRenderer()); mainTree.addMouseListener(new MouseHandler()); mainTree.getSelectionModel().addTreeSelectionListener(new SelectionHandler()); ToolTipManager.sharedInstance().registerComponent(mainTree); // open up first level of nodes TreeNode root = (TreeNode) sharingTreeModel.getRoot(); int count = root.getChildCount(); for (int i = 0; i < count; i++) { mainTree.expandPath(new TreePath(new Object[] { root, root.getChildAt(i) })); } JScrollPane treeScrollPane = new JScrollPane(mainTree); tabBuilder.add(treeScrollPane, cc.xywh(1, 1, 1, 1)); FWToolBar shareToolbar = new FWToolBar(FWToolBar.HORIZONTAL); shareToolbar.setBorderPainted(false); shareToolbar.setFloatable(false); tabBuilder.add(shareToolbar, cc.xy(1, 3)); addShareFolderAction = new AddShareFolderAction(); shareToolbar.addAction(addShareFolderAction); removeShareFolderAction = new RemoveShareFolderAction(); shareToolbar.addAction(removeShareFolderAction); if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) { exploreFolderAction = new ExploreFolderAction(); } fileTreePopup = new FWPopupMenu(); fileTreePopup.addAction(addShareFolderAction); fileTreePopup.addAction(removeShareFolderAction); if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) { fileTreePopup.addAction(exploreFolderAction); } }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void connectToDataSource(String dataSourceName) { try {/*from w w w . jav a 2 s.co m*/ if (DefaultDataSourceManager.getInstance().getConnectedDataSource() != null) { return; // already connected } DefaultDataSourceManager.getInstance().connect(dataSourceName); DBBrowserNode node = searchNode(DBNodeExpander.CONNECTIONS); if (node.getChildCount() == 0) { return; } DBBrowserNode selectedNode = searchNode(dataSourceName, DBObject.DATABASE); // select data source node and expand it TreeNode[] nodes = model.getPathToRoot(selectedNode); TreePath path = new TreePath(nodes); scrollPathToVisible(path); setSelectionPath(path); instance.fireTreeExpanded(path); } catch (Exception e) { LOG.error(e.getMessage(), e); e.printStackTrace(); } }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
public void selectNode(String name, byte type) { DBBrowserNode foundNode = searchNode(name, type); if (foundNode != null) { TreePath treePath = new TreePath(foundNode.getPath()); this.setSelectionPath(treePath); this.scrollPathToVisible(treePath); }/* ww w . j av a 2 s .com*/ }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
public void selectNode(String name, String path, byte type) { DBBrowserNode foundNode = searchNode(name, path, type); //System.out.println("----------------"); //System.out.println("name="+name + " path="+path + " type="+type); //System.out.println("foundNode="+foundNode); if (foundNode != null) { TreePath treePath = new TreePath(foundNode.getPath()); this.setSelectionPath(treePath); this.scrollPathToVisible(treePath); }/*from w w w . j av a2 s . c o m*/ }