com.alee.extended.tree
Class AsyncTreeTransferHandler<N extends AsyncUniqueNode,T extends WebAsyncTree<N>>

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

public abstract class AsyncTreeTransferHandler<N extends AsyncUniqueNode,T extends WebAsyncTree<N>>
extends javax.swing.TransferHandler

Custom TransferHandler for WebAsyncTree that provides a quick and convenient way to implement nodes DnD.

Author:
Mikle Garin
See Also:
Serialized Form

Nested Class Summary
 class AsyncTreeTransferHandler.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  boolean allowUncheckedDrop
          Whether should allow dropping nodes onto not-yet-loaded node or not.
protected  java.awt.datatransfer.DataFlavor[] flavors
          Nodes flavor array.
protected  java.awt.datatransfer.DataFlavor nodesFlavor
          Nodes flavor.
protected  java.util.List<N> nodesToRemove
          Array of dragged nodes that should be removed at the end of DnD operation.
protected  java.util.Map<java.lang.String,java.util.List<java.lang.Integer>> removedUnder
          Map of removed node indices lists under their parent node IDs.
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE
 
Constructor Summary
AsyncTreeTransferHandler()
          Constructs new async 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.
 boolean canImport(javax.swing.TransferHandler.TransferSupport support)
          
protected abstract  N copy(N node)
          Returns node copy used in createTransferable.
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, 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 isAllowUncheckedDrop()
          Returns whether should allow dropping nodes onto not-yet-loaded node or not.
abstract  void nodesDropped(java.util.List<N> nodes, N parent, T tree, AsyncTreeModel<N> model, int index)
          Informs about nodes drop operation completition in a separate tree thread.
protected  void performDropOperation(java.util.List<N> nodes, N parent, T tree, AsyncTreeModel<N> model, int index)
          Performs actual nodes drop operation.
 void setAllowUncheckedDrop(boolean allowUncheckedDrop)
          Sets whether should allow dropping nodes onto not-yet-loaded node or not
 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

allowUncheckedDrop

protected boolean allowUncheckedDrop
Whether should allow dropping nodes onto not-yet-loaded node or not. Be aware that if this set to true and your tree might fail loading childs - old nodes will still get removed on drop. If set to false tree will try to load child nodes first and then perform the drop operation.


nodesFlavor

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


flavors

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


nodesToRemove

protected java.util.List<N extends AsyncUniqueNode> nodesToRemove
Array of dragged nodes that should be removed at the end of DnD operation.


removedUnder

protected java.util.Map<java.lang.String,java.util.List<java.lang.Integer>> removedUnder
Map of removed 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

AsyncTreeTransferHandler

public AsyncTreeTransferHandler()
Constructs new async tree transfer handler.

Method Detail

isAllowUncheckedDrop

public boolean isAllowUncheckedDrop()
Returns whether should allow dropping nodes onto not-yet-loaded node or not.

Returns:
true if should allow dropping nodes onto not-yet-loaded node, false otherwise

setAllowUncheckedDrop

public void setAllowUncheckedDrop(boolean allowUncheckedDrop)
Sets whether should allow dropping nodes onto not-yet-loaded node or not

Parameters:
allowUncheckedDrop - whether should allow dropping nodes onto not-yet-loaded node or not

canImport

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

Overrides:
canImport in class javax.swing.TransferHandler

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

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.

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

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

importData

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

Overrides:
importData in class javax.swing.TransferHandler

getAdjustedDropIndex

protected int getAdjustedDropIndex(int dropIndex,
                                   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
parent - parent node to drop nodes into
Returns:
properly adjusted nodes drop index

performDropOperation

protected void performDropOperation(java.util.List<N> nodes,
                                    N parent,
                                    T tree,
                                    AsyncTreeModel<N> 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

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

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

nodesDropped

public abstract void nodesDropped(java.util.List<N> nodes,
                                  N parent,
                                  T tree,
                                  AsyncTreeModel<N> 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. You are allowed to perform slow operations here as it is executed in a special async tree thread.

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

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object