List of usage examples for javax.swing.tree TreeModel getChild
public Object getChild(Object parent, int index);
parent
at index index
in the parent's child array. From source file:Main.java
/** * Returns the node with the given text below the given node in the specified TreeModel * @param model//w w w .j av a 2 s . c om * the TreeModel to search * @param node * the node to search below * @param text * the text associated with the required node * @return * the required node, if found; otherwise null */ static Object findChildNode(TreeModel model, Object node, String text) { for (int i = 0; i < model.getChildCount(node); i++) { Object currNode = model.getChild(node, i); if (currNode.toString() != null && currNode.toString().equals(text)) return currNode; } return null; }
From source file:Main.java
private static void appendTreeNodes(TreeModel model, Object node, StringBuilder builder, String indent) { builder.append(NEWLINE);//www .ja va2 s . c om builder.append(indent); if (node instanceof Component) { builder.append(node.toString()); appendComponentStructure((Component) node, builder, "| " + indent); } else { builder.append(node.toString()); builder.append(" ("); appendClassDerivation(node, builder); builder.append(")"); } for (int i = 0; i < model.getChildCount(node); i++) appendTreeNodes(model, model.getChild(node, i), builder, "| " + indent); }
From source file:org.robotframework.swing.tree.TreePathWaitable.java
private Iterator<Object> getChildren(Object node) { TreeModel model = treeOperator.getModel(); int childCount = model.getChildCount(node); List<Object> children = new ArrayList<Object>(childCount); for (int i = 0; i < childCount; i++) { children.add(model.getChild(node, i)); }/* w w w .j a v a 2 s .c om*/ return children.iterator(); }
From source file:it.unibas.spicygui.controllo.datasource.operators.CreaWidgetAlberi.java
private void analisiRicorsiva(TreeModel model, Object root) { contatore++;//from ww w. j a v a 2 s .com int indice = model.getChildCount(root); if (indice == 0) { Integer numeroFoglia = contatore /* -1 */; listaFoglie.add(numeroFoglia); if (logger.isDebugEnabled()) { logger.debug(root); } return; } for (int i = 0; i < indice; i++) { analisiRicorsiva(model, model.getChild(root, i)); } }
From source file:dotaSoundEditor.Controls.EditorPanel.java
protected TreeModel buildSoundListTree(TreeModel scriptTree) { TreeNode rootNode = (TreeNode) scriptTree.getRoot(); int childCount = rootNode.getChildCount(); TreeModel soundListTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode("root")); ArrayList<String> wavePathsList = new ArrayList<>(); for (int i = 0; i < childCount; i++) { String nodeValue = scriptTree.getChild(rootNode, i).toString(); if (nodeValue.trim().startsWith("//")) { continue; }/*from w w w. jav a 2s.c o m*/ wavePathsList = getWavePathsAsList((TreeNode) scriptTree.getChild(rootNode, i)); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(nodeValue); for (String s : wavePathsList) { DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(s); newNode.add(tempNode); } ((DefaultMutableTreeNode) soundListTreeModel.getRoot()).add(newNode); } return soundListTreeModel; }
From source file:eu.apenet.dpt.standalone.gui.hgcreation.LevelTreeActions.java
private Element createArchdesc(Document doc, TreeModel model, Object node, HashMap<String, String> paramMap, String id, String title) { CLevelTreeObject obj = (CLevelTreeObject) ((DefaultMutableTreeNode) node).getUserObject(); Element archdesc = doc.createElement("archdesc"); archdesc.setAttribute("level", "fonds"); archdesc.setAttribute("type", "holdings_guide"); archdesc.setAttribute("encodinganalog", "3.1.4"); archdesc.setAttribute("relatedencoding", "ISAD(G)v2"); Element did = doc.createElement("did"); Element unitid = doc.createElement("unitid"); unitid.setAttribute("encodinganalog", "3.1.1"); unitid.setTextContent(id);/*from www . j ava 2 s . c om*/ Element unittitle = doc.createElement("unittitle"); unittitle.setAttribute("encodinganalog", "3.1.2"); unittitle.setTextContent(title); Element dsc = doc.createElement("dsc"); did.appendChild(unitid); did.appendChild(unittitle); archdesc.appendChild(did); if (!obj.getDescription().equals("")) { Element scopecontent = doc.createElement("scopecontent"); scopecontent.setAttribute("encodinganalog", "summary"); Element pElt = doc.createElement("p"); pElt.setTextContent(obj.getDescription()); scopecontent.appendChild(pElt); archdesc.appendChild(scopecontent); } archdesc.appendChild(dsc); for (int i = 0; i < model.getChildCount(node); i++) { dsc.appendChild(createTree(doc, model, model.getChild(node, i), paramMap)); } return archdesc; }
From source file:eu.apenet.dpt.standalone.gui.hgcreation.LevelTreeActions.java
private Node createTree(Document doc, TreeModel model, Object node, HashMap<String, String> paramMap) { CLevelTreeObject obj = (CLevelTreeObject) ((DefaultMutableTreeNode) node).getUserObject(); if (obj.isFile()) { File file = obj.getFile(); try {/*from w w w .j av a 2 s . co m*/ File outputFileTmp = new File(Utilities.TEMP_DIR + ".temp_HG.xml"); FileWriter fileWriter = new FileWriter(outputFileTmp); InputStream xslIs = TransformationTool.class.getResourceAsStream("/xsl/fa2hg.xsl"); Source xsltSource = new StreamSource(xslIs); StringWriter stringWriter = new StringWriter(); StringWriter xslMessages = TransformationTool.createTransformation( fileUtil.readFileAsInputStream(file), stringWriter, xsltSource, paramMap); fileWriter.write(stringWriter.toString()); fileWriter.close(); List<String> filesWithoutEadid = new ArrayList<String>(); if (xslMessages != null && xslMessages.toString().contains("NO_EADID_IN_FILE")) { filesWithoutEadid.add(file.getName()); } else { Reader reader = new FileReader(outputFileTmp); ReaderInputStream readerInputStream = new ReaderInputStream(reader, "UTF-8"); Node fileLevel = stringToNode(doc, readerInputStream); return fileLevel; // el.getParentNode().appendChild(fileLevel); } outputFileTmp.delete(); } catch (Exception e) { LOG.error("Could not create HG part for file: " + file.getName(), e); // createErrorOrWarningPanel(e, true, "Could not create HG"); } } else { Element el = doc.createElement("c"); Element did = doc.createElement("did"); if (!obj.getId().equals("")) { Element unitid = doc.createElement("unitid"); unitid.setAttribute("encodinganalog", "3.1.1"); unitid.setTextContent(obj.getId()); did.appendChild(unitid); } Element title = doc.createElement("unittitle"); title.setAttribute("encodinganalog", "3.1.2"); title.setTextContent(obj.getName()); did.appendChild(title); el.appendChild(did); if (!obj.getDescription().equals("")) { Element scopecontent = doc.createElement("scopecontent"); scopecontent.setAttribute("encodinganalog", "summary"); Element pElt = doc.createElement("p"); pElt.setTextContent(obj.getDescription()); scopecontent.appendChild(pElt); el.appendChild(scopecontent); } for (int i = 0; i < model.getChildCount(node); i++) { Object child = model.getChild(node, i); el.appendChild(createTree(doc, model, child, paramMap)); } return el; } return null; }
From source file:org.alfresco.repo.jive.impl.MockJiveService.java
private final static TreeNode findNodeById(final TreeModel tree, final DefaultMutableTreeNode node, final long communityId) { TreeNode result = null;/*from w ww . j av a 2 s . c om*/ if (node != null) { JiveCommunity community = (JiveCommunity) node.getUserObject(); if (community != null && community.getId() == communityId) { result = node; } else { int childCount = tree.getChildCount(node); if (childCount > 0) { for (int i = 0; i < childCount; i++) { // Recursion result = findNodeById(tree, (DefaultMutableTreeNode) tree.getChild(node, i), communityId); // Termination condition if (result != null) { break; } } } } } return (result); }
From source file:org.kepler.gui.OntLibrarySearcher.java
private void buildHashTable(NamedObj parent, TreeModel model) { for (int i = 0; i < model.getChildCount(parent); i++) { NamedObj child = (NamedObj) model.getChild(parent, i); _pathStack.push(child);//w ww.j a v a 2s.c o m if (model.isLeaf(child)) { Iterator<String> iter = getIds(child).iterator(); while (iter.hasNext()) { TreePath path = new TreePath(_pathStack.toArray()); hashTablePut(iter.next(), path); } } else { buildHashTable(child, model); } _pathStack.pop(); } }
From source file:org.kepler.gui.SimpleLibrarySearcher.java
/** * Search the tree model and add any components that match any of the * supplied KeplerLSIDs to the results. This method does not match * EntityLibraries but only checks leaf nodes that are ComponentEntities. * //from w w w . j ava 2s.c o m * @param lsids * @param model */ private void findLiids(Vector<Integer> liids, TreeModel model) { if (isDebugging) log.debug("findLsids(" + liids + " " + model.getRoot() + ""); Object o = model.getRoot(); // start from the root _pathStack = new Stack<Object>(); _pathStack.push(o); for (int i = 0; i < model.getChildCount(o); i++) { Object child = model.getChild(o, i); if (child instanceof NamedObj) { NamedObj nobjChild = (NamedObj) child; String name = nobjChild.getName(); if (name.startsWith("_")) continue; _pathStack.push(child); if (nobjChild instanceof EntityLibrary) { findLiids(liids, (EntityLibrary) nobjChild); } else if (nobjChild instanceof ComponentEntity) { checkLiid((ComponentEntity) nobjChild, liids); } } } }