package editor.gui.ccp.handler;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;

import javax.swing.TransferHandler;

import editor.database.card.Card;
import editor.gui.ccp.data.DataFlavors;
import editor.gui.editor.EditorFrame;

@SuppressWarnings("serial")
public class CardImportHandler extends TransferHandler implements ImportHandler
{
    private final EditorFrame editor;
    private final int id;

    public CardImportHandler(EditorFrame e, int i)
    {
        editor = e;
        id = i;
    }

    @Override
    public DataFlavor supportedFlavor()
    {
        return DataFlavors.cardFlavor;
    }

    @Override
    public boolean canImport(TransferSupport supp)
    {
        return supp.isDataFlavorSupported(supportedFlavor());
    }

    @Override
    public boolean importData(TransferSupport supp)
    {
        if (!canImport(supp))
            return false;
        else
        {
            try
            {
                var data = Arrays.stream((Card[])supp.getTransferable().getTransferData(supportedFlavor())).collect(Collectors.toSet());
                return editor.addCards(id, data, 1);
            }
            catch (UnsupportedFlavorException | IOException e)
            {
                return false;
            }
        }
    }
}
@@ -364,16 +364,90 @@
 Frame;%0A%0A
+/**%0A * Import handler for importing a list of single copies of cards.%0A */%0A
 @Suppres
@@ -556,68 +556,360 @@
     
-private final EditorFrame editor;%0A    private final int id;%0A
+/** Editor frame that is importing the cards. */%0A    private final EditorFrame editor;%0A    /** ID of the list to import cards to. */%0A    private final int id;%0A%0A    /**%0A     * Create a new card import handler.%0A     * %0A     * @param e editor frame containing the deck to import cards into%0A     * @param i ID of the list in the deck to import into%0A     */
 %0A   

Add documentation to card import handler