List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject
public Object getUserObject()
From source file:org.codinjutsu.tools.jenkins.view.BrowserPanel.java
public Job getSelectedJob() { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) jobTree.getLastSelectedPathComponent(); if (treeNode != null) { Object userObject = treeNode.getUserObject(); if (userObject instanceof Job) { return (Job) userObject; }/*from w w w .j a va 2s . co m*/ } return null; }
From source file:org.codinjutsu.tools.jenkins.view.BrowserPanel.java
private void updateJobNode(Job job) { final DefaultTreeModel model = (DefaultTreeModel) jobTree.getModel(); final Object modelRoot = model.getRoot(); final int childCount = model.getChildCount(modelRoot); for (int i = 0; i < childCount; ++i) { Object child = model.getChild(modelRoot, i); if (child instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child; if (childNode.getUserObject() == job) { model.nodeChanged(childNode); break; }/* w w w . ja v a 2 s . c o m*/ } } }
From source file:org.codinjutsu.tools.jenkins.view.BrowserPanel.java
private Tree createTree(final List<JenkinsSettings.FavoriteJob> favoriteJobs) { SimpleTree tree = new SimpleTree(); tree.getEmptyText().setText(LOADING); tree.setCellRenderer(new JenkinsTreeRenderer(favoriteJobs)); tree.setName("jobTree"); tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode(jenkins))); new TreeSpeedSearch(tree, new Convertor<TreePath, String>() { @Override//from w w w. ja v a 2 s. c o m public String convert(TreePath treePath) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent(); final Object userObject = node.getUserObject(); if (userObject instanceof Job) { return ((Job) userObject).getName(); } return "<empty>"; } }); return tree; }
From source file:org.codinjutsu.tools.jenkins.view.JenkinsTreeRenderer.java
@Override public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object userObject = node.getUserObject(); if (userObject instanceof Jenkins) { Jenkins jenkins = (Jenkins) userObject; append(buildLabel(jenkins), SimpleTextAttributes.REGULAR_ITALIC_ATTRIBUTES); setToolTipText(jenkins.getServerUrl()); setIcon(SERVER_ICON);/*from w w w . j av a2 s. c o m*/ } else if (userObject instanceof Job) { Job job = (Job) node.getUserObject(); append(buildLabel(job), getAttribute(job)); setToolTipText(job.findHealthDescription()); if (isFavoriteJob(job)) { setIcon(new CompositeIcon(job.getStateIcon(), job.getHealthIcon(), FAVORITE_ICON)); } else { setIcon(new CompositeIcon(job.getStateIcon(), job.getHealthIcon())); } } else if (userObject instanceof Build) { Build build = (Build) node.getUserObject(); append(buildLabel(build), SimpleTextAttributes.REGULAR_ITALIC_ATTRIBUTES); setIcon(new CompositeIcon(build.getStateIcon())); } }
From source file:org.codinjutsu.tools.mongo.view.MongoResultPanel.java
private String stringifyResult(DefaultMutableTreeNode selectedResultNode) { List<Object> stringifiedObjects = new LinkedList<Object>(); for (int i = 0; i < selectedResultNode.getChildCount(); i++) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) selectedResultNode.getChildAt(i); stringifiedObjects.add(childNode.getUserObject()); }//from ww w.j a v a2 s . co m return String.format("[ %s ]", StringUtils.join(stringifiedObjects, " , ")); }
From source file:org.codinjutsu.tools.mongo.view.MongoTreeRenderer.java
@Override public void customizeCellRenderer(@NotNull JTree mongoTree, Object value, boolean isSelected, boolean isExpanded, boolean isLeaf, int row, boolean focus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object userObject = node.getUserObject(); if (userObject instanceof MongoServer) { MongoServer mongoServer = (MongoServer) userObject; String label = mongoServer.getLabel(); String host = StringUtils.join(mongoServer.getServerUrls(), ","); append(StringUtils.isBlank(label) ? host : label); if (MongoServer.Status.OK.equals(mongoServer.getStatus())) { setToolTipText(host);/*w w w . j av a 2s. c o m*/ setIcon(MONGO_SERVER); } else { setForeground(JBColor.RED); setIcon(MONGO_SERVER_ERROR); setToolTipText("Unable to connect"); } } else if (userObject instanceof MongoDatabase) { MongoDatabase mongoDatabase = (MongoDatabase) userObject; append(mongoDatabase.getName()); setIcon(MONGO_DATABASE); } else if (userObject instanceof MongoCollection) { MongoCollection mongoCollection = (MongoCollection) userObject; append(mongoCollection.getName()); setIcon(MONGO_COLLECTION); } }
From source file:org.codinjutsu.tools.nosql.mongo.view.MongoResultPanel.java
private String stringifyResult(DefaultMutableTreeNode selectedResultNode) { List<Object> stringifiedObjects = new LinkedList<>(); for (int i = 0; i < selectedResultNode.getChildCount(); i++) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) selectedResultNode.getChildAt(i); stringifiedObjects.add(childNode.getUserObject()); }/*from w ww .ja v a2 s . co m*/ return String.format("[ %s ]", StringUtils.join(stringifiedObjects, " , ")); }
From source file:org.codinjutsu.tools.nosql.NoSqlTreeRenderer.java
@Override public void customizeCellRenderer(@NotNull JTree mongoTree, Object value, boolean isSelected, boolean isExpanded, boolean isLeaf, int row, boolean focus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object userObject = node.getUserObject(); if (userObject instanceof DatabaseServer) { DatabaseServer mongoServer = (DatabaseServer) userObject; String label = mongoServer.getLabel(); String host = mongoServer.getServerUrl(); append(StringUtils.isBlank(label) ? host : label); if (DatabaseServer.Status.OK.equals(mongoServer.getStatus())) { setToolTipText(host);//from w w w. j ava 2 s. c om setIcon(mongoServer.getConfiguration().getDatabaseVendor().icon); } else { setForeground(JBColor.RED); setToolTipText("Unable to connect"); } } else if (userObject instanceof Database) { Database noSqlDatabase = (Database) userObject; append(noSqlDatabase.getName()); setIcon(DATABASE); } else if (userObject instanceof SingleMongoCollection) { SingleMongoCollection singleMongoCollection = (SingleMongoCollection) userObject; append(singleMongoCollection.getName()); setIcon(MONGO_COLLECTION); } }
From source file:org.company.processmaker.TreeFilesTopComponent.java
public TreeFilesTopComponent() { initComponents();//from w ww . j av 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.eclipse.wb.internal.swing.model.property.editor.models.tree.TreeModelPropertyEditor.java
/** * Appends given {@link TreeNode} and its children to the {@link StringBuffer}. *//* ww w .j a v a2 s. c om*/ private static void getText_appendNodes(StringBuffer buffer, TreeNode node, String prefix) { // append separator if (buffer.length() != 0) { buffer.append(", "); } // append current node buffer.append(prefix); if (node instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode mutableTreeNode = (DefaultMutableTreeNode) node; buffer.append(mutableTreeNode.getUserObject()); } // append children String newPrefix = prefix + "+"; for (int i = 0; i < node.getChildCount(); i++) { getText_appendNodes(buffer, node.getChildAt(i), newPrefix); } }