List of usage examples for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode
public DefaultMutableTreeNode(Object userObject, boolean allowsChildren)
From source file:Main.java
public MyTreeNode(int index, int depth) { this.index = index; this.depth = depth; add(new DefaultMutableTreeNode("Loading...", false)); setAllowsChildren(true);//from w w w . j av a 2 s . c o m setUserObject("Index " + index + " at level " + depth); }
From source file:com.yosanai.java.aws.console.panel.InstancesPanel.java
public void loadInstances() { new Thread(new Runnable() { @Override// w ww .j a v a2s .c om public void run() { DefaultTreeModel treeModel = (DefaultTreeModel) trInstances.getModel(); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot(); tblInstances.clearSelection(); trInstances.clearSelection(); rootNode.removeAllChildren(); treeModel.reload(); tblInstances.setModel(instancesTableModel); DescribeInstancesResult result = awsConnectionProvider.getConnection().describeInstances(); while (0 < instancesTableModel.getRowCount()) { instancesTableModel.removeRow(0); } for (Reservation reservation : result.getReservations()) { for (Instance instance : reservation.getInstances()) { String name = null; StringBuilder tags = new StringBuilder(); for (Tag tag : instance.getTags()) { tags.append(tag.getKey()); tags.append("="); tags.append(tag.getValue()); if (StringUtils.equalsIgnoreCase(nameTag, tag.getKey())) { name = tag.getValue(); } } try { boolean apiTermination = awsConnectionProvider .getApiTermination(instance.getInstanceId()); instancesTableModel.addRow(new Object[] { instance.getInstanceId(), instance.getPublicDnsName(), instance.getPublicIpAddress(), instance.getPrivateDnsName(), instance.getPrivateIpAddress(), apiTermination ? "Yes" : "No", instance.getState().getName(), instance.getInstanceType(), instance.getKeyName(), StringUtils.join(reservation.getGroupNames(), ","), instance.getPlacement().getAvailabilityZone(), DATE_FORMAT.format(instance.getLaunchTime()), tags.toString() }); DefaultMutableTreeNode instanceNode = new DefaultMutableTreeNode( new InstanceObjectWrapper(instance, name), false); rootNode.add(instanceNode); treeModel.reload(); } catch (Exception ex) { Logger.getLogger(InstancesPanel.class.getName()).log(Level.SEVERE, null, ex); } } } } }).start(); }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java
public void exploreBean(DefaultMutableTreeNode root, String classname, String parentPath) { try {/*from w w w .j a v a2 s. c om*/ root.removeAllChildren(); if (parentPath.length() > 0) parentPath += "."; Class clazz = Class.forName(classname, true, IReportManager.getInstance().getReportClassLoader()); java.beans.PropertyDescriptor[] pd = org.apache.commons.beanutils.PropertyUtils .getPropertyDescriptors(clazz); for (int nd = 0; nd < pd.length; ++nd) { String fieldName = pd[nd].getName(); if (pd[nd].getPropertyType() != null && pd[nd].getReadMethod() != null) { Class clazzRT = pd[nd].getPropertyType(); if (clazzRT.isPrimitive()) { clazzRT = MethodUtils.getPrimitiveWrapper(clazzRT); } String returnType = clazzRT.getName(); JRDesignField field = new JRDesignField(); field.setName(fieldName); field.setValueClassName(returnType); if (isPathOnDescription()) { field.setDescription(parentPath + fieldName); } else { field.setName(parentPath + fieldName); } TreeJRField jtf = new TreeJRField(); jtf.setField(field); jtf.setObj(pd[nd].getPropertyType()); boolean bChildrens = true; if (pd[nd].getPropertyType().isPrimitive() || pd[nd].getPropertyType().getName().startsWith("java.lang.")) { bChildrens = false; } root.add(new DefaultMutableTreeNode(jtf, bChildrens)); } } jTree1.expandPath(new TreePath(root.getPath())); jTree1.updateUI(); } catch (ClassNotFoundException cnf) { javax.swing.JOptionPane.showMessageDialog(this, Misc.formatString( //"messages.BeanInspectorPanel.classNotFoundError", I18n.getString("BeanInspectorPanel.Message.Error"), new Object[] { cnf.getMessage() }), I18n.getString("BeanInspectorPanel.Message.Error2"), javax.swing.JOptionPane.ERROR_MESSAGE); return; } catch (Exception ex) { ex.printStackTrace(); javax.swing.JOptionPane.showMessageDialog(this, ex.getMessage(), I18n.getString("BeanInspectorPanel.Message.Error2"), javax.swing.JOptionPane.ERROR_MESSAGE); return; } }
From source file:com.compomics.cell_coord.gui.controller.load.LoadTracksController.java
/** * Load the data files into the tree.//from w w w .ja va2s. c o m * * @throws LoadDirectoryException - when the directory is empty! */ private void loadDataIntoTree() throws LoadDirectoryException { DefaultTreeModel model = (DefaultTreeModel) loadTracksPanel.getDirectoryTree().getModel(); DefaultMutableTreeNode rootNote = (DefaultMutableTreeNode) model.getRoot(); // change name (user object) of root node rootNote.setUserObject(directory.getName()); File[] listFiles = directory.listFiles(); if (listFiles.length != 0) { for (File file : listFiles) { if (!file.isDirectory()) { DefaultMutableTreeNode fileNode = new DefaultMutableTreeNode(file.getName(), Boolean.FALSE); rootNote.add(fileNode); } else { // reset the directory to null directory = null; throw new LoadDirectoryException("This directory has a wrong structure!"); } } } else { // reset the directory to null directory = null; throw new LoadDirectoryException("This directory seems to be empty!"); } model.reload(); loadTracksPanel.getChosenDirectoryTextArea().setText(directory.getAbsolutePath()); cellCoordController.showMessage("Directory successful loaded!\nYou can now select the files to import!", "", JOptionPane.INFORMATION_MESSAGE); loadTracksPanel.getImportFilesButton().setEnabled(true); }
From source file:com.edduarte.protbox.core.registry.PReg.java
public DefaultMutableTreeNode buildEntryTree() { DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(root, true); build(treeRoot, root);//from ww w.jav a2 s. c om return treeRoot; }
From source file:com.edduarte.protbox.core.registry.PReg.java
private boolean build(final DefaultMutableTreeNode treeRoot, final PbxFolder root) { root.getSubFolders().forEach(f -> { DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(f, true); newNode.setAllowsChildren(true); build(newNode, f);//from ww w. j a va2 s . co m treeRoot.add(newNode); }); root.getSubFiles().forEach(f -> { DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(f, true); newNode.setAllowsChildren(false); treeRoot.add(newNode); }); return false; }
From source file:org.apache.cayenne.modeler.ProjectTreeView.java
public void procedureAdded(ProcedureEvent e) { DefaultMutableTreeNode node = getProjectModel().getNodeForObjectPath(new Object[] { (DataChannelDescriptor) mediator.getProject().getRootNode(), e.getProcedure().getDataMap() }); if (node == null) { return;/*from w w w. ja va 2 s .c o m*/ } Procedure procedure = e.getProcedure(); DefaultMutableTreeNode currentNode = new DefaultMutableTreeNode(procedure, false); positionNode(node, currentNode, Comparators.getDataMapChildrenComparator()); showNode(currentNode); }
From source file:org.apache.cayenne.modeler.ProjectTreeView.java
public void queryAdded(QueryEvent e) { DefaultMutableTreeNode node = getProjectModel().getNodeForObjectPath(new Object[] { e.getDomain() != null ? e.getDomain() : (DataChannelDescriptor) mediator.getProject().getRootNode(), e.getDataMap() });//from w w w. j a v a 2s . c om if (node == null) { return; } QueryDescriptor query = e.getQuery(); DefaultMutableTreeNode currentNode = new DefaultMutableTreeNode(query, false); positionNode(node, currentNode, Comparators.getDataMapChildrenComparator()); showNode(currentNode); }
From source file:org.apache.cayenne.modeler.ProjectTreeView.java
public void dataNodeChanged(DataNodeEvent e) { DefaultMutableTreeNode node = getProjectModel().getNodeForObjectPath(new Object[] { e.getDomain() != null ? e.getDomain() : (DataChannelDescriptor) mediator.getProject().getRootNode(), e.getDataNode() });//from w w w . ja v a 2 s .c o m if (node != null) { if (e.isNameChange()) { positionNode((DefaultMutableTreeNode) node.getParent(), node, Comparators.getDataDomainChildrenComparator()); showNode(node); } else { getProjectModel().nodeChanged(node); DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode(); // check for DataMap additions/removals... Object[] mapsName = e.getDataNode().getDataMapNames().toArray(); int mapCount = mapsName.length; // DataMap was linked if (mapCount > node.getChildCount()) { for (int i = 0; i < mapCount; i++) { boolean found = false; for (int j = 0; j < node.getChildCount(); j++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(j); if (domain.getDataMap(mapsName[i].toString()) == child.getUserObject()) { found = true; break; } } if (!found) { DefaultMutableTreeNode newMapNode = new DefaultMutableTreeNode( domain.getDataMap(mapsName[i].toString()), false); positionNode(node, newMapNode, Comparators.getNamedObjectComparator()); break; } } } // DataMap was unlinked else if (mapCount < node.getChildCount()) { int j = 0; while (j < node.getChildCount()) { boolean found = false; DefaultMutableTreeNode child; child = (DefaultMutableTreeNode) node.getChildAt(j); Object obj = child.getUserObject(); for (int i = 0; i < mapCount; i++) { if (domain.getDataMap(mapsName[i].toString()) == obj) { found = true; j++; } } if (!found) { removeNode(child); } } } } } }
From source file:org.apache.cayenne.modeler.ProjectTreeView.java
/** * Event handler for ObjEntity and DbEntity additions. Adds a tree node for the entity * and make it selected./*from w w w .ja v a 2s . c o m*/ */ protected void entityAdded(EntityEvent e) { Entity entity = e.getEntity(); DefaultMutableTreeNode mapNode = getProjectModel().getNodeForObjectPath(new Object[] { e.getDomain() != null ? e.getDomain() : (DataChannelDescriptor) mediator.getProject().getRootNode(), e.getEntity().getDataMap() }); if (mapNode == null) { return; } DefaultMutableTreeNode currentNode = new DefaultMutableTreeNode(entity, false); positionNode(mapNode, currentNode, Comparators.getDataMapChildrenComparator()); showNode(currentNode); }