Example usage for java.awt.dnd DropTargetEvent getDropTargetContext

List of usage examples for java.awt.dnd DropTargetEvent getDropTargetContext

Introduction

In this page you can find the example usage for java.awt.dnd DropTargetEvent getDropTargetContext.

Prototype


public DropTargetContext getDropTargetContext() 

Source Link

Document

This method returns the DropTargetContext associated with this DropTargetEvent .

Usage

From source file:org.kuali.test.ui.dnd.RepositoryDropTargetAdapter.java

private boolean canDrop(DropTargetEvent dte) {
    boolean retval = false;
    try {//from   w ww  .java  2  s .com
        if (dte.getDropTargetContext().getComponent() == repositoryTree) {
            Point pt = null;
            Transferable t = null;
            int ops = -1;
            DataFlavor dataFlavor = null;
            if (dte instanceof DropTargetDragEvent) {
                pt = ((DropTargetDragEvent) dte).getLocation();
                t = ((DropTargetDragEvent) dte).getTransferable();
                ops = ((DropTargetDragEvent) dte).getSourceActions();
                dataFlavor = ((DropTargetDragEvent) dte).getCurrentDataFlavors()[0];
            } else if (dte instanceof DropTargetDropEvent) {
                pt = ((DropTargetDropEvent) dte).getLocation();
                t = ((DropTargetDropEvent) dte).getTransferable();
                ops = ((DropTargetDropEvent) dte).getSourceActions();
                dataFlavor = ((DropTargetDropEvent) dte).getCurrentDataFlavors()[0];
            }

            if ((pt != null) && (t != null)) {
                if (isTestLinkTransfer(t, ops, dataFlavor)) {
                    DefaultMutableTreeNode node = getNodeAtPoint(pt);
                    if (node != null) {
                        Object uo = node.getUserObject();

                        if (uo != null) {
                            if (uo instanceof TestSuite) {
                                TestSuite testSuite = (TestSuite) uo;
                                RepositoryTransferData<Platform, List<String>> data = (RepositoryTransferData<Platform, List<String>>) t
                                        .getTransferData(dataFlavor);

                                retval = (StringUtils.equalsIgnoreCase(data.getTarget().getName(),
                                        testSuite.getPlatformName()));
                            }
                        }
                    }
                } else if (isTestOrderTransfer(t, ops, dataFlavor)) {
                    DefaultMutableTreeNode node = getNodeAtPoint(pt);
                    if (node != null) {
                        Object uo = node.getUserObject();
                        if (uo != null) {
                            if (uo instanceof SuiteTest) {
                                SuiteTest targetSuiteTest = (SuiteTest) uo;
                                RepositoryTransferData<TestSuite, SuiteTest> data = (RepositoryTransferData<TestSuite, SuiteTest>) t
                                        .getTransferData(dataFlavor);

                                retval = (StringUtils.equalsIgnoreCase(data.getTarget().getPlatformName(),
                                        targetSuiteTest.getTestHeader().getPlatformName())
                                        && !StringUtils.equalsIgnoreCase(
                                                targetSuiteTest.getTestHeader().getTestName(),
                                                data.getData().getTestHeader().getTestName())
                                        && (targetSuiteTest.getIndex() != data.getData().getIndex()));
                            }
                        }
                    }
                }
            }
        }
    }

    catch (Exception ex) {
        LOG.warn(ex.toString(), ex);
    }

    return retval;
}