com.alee.extended.tree
Class AbstractTreeTransferHandler<N extends UniqueNode,T extends WebTree<N>,M extends WebTreeModel<N>>

java.lang.Object
  extended by javax.swing.TransferHandler
      extended by com.alee.extended.tree.AbstractTreeTransferHandler<N,T,M>
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AsyncTreeTransferHandler, ExTreeTransferHandler

public abstract class AbstractTreeTransferHandler<N extends UniqueNode,T extends WebTree<N>,M extends WebTreeModel<N>>
extends javax.swing.TransferHandler

Author:
Mikle Garin
See Also:
Serialized Form

Nested Class Summary
 class AbstractTreeTransferHandler.NodesTransferable
          Custom nodes transferable used for D&D operation.
 
Nested classes/interfaces inherited from class javax.swing.TransferHandler
javax.swing.TransferHandler.DropLocation, javax.swing.TransferHandler.TransferSupport
 
Field Summary
protected  java.util.Map<java.lang.String,java.util.List<java.lang.Integer>> draggedNodeIndices
          Map of node indices lists under their parent node IDs.
protected  java.util.List<N> draggedNodes
          Array of dragged nodes.
protected  boolean expandMultiplyNodes
          Whether or not should expand multiply dragged nodes when they are dropped onto the tree.
protected  boolean expandSingleNode
          Whether or not should expand single dragged node when it is dropped onto the tree.
protected  java.awt.datatransfer.DataFlavor[] flavors
          Nodes flavor array.
protected  java.awt.datatransfer.DataFlavor nodesFlavor
          Nodes flavor.
protected  boolean optimizeDraggedNodes
          Whether or not should optimize dragged nodes list to minimum.
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE
 
Constructor Summary
AbstractTreeTransferHandler()
          Constructs new tree transfer handler.
 
Method Summary
protected abstract  boolean canBeDragged(java.util.List<N> nodes)
          Returns whether the specified nodes drag can be started or not.
protected abstract  boolean canBeDropped(java.util.List<N> nodes, N dropLocation, int dropIndex)
          Returns whether nodes can be dropped to the specified location and index or not.
protected  boolean canDropTo(N dropLocation)
          Checks whether specified target is acceptable for drop or not.
 boolean canImport(javax.swing.TransferHandler.TransferSupport support)
          
protected
<O> java.util.List<O>
collect(java.util.List<N> nodes)
          Returns user objects collected from specified nodes.
protected abstract  N copy(N node)
          Returns node copy used in createTransferable.
protected  java.awt.datatransfer.DataFlavor createNodesFlavor()
          Creates nodes transferable flavor.
protected  java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent c)
          Creates a Transferable to use as the source for a data transfer.
protected  void exportDone(javax.swing.JComponent source, java.awt.datatransfer.Transferable data, int action)
          Invoked after data has been exported.
protected  int getAdjustedDropIndex(int dropIndex, int dropAction, N parent)
          Returns properly adjusted nodes drop index.
 int getSourceActions(javax.swing.JComponent c)
          Returns the type of transfer actions supported by the source.
 boolean importData(javax.swing.TransferHandler.TransferSupport support)
          
 boolean isExpandMultiplyNodes()
          Returns whether or not should expand multiply dragged nodes when they are dropped onto the tree.
 boolean isExpandSingleNode()
          Returns whether should expand single dragged node when it is dropped onto the tree or not.
protected  boolean isMoveAction(int action)
          Returns whether action is MOVE or not.
 boolean isOptimizeDraggedNodes()
          Return whether or not should optimize dragged nodes list to minimum.
abstract  void nodesDropped(java.util.List<N> nodes, N parent, T tree, M model, int index)
          Informs about nodes drop operation completition in a separate tree thread.
protected abstract  boolean performDropOperation(java.util.List<N> nodes, N parent, T tree, M model, int index)
          Performs actual nodes drop operation.
protected abstract  boolean prepareDropOperation(javax.swing.TransferHandler.TransferSupport support, java.util.List<N> nodes, int dropIndex, N parent, T tree, M model)
          Performs all preparations required to perform drop operation and calls for actual drop when ready.
protected abstract  void removeTreeNodes(T tree, java.util.List<N> nodesToRemove)
          Asks tree to remove nodes after drag move operation has completed.
 void setExpandMultiplyNodes(boolean expand)
          Sets whether or not should expand multiply dragged nodes when they are dropped onto the tree.
 void setExpandSingleNode(boolean expand)
          Sets whether should expand single dragged node when it is dropped onto the tree or not.
 void setOptimizeDraggedNodes(boolean optimize)
          Sets whether or not should optimize dragged nodes list to minimum.
 java.lang.String toString()
          
 
Methods inherited from class javax.swing.TransferHandler
canImport, exportAsDrag, exportToClipboard, getCopyAction, getCutAction, getPasteAction, getVisualRepresentation, importData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nodesFlavor

protected java.awt.datatransfer.DataFlavor nodesFlavor
Nodes flavor.


flavors

protected java.awt.datatransfer.DataFlavor[] flavors
Nodes flavor array.


optimizeDraggedNodes

protected boolean optimizeDraggedNodes
Whether or not should optimize dragged nodes list to minimum.


expandSingleNode

protected boolean expandSingleNode
Whether or not should expand single dragged node when it is dropped onto the tree.


expandMultiplyNodes

protected boolean expandMultiplyNodes
Whether or not should expand multiply dragged nodes when they are dropped onto the tree.


draggedNodes

protected java.util.List<N extends UniqueNode> draggedNodes
Array of dragged nodes.


draggedNodeIndices

protected java.util.Map<java.lang.String,java.util.List<java.lang.Integer>> draggedNodeIndices
Map of node indices lists under their parent node IDs. This map is used to properly adjust drop index in the destination node if D&D performed within one tree.

Constructor Detail

AbstractTreeTransferHandler

public AbstractTreeTransferHandler()
Constructs new tree transfer handler.

Method Detail

createNodesFlavor

protected java.awt.datatransfer.DataFlavor createNodesFlavor()
Creates nodes transferable flavor.

Returns:
nodes transferable flavor

isOptimizeDraggedNodes

public boolean isOptimizeDraggedNodes()
Return whether or not should optimize dragged nodes list to minimum.

Returns:
true if should optimize dragged nodes list to minimum, false otherwise

setOptimizeDraggedNodes

public void setOptimizeDraggedNodes(boolean optimize)
Sets whether or not should optimize dragged nodes list to minimum.

Parameters:
optimize - whether or not should optimize dragged nodes list to minimum

isExpandSingleNode

public boolean isExpandSingleNode()
Returns whether should expand single dragged node when it is dropped onto the tree or not.

Returns:
true if should expand single dragged node when it is dropped onto the tree, false otherwise

setExpandSingleNode

public void setExpandSingleNode(boolean expand)
Sets whether should expand single dragged node when it is dropped onto the tree or not.

Parameters:
expand - whether should expand single dragged node when it is dropped onto the tree or not

isExpandMultiplyNodes

public boolean isExpandMultiplyNodes()
Returns whether or not should expand multiply dragged nodes when they are dropped onto the tree.

Returns:
true if should expand multiply dragged nodes when they are dropped onto the tree, false otherwise

setExpandMultiplyNodes

public void setExpandMultiplyNodes(boolean expand)
Sets whether or not should expand multiply dragged nodes when they are dropped onto the tree.

Parameters:
expand - whether or not should expand multiply dragged nodes when they are dropped onto the tree

getSourceActions

public int getSourceActions(javax.swing.JComponent c)
Returns the type of transfer actions supported by the source. Any bitwise-OR combination of COPY, MOVE and LINK. Returning NONE disables transfers from the component.

Overrides:
getSourceActions in class javax.swing.TransferHandler
Parameters:
c - the component holding the data to be transferred
Returns:
type of transfer actions supported by the source

createTransferable

protected java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent c)
Creates a Transferable to use as the source for a data transfer. Returns the representation of the data to be transferred, or null if the component's property is null

Overrides:
createTransferable in class javax.swing.TransferHandler
Parameters:
c - the component holding the data to be transferred, provided to enable sharing of TransferHandlers
Returns:
the representation of the data to be transferred, or null if the property associated with component is null

canImport

public boolean canImport(javax.swing.TransferHandler.TransferSupport support)

Overrides:
canImport in class javax.swing.TransferHandler

importData

public boolean importData(javax.swing.TransferHandler.TransferSupport support)

Overrides:
importData in class javax.swing.TransferHandler

prepareDropOperation

protected abstract boolean prepareDropOperation(javax.swing.TransferHandler.TransferSupport support,
                                                java.util.List<N> nodes,
                                                int dropIndex,
                                                N parent,
                                                T tree,
                                                M model)
Performs all preparations required to perform drop operation and calls for actual drop when ready.

Parameters:
support - transfer support data
nodes - list of nodes to drop
dropIndex - preliminary nodes drop index
parent - parent node to drop nodes into
tree - tree to drop nodes onto
model - tree model
Returns:
true if drop operation was successfully completed, false otherwise

performDropOperation

protected abstract boolean performDropOperation(java.util.List<N> nodes,
                                                N parent,
                                                T tree,
                                                M model,
                                                int index)
Performs actual nodes drop operation.

Parameters:
nodes - list of nodes to drop
parent - parent node to drop nodes into
tree - tree to drop nodes onto
model - tree model
index - nodes drop index
Returns:
true if drop operation was successfully completed, false otherwise

getAdjustedDropIndex

protected int getAdjustedDropIndex(int dropIndex,
                                   int dropAction,
                                   N parent)
Returns properly adjusted nodes drop index.

Parameters:
dropIndex - drop index if dropped between nodes under dropLocation node or -1 if dropped directly onto dropLocation node
dropAction - actual drop action
parent - parent node to drop nodes into @return properly adjusted nodes drop index

exportDone

protected void exportDone(javax.swing.JComponent source,
                          java.awt.datatransfer.Transferable data,
                          int action)
Invoked after data has been exported. This method should remove the data that was transferred if the action was MOVE. This method is invoked from EDT so it is safe to perform tree operations.

Overrides:
exportDone in class javax.swing.TransferHandler
Parameters:
source - the component that was the source of the data
data - the data that was transferred or possibly null if the action is NONE
action - the actual action that was performed

isMoveAction

protected boolean isMoveAction(int action)
Returns whether action is MOVE or not.

Parameters:
action - drag action
Returns:
true if action is MOVE, false otherwise

canBeDragged

protected abstract boolean canBeDragged(java.util.List<N> nodes)
Returns whether the specified nodes drag can be started or not.

Parameters:
nodes - nodes to drag
Returns:
true if the specified nodes drag can be started, false otherwise

canDropTo

protected boolean canDropTo(N dropLocation)
Checks whether specified target is acceptable for drop or not. This check is performed before another check for nodes drop possibility.

Parameters:
dropLocation - node onto which drop was performed
Returns:
true if the specified target is acceptable for drop, false otherwise

canBeDropped

protected abstract boolean canBeDropped(java.util.List<N> nodes,
                                        N dropLocation,
                                        int dropIndex)
Returns whether nodes can be dropped to the specified location and index or not.

Parameters:
nodes - list of nodes to drop
dropLocation - node onto which drop was performed
dropIndex - drop index if dropped between nodes under dropLocation node or -1 if dropped directly onto dropLocation node
Returns:
true if nodes can be dropped to the specified location and index, false otherwise

copy

protected abstract N copy(N node)
Returns node copy used in createTransferable. Used each time when node is moved within tree or into another tree. Node copy should have the same ID and content but must be another instance of node type class.

Parameters:
node - node to copy
Returns:
node copy

removeTreeNodes

protected abstract void removeTreeNodes(T tree,
                                        java.util.List<N> nodesToRemove)
Asks tree to remove nodes after drag move operation has completed.

Parameters:
tree - tree to remove nodes from
nodesToRemove - nodes that should be removed

nodesDropped

public abstract void nodesDropped(java.util.List<N> nodes,
                                  N parent,
                                  T tree,
                                  M model,
                                  int index)
Informs about nodes drop operation completition in a separate tree thread. This method should be used to perform actual data move operation.

Parameters:
nodes - list of nodes to drop
parent - parent node to drop nodes into
tree - tree to drop nodes onto
model - tree model
index - nodes drop index

collect

protected <O> java.util.List<O> collect(java.util.List<N> nodes)
Returns user objects collected from specified nodes.

Type Parameters:
O - user object type
Parameters:
nodes - list of nodes to collect user objects from
Returns:
user objects collected from specified nodes

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object