List of usage examples for javax.swing.tree DefaultTreeModel nodeStructureChanged
public void nodeStructureChanged(TreeNode node)
From source file:Main.java
public static void main(String[] args) { DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); DefaultTreeModel model = new DefaultTreeModel(root); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(new JTree(model))); f.getContentPane().add(new JButton(new AbstractAction("Add thousand children") { @Override/*from w w w .jav a 2 s. c o m*/ public void actionPerformed(ActionEvent e) { int offset = root.getChildCount() + 1; for (int i = 0; i < 1000; i++) { DefaultMutableTreeNode child = new DefaultMutableTreeNode("Person " + (i + offset)); // model.insertNodeInto(child, root, root.getChildCount()); root.add(child); } model.nodeStructureChanged(root); } }), BorderLayout.PAGE_END); f.pack(); f.setVisible(true); }
From source file:com.edduarte.protbox.ui.windows.RestoreFileWindow.java
private RestoreFileWindow(final PReg registry) { super();/*from ww w . j av a2s. co m*/ setLayout(null); final JTextField searchField = new JTextField(); searchField.setLayout(null); searchField.setBounds(2, 2, 301, 26); searchField.setBorder(new LineBorder(Color.lightGray)); searchField.setFont(Constants.FONT); add(searchField); final JLabel noBackupFilesLabel = new JLabel("<html>No backups files were found!<br><br>" + "<font color=\"gray\">If you think there is a problem with the<br>" + "backup system, please create an issue here:<br>" + "<a href=\"#\">https://github.com/com.edduarte/protbox/issues</a></font></html>"); noBackupFilesLabel.setLayout(null); noBackupFilesLabel.setBounds(20, 50, 300, 300); noBackupFilesLabel.setFont(Constants.FONT.deriveFont(14f)); noBackupFilesLabel.addMouseListener((OnMouseClick) e -> { String urlPath = "https://github.com/com.edduarte/protbox/issues"; try { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(new URI(urlPath)); } else { if (SystemUtils.IS_OS_WINDOWS) { Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + urlPath); } else { java.util.List<String> browsers = Lists.newArrayList("firefox", "opera", "safari", "mozilla", "chrome"); for (String browser : browsers) { if (Runtime.getRuntime().exec(new String[] { "which", browser }).waitFor() == 0) { Runtime.getRuntime().exec(new String[] { browser, urlPath }); break; } } } } } catch (Exception ex) { ex.printStackTrace(); } }); DefaultMutableTreeNode rootTreeNode = registry.buildEntryTree(); final JTree tree = new JTree(rootTreeNode); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); if (rootTreeNode.getChildCount() == 0) { searchField.setEnabled(false); add(noBackupFilesLabel); } expandTree(tree); tree.setLayout(null); tree.setRootVisible(false); tree.setEditable(false); tree.setCellRenderer(new SearchableTreeCellRenderer(searchField)); searchField.addKeyListener((OnKeyReleased) e -> { // update and expand tree DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); model.nodeStructureChanged((TreeNode) model.getRoot()); expandTree(tree); }); final JScrollPane scroll = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setBorder(new DropShadowBorder()); scroll.setBorder(new LineBorder(Color.lightGray)); scroll.setBounds(2, 30, 334, 360); add(scroll); JLabel close = new JLabel(new ImageIcon(Constants.getAsset("close.png"))); close.setLayout(null); close.setBounds(312, 7, 18, 18); close.setFont(Constants.FONT); close.setForeground(Color.gray); close.addMouseListener((OnMouseClick) e -> dispose()); add(close); final JLabel permanentDeleteButton = new JLabel(new ImageIcon(Constants.getAsset("permanent.png"))); permanentDeleteButton.setLayout(null); permanentDeleteButton.setBounds(91, 390, 40, 39); permanentDeleteButton.setBackground(Color.black); permanentDeleteButton.setEnabled(false); permanentDeleteButton.addMouseListener((OnMouseClick) e -> { if (permanentDeleteButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (JOptionPane.showConfirmDialog(null, "Are you sure you wish to permanently delete '" + entry.realName() + "'?\nThis file and its " + "backup copies will be deleted immediately. You cannot undo this action.", "Confirm Cancel", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) { registry.permanentDelete(entry); dispose(); RestoreFileWindow.getInstance(registry); } else { setVisible(true); } } }); add(permanentDeleteButton); final JLabel configBackupsButton = new JLabel(new ImageIcon(Constants.getAsset("config.png"))); configBackupsButton.setLayout(null); configBackupsButton.setBounds(134, 390, 40, 39); configBackupsButton.setBackground(Color.black); configBackupsButton.setEnabled(false); configBackupsButton.addMouseListener((OnMouseClick) e -> { if (configBackupsButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (entry instanceof PbxFile) { PbxFile pbxFile = (PbxFile) entry; JFrame frame = new JFrame("Choose backup policy"); Object option = JOptionPane.showInputDialog(frame, "Choose below the backup policy for this file:", "Choose backup", JOptionPane.QUESTION_MESSAGE, null, PbxFile.BackupPolicy.values(), pbxFile.getBackupPolicy()); if (option == null) { setVisible(true); return; } PbxFile.BackupPolicy pickedPolicy = PbxFile.BackupPolicy.valueOf(option.toString()); pbxFile.setBackupPolicy(pickedPolicy); } setVisible(true); } }); add(configBackupsButton); final JLabel restoreBackupButton = new JLabel(new ImageIcon(Constants.getAsset("restore.png"))); restoreBackupButton.setLayout(null); restoreBackupButton.setBounds(3, 390, 85, 39); restoreBackupButton.setBackground(Color.black); restoreBackupButton.setEnabled(false); restoreBackupButton.addMouseListener((OnMouseClick) e -> { if (restoreBackupButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (entry instanceof PbxFolder) { registry.restoreFolderFromEntry((PbxFolder) entry); } else if (entry instanceof PbxFile) { PbxFile pbxFile = (PbxFile) entry; java.util.List<String> snapshots = pbxFile.snapshotsToString(); if (snapshots.isEmpty()) { setVisible(true); return; } JFrame frame = new JFrame("Choose backup"); Object option = JOptionPane.showInputDialog(frame, "Choose below what backup snapshot would you like restore:", "Choose backup", JOptionPane.QUESTION_MESSAGE, null, snapshots.toArray(), snapshots.get(0)); if (option == null) { setVisible(true); return; } int pickedIndex = snapshots.indexOf(option.toString()); registry.restoreFileFromEntry((PbxFile) entry, pickedIndex); } dispose(); } }); add(restoreBackupButton); tree.addMouseListener((OnMouseClick) e -> { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node != null) { PbxEntry entry = (PbxEntry) node.getUserObject(); if ((entry instanceof PbxFolder && entry.areNativeFilesDeleted())) { permanentDeleteButton.setEnabled(true); restoreBackupButton.setEnabled(true); configBackupsButton.setEnabled(false); } else if (entry instanceof PbxFile) { permanentDeleteButton.setEnabled(true); restoreBackupButton.setEnabled(true); configBackupsButton.setEnabled(true); } else { permanentDeleteButton.setEnabled(false); restoreBackupButton.setEnabled(false); configBackupsButton.setEnabled(false); } } }); final JLabel cancel = new JLabel(new ImageIcon(Constants.getAsset("cancel.png"))); cancel.setLayout(null); cancel.setBounds(229, 390, 122, 39); cancel.setBackground(Color.black); cancel.addMouseListener((OnMouseClick) e -> dispose()); add(cancel); addWindowFocusListener(new WindowFocusListener() { private boolean gained = false; @Override public void windowGainedFocus(WindowEvent e) { gained = true; } @Override public void windowLostFocus(WindowEvent e) { if (gained) { dispose(); } } }); setSize(340, 432); setUndecorated(true); getContentPane().setBackground(Color.white); setResizable(false); getRootPane().setBorder(BorderFactory.createLineBorder(new Color(100, 100, 100))); Utils.setComponentLocationOnCenter(this); setVisible(true); }
From source file:Main.java
public void loadChildren(final DefaultTreeModel model, final PropertyChangeListener progressListener) { if (loaded) { return;//from ww w .j av a2 s . c om } SwingWorker<List<MyTreeNode>, Void> worker = new SwingWorker<List<MyTreeNode>, Void>() { @Override protected List<MyTreeNode> doInBackground() throws Exception { setProgress(0); List<MyTreeNode> children = new ArrayList<MyTreeNode>(); if (depth < 5) { for (int i = 0; i < 5; i++) { Thread.sleep(300); children.add(new MyTreeNode(i + 1, depth + 1)); setProgress((i + 1) * 20); } } else { Thread.sleep(1000); } setProgress(0); return children; } @Override protected void done() { try { setChildren(get()); model.nodeStructureChanged(MyTreeNode.this); } catch (Exception e) { e.printStackTrace(); } super.done(); } }; if (progressListener != null) { worker.getPropertyChangeSupport().addPropertyChangeListener("progress", progressListener); } worker.execute(); }
From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java
protected void buildTreeModel(final ViewDefIFace viewDef) { DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); DefaultMutableTreeNode vdNode = new DefaultMutableTreeNode(viewDef.getName()); vdNode.setUserObject(viewDef);/*from w w w . j a v a 2s .c om*/ model.setRoot(vdNode); if (viewDef instanceof FormViewDef) { FormViewDef fvd = (FormViewDef) viewDef; for (FormRowIFace r : fvd.getRows()) { FormRow row = (FormRow) r; DefaultMutableTreeNode rowNode = new DefaultMutableTreeNode(row.getRowNumber()); rowNode.setUserObject(row); vdNode.add(rowNode); for (FormCellIFace c : row.getCells()) { FormCell cell = (FormCell) c; DefaultMutableTreeNode cellNode = new DefaultMutableTreeNode(cell.toString()); cellNode.setUserObject(cell); rowNode.add(cellNode); } } } model.nodeStructureChanged(vdNode); }
From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java
/** * @param viewDefs//from w w w . j a v a2 s .c o m */ protected void buildTreeModel(Vector<ViewDefIFace> viewDefs) { DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); DefaultMutableTreeNode root = new DefaultMutableTreeNode("ViewDefs"); //$NON-NLS-1$ model.setRoot(root); for (ViewDefIFace vd : viewDefs) { DefaultMutableTreeNode vdNode = new DefaultMutableTreeNode(vd.getName()); vdNode.setUserObject(vd); if (vd instanceof FormViewDef) { root.add(vdNode); FormViewDef fvd = (FormViewDef) vd; for (FormRowIFace r : fvd.getRows()) { FormRow row = (FormRow) r; DefaultMutableTreeNode rowNode = new DefaultMutableTreeNode(row.getRowNumber()); rowNode.setUserObject(row); vdNode.add(rowNode); for (FormCellIFace c : row.getCells()) { FormCell cell = (FormCell) c; DefaultMutableTreeNode cellNode = new DefaultMutableTreeNode(cell.toString()); cellNode.setUserObject(cell); rowNode.add(cellNode); } } } } model.nodeStructureChanged(root); }
From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java
private boolean modify() { final ParameterInATree userObj = (ParameterInATree) editedNode.getUserObject(); final String[] errors = checkInput(userObj.info); if (errors != null && errors.length != 0) { Utilities.userAlert(sweepPanel, (Object) errors); return false; } else {/*www . ja v a 2s. c om*/ modifyParameterInfo(userObj.info); resetSettings(); modifyButton.setEnabled(false); if (!(userObj.info instanceof SubmodelInfo)) { final DefaultTreeModel model = (DefaultTreeModel) editedTree.getModel(); model.nodeStructureChanged(editedNode); } editedNode = null; editedTree = null; updateNumberOfRuns(); enableDisableSettings(false); return true; } }
From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java
private void addSubParametersToTree(final SubmodelInfo sInfo, final JTree tree, final DefaultMutableTreeNode node) { try {/*from w w w . j a va2 s . co m*/ final List<ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?>> subparameters = ParameterTreeUtils .fetchSubparameters(currentModelHandler, sInfo); final List<ParameterInfo> convertedSubparameters = new ArrayList<ParameterInfo>(subparameters.size()); for (ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?> parameterInfo : subparameters) { final ParameterInfo converted = InfoConverter.parameterInfo2ParameterInfo(parameterInfo); converted.setRuns(0); convertedSubparameters.add(converted); } Collections.sort(convertedSubparameters); final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel(); if (node.getChildCount() > 0) { node.removeAllChildren(); treeModel.nodeStructureChanged(node); } for (final ParameterInfo pInfo : convertedSubparameters) { final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode( new ParameterInATree(pInfo, currentModelHandler.getModelClass())); treeModel.insertNodeInto(newNode, node, node.getChildCount()); if (pInfo instanceof SubmodelInfo) { final SubmodelInfo ssInfo = (SubmodelInfo) pInfo; if (ssInfo.getActualType() != null) addSubParametersToTree(ssInfo, tree, newNode); } } //tree.expandPath(new TreePath(treeModel.getPathToRoot(node))); } catch (final ModelInformationException e) { sInfo.setActualType(null, null); JOptionPane.showMessageDialog(wizard, new JLabel(e.getMessage()), "Error while analyizing model", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); submodelTypeBox.setSelectedIndex(0); } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
/** * Refreshes Entity tree to expand any labels that may not have rendered fully. Eg. "Som..." instead of "Some Folder" *///from www . ja v a 2 s .c o m private void refreshEntityTree() { DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) theEntityTree.getModel().getRoot(); DefaultTreeModel model = (DefaultTreeModel) theEntityTree.getModel(); if (rootNode.getChildCount() > 0) { for (int i = 0; i < rootNode.getChildCount(); i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) rootNode.getChildAt(i); model.nodeStructureChanged(child); model.nodeChanged(child); } expandNode(theEntityTree, rootNode, true); } }
From source file:org.codinjutsu.tools.jenkins.view.BrowserPanel.java
public void setSortedByStatus(boolean selected) { sortedByBuildStatus = selected;//from w w w .j av a 2 s . c o m final DefaultTreeModel model = (DefaultTreeModel) jobTree.getModel(); if (selected) { TreeUtil.sort(model, sortByStatusComparator); } else { TreeUtil.sort(model, sortByNameComparator); } GuiUtil.runInSwingThread(new Runnable() { @Override public void run() { model.nodeStructureChanged((TreeNode) model.getRoot()); } }); }
From source file:org.codinjutsu.tools.jenkins.view.BrowserPanel.java
public void handleEmptyConfiguration() { JenkinsWidget.getInstance(project).updateStatusIcon(BuildStatusAggregator.EMPTY); //FIXME could be handled elsehwere DefaultTreeModel model = (DefaultTreeModel) jobTree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); root.removeAllChildren();/*from w w w.j a v a 2 s .co m*/ model.nodeStructureChanged(root); jobTree.setRootVisible(false); jenkins.update(Jenkins.byDefault()); currentSelectedView = null; setJobsUnavailable(); }