@Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); JCheckBox columnCheckBox = (JCheckBox) source; this.nodeModel.setSelected(columnCheckBox.isSelected()); DefaultTreeModel treeModel = (DefaultTreeModel) MediatorGui.treeDatabase().getModel(); DefaultMutableTreeNode tableNode = (DefaultMutableTreeNode) this.currentTableNode.getParent(); int tableChildCount = treeModel.getChildCount(tableNode); boolean isOneChildSelected = false; for (int i = 0 ; i < tableChildCount ; i++) { DefaultMutableTreeNode currentChild = (DefaultMutableTreeNode) treeModel.getChild(tableNode, i); if (currentChild.getUserObject() instanceof AbstractNodeModel) { AbstractNodeModel columnTreeNodeModel = (AbstractNodeModel) currentChild.getUserObject(); if (columnTreeNodeModel.isSelected()) { isOneChildSelected = true; break; } } } AbstractNodeModel nodeUserObject = (AbstractNodeModel) tableNode.getUserObject(); nodeUserObject.setContainingSelection(isOneChildSelected); }
final List<Column> columnsToSearch = new ArrayList<>(); int tableChildCount = treeModel.getChildCount(tableNode); for (int i = 0 ; i < tableChildCount ; i++) { DefaultMutableTreeNode currentChild = (DefaultMutableTreeNode) treeModel.getChild(tableNode, i);
@Override public int getChildCount(Object parent) { return model.getChildCount(parent); }
protected int getFilteredIndexOfChild(DefaultMutableTreeNode parent, Object child) { int count = -1; for (int i = 0; i < delegate.getChildCount(parent); i++) { final Object c = delegate.getChild(parent, i); if (isShown(c)) { count++; if (c.equals(child)) { return count; } } if (c.equals(child)) { return -1; } } return -1; }
public Object getChild(Object parent, int index) { int cnt = -1; for (int i = 0; i < super.getChildCount(parent); i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) super.getChild(parent, i); if (filter.pass(child)) { cnt++; } if (cnt == index) { return child; } } return null; }
public int getChildCount(Object parent) { int filterCount = 0; for (int i = 0, realCount = super.getChildCount(parent); i < realCount; i++) { if (filter.pass((DefaultMutableTreeNode) super.getChild(parent, i))) { filterCount++; } } return filterCount; }
public int getChildCount(Object parent) { int count = 0; for (int i = 0; i < delegate.getChildCount(parent); i++) { final Object child = delegate.getChild(parent, i); if (isShown(child)) { count++; } } return count; }
public Object getChild(Object parent, int index) { int count = -1; for (int i = 0; i < delegate.getChildCount(parent); i++) { final Object child = delegate.getChild(parent, i); if (isShown(child)) { count++; if (count == index) { return child; } } } return null; }
public TreeNode[] getNodeWith(final DefaultTreeModel _model, final DefaultMutableTreeNode _parent, final URL _url) { if (trIndex_ == null) { return null; } //NE PAS COMPARER DES URL CAR CELA PEUT FOUTRE EN L'AIR LES PERFORMANCES if (_parent.getParent() != null && getUrlFor(_parent).toString().equals(_url.toExternalForm())) { return _model.getPathToRoot(_parent); } final int nb = _model.getChildCount(_parent); for (int i = 0; i < nb; i++) { final TreeNode[] nds = getNodeWith(_model, (DefaultMutableTreeNode) _parent.getChildAt(i), _url); if (nds != null) { return nds; } } return null; }
public boolean addUniqueNode(DefaultMutableTreeNode childNode, DefaultTreeModel model) { DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); // Check each node boolean isUnique = true; for (int i = 0; i < model.getChildCount(root); i++) { Object compUserObj = ((DefaultMutableTreeNode) model.getChild(root, i)).getUserObject(); if (compUserObj.equals(childNode.getUserObject())) { isUnique = false; break; } } // If Unique, insert if(isUnique) model.insertNodeInto(childNode, root, root.getChildCount()); return isUnique; }
/** * Create a new node in the monitor */ protected void registerNode(final Object workflowObject, final String[] owningProcess, final Set<MonitorableProperty<?>> properties) { // logger.debug("Registering node " + printProcess(owningProcess)); // Create a new MonitorNode final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode( new MonitorNodeImpl(workflowObject, owningProcess, properties)); synchronized (monitorTree) { final MutableTreeNode parentNode = nodeAtProcessPath(owningProcess, owningProcess.length - 1); monitorTree.insertNodeInto(newNode, parentNode, monitorTree .getChildCount(parentNode)); } }
/** * Create a new node in the monitor */ protected void registerNode(final Object workflowObject, final String[] owningProcess, final Set<MonitorableProperty<?>> properties) { // logger.debug("Registering node " + printProcess(owningProcess)); // Create a new MonitorNode final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode( new MonitorNodeImpl(workflowObject, owningProcess, properties)); synchronized (monitorTree) { final MutableTreeNode parentNode = nodeAtProcessPath(owningProcess, owningProcess.length - 1); monitorTree.insertNodeInto(newNode, parentNode, monitorTree .getChildCount(parentNode)); } }
/** * Create a new node in the monitor */ protected void registerNode(final Object workflowObject, final String[] owningProcess, final Set<MonitorableProperty<?>> properties) { // logger.debug("Registering node " + printProcess(owningProcess)); // Create a new MonitorNode final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode( new MonitorNodeImpl(workflowObject, owningProcess, properties)); synchronized (monitorTree) { final MutableTreeNode parentNode = nodeAtProcessPath(owningProcess, owningProcess.length - 1); monitorTree.insertNodeInto(newNode, parentNode, monitorTree .getChildCount(parentNode)); } }
public void addScavenger(Scavenger theScavenger) { synchronized (getModel()) { // Check to see we don't already have a scavenger with this name String newName = theScavenger.getUserObject().toString(); if (!scavengerList.contains(newName)) { this.scavengerList.add(theScavenger.getUserObject().toString()); treeModel.insertNodeInto(theScavenger, (MutableTreeNode) this.treeModel.getRoot(), this.treeModel .getChildCount(this.treeModel.getRoot())); treeModel.nodeStructureChanged(theScavenger); // Set the visibility sensibly so that the root node // is expanded and visible TreePath path = new TreePath(this.root); expandPath(path); } } }
/** * Create a new node in the monitor */ protected void registerNode(final Object workflowObject, final String[] owningProcess, final Set<MonitorableProperty<?>> properties) { // logger.debug("Registering node " + printProcess(owningProcess)); // Create a new MonitorNode final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode( new MonitorNodeImpl(workflowObject, owningProcess, properties)); synchronized (monitorTree) { final MutableTreeNode parentNode = nodeAtProcessPath(owningProcess, owningProcess.length - 1); monitorTree.insertNodeInto(newNode, parentNode, monitorTree .getChildCount(parentNode)); } }
/** * Collapses all nodes by walking the TreeModel. */ public void collapseAllNodes( TreePath currentPath ) { Object currentNode = currentPath.getLastPathComponent(); for ( int i = treeModel.getChildCount( currentNode )-1; i >= 0; i-- ) { Object childNode = treeModel.getChild( currentNode, i ); TreePath childPath = currentPath.pathByAddingChild( childNode ); collapseAllNodes( childPath ); } if ( currentNode != treeModel.getRoot() ) tree.collapsePath( currentPath ); }
private void updateJobNode(Job job) { final DefaultTreeModel model = (DefaultTreeModel) jobTree.getModel(); final Object modelRoot = model.getRoot(); final int childCount = model.getChildCount(modelRoot); for (int i = 0; i < childCount; ++i) { Object child = model.getChild(modelRoot, i); if (child instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child; if (childNode.getUserObject() == job) { model.nodeChanged(childNode); fillBuildsTree(job, childNode); break; } } } }
private void m_objBtnMoveUpLevelActionPerformed(ActionEvent evt) { TreePath l_objTreePath = m_objTree.getSelectionPath(); // get path of selected node. if (l_objTreePath == null) return; boolean l_bIsExpanded = m_objTree.isExpanded(l_objTreePath); DefaultMutableTreeNode l_objNode = (DefaultMutableTreeNode) l_objTreePath.getLastPathComponent(); DefaultMutableTreeNode l_objParentNode = (DefaultMutableTreeNode) l_objNode.getParent(); DefaultMutableTreeNode l_objGrandParentNode = (DefaultMutableTreeNode) l_objParentNode.getParent(); if (l_objGrandParentNode == null) return; m_objModelTree.removeNodeFromParent(l_objNode); m_objModelTree.insertNodeInto(l_objNode, l_objGrandParentNode, m_objModelTree.getChildCount(l_objGrandParentNode)); TreePath l_objNodePath = new TreePath(l_objNode.getPath()); if (l_bIsExpanded) m_objTree.expandPath(l_objNodePath); m_objTree.scrollPathToVisible(l_objNodePath); m_objTree.setSelectionPath(l_objNodePath); SaveDataModified(); }
private void m_objBtnMoveDownActionPerformed(ActionEvent evt) { TreePath l_objTreePath = m_objTree.getSelectionPath(); // get path of selected node. if (l_objTreePath == null) return; boolean l_bIsExpanded = m_objTree.isExpanded(l_objTreePath); DefaultMutableTreeNode l_objNode = (DefaultMutableTreeNode) l_objTreePath.getLastPathComponent(); DefaultMutableTreeNode l_objParentNode = (DefaultMutableTreeNode) l_objNode.getParent(); //now get the index of the selected node in the DefaultTreeModel int l_iIndex = m_objModelTree.getIndexOfChild(l_objParentNode, l_objNode); int l_iMaxIndex = m_objModelTree.getChildCount(l_objParentNode) - 1; // if selected node is first, return (can't move it up) if (l_iIndex < l_iMaxIndex) { m_objModelTree.removeNodeFromParent(l_objNode); m_objModelTree.insertNodeInto(l_objNode, l_objParentNode, l_iIndex + 1); // move the node TreePath l_objNodePath = new TreePath(l_objNode.getPath()); if (l_bIsExpanded) m_objTree.expandPath(l_objNodePath); m_objTree.scrollPathToVisible(l_objNodePath); m_objTree.setSelectionPath(l_objNodePath); SaveDataModified(); } }
for (int i=0; i<treeModel.getChildCount(treeNode); i++)