public void addHijos(DefaultMutableTreeNode nodo) { if (nodo.getChildCount() != 0) { nodo.removeAllChildren(); } Vector<String> ListaDir = new Vector<String>(); Vector<String> ListaArch = new Vector<String>(); DefaultMutableTreeNode upNode = (nodo.isRoot()) ? nodo : (DefaultMutableTreeNode) nodo.getParent(); String Ruta = nodo.getUserObject().toString(); while (!upNode.isRoot()) { Ruta = upNode.getUserObject().toString() + "\\" + Ruta; upNode = (DefaultMutableTreeNode) upNode.getParent(); } try { Process sysCall; BufferedReader br; String s = ""; String strCmd = "cmd /c cd " + localDir + "\\" + Ruta + " & dir"; System.out.println(strCmd); sysCall = Runtime.getRuntime().exec(strCmd); br = new BufferedReader(new InputStreamReader(sysCall.getInputStream())); while ((s = br.readLine()) != null) { System.out.println(s); int indexArch = " ".length(); if (s.contains("<DIR>")) { int indexDir = s.indexOf("<DIR>") + "<DIR>".length() + 1; String nomDir = s.substring(indexDir); ListaDir.add(nomDir.trim()); } else { String nomArch = (s.length() > indexArch) ? s.substring(indexArch) : s; ListaArch.add(nomArch); } } ListaDir = new Vector<String>(ListaDir.subList(2, ListaDir.size())); ListaArch = new Vector<String>(ListaArch.subList(5, ListaArch.size() - 2)); int i; for (i = 0; i < ListaDir.size(); i++) { DefaultMutableTreeNode hijo = new DefaultMutableTreeNode(ListaDir.get(i).toString()); nodo.add(hijo); } for (i = 0; i < ListaArch.size(); i++) { DefaultMutableTreeNode hijo = new DefaultMutableTreeNode(ListaArch.get(i).toString()); nodo.add(hijo); } ListaArchSup.addAll(ListaArch); ListaDirSup.addAll(ListaDir); } catch (Exception e) { } }
public synchronized void updateCategory(ViewerType type, HashSet<String> names) { final DefaultMutableTreeNode node; Enumeration<TreePath> userPath = getExpandedDescendants(); switch (type) { case STAFF: staff.removeAllChildren(); node = staff; break; case ADMIN: admins.removeAllChildren(); node = admins; break; case MOD: mods.removeAllChildren(); node = mods; break; case VIEWER: viewers.removeAllChildren(); node = viewers; break; case GLOBAL_MOD: global_mods.removeAllChildren(); node = global_mods; break; default: node = null; break; } if (node != null) { if (!names.isEmpty()) { names.stream().sorted().forEach(s -> node.add(new DefaultMutableTreeNode(s))); } updateRoot(userPath); } }
@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()); }
public synchronized void resetRoot() { if (tableModelListener != null) { int nodeFoundSetsSize = nodeFoundSets.size(); for (int i = 0; i < nodeFoundSetsSize; i++) { if (nodeFoundSets.get(i) instanceof ISwingFoundSet) { ((ISwingFoundSet) nodeFoundSets.get(i)).removeTableModelListener(tableModelListener); } } } nodeFoundSets.clear(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) getRoot(); removeModificationListenerRecursiv(root); // remove all nodes modification listeners root.removeAllChildren(); DefaultMutableTreeNode child; ArrayList rootFoundSets = bindingInfo.getRootFoundSets(); IFoundSet rootFs; for (int j = 0; j < rootFoundSets.size(); j++) { rootFs = (IFoundSet) rootFoundSets.get(j); for (int i = 0; i < rootFs.getSize(); i++) { rootFs.getRecord(i); child = createChildNode(root, rootFs, i); } // check child item to detect dir/leaf status (need this for icon display) Enumeration<DefaultMutableTreeNode> childEnum = root.children(); while (childEnum.hasMoreElements()) childEnum.nextElement().isLeaf(); addListenerToFoundSet(rootFs); } }
public void update() { try { _mpd.getMPDAdmin().updateDatabase(); } catch (Exception e) { } DefaultMutableTreeNode parent = (DefaultMutableTreeNode) getRoot(); Iterator<Path> pathIter = null; Path subPath = null; MPDSong song = null; try { Iterator<MPDSong> list = _mpd.getMPDDatabase().listAllSongs().iterator(); parent.removeAllChildren(); while (list.hasNext()) { song = list.next(); pathIter = Paths.get(song.getFile()).iterator(); parent = (DefaultMutableTreeNode) getRoot(); while (pathIter.hasNext()) { subPath = pathIter.next(); if (pathIter.hasNext()) { parent = appendNode(parent, new DefaultMutableTreeNode(subPath)); } else { appendNode(parent, new DefaultMutableTreeNode(new SongContainer(song))); } } } super.reload(); } catch (Exception e) { } }
public void treeWillExpand(TreeExpansionEvent e) { // get the tree path which will be expanded TreePath path = e.getPath(); if (path == null) { return; } // get the directory at the node DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); File selDir = (File) node.getUserObject(); // remove old entries if (node.getChildCount() > 0) { node.removeAllChildren(); } // get all the subdirectories File childDirs[] = selDir.listFiles(this); if (childDirs == null) { return; } // add the subdirectories Arrays.sort(childDirs); for (int i = 0; i < childDirs.length; i++) { if (childDirs[i].isHidden()) { if (showHidden) { node.add(new DefaultMutableTreeNode(childDirs[i])); } } else { node.add(new DefaultMutableTreeNode(childDirs[i])); } } }
/** Empty the interface. */ public void resetInterface() { // Empty tree objects this.treeNodeModels.clear(); this.consoles.clear(); /* * TODO : clear properly paused processes remaining when another new * injection is run. */ // GUIMediator.model().suspendables.clear(); MediatorGUI.bottomPanel().listHTTPHeader.clear(); // Tree model for refreshing the tree DefaultTreeModel treeModel = (DefaultTreeModel) MediatorGUI.databaseTree().getModel(); // The tree root DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot(); // Delete tabs MediatorGUI.right().removeAll(); // Remove tree nodes root.removeAllChildren(); // Refresh the root treeModel.nodeChanged(root); // Refresh the tree treeModel.reload(); MediatorGUI.databaseTree().setRootVisible(true); // Empty infos tabs MediatorGUI.bottomPanel().chunkTab.setText(""); MediatorGUI.bottomPanel().binaryTab.setText(""); ((DefaultTableModel) MediatorGUI.bottomPanel().networkTable.getModel()).setRowCount(0); MediatorGUI.bottomPanel().javaTab.getProxy().setText(""); MediatorGUI.bottomPanel().networkTabHeader.setText(""); MediatorGUI.bottomPanel().networkTabParam.setText(""); MediatorGUI.bottomPanel().networkTabResponse.setText(""); MediatorGUI.bottomPanel().networkTabTiming.setText(""); MediatorGUI.bottomPanel().networkTabSource.setText(""); MediatorGUI.bottomPanel().networkTabPreview.setText(""); for (int i = 0; i < MediatorGUI.bottom().getTabCount(); i++) { Component tabComponent = MediatorGUI.bottom().getTabComponentAt(i); if (tabComponent != null) { tabComponent.setFont(tabComponent.getFont().deriveFont(Font.PLAIN)); } } MediatorGUI.left().fileManager.setButtonEnable(false); MediatorGUI.left().shellManager.setButtonEnable(false); MediatorGUI.left().sqlShellManager.setButtonEnable(false); // Default status info MediatorGUI.status().reset(); MediatorGUI.left().fileManager.changePrivilegeIcon(HelperGUI.SQUARE_GREY); MediatorGUI.left().shellManager.changePrivilegeIcon(HelperGUI.SQUARE_GREY); MediatorGUI.left().sqlShellManager.changePrivilegeIcon(HelperGUI.SQUARE_GREY); MediatorGUI.left().uploadManager.changePrivilegeIcon(HelperGUI.SQUARE_GREY); }
private static void replaceChildren( final DefaultMutableTreeNode node, final Collection<? extends ElementNode> arrayList) { node.removeAllChildren(); for (ElementNode child : arrayList) { node.add(child); } }
// reorder the nodes private void reorder(Vector nodes) { debug("reorder nodes"); // remove all the children of topNode (they'll be added back later) topNode.removeAllChildren(); // Create an array of the elements for sorting & copy the elements // into the array. DefaultMutableTreeNode[] array = new DefaultMutableTreeNode[nodes.size()]; nodes.copyInto(array); // Sort the array (Quick Sort) quickSort(array, 0, array.length - 1); // Reload the topNode. Everthing is in order now. for (int i = 0; i < array.length; i++) { topNode.add((DefaultMutableTreeNode) array[i]); } // Tell the tree to repaint itself ((DefaultTreeModel) tree.getModel()).reload(); tree.invalidate(); tree.repaint(); }
/** * Reloads data from new model, creates new search engine to search in new model if model contains * view with the same name */ private void reloadData(HelpModel model) { debug("reloadData using new model"); helpsearch = null; SearchView view = null; newHelpSet = model.getHelpSet(); SearchView oldView = (SearchView) searchnav.getNavigatorView(); String oldName = oldView.getName(); NavigatorView[] navViews = newHelpSet.getNavigatorViews(); for (int i = 0; i < navViews.length; i++) { if ((navViews[i].getName()).equals(oldName)) { NavigatorView tempView = navViews[i]; if (tempView instanceof SearchView) { view = (SearchView) tempView; break; } } } if (view == null) return; topNode.removeAllChildren(); searchnav.setSearchEngine(new MergingSearchEngine(view)); setCellRenderer(view, tree); // add all subhelpsets addSubHelpSets(newHelpSet); }
private void populateNetworkTree() { DefaultTreeModel tree = (DefaultTreeModel) networkJTree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getRoot(); root.removeAllChildren(); DefaultMutableTreeNode networkNode; DefaultMutableTreeNode stateNode; DefaultMutableTreeNode cityNode; ArrayList<Network> networkList = system.getNetworkList(); for (int i = 0; i < networkList.size(); i++) { Network country = networkList.get(i); networkNode = new DefaultMutableTreeNode(country.getNetworkname()); root.insert(networkNode, i); ArrayList<Network> stateList = country.getSubnetworklist(); DefaultMutableTreeNode enterpriseNode; for (int j = 0; j < stateList.size(); j++) { Network state = stateList.get(j); stateNode = new DefaultMutableTreeNode(state.getNetworkname()); networkNode.insert(stateNode, j); ArrayList<Network> cityList = state.getSubnetworklist(); for (int k = 0; k < cityList.size(); k++) { Network city = cityList.get(k); cityNode = new DefaultMutableTreeNode(city.getNetworkname()); stateNode.insert(cityNode, k); } } } tree.reload(); }
public void exploreBean(DefaultMutableTreeNode root, String classname, String parentPath) { try { root.removeAllChildren(); if (parentPath.length() > 0) parentPath += "."; MainFrame.reportClassLoader.rescanLibDirectory(); Class clazz = Class.forName(classname, true, MainFrame.reportClassLoader); java.beans.PropertyDescriptor[] pd = org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptors(clazz); for (int nd = 0; nd < pd.length; ++nd) { String fieldName = pd[nd].getName(); if (pd[nd].getPropertyType() != null && pd[nd].getReadMethod() != null) { String returnType = pd[nd].getPropertyType().getName(); it.businesslogic.ireport.JRField field = new it.businesslogic.ireport.JRField(Misc.getJRFieldType(fieldName), returnType); if (isPathOnDescription()) { field.setDescription(parentPath + fieldName); } else { field.setName(parentPath + fieldName); } TreeJRField jtf = new TreeJRField(); jtf.setField(field); jtf.setObj(pd[nd].getPropertyType()); boolean bChildrens = true; if (pd[nd].getPropertyType().isPrimitive() || pd[nd].getPropertyType().getName().startsWith("java.lang.")) { bChildrens = false; } root.add(new DefaultMutableTreeNode(jtf, bChildrens)); } } jTree1.expandPath(new TreePath(root.getPath())); jTree1.updateUI(); } catch (ClassNotFoundException cnf) { javax.swing.JOptionPane.showMessageDialog( this, I18n.getFormattedString( "messages.BeanInspectorPanel.classNotFoundError", "Class not found error!!\nCheck your classpath and retry!\n{0}", new Object[] {cnf.getMessage()}), I18n.getString("message.title.error", "Error"), javax.swing.JOptionPane.ERROR_MESSAGE); return; } catch (Exception ex) { javax.swing.JOptionPane.showMessageDialog( this, ex.getMessage(), I18n.getString("message.title.error", "Error"), javax.swing.JOptionPane.ERROR_MESSAGE); return; } }
/** Must be used when the combobox is not visible... */ public void setClassName(String className) { DefaultMutableTreeNode root = (DefaultMutableTreeNode) jTree1.getModel().getRoot(); root.removeAllChildren(); jTree1.updateUI(); if (className != null && className.trim().length() > 0) { exploreBean(root, className, ""); } }
public static void sort(final DefaultMutableTreeNode node, final Comparator comparator) { final List<TreeNode> children = childrenToArray(node); Collections.sort(children, comparator); node.removeAllChildren(); addChildrenTo(node, children); for (int i = 0; i < node.getChildCount(); i++) { sort((DefaultMutableTreeNode) node.getChildAt(i), comparator); } }
private void patchActionsTreeCorrespondingToSchema(DefaultMutableTreeNode root) { root.removeAllChildren(); if (mySelectedSchema != null) { mySelectedSchema.fillActionGroups(root); for (final ActionUrl actionUrl : mySelectedSchema.getActions()) { ActionUrl.changePathInActionsTree(myActionsTree, actionUrl); } } ((DefaultTreeModel) myActionsTree.getModel()).reload(); }
private void loadActions() { rootActionsNode.removeAllChildren(); loadAction(rootActionsNode, Main.main.menu); for (Map.Entry<String, Action> a : regactions.entrySet()) { if (actions.get(a.getKey()) == null) { rootActionsNode.add(new DefaultMutableTreeNode(a.getValue())); } } rootActionsNode.add(new DefaultMutableTreeNode(null)); }
public void buildTree() { top.removeAllChildren(); DefaultTreeModel model = (DefaultTreeModel) this.getModel(); top.setUserObject(new NodeData(jsonElement, "data")); model.setRoot(top); prepareElement(top, jsonElement); repaint(); setSelectionRow(0); }
private void updateCheckBoxTree() { DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.checkboxTree.getModel().getRoot(); this.checkboxTree.removeCheckingPaths(this.checkboxTree.getCheckingPaths()); root.removeAllChildren(); if (this.dateDisplay) { TreeMap<Integer, ArrayList<Game>> dateGames = new TreeMap<Integer, ArrayList<Game>>(); for (Game g : this.games) { if (!g.getTitle() .equals("SIVOX")) { // TODO A Supprimer lorsque le nouvel installeur sera en place SEUL if (!dateGames.containsKey(g.getAnnee())) { dateGames.put(g.getAnnee(), new ArrayList<Game>()); } dateGames.get(g.getAnnee()).add(g); } } for (Integer annee : dateGames.keySet()) { DefaultMutableTreeNode anneeNode = new DefaultMutableTreeNode(String.valueOf(annee)); for (Game g : dateGames.get(annee)) { anneeNode.add(new DefaultMutableTreeNode(g)); } root.add(anneeNode); } } else { TreeMap<GameCategory, ArrayList<Game>> catGames = new TreeMap<GameCategory, ArrayList<Game>>(); for (Game g : this.games) { if (!g.getTitle() .equals("SIVOX")) { // TODO A Supprimer lorsque le nouvel installeur sera en place SEUL for (GameCategory gameCat : g.getGameCategories()) { if (!catGames.containsKey(gameCat)) { catGames.put(gameCat, new ArrayList<Game>()); } catGames.get(gameCat).add(g); } } } for (GameCategory gameCat : catGames.keySet()) { DefaultMutableTreeNode gameCatNode = new DefaultMutableTreeNode(gameCat); for (Game g : catGames.get(gameCat)) { gameCatNode.add(new DefaultMutableTreeNode(g)); } root.add(gameCatNode); } } ((DefaultTreeModel) this.checkboxTree.getModel()).nodeStructureChanged(root); this.checkboxTree.expandAll(); this.validate(); }
public void appendNodes(DefaultMutableTreeNode node1, Vector vct) { Vector newvct = new Vector(); if (vct != null) { newvct = vct; node1.removeAllChildren(); } else { node1.removeAllChildren(); return; } for (int i = 0; i < vct.size(); i++) { File file = (File) newvct.get(i); FileTreeNode childnode = new FileTreeNode(file); if (file.listFiles() != null) { File[] f = file.listFiles(); for (int j = 0; j < f.length; j++) { if (f[j].isDirectory()) childnode.add(new FileTreeNode("")); } } node1.add(childnode); } }
/** * Shut the repository down. * * @param wait true, if ORB should wait for still open connections to be closed by clients. */ public void imrShutdown(boolean wait) { disableRefresh(); try { m_admin.shutdown(wait); m_top_node.removeAllChildren(); m_servers = null; } catch (Exception _e) { handleException(_e); } }
public synchronized void buildFilteredModel(String text) { filtered_root.removeAllChildren(); ArrayList<DefaultMutableTreeNode> rows = new ArrayList<>(); if (staff.getChildCount() > 0) { DefaultMutableTreeNode filtered = new DefaultMutableTreeNode("Staff"); filterNode(staff, text, filtered); if (filtered.getChildCount() > 0) { filtered_root.add(filtered); rows.add(filtered); } } if (admins.getChildCount() > 0) { DefaultMutableTreeNode filtered = new DefaultMutableTreeNode("Admins"); filterNode(admins, text, filtered); if (filtered.getChildCount() > 0) { filtered_root.add(filtered); rows.add(filtered); } } if (global_mods.getChildCount() > 0) { DefaultMutableTreeNode filtered = new DefaultMutableTreeNode("Global Moderators"); filterNode(global_mods, text, filtered); if (filtered.getChildCount() > 0) { filtered_root.add(filtered); rows.add(filtered); } } if (mods.getChildCount() > 0) { DefaultMutableTreeNode filtered = new DefaultMutableTreeNode("Moderators"); filterNode(mods, text, filtered); if (filtered.getChildCount() > 0) { filtered_root.add(filtered); rows.add(filtered); } } if (viewers.getChildCount() > 0) { DefaultMutableTreeNode filtered = new DefaultMutableTreeNode("Viewers"); filterNode(viewers, text, filtered); if (filtered.getChildCount() > 0) { filtered_root.add(filtered); rows.add(filtered); } } setViewerTreeModel(new DefaultTreeModel(filtered_root)); for (DefaultMutableTreeNode row : rows) { TreePath tp = new TreePath(row.getPath()); viewerTree.expandPath(tp); } }
/** * Set the list of SchemaClasses to be displayed in this EntityInstanceListPane. * * @param classes * @throws Exception */ public void setSchemaClasses(List<GKSchemaClass> classes, XMLFileAdaptor fileAdaptor) throws Exception { DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); root.removeAllChildren(); for (GKSchemaClass cls : classes) { Collection instances = fileAdaptor.fetchInstancesByClass(cls.getName()); // Don't add an empty class node to save space if (instances == null || instances.size() == 0) continue; DefaultMutableTreeNode clsNode = new DefaultMutableTreeNode(cls); root.add(clsNode); buildTree(instances, clsNode); } model.nodeStructureChanged(root); }
private synchronized void updateRoot(Enumeration<TreePath> userPath) { DefaultMutableTreeNode root = default_root; root.removeAllChildren(); if (staff.getChildCount() > 0) root.add(staff); if (admins.getChildCount() > 0) root.add(admins); if (global_mods.getChildCount() > 0) root.add(global_mods); if (mods.getChildCount() > 0) root.add(mods); root.add(viewers); if (!isFiltering) defaultModel.reload(root); if (userPath != null) { while (userPath.hasMoreElements()) { viewerTree.expandPath(userPath.nextElement()); } } }
/** * Generic method to add a logical operator to rule. * * @param dialog * @param operator * @return node of logical operator */ private DefaultMutableTreeNode addLogicalOperator( final CustomSearchDialog dialog, final ILogicalSearchOperator operator) { // Get selected node and parent DefaultTreeModel model = ((DefaultTreeModel) dialog.getComplexRulesTree().getModel()); DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) dialog.getComplexRulesTree().getSelectionPath().getLastPathComponent(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent(); // Create node DefaultMutableTreeNode logicalNode = new DefaultMutableTreeNode(operator); // Node is root if (parentNode == null) { // add as root model.setRoot(logicalNode); } else { // add as child of parent // remove all nodes and add again to keep order List<MutableTreeNode> nodes = new ArrayList<MutableTreeNode>(); for (int i = 0; i < parentNode.getChildCount(); i++) { nodes.add((MutableTreeNode) parentNode.getChildAt(i)); } parentNode.removeAllChildren(); for (MutableTreeNode node : nodes) { if (node.equals(selectedNode)) { parentNode.add(logicalNode); } else { parentNode.add(node); } } } // Add previous selected node as child of new logical operator node logicalNode.add(selectedNode); // Reload model model.reload(); // Expand complex rules tree to display full rule GuiUtils.expandTree(dialog.getComplexRulesTree()); // Select added node dialog.getComplexRulesTree().setSelectionPath(new TreePath(logicalNode.getPath())); return logicalNode; }
public void populateTree() { DefaultTreeModel model = (DefaultTreeModel) JTree.getModel(); ArrayList<Network> networkList = system.getNetworkList(); ArrayList<Enterprise> enterpriseList; ArrayList<Organization> organizationList; Network network; Enterprise enterprise; Organization organization; DefaultMutableTreeNode networks = new DefaultMutableTreeNode("Networks"); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); root.removeAllChildren(); root.insert(networks, 0); DefaultMutableTreeNode networkNode; DefaultMutableTreeNode enterpriseNode; DefaultMutableTreeNode organizationNode; for (int i = 0; i < networkList.size(); i++) { network = networkList.get(i); networkNode = new DefaultMutableTreeNode(network.getName()); networks.insert(networkNode, i); enterpriseList = network.getEnterpriseDirectory().getEnterpriseList(); for (int j = 0; j < enterpriseList.size(); j++) { enterprise = enterpriseList.get(j); enterpriseNode = new DefaultMutableTreeNode(enterprise.getName()); networkNode.insert(enterpriseNode, j); organizationList = enterprise.getOrganizationDirectory().getOrganizationList(); for (int k = 0; k < organizationList.size(); k++) { organization = organizationList.get(k); organizationNode = new DefaultMutableTreeNode(organization.getName()); enterpriseNode.insert(organizationNode, k); } } } model.reload(); }
private void reset( final Keymap keymap, final QuickList[] allQuickLists, String filter, @Nullable KeyboardShortcut shortcut) { myKeymap = keymap; final PathsKeeper pathsKeeper = new PathsKeeper(); pathsKeeper.storePaths(); myRoot.removeAllChildren(); ActionManager actionManager = ActionManager.getInstance(); Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myComponent)); Group mainGroup = ActionsTreeUtil.createMainGroup( project, myKeymap, allQuickLists, filter, true, ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut, filter, true)); if ((filter != null && filter.length() > 0 || shortcut != null) && mainGroup.initIds().isEmpty()) { mainGroup = ActionsTreeUtil.createMainGroup( project, myKeymap, allQuickLists, filter, false, ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut, filter, false)); } myRoot = ActionsTreeUtil.createNode(mainGroup); myMainGroup = mainGroup; MyModel model = (MyModel) myTree.getModel(); model.setRoot(myRoot); model.nodeStructureChanged(myRoot); pathsKeeper.restorePaths(); }
private void updateTree() { // Create a tree that allows one selection at a time top.removeAllChildren(); HashMap<String, DefaultMutableTreeNode> paletteNodes = new HashMap<>(); for (ObjectType type : ObjectType.getAll()) { if (!type.isDragAndDrop()) continue; String pName = type.getPaletteName(); DefaultMutableTreeNode palNode = paletteNodes.get(pName); if (palNode == null) { palNode = new DefaultMutableTreeNode(pName, true); paletteNodes.put(pName, palNode); top.add(palNode); } DefaultMutableTreeNode classNode = new DefaultMutableTreeNode(type, true); palNode.add(classNode); } treeModel.reload(top); }
/** remove all from the tree */ protected void clearTree() { switch (getTreeMode()) { case DEPENDENCY: indNode.removeAllChildren(); depNode.removeAllChildren(); auxiliaryNode.removeAllChildren(); break; case TYPE: rootType.removeAllChildren(); typeNodesMap.clear(); break; case LAYER: rootLayer.removeAllChildren(); layerNodesMap.clear(); break; case ORDER: rootOrder.removeAllChildren(); } }
/** * Repopulates the contents of the tree. * * @param tree the tree to be repopulated. */ private void repopulateTree(JTree tree) { ignoreSelectionEvents = true; final Point currentPosition = treeScroll.getViewport().getViewPosition(); DefaultMutableTreeNode root = getRoot(tree); TreePath path = tree.getSelectionPath(); DefaultMutableTreeNode lastSelectedNode = null; if (path != null) { lastSelectedNode = (DefaultMutableTreeNode) path.getLastPathComponent(); } TreePath newSelectionPath = null; BackendDescriptor backend = null; String backendName = (String) backends.getSelectedItem(); if (backendName != null) { for (BackendDescriptor b : getInfo().getServerDescriptor().getBackends()) { if (b.getBackendID().equalsIgnoreCase(backendName)) { backend = b; break; } } } ArrayList<ArrayList<? extends AbstractIndexTreeNode>> nodes = new ArrayList<ArrayList<? extends AbstractIndexTreeNode>>(); ArrayList<IndexTreeNode> standardIndexNodes = new ArrayList<IndexTreeNode>(); ArrayList<VLVIndexTreeNode> vlvIndexNodes = new ArrayList<VLVIndexTreeNode>(); nodes.add(standardIndexNodes); nodes.add(vlvIndexNodes); if (backend != null) { for (IndexDescriptor index : backend.getIndexes()) { standardIndexNodes.add(new IndexTreeNode(index.getName(), index)); } for (VLVIndexDescriptor index : backend.getVLVIndexes()) { vlvIndexNodes.add(new VLVIndexTreeNode(index.getName(), index)); } } DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); int i = 0; int positionUnderRoot = 0; for (DefaultMutableTreeNode parent : categoryNodes) { if (nodes.get(i).size() == 0) { if (root.getIndex(parent) != -1) { model.removeNodeFromParent(parent); parent.removeAllChildren(); } } else { boolean expand = true; if (root.getIndex(parent) == -1) { model.insertNodeInto(parent, root, positionUnderRoot); } else { expand = tree.isExpanded(new TreePath(parent)) || (parent.getChildCount() == 0); parent.removeAllChildren(); } for (AbstractIndexTreeNode node : nodes.get(i)) { parent.add(node); if ((newSelectionPath == null) && ((lastSelectedNode != null) || (lastCreatedIndex != null))) { if (lastCreatedIndex != null) { if ((node instanceof IndexTreeNode) && (lastCreatedIndex instanceof IndexDescriptor)) { if (node.getName().equals(lastCreatedIndex.getName())) { newSelectionPath = new TreePath(node.getPath()); lastCreatedIndex = null; } } else if ((node instanceof VLVIndexTreeNode) && (lastCreatedIndex instanceof VLVIndexDescriptor)) { if (node.getName().equals(lastCreatedIndex.getName())) { newSelectionPath = new TreePath(node.getPath()); lastCreatedIndex = null; } } } else if (node.getName().equals(lastSelectedNode.getUserObject())) { newSelectionPath = new TreePath(node.getPath()); } } } model.nodeStructureChanged(parent); if (expand) { tree.expandPath(new TreePath(parent.getPath())); } positionUnderRoot++; } i++; } if (newSelectionPath == null) { if (firstTreeRepopulate) { newSelectionPath = new TreePath(standardIndexes.getPath()); } } if (newSelectionPath != null) { tree.setSelectionPath(newSelectionPath); tree.scrollPathToVisible(newSelectionPath); } updateEntryPane(); SwingUtilities.invokeLater( new Runnable() { public void run() { if (firstTreeRepopulate) { treeScroll.getViewport().setViewPosition(new Point(0, 0)); } else { treeScroll.getViewport().setViewPosition(currentPosition); } } }); firstTreeRepopulate = false; ignoreSelectionEvents = false; }
private void clearNode(DefaultMutableTreeNode node) { while (node.getChildCount() > 0) { node.removeAllChildren(); } }