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

The following examples show how to use javax.swing.tree.DefaultTreeModel#reload() . 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: SortTreeHelper.java    From ISO8583 with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public static void sortTree(PnlGuiConfig pnlGuiConfig, DefaultMutableTreeNode root, JTree treeTypes) {
	if (root != null) {
		Enumeration e = root.depthFirstEnumeration();
		while (e.hasMoreElements()) {
			DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
			if (!node.isLeaf()) {
				sort(node);   //selection sort
			}
		}
		
		//Atualizando a arvore
		if (updateTree) {
			TreePath treePath = treeTypes.getSelectionPath();
			DefaultTreeModel model = (DefaultTreeModel) treeTypes.getModel();
			model.reload();
			treeTypes.setSelectionPath(treePath);
			updateTree = false;
		}
	}
}
 
Example 2
Source File: ScrGrammarGuide.java    From PolyGlot with MIT License 6 votes vote down vote up
private void deleteNode() {
    Object selection = treChapList.getLastSelectedPathComponent();
    DefaultTreeModel model = (DefaultTreeModel) treChapList.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();

    if (selection != null
            && InfoBox.yesNoCancel("Confirmation", "Really delete? This cannot be undone.", 
                    core.getRootWindow())
                    == JOptionPane.YES_OPTION) {
        if (selection instanceof GrammarSectionNode) {
            GrammarSectionNode curNode = (GrammarSectionNode) selection;
            GrammarChapNode parent = (GrammarChapNode) curNode.getParent();
            parent.doRemove(curNode);
            treChapList.expandPath(new TreePath(model.getPathToRoot(parent)));
            treChapList.setSelectionPath(new TreePath(model.getPathToRoot(parent)));
        } else if (selection instanceof GrammarChapNode) {
            ((GrammarChapNode) root).doRemove((GrammarChapNode) selection);
            gramMan.removeChapter((GrammarChapNode) selection);
        }

        model.reload(root);
    }
}
 
Example 3
Source File: MongoEditionPanel.java    From nosql4idea with Apache License 2.0 6 votes vote down vote up
public void addKey(String key, Object value) {

        List<TreeNode> node = new LinkedList<TreeNode>();
        NoSqlTreeNode treeNode = new NoSqlTreeNode(MongoKeyValueDescriptor.createDescriptor(key, value));

        if (value instanceof DBObject) {
            JsonTreeModel.processDbObject(treeNode, (DBObject) value);
        }

        node.add(treeNode);

        DefaultTreeModel treeModel = (DefaultTreeModel) editTableView.getTree().getModel();
        NoSqlTreeNode parentNode = getParentNode();
        if (parentNode == null) {
            parentNode = (NoSqlTreeNode) treeModel.getRoot();
        }
        TreeUtil.addChildrenTo(parentNode, node);
        treeModel.reload(parentNode);
    }
 
Example 4
Source File: MongoEditionPanel.java    From nosql4idea with Apache License 2.0 6 votes vote down vote up
public void addValue(Object value) {
    List<TreeNode> node = new LinkedList<TreeNode>();

    NoSqlTreeNode parentNode = getParentNode();

    NoSqlTreeNode treeNode = new NoSqlTreeNode(MongoValueDescriptor.createDescriptor(parentNode.getChildCount(), value));
    if (value instanceof DBObject) {
        JsonTreeModel.processDbObject(treeNode, (DBObject) value);
    }

    node.add(treeNode);

    DefaultTreeModel treeModel = (DefaultTreeModel) editTableView.getTree().getModel();
    TreeUtil.addChildrenTo(parentNode, node);
    treeModel.reload(parentNode);
}
 
Example 5
Source File: AsposeExamplePanel.java    From Aspose.OCR-for-Java with MIT License 6 votes vote down vote up
private void retrieveAPIExamples() {
    final String item = (String) getComponentSelection().getSelectedItem();
    CustomMutableTreeNode top = new CustomMutableTreeNode("");
    DefaultTreeModel model = (DefaultTreeModel) getExamplesTree().getModel();
    model.setRoot(top);
    model.reload(top);
    if (item != null && !item.equals(AsposeConstants.API_DEPENDENCY_NOT_FOUND)) {

        AsposeExampleCallback callback = new AsposeExampleCallback(this, top);
        final ModalTaskImpl modalTask = new ModalTaskImpl(AsposeMavenProjectManager.getInstance().getProjectHandle(), callback, "Please wait...");
        ProgressManager.getInstance().run(modalTask);
        top.setTopTreeNodeText(AsposeConstants.API_NAME);
        model.setRoot(top);
        model.reload(top);
        getExamplesTree().expandPath(new TreePath(top.getPath()));

    }

}
 
Example 6
Source File: DasaTreeListener.java    From Astrosoft with GNU General Public License v2.0 6 votes vote down vote up
public void valueChanged(TreeSelectionEvent e) {
	JTree tree = (JTree) e.getSource();

	DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
	
	if (node != null){
	
		boolean isRoot = node.isRoot();
		Dasa dasa = (Dasa) node.getUserObject();
		
		//Add sub dasas only if not present already.
		if (!isRoot && node.isLeaf()){
			
			
			for(Dasa d : dasa.subDasas()){
				node.add(new DefaultMutableTreeNode(d, true));
			}
			DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
			model.reload(node);
		}
		handler.nodeSelected(node, e.getNewLeadSelectionPath());
			
	}
	//tree.collapsePath(e.getOldLeadSelectionPath());
}
 
Example 7
Source File: ApplicationPanel.java    From EchoSim with Apache License 2.0 5 votes vote down vote up
private void doNewApplication()
{
    if (mRuntime.getApp().getEndpoint() == null)
        mEndpoint.setText("");
    else
        if (!mRuntime.getApp().getEndpoint().equals(mEndpoint.getText()))
            mEndpoint.setText(mRuntime.getApp().getEndpoint());
    if (mRuntime.getApp().getApplicationID() == null)
        mApplicationID.setText("");
    else
        if (!mRuntime.getApp().getApplicationID().equals(mApplicationID.getText()))
            mApplicationID.setText(mRuntime.getApp().getApplicationID());
    if (mRuntime.getApp().getUserID() == null)
        mUserID.setText("");
    else
        if (!mRuntime.getApp().getUserID().equals(mUserID.getText()))
            mUserID.setText(mRuntime.getApp().getUserID());
    mRoot.removeAllChildren();
    if (mRuntime.getApp().getSchema() != null)
        for (IntentBean intent : mRuntime.getApp().getSchema().getIntents())
        {
            DefaultMutableTreeNode i = new DefaultMutableTreeNode(intent);
            mRoot.add(i);
            for (SlotBean slot : intent.getSlots())
            {
                DefaultMutableTreeNode s = new DefaultMutableTreeNode(slot);
                i.add(s);
            }
        }
    DefaultTreeModel m = (DefaultTreeModel)mIntents.getModel();
    m.reload();
    mIntents.expandRow(0);
    List<String> data = new ArrayList<String>();
    for (UtteranceBean u : mRuntime.getApp().getUtterances())
        data.add(u.toString());
    mUtterances.setListData(data.toArray(new String[0]));
    //mUtterances.setText("<html><body>"+UtteranceLogic.renderAsHTML(mRuntime.getApp().getUtterances())+"</body></html>");
}
 
Example 8
Source File: SearchInConstantPoolsView.java    From jd-gui with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void populate(DefaultTreeModel model, T node) {
    // Populate node
    populate(node);
    // Populate children
    int i = node.getChildCount();
    while (i-- > 0) {
        T child = (T)node.getChildAt(i);
        if ((child instanceof TreeNodeExpandable) && !expanded.contains(child.getUri())) {
            populate(child);
        }
    }
    // Refresh
    model.reload(node);
}
 
Example 9
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 10
Source File: ScrGrammarGuide.java    From PolyGlot with MIT License 5 votes vote down vote up
/**
 * populates all grammar chapters and sections
 */
private void populateSections() {
    DefaultMutableTreeNode rootNode = new GrammarChapNode("Root Node", gramMan);
    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
    treChapList.setModel(treeModel);

    for (GrammarChapNode curChap : gramMan.getChapters()) {
        rootNode.add(curChap);
    }

    treeModel.reload(rootNode);
    treChapList.setLargeModel(true);
}
 
Example 11
Source File: ScrGrammarGuide.java    From PolyGlot with MIT License 5 votes vote down vote up
/**
 * Populates all grammar chapters and sections that match search value
 */
private void populateFromSearch() {
    savePropsToNode((DefaultMutableTreeNode) treChapList.getLastSelectedPathComponent());
    GrammarChapNode rootNode = new GrammarChapNode("Root Node", gramMan);

    if (((PTextField) txtSearch).isDefaultText() || txtSearch.getText().isEmpty()) {
        populateSections();
        return;
    }

    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
    treChapList.setModel(treeModel);
    for (GrammarChapNode chapter : gramMan.getChapters()) {
        GrammarChapNode srcChap = new GrammarChapNode(gramMan);
        srcChap.setName(chapter.getName());

        Enumeration sections = chapter.children(txtSearch.getText());
        while (sections.hasMoreElements()) {
            GrammarSectionNode curSec = (GrammarSectionNode) sections.nextElement();
            srcChap.add(curSec);
        }

        if (srcChap.children().hasMoreElements()) {
            rootNode.add(srcChap);
        }
    }
    
    treeModel.reload(rootNode);
}
 
Example 12
Source File: ScopeTreeViewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void reload(@Nullable final DefaultMutableTreeNode rootToReload) {
  final DefaultTreeModel treeModel = (DefaultTreeModel)myTree.getModel();
  if (rootToReload != null && rootToReload != treeModel.getRoot()) {
    final List<TreePath> treePaths = TreeUtil.collectExpandedPaths(myTree, new TreePath(rootToReload.getPath()));
    final List<TreePath> selectionPaths = TreeUtil.collectSelectedPaths(myTree, new TreePath(rootToReload.getPath()));
    final TreePath path = new TreePath(rootToReload.getPath());
    final boolean wasCollapsed = myTree.isCollapsed(path);
    final Runnable runnable = new Runnable() {
      @Override
      public void run() {
        if (!isTreeShowing() || rootToReload.getParent() == null) return;
        TreeUtil.sort(rootToReload, getNodeComparator());
        treeModel.reload(rootToReload);
        if (!wasCollapsed) {
          myTree.collapsePath(path);
          for (TreePath treePath : treePaths) {
            myTree.expandPath(treePath);
          }
          for (TreePath selectionPath : selectionPaths) {
            TreeUtil.selectPath(myTree, selectionPath);
          }
        }
      }
    };
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      runnable.run();
    }
    else {
      SwingUtilities.invokeLater(runnable);
    }
  }
  else {
    TreeUtil.sort(treeModel, getNodeComparator());
    treeModel.reload();
  }
}
 
Example 13
Source File: ClassTree.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public void refreshTree(JarArchive jar) {
  DefaultTreeModel tm = this.model;
  SortedTreeNode root = (SortedTreeNode) tm.getRoot();
  root.removeAllChildren();
  tm.reload();

  preloadMap = new HashMap<>();
  if (jar.getClasses() != null)
    for (ClassNode c : jar.getClasses().values()) {
      String name = c.name;
      String[] path = name.split("/");
      int i = 0;
      int slashIndex = 0;
      SortedTreeNode prev = root;
      while (true) {
        slashIndex = name.indexOf("/", slashIndex + 1);
        if (slashIndex == -1) {
          break;
        }
        String p = name.substring(0, slashIndex);
        if (preloadMap.containsKey(p)) {
          prev = preloadMap.get(p);
        } else {
          SortedTreeNode stn = new SortedTreeNode(path[i]);
          prev.add(stn);
          prev = stn;
          preloadMap.put(p, prev);
        }
        i++;
      }
      SortedTreeNode clazz = new SortedTreeNode(c);
      prev.add(clazz);
      for (MethodNode m : c.methods) {
        clazz.add(new SortedTreeNode(c, m));
      }
    }
  boolean sort = JByteMod.ops.get("sort_methods").getBoolean();
  sort(tm, root, sort);
  tm.reload();
  addListener();
  if (!expandedNodes.isEmpty()) {
    expandSaved(root);
  }
}
 
Example 14
Source File: SessionAndContactsTreeView.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
private void updateTree() {
  DefaultTreeModel model = (DefaultTreeModel) (getModel());
  model.reload();

  expandRow(2);
}