List of usage examples for javax.swing.event TreeModelEvent getChildIndices
public int[] getChildIndices()
From source file:MyTreeModelListener.java
public void treeNodesChanged(TreeModelEvent e) { DefaultMutableTreeNode node;/* w w w .ja v a2s. c o m*/ node = (DefaultMutableTreeNode) (e.getTreePath().getLastPathComponent()); try { int index = e.getChildIndices()[0]; node = (DefaultMutableTreeNode) (node.getChildAt(index)); } catch (NullPointerException exc) { } System.out.println("New value: " + node.getUserObject()); }
From source file:MyTreeModelListener.java
public void treeNodesChanged(TreeModelEvent e) { DefaultMutableTreeNode node;/* ww w .j a v a 2 s.com*/ node = (DefaultMutableTreeNode) (e.getTreePath().getLastPathComponent()); try { int index = e.getChildIndices()[0]; node = (DefaultMutableTreeNode) (node.getChildAt(index)); } catch (NullPointerException exc) { } System.out.println("The user has finished editing the node."); System.out.println("New value: " + node.getUserObject()); }
From source file:cz.lidinsky.editor.Editor.java
/** * Add a link component -> tree to each new node. * And select last inserted node./*from w ww . j a va 2 s .com*/ */ public void treeNodesInserted(TreeModelEvent e) { // add a link component -> tree TreePath parentPath = e.getTreePath(); Node<GuiObject> parent = (Node<GuiObject>) parentPath.getLastPathComponent(); int[] indexes = e.getChildIndices(); for (int i : indexes) { Node<GuiObject> child = parent.getChild(i); setComponent2TreeLink(child); } // select last inserted node Node<GuiObject> child = parent.getChild(indexes[indexes.length - 1]); guiStructureTree.setSelectionPath(parentPath.pathByAddingChild(child)); }
From source file:com.mindcognition.mindraider.ui.swing.explorer.LabelsTree.java
public void treeNodesChanged(TreeModelEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) (e.getTreePath().getLastPathComponent()); /*//from w ww .j av a 2 s. c om * If the event lists children, then the changed node is the child * of the node we've already gotten. Otherwise, the changed node and * the specified node are the same. */ // TODO try { int index = e.getChildIndices()[0]; node = (DefaultMutableTreeNode) (node.getChildAt(index)); // TODO RENAME NOT IMPLEMENTED investigate how is the node stored into the user object /* if (node.getLevel() == LEVEL_LABELS) { MindRaider.folderCustodian.rename( (String) getTreeNodeToResourceUriMap().get(node), (String) node.getUserObject()); } else { if (node.getLevel() == LEVEL_NOTEBOOKS) { MindRaider.notebookCustodian.rename( (String) getTreeNodeToResourceUriMap() .get(node), (String) node .getUserObject()); MindRaider.profile.setActiveNotebookUri(null); MindRaider.notebookCustodian.loadNotebook(new URI( (String) getTreeNodeToResourceUriMap() .get(node))); NotebookJPanel.getInstance().refresh(); } } */ } catch (Exception ex) { logger.debug("Unable to found node!", ex); } logger.debug("New value: " + node.getUserObject()); }
From source file:org.languagetool.gui.ConfigurationDialog.java
@NotNull private DefaultTreeModel getTreeModel(DefaultMutableTreeNode rootNode) { DefaultTreeModel treeModel = new DefaultTreeModel(rootNode); treeModel.addTreeModelListener(new TreeModelListener() { @Override//from ww w. j ava 2 s. com public void treeNodesChanged(TreeModelEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getTreePath().getLastPathComponent(); int index = e.getChildIndices()[0]; node = (DefaultMutableTreeNode) node.getChildAt(index); if (node instanceof RuleNode) { RuleNode o = (RuleNode) node; if (o.getRule().isDefaultOff() || o.getRule().getCategory().isDefaultOff()) { if (o.isEnabled()) { config.getEnabledRuleIds().add(o.getRule().getId()); config.getDisabledRuleIds().remove(o.getRule().getId()); } else { config.getEnabledRuleIds().remove(o.getRule().getId()); config.getDisabledRuleIds().add(o.getRule().getId()); } } else { if (o.isEnabled()) { config.getDisabledRuleIds().remove(o.getRule().getId()); } else { config.getDisabledRuleIds().add(o.getRule().getId()); } } } if (node instanceof CategoryNode) { CategoryNode o = (CategoryNode) node; if (o.getCategory().isDefaultOff()) { if (o.isEnabled()) { config.getDisabledCategoryNames().remove(o.getCategory().getName()); config.getEnabledCategoryNames().add(o.getCategory().getName()); } else { config.getDisabledCategoryNames().add(o.getCategory().getName()); config.getEnabledCategoryNames().remove(o.getCategory().getName()); } } else { if (o.isEnabled()) { config.getDisabledCategoryNames().remove(o.getCategory().getName()); } else { config.getDisabledCategoryNames().add(o.getCategory().getName()); } } } } @Override public void treeNodesInserted(TreeModelEvent e) { } @Override public void treeNodesRemoved(TreeModelEvent e) { } @Override public void treeStructureChanged(TreeModelEvent e) { } }); return treeModel; }