Java Code Examples for javax.swing.tree.DefaultMutableTreeNode#removeAllChildren()

The following examples show how to use javax.swing.tree.DefaultMutableTreeNode#removeAllChildren() . 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: ModulesDependenciesPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void buildRightTree(Module module){
  final DefaultMutableTreeNode root = (DefaultMutableTreeNode)myRightTreeModel.getRoot();
  root.removeAllChildren();
  final Set<List<Module>> cycles = GraphAlgorithms.getInstance().findCycles(myModulesGraph, module);
  int index = 1;
  for (List<Module> modules : cycles) {
    final DefaultMutableTreeNode cycle = new DefaultMutableTreeNode(
      AnalysisScopeBundle.message("module.dependencies.cycle.node.text", Integer.toString(index++).toUpperCase()));
    root.add(cycle);
    cycle.add(new DefaultMutableTreeNode(new MyUserObject(false, module)));
    for (Module moduleInCycle : modules) {
      cycle.add(new DefaultMutableTreeNode(new MyUserObject(false, moduleInCycle)));
    }
  }
  ((DefaultTreeModel)myRightTree.getModel()).reload();
  TreeUtil.expandAll(myRightTree);
}
 
Example 2
Source File: OutlineComponent.java    From MogwaiERDesignerNG with GNU General Public License v3.0 6 votes vote down vote up
private void updateCustomTypeTreeNode(Model aModel, CustomType aCustomType,
									  DefaultMutableTreeNode aCustomTypeNode) {

	aCustomTypeNode.removeAllChildren();

	//display only details of ENUMERATION and COMPOSITE CustomTypes
	if ((aCustomType.getType() == CustomTypeType.ENUMERATION) ||
			(aCustomType.getType() == CustomTypeType.COMPOSITE)) {
           aCustomType.getAttributes().stream().filter(theAttribute -> isVisible(theAttribute)).forEach(theAttribute -> {
               DefaultMutableTreeNode theAttributeNode = new DefaultMutableTreeNode(theAttribute);

               aCustomTypeNode.add(theAttributeNode);

               registerUserObject(theAttribute, theAttributeNode);
           });
	} else {
		//TODO: handle EXTERNAL CustomTypes here
	}
}
 
Example 3
Source File: PreviewView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setSelectedFile(VirtualFile newFile) {
  if (currentFile.getValue() != null) {
    flutterAnalysisServer.removeOutlineListener(currentFilePath, outlineListener);
    currentFile.setValue(null);
    currentFilePath = null;
  }

  // If not a Dart file, ignore it.
  if (newFile != null && !FlutterUtils.isDartFile(newFile)) {
    newFile = null;
  }

  // Show the toolbar if the new file is a Dart file, or hide otherwise.
  if (windowPanel != null) {
    if (newFile != null) {
      windowPanel.setToolbar(widgetEditToolbar.getToolbar().getComponent());
    }
    else if (windowPanel.isToolbarVisible()) {
      windowPanel.setToolbar(null);
    }
  }

  // If the tree is already created, clear it now, until the outline for the new file is received.
  if (tree != null) {
    final DefaultMutableTreeNode rootNode = getRootNode();
    rootNode.removeAllChildren();
    getTreeModel().reload(rootNode);
  }

  // Subscribe for the outline for the new file.
  if (newFile != null) {
    currentFile.setValue(newFile);
    currentFilePath = FileUtil.toSystemDependentName(newFile.getPath());
    flutterAnalysisServer.addOutlineListener(currentFilePath, outlineListener);
  }
}
 
Example 4
Source File: DNDTree.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Set the root Thing, and the expanded state of all nodes if {@code expanded_state} is not null.
 *  Used for restoring purposes from an undo step. */
public void reset(final HashMap<Thing,Boolean> expanded_state) {
	// rebuild all nodes, restore their expansion state.
	DefaultMutableTreeNode root_node = (DefaultMutableTreeNode) this.getModel().getRoot();
	root_node.removeAllChildren();
	set(root_node, getRootThing(), expanded_state);
	updateUILater();
}
 
Example 5
Source File: MainFrame.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Update index tree.
 *
 * @param useCAS the use CAS
 */
@SuppressWarnings("unchecked")
public void updateIndexTree(boolean useCAS) {
  deleteFSTree();
  DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.indexTree.getModel().getRoot();
  if (useCAS) {
    root.setUserObject(indexReposRootLabel);
  } else {
    root.setUserObject(noIndexReposLabel);
  }
  root.removeAllChildren();
  if (this.cas != null && useCAS) {
    FSIndexRepository ir = this.cas.getIndexRepository();
    Iterator<String> it = ir.getLabels();
    while (it.hasNext()) {
      String label = it.next();
      FSIndex index1 = ir.getIndex(label);
      IndexTreeNode nodeObj = new IndexTreeNode(label, index1.getType(), index1.size());
      DefaultMutableTreeNode node = new DefaultMutableTreeNode(nodeObj);
      root.add(node);
      node.add(createTypeTree(index1.getType(), this.cas.getTypeSystem(), label, ir));
    }
  }
  DefaultTreeModel model = (DefaultTreeModel) this.indexTree.getModel();
  // 1.3 workaround
  TreeModelListener[] listeners = org.apache.uima.tools.cvd.tsview.MainFrame
      .getTreeModelListeners(model);
  // TreeModelListener[] listeners = model.getTreeModelListeners();
  // System.out.println("Number of tree model listeners: " +
  // listeners.length);
  Object[] path = new Object[1];
  path[0] = root;
  TreeModelEvent event = new TreeModelEvent(root, path);
  for (int i = 0; i < listeners.length; i++) {
    listeners[i].treeStructureChanged(event);
  }
}
 
Example 6
Source File: MainWin.java    From openprodoc with GNU Affero General Public License v3.0 5 votes vote down vote up
private void ExpandFold(DefaultMutableTreeNode ChildTreeFolder)
{
try {
setCursor(WaitCur);
ChildTreeFolder.removeAllChildren();
PDFolders Fold= ((TreeFolder) ChildTreeFolder.getUserObject()).getFold();
HashSet Child =Fold.getListDirectDescendList(Fold.getPDId());
for (Iterator it = Child.iterator(); it.hasNext();)
    {
    String ChildId=(String)it.next();
    if (ChildId.compareTo(Fold.getPDId())==0)
        continue;
    PDFolders ChildFolder=new PDFolders(Session);
    ChildFolder.LoadFull(ChildId);
    TreeFolder TFc=new TreeFolder(ChildFolder);
    DefaultMutableTreeNode ChildTreeFolder2=new DefaultMutableTreeNode(TFc);
    DefaultMutableTreeNode ChildTreeFolder3=new DefaultMutableTreeNode(null);
    ChildTreeFolder2.add(ChildTreeFolder3);
    ChildTreeFolder.add(ChildTreeFolder2);
    }
(((TreeFolder) ChildTreeFolder.getUserObject())).setExpanded(true);
FoldTreeModel.reload(ChildTreeFolder);
TreeFolder.setPreferredSize(null);
setCursor(DefCur);
} catch (PDException ex)
    {
    setCursor(DefCur);
    Message(DrvTT(ex.getLocalizedMessage()));
    }
}
 
Example 7
Source File: QueryKBServerTask.java    From KodeBeagle with Apache License 2.0 5 votes vote down vote up
private void updateMainPaneJTreeUI() {
    DefaultTreeModel model = (DefaultTreeModel) jTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    root.removeAllChildren();
    projectTree.updateRoot(root, projectNodes);
    model.reload(root);
    jTree.addTreeSelectionListener(projectTree.getTreeSelectionListener(root));
    ToolTipManager.sharedInstance().registerComponent(jTree);
    jTree.setCellRenderer(projectTree.getJTreeCellRenderer());
    jTree.addMouseListener(projectTree.getMouseListener(root));
    jTree.addKeyListener(projectTree.getKeyListener());
    windowObjects.getjTreeScrollPane().setViewportView(jTree);
}
 
Example 8
Source File: MainFrame.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Update type tree.
 */
private void updateTypeTree() {
  if (this.ts == null) {
    return;
  }
  DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) this.typeTree.getModel().getRoot();
  rootNode.removeAllChildren();
  // UIMA-2565 - Clash btw. cas.Type and Window.Type on JDK 7
  org.apache.uima.cas.Type top = this.ts.getTopType();
  rootNode.setUserObject(top);
  List<org.apache.uima.cas.Type> types = this.ts.getDirectSubtypes(top);
  for (int i = 0; i < types.size(); i++) {
    rootNode.add(createTypeTree(types.get(i)));
  }
  DefaultTreeModel model = (DefaultTreeModel) this.typeTree.getModel();
  // 1.3 compatability hack.
  // TreeModelListener[] listeners = model.getTreeModelListeners();
  TreeModelListener[] listeners = getTreeModelListeners(model);
  // System.out.println("Number of tree model listeners: " +
  // listeners.length);
  Object[] path = new Object[1];
  path[0] = rootNode;
  TreeModelEvent event = new TreeModelEvent(rootNode, path);
  for (int i = 0; i < listeners.length; i++) {
    listeners[i].treeStructureChanged(event);
  }
}
 
Example 9
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 10
Source File: Viewer.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void treeCollapsed(TreeExpansionEvent event) {
  DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
  @SuppressWarnings("unchecked")
  Enumeration<DefaultMutableTreeNode> children = node.children();
  while (children.hasMoreElements()) {
    DefaultMutableTreeNode child = children.nextElement();
    log.debug("removing children of " + ((NodeInfo) child.getUserObject()).getFullName());
    child.removeAllChildren();
  }
}
 
Example 11
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private static void sort3(DefaultMutableTreeNode parent) {
  // @SuppressWarnings("unchecked")
  // Enumeration<DefaultMutableTreeNode> e = parent.children();
  // ArrayList<DefaultMutableTreeNode> children = Collections.list(e);

  int n = parent.getChildCount();
  List<DefaultMutableTreeNode> children = new ArrayList<>(n);
  for (int i = 0; i < n; i++) {
    children.add((DefaultMutableTreeNode) parent.getChildAt(i));
  }

  children.sort(tnc);
  parent.removeAllChildren();
  children.forEach(parent::add);
}
 
Example 12
Source File: CustomizationUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void optimizeSchema(final JTree tree, final CustomActionsSchema schema) {
  //noinspection HardCodedStringLiteral
  Group rootGroup = new Group("root", null, null);
  DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootGroup);
  root.removeAllChildren();
  schema.fillActionGroups(root);
  final JTree defaultTree = new Tree(new DefaultTreeModel(root));

  final ArrayList<ActionUrl> actions = new ArrayList<ActionUrl>();

  TreeUtil.traverseDepth((TreeNode)tree.getModel().getRoot(), new TreeUtil.Traverse() {
    public boolean accept(Object node) {
      DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)node;
      if (treeNode.isLeaf()) {
        return true;
      }
      final ActionUrl url = getActionUrl(new TreePath(treeNode.getPath()), 0);
      url.getGroupPath().add(((Group)treeNode.getUserObject()).getName());
      final TreePath treePath = getTreePath(defaultTree, url);
      if (treePath != null) {
        final DefaultMutableTreeNode visited = (DefaultMutableTreeNode)treePath.getLastPathComponent();
        final ActionUrl[] defaultUserObjects = getChildUserObjects(visited, url);
        final ActionUrl[] currentUserObjects = getChildUserObjects(treeNode, url);
        computeDiff(defaultUserObjects, currentUserObjects, actions);
      } else {
        //customizations at the new place
        url.getGroupPath().remove(url.getParentGroup());
        if (actions.contains(url)){
          url.getGroupPath().add(((Group)treeNode.getUserObject()).getName());
          actions.addAll(schema.getChildActions(url));
        }
      }
      return true;
    }
  });
  schema.setActions(actions);
}
 
Example 13
Source File: ObjectTree.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Refresh the nodes currently selected in the object tree.
 */
public void refreshSelectedNodes()
{

   final TreePath[] selectedPaths = getSelectionPaths();
   ObjectTreeNode[] nodes = getSelectedNodes();
   final Map<String, Object> selectedPathNames = 
       new HashMap<String, Object>();
   if (selectedPaths != null)
   {
      for (int i = 0; i < selectedPaths.length; ++i)
      {
         selectedPathNames.put(selectedPaths[i].toString(), null);
      }
   }
   clearSelection();


   DefaultMutableTreeNode parent = (DefaultMutableTreeNode) nodes[0].getParent();

   if (parent != null)
   {
      parent.removeAllChildren();
      startExpandingTree((ObjectTreeNode) parent, false, selectedPathNames, true);
   }
   else
   {
      nodes[0].removeAllChildren();
      startExpandingTree(nodes[0], false, selectedPathNames, true);
   }
}
 
Example 14
Source File: DNDTree.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Rebuilds the entire tree, from the given node downward. */
public void rebuild(final DefaultMutableTreeNode node, final boolean repaint) {
	if (null == node) return;
	if (0 != node.getChildCount()) node.removeAllChildren();
	final Thing thing = (Thing)node.getUserObject();
	final ArrayList<? extends Thing> al_children = thing.getChildren();
	if (null == al_children) return;
	for (Iterator<? extends Thing> it = al_children.iterator(); it.hasNext(); ) {
		Thing child = it.next();
		DefaultMutableTreeNode childnode = new DefaultMutableTreeNode(child);
		node.add(childnode);
		rebuild(childnode, false);
	}
	if (repaint) updateUILater();
}
 
Example 15
Source File: LogParserView.java    From yGuard with MIT License 5 votes vote down vote up
private static void sort(DefaultMutableTreeNode parent, Comparator c) {
  DefaultMutableTreeNode[] children = new DefaultMutableTreeNode[parent.getChildCount()];
  for (int i = 0; i < children.length; ++i) {
    children[i] = ((DefaultMutableTreeNode) parent.getChildAt(i));
  }
  parent.removeAllChildren();
  Arrays.sort(children, c);
  for (int i = 0; i < children.length; ++i) {
    parent.add(children[i]);
  }
}
 
Example 16
Source File: OutlineComponent.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
private void updateTableTreeNode(Model aModel, Table aTable,
								 DefaultMutableTreeNode aTableNode) {

	aTableNode.removeAllChildren();

       aTable.getAttributes().stream().filter(theAttribute -> isVisible(theAttribute)).forEach(theAttribute -> {
           DefaultMutableTreeNode theAttributeNode = new DefaultMutableTreeNode(
                   theAttribute);
           aTableNode.add(theAttributeNode);

           registerUserObject(theAttribute, theAttributeNode);
       });

       aTable.getIndexes().stream().filter(theIndex -> isVisible(theIndex)).forEach(theIndex -> {
           createIndexTreeNode(aTableNode, theIndex);
       });

       aModel.getRelations().getForeignKeysFor(
               aTable).stream().filter(theRelation -> isVisible(theRelation)).forEach(theRelation -> {
           createRelationTreeNode(aTableNode, theRelation);
       });

	Set<Table> theAlreadyKnown = new HashSet<>();
       aModel.getRelations().getExportedKeysFor(aTable).stream().filter(theRelation -> isVisible(theRelation) && !theAlreadyKnown.contains(theRelation.getImportingTable())).forEach(theRelation -> {
           UsedBy theUsedBy = new UsedBy();
           theUsedBy.ref = theRelation.getImportingTable();
           DefaultMutableTreeNode theUsedByNode = new DefaultMutableTreeNode(theUsedBy);
           aTableNode.add(theUsedByNode);

           theAlreadyKnown.add(theRelation.getImportingTable());
       });
}
 
Example 17
Source File: MainFrame.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * Refreshes the navigation tree.
 */
public void refreshNavigationTree() {
	// Only need to refresh the rep sources and rep lists node, the rest are always up-to-date
	for ( int i = 0; i < 2; i++ ) { // 2 nodes to rebuild
		final DefaultMutableTreeNode node = i == 0 ? repSourcesNode : repListsNode;
		node.removeAllChildren();
		
		if ( node == repSourcesNode ) {
			node.add( sc2AutoRepsRepSourceNode   );
			node.add( autoSavedRepsRepSourceNode );
		}
		
		final String folderName = i == 0 ? Consts.FOLDER_REPLAY_SOURCES : Consts.FOLDER_REPLAY_LISTS;
		final String extension  = i == 0 ? Consts.EXT_SC2REPLAY_SOURCE  : Consts.EXT_SC2REPLAY_LIST;
		
		final String[] fileNames = new File( folderName ).list( new FilenameFilter() {
			@Override
			public boolean accept( final File dir, final String name ) {
				return name.toLowerCase().endsWith( extension );
			}
		} );
		
		if ( fileNames == null || fileNames.length == 0 ) {
			node.add( node == repSourcesNode ? emptyRepSourceNode : emptyRepListNode );
		}
		else {
			Arrays.sort( fileNames, String.CASE_INSENSITIVE_ORDER );
			for ( final String fileName : fileNames )
				node.add( new DefaultMutableTreeNode( fileName.substring( 0, fileName.lastIndexOf( '.' ) ) ) );
		}
		
		( (DefaultTreeModel) navigationTree.getModel() ).reload( node );
	}
}
 
Example 18
Source File: MiscTools.java    From megabasterd with GNU General Public License v3.0 4 votes vote down vote up
private static void _sortTreeNode(DefaultMutableTreeNode parent) {

        int n = parent.getChildCount();

        List<DefaultMutableTreeNode> children = new ArrayList<>(n);

        for (int i = 0; i < n; i++) {

            children.add((DefaultMutableTreeNode) parent.getChildAt(i));
        }

        Collections.sort(children, TREE_NODE_COMPARATOR);

        parent.removeAllChildren();

        children.forEach((node) -> {
            parent.add(node);
        });
    }
 
Example 19
Source File: DNDTree.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
/** Rebuilds the part of the tree under the given node, one level deep only, for reordering purposes. */
public void updateList(DefaultMutableTreeNode node) {
	if (null == node) return;
	Thing thing = (Thing)node.getUserObject();
	// store scrolling position for restoring purposes
	Component c = this.getParent();
	Point point = null;
	if (c instanceof JScrollPane) {
		point = ((JScrollPane)c).getViewport().getViewPosition();
	}
	// collect all current nodes
	HashMap<Object,DefaultMutableTreeNode> ht = new HashMap<Object,DefaultMutableTreeNode>();
	for (Enumeration<?> e = node.children(); e.hasMoreElements(); ) {
		DefaultMutableTreeNode child_node = (DefaultMutableTreeNode)e.nextElement();
		ht.put(child_node.getUserObject(), child_node);
	}
	// clear node
	node.removeAllChildren();
	// re-add nodes in the order present in the contained Thing
	for (Iterator<? extends Thing> it = thing.getChildren().iterator(); it.hasNext(); ) {
		Object ob_thing = it.next();
		Object ob = ht.remove(ob_thing);
		if (null == ob) {
			Utils.log2("Adding missing node for " + ob_thing);
			node.add(new DefaultMutableTreeNode(ob_thing));
			continue;
		}
		node.add((DefaultMutableTreeNode)ob);
	}
	// consistency check: that all nodes have been re-added
	if (0 != ht.size()) {
		Utils.log2("WARNING DNDTree.updateList: did not end up adding this nodes:");
		for (Iterator<?> it = ht.keySet().iterator(); it.hasNext(); ) {
			Utils.log2(it.next().toString());
		}
	}
	this.updateUILater();
	// restore viewport position
	if (null != point) {
		((JScrollPane)c).getViewport().setViewPosition(point);
	}
}
 
Example 20
Source File: OutlineComponent.java    From MogwaiERDesignerNG with GNU General Public License v3.0 4 votes vote down vote up
private void updateViewTreeNode(Model aModel, View aView,
								DefaultMutableTreeNode aViewNode) {

	aViewNode.removeAllChildren();
}