List of usage examples for javax.swing.tree TreeModel getChildCount
public int getChildCount(Object parent);
parent
. From source file:Main.java
/** * Returns the node with the given text below the given node in the specified TreeModel * @param model/*from ww w . ja va 2s . c o m*/ * 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);/*from w ww .ja va 2 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 . ja v a 2s .c o m return children.iterator(); }
From source file:it.unibas.spicygui.controllo.datasource.operators.CreaWidgetAlberi.java
private void analisiRicorsiva(TreeModel model, Object root) { contatore++;//ww w.j av a2 s . c om 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: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 w w w . j a va 2 s .com 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 {//w ww . java2 s. c om 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;// w ww . j a v a2 s. co m 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);/*from www . j ava 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. * // w ww . j a v a 2 s .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); } } } }
From source file:org.pentaho.reporting.designer.core.ReportDesignerFrame.java
private void insertReports(final TreeModel model, final Object currentLevel, final XulMenupopup popup) throws XulException { final int childCount = model.getChildCount(currentLevel); for (int i = 0; i < childCount; i += 1) { final ReportDesignerView frame = context.getView(); final Object child = model.getChild(currentLevel, i); if (model.isLeaf(child)) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) child; final File file = new File(String.valueOf(node.getUserObject())); final OpenSampleReportAction action = new OpenSampleReportAction(file, node.toString()); action.setReportDesignerContext(context); popup.addChild(frame.createMenuItem(action)); } else {//from w ww .j a v a 2s.c o m final XulMenupopup childPopup = frame.createPopupMenu(String.valueOf(child), popup); insertReports(model, child, childPopup); } } }