Search in sources :

Example 11 with TreeModelEvent

use of javax.swing.event.TreeModelEvent in project processdash by dtuma.

the class AbstractTreeTableModel method fireTreeStructureWillChange.

/*
     * Notify all listeners that have registered interest for
     * notification on this event type.  The event instance
     * is lazily created using the parameters passed into
     * the fire method.
     * @see EventListenerList
     */
protected void fireTreeStructureWillChange(Object source, Object[] path, int[] childIndices, Object[] children) {
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    TreeModelEvent e = null;
    // those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == TreeModelWillChangeListener.class) {
            // Lazily create the event:
            if (e == null)
                e = new TreeModelEvent(source, path, childIndices, children);
            ((TreeModelWillChangeListener) listeners[i + 1]).treeStructureWillChange(e);
        }
    }
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent)

Example 12 with TreeModelEvent

use of javax.swing.event.TreeModelEvent in project checkstyle by checkstyle.

the class ParseTreeTableModel method fireTreeStructureChanged.

/**
     * Notify all listeners that have registered interest for
     * 'tree structure changed' event.  The event instance
     * is lazily created using the parameters passed into
     * the fire method.
     * @param source The Object responsible for generating the event.
     * @param path An array of Object identifying the path to the parent of the modified items.
     * @param childIndices An array of int that specifies the index values of the removed items.
     * @param children An array of Object containing the inserted, removed, or changed objects.
     * @see EventListenerList
     */
private void fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object... children) {
    // Guaranteed to return a non-null array
    final Object[] listeners = listenerList.getListenerList();
    TreeModelEvent event = null;
    // those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == TreeModelListener.class) {
            // Lazily create the event:
            if (event == null) {
                event = new TreeModelEvent(source, path, childIndices, children);
            }
            ((TreeModelListener) listeners[i + 1]).treeStructureChanged(event);
        }
    }
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) TreeModelListener(javax.swing.event.TreeModelListener)

Example 13 with TreeModelEvent

use of javax.swing.event.TreeModelEvent in project intellij-community by JetBrains.

the class TreeBuilder method nodeStructureChanged.

public void nodeStructureChanged(TreeNode node) {
    TreeModelEvent event = new TreeModelEvent(this, getPathToRoot(node, 0), null, null);
    myDispatcher.getMulticaster().treeStructureChanged(event);
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent)

Example 14 with TreeModelEvent

use of javax.swing.event.TreeModelEvent in project intellij-community by JetBrains.

the class TreeUiTest method testNoExtraJTreeModelUpdate.

public void testNoExtraJTreeModelUpdate() throws Exception {
    buildStructure(myRoot);
    expand(getPath("/"));
    assertTree("-/\n" + " +com\n" + " +jetbrains\n" + " +org\n" + " +xUnit\n");
    final Ref<StringBuffer> updates = new Ref<>(new StringBuffer());
    notNull(getMyBuilder().getTreeModel()).addTreeModelListener(new TreeModelListener() {

        @Override
        public void treeNodesChanged(TreeModelEvent e) {
            updates.get().append("changed parent").append(e.getTreePath()).append(" children=").append(Arrays.asList(e.getChildren())).append("\n");
        }

        @Override
        public void treeNodesInserted(TreeModelEvent e) {
            updates.get().append("inserted=").append(e.getTreePath()).append("\n");
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent e) {
            updates.get().append("removed=").append(e.getTreePath()).append("\n");
        }

        @Override
        public void treeStructureChanged(TreeModelEvent e) {
            updates.get().append("structureChanged=").append(e.getTreePath()).append("\n");
        }
    });
    assertEquals("", updates.get().toString());
    updateFromRoot();
    assertEquals("", updates.get().toString());
    myChanges.add(new NodeElement("com"));
    updateFromRoot();
    assertEquals("changed parent[/] children=[com]\n", updates.get().toString());
    assertTree("-/\n" + " +com\n" + " +jetbrains\n" + " +org\n" + " +xUnit\n");
    updates.set(new StringBuffer());
    updateFrom(new NodeElement("org"));
    assertEquals("", updates.get().toString());
    myChanges.add(new NodeElement("org"));
    updateFrom(new NodeElement("org"));
    assertEquals("changed parent[/] children=[org]\n", updates.get().toString());
    updates.set(new StringBuffer());
    myChanges.add(new NodeElement("intellij"));
    updateFromRoot();
    assertEquals("", updates.get().toString());
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) TreeModelListener(javax.swing.event.TreeModelListener)

Example 15 with TreeModelEvent

use of javax.swing.event.TreeModelEvent in project pcgen by PCGen.

the class EquipmentTreeTableModel method fireTreeStructureChanged.

/**
	 * Notifies all listeners that have registered interest for
	 * notification on this event type.  The event instance
	 * is lazily created using the parameters passed into
	 * the fire method.
	 *
	 * @param source the node where the tree model has changed
	 * @param path the path to the root node
	 * @param childIndices the indices of the affected elements
	 * @param children the affected elements
	 * @see EventListenerList
	 */
protected void fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children) {
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    TreeModelEvent e = null;
    // those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == TreeModelListener.class) {
            // Lazily create the event:
            if (e == null) {
                e = new TreeModelEvent(source, path, childIndices, children);
            }
            ((TreeModelListener) listeners[i + 1]).treeStructureChanged(e);
        }
    }
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) TreeModelListener(javax.swing.event.TreeModelListener)

Aggregations

TreeModelEvent (javax.swing.event.TreeModelEvent)20 TreeModelListener (javax.swing.event.TreeModelListener)17 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)2 TreeSelectionListener (javax.swing.event.TreeSelectionListener)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 PsiCopyPasteManager (com.intellij.ide.PsiCopyPasteManager)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 TreeModel (javax.swing.tree.TreeModel)1 TreeNode (javax.swing.tree.TreeNode)1 TreePath (javax.swing.tree.TreePath)1 NotNull (org.jetbrains.annotations.NotNull)1