List of usage examples for javax.swing JTree getSelectionPath
public TreePath getSelectionPath()
From source file:org.nuclos.client.explorer.ExplorerNode.java
/** * refreshes the current node (and its children) and notifies the given treemodel * @param dtm the DefaultTreeModel to notify. Must contain this node. * @throws CommonFinderException if the object presented by this node no longer exists. */// ww w.j a v a2s . co m public void refresh(final JTree tree, boolean fullRefreshCurrent) throws CommonFinderException { List<String> lstExpandedPathsResult = new ArrayList<String>(); ExplorerNode.createExpandendPathsForTree(new TreePath(tree.getModel().getRoot()), tree, lstExpandedPathsResult); final TreePath selected = tree.getSelectionPath(); DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel(); unloadChildren(); final TN treenode = getTreeNode(); if (treenode.implementsNewRefreshMethod()) { TN refreshed = null; if (fullRefreshCurrent && !this.isRoot()) { TreeNode parentTreeNode = ((ExplorerNode<TN>) this.getParent()).getTreeNode(); parentTreeNode.removeSubNodes(); List<? extends TreeNode> parentSubNodes = parentTreeNode.getSubNodes(); for (TreeNode parentSubNode : parentSubNodes) { if (ObjectUtils.equals(parentSubNode.getId(), treenode.getId())) refreshed = (TN) parentSubNode; } if (refreshed == null) { this.removeFromParent(); dtm.nodeStructureChanged(this); return; } } else { refreshed = (TN) treenode.refreshed(); } setTreeNode(refreshed); } else { treenode.refresh(); } treenode.removeSubNodes(); loadChildren(true); assert getChildrenHaveBeenLoaded(); dtm.nodeStructureChanged(this); ExplorerNode.expandTreeAsync(lstExpandedPathsResult, tree); if (selected != null) { List<Object> pathEssence = CollectionUtils.asList(selected.getPath()); Collections.reverse(pathEssence); if (pathEssence.size() > 1) { pathEssence = pathEssence.subList(0, pathEssence.size() - 1); new Thread(new TreeExpander(tree, pathEssence)).start(); } } }
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./* w w w . jav a 2 s . co m*/ */ 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 w w. j av a 2 s.c o m*/ 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:view.MainWindow.java
private File getSelectedFile(JTree jtree) { String selectedFile = ""; if (jtree.getSelectionPath() != null) { Object[] paths = jtree.getSelectionPath().getPath(); for (int i = 0; i < paths.length; i++) { selectedFile += paths[i];/* w w w. j a v a2 s .c o m*/ if (!paths[i].toString().isEmpty() && i + 1 < paths.length) { selectedFile += File.separator; } } return new File(selectedFile); } else { return null; } }
From source file:view.MainWindow.java
private ArrayList<File> getMultipleSelectedFiles(JTree jtree) { ArrayList<File> aLSelectedFiles = new ArrayList<>(); if (jtree == null) { return aLSelectedFiles; }//w w 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; }
From source file:vista.MainWindow.java
/** * Borra el Fichero o Directorio (debe estar vacio) seleccionado en el JTree. *//*from w w w.j a v a 2 s . c o m*/ private boolean accionBorrar(boolean isServer, JTree tree) { try { String rutaSeleccionada = conversionJTreePath.conversion(isServer, tree.getSelectionPath().toString()); boolean res = new File(rutaSeleccionada).delete(); if (res) { System.out.println("Elemento local borrado con Exito."); return true; } else { System.out.println("No se puede borrar el Elemento local, comprueba que esta vacio."); return false; } } catch (NullPointerException ex) { System.out.println("INFO: NullPointerException al borrar sin especificar capturado."); } return false; }
From source file:vista.MainWindow.java
/** * Borrado de un Archivo o Fichero mediante FTP. * @param tree JTree de donde obtenemos el elemento seleccionado para eliminar. * @return Estado de la operacion//from w ww . j a v a 2 s . com */ private boolean borrarFTP(JTree tree) { boolean pedirConfirmacion = this.jCheckBoxMenuItemConfBorrar.getState(); String name = conversionJTreePath.conversion(false, tree.getSelectionPath().toString()); name = name.substring(name.lastIndexOf('\\') + 1); if (pedirConfirmacion) { if (JOptionPane.showConfirmDialog(this, "Seguro?") == 0) return Red.borrarFTP(name); } else return Red.borrarFTP(name); return false; }
From source file:vista.MainWindow.java
/** * Crea un directorio dentro del item seleccionado en el JTree pasado como parametro. * @return Estado de la operacion.//from w w w .j ava2 s . c o m */ private boolean crearDirectorioLocal(JTree jtree) { try { String rutaSeleccionada = conversionJTreePath.conversion(false, jtree.getSelectionPath().toString()); String nombre = JOptionPane.showInputDialog("Introduce el nombre de la Carpeta."); if (nombre != null) { boolean res = new File(rutaSeleccionada + "\\" + nombre).mkdir(); if (res) System.out.println("Directorio Local Creado con Exito."); else System.out.println("Problemas con la creacion de un directorio local."); return res; } return false; } catch (NullPointerException ex) { System.out.println("INFO: NullPointerException al crear directorio sin ruta capturado."); } return false; }