Example usage for javax.swing JTree getTransferHandler

List of usage examples for javax.swing JTree getTransferHandler

Introduction

In this page you can find the example usage for javax.swing JTree getTransferHandler.

Prototype

public TransferHandler getTransferHandler() 

Source Link

Document

Gets the transferHandler property.

Usage

From source file:org.nuclos.client.explorer.ExplorerNode.java

/**
 * @param tree the tree where the action is about to take place.
 * @return the list of possible <code>TreeNodeAction</code>s for this node.
 * These may be shown in the node's context menu.
 * Separators are shown in the menus for <code>null</code> entries.
 *///from   w  w  w.jav  a2  s  .com
public List<TreeNodeAction> getTreeNodeActions(JTree tree) {
    final List<TreeNodeAction> result = new LinkedList<TreeNodeAction>();

    result.add(new RefreshAction(tree));
    final ShowInOwnTabAction actShowInOwnTab = new ShowInOwnTabAction(tree);
    actShowInOwnTab.setEnabled(!this.getTreeNode().needsParent());
    result.add(actShowInOwnTab);

    result.addAll(getExpandCollapseActions(tree));

    final TreeNodeAction exploreractCopy = new ChainedTreeNodeAction(ACTIONCOMMAND_COPY,
            getSpringLocaleDelegate().getMessage("ExplorerNode.4", "Kopieren"), TransferHandler.getCopyAction(),
            tree);
    result.add(exploreractCopy);

    final TreeNodeAction exploreractPaste = new ChainedTreeNodeAction(ACTIONCOMMAND_PASTE,
            getSpringLocaleDelegate().getMessage("ExplorerNode.2", "Einf\u00fcgen"),
            TransferHandler.getPasteAction(), tree);
    result.add(exploreractPaste);

    // enable "copy" action according to the tree's TransferHandler:
    final boolean bCopyEnabled = (tree.getTransferHandler().getSourceActions(tree) & TransferHandler.COPY) != 0;
    exploreractCopy.setEnabled(bCopyEnabled);

    // enable "paste" action according to the tree's TransferHandler:
    // This is hard because TransferHandler.canImport is not called every time the selection changes.
    // Workaround: call canImport anyway to reduce bad paste actions:
    final DataFlavor[] aflavors = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this)
            .getTransferDataFlavors();
    final boolean bPasteEnabled = tree.getTransferHandler().canImport(tree, aflavors);
    exploreractPaste.setEnabled(bPasteEnabled);

    return result;
}