List of usage examples for javax.swing.tree DefaultMutableTreeNode removeAllChildren
public void removeAllChildren()
From source file:Main.java
public TestPane() { setLayout(new BorderLayout()); tree = new JTree(); File rootFile = new File("."); DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootFile); model = new DefaultTreeModel(root); tree.setModel(model);//from ww w.j a v a2s . co m tree.setRootVisible(true); tree.setShowsRootHandles(true); add(new JScrollPane(tree)); JButton load = new JButton("Load"); add(load, BorderLayout.SOUTH); load.addActionListener(e -> { DefaultMutableTreeNode r = (DefaultMutableTreeNode) model.getRoot(); root.removeAllChildren(); model.reload(); File f = (File) r.getUserObject(); addFiles(f, model, r); tree.expandPath(new TreePath(r)); }); }
From source file:com.compomics.cell_coord.gui.controller.load.LoadTracksController.java
/** * Initialize the view components./* www. j a v a2 s . c o m*/ */ private void initView() { // create new view loadTracksPanel = new LoadTracksPanel(); // disable the IMPORT FILES button loadTracksPanel.getImportFilesButton().setEnabled(false); // initialize the flag to keep track of importing isImported = false; // populate the combobox with available file formats // note: these are annoatated as spring beans Set<String> parsers = TrackFileParserFactory.getInstance().getParserBeanNames(); for (String parser : parsers) { loadTracksPanel.getFileFormatComboBox().addItem(parser); } // format the table JTableHeader tracksTableHeader = loadTracksPanel.getTracksTable().getTableHeader(); tracksTableHeader.setBackground(GuiUtils.getHeaderColor()); tracksTableHeader.setFont(GuiUtils.getHeaderFont()); tracksTableHeader.setReorderingAllowed(false); /** * Action Listeners. */ // load directory loadTracksPanel.getLoadDirectoryButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (directory == null) { chooseDirectoryAndLoadData(); } else { // otherwise we ask the user if they want to reload the directory Object[] options = { "Load a different directory", "Cancel" }; int showOptionDialog = JOptionPane.showOptionDialog(null, "It seems a directory was already loaded.\nWhat do you want to do?", "", JOptionPane.CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); switch (showOptionDialog) { case 0: // load a different directory: // reset the model of the directory tree DefaultTreeModel model = (DefaultTreeModel) loadTracksPanel.getDirectoryTree().getModel(); DefaultMutableTreeNode rootNote = (DefaultMutableTreeNode) model.getRoot(); rootNote.removeAllChildren(); model.reload(); chooseDirectoryAndLoadData(); loadTracksPanel.getChosenDirectoryTextArea().setText(directory.getAbsolutePath()); break; // cancel: do nothing } } } }); // import the selected files in the tree loadTracksPanel.getImportFilesButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // check if an import already took place if (!isImported) { // get the selected file(s) from the JTree TreePath[] selectionPaths = loadTracksPanel.getDirectoryTree().getSelectionPaths(); if (selectionPaths != null && selectionPaths.length != 0) { // at least a file was selected -- proceed with the import importFiles(); isImported = true; cellCoordController.showMessage(selectionPaths.length + " file(s) successfully imported!", "success loading", JOptionPane.INFORMATION_MESSAGE); // do basic computations preprocess(); // go to child controllers and show samples in the tables summaryDataController.showSamplesInTable(); computationMainController.showSamplesInTable(); // proceed with next step in the plugin cellCoordController.getCellCoordFrame().getNextButton().setEnabled(true); } else { // inform the user that no file was selected! cellCoordController.showMessage("You have to select at least one file!", "no files selected", JOptionPane.WARNING_MESSAGE); } } else { // an import already took place: ask for user input Object[] options = { "Load other file(s)", "Cancel" }; int showOptionDialog = JOptionPane.showOptionDialog(loadTracksPanel, "It seems some files were already loaded.\nWhat do you want to do?", "", JOptionPane.CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); switch (showOptionDialog) { case 0: // load other files // clear the sample list samples.clear(); // clear the track spot list trackSpotsBindingList.clear(); // clear the selection in the JTree loadTracksPanel.getDirectoryTree().clearSelection(); isImported = false; // inform the user they need to select other files JOptionPane.showMessageDialog(loadTracksPanel, "Please select other files", "", JOptionPane.INFORMATION_MESSAGE); break; // cancel: do nothing } } } }); // add view to parent component cellCoordController.getCellCoordFrame().getLoadTracksParentPanel().add(loadTracksPanel, gridBagConstraints); }
From source file:com.imaginea.betterdocs.BetterDocsAction.java
public void runAction(final AnActionEvent e) throws IOException { final Editor projectEditor = DataKeys.EDITOR.getData(e.getDataContext()); if (projectEditor != null) { Set<String> imports = getImports(projectEditor.getDocument()); Set<String> lines = getLines(projectEditor, projectEditor.getDocument()); Set<String> importsInLines = importsInLines(lines, imports); DefaultTreeModel model = (DefaultTreeModel) jTree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); root.removeAllChildren(); if (!importsInLines.isEmpty()) { jTree.setVisible(true);/*from w ww . ja va 2 s . c om*/ String esQueryJson = getESQueryJson(importsInLines); String esResultJson = getESResultJson(esQueryJson, esURL + BETTERDOCS_SEARCH); if (!esResultJson.equals(EMPTY_ES_URL)) { Map<String, String> fileTokensMap = getFileTokens(esResultJson); Map<String, ArrayList<CodeInfo>> projectNodes = new HashMap<String, ArrayList<CodeInfo>>(); updateProjectNodes(imports, fileTokensMap, projectNodes); updateRoot(root, projectNodes); model.reload(root); jTree.addTreeSelectionListener(getTreeSelectionListener(root)); } else { Messages.showInfoMessage(EMPTY_ES_URL, INFO); } } else { jTree.updateUI(); } } }
From source file:Main.java
public void actionPerformed(ActionEvent ae) { DefaultMutableTreeNode dmtn, node; TreePath path = this.getSelectionPath(); dmtn = (DefaultMutableTreeNode) path.getLastPathComponent(); if (ae.getActionCommand().equals("insert")) { node = new DefaultMutableTreeNode("children"); dmtn.add(node);/*from w ww .ja va 2s . c o m*/ ((DefaultTreeModel) this.getModel()).nodeStructureChanged((TreeNode) dmtn); } if (ae.getActionCommand().equals("remove")) { node = (DefaultMutableTreeNode) dmtn.getParent(); int nodeIndex = node.getIndex(dmtn); dmtn.removeAllChildren(); node.remove(nodeIndex); ((DefaultTreeModel) this.getModel()).nodeStructureChanged((TreeNode) dmtn); } }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java
/** * Must be used when the combobox is not visible... *///from w ww .j a v a 2 s.com public void setClassName(String className) { DefaultMutableTreeNode root = (DefaultMutableTreeNode) jTree1.getModel().getRoot(); root.removeAllChildren(); jTree1.updateUI(); if (className != null && className.trim().length() > 0) { exploreBean(root, className, ""); } }
From source file:FileTree2.java
public boolean expand(DefaultMutableTreeNode parent) { DefaultMutableTreeNode flag = (DefaultMutableTreeNode) parent.getFirstChild(); if (flag == null) // No flag return false; Object obj = flag.getUserObject(); if (!(obj instanceof Boolean)) return false; // Already expanded parent.removeAllChildren(); // Remove Flag File[] files = listFiles();/* ww w . j a v a2 s . c o m*/ if (files == null) return true; Vector v = new Vector(); for (int k = 0; k < files.length; k++) { File f = files[k]; if (!(f.isDirectory())) continue; FileNode newNode = new FileNode(f); boolean isAdded = false; for (int i = 0; i < v.size(); i++) { FileNode nd = (FileNode) v.elementAt(i); if (newNode.compareTo(nd) < 0) { v.insertElementAt(newNode, i); isAdded = true; break; } } if (!isAdded) v.addElement(newNode); } for (int i = 0; i < v.size(); i++) { FileNode nd = (FileNode) v.elementAt(i); IconData idata = new IconData(FileTree2.ICON_FOLDER, FileTree2.ICON_EXPANDEDFOLDER, nd); DefaultMutableTreeNode node = new DefaultMutableTreeNode(idata); parent.add(node); if (nd.hasSubDirs()) node.add(new DefaultMutableTreeNode(new Boolean(true))); } return true; }
From source file:FileTree3.java
public boolean expand(DefaultMutableTreeNode parent) { DefaultMutableTreeNode flag = (DefaultMutableTreeNode) parent.getFirstChild(); if (flag == null) // No flag return false; Object obj = flag.getUserObject(); if (!(obj instanceof Boolean)) return false; // Already expanded parent.removeAllChildren(); // Remove Flag File[] files = listFiles();/*from w w w .ja va 2s . c o m*/ if (files == null) return true; Vector v = new Vector(); for (int k = 0; k < files.length; k++) { File f = files[k]; if (!(f.isDirectory())) continue; FileNode newNode = new FileNode(f); boolean isAdded = false; for (int i = 0; i < v.size(); i++) { FileNode nd = (FileNode) v.elementAt(i); if (newNode.compareTo(nd) < 0) { v.insertElementAt(newNode, i); isAdded = true; break; } } if (!isAdded) v.addElement(newNode); } for (int i = 0; i < v.size(); i++) { FileNode nd = (FileNode) v.elementAt(i); IconData idata = new IconData(FileTree3.ICON_FOLDER, FileTree3.ICON_EXPANDEDFOLDER, nd); DefaultMutableTreeNode node = new DefaultMutableTreeNode(idata); parent.add(node); if (nd.hasSubDirs()) node.add(new DefaultMutableTreeNode(new Boolean(true))); } return true; }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java
public void exploreBean(DefaultMutableTreeNode root, String classname, String parentPath) { try {/*from w ww . j a va2 s . c o m*/ 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.yosanai.java.aws.console.panel.InstancesPanel.java
public void loadInstances() { new Thread(new Runnable() { @Override//from w w w .j a v a 2 s . co m 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:de.erdesignerng.visual.common.OutlineComponent.java
private void updateViewTreeNode(Model aModel, View aView, DefaultMutableTreeNode aViewNode) { aViewNode.removeAllChildren(); }