public void run() { if (getTree().isExpanded(t)) { expandedNodes.add(t.getLastPathComponent()); } else { expandedNodes.remove(t.getLastPathComponent()); } }
@Override public void valueChanged(TreeSelectionEvent e) { if (e.getSource() == colors && !locked) { TreeSelectionModel tsm = colors.getSelectionModel(); TreePath tp[] = tsm.getSelectionPaths(); if (tp == null) return; Vector<ClassedItem> tmp = new Vector<ClassedItem>(); for (TreePath element : tp) { try { Object[] path = element.getPath(); ClassedItem ci = new ClassedItem(path[1].toString(), path[2].toString()); tmp.add(ci); } catch (Exception exp) { // User did not select a leafnode } } if (sceneElement instanceof NenyaImageSceneElement) { ((NenyaImageSceneElement) sceneElement).setColorList(tmp.toArray(new ClassedItem[0])); } if (sceneElement instanceof NenyaTileSceneElement) { ((NenyaTileSceneElement) sceneElement).setColorList(tmp.toArray(new ClassedItem[0])); } if (sceneElement instanceof NenyaComponentSceneElement) { ((NenyaComponentSceneElement) sceneElement) .getComponents()[itemList.getSelectedIndex()].setColorList( tmp.toArray(new ClassedItem[0])); } submitElement(sceneElement, null); } else { super.valueChanged(e); } }
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); } } } }
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 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()); }
@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(); } } }
@NotNull public Change[] getSelectedChanges() { Set<Change> changes = new LinkedHashSet<Change>(); final TreePath[] paths = getSelectionPaths(); if (paths == null) { return new Change[0]; } for (TreePath path : paths) { ChangesBrowserNode<?> node = (ChangesBrowserNode) path.getLastPathComponent(); changes.addAll(node.getAllChangesUnder()); } if (changes.isEmpty()) { final List<VirtualFile> selectedModifiedWithoutEditing = getSelectedModifiedWithoutEditing(); if (selectedModifiedWithoutEditing != null && !selectedModifiedWithoutEditing.isEmpty()) { for (VirtualFile file : selectedModifiedWithoutEditing) { AbstractVcs vcs = ProjectLevelVcsManager.getInstance(myProject).getVcsFor(file); if (vcs == null) continue; final VcsCurrentRevisionProxy before = VcsCurrentRevisionProxy.create(file, myProject, vcs.getKeyInstanceMethod()); if (before != null) { ContentRevision afterRevision = new CurrentContentRevision(new FilePathImpl(file)); changes.add(new Change(before, afterRevision, FileStatus.HIJACKED)); } } } } return changes.toArray(new Change[changes.size()]); }
private void updateSelectionFromTree() { TreePath[] treePaths = myTree.getSelectionPaths(); if (treePaths != null) { List<NamedConfigurable> selectedConfigurables = new ArrayList<NamedConfigurable>(); for (TreePath path : treePaths) { Object lastPathComponent = path.getLastPathComponent(); if (lastPathComponent instanceof MyNode) { selectedConfigurables.add(((MyNode) lastPathComponent).getConfigurable()); } } if (selectedConfigurables.size() > 1 && updateMultiSelection(selectedConfigurables)) { return; } } final TreePath path = myTree.getSelectionPath(); if (path != null) { final Object lastPathComp = path.getLastPathComponent(); if (!(lastPathComp instanceof MyNode)) return; final MyNode node = (MyNode) lastPathComp; setSelectedNode(node); } else { setSelectedNode(null); } }
public void valueChanged(TreeSelectionEvent e) { TreePath tp = e.getNewLeadSelectionPath(); if (tp == null) return; Object selNode = tp.getLastPathComponent(); if (selNode instanceof ButtonTreeNode) { ButtonTreeNode btn = (ButtonTreeNode) selNode; btn.onClick(); setSelectionPath(e.getOldLeadSelectionPath()); return; } if (!(selNode instanceof SelectableTreeNode)) return; SelectableTreeNode stn = (SelectableTreeNode) selNode; if (stn.wantSelect()) { sideBar.clearSelectionExcept(FriendTree.this); // If this is a library or playlist node with comments, and the comments tab is showing, // mark the // comments as read FriendTreeModel m = getModel(); if (stn instanceof LibraryTreeNode) { LibraryTreeNode ltn = (LibraryTreeNode) stn; ContentPanel cp = frame.mainPanel.getContentPanel("library/" + ltn.userId); // library content panel gets created on demand, so might be null if (cp != null && cp.tabPane.getSelectedIndex() == 1) m.markLibraryCommentsAsRead(ltn.userId); } else if (stn instanceof PlaylistTreeNode) { PlaylistTreeNode ptn = (PlaylistTreeNode) stn; long plId = ptn.getPlaylist().getPlaylistId(); ContentPanel cp = frame.mainPanel.getContentPanel("playlist/" + plId); if (cp.tabPane.getSelectedIndex() == 1) m.markPlaylistCommentsAsRead(plId); } if (stn.handleSelect()) m.firePathToRootChanged(stn); } else setSelectionPath(e.getOldLeadSelectionPath()); }
@Nullable private MessageNode getSelectedItem() { TreePath path = myTree.getSelectionPath(); if (path == null) return null; if (!(path.getLastPathComponent() instanceof MessageNode)) return null; return (MessageNode) path.getLastPathComponent(); }
public static List<TreePath> collectExpandedPaths(final JTree tree, TreePath path) { final ArrayList<TreePath> result = new ArrayList<TreePath>(); if (!tree.isExpanded(path)) return result; final Object lastPathComponent = path.getLastPathComponent(); final TreeModel model = tree.getModel(); if (model.isLeaf(lastPathComponent)) { result.add(path); } else { boolean pathWasAdded = false; for (int i = model.getChildCount(lastPathComponent) - 1; i >= 0; i--) { final TreePath childPath = path.pathByAddingChild(model.getChild(lastPathComponent, i)); if (model.isLeaf(lastPathComponent)) { if (!pathWasAdded) { result.add(path); pathWasAdded = true; } } else if (tree.isExpanded(childPath)) { result.addAll(collectExpandedPaths(tree, childPath)); } else { if (!pathWasAdded) { result.add(path); pathWasAdded = true; } } } } return result; }
private CheckedTreeNode getSelectedNode() { TreePath selectionPath = myTree.getSelectionPath(); if (selectionPath != null) { return (CheckedTreeNode) selectionPath.getLastPathComponent(); } return null; }
private static boolean isMoveSupported(JTree tree, int dir) { final TreePath[] selectionPaths = tree.getSelectionPaths(); if (selectionPaths != null) { DefaultMutableTreeNode parent = null; for (TreePath treePath : selectionPaths) if (treePath.getLastPathComponent() != null) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent(); if (parent == null) { parent = (DefaultMutableTreeNode) node.getParent(); } if (parent != node.getParent()) { return false; } if (dir > 0) { if (parent.getIndex(node) == parent.getChildCount() - 1) { return false; } } else { if (parent.getIndex(node) == 0) { return false; } } } return true; } return false; }
@Override public String getToolTipText(MouseEvent evt) { Point p = evt.getPoint(); TreePath tp = getClosestPathForLocation(p.x, p.y); Object node = tp.getLastPathComponent(); if (node instanceof PlaylistTreeNode) { PlaylistTreeNode ptn = (PlaylistTreeNode) node; int unseen = ptn.numUnseenTracks; if (unseen > 0) { String nt = numItems(unseen, "new track"); if (ptn.hasComments) { // html allows us to have linebreaks return "<html>" + nt + "<br>Unread comments</html>"; } else return nt; } if (ptn.hasComments) return "Unread comments"; } else if (node instanceof LibraryTreeNode) { LibraryTreeNode ltn = (LibraryTreeNode) node; int unseen = ltn.numUnseenTracks; if (unseen > 0) { String nt = numItems(unseen, "new track"); if (ltn.hasComments) { // html allows us to have linebreaks return "<html>" + nt + "<br>Unread comments</html>"; } else return nt; } if (ltn.hasComments) return "Unread comments"; } return null; }
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); } } // }}}
@Override public void calcData(DataKey key, DataSink sink) { if (key == VcsDataKeys.CHANGES) { sink.put(VcsDataKeys.CHANGES, getSelectedChanges()); } else if (key == VcsDataKeys.CHANGE_LEAD_SELECTION) { sink.put(VcsDataKeys.CHANGE_LEAD_SELECTION, getLeadSelection()); } else if (key == VcsDataKeys.CHANGE_LISTS) { sink.put(VcsDataKeys.CHANGE_LISTS, getSelectedChangeLists()); } else if (key == PlatformDataKeys.VIRTUAL_FILE_ARRAY) { sink.put(PlatformDataKeys.VIRTUAL_FILE_ARRAY, getSelectedFiles()); } else if (key == PlatformDataKeys.NAVIGATABLE) { final VirtualFile[] files = getSelectedFiles(); if (files.length == 1 && !files[0].isDirectory()) { sink.put(PlatformDataKeys.NAVIGATABLE, new OpenFileDescriptor(myProject, files[0], 0)); } } else if (key == PlatformDataKeys.NAVIGATABLE_ARRAY) { sink.put( PlatformDataKeys.NAVIGATABLE_ARRAY, ChangesUtil.getNavigatableArray(myProject, getSelectedFiles())); } else if (key == PlatformDataKeys.DELETE_ELEMENT_PROVIDER) { final TreePath[] paths = getSelectionPaths(); if (paths != null) { for (TreePath path : paths) { ChangesBrowserNode node = (ChangesBrowserNode) path.getLastPathComponent(); if (!(node.getUserObject() instanceof ChangeList)) { sink.put(PlatformDataKeys.DELETE_ELEMENT_PROVIDER, new VirtualFileDeleteProvider()); break; } } } } else if (key == PlatformDataKeys.COPY_PROVIDER) { sink.put(PlatformDataKeys.COPY_PROVIDER, myCopyProvider); } else if (key == UNVERSIONED_FILES_DATA_KEY) { sink.put(UNVERSIONED_FILES_DATA_KEY, getSelectedUnversionedFiles()); } else if (key == VcsDataKeys.MODIFIED_WITHOUT_EDITING_DATA_KEY) { sink.put(VcsDataKeys.MODIFIED_WITHOUT_EDITING_DATA_KEY, getSelectedModifiedWithoutEditing()); } else if (key == LOCALLY_DELETED_CHANGES) { sink.put(LOCALLY_DELETED_CHANGES, getSelectedLocallyDeletedChanges()); } else if (key == MISSING_FILES_DATA_KEY) { sink.put(MISSING_FILES_DATA_KEY, getSelectedMissingFiles()); } else if (VcsDataKeys.HAVE_LOCALLY_DELETED == key) { sink.put(VcsDataKeys.HAVE_LOCALLY_DELETED, haveLocallyDeleted()); } else if (VcsDataKeys.HAVE_MODIFIED_WITHOUT_EDITING == key) { sink.put(VcsDataKeys.HAVE_MODIFIED_WITHOUT_EDITING, haveLocallyModified()); } else if (VcsDataKeys.HAVE_SELECTED_CHANGES == key) { sink.put(VcsDataKeys.HAVE_SELECTED_CHANGES, haveSelectedChanges()); } else if (key == HELP_ID_DATA_KEY) { sink.put(HELP_ID_DATA_KEY, ourHelpId); } else if (key == VcsDataKeys.CHANGES_IN_LIST_KEY) { final TreePath selectionPath = getSelectionPath(); if (selectionPath != null && selectionPath.getPathCount() > 1) { ChangesBrowserNode<?> firstNode = (ChangesBrowserNode) selectionPath.getPathComponent(1); if (firstNode instanceof ChangesBrowserChangeListNode) { final List<Change> list = firstNode.getAllChangesUnder(); sink.put(VcsDataKeys.CHANGES_IN_LIST_KEY, list); } } } }
protected Transferable createTransferable(JComponent c) { JTree tree = (JTree) c; TreePath[] paths = tree.getSelectionPaths(); if (paths == null || paths.length != 1) return null; TreePath path = tree.getSelectionPath(); GroovyTreeNode groovyTreeNode = (GroovyTreeNode) path.getLastPathComponent(); return new StringTransferable((String) (groovyTreeNode.node.getNodeValue())); }
public static ActionCallback selectFirstNode(final JTree tree) { final TreeModel model = tree.getModel(); final Object root = model.getRoot(); TreePath selectionPath = new TreePath(root); if (!tree.isRootVisible() && model.getChildCount(root) > 0) selectionPath = selectionPath.pathByAddingChild(model.getChild(root, 0)); return selectPath(tree, selectionPath); }
private static IndexTreePathState removeLastPathComponent( final DefaultTreeModel model, final TreePath pathToBeRemoved) { final IndexTreePathState selectionState = new IndexTreePathState(pathToBeRemoved); if (((MutableTreeNode) pathToBeRemoved.getLastPathComponent()).getParent() == null) return selectionState; model.removeNodeFromParent((MutableTreeNode) pathToBeRemoved.getLastPathComponent()); return selectionState; }
@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; }
private static void expand(JTree tree, TreePath path, int levels) { if (levels == 0) return; tree.expandPath(path); TreeNode node = (TreeNode) path.getLastPathComponent(); Enumeration children = node.children(); while (children.hasMoreElements()) { expand(tree, path.pathByAddingChild(children.nextElement()), levels - 1); } }
private static boolean areComponentsEqual(final TreePath[] paths, final int componentIndex) { if (paths[0].getPathCount() <= componentIndex) return false; final Object pathComponent = paths[0].getPathComponent(componentIndex); for (final TreePath treePath : paths) { if (treePath.getPathCount() <= componentIndex) return false; if (!pathComponent.equals(treePath.getPathComponent(componentIndex))) return false; } return true; }
public static TreePath findCommonPath(final TreePath[] treePaths) { LOG.assertTrue(areComponentsEqual(treePaths, 0)); TreePath result = new TreePath(treePaths[0].getPathComponent(0)); int pathIndex = 1; while (areComponentsEqual(treePaths, pathIndex)) { result = result.pathByAddingChild(treePaths[0].getPathComponent(pathIndex)); pathIndex++; } return result; }
@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())); }
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()); } }
@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); }
private void popupInvoked(Component component, int x, int y) { final TreePath path = myTree.getLeadSelectionPath(); if (path == null) return; if (!(path.getLastPathComponent() instanceof MessageNode)) return; if (getData(DataConstants.NAVIGATABLE_ARRAY) == null) return; DefaultActionGroup group = new DefaultActionGroup(); group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE)); ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.ANT_MESSAGES_POPUP, group); menu.getComponent().show(component, x, y); }
@Nullable public NamedConfigurable getSelectedConfigurable() { final TreePath selectionPath = myTree.getSelectionPath(); if (selectionPath != null) { MyNode node = (MyNode) selectionPath.getLastPathComponent(); final NamedConfigurable configurable = node.getConfigurable(); LOG.assertTrue(configurable != null, "already disposed"); return configurable; } return null; }
TreePath getTreePath(TreeNode treeNode) { TreeNode parent = treeNode.getParent(); if (parent == null) { return new TreePath(treeNode); } else { TreePath ptp = getTreePath(parent); ptp = ptp.pathByAddingChild(treeNode); return ptp; } }
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)); } } }