List of usage examples for javax.swing.tree TreeNode toString
public String toString()
From source file:com.mirth.connect.client.ui.components.MirthTree.java
/** * Get the index of a node in relation to other nodes with the same name. Returns -1 if there * isn't an index./*from www . jav a2 s .c om*/ * * @param node * @return */ public static int getIndexOfNode(TreeNode node) { String nodeName = node.toString().replaceAll(" \\(.*\\)", ""); // Get the node name without the vocab TreeNode parent = node.getParent(); // The parent will be null for the root node if (parent != null) { Enumeration children = parent.children(); int indexCounter = 0; int foundIndex = -1; // Look through all of the children of the parent to see if there // are multiple children with the same name. while (children.hasMoreElements()) { TreeNode child = (TreeNode) children.nextElement(); // Ignore the draggable nodes that have no children if (child.getChildCount() > 0) { if (nodeName.equals(child.toString().replaceAll(" \\(.*\\)", ""))) { if (child != node) { indexCounter++; } else { foundIndex = indexCounter; indexCounter++; } } } } // If there were multiple children, add the index to the nodeQ. if (indexCounter > 1) { return foundIndex; } } return -1; }
From source file:Main.java
@Override public String toString() { TreeNode parent = getParent(); if (parent == null) { return String.valueOf(outlineNum); } else {//from www . ja v a 2 s. c o m return parent.toString() + "." + outlineNum; } }
From source file:TreeUtil.java
public void addNode(String name, Object obj) { itsMap.put(name, obj);/*w w w . j a v a 2 s. com*/ DefaultMutableTreeNode tempNode = itsRootNode; StringTokenizer tok = new StringTokenizer(name, "."); String currentName = null; while (tok.hasMoreTokens()) { String myTok = tok.nextToken(); currentName = (currentName == null) ? myTok : currentName + "." + myTok; boolean createNew = true; for (int j = 0; j < tempNode.getChildCount(); j++) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) tempNode.getChildAt(j); if (childNode.toString().equals(myTok)) { tempNode = childNode; createNew = false; break; } } if (createNew) { DefaultMutableTreeNode aNode = new DefaultMutableTreeNode(myTok); itsTreeMap.put(currentName, aNode); // Let's give some consideration to where in the tree we place // the new node. // We want any nodes with children to be listed first, in // alphabetical order. // Then come nodes with no children, in alphabetical order. if (tok.hasMoreTokens()) { // This node is not a leaf node int targeti; for (targeti = 0; targeti < tempNode.getChildCount(); targeti++) { TreeNode bNode = tempNode.getChildAt(targeti); if (bNode.isLeaf() || bNode.toString().compareToIgnoreCase(myTok) > 0) { break; } } tempNode.insert(aNode, targeti); } else { // This node is a leaf node int targeti; for (targeti = 0; targeti < tempNode.getChildCount(); targeti++) { TreeNode bNode = tempNode.getChildAt(targeti); if (bNode.isLeaf() && bNode.toString().compareToIgnoreCase(myTok) > 0) { break; } } tempNode.insert(aNode, targeti); } tempNode = aNode; } } }
From source file:fi.elfcloud.client.tree.ClusterHierarchyModel.java
public void previous() { ClusterNode root = (ClusterNode) getRoot(); TreeNode parent = root.getParent(); if (parent != null) { setRoot(parent);/* ww w .j a v a 2s .c o m*/ root.removeAllChildren(); gui.updateTitle(parent.toString()); gui.allowUpload(parent != homeNode); } }
From source file:dotaSoundEditor.Controls.EditorPanel.java
protected void replaceButtonActionPerformed(ActionEvent evt) { if (currentTree.getSelectionRows() != null && currentTree.getSelectionRows().length != 0 && ((TreeNode) currentTree.getSelectionPath().getLastPathComponent()).isLeaf()) { TreeNode selectedFile = (TreeNode) currentTree.getSelectionPath().getLastPathComponent(); promptUserForNewFile(selectedFile.toString()); }// www . j av a 2 s . c o m }
From source file:org.apache.accumulo.examples.wikisearch.iterator.BooleanLogicTreeNode.java
public String buildTreePathString(TreeNode[] path) { StringBuilder s = new StringBuilder("["); for (TreeNode p : path) { s.append(p.toString()); s.append(","); }//from w w w. j a va 2 s .c o m s.deleteCharAt(s.length() - 1); s.append("]"); return s.toString(); }
From source file:org.company.processmaker.TreeFilesTopComponent.java
public TreeFilesTopComponent() { initComponents();/*from w w w .j a va 2s . c o m*/ setName(Bundle.CTL_TreeFilesTopComponent()); setToolTipText(Bundle.HINT_TreeFilesTopComponent()); // new codes instance = this; MouseListener ml = new MouseAdapter() { public void mousePressed(MouseEvent e) { int selRow = jTree1.getRowForLocation(e.getX(), e.getY()); TreePath selPath = jTree1.getPathForLocation(e.getX(), e.getY()); if (selRow != -1) { if (e.getClickCount() == 1) { //mySingleClick(selRow, selPath); } else if (e.getClickCount() == 2) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1 .getLastSelectedPathComponent(); if (node == null) { return; } Object nodeInfo = node.getUserObject(); int node_level = node.getLevel(); if (node_level < 2) { return; } // for each dyna form if (node_level == 2) { Global gl_obj = Global.getInstance(); //myDoubleClick(selRow, selPath); conf = Config.getInstance(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); String parentName = (String) parent.getUserObject(); // handle triggers if (parentName.equals("Triggers")) { String filePath = ""; for (String[] s : res_trigger) { if (s[0].equals(nodeInfo.toString())) { // get path of dyna in xml forms filePath = conf.tmp + "triggers/" + s[3] + "/" + s[2] + ".php"; break; } } File toAdd = new File(filePath); try { DataObject dObject = DataObject.find(FileUtil.toFileObject(toAdd)); dObject.getLookup().lookup(OpenCookie.class).open(); // dont listen for exist listen files if (existFile(filePath)) { return; } dObject.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { //fire a dummy event if (!Boolean.TRUE.equals(evt.getNewValue())) { /*String msg = "Saved to" + evt.toString(); NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd);*/ TopComponent activeTC = TopComponent.getRegistry() .getActivated(); DataObject dataLookup = activeTC.getLookup() .lookup(DataObject.class); String filePath = FileUtil.toFile(dataLookup.getPrimaryFile()) .getAbsolutePath(); File userFile = new File(filePath); String fileName = userFile.getName(); fileName = fileName.substring(0, fileName.lastIndexOf(".")); try { String content = new String( Files.readAllBytes(Paths.get(filePath))); // remote php tag and info "<?php //don't remove this tag! \n" content = content.substring(6, content.length()); String query = "update triggers set TRI_WEBBOT = '" + StringEscapeUtils.escapeSql(content) + "' where TRI_UID = '" + fileName + "'"; GooglePanel.updateQuery(query); } catch (Exception e) { //Exceptions.printStackTrace(e); String msg = "Can not update trigger"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } } }); } catch (DataObjectNotFoundException ex) { //Exceptions.printStackTrace(ex); String msg = "Trigger not found"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } return; } List<String[]> res_dyna = gl_obj.getDyna(); String FileDir = ""; for (String[] s : res_dyna) { if (s[1].equals(nodeInfo.toString())) { // get path of dyna in xml forms FileDir = s[3]; break; } } //String msg = "selRow" + nodeInfo.toString() + "|" + conf.getXmlForms() + FileDir; String filePath = conf.getXmlForms() + FileDir + ".xml"; if (conf.isRemote()) { String[] res = FileDir.split("/"); filePath = conf.get("local_tmp_for_remote") + "/" + FileDir + "/" + res[1] + ".xml"; } File toAdd = new File(filePath); //Result will be null if the user clicked cancel or closed the dialog w/o OK if (toAdd != null) { try { DataObject dObject = DataObject.find(FileUtil.toFileObject(toAdd)); dObject.getLookup().lookup(OpenCookie.class).open(); // dont listen for exist listen files if (existFile(filePath)) { return; } dObject.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { //fire a dummy event if (!Boolean.TRUE.equals(evt.getNewValue())) { /*String msg = "Saved to" + evt.toString(); NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd);*/ TopComponent activeTC = TopComponent.getRegistry() .getActivated(); DataObject dataLookup = activeTC.getLookup() .lookup(DataObject.class); String filePath = FileUtil.toFile(dataLookup.getPrimaryFile()) .getAbsolutePath(); File userFile = new File(filePath); String fileName = userFile.getName(); fileName = fileName.substring(0, fileName.lastIndexOf(".")); Global gl_obj = Global.getInstance(); List<String[]> res_dyna = gl_obj.getDyna(); String FileDir = ""; for (String[] s : res_dyna) { if (filePath.contains(s[0])) { FileDir = s[3]; break; } } if (conf.isRemote()) { boolean res_Upload = SSH.getInstance().uplaodFile(FileDir); if (res_Upload) { String msg = "file upload Successfully!"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } else { String msg = "error in uploading file!"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } } } }); } catch (DataObjectNotFoundException ex) { //Exceptions.printStackTrace(ex); String msg = "Can not find xml file"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } // for each js file if (node_level == 3) { TreeNode parentInfo = node.getParent(); Global gl_obj = Global.getInstance(); List<String[]> res_dyna = gl_obj.getDyna(); String FileDir = ""; for (String[] s : res_dyna) { if (s[1].equals(parentInfo.toString())) { // get path of dyna in xml forms FileDir = s[3]; break; } } //myDoubleClick(selRow, selPath); conf = Config.getInstance(); String filePath = conf.tmp + "xmlForms/" + FileDir + "/" + nodeInfo.toString() + ".js"; if (conf.isRemote()) { filePath = conf.get("local_tmp_for_remote") + FileDir + "/" + nodeInfo.toString() + ".js"; } File toAdd = new File(filePath); //Result will be null if the user clicked cancel or closed the dialog w/o OK if (toAdd != null) { try { DataObject dObject = DataObject.find(FileUtil.toFileObject(toAdd)); dObject.getLookup().lookup(OpenCookie.class).open(); // dont listen for exist listen files if (existFile(filePath)) { return; } dObject.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { //fire a dummy event if (!Boolean.TRUE.equals(evt.getNewValue())) { JTextComponent ed = EditorRegistry.lastFocusedComponent(); String jsDoc = ""; try { jsDoc = ed.getText(); } catch (Exception ex) { //Exceptions.printStackTrace(ex); String msg = "Can not get text from editor"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } TopComponent activeTC = TopComponent.getRegistry() .getActivated(); DataObject dataLookup = activeTC.getLookup() .lookup(DataObject.class); String filePath = FileUtil.toFile(dataLookup.getPrimaryFile()) .getAbsolutePath(); File userFile = new File(filePath); String fileName = userFile.getName(); fileName = fileName.substring(0, fileName.lastIndexOf(".")); Global gl_obj = Global.getInstance(); List<String[]> res_dyna = gl_obj.getDyna(); String FileDir = ""; for (String[] s : res_dyna) { if (filePath.contains(s[0])) { FileDir = s[3]; break; } } String fullPath = conf.getXmlForms() + FileDir + ".xml"; if (conf.isRemote()) { String[] res = FileDir.split("/"); fullPath = conf.get("local_tmp_for_remote") + FileDir + "/" + res[1] + ".xml"; } try { DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document mainDoc = builder.parse(fullPath); XPath xPath = XPathFactory.newInstance().newXPath(); Node startDateNode = (Node) xPath .compile("//dynaForm/" + fileName) .evaluate(mainDoc, XPathConstants.NODE); Node cdata = mainDoc.createCDATASection(jsDoc); startDateNode.setTextContent(""); startDateNode.appendChild(cdata); /*String msg = evt.getPropertyName() + "-" + fileName; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd);*/ // write the content into xml file TransformerFactory transformerFactory = TransformerFactory .newInstance(); Transformer transformer = transformerFactory .newTransformer(); DOMSource source = new DOMSource(mainDoc); StreamResult result = new StreamResult(new File(fullPath)); transformer.transform(source, result); if (conf.isRemote()) { boolean res_Upload = SSH.getInstance() .uplaodFile(FileDir); if (res_Upload) { String msg = "file upload Successfully!"; NotifyDescriptor nd = new NotifyDescriptor.Message( msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } else { String msg = "error in uploading file!"; NotifyDescriptor nd = new NotifyDescriptor.Message( msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } catch (Exception ex) { //Exceptions.printStackTrace(ex); String msg = "Can not save to xml form"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } } }); } catch (DataObjectNotFoundException ex) { //Exceptions.printStackTrace(ex); String msg = "Can not save to xml form"; NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(nd); } } } } } } }; jTree1.addMouseListener(ml); jTree1.setModel(null); }
From source file:org.olivier.ihm.FramePUMLCleanerControler.java
/** * Slectionne les noeuds dans l'arbre de filtrage corespondant au motif * @param motif Le motif pour slectionner les noeuds * @param jTreeFiltre L'arbre de filtrage *//* www . java2 s . co m*/ public void selectionnerNoeud(String motif, JTree jTreeFiltre) { // TODO : finir TreePath[] allPath = Util.getPaths(jTreeFiltre, true); // parcours des categories for (TreePath path : allPath) { // recup de la racine final DefaultMutableTreeNode root = (DefaultMutableTreeNode) path.getLastPathComponent(); // parcours des catgories for (int j = 0; j < root.getChildCount(); j++) { final TreeNode categ = root.getChildAt(j); // parcours des noeuds for (j = 0; j < categ.getChildCount(); j++) { final TreeNode unNoeudSelectionner = categ.getChildAt(j); if (!unNoeudSelectionner.toString().contains(motif)) { } } } } checkTreeManager.getSelectionModel().setSelectionPaths(allPath); }
From source file:pcgen.gui2.tabs.CompanionInfoTab.java
@Override public void adviseTodo(String fieldName) { CompanionsModel model = (CompanionsModel) companionsTable.getTreeTableModel(); CompanionsModel.RootNode root = (CompanionsModel.RootNode) model.getRoot(); for (int i = 0; i < root.getChildCount(); i++) { TreeNode node = root.getChildAt(i); if (node.toString().startsWith(fieldName)) { companionsTable.getSelectionModel().setSelectionInterval(i, i); return; }/*from ww w .j av a2s. c o m*/ } }