Copyright 2012-02-25 Werner Randelshofer

ch.randelshofer.gui.tree
Interface MutableTreeModel

All Superinterfaces:
javax.swing.tree.TreeModel
All Known Implementing Classes:
DefaultMutableTreeModel, ZipTreeModel

public interface MutableTreeModel
extends javax.swing.tree.TreeModel

Speficies the requirements for a mutable tree model.

The mutable list model adds suport for the following operations to the javax.swing.tree.TreeModel interface:

Version:
3.1 2009-12-21 MutableTreeModel.createNodeAt-method returns path to created node.
3.0 2004-05-16 Revised.
2.3 2002-04-08 Interface streamlined. Support for Transferables added.
2.0.1 2002-04-07 Method getInsertableRowTypes added.
2.0 2001-07-18
Author:
Werner Randelshofer

Method Summary
 javax.swing.tree.TreePath createNodeAt(java.lang.Object type, javax.swing.tree.MutableTreeNode parent, int index)
          Creates the specified element type at the specified position in this list Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
 java.awt.datatransfer.Transferable exportTransferable(javax.swing.tree.MutableTreeNode[] nodes)
          Creates a Transferable to use as the source for a data transfer of the specified elements.
 java.lang.Object getCreatableNodeType(java.lang.Object parent)
          Returns the default type of children that can be created at the specified node.
 java.lang.Object[] getCreatableNodeTypes(java.lang.Object parent)
          Returns the types of children that may be created at this node.
 javax.swing.Action[] getNodeActions(javax.swing.tree.MutableTreeNode[] nodes)
          Gets actions for the specified nodes.
 int importTransferable(java.awt.datatransfer.Transferable t, int action, javax.swing.tree.MutableTreeNode parent, int index)
          Causes a transfer to the model from a clipboard or a DND drop operation.
 boolean isImportable(java.awt.datatransfer.DataFlavor[] transferFlavors, int action, javax.swing.tree.MutableTreeNode parent, int index)
          Indicates whether the model would accept an import of the given set of data flavors prior to actually attempting to import it.
 boolean isNodeAddable(javax.swing.tree.MutableTreeNode parent, int index)
          Returns whether a node may be added.
 boolean isNodeEditable(javax.swing.tree.MutableTreeNode node)
          Returns wether the specified node may be edited.
 boolean isNodeRemovable(javax.swing.tree.MutableTreeNode node)
          Returns whether the specified node may be removed.
 void removeNodeFromParent(javax.swing.tree.MutableTreeNode node)
          Message this to remove a child from its parent.
 
Methods inherited from interface javax.swing.tree.TreeModel
addTreeModelListener, getChild, getChildCount, getIndexOfChild, getRoot, isLeaf, removeTreeModelListener, valueForPathChanged
 

Method Detail

getCreatableNodeTypes

java.lang.Object[] getCreatableNodeTypes(java.lang.Object parent)
Returns the types of children that may be created at this node.

Parameters:
parent - a node from the tree, obtained from this data source.
Returns:
an array of objects that specify a child type that may be added to the node. Returns an empty array for nodes that cannot have additional children.

getCreatableNodeType

java.lang.Object getCreatableNodeType(java.lang.Object parent)
Returns the default type of children that can be created at the specified node.

Parameters:
parent - a node from the tree, obtained from this data source.
Returns:
an Object that specifies the default child type that can be inserted at the insertion point. Returns null if no children can be inserted here. The value must be one of the types returned by operation getCreatableNodeTypes.

createNodeAt

javax.swing.tree.TreePath createNodeAt(java.lang.Object type,
                                       javax.swing.tree.MutableTreeNode parent,
                                       int index)
                                       throws java.lang.IllegalStateException
Creates the specified element type at the specified position in this list Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

This method may create a node at a different location.

Parameters:
type - the type of the new child to be created, obtained from getCreatableChildren
parent - a node from the tree, obtained from this data source.
index - index of the child.
Returns:
The path pointing to the newly created node.
Throws:
java.lang.IllegalArgumentException - if the type is not contained in the array returned by getInsertableTypes(int).
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()).
java.lang.IllegalStateException

isNodeAddable

boolean isNodeAddable(javax.swing.tree.MutableTreeNode parent,
                      int index)
Returns whether a node may be added.

Parameters:
parent - a node from the tree, obtained from this data source.
index - the insertion index.

isNodeRemovable

boolean isNodeRemovable(javax.swing.tree.MutableTreeNode node)
Returns whether the specified node may be removed.

Parameters:
node - a node from the tree, obtained from this data source.

removeNodeFromParent

void removeNodeFromParent(javax.swing.tree.MutableTreeNode node)
Message this to remove a child from its parent.

Parameters:
node - a node from the tree, obtained from this data source.
Throws:
java.lang.IllegalStateException - if the node may not be removed.

isNodeEditable

boolean isNodeEditable(javax.swing.tree.MutableTreeNode node)
Returns wether the specified node may be edited.

Parameters:
node - a node from the tree, obtained from this data source.

getNodeActions

javax.swing.Action[] getNodeActions(javax.swing.tree.MutableTreeNode[] nodes)
Gets actions for the specified nodes.

Parameters:
nodes - The nodes.

exportTransferable

java.awt.datatransfer.Transferable exportTransferable(javax.swing.tree.MutableTreeNode[] nodes)
Creates a Transferable to use as the source for a data transfer of the specified elements. Returns the representation of the rows to be transferred, or null if transfer is not possible.

Parameters:
nodes - The nodes.

isImportable

boolean isImportable(java.awt.datatransfer.DataFlavor[] transferFlavors,
                     int action,
                     javax.swing.tree.MutableTreeNode parent,
                     int index)
Indicates whether the model would accept an import of the given set of data flavors prior to actually attempting to import it.

Parameters:
transferFlavors - the data formats available
action - the action, this is either COPY, MOVE or LINK.
parent - a node from the tree, obtained from this data source.
index - The insertion point.
Returns:
true if the data can be inserted into the component, false otherwise

importTransferable

int importTransferable(java.awt.datatransfer.Transferable t,
                       int action,
                       javax.swing.tree.MutableTreeNode parent,
                       int index)
                       throws java.awt.datatransfer.UnsupportedFlavorException,
                              java.io.IOException
Causes a transfer to the model from a clipboard or a DND drop operation.

Parameters:
t - The transfer data.
parent - a node from the tree, obtained from this data source.
index - The insertion point.
Returns:
The number of imported elements or 0 if nothing was imported.
Throws:
java.awt.datatransfer.UnsupportedFlavorException
java.io.IOException

Copyright 2012-02-25 Werner Randelshofer