// {{{ removeSelectedNode() method private void removeSelectedNode() { TreePath path = resultTree.getSelectionPath(); if (path == null) return; MutableTreeNode value = (MutableTreeNode) path.getLastPathComponent(); if (path.getPathCount() > 1) { // Adjust selection so that repeating some removals // behave naturally. TreePath parentPath = path.getParentPath(); MutableTreeNode parent = (MutableTreeNode) parentPath.getLastPathComponent(); int removingIndex = parent.getIndex(value); int nextIndex = removingIndex + 1; if (nextIndex < parent.getChildCount()) { TreeNode next = parent.getChildAt(nextIndex); resultTree.setSelectionPath(parentPath.pathByAddingChild(next)); } else { resultTree.setSelectionPath(parentPath); } resultTreeModel.removeNodeFromParent(value); } HyperSearchOperationNode.removeNodeFromCache(value); if (resultTreeRoot.getChildCount() == 0) { hideDockable(); } } // }}}
public void run() { if (getTree().isExpanded(t)) { expandedNodes.add(t.getLastPathComponent()); } else { expandedNodes.remove(t.getLastPathComponent()); } }
private Pair<ElementNode, List<ElementNode>> storeSelection() { List<ElementNode> selectedNodes = new ArrayList<ElementNode>(); TreePath[] paths = myTree.getSelectionPaths(); if (paths != null) { for (TreePath path : paths) { selectedNodes.add((ElementNode) path.getLastPathComponent()); } } TreePath leadSelectionPath = myTree.getLeadSelectionPath(); return Pair.create( leadSelectionPath != null ? (ElementNode) leadSelectionPath.getLastPathComponent() : null, selectedNodes); }
@Override public void actionPerformed(ActionEvent evt) { JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem) evt.getSource(); boolean curState = menuItem.isSelected(); TreePath path = resultTree.getSelectionPath(); DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent(); HyperSearchOperationNode operNodeObj = (HyperSearchOperationNode) operNode.getUserObject(); if (curState) operNodeObj.cacheResultNodes(operNode); operNode.removeAllChildren(); if (curState) { Exception excp = null; try { operNodeObj.insertTreeNodes(resultTree, operNode); } catch (Exception ex) { operNodeObj.restoreFlatNodes(resultTree, operNode); menuItem.setSelected(false); excp = ex; } finally { ((DefaultTreeModel) resultTree.getModel()).nodeStructureChanged(operNode); expandAllNodes(operNode); resultTree.scrollPathToVisible(new TreePath(operNode.getPath())); } if (excp != null) throw new RuntimeException(excp); } else operNodeObj.restoreFlatNodes(resultTree, operNode); operNodeObj.setTreeViewDisplayed(menuItem.isSelected()); }
void onDelete() { TreePath path = m_tree.getSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object[] options = {"Yes", "No"}; int choise = JOptionPane.showOptionDialog( pohaci.gumunda.cgui.GumundaMainFrame.getMainFrame(), "Are you sure deleting this " + node + " ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if (choise == JOptionPane.YES_OPTION) { try { deleteNodeParent(node); } catch (Exception ex) { JOptionPane.showMessageDialog( this, ex.getMessage(), "Warning", JOptionPane.WARNING_MESSAGE); } } } }
private void goToSelectedNode(int mode) { TreePath path = resultTree.getSelectionPath(); if (path == null) return; DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object value = node.getUserObject(); // do nothing if clicked "foo (showing n occurrences in m files)" if (node.getParent() != resultTreeRoot && value instanceof HyperSearchNode) { HyperSearchNode n = (HyperSearchNode) value; Buffer buffer = n.getBuffer(view); if (buffer == null) return; EditPane pane; switch (mode) { case M_OPEN: pane = view.goToBuffer(buffer); break; case M_OPEN_NEW_VIEW: pane = jEdit.newView(view, buffer, false).getEditPane(); break; case M_OPEN_NEW_PLAIN_VIEW: pane = jEdit.newView(view, buffer, true).getEditPane(); break; case M_OPEN_NEW_SPLIT: pane = view.splitHorizontally(); break; default: throw new IllegalArgumentException("Bad mode: " + mode); } n.goTo(pane); } } // }}}
void onEdit() { DefaultTreeModel model = (DefaultTreeModel) m_tree.getModel(); TreePath path = m_tree.getSelectionPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); Organization org = (Organization) node.getUserObject(); OrganizationEditorDlg dlg = null; if (parent == model.getRoot()) dlg = new OrganizationEditorDlg( pohaci.gumunda.cgui.GumundaMainFrame.getMainFrame(), m_conn, m_sessionid, null, org); else dlg = new OrganizationEditorDlg( pohaci.gumunda.cgui.GumundaMainFrame.getMainFrame(), m_conn, m_sessionid, (DefaultMutableTreeNode) node.getParent(), org); dlg.setVisible(true); if (dlg.getResponse() == JOptionPane.OK_OPTION) { node.setUserObject(dlg.getOrganization()); model.nodeChanged(node); } }
@Override public void keyPressed(KeyEvent e) { TreePath path = myTree.getLeadSelectionPath(); if (path == null) return; final Object lastComponent = path.getLastPathComponent(); if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (lastComponent instanceof ParentNode) return; doOKAction(); e.consume(); } else if (e.getKeyCode() == KeyEvent.VK_INSERT) { if (lastComponent instanceof ElementNode) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent; if (!mySelectedNodes.contains(node)) { if (node.getNextNode() != null) { myTree.setSelectionPath(new TreePath(node.getNextNode().getPath())); } } else { if (node.getNextNode() != null) { myTree.removeSelectionPath(new TreePath(node.getPath())); myTree.setSelectionPath(new TreePath(node.getNextNode().getPath())); myTree.repaint(); } } e.consume(); } } }
@Nullable private Node getSelectedNode() { TreePath leadSelectionPath = myTree.getLeadSelectionPath(); if (leadSelectionPath == null) return null; DefaultMutableTreeNode node = (DefaultMutableTreeNode) leadSelectionPath.getLastPathComponent(); return node instanceof Node ? (Node) node : null; }
@Override public void actionPerformed(ActionEvent evt) { TreePath path = resultTree.getSelectionPath(); DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent(); for (Enumeration e = operNode.children(); e.hasMoreElements(); ) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); resultTree.collapsePath(new TreePath(node.getPath())); } resultTree.scrollPathToVisible(new TreePath(operNode.getPath())); }
@Override public void actionPerformed(ActionEvent evt) { TreePath path = resultTree.getSelectionPath(); DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent(); ToStringNodes toStringNodes = new ToStringNodes(); traverseNodes(operNode, toStringNodes); StringSelection selection = new StringSelection(toStringNodes.nodesString.toString()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, null); }
public void actionPerformed(ActionEvent event) { JTree tree = getTree(); TreePath path = tree.getSelectionPath(); if (path == null) { sheet.getLogger().warning("Warning: User must select a node to attach a new config to"); // XXX add a message telling users to select a node } else { createAttrConfigForNode((Node) path.getLastPathComponent()); } }
private String textGen(TreePath p) { MyNode selectedNode = (MyNode) p.getLastPathComponent(); String text = "men allt som"; int n = selectedNode.getPath().length; for (int i = n - 1; i >= 0; i--) { text = text + " är " + selectedNode.getPath()[i].toString(); } return text; }
public void editSelected() { TreePath selected = tree.getSelectionPath(); if (selected != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) selected.getLastPathComponent(); Object obj = node.getUserObject(); if (obj instanceof CavityDBObject) { CavityDBObject dbObj = (CavityDBObject) obj; new ObjectEditingFrame(new ObjectEditingPanel(dbObj)); } } }
@Override public void actionPerformed(ActionEvent evt) { TreePath path = resultTree.getSelectionPath(); DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent(); HyperSearchFolderNode nodeObj = (HyperSearchFolderNode) operNode.getUserObject(); String glob = "*"; SearchFileSet dirList = SearchAndReplace.getSearchFileSet(); if (dirList instanceof DirectoryListSet) glob = ((DirectoryListSet) dirList).getFileFilter(); SearchAndReplace.setSearchFileSet( new DirectoryListSet(nodeObj.getNodeFile().getAbsolutePath(), glob, true)); SearchDialog.showSearchDialog(view, null, SearchDialog.DIRECTORY); }
@Override public void exportToClipboard(JComponent comp, Clipboard clip, int action) throws IllegalStateException { TreePath[] paths = resultTree.getSelectionPaths(); ToStringNodes toStringNodes = new ToStringNodes(); for (TreePath path : paths) { DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent(); toStringNodes.processNode(operNode); } StringSelection selection = new StringSelection(toStringNodes.nodesString.toString()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, null); }
@Nullable private Node[] getSelectedNodes() { TreePath[] leadSelectionPath = myTree.getSelectionPaths(); if (leadSelectionPath == null || leadSelectionPath.length == 0) return null; final List<Node> result = new ArrayList<Node>(); for (TreePath comp : leadSelectionPath) { final Object lastPathComponent = comp.getLastPathComponent(); if (lastPathComponent instanceof Node) { final Node node = (Node) lastPathComponent; result.add(node); } } return result.isEmpty() ? null : result.toArray(new Node[result.size()]); }
@Override @Nullable public Set<Usage> getSelectedUsages() { TreePath[] selectionPaths = myTree.getSelectionPaths(); if (selectionPaths == null) { return null; } Set<Usage> usages = new THashSet<Usage>(); for (TreePath selectionPath : selectionPaths) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); collectUsages(node, usages); } return usages; }
public void actionPerformed(ActionEvent event) { JTree tree = getTree(); TreePath path = tree.getSelectionPath(); if (path == null) { sheet.getLogger().warning("Warning: User must select a node to delete"); // XXX add message telling users to select a node } else { Node selected = (Node) path.getLastPathComponent(); try { Node parent = selected.getParent(); if (parent != null) { parent.removeChild(selected); select(parent); } } catch (UnsupportedOperationException uox) { sheet.getLogger().warning("Cannot delete node: " + selected); } } }
private void captureUsagesExpandState(TreePath pathFrom, final Collection<UsageState> states) { if (!myTree.isExpanded(pathFrom)) { return; } final DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathFrom.getLastPathComponent(); final int childCount = node.getChildCount(); for (int idx = 0; idx < childCount; idx++) { final TreeNode child = node.getChildAt(idx); if (child instanceof UsageNode) { final Usage usage = ((UsageNode) child).getUsage(); states.add( new UsageState( usage, myTree.getSelectionModel().isPathSelected(pathFrom.pathByAddingChild(child)))); } else { captureUsagesExpandState(pathFrom.pathByAddingChild(child), states); } } }
@Nullable private UsageTarget[] getSelectedUsageTargets() { TreePath[] selectionPaths = myTree.getSelectionPaths(); if (selectionPaths == null) return null; Set<UsageTarget> targets = new THashSet<UsageTarget>(); for (TreePath selectionPath : selectionPaths) { Object lastPathComponent = selectionPath.getLastPathComponent(); if (lastPathComponent instanceof UsageTargetNode) { UsageTargetNode usageTargetNode = (UsageTargetNode) lastPathComponent; UsageTarget target = usageTargetNode.getTarget(); if (target != null && target.isValid()) { targets.add(target); } } } return targets.isEmpty() ? null : targets.toArray(new UsageTarget[targets.size()]); }
private void showDetails(TreePath p) { if (p == null) { return; } MyNode selectedNode = (MyNode) p.getLastPathComponent(); String textPath = textGen(p); JOptionPane.showMessageDialog( this, selectedNode.getLevelName() + ": " + selectedNode.getUserObject() + "\n" + selectedNode.getText() + "\n" + textPath); }
/** * Called whenever the value of the selection changes. * * @param e the event that characterizes the change. */ public void valueChanged(TreeSelectionEvent e) { TreePath path = e.getPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); if (node.isLeaf()) { if (getInformation(path) != null) { // When selecting an image information. XmlInformation info = getInformation(path); for (int i = 0; i < listener_list.size(); i++) { InformationTreeSelectionListener listener = (InformationTreeSelectionListener) listener_list.elementAt(i); listener.select(info); } } else { // When expanding a folder. expandNode(node); } } } }
/** Removes the current selected group. */ final void removeSelectedGroup() { TreePath[] selectionPaths = this.tree.getSelectionPaths(); if (selectionPaths == null) { return; } DefaultTreeModel model = (DefaultTreeModel) this.tree.getModel(); ElementTreeNode rootNode = (ElementTreeNode) model.getRoot(); for (TreePath selectionPath : selectionPaths) { ElementTreeNode treeNode = (ElementTreeNode) selectionPath.getLastPathComponent(); if (treeNode.getUserObject() instanceof ElementGroup) { ElementGroup elementGroup = (ElementGroup) treeNode.getUserObject(); this.model.removeGroup(elementGroup); model.nodesWereRemoved( rootNode, new int[] {rootNode.getIndex(treeNode)}, new Object[] {treeNode}); } } }
private void myDoubleClick(int row, TreePath path) { if (path != null) { JFrame infoFrame = new JFrame("Object Info for: " + path); JLabel objectLabel; JLabel parentPathLabel; // Display Selected Object Name; objectLabel = new JLabel("Object: " + path.getLastPathComponent().toString()); objectLabel.setHorizontalAlignment(SwingConstants.CENTER); // Display specific object information parentPathLabel = new JLabel("Parent Path: " + path.getParentPath()); parentPathLabel.setHorizontalAlignment(SwingConstants.CENTER); // Construct infoFrame infoFrame.getContentPane().add(objectLabel, BorderLayout.CENTER); infoFrame.getContentPane().add(parentPathLabel, BorderLayout.SOUTH); infoFrame.pack(); infoFrame.setVisible(true); } }
/** * Processes an idChanged event. Search is different from all other navigators in that you while * search tree is synchronized the highlighting doesn't occur unless selected from the search * navigator. */ public void idChanged(HelpModelEvent e) { ID id = e.getID(); URL url = e.getURL(); HelpModel helpModel = searchnav.getModel(); debug("idChanged(" + e + ")"); if (e.getSource() != helpModel) { debug("Internal inconsistency!"); debug(" " + e.getSource() + " != " + helpModel); throw new Error("Internal error"); } TreePath s = tree.getSelectionPath(); if (s != null) { Object o = s.getLastPathComponent(); // should require only a TreeNode if (o instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode tn = (DefaultMutableTreeNode) o; SearchTOCItem item = (SearchTOCItem) tn.getUserObject(); if (item != null) { ID nId = item.getID(); if (nId != null && nId.equals(id)) { return; } } } } DefaultMutableTreeNode node = findIDorURL(topNode, id, url); if (node == null) { // node doesn't exist. Need to clear the selection. debug("node didn't exist"); tree.clearSelection(); return; } TreePath path = new TreePath(node.getPath()); tree.expandPath(path); tree.setSelectionPath(path); tree.scrollPathToVisible(path); }
public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { DefaultTreeModel model = (DefaultTreeModel) m_tree.getModel(); TreePath path = m_tree.getSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); if (node == model.getRoot()) { mi_add.setEnabled(true); mi_edit.setEnabled(false); mi_delete.setEnabled(false); } else { mi_add.setEnabled(true); mi_edit.setEnabled(true); mi_delete.setEnabled(true); } Rectangle rectangle = m_tree.getPathBounds(path); if (rectangle.contains(e.getPoint())) m_popupMenu.show(m_tree, e.getX(), e.getY()); } } }
void onAdd() { DefaultTreeModel model = (DefaultTreeModel) m_tree.getModel(); TreePath path = m_tree.getSelectionPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); OrganizationEditorDlg dlg = null; if (node == model.getRoot()) dlg = new OrganizationEditorDlg( pohaci.gumunda.cgui.GumundaMainFrame.getMainFrame(), m_conn, m_sessionid, null); else dlg = new OrganizationEditorDlg( pohaci.gumunda.cgui.GumundaMainFrame.getMainFrame(), m_conn, m_sessionid, node); dlg.setVisible(true); if (dlg.getResponse() == JOptionPane.OK_OPTION) { Organization org = new Organization(dlg.getOrganization(), dlg.getOrganization().getCode()); DefaultMutableTreeNode child = new DefaultMutableTreeNode(org); model.insertNodeInto(child, node, node.getChildCount()); m_tree.scrollPathToVisible(new TreePath(model.getPathToRoot(child))); } }
// {{{ showPopupMenu method private void showPopupMenu(MouseEvent evt) { TreePath path = resultTree.getSelectionPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); popupMenu = new JPopupMenu(); Object userObj = node.getUserObject(); if (userObj instanceof HyperSearchFileNode || userObj instanceof HyperSearchResult) { popupMenu.add(new GoToNodeAction("hypersearch-results.open", M_OPEN)); popupMenu.add(new GoToNodeAction("hypersearch-results.open-view", M_OPEN_NEW_VIEW)); popupMenu.add( new GoToNodeAction("hypersearch-results.open-plain-view", M_OPEN_NEW_PLAIN_VIEW)); popupMenu.add(new GoToNodeAction("hypersearch-results.open-split", M_OPEN_NEW_SPLIT)); } if (!(userObj instanceof HyperSearchFolderNode)) popupMenu.add(new RemoveTreeNodeAction()); popupMenu.add(new ExpandChildTreeNodesAction()); if (userObj instanceof HyperSearchFolderNode || userObj instanceof HyperSearchOperationNode) { popupMenu.add(new CollapseChildTreeNodesAction()); if (userObj instanceof HyperSearchFolderNode) popupMenu.add(new NewSearchAction()); } if (userObj instanceof HyperSearchOperationNode) { popupMenu.add(new JPopupMenu.Separator()); HyperSearchOperationNode resultNode = (HyperSearchOperationNode) userObj; JCheckBoxMenuItem chkItem = new JCheckBoxMenuItem( jEdit.getProperty("hypersearch-results.tree-view"), resultNode.isTreeViewDisplayed()); chkItem.addActionListener(new TreeDisplayAction()); popupMenu.add(chkItem); popupMenu.add(new RedoSearchAction((HyperSearchOperationNode) userObj)); } popupMenu.add(new CopyToClipboardAction()); GUIUtilities.showPopupMenu(popupMenu, evt.getComponent(), evt.getX(), evt.getY()); evt.consume(); } // }}}
/** * Creates a new check for the Config in the path. * * @param t The path to the descriptor config to check. */ public CheckIfExpanded(TreePath t) { assert t.getLastPathComponent() instanceof Config; this.t = t; }