Java Code Examples for javax.swing.tree.DefaultTreeModel#removeNodeFromParent()

The following examples show how to use javax.swing.tree.DefaultTreeModel#removeNodeFromParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Test8015926.java    From jdk8u_jdk with GNU General Public License v2.0 10 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 2
Source File: Test8015926.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 3
Source File: RecentFilesController.java    From bigtable-sql with Apache License 2.0 6 votes vote down vote up
private void onRemoveSelected()
{

   HashSet<DefaultMutableTreeNode> changedParents = new HashSet<DefaultMutableTreeNode>();
   TreePath[] paths = _dialog.treFiles.getSelectionPaths();

   DefaultTreeModel model = (DefaultTreeModel) _dialog.treFiles.getModel();
   for (TreePath path : paths)
   {
      DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) path.getLastPathComponent();
      if( dmtn.getUserObject() instanceof File )
      {
         model.removeNodeFromParent(dmtn);
         changedParents.add((DefaultMutableTreeNode) path.getParentPath().getLastPathComponent());
      }
   }

   for (DefaultMutableTreeNode changedParent : changedParents)
   {
      model.nodeStructureChanged(changedParent);
   }

   writeUiTreeToModel();

}
 
Example 4
Source File: Test8015926.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 5
Source File: Editor.java    From jclic with GNU General Public License v2.0 6 votes vote down vote up
public boolean moveToIndex(int index, boolean updateSelection) {
  boolean result = false;
  DefaultTreeModel model = getTreeModel();
  Editor p = getEditorParent();
  if (p != null && model != null) {
    index = Math.min(Math.max(0, index), p.getChildCount());
    if (index != p.getIndex(this)) {
      p.setModified(true);
      model.removeNodeFromParent(this);
      model.insertNodeInto(this, p, index);
      result = true;
      if (updateSelection)
        select();
    }
  }
  return result;
}
 
Example 6
Source File: Test8015926.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 7
Source File: Test8015926.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 8
Source File: Test8015926.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 9
Source File: Test8015926.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 10
Source File: Test8015926.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 11
Source File: Test8015926.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 12
Source File: Test8015926.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
Example 13
Source File: TemplateRemoveAction.java    From CodeGen with MIT License 5 votes vote down vote up
@Override
public void run(AnActionButton button) {
    DefaultMutableTreeNode selectedNode = getSelectedNode();
    if (selectedNode != null && selectedNode.getParent() != null) {
        // 删除指定节点
        DefaultTreeModel model = (DefaultTreeModel) this.templateTree.getModel();
        model.removeNodeFromParent(selectedNode);
    }
}
 
Example 14
Source File: CatalogTree.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public void resolveCatalogReferenceNode(DefaultMutableTreeNode catalogReferenceNode, boolean expandPath) {
    final DefaultTreeModel model = (DefaultTreeModel) jTree.getModel();
    final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) catalogReferenceNode.getParent();
    model.removeNodeFromParent(catalogReferenceNode);
    try {
        List<InvDataset> catalogDatasets = CatalogTreeUtils.getCatalogDatasets(catalogReferenceNode);
        insertCatalogElements(catalogDatasets, parent, expandPath);
    } catch (Exception e) {
        String msg = MessageFormat.format("Unable to completely resolve catalog. Reason: {0}", e.getMessage());
        SystemUtils.LOG.warning(msg);
        appContext.handleError(msg, e);
    }
}
 
Example 15
Source File: LastNodeLowerHalfDrop.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void exportDone(JComponent source, Transferable data, int action) {
    if ((action & MOVE) == MOVE) {
        JTree tree = (JTree) source;
        DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
        // Remove nodes saved in nodesToRemove in createTransferable.
        for (DefaultMutableTreeNode nodesToRemove1 : nodesToRemove) {
            model.removeNodeFromParent(nodesToRemove1);
        }
    }
}
 
Example 16
Source File: LibraryTreePanel.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Removes a given tree node.
 *
 * @param node the node
 */
protected void removeNode(LibraryTreeNode node) {
	if (rootNode==null || node==rootNode) return;
	LibraryTreeNode parent = (LibraryTreeNode)node.getParent();
htmlPanesByNode.remove(parent);
htmlPanesByNode.remove(node);
	LibraryCollection collection = (LibraryCollection)parent.record;
	collection.removeResource(node.record);
	DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
model.removeNodeFromParent(node);
	TreePath path = new TreePath(parent.getPath());
	tree.scrollPathToVisible(path);
  tree.setSelectionPath(path);
}
 
Example 17
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override protected void exportDone(JComponent src, Transferable data, int action) {
  if (action == TransferHandler.MOVE && src instanceof JTree) {
    JTree tree = (JTree) src;
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    TreePath[] selectionPaths = tree.getSelectionPaths();
    if (selectionPaths != null) {
      for (TreePath path : selectionPaths) {
        model.removeNodeFromParent((MutableTreeNode) path.getLastPathComponent());
      }
    }
  }
}
 
Example 18
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override protected void exportDone(JComponent src, Transferable data, int action) {
  if (action == TransferHandler.MOVE && src instanceof JTree) {
    JTree tree = (JTree) src;
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    TreePath[] selectionPaths = tree.getSelectionPaths();
    if (selectionPaths != null) {
      for (TreePath path : selectionPaths) {
        model.removeNodeFromParent((MutableTreeNode) path.getLastPathComponent());
      }
    }
  }
}
 
Example 19
Source File: CatalogTree.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void setLeafInvisible(OpendapLeaf leaf) {
    boolean leafIsRemovedFromTree = leafToParentNode.containsKey(leaf);
    if (!leafIsRemovedFromTree) {
        final MutableTreeNode node = getNode(leaf);
        final DefaultTreeModel model = (DefaultTreeModel) jTree.getModel();
        leafToParentNode.put(leaf, (MutableTreeNode) node.getParent());
        model.removeNodeFromParent(node);
    }
}
 
Example 20
Source File: RecentFilesController.java    From bigtable-sql with Apache License 2.0 4 votes vote down vote up
private File findFileToOpen(MouseEvent evt)
{

   DefaultMutableTreeNode tn = getSelectedFileNode(evt);

   if (tn == null)
   {
      if (null == evt) // The open button was pushed
      {
         JOptionPane.showMessageDialog(_dialog, s_stringMgr.getString("RecentFilesController.pleaseSelectFile"));
      }
      return null;
   }

   File file = (File) tn.getUserObject();


   if(false == file.exists())
   {
      if(JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(_dialog, s_stringMgr.getString("RecentFilesController.fileDoesNotExist")))
      {
         DefaultTreeModel model = (DefaultTreeModel) _dialog.treFiles.getModel();
         TreeNode parent = tn.getParent();
         model.removeNodeFromParent(tn);
         model.nodeStructureChanged(parent);

         if(parent == _recentFilesNode)
         {
            _app.getRecentFilesManager().setRecentFiles(getFileStringsFromNode(_recentFilesNode));
         }
         else if(parent == _favouriteFilesNode)
         {
            _app.getRecentFilesManager().setFavouriteFiles(getFileStringsFromNode(_favouriteFilesNode));
         }
         else if(parent == _recentFilesForAliasNode)
         {
            _app.getRecentFilesManager().setRecentFilesForAlias(_selectedAlias, getFileStringsFromNode(_recentFilesForAliasNode));
         }
         else
         {
            _app.getRecentFilesManager().setFavouriteFilesForAlias(_selectedAlias, getFileStringsFromNode(_favouriteFilesForAliasNode));
         }
      }

      return null;
   }

   if(file.isDirectory())
   {
      JFileChooser fc = new JFileChooser(file);
      fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

      int returnVal = fc.showOpenDialog(_parent);
      if (returnVal != JFileChooser.APPROVE_OPTION)
      {
         return null;
      }

      file = fc.getSelectedFile();
   }


   if(false == file.canRead())
   {
      JOptionPane.showMessageDialog(_dialog, s_stringMgr.getString("RecentFilesController.fileIsNotReadable"));
      return null;
   }

   return file;

}