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

The following examples show how to use javax.swing.tree.DefaultTreeModel#nodeStructureChanged() . 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: ViewerJTree.java    From megan-ce with GNU General Public License v3.0 6 votes vote down vote up
/**
 * add all children of a given node
 *
 * @param node
 */
public void addChildren(MyJTreeNode node) {
    final Node v = node.getV();
    final DefaultTreeModel model = (DefaultTreeModel) getModel();

    if (v.getOutDegree() > 0 && node.getChildCount() == 0) {
        for (Edge e = v.getFirstOutEdge(); e != null; e = v.getNextOutEdge(e)) {
            final Node w = e.getTarget();
            final MyJTreeNode wNode = new MyJTreeNode(w);
            node.add(wNode);
            id2node.put((Integer) w.getInfo(), wNode);
            model.nodeStructureChanged(wNode);
        }
    }
    model.nodeStructureChanged(node);
}
 
Example 2
Source File: InspectorWindow.java    From megan-ce with GNU General Public License v3.0 6 votes vote down vote up
/**
 * delete all the selected nodes
 */
public void deleteSelectedNodes() {
    DefaultTreeModel model = (DefaultTreeModel) dataTree.getModel();
    TreePath[] selectedPaths = dataTree.getSelectionPaths();
    if (selectedPaths != null) {
        for (TreePath selectedPath : selectedPaths) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedPath.getLastPathComponent();
            node.removeAllChildren();
            model.nodeStructureChanged(node);
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
            if (parent != null) {
                parent.remove(node);
                model.nodeStructureChanged(parent);
            }
        }
    }
}
 
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: ComponentSelector.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void circuitChanged(CircuitEvent event) {
	int action = event.getAction();
	DefaultTreeModel model = (DefaultTreeModel) getModel();
	if (action == CircuitEvent.ACTION_SET_NAME) {
		model.nodeChanged(this);
	} else {
		if (computeChildren()) {
			model.nodeStructureChanged(this);
		} else if (action == CircuitEvent.ACTION_INVALIDATE) {
			Object o = event.getData();
			for (int i = children.size() - 1; i >= 0; i--) {
				Object o2 = children.get(i);
				if (o2 instanceof ComponentNode) {
					ComponentNode n = (ComponentNode) o2;
					if (n.comp == o) {
						int[] changed = { i };
						children.remove(i);
						model.nodesWereRemoved(this, changed, new Object[] { n });
						children.add(i, new ComponentNode(this, n.comp));
						model.nodesWereInserted(this, changed);
					}
				}
			}
		}
	}
}
 
Example 5
Source File: InspectorWindow.java    From megan-ce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * erase the tree
 */
public void clear() {
    final DefaultTreeModel model = (DefaultTreeModel) dataTree.getModel();
    for (NodeBase root : classification2RootNode.values()) {
        root.removeAllChildren();
        model.nodeStructureChanged(root);
    }
}
 
Example 6
Source File: InspectorWindow.java    From megan-ce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called whenever an item in the tree has been collapsed.
 */
public void treeCollapsed(TreeExpansionEvent event) {
    final TreePath path = event.getPath();
    final NodeBase node = (NodeBase) path.getLastPathComponent();
    if (!inspectorWindow.getClassification2RootNode().containsValue(node)) {
        //node.removeAllChildren();
        DefaultTreeModel model = (DefaultTreeModel) inspectorWindow.dataTree.getModel();
        model.nodeStructureChanged(node);
    }
    inspectorWindow.updateView(Director.ALL);
}
 
Example 7
Source File: RecentFilesController.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
private void onAddToFavourites(ISQLAlias alias)
{
   JFileChooser fc = new JFileChooser(_app.getSquirrelPreferences().getFilePreviousDir());
   fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

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


   DefaultMutableTreeNode nodeToAddTo;
   ArrayList<String> listToAddTo;

   if (null == alias)
   {
      _app.getRecentFilesManager().adjustFavouriteFiles(fc.getSelectedFile());
      nodeToAddTo = _favouriteFilesNode;
      listToAddTo = _app.getRecentFilesManager().getFavouriteFiles();
   }
   else
   {
      _app.getRecentFilesManager().adjustFavouriteAliasFiles(alias, fc.getSelectedFile());
      nodeToAddTo = _favouriteFilesForAliasNode;
      listToAddTo = _app.getRecentFilesManager().getFavouriteFilesForAlias(alias);
   }

   nodeToAddTo.removeAllChildren();
   addFileKidsToNode(nodeToAddTo, listToAddTo, false);

   DefaultTreeModel dtm = (DefaultTreeModel) _dialog.treFiles.getModel();
   dtm.nodeStructureChanged(nodeToAddTo);
   _dialog.treFiles.expandPath(new TreePath(nodeToAddTo.getPath()));

   DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode) nodeToAddTo.getFirstChild();
   _dialog.treFiles.scrollPathToVisible(new TreePath(firstChild.getPath()));

}
 
Example 8
Source File: CustomMessages.java    From Spark with Apache License 2.0 5 votes vote down vote up
private static void reloadTree(JiveTreeNode rootNode, Tree tree) {
    StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
    rootNode.removeAllChildren();
    Iterator<StatusItem> statusItems = statusBar.getStatusList().iterator();
    while (statusItems.hasNext()) {
        StatusItem statusItem = statusItems.next();
        JiveTreeNode node = new JiveTreeNode(statusItem.getText(), false, statusItem.getIcon());

        List<CustomStatusItem> newItems = load();
        Iterator<CustomStatusItem> cMessages = newItems.iterator();

        node.setAllowsChildren(true);

        while (cMessages.hasNext()) {
            CustomStatusItem csi = cMessages.next();
            if (csi.getType().equals(statusItem.getText())) {
                JiveTreeNode subNode = new JiveTreeNode(csi.getStatus(), false);
                node.add(subNode);

            }
        }


        rootNode.add(node);
    }

    DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
    model.nodeStructureChanged(rootNode);
    tree.expandTree();
}
 
Example 9
Source File: BookmarksUI.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new service (ex. [email protected]) to the services list.
 *
 * @param service the new service.
 * @return the new service node created.
 */
public JiveTreeNode addServiceToList(DomainBareJid service) {
    final JiveTreeNode serviceNode = new JiveTreeNode(service.toString(), true, SparkRes.getImageIcon(SparkRes.SERVER_ICON));
    rootNode.add(serviceNode);
    final DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
    model.nodeStructureChanged(rootNode);
    // expand the tree for displaying
    for (int i = 0; i <= tree.getRowCount(); i++) {
        tree.expandPath(tree.getPathForRow(i));
    }
    return serviceNode;
}
 
Example 10
Source File: BookmarksUI.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new bookmark to a particular service node.
 *
 * @param serviceNode the service node.
 * @param roomName    the name of the room to bookmark.
 * @param roomJID     the jid of the room.
 * @return the new bookmark created.
 */
public JiveTreeNode addBookmark(JiveTreeNode serviceNode, String roomName, String roomJID) {
    JiveTreeNode roomNode = new JiveTreeNode(roomName, false, SparkRes.getImageIcon(SparkRes.BOOKMARK_ICON));
    roomNode.setAssociatedObject(roomJID);
    serviceNode.add(roomNode);
    final DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
    model.nodeStructureChanged(serviceNode);
    return roomNode;
}
 
Example 11
Source File: LibraryTreePanel.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the font level.
 *
 * @param level the desired font level
 */
protected void setFontLevel(int level) {

Object[] toSize = new Object[] {
		splitPane, editorPanel, editorbar, authorField, contactField, keywordsField,
		authorLabel, contactLabel, keywordsLabel, metadataLabel, metadataDropdown};
FontSizer.setFonts(toSize, level);
EntryField.font = authorField.getFont();

// resize treeNodeRenderer and LibraryResource icons
treeNodeRenderer.resizableOpenIcon.resize(FontSizer.getIntegerFactor());
treeNodeRenderer.resizableClosedIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.trackerIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.ejsIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.imageIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.videoIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.htmlIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.pdfIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.unknownIcon.resize(FontSizer.getIntegerFactor());

// resize LibraryResource stylesheet font sizes
LibraryResource.bodyFont = FontSizer.getResizedFont(LibraryResource.bodyFont, level);
LibraryResource.h1Font = FontSizer.getResizedFont(LibraryResource.h1Font, level);
LibraryResource.h2Font = FontSizer.getResizedFont(LibraryResource.h2Font, level);

// clear htmlPanesByNode to force new HTML code with new stylesheets
htmlPanesByNode.clear();

// refresh the tree structure
TreeModel model = tree.getModel();
if (model instanceof DefaultTreeModel) {
	LibraryTreeNode selectedNode = getSelectedNode();
	DefaultTreeModel treeModel = (DefaultTreeModel)model;
	treeModel.nodeStructureChanged(rootNode);
	setSelectedNode(selectedNode);
}
refreshGUI();

}
 
Example 12
Source File: LogParserView.java    From yGuard with MIT License 4 votes vote down vote up
static void sort( final DefaultTreeModel model, final Comparator c ) {
  sortRecursively((DefaultMutableTreeNode) model.getRoot(), c);
  model.nodeStructureChanged((DefaultMutableTreeNode) model.getRoot());
}
 
Example 13
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;

}