List of usage examples for javax.swing.tree DefaultMutableTreeNode add
public void add(MutableTreeNode newChild)
newChild
from its parent and makes it a child of this node by adding it to the end of this node's child array. From source file:org.mbari.aved.ui.classifier.knowledgebase.ConceptTree.java
/** * Loads the JTree model using the specified <code>Concept</code> as the root * node.// w w w . j av a 2 s .c om * * @param rootConcept Description of the Parameter */ public void loadModel(Concept rootConcept) { if (rootConcept == null) { setModel(null); } else { TreeConcept treeConcept = new TreeConcept(rootConcept); DefaultMutableTreeNode rootNode = new SortedTreeNode(treeConcept); // addChildrenNodes( rootNode, rootConcept ); // adding a boolean value as a child to this concept indicates that // the node has children that will be loaded dynamically, start off by // assuming this node has children, the rest will be taken care of in // the ConceptTreeLazyLoader rootNode.add(new DefaultMutableTreeNode(Boolean.TRUE)); treeConcept.lazyExpand(rootNode); DefaultTreeModel model = new DefaultTreeModel(rootNode); setModel(model); addTreeExpansionListener(new ConceptTreeLazyLoader(model)); } }
From source file:org.objectpocket.viewer.Viewer.java
private void updateTree() { DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("OBJECT STORES"); DefaultTreeModel treeModel = new DefaultTreeModel(rootNode); for (ObjectPocketImpl objectPocketImpl : objectPocketList) { DefaultMutableTreeNode objectPocketNode = new DefaultMutableTreeNode(objectPocketImpl.getSource()); rootNode.add(objectPocketNode); Set<String> availableTypes = objectPocketImpl.getAvailableTypes(); for (String type : availableTypes) { DefaultMutableTreeNode typeNode = new DefaultMutableTreeNode(type); objectPocketNode.add(typeNode); }//from www . jav a2 s . c o m } classTree.setModel(treeModel); }
From source file:org.olivier.ihm.FramePUMLCleanerControler.java
/** * Analyser le fichier PUML et initialiser le filtre * * @param jTextAreaFichier Le contenu du fichier PUML * @param jTreeFiltre Le filtre initialiser *//*from ww w .j av a2 s . c om*/ private void analyserFichier(JTextArea jTextAreaFichier, JTree jTreeFiltre) { lines = jTextAreaFichier.getText().split("[\\r\\n]+"); final DefaultMutableTreeNode newFilter = initaliserNodes(); // parcours de chaque ligne du fichier pour analyse for (String line : lines) { if (line.contains(">")) { break; } else { String categ = ""; String noeud = null; // recherche de la catgorie for (String categorie : categories) { if (line.contains(categorie)) { categ = categorie; noeud = line.replaceFirst(categorie, "").replaceAll(" ", ""); // ajout du noeud dans la bonne catgorie de l'arbre for (int i = 0; i < newFilter.getChildCount(); i++) { final DefaultMutableTreeNode dmtr = (DefaultMutableTreeNode) newFilter.getChildAt(i); if (dmtr.toString().equals(categ)) { final DefaultMutableTreeNode node = new DefaultMutableTreeNode(new NodeInfo(noeud)); dmtr.add(node); } } break; } } } } jTreeFiltre.setModel(new DefaultTreeModel(newFilter)); jTextAreaFichier.requestFocus(); }
From source file:org.olivier.ihm.FramePUMLCleanerControler.java
/** * Renvoi la liste des noeuds non slectionns * * @param allTreeNode Liste de tous les noeuds * @param selectedPath Chemins slectionns * @return Liste des noeuds non slectionns *///from www .ja v a 2 s . c o m private DefaultMutableTreeNode getNodeToDelete(DefaultMutableTreeNode allTreeNode, TreePath[] selectedPath) { final DefaultMutableTreeNode nodeToDelete = new DefaultMutableTreeNode("Node to delete"); // Parcours de l'arbre pour supprimer les noeuds slectionns // Parcours des catgories for (int i = 0; i < allTreeNode.getChildCount(); i++) { final DefaultMutableTreeNode tnCateg = (DefaultMutableTreeNode) allTreeNode.getChildAt(i); // les catgories sont systmatiquement ajoutes final DefaultMutableTreeNode newTnCateg = new DefaultMutableTreeNode(tnCateg.toString());//) allTreeNode.getChildAt(i); nodeToDelete.add(newTnCateg); // parcours des noeuds for (int j = 0; j < tnCateg.getChildCount(); j++) { final DefaultMutableTreeNode tnNoeud = (DefaultMutableTreeNode) tnCateg.getChildAt(j); // Ajout du noeud s'il n'est pas slectionn if (!isNoeudSelected(tnNoeud, selectedPath)) { /* Il est impratif de crer un nouveau noeud ! Si on se contente d'ajouter tnNoeud dans newTnCateg, celui-ci est supprim de tnCateg ! Visiblement, un noeud ne peut pas appartenir 2 arbres diffrents. Cela semble logique car la dfinition des anctres risque de poser problme. A approfondir quand j'aurai le temps ... */ final DefaultMutableTreeNode newTnNoeud = new DefaultMutableTreeNode( new NodeInfo(tnNoeud.toString())); newTnCateg.add(newTnNoeud); } } } return nodeToDelete; }
From source file:org.olivier.ihm.FramePUMLCleanerControler.java
/** * Initialiser un arbre avec les catgories * * @return L'arbre initialis/*w w w. j av a2s.com*/ */ public DefaultMutableTreeNode initaliserNodes() { DefaultMutableTreeNode top = new DefaultMutableTreeNode("PUML filter"); DefaultMutableTreeNode category = null; DefaultMutableTreeNode node = null; for (String categorie : categories) { category = new DefaultMutableTreeNode(categorie); top.add(category); } // //original Tutorial // node = new DefaultMutableTreeNode(new NodeInfo("The Java Tutorial: A Short Course on the Basics")); // category.add(node); // // //Tutorial Continued // node = new DefaultMutableTreeNode(new NodeInfo("The Java Tutorial Continued: The Rest of the JDK")); // category.add(node); // // //Swing Tutorial // node = new DefaultMutableTreeNode(new NodeInfo("The Swing Tutorial: A Guide to Constructing GUIs")); // category.add(node); // // //...add more books for programmers... // category = new DefaultMutableTreeNode("Books for Java Implementers"); // top.add(category); // // //VM // node = new DefaultMutableTreeNode(new NodeInfo("The Java Virtual Machine Specification")); // category.add(node); // // //Language Spec // node = new DefaultMutableTreeNode(new NodeInfo("The Java Language Specification")); // category.add(node); return top; }
From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java
/** * Reconstructs the requested tree from the given JSONObjects and adds it to the given Node * // w ww . j a v a2 s . com * @param node * @param jsoTree */ private void reconstructTree(DefaultMutableTreeNode node, JSONObject jsoTree) { try { JSONArray children = new JSONArray(); try { children = jsoTree.getJSONArray("children"); } catch (Exception e) { } for (int i = 0; i < children.length(); i++) { JSONObject jsoo = (JSONObject) children.get(i); OIDObject oi = new OIDObject(jsoo.getString("identifier"), jsoo.getString("name"), jsoo.getBoolean("isActive")); oi.setHasChildren(jsoo.getBoolean("hasChildren")); DefaultMutableTreeNode oin = new DefaultMutableTreeNode(oi); JSONArray tejso = new JSONArray(); try { tejso = jsoo.getJSONArray("children"); } catch (Exception e) { } if (tejso.length() != 0) { reconstructTree(oin, jsoo); } node.add(oin); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorUtilities.java
/** * Searches all children of the currentNode and adds the path to it. * /*www. ja va2 s. co m*/ * @param path * @param currentNode * @param depth * @return */ public int addNodeToModel(TreeNode[] path, TreeNode currentNode, int depth) { int chInt = currentNode.getChildCount(); int i = 0; for (; i < chInt; i++) { String currentNodeIdentifier = ((OIDObject) ((DefaultMutableTreeNode) currentNode.getChildAt(i)) .getUserObject()).getIdentifier(); String pathNodeIdentifer = ((OIDObject) ((DefaultMutableTreeNode) path[depth]).getUserObject()) .getIdentifier(); if (currentNodeIdentifier.equals(pathNodeIdentifer)) { if (depth == path.length) { return -1; //Already added, scenario never occurs. } else { addNodeToModel(path, currentNode.getChildAt(i), depth + 1); return -1; } } else if (containsOID(currentNodeIdentifier, pathNodeIdentifer)) { i = addNodeToModel(path, currentNode.getChildAt(i), depth + 1); //currentNode and pathNode share OID, continue search one level below } } //None of the children of the current node have a child sharing the OID, add the remaining path to the current Node if (i <= chInt) { int k = depth; DefaultMutableTreeNode nodeToAddTo = (DefaultMutableTreeNode) currentNode; for (; k < path.length; k++) { DefaultMutableTreeNode newNode = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) path[k]) .clone(); nodeToAddTo.add(newNode); nodeToAddTo = newNode; } return chInt + 2; } return i + chInt; }
From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorUtilities.java
/** * Sorts all Nodes and children of these Nodes by the name of their OIDObjects * //from w w w .j av a 2s . c om * @param root */ public void sortTree(DefaultMutableTreeNode root) { Vector<DefaultMutableTreeNode> childrenV = new Vector<DefaultMutableTreeNode>(); if (root.getChildCount() > 1) { for (int i = 0; i < root.getChildCount(); i++) { childrenV.add((DefaultMutableTreeNode) root.getChildAt(i)); } root.removeAllChildren(); boolean swapped = true; while (swapped) { swapped = false; for (int i = 0; i < childrenV.size() - 1; i++) { if (childrenV.elementAt(i).getChildCount() > 0) { sortTree(childrenV.elementAt(i)); } OIDObject oo1 = (OIDObject) childrenV.elementAt(i).getUserObject(); OIDObject oo2 = (OIDObject) childrenV.elementAt(i + 1).getUserObject(); DefaultMutableTreeNode node1 = childrenV.elementAt(i); DefaultMutableTreeNode node2 = childrenV.elementAt(i + 1); if (oo1.getName().compareTo(oo2.getName()) > 0) { childrenV.setElementAt(node2, i); childrenV.setElementAt(node1, i + 1); swapped = true; } } } for (int i = 0; i < childrenV.size(); i++) { root.add(childrenV.elementAt(i)); } } }
From source file:org.openengsb.ui.admin.testClient.TestClient.java
private void addDomainProvider(DomainProvider provider, DefaultMutableTreeNode node) { String providerName = provider.getName().getString(getSession().getLocale()); DefaultMutableTreeNode providerNode = new DefaultMutableTreeNode(providerName); node.add(providerNode); // add domain entry to call via domain endpoint factory ServiceId domainProviderServiceId = new ServiceId(); Class<? extends Domain> domainInterface = provider.getDomainInterface(); domainProviderServiceId.setServiceClass(domainInterface); domainProviderServiceId.setDomainName(provider.getId()); DefaultMutableTreeNode endPointReferenceNode = new DefaultMutableTreeNode(domainProviderServiceId, false); providerNode.add(endPointReferenceNode); // add all corresponding services List<? extends Domain> domainEndpoints = wiringService.getDomainEndpoints(domainInterface, "*"); for (Domain serviceReference : domainEndpoints) { String id = serviceReference.getInstanceId(); if (id != null) { ServiceId serviceId = new ServiceId(); serviceId.setServiceId(id);//from w ww .jav a 2s . c o m serviceId.setServiceClass(domainInterface); DefaultMutableTreeNode referenceNode = new DefaultMutableTreeNode(serviceId, false); providerNode.add(referenceNode); } } }
From source file:org.openengsb.ui.admin.wiringPage.WiringPage.java
@SuppressWarnings("serial") private IModel<TreeModel> createGlobalTreeModel(final Class<? extends Domain> domainType) { return new LoadableDetachableModel<TreeModel>() { @Override/* w ww . j a va 2 s.c o m*/ protected TreeModel load() { DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Globals"); if (domainType != null) { for (Entry<String, String> e : ruleManager.listGlobals().entrySet()) { if (e.getValue().equals(domainType.getCanonicalName())) { DefaultMutableTreeNode child = new DefaultMutableTreeNode(e.getKey()); rootNode.add(child); } } } return new DefaultTreeModel(rootNode); } }; }