Example usage for com.vaadin.event.dd DropTarget getDropHandler

List of usage examples for com.vaadin.event.dd DropTarget getDropHandler

Introduction

In this page you can find the example usage for com.vaadin.event.dd DropTarget getDropHandler.

Prototype

public DropHandler getDropHandler();

Source Link

Usage

From source file:com.foc.web.unitTesting.FocUnitTestingCommand.java

License:Apache License

/**
 * Simulates a drag and drop event./*from   www .j  a  va 2  s .c o  m*/
 * @param sourceName
 * @param sourcePropertyName
 * @param targetPropertyName
 * @param targetPropertyValue
 */

public void dragAndDropHighLevel(String sourceName, String sourcePropertyName, String sourcePropertyValue,
        String targetName, String targetPropertyName, String targetPropertyValue) throws Exception {
    FocXMLLayout navigationLayout = getCurrentCentralPanel();

    if (navigationLayout != null) {

        FVTableWrapperLayout sourceWrapper = (FVTableWrapperLayout) findComponent(navigationLayout, sourceName);
        ITableTree sourceTableOrTree = sourceWrapper == null ? null : sourceWrapper.getTableOrTree();
        Object sourceItemId = null;

        if (sourceTableOrTree != null) {
            FocObject sourceObject = sourceTableOrTree.getTableTreeDelegate()
                    .selectByFocProperty(sourcePropertyName, sourcePropertyValue);

            if (sourceObject != null) {
                sourceItemId = sourceObject.getReference().getLong();
            } else {
                String message = "Could not find source row PROPERTY=" + sourcePropertyName + " VALUE="
                        + sourcePropertyValue;
                getLogger().addFailure(message);
                Globals.logString(message);
                sourceTableOrTree.getTableTreeDelegate().debug_ListOfColumns();
            }
        }

        FocXMLGuiComponent targetComponent = findComponent(navigationLayout, targetName);
        if (targetComponent instanceof FVTableWrapperLayout) {
            FVTableWrapperLayout targetWrapper = (FVTableWrapperLayout) findComponent(navigationLayout,
                    targetName);
            ITableTree targetTableOrTree = targetWrapper == null ? null : targetWrapper.getTableOrTree();
            Object targetItemId = null;

            if (targetTableOrTree != null) {
                if (targetPropertyName != null && targetPropertyValue != null) {
                    FocObject targetObject = targetTableOrTree.getTableTreeDelegate()
                            .selectByFocProperty(targetPropertyName, targetPropertyValue);

                    if (targetObject != null) {
                        targetItemId = targetObject.getReference().getLong();
                    }
                }
            }

            dragAndDropLowLevel(sourceTableOrTree, sourceItemId, targetTableOrTree, targetItemId);
        } else if (targetComponent instanceof DropTarget) {
            DataBoundTransferable dbt = buildDragTransferable(sourceTableOrTree, sourceItemId);
            DropTarget dropTarget = (DropTarget) targetComponent;
            DropHandler dropHandler = dropTarget.getDropHandler();

            HashMap<String, Object> rawVariables = new HashMap<String, Object>();

            TargetDetailsImpl details = new TargetDetailsImpl(rawVariables, dropTarget);
            DragAndDropEvent dde = new DragAndDropEvent(dbt, details);
            if (dropHandler != null) {
                dropHandler.drop(dde);
            }
        }
    }
}