Example usage for com.vaadin.ui DragAndDropWrapper setDragImageComponent

List of usage examples for com.vaadin.ui DragAndDropWrapper setDragImageComponent

Introduction

In this page you can find the example usage for com.vaadin.ui DragAndDropWrapper setDragImageComponent.

Prototype

public void setDragImageComponent(Component dragImageComponent) 

Source Link

Document

Sets the component that will be used as the drag image.

Usage

From source file:org.lucidj.browser.AbstractCell.java

License:Apache License

private Component build_left_panel() {
    left_panel = new CssLayout();
    left_panel.setWidth(32, Sizeable.Unit.PIXELS);
    left_panel.addStyleName("cell-panel-left");
    left_panel.setHeight(100, Sizeable.Unit.PERCENTAGE);

    String icon_url = "/VAADIN/~/formulas/impossible.png";
    String icon_title = "The Unknown";

    ComponentInterface component_interface = Aggregate.adapt(ComponentInterface.class, source_object);
    if (component_interface != null) {
        // If it is a valid component, displays its icon on the top left corner of the cell
        ComponentDescriptor descriptor = (ComponentDescriptor) component_interface
                .getProperty(ComponentDescriptor.DESCRIPTOR);

        if (descriptor != null) {
            icon_url = descriptor.getIconUrl();
            icon_title = descriptor.getIconTitle();
        }//from   w  w w  . ja v  a  2s  . com
    }

    String component_icon_html = "<img class='component-icon' src='" + icon_url + "' title='"
            + SafeHtmlUtils.htmlEscape(icon_title) + "'/>";
    component_icon = new Label(component_icon_html, ContentMode.HTML);
    left_panel.addComponent(component_icon);

    // Put the component in a D&D wrapper and allow dragging it
    final DragAndDropWrapper panel_dd_wrap = new DragAndDropWrapper(left_panel);
    panel_dd_wrap.setDragStartMode(DragAndDropWrapper.DragStartMode.COMPONENT_OTHER);
    panel_dd_wrap.setDragImageComponent(component_icon);
    panel_dd_wrap.addStyleName("no-horizontal-drag-hints");
    panel_dd_wrap.addStyleName("no-box-drag-hints");

    // Set the wrapper to wrap tightly around the component
    panel_dd_wrap.setHeight(100, Sizeable.Unit.PERCENTAGE);
    panel_dd_wrap.setWidthUndefined();
    panel_dd_wrap.setId("test");

    // Setup DD handlers for component insertion
    panel_dd_wrap.setData(this);
    panel_dd_wrap.setDropHandler(this);

    // While left_panel is kept in order to be customized, here we return D&D wrapper
    return (panel_dd_wrap);
}