List of usage examples for javax.swing.tree DefaultMutableTreeNode getLevel
public int getLevel()
From source file:org.company.processmaker.TreeFilesTopComponent.java
public TreeFilesTopComponent() { initComponents();//from ww w . j a v a 2 s .co 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.kuali.test.comparators.SqlHierarchyComparator.java
@Override public int compare(TableData o1, TableData o2) { int retval = 0; if (StringUtils.isBlank(o1.getForeignKeyName())) { retval = -1;/*from w w w .j a v a2 s .co m*/ } else if (StringUtils.isBlank(o2.getForeignKeyName())) { retval = 1; } else { DefaultMutableTreeNode tn1 = o1.getTreeNode(); DefaultMutableTreeNode tn2 = o2.getTreeNode(); if ((tn1 != null) && (tn2 != null)) { Integer i1 = Integer.valueOf(tn1.getLevel()); Integer i2 = Integer.valueOf(tn2.getLevel()); retval = i1.compareTo(i2); } if (retval == 0) { retval = o1.getName().compareTo(o2.getName()); } } return retval; }
From source file:org.openconcerto.erp.model.RubriquePayeTree.java
public RubriquePayeTree() { super();//from w w w . j a va 2s. c o m this.setModel(model); DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer(); renderer.setOpenIcon(null); renderer.setClosedIcon(null); renderer.setLeafIcon(null); this.setCellRenderer(renderer); DefaultMutableTreeNode currentNode = ((DefaultMutableTreeNode) this.getModel().getRoot()).getNextNode(); do { if (currentNode.getLevel() == 1) this.expandPath(new TreePath(currentNode.getPath())); currentNode = currentNode.getNextNode(); } while (currentNode != null); }
From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java
public void updateP2PThumbnail(SearchResult result) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) getjTreeResults().getLastSelectedPathComponent(); if (node == null) { return;//www .jav a 2 s. com } Object nodeInfo = null; DefaultMutableTreeNode nodeLeaf = null; if (node.getLevel() == 4 || (node.isLeaf() && node.getLevel() > 1)) { Object nodeInfoLeaf = null; if (node.getLevel() == 4) { nodeLeaf = node.getFirstLeaf(); nodeInfoLeaf = nodeLeaf.getUserObject(); } else { // Leaf nodeInfo = node.getUserObject(); nodeLeaf = node; nodeInfoLeaf = nodeInfo; } //SearchResult r = (SearchResult) nodeInfoLeaf; if (nodeInfoLeaf == result) { showThumbnail(result.getExtrafields().get("Thumbnail")); } } }
From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java
private void jTreeResultsValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jTreeResultsValueChanged DefaultMutableTreeNode node = (DefaultMutableTreeNode) getjTreeResults().getLastSelectedPathComponent(); if (node == null) { return;/*w ww.j av a 2 s . c o m*/ } this.jButtonDownload.setEnabled(false); Object nodeInfo = null; DefaultMutableTreeNode nodeLeaf = null; if (node.getLevel() == 4 || (node.isLeaf() && node.getLevel() > 1)) { Object nodeInfoLeaf = null; if (node.getLevel() == 4) { nodeLeaf = node.getFirstLeaf(); nodeInfoLeaf = nodeLeaf.getUserObject(); } else { // Leaf nodeInfo = node.getUserObject(); nodeLeaf = node; nodeInfoLeaf = nodeInfo; } SearchResult r = (SearchResult) nodeInfoLeaf; Hashtable extras = r.getExtrafields(); String thumb = (String) extras.get("Thumbnail"); //System.out.println("Filename: " + r.getFileName()); //System.out.println("FileHash: " + r.getFileHash()); if (thumb != null) { showThumbnail(thumb); } else if (!SearchResult.class.isInstance(nodeInfoLeaf) && SearchResult.class.isInstance(nodeInfoLeaf)) { SearchResult res = searchTree.searchThumbnail(r.getFileName(), r.getFileHash()); if (res != null) { Hashtable extras2 = res.getExtrafields(); if (extras2 != null) { thumb = (String) extras2.get("Thumbnail"); if (thumb != null) { extras.put("Thumbnail", thumb); // put the thumbnail in the original SearchResult showThumbnail(thumb); } else { cleanThumbnails(); } } } } else if (SearchResult.class.isInstance(nodeInfoLeaf)) { searchTree.searchP2PThumbnail((SearchResult) r); cleanThumbnails(); } else { cleanThumbnails(); } } else { cleanThumbnails(); } //Controll the enable buttons if (node.isLeaf()) { jButtonDump.setEnabled(true); IPluginControllerUser plugins = null; try { plugins = this.clientCore.getUser().getPluginController(); if ((SearchResult) nodeInfo == null) { } if (!plugins.isLocalPlugin(((SearchResult) nodeInfo).getPluginName())) { jButtonDownload.setEnabled(true); jButtonSend.setEnabled(false); } else { jButtonSend.setEnabled(true); jButtonView.setEnabled(true); } } catch (RemoteException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } else { jButtonDump.setEnabled(false); jButtonDownload.setEnabled(false); jButtonView.setEnabled(false); jButtonSend.setEnabled(true); } }
From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java
/** * Checks if the options form is displayed * @return true if not displaying, true otherwise */// ww w .java 2 s . c om private void showMetaData() { /** * Just show metadata for now **/ DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeResults.getLastSelectedPathComponent(); if (node != null && node.isLeaf() && node.getLevel() > 3) { Object nodeInfo = node.getUserObject(); SearchResult fileInfo = (SearchResult) nodeInfo; if (nodeInfo instanceof SearchResult) { IndexedMetaData metadataWindow = new IndexedMetaData(fileInfo, this); metadataWindow.setVisible(true); metadataWindow.toFront(); } } }
From source file:streamme.visuals.Main.java
public void askTree() { if (client == null) { this.setMessage("Connect first..."); return;//from w w w .j a v a2 s . c o m } this.setMessage("Asking path..."); askedFiles = true; new Thread() { @Override public void run() { JSONArray json = client.askJSON(); tree_model = (DefaultTreeModel) tree_files.getModel(); //DefaultMutableTreeNode allNode = (DefaultMutableTreeNode) new DefaultMutableTreeNode("Folders"); //tree_model.setRoot(allNode); DefaultMutableTreeNode allNode = (DefaultMutableTreeNode) tree_model.getRoot(); allNode.removeAllChildren(); tree_model.reload(); for (Object obj : json) { JSONObject jsonObj = (JSONObject) obj; fillTree(jsonObj, allNode); } DefaultMutableTreeNode currentNode = allNode; while (currentNode != null) { if (currentNode.getLevel() == 0) tree_files.expandPath(new javax.swing.tree.TreePath(currentNode.getPath())); currentNode = currentNode.getNextNode(); } setMessage("Path loaded"); } }.start(); }