/*
 * TreeTransfertHandler.java
 *
 * Created on 15 settembre 2004, 2.19
 */

package it.businesslogic.ireport.gui.library;
import java.awt.datatransfer.Transferable;
import javax.swing.*;
import javax.swing.tree.*;
/**
 *
 * @author  Administrator
 */
public class TreeTransfertHandler extends javax.swing.TransferHandler {
    
    /** Creates a new instance of TreeTransfertHandler */
    public TreeTransfertHandler() {
        super();
    }
    
    public int getSourceActions(JComponent c) 
    {
        return COPY_OR_MOVE;
        
    }
    
    protected Transferable createTransferable(JComponent c) 
    {
        if (c instanceof JTree)
        {
            JTree tree = (JTree)c;
            TreePath path = tree.getLeadSelectionPath();
	    DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode)path.getLastPathComponent();
            return new it.businesslogic.ireport.gui.dnd.TransferableObject(dmtn.getUserObject());           
        }
        
        return new it.businesslogic.ireport.gui.dnd.TransferableObject(c);
    }
}
